15 using namespace fastjet;
16 using namespace findNode;
20 namespace SColdQcdCorrelatorAnalysis {
28 cout <<
"SCorrelatorJetTree::FindTrueJets(PHCompositeNode*) Finding truth (inclusive) jets..." << endl;
32 m_trueJetDef =
new JetDefinition(m_jetAlgo, m_jetR, m_recombScheme,
fastjet::Best);
36 map<int, pair<Jet::SRC, int>> fjMapMC;
39 AddParticles(topNode, particles, fjMapMC);
42 m_trueClust =
new ClusterSequence(particles, *m_trueJetDef);
43 m_trueJets = m_trueClust -> inclusive_jets();
54 cout <<
"SCorrelatorJetTree::FindRecoJets(PHCompositeNode*) Finding jets..." << endl;
58 m_recoJetDef =
new JetDefinition(m_jetAlgo, m_jetR, m_recombScheme,
fastjet::Best);
62 map<int, pair<Jet::SRC, int>> fjMap;
65 if (m_addTracks) AddTracks(topNode, particles, fjMap);
66 if (m_addFlow) AddFlow(topNode, particles, fjMap);
67 if (m_addECal) AddECal(topNode, particles, fjMap);
68 if (m_addHCal) AddHCal(topNode, particles, fjMap);
71 m_recoClust =
new ClusterSequence(particles, *m_recoJetDef);
72 m_recoJets = m_recoClust -> inclusive_jets();
79 void SCorrelatorJetTree::AddParticles(
PHCompositeNode* topNode, vector<PseudoJet>&
particles, map<
int, pair<Jet::SRC, int>>& fjMap) {
83 cout <<
"SCorrelatorJetTree::AddParticles(PHComposite*, vector<PseudoJet>&, map<int, pair<Jet::SRC, int>>&) Adding MC particles..." << endl;
87 unsigned int iCst = particles.size();
88 unsigned int nParTot = 0;
89 unsigned int nParAcc = 0;
91 for (
const int evtToGrab : m_vecEvtsToGrab) {
94 HepMC::GenEvent* mcEvt =
GetMcEvent(topNode, evtToGrab);
97 const int embedID =
GetEmbedID(topNode, evtToGrab);
100 for (HepMC::GenEvent::particle_const_iterator itPar = mcEvt -> particles_begin(); itPar != mcEvt -> particles_end(); ++itPar) {
103 const bool isFinalState = ((*itPar) ->
status() == 1);
111 const bool isGoodPar = IsGoodParticle(*itPar);
119 const double parPx = (*itPar) ->
momentum().px();
120 const double parPy = (*itPar) ->
momentum().py();
121 const double parPz = (*itPar) ->
momentum().pz();
122 const double parE = (*itPar) ->
momentum().e();
123 const int parID = (*itPar) -> barcode();
126 m_mapCstToEmbedID[parID] = embedID;
129 fastjet::PseudoJet fjParticle(parPx, parPy, parPz, parE);
130 fjParticle.set_user_index(parID);
131 particles.push_back(fjParticle);
134 pair<int, pair<Jet::SRC, int>> jetPartPair(iCst, make_pair(Jet::SRC::PARTICLE, parID));
135 fjMap.insert(jetPartPair);
138 m_hObjectQA[OBJECT::PART][
INFO::PT] ->
Fill(fjParticle.perp());
139 m_hObjectQA[OBJECT::PART][INFO::ETA] ->
Fill(fjParticle.pseudorapidity());
140 m_hObjectQA[OBJECT::PART][INFO::PHI] ->
Fill(fjParticle.phi_std());
141 m_hObjectQA[OBJECT::PART][INFO::ENE] ->
Fill(fjParticle.E());
148 m_hNumObject[OBJECT::PART] ->
Fill(nParAcc);
149 m_hNumCstAccept[CST_TYPE::PART_CST][0] ->
Fill(nParTot);
150 m_hNumCstAccept[CST_TYPE::PART_CST][1] ->
Fill(nParAcc);
151 m_hSumCstEne[CST_TYPE::PART_CST] ->
Fill(eParSum);
162 cout <<
"SCorrelatorJetTree::AddTracks(PHCompositeNode*, vector<PseudoJet>&, map<int, pair<Jet::SRC, int>>&) Adding tracks..." << endl;
166 array<float, 40> arrWeirdTrackLeaves;
167 for (
size_t iLeaf = 0; iLeaf < 40; iLeaf++) {
168 arrWeirdTrackLeaves[iLeaf] = 0.;
171 vector<TrkrDefs::cluskey> clustKeysA;
172 vector<TrkrDefs::cluskey> clustKeysB;
177 unsigned int iCst = particles.size();
178 unsigned int nTrkTot = 0;
179 unsigned int nTrkAcc = 0;
187 track = itTrk -> second;
195 const bool isGoodTrack = IsGoodTrack(track, topNode);
203 const int trkID = track -> get_id();
204 const double trkPx = track -> get_px();
205 const double trkPy = track -> get_py();
206 const double trkPz = track -> get_pz();
207 const double trkE = sqrt((trkPx * trkPx) + (trkPy * trkPy) + (trkPz * trkPz) + (0.140 * 0.140));
218 fastjet::PseudoJet fjTrack(trkPx, trkPy, trkPz, trkE);
219 fjTrack.set_user_index(matchID);
220 particles.push_back(fjTrack);
223 pair<int, pair<Jet::SRC, int>> jetTrkPair(iCst, make_pair(Jet::SRC::TRACK, trkID));
224 fjMap.insert(jetTrkPair);
231 const double trkQuality = track -> get_quality();
233 const double trkDcaXY = trkDcaPair.first;
234 const double trkDcaZ = trkDcaPair.second;
242 const double trkPhi = track -> get_phi();
243 const double trkEta = track -> get_eta();
244 const double trkPt = track -> get_pt();
245 if (m_checkWeirdTrks) {
249 trackB = itTrkB -> second;
250 if (!trackB)
continue;
252 const bool isGoodTrackB = IsGoodTrack(trackB, topNode);
253 if (!isGoodTrackB)
continue;
260 const int trkIDB = trackB -> get_id();
267 const double trkQualityB = trackB -> get_quality();
269 const double trkDcaXYB = trkDcaPairB.first;
270 const double trkDcaZB = trkDcaPairB.second;
271 const double trkPxB = trackB -> get_px();
272 const double trkPyB = trackB -> get_py();
273 const double trkPzB = trackB -> get_pz();
274 const double trkEB = sqrt((trkPxB * trkPxB) + (trkPyB * trkPyB) + (trkPzB * trkPzB) + (0.140 * 0.140));
275 const double trkPhiB = trackB -> get_phi();
276 const double trkEtaB = trackB -> get_eta();
277 const double trkPtB = trackB -> get_pt();
280 const double dfTrkAB = trkPhi - trkPhiB;
281 const double dhTrkAB = trkEta - trkEtaB;
282 const double drTrkAB = sqrt((dfTrkAB * dfTrkAB) + (dhTrkAB * dhTrkAB));
285 if (trkID == trkIDB)
continue;
292 auto seedTpcA = track -> get_tpc_seed();
294 for (
auto local_iterA = seedTpcA -> begin_cluster_keys(); local_iterA != seedTpcA -> end_cluster_keys(); ++local_iterA) {
296 clustKeysA.push_back(cluster_keyA);
301 auto seedTpcB = trackB -> get_tpc_seed();
303 for (
auto local_iterB = seedTpcB -> begin_cluster_keys(); local_iterB != seedTpcB -> end_cluster_keys(); ++local_iterB) {
305 clustKeysB.push_back(cluster_keyB);
310 uint64_t nSameKey = 0;
311 for (
auto keyA : clustKeysA) {
312 for (
auto keyB : clustKeysB) {
321 arrWeirdTrackLeaves[0] = (float) trkID;
322 arrWeirdTrackLeaves[1] = (float) trkIDB;
323 arrWeirdTrackLeaves[2] = (float) trkPt;
324 arrWeirdTrackLeaves[3] = (float) trkPtB;
325 arrWeirdTrackLeaves[4] = (float) trkEta;
326 arrWeirdTrackLeaves[5] = (float) trkEtaB;
327 arrWeirdTrackLeaves[6] = (float) trkPhi;
328 arrWeirdTrackLeaves[7] = (float) trkPhiB;
329 arrWeirdTrackLeaves[8] = (float) trkE;
330 arrWeirdTrackLeaves[9] = (float) trkEB;
331 arrWeirdTrackLeaves[10] = (float) trkDcaXY;
332 arrWeirdTrackLeaves[11] = (float) trkDcaXYB;
333 arrWeirdTrackLeaves[12] = (float) trkDcaZ;
334 arrWeirdTrackLeaves[13] = (float) trkDcaZB;
335 arrWeirdTrackLeaves[14] = (float) trkVtx.x();
336 arrWeirdTrackLeaves[15] = (float) trkVtxB.x();
337 arrWeirdTrackLeaves[16] = (float) trkVtx.y();
338 arrWeirdTrackLeaves[17] = (float) trkVtxB.y();
339 arrWeirdTrackLeaves[18] = (float) trkVtx.z();
340 arrWeirdTrackLeaves[19] = (float) trkVtxB.z();
341 arrWeirdTrackLeaves[20] = (float) trkQuality;
342 arrWeirdTrackLeaves[21] = (float) trkQualityB;
343 arrWeirdTrackLeaves[22] = (float) trkDeltaPt;
344 arrWeirdTrackLeaves[23] = (float) trkDeltaPtB;
345 arrWeirdTrackLeaves[24] = (float) trkNumMvtx;
346 arrWeirdTrackLeaves[25] = (float) trkNumMvtxB;
347 arrWeirdTrackLeaves[26] = (float) trkNumIntt;
348 arrWeirdTrackLeaves[27] = (float) trkNumInttB;
349 arrWeirdTrackLeaves[28] = (float) trkNumTpc;
350 arrWeirdTrackLeaves[29] = (float) trkNumTpcB;
351 arrWeirdTrackLeaves[30] = (float) trkClustMvtx;
352 arrWeirdTrackLeaves[31] = (float) trkClustMvtxB;
353 arrWeirdTrackLeaves[32] = (float) trkClustIntt;
354 arrWeirdTrackLeaves[33] = (float) trkClustInttB;
355 arrWeirdTrackLeaves[34] = (float) trkClustTpc;
356 arrWeirdTrackLeaves[35] = (float) trkClustTpcB;
357 arrWeirdTrackLeaves[36] = (float) clustKeysA.size();
358 arrWeirdTrackLeaves[37] = (float) clustKeysB.size();
359 arrWeirdTrackLeaves[38] = (float) nSameKey;
360 arrWeirdTrackLeaves[39] = (float) drTrkAB;
363 m_ntWeirdTracks ->
Fill(arrWeirdTrackLeaves.data());
369 m_hObjectQA[OBJECT::TRACK][
INFO::PT] ->
Fill(fjTrack.perp());
370 m_hObjectQA[OBJECT::TRACK][INFO::ETA] ->
Fill(fjTrack.pseudorapidity());
371 m_hObjectQA[OBJECT::TRACK][INFO::PHI] ->
Fill(fjTrack.phi_std());
372 m_hObjectQA[OBJECT::TRACK][INFO::ENE] ->
Fill(fjTrack.E());
373 m_hObjectQA[OBJECT::TRACK][INFO::QUAL] ->
Fill(trkQuality);
374 m_hObjectQA[OBJECT::TRACK][INFO::DCAXY] ->
Fill(trkDcaXY);
375 m_hObjectQA[OBJECT::TRACK][INFO::DCAZ] ->
Fill(trkDcaZ);
376 m_hObjectQA[OBJECT::TRACK][INFO::DELTAPT] ->
Fill(trkDeltaPt);
377 m_hObjectQA[OBJECT::TRACK][INFO::NTPC] ->
Fill(trkNumTpc);
381 (
float) fjTrack.perp(),
382 (float) fjTrack.pseudorapidity(),
383 (float) fjTrack.phi_std(),
402 m_hNumObject[OBJECT::TRACK] ->
Fill(nTrkAcc);
403 m_hNumCstAccept[CST_TYPE::TRACK_CST][0] ->
Fill(nTrkTot);
404 m_hNumCstAccept[CST_TYPE::TRACK_CST][1] ->
Fill(nTrkAcc);
405 m_hSumCstEne[CST_TYPE::TRACK_CST] ->
Fill(eTrkSum);
416 cout <<
"SCorrelatorJetTree::AddFlow(PHCompositeNode*, vector<PseudoJet>&, map<int, pair<Jet::SRC, int>>&) Adding particle flow elements..." << endl;
420 if (m_doDebug && (m_jetType != 1)) {
421 cerr <<
"SCorrelatorJetTree::AddFlow - Warning - trying to add particle flow elements to charged jets!" << endl;
425 unsigned int iCst = particles.size();
426 unsigned int nFlowTot = 0;
427 unsigned int nFlowAcc = 0;
428 double eFlowSum = 0.;
432 for (itFlow = flowRange.first; itFlow != flowRange.second; ++itFlow) {
443 const bool isGoodFlow = IsGoodFlow(flow);
451 const int pfID = flow -> get_id();
452 const double pfE = flow -> get_e();
453 const double pfPx = flow -> get_px();
454 const double pfPy = flow -> get_py();
455 const double pfPz = flow -> get_pz();
457 fastjet::PseudoJet fjFlow(pfPx, pfPy, pfPz, pfE);
458 fjFlow.set_user_index(iCst);
459 particles.push_back(fjFlow);
462 pair<int, pair<Jet::SRC, int>> jetPartFlowPair(iCst, make_pair(Jet::SRC::PARTICLE, pfID));
463 fjMap.insert(jetPartFlowPair);
476 m_hNumCstAccept[CST_TYPE::FLOW_CST][0] ->
Fill(nFlowTot);
477 m_hNumCstAccept[CST_TYPE::FLOW_CST][1] ->
Fill(nFlowAcc);
478 m_hSumCstEne[CST_TYPE::FLOW_CST] ->
Fill(eFlowSum);
489 cout <<
"SCorrelatorJetTree::AddECal(PHCompositeNode*, vector<PseudoJet>&, map<int, pair<Jet::SRC, int>>&) Adding ECal clusters..." << endl;
493 if (m_doDebug && (m_jetType != 1)) {
494 cerr <<
"SCorrelatorJetTree::AddECal - Warning - trying to add calorimeter clusters to charged jets!" << endl;
502 unsigned int iCst = particles.size();
503 unsigned int nClustTot = 0;
504 unsigned int nClustAcc = 0;
505 unsigned int nClustEM = 0;
506 double eClustSum = 0.;
511 for (itEMClust = emClustRange.first; itEMClust != emClustRange.second; ++itEMClust) {
514 const RawCluster* emClust = itEMClust -> second;
522 const double vX = vtx -> get_x();
523 const double vY = vtx -> get_y();
524 const double vZ = vtx -> get_z();
526 CLHEP::Hep3Vector hepVecVtx = CLHEP::Hep3Vector(vX, vY, vZ);
530 const bool isGoodECal = IsGoodECal(hepVecEMClust);
538 const int emClustID = emClust -> get_id();
539 const double emClustE = hepVecEMClust.mag();
540 const double emClustPt = hepVecEMClust.perp();
541 const double emClustPhi = hepVecEMClust.getPhi();
542 const double emClustPx = emClustPt * cos(emClustPhi);
543 const double emClustPy = emClustPt * sin(emClustPhi);
544 const double emClustPz = sqrt((emClustE * emClustE) - (emClustPx * emClustPx) - (emClustPy * emClustPy));
546 fastjet::PseudoJet fjCluster(emClustPx, emClustPy, emClustPz, emClustE);
547 fjCluster.set_user_index(iCst);
548 particles.push_back(fjCluster);
552 fjMap.insert(jetEMClustPair);
555 m_hObjectQA[OBJECT::ECLUST][
INFO::PT] ->
Fill(fjCluster.perp());
556 m_hObjectQA[OBJECT::ECLUST][INFO::ETA] ->
Fill(fjCluster.pseudorapidity());
557 m_hObjectQA[OBJECT::ECLUST][INFO::PHI] ->
Fill(fjCluster.phi_std());
558 m_hObjectQA[OBJECT::ECLUST][INFO::ENE] ->
Fill(fjCluster.E());
559 eClustSum += emClustE;
565 m_hNumObject[OBJECT::ECLUST] ->
Fill(nClustEM);
566 m_hNumCstAccept[CST_TYPE::ECAL_CST][0] ->
Fill(nClustTot);
567 m_hNumCstAccept[CST_TYPE::ECAL_CST][1] ->
Fill(nClustAcc);
568 m_hSumCstEne[CST_TYPE::ECAL_CST] ->
Fill(eClustSum);
579 cout <<
"SCorrelatorJetTree::AddHCal(PHCompositeNode*, vector<PseudoJet>&, map<int, pair<Jet::SRC, int>>&) Adding HCal clusters..." << endl;
583 if (m_doDebug && (m_jetType != 1)) {
584 cerr <<
"SCorrelatorJetTree::AddHCal - Warning - trying to add calorimeter clusters to charged jets!" << endl;
593 unsigned int iCst = particles.size();
594 unsigned int nClustTot = 0;
595 unsigned int nClustAcc = 0;
596 unsigned int nClustH = 0;
597 double eClustSum = 0.;
602 for (itIHClust = ihClustRange.first; itIHClust != ihClustRange.second; ++itIHClust) {
605 const RawCluster* ihClust = itIHClust -> second;
613 const double vX = vtx -> get_x();
614 const double vY = vtx -> get_y();
615 const double vZ = vtx -> get_z();
617 CLHEP::Hep3Vector hepVecVtx = CLHEP::Hep3Vector(vX, vY, vZ);
621 const bool isGoodHCal = IsGoodHCal(hepVecIHClust);
629 const int ihClustID = ihClust -> get_id();
630 const double ihClustE = hepVecIHClust.mag();
631 const double ihClustPt = hepVecIHClust.perp();
632 const double ihClustPhi = hepVecIHClust.getPhi();
633 const double ihClustPx = ihClustPt * cos(ihClustPhi);
634 const double ihClustPy = ihClustPt * sin(ihClustPhi);
635 const double ihClustPz = sqrt((ihClustE * ihClustE) - (ihClustPx * ihClustPx) - (ihClustPy * ihClustPy));
637 fastjet::PseudoJet fjCluster(ihClustPx, ihClustPy, ihClustPz, ihClustE);
638 fjCluster.set_user_index(iCst);
639 particles.push_back(fjCluster);
643 fjMap.insert(jetIHClustPair);
646 m_hObjectQA[OBJECT::HCLUST][
INFO::PT] ->
Fill(fjCluster.perp());
647 m_hObjectQA[OBJECT::HCLUST][INFO::ETA] ->
Fill(fjCluster.pseudorapidity());
648 m_hObjectQA[OBJECT::HCLUST][INFO::PHI] ->
Fill(fjCluster.phi_std());
649 m_hObjectQA[OBJECT::HCLUST][INFO::ENE] ->
Fill(fjCluster.E());
650 eClustSum += ihClustE;
658 for (itOHClust = ohClustRange.first; itOHClust != ohClustRange.second; ++itOHClust) {
661 const RawCluster* ohClust = itOHClust -> second;
669 const double vX = vtx -> get_x();
670 const double vY = vtx -> get_y();
671 const double vZ = vtx -> get_z();
673 CLHEP::Hep3Vector hepVecVtx = CLHEP::Hep3Vector(vX, vY, vZ);
677 const bool isGoodHCal = IsGoodHCal(hepVecOHClust);
685 const int ohClustID = ohClust -> get_id();
686 const double ohClustE = hepVecOHClust.mag();
687 const double ohClustPt = hepVecOHClust.perp();
688 const double ohClustPhi = hepVecOHClust.getPhi();
689 const double ohClustPx = ohClustPt * cos(ohClustPhi);
690 const double ohClustPy = ohClustPt * sin(ohClustPhi);
691 const double ohClustPz = sqrt((ohClustE * ohClustE) - (ohClustPx * ohClustPx) - (ohClustPy * ohClustPy));
693 fastjet::PseudoJet fjCluster(ohClustPx, ohClustPy, ohClustPz, ohClustE);
694 fjCluster.set_user_index(iCst);
695 particles.push_back(fjCluster);
699 fjMap.insert(jetOHClustPair);
702 m_hObjectQA[OBJECT::HCLUST][
INFO::PT] ->
Fill(fjCluster.perp());
703 m_hObjectQA[OBJECT::HCLUST][INFO::ETA] ->
Fill(fjCluster.pseudorapidity());
704 m_hObjectQA[OBJECT::HCLUST][INFO::PHI] ->
Fill(fjCluster.phi_std());
705 m_hObjectQA[OBJECT::HCLUST][INFO::ENE] ->
Fill(fjCluster.E());
706 eClustSum += ohClustE;
712 m_hNumObject[OBJECT::HCLUST] ->
Fill(nClustH);
713 m_hSumCstEne[CST_TYPE::HCAL_CST] ->
Fill(eClustSum);
714 m_hNumCstAccept[CST_TYPE::HCAL_CST][0] ->
Fill(nClustTot);
715 m_hNumCstAccept[CST_TYPE::HCAL_CST][1] ->
Fill(nClustAcc);