39 #pragma GCC diagnostic push
40 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
41 #include <HepMC/GenEvent.h>
42 #include <HepMC/GenVertex.h>
43 #pragma GCC diagnostic pop
45 #include <HepMC/GenParticle.h>
46 #include <HepMC/IteratorRange.h>
47 #include <HepMC/SimpleVector.h>
60 std::map<std::string, int>
Use =
70 : m_svtx_evalstack(nullptr)
80 for (
auto &iter : *trackmap)
82 if (iter.first == track_id)
84 matched_track = iter.second;
95 return matched_vertex;
115 m_truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
119 std::cout <<
"KFParticle truth matching: G4TruthInfo does not exist" << std::endl;
122 SvtxPHG4ParticleMap_v1 *dst_reco_truth_map = findNode::getClass<SvtxPHG4ParticleMap_v1>(topNode,
"SvtxPHG4ParticleMap");
124 std::map<float, std::set<int>> truth_set = dst_reco_truth_map->
get(thisTrack->
get_id());
125 const auto &best_weight = truth_set.rbegin();
126 int best_truth_id = *best_weight->second.rbegin();
131 std::cout << __FILE__ <<
": SvtxPHG4ParticleMap not found, reverting to max_truth_particle_by_nclusters()" << std::endl;
152 m_tree->Branch(TString(daughter_number) +
"_true_ID", &
m_true_daughter_id[daughter_id], TString(daughter_number) +
"_true_ID/I");
153 if (m_constrain_to_vertex_truthMatch)
155 m_tree->Branch(TString(daughter_number) +
"_true_IP", &
m_true_daughter_ip[daughter_id], TString(daughter_number) +
"_true_IP/F");
156 m_tree->Branch(TString(daughter_number) +
"_true_IP_xy", &
m_true_daughter_ip_xy[daughter_id], TString(daughter_number) +
"_true_IP_xy/F");
158 m_tree->Branch(TString(daughter_number) +
"_true_px", &
m_true_daughter_px[daughter_id], TString(daughter_number) +
"_true_px/F");
159 m_tree->Branch(TString(daughter_number) +
"_true_py", &
m_true_daughter_py[daughter_id], TString(daughter_number) +
"_true_py/F");
160 m_tree->Branch(TString(daughter_number) +
"_true_pz", &
m_true_daughter_pz[daughter_id], TString(daughter_number) +
"_true_pz/F");
161 m_tree->Branch(TString(daughter_number) +
"_true_p", &
m_true_daughter_p[daughter_id], TString(daughter_number) +
"_true_p/F");
162 m_tree->Branch(TString(daughter_number) +
"_true_pT", &
m_true_daughter_pt[daughter_id], TString(daughter_number) +
"_true_pT/F");
163 m_tree->Branch(TString(daughter_number) +
"_true_EV_x", &
m_true_daughter_vertex_x[daughter_id], TString(daughter_number) +
"_true_EV_x/F");
164 m_tree->Branch(TString(daughter_number) +
"_true_EV_y", &
m_true_daughter_vertex_y[daughter_id], TString(daughter_number) +
"_true_EV_y/F");
165 m_tree->Branch(TString(daughter_number) +
"_true_EV_z", &
m_true_daughter_vertex_z[daughter_id], TString(daughter_number) +
"_true_EV_z/F");
166 if (m_constrain_to_vertex_truthMatch)
168 m_tree->Branch(TString(daughter_number) +
"_true_PV_x", &
m_true_daughter_pv_x[daughter_id], TString(daughter_number) +
"_true_PV_x/F");
169 m_tree->Branch(TString(daughter_number) +
"_true_PV_y", &
m_true_daughter_pv_y[daughter_id], TString(daughter_number) +
"_true_PV_y/F");
170 m_tree->Branch(TString(daughter_number) +
"_true_PV_z", &
m_true_daughter_pv_z[daughter_id], TString(daughter_number) +
"_true_PV_z/F");
183 float true_px, true_py, true_pz, true_p, true_pt;
204 auto globalvertexmap = findNode::getClass<GlobalVertexMap>(topNode,
"GlobalVertexMap");
205 if (!globalvertexmap)
207 std::cout <<
"KFParticle truth matching: GlobalVertexMap does not exist" << std::endl;
212 bool isParticleValid = g4particle ==
nullptr ?
false :
true;
214 true_px = isParticleValid ? (Float_t) g4particle->get_px() : 0.;
215 true_py = isParticleValid ? (Float_t) g4particle->get_py() : 0.;
216 true_pz = isParticleValid ? (Float_t) g4particle->get_pz() : 0.;
217 true_p = sqrt(pow(true_px, 2) + pow(true_py, 2) + pow(true_pz, 2));
218 true_pt = sqrt(pow(true_px, 2) + pow(true_py, 2));
246 if (m_constrain_to_vertex_truthMatch)
254 std::cout <<
"Have a global vertex with no track vertex... shouldn't happen in KFParticle_truthAndDetTools::fillTruthBranch..." << std::endl;
257 auto svtxvertexvector = svtxviter->second;
260 for (
auto &
vertex : svtxvertexvector)
267 if (truePoint ==
nullptr)
275 float f_vertexParameters[6] = {0};
277 if (truePoint ==
nullptr)
279 std::cout <<
"KFParticle truth matching: This event has no PHG4VtxPoint information!\n";
280 std::cout <<
"Your truth track DCA will be measured wrt a reconstructed vertex!" << std::endl;
282 f_vertexParameters[0] = recoVertex->
get_x();
283 f_vertexParameters[1] = recoVertex->
get_y();
284 f_vertexParameters[2] = recoVertex->
get_z();
288 f_vertexParameters[0] = truePoint->
get_x();
289 f_vertexParameters[1] = truePoint->
get_y();
290 f_vertexParameters[2] = truePoint->
get_z();
293 float f_vertexCovariance[21] = {0};
295 trueKFParticleVertex.
Create(f_vertexParameters, f_vertexCovariance, 0, -1);
306 float f_trackCovariance[21] = {0};
308 trueKFParticle.
Create(f_trackParameters, f_trackCovariance, 1, -1);
321 Float_t
pT = sqrt(pow(particle->
get_px(), 2) + pow(particle->
get_py(), 2));
334 const HepMC::FourVector &myFourVector = particle->momentum();
348 HepMC::GenParticle *dummyParticle =
new HepMC::GenParticle();
349 HepMC::FourVector dummyFourVector(0, 0, 0, 0);
350 dummyParticle->set_momentum(dummyFourVector);
351 dummyParticle->set_pdg_id(0);
352 dummyParticle->set_generated_mass(0.);
368 bool isParticleValid = g4particle ==
nullptr ?
false :
true;
370 if (!isParticleValid)
372 std::cout <<
"KFParticle truth matching: this track is a ghost" << std::endl;
377 m_geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
380 std::cout <<
"KFParticle truth matching: Missing node PHHepMCGenEventMap" << std::endl;
381 std::cout <<
"You will have no mother information" << std::endl;
389 std::cout <<
"KFParticle truth matching: Missing node PHHepMCGenEvent" << std::endl;
390 std::cout <<
"You will have no mother information" << std::endl;
398 if (g4particle->get_parent_id() != 0)
403 m_truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
407 std::cout <<
"KFParticle truth matching: G4TruthInfo does not exist" << std::endl;
409 while (g4particle->get_parent_id() != 0)
417 HepMC::GenParticle *prevParticle =
nullptr;
420 int forbiddenPDGIDs[] = {0};
422 for (HepMC::GenEvent::particle_const_iterator
p = theEvent->particles_begin();
p != theEvent->particles_end(); ++
p)
424 if (((*p)->barcode() == g4particle->get_barcode()))
427 while (!prevParticle->is_beam())
429 bool breakOut =
false;
430 for (HepMC::GenVertex::particle_iterator mother = prevParticle->production_vertex()->particles_begin(HepMC::parents);
431 mother != prevParticle->production_vertex()->particles_end(HepMC::parents); ++mother)
434 abs((*mother)->pdg_id())) !=
std::end(forbiddenPDGIDs))
441 prevParticle = *mother;
456 m_tree->Branch(TString(daughter_number) +
"_EMCAL_DeltaPhi", &
detector_emcal_deltaphi[daughter_id], TString(daughter_number) +
"_EMCAL_DeltaPhi/F");
457 m_tree->Branch(TString(daughter_number) +
"_EMCAL_DeltaEta", &
detector_emcal_deltaeta[daughter_id], TString(daughter_number) +
"_EMCAL_DeltaEta/F");
458 m_tree->Branch(TString(daughter_number) +
"_EMCAL_energy_3x3", &
detector_emcal_energy_3x3[daughter_id], TString(daughter_number) +
"_EMCAL_energy_3x3/F");
459 m_tree->Branch(TString(daughter_number) +
"_EMCAL_energy_5x5", &
detector_emcal_energy_5x5[daughter_id], TString(daughter_number) +
"_EMCAL_energy_5x5/F");
460 m_tree->Branch(TString(daughter_number) +
"_EMCAL_energy_cluster", &
detector_emcal_cluster_energy[daughter_id], TString(daughter_number) +
"_EMCAL_energy_cluster/F");
461 m_tree->Branch(TString(daughter_number) +
"_IHCAL_DeltaPhi", &
detector_ihcal_deltaphi[daughter_id], TString(daughter_number) +
"_IHCAL_DeltaPhi/F");
462 m_tree->Branch(TString(daughter_number) +
"_IHCAL_DeltaEta", &
detector_ihcal_deltaeta[daughter_id], TString(daughter_number) +
"_IHCAL_DeltaEta/F");
463 m_tree->Branch(TString(daughter_number) +
"_IHCAL_energy_3x3", &
detector_ihcal_energy_3x3[daughter_id], TString(daughter_number) +
"_IHCAL_energy_3x3/F");
464 m_tree->Branch(TString(daughter_number) +
"_IHCAL_energy_5x5", &
detector_ihcal_energy_5x5[daughter_id], TString(daughter_number) +
"_IHCAL_energy_5x5/F");
465 m_tree->Branch(TString(daughter_number) +
"_IHCAL_energy_cluster", &
detector_ihcal_cluster_energy[daughter_id], TString(daughter_number) +
"_IHCAL_energy_cluster/F");
466 m_tree->Branch(TString(daughter_number) +
"_OHCAL_DeltaPhi", &
detector_ohcal_deltaphi[daughter_id], TString(daughter_number) +
"_OHCAL_DeltaEta/F");
467 m_tree->Branch(TString(daughter_number) +
"_OHCAL_DeltaEta", &
detector_ohcal_deltaeta[daughter_id], TString(daughter_number) +
"_OHCAL_DeltaEta/F");
468 m_tree->Branch(TString(daughter_number) +
"_OHCAL_energy_3x3", &
detector_ohcal_energy_3x3[daughter_id], TString(daughter_number) +
"_OHCAL_energy_3x3/F");
469 m_tree->Branch(TString(daughter_number) +
"_OHCAL_energy_5x5", &
detector_ohcal_energy_5x5[daughter_id], TString(daughter_number) +
"_OHCAL_energy_5x5/F");
470 m_tree->Branch(TString(daughter_number) +
"_OHCAL_energy_cluster", &
detector_ohcal_cluster_energy[daughter_id], TString(daughter_number) +
"_OHCAL_energy_cluster/F");
474 TTree * ,
const KFParticle &daughter,
int daughter_id)
510 m_tree->Branch(TString(daughter_number) +
"_local_x", &
detector_local_x[daughter_id]);
511 m_tree->Branch(TString(daughter_number) +
"_local_y", &
detector_local_y[daughter_id]);
512 m_tree->Branch(TString(daughter_number) +
"_local_z", &
detector_local_z[daughter_id]);
513 m_tree->Branch(TString(daughter_number) +
"_layer", &
detector_layer[daughter_id]);
515 for (
auto const &subdetector : Use)
517 if (subdetector.second)
526 if (detectorName ==
"MVTX")
528 m_tree->Branch(TString(daughter_number) +
"_" + TString(detectorName) +
"_staveID", &
mvtx_staveID[daughter_id]);
529 m_tree->Branch(TString(daughter_number) +
"_" + TString(detectorName) +
"_chipID", &
mvtx_chipID[daughter_id]);
531 if (detectorName ==
"INTT")
533 m_tree->Branch(TString(daughter_number) +
"_" + TString(detectorName) +
"_ladderZID", &
intt_ladderZID[daughter_id]);
534 m_tree->Branch(TString(daughter_number) +
"_" + TString(detectorName) +
"_ladderPhiID", &
intt_ladderPhiID[daughter_id]);
536 if (detectorName ==
"TPC")
538 m_tree->Branch(TString(daughter_number) +
"_" + TString(detectorName) +
"_sectorID", &
tpc_sectorID[daughter_id]);
539 m_tree->Branch(TString(daughter_number) +
"_" + TString(detectorName) +
"_side", &
tpc_side[daughter_id]);
544 TTree * ,
const KFParticle &daughter,
int daughter_id)
561 dst_clustermap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
565 std::cout <<
"KFParticle detector info: TRKR_CLUSTER does not exist" << std::endl;
582 unsigned int staveId, chipId, ladderZId, ladderPhiId, sectorId, side;
583 staveId = chipId = ladderZId = ladderPhiId = sectorId = side = -99;
606 tpc_side[daughter_id].push_back(side);
613 std::vector<KFParticle> daughters,
614 std::vector<KFParticle> intermediates)
619 for (
auto &primaryVertice : primaryVertices)
621 allPV_x.push_back(primaryVertice.GetX());
622 allPV_y.push_back(primaryVertice.GetY());
623 allPV_z.push_back(primaryVertice.GetZ());
628 for (
unsigned int j = 0;
j < daughters.size(); ++
j)
634 for (
unsigned int j = 0;
j < intermediates.size(); ++
j)