4 #include <calobase/RawCluster.h>
5 #include <calobase/RawClusterContainer.h>
6 #include <calobase/RawClusterUtility.h>
28 #include <particleflowreco/ParticleFlowElement.h>
29 #include <particleflowreco/ParticleFlowElementContainer.h>
38 #include <kfparticle_sphenix/KFParticle_Container.h>
42 #include <fastjet/ClusterSequence.hh>
43 #include <fastjet/FunctionOfPseudoJet.hh>
44 #include <fastjet/JetDefinition.hh>
46 #pragma GCC diagnostic push
47 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
48 #include <HepMC/GenEvent.h>
49 #include <HepMC/GenVertex.h>
50 #pragma GCC diagnostic pop
53 #include <TDatabasePDG.h>
81 , m_particleflow_mineta(-1.1)
82 , m_particleflow_maxeta(1.1)
84 , m_track_maxpt(9999.)
85 , m_track_mineta(-1.1)
87 , m_EMCal_cluster_minpt(0.)
88 , m_EMCal_cluster_maxpt(9999.)
89 , m_EMCal_cluster_mineta(-1.1)
90 , m_EMCal_cluster_maxeta(1.1)
91 , m_HCal_cluster_minpt(0.)
92 , m_HCal_cluster_maxpt(9999.)
93 , m_HCal_cluster_mineta(-1.1)
94 , m_HCal_cluster_maxeta(1.1)
95 , m_add_particleflow(
true)
97 , m_add_EMCal_clusters(
false)
98 , m_add_HCal_clusters(
false)
105 , m_tag_particle(tag)
106 , m_KFparticle_name(KFparticle_Container_name)
109 case ResonanceJetTagging::TAG::D0:
113 case ResonanceJetTagging::TAG::D0TOK3PI:
117 case ResonanceJetTagging::TAG::DPLUS:
121 case ResonanceJetTagging::TAG::DSTAR:
125 case ResonanceJetTagging::TAG::JPSY:
129 case ResonanceJetTagging::TAG::K0:
133 case ResonanceJetTagging::TAG::GAMMA:
137 case ResonanceJetTagging::TAG::ELECTRON:
141 case ResonanceJetTagging::TAG::LAMBDAC:
164 std::cout <<
"Beginning Init in ResonanceJetTagging" << std::endl;
180 std::cout<<
"ERROR: Number of Decay Daughters Not Set, ABORTING!";
185 case ResonanceJetTagging::TAG::D0:
187 case ResonanceJetTagging::TAG::D0TOK3PI:
189 case ResonanceJetTagging::TAG::DPLUS:
191 case ResonanceJetTagging::TAG::LAMBDAC:
195 std::cout<<
"ERROR: Tag Function Not Set, ABORTING!";
211 std::cout <<
"Finished ResonanceJetTagging analysis package" << std::endl;
231 for (
unsigned int i = 0;
i < kfContainer->
size();
i++)
233 TagCand = kfContainer->
get(
i);
238 TagDaughters.at(idau) = kfContainer->
get(
i + idau + 1);
240 Daughters.at(idau)->set_px(TagDaughters.at(idau)->Px());
241 Daughters.at(idau)->set_py(TagDaughters.at(idau)->Py());
242 Daughters.at(idau)->set_pz(TagDaughters.at(idau)->Pz());
245 Daughters.at(idau)->set_barcode(TagDaughters.at(idau)->Id());
251 Cand->
set_e(TagCand->
E());
258 for (
long unsigned int idau = 0; idau < Daughters.size(); idau++)
delete Daughters.at(idau);
278 std::vector<fastjet::PseudoJet>
particles;
280 std::map<int, std::pair<Jet::SRC, int>> fjMap;
283 fjTag.set_user_index(0);
284 particles.push_back(fjTag);
285 fjMap.insert(std::pair<
int, std::pair<Jet::SRC, int>>(0, std::make_pair(Jet::SRC::VOID, Tag->
get_barcode())));
294 addTracks(topNode, particles, TagDecays, fjMap);
302 fastjet::ClusterSequence jetFinder(particles, *jetdef);
303 std::vector<fastjet::PseudoJet> fastjets = jetFinder.inclusive_jets();
307 for (
auto &fastjet : fastjets)
309 bool isTaggedJet =
false;
310 std::vector<fastjet::PseudoJet> comps = fastjet.constituents();
311 for (
auto &
comp : comps)
314 if (
comp.user_index() == 0)
316 taggedJet->
set_px(fastjet.px());
317 taggedJet->
set_py(fastjet.py());
318 taggedJet->
set_pz(fastjet.pz());
319 taggedJet->
set_e(fastjet.e());
344 <<
"ParticleFlowElements node is missing, can't collect particles"
351 std::vector<RawCluster *> pfEMCalClusters;
352 std::vector<RawCluster *> pfHCalClusters;
354 int idpart = particles.size();
358 for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
375 if (track &&
isDecay(track, TagDecays))
382 fjPartFlow.set_user_index(idpart);
383 particles.push_back(fjPartFlow);
384 fjMap.insert(std::pair<
int, std::pair<Jet::SRC, int>>(idpart, std::make_pair(Jet::SRC::PARTICLE, pflow->
get_id())));
401 SvtxTrackMap *trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
406 <<
"SvtxTrackMap node is missing, can't collect tracks"
411 int idpart = particles.size();
415 for (
auto &iter : *trackmap)
431 fjTrack.set_user_index(idpart);
432 particles.push_back(fjTrack);
433 fjMap.insert(std::pair<
int, std::pair<Jet::SRC, int>>(idpart, std::make_pair(Jet::SRC::TRACK, track->
get_id())));
454 GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode,
"GlobalVertexMap");
457 std::cout <<
"ResonanceJetTagging::getEmcalClusters - Fatal Error - GlobalVertexMap node is missing. Please turn on the do_global flag in the main macro in order to reconstruct the global vertex." << std::endl;
463 if (vertexmap->
empty())
465 std::cout <<
"ResonanceJetTagging::getEmcalClusters - Fatal Error - GlobalVertexMap node is empty. Please turn on the do_global flag in the main macro in order to reconstruct the global vertex." << std::endl;
476 int idpart = particles.size();
481 RawClusterContainer *clustersEMC = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_CEMC");
486 <<
"EMCal cluster node is missing, can't collect EMCal clusters"
495 for (clusIter_EMC = begin_end_EMC.first;
496 clusIter_EMC != begin_end_EMC.second;
499 const RawCluster *cluster = clusIter_EMC->second;
509 double cluster_e = E_vec_cluster.mag();
511 double cluster_pt = E_vec_cluster.perp();
513 double cluster_phi = E_vec_cluster.getPhi();
515 double cluster_px = cluster_pt * cos(cluster_phi);
516 double cluster_py = cluster_pt * sin(cluster_phi);
517 double cluster_pz = sqrt(cluster_e * cluster_e - cluster_px * cluster_px - cluster_py * cluster_py);
519 fastjet::PseudoJet fjCluster(cluster_px, cluster_py, cluster_pz, cluster_e);
521 fjCluster.set_user_index(idpart);
522 particles.push_back(fjCluster);
531 RawClusterContainer *clustersHCALIN = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_HCALIN");
536 <<
"EMCal cluster node is missing, can't collect EMCal clusters"
545 for (clusIter_HCALIN = begin_end_HCALIN.first;
546 clusIter_HCALIN != begin_end_HCALIN.second;
550 const RawCluster *cluster = clusIter_HCALIN->second;
560 double cluster_e = E_vec_cluster.mag();
561 double cluster_pt = E_vec_cluster.perp();
562 double cluster_phi = E_vec_cluster.getPhi();
564 double cluster_px = cluster_pt * cos(cluster_phi);
565 double cluster_py = cluster_pt * sin(cluster_phi);
566 double cluster_pz = sqrt(cluster_e * cluster_e - cluster_px * cluster_px - cluster_py * cluster_py);
568 fastjet::PseudoJet fjCluster(cluster_px, cluster_py, cluster_pz, cluster_e);
570 fjCluster.set_user_index(idpart);
571 particles.push_back(fjCluster);
575 RawClusterContainer *clustersHCALOUT = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_HCALOUT");
577 if (!clustersHCALOUT)
580 <<
"EMCal cluster node is missing, can't collect EMCal clusters"
589 for (clusIter_HCALOUT = begin_end_HCALOUT.first;
590 clusIter_HCALOUT != begin_end_HCALOUT.second;
594 const RawCluster *cluster = clusIter_HCALOUT->second;
608 double cluster_e = E_vec_cluster.mag();
609 double cluster_pt = E_vec_cluster.perp();
610 double cluster_phi = E_vec_cluster.getPhi();
612 double cluster_px = cluster_pt * cos(cluster_phi);
613 double cluster_py = cluster_pt * sin(cluster_phi);
614 double cluster_pz = sqrt(cluster_e * cluster_e - cluster_px * cluster_px - cluster_py * cluster_py);
616 fastjet::PseudoJet fjCluster(cluster_px, cluster_py, cluster_pz, cluster_e);
618 fjCluster.set_user_index(idpart);
619 particles.push_back(fjCluster);
656 for (
long unsigned int idecay = 0; idecay < decays.size(); idecay++)
658 if(
int(track->
get_id()) == decays.at(idecay)->get_barcode())
668 for (
long unsigned int idecay = 0; idecay < decays.size(); idecay++)
670 if (particle->barcode() == decays.at(idecay)->get_barcode())
680 PHHepMCGenEventMap *hepmceventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
685 <<
"HEPMC event map node is missing, can't collected HEPMC truth particles"
697 HepMC::GenEvent *hepMCGenEvent = hepmcevent->
getEvent();
704 TDatabasePDG *database = TDatabasePDG::Instance();
705 TParticlePDG *partPDG =
nullptr;
709 m_truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
715 for (HepMC::GenEvent::particle_const_iterator tag = hepMCGenEvent->particles_begin(); tag != hepMCGenEvent->particles_end(); ++tag)
722 if (std::abs((*tag)->pdg_id()) ==
m_tag_pdg)
724 std::vector<int> decayIDs;
726 HepMC::GenVertex *TagVertex = (*tag)->end_vertex();
729 for (HepMC::GenVertex::particle_iterator
it = TagVertex->particles_begin(HepMC::descendants);
it != TagVertex->particles_end(HepMC::descendants); ++
it)
731 decayIDs.push_back((*it)->barcode());
744 if (mother->
get_barcode() == (*tag)->barcode() && mother->
get_pid() == (*tag)->pdg_id())
751 std::map<int, std::pair<Jet::SRC, int>> fjMapMC;
753 std::vector<fastjet::PseudoJet>
particles;
754 fastjet::PseudoJet fjMCParticle((*tag)->momentum().px(), (*tag)->momentum().py(), (*tag)->momentum().pz(), (*tag)->momentum().e());
755 fjMapMC.insert(std::pair<
int, std::pair<Jet::SRC, int>>(0, std::make_pair(Jet::SRC::VOID, (*tag)->barcode())));
756 fjMCParticle.set_user_index(0);
757 particles.push_back(fjMCParticle);
759 int idpart = particles.size();
761 for (HepMC::GenEvent::particle_const_iterator
p = hepMCGenEvent->particles_begin();
p != hepMCGenEvent->particles_end(); ++
p)
767 if ((*p)->status() > 1)
771 if (std::abs((*p)->pdg_id()) ==
m_tag_pdg)
776 partPDG = database->GetParticle((*p)->pdg_id());
777 double hepmcPartPt = std::sqrt(((*p)->momentum().px() * (*p)->momentum().px()) + ((*p)->momentum().py() * (*p)->momentum().py()));
779 if (partPDG->Charge() != 0)
793 bool isTagDecay =
false;
794 for (
auto mcid : decayIDs)
796 if (mcid == (*p)->barcode())
806 fastjet::PseudoJet fjMCParticle2((*p)->momentum().px(), (*p)->momentum().py(), (*p)->momentum().pz(), (*p)->momentum().e());
807 fjMapMC.insert(std::pair<
int, std::pair<Jet::SRC, int>>(idpart, std::make_pair(Jet::SRC::PARTICLE, (*p)->barcode())));
808 fjMCParticle2.set_user_index(idpart);
809 particles.push_back(fjMCParticle2);
815 fastjet::ClusterSequence jetFinder(particles, *jetdef);
816 std::vector<fastjet::PseudoJet> mcfastjets = jetFinder.inclusive_jets();
820 for (
auto &mcfastjet : mcfastjets)
822 bool isTaggedJet =
false;
823 std::vector<fastjet::PseudoJet> comps = mcfastjet.constituents();
824 for (
auto &
comp : comps)
826 mcTaggedJet->
insert_comp(fjMapMC[
comp.user_index()].first, fjMapMC[
comp.user_index()].second);
827 if (
comp.user_index() == 0)
829 mcTaggedJet->
set_px(mcfastjet.px());
830 mcTaggedJet->
set_py(mcfastjet.py());
831 mcTaggedJet->
set_pz(mcfastjet.pz());
832 mcTaggedJet->
set_e(mcfastjet.e());
833 mcTaggedJet->
set_id(m_truth_jet_id);
862 std::cout <<
"DST node added" << std::endl;
871 baseName =
"taggedJet";
881 std::map<std::string, std::string> forbiddenStrings;
882 forbiddenStrings[
"/"] = undrscr;
883 forbiddenStrings[
"("] = undrscr;
884 forbiddenStrings[
")"] = nothing;
885 forbiddenStrings[
"+"] =
"plus";
886 forbiddenStrings[
"-"] =
"minus";
887 forbiddenStrings[
"*"] =
"star";
888 for (
auto const &[badString, goodString] : forbiddenStrings)
891 while ((pos = baseName.find(badString)) != std::string::npos)
893 baseName.replace(pos, 1, goodString);
897 jetNodeName = baseName +
"_Jet_Container";
898 jetNodeNameMC = baseName +
"_Truth_Jet_Container";
903 std::cout << jetNodeName <<
" node added" << std::endl;
908 std::cout << jetNodeNameMC <<
" node added" << std::endl;