6 , m_triggerOnDecay(
false)
7 , m_input_track_map_node_name(
"SvtxTrackMap")
8 , m_output_track_map_node_name(
"HFSelected")
9 , m_write_track_map(
false)
13 , m_write_nTuple(
false)
14 , m_truthRecoMatchPercent(5.)
36 std::cout <<
"DST node added" << std::endl;
42 dstNode->
addNode(outputTrackNode);
57 m_decayMap = findNode::getClass<DecayFinderContainer_v1>(topNode, df_node_name.c_str());
60 std::cout << __FILE__ <<
": Missing node " << df_node_name << std::endl;
71 m_geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
74 std::cout << __FILE__ <<
": Missing node PHHepMCGenEventMap" << std::endl;
77 m_truthInfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
82 std::cout << __FILE__ <<
": Missing node G4TruthInfo" << std::endl;
86 m_dst_truth_reco_map = findNode::getClass<PHG4ParticleSvtxMap_v1>(topNode,
"PHG4ParticleSvtxMap");
91 std::cout << __FILE__ <<
": PHG4ParticleSvtxMap found, truth matching will be more accurate" << std::endl;
98 std::cout << __FILE__ <<
": PHG4ParticleSvtxMap not found, reverting to true matching by momentum relations. Truth matching will be less accurate" << std::endl;
108 bool reconstructableDecay =
false;
111 Decay decay = iter.second;
118 reconstructableDecay =
true;
136 std::cout <<
"No decays were reconstructable in this event, skipping" << std::endl;
162 int trackableParticles[] = {11, 13, 211, 321, 2212};
163 bool recoTrackFound =
false;
164 std::set<SvtxTrack *> selectedTracks;
166 CLHEP::HepLorentzVector motherRecoLV;
167 CLHEP::HepLorentzVector daughterSumTrueLV;
168 CLHEP::HepLorentzVector *motherTrueLV =
new CLHEP::HepLorentzVector();
169 CLHEP::HepLorentzVector *daughterTrueLV =
new CLHEP::HepLorentzVector();
171 HepMC::GenEvent *theEvent =
nullptr;
178 HepMC::GenParticle *mother = theEvent->barcode_to_particle(decay[0].first.second);
186 m_true_mother_p = std::sqrt(std::pow(mother->momentum().px(), 2) + std::pow(mother->momentum().py(), 2) + std::pow(mother->momentum().pz(), 2));
189 HepMC::GenVertex *thisVtx = mother->production_vertex();
195 for (
unsigned int i = 1;
i < decay.size(); ++
i)
200 std::abs(decay[
i].second)) !=
std::end(trackableParticles))
202 if (theEvent && decay[
i].first.second > -1)
204 HepMC::GenParticle *daughterHepMC = theEvent->barcode_to_particle(decay[
i].first.second);
207 daughterHepMC->print();
210 daughterTrueLV->setVectM(CLHEP::Hep3Vector(daughterHepMC->momentum().px(), daughterHepMC->momentum().py(), daughterHepMC->momentum().pz()),
getParticleMass(decay[i].second));
211 daughterSumTrueLV += *daughterTrueLV;
216 HepMC::GenVertex *thisVtx = daughterHepMC->production_vertex();
230 if (abs(daughterG4->
get_px() - daughterTrueLV->x()) <= 5
e-3 &&
231 abs(daughterG4->
get_py() - daughterTrueLV->y()) <= 5
e-3 &&
232 abs(daughterG4->
get_pz() - daughterTrueLV->z()) <= 5
e-3 && daughterG4->
get_pid() == decay[
i].second)
258 if (motherG4->
get_pid() == decay[0].second && motherG4->
get_barcode() == decay[0].first.second && daughterG4->
get_pid() == decay[
i].second && daughterG4->
get_barcode() == decay[
i].first.second)
265 CLHEP::Hep3Vector *mother3Vector =
new CLHEP::Hep3Vector(motherG4->
get_px(), motherG4->
get_py(), motherG4->
get_pz());
266 motherTrueLV->setVectM((*mother3Vector),
getParticleMass(decay[0].second));
277 daughterSumTrueLV += *daughterTrueLV;
288 delete mother3Vector;
301 if (reco_set.size() == 0)
305 const auto &best_weight = reco_set.rbegin();
306 if (best_weight->second.size() == 0)
310 unsigned int best_reco_id = *best_weight->second.rbegin();
315 recoTrackFound =
true;
323 float delta_px = (
m_dst_track->
get_px() - daughterTrueLV->px()) / daughterTrueLV->px();
324 float delta_py = (
m_dst_track->
get_py() - daughterTrueLV->py()) / daughterTrueLV->py();
325 float delta_pz = (
m_dst_track->
get_pz() - daughterTrueLV->pz()) / daughterTrueLV->pz();
329 recoTrackFound =
true;
358 CLHEP::HepLorentzVector *daughterRecoLV =
new CLHEP::HepLorentzVector();
361 motherRecoLV += *daughterRecoLV;
362 delete daughterRecoLV;
365 recoTrackFound =
false;
370 bool foundDecay =
true;
377 for (
auto &track : selectedTracks)
388 selectedTracks.clear();
391 delete daughterTrueLV;
399 m_tree =
new TTree(
"HFTrackEfficiency",
"HFTrackEfficiency");
400 m_tree->OptimizeBaskets();
401 m_tree->SetAutoSave(-5e6);
414 for (
unsigned int iTrack = 0; iTrack <
m_nDaughters; ++iTrack)
417 m_tree->Branch(
"reco_" + TString(daughter_number) +
"_exists", &
m_reco_track_exists[iTrack],
"reco_" + TString(daughter_number) +
"_exists/O");
418 m_tree->Branch(
"reco_" + TString(daughter_number) +
"_used_truth_reco_map", &
m_used_truth_reco_map[iTrack],
"reco_" + TString(daughter_number) +
"_used_truth_reco_map/O");
419 m_tree->Branch(
"true_" + TString(daughter_number) +
"_pT", &
m_true_track_pT[iTrack],
"true_" + TString(daughter_number) +
"_pT/F");
420 m_tree->Branch(
"reco_" + TString(daughter_number) +
"_pT", &
m_reco_track_pT[iTrack],
"reco_" + TString(daughter_number) +
"_pT/F");
421 m_tree->Branch(
"true_" + TString(daughter_number) +
"_eta", &
m_true_track_eta[iTrack],
"true_" + TString(daughter_number) +
"_eta/F");
422 m_tree->Branch(
"reco_" + TString(daughter_number) +
"_eta", &
m_reco_track_eta[iTrack],
"reco_" + TString(daughter_number) +
"_eta/F");
423 m_tree->Branch(
"true_" + TString(daughter_number) +
"_PID", &
m_true_track_PID[iTrack],
"true_" + TString(daughter_number) +
"_PID/F");
424 m_tree->Branch(
"reco_" + TString(daughter_number) +
"_chi2nDoF", &
m_reco_track_chi2nDoF[iTrack],
"reco_" + TString(daughter_number) +
"_chi2nDoF/F");
425 m_tree->Branch(
"reco_" + TString(daughter_number) +
"_silicon_seeds", &
m_reco_track_silicon_seeds[iTrack],
"reco_" + TString(daughter_number) +
"_silicon_seeds/I");
426 m_tree->Branch(
"reco_" + TString(daughter_number) +
"_tpc_seeds", &
m_reco_track_tpc_seeds[iTrack],
"reco_" + TString(daughter_number) +
"_tpc_seeds/I");
429 m_tree->Branch(
"true_primary_vertex_x", &
m_primary_vtx_x,
"true_primary_vertex_x/F");
430 m_tree->Branch(
"true_primary_vertex_y", &
m_primary_vtx_y,
"true_primary_vertex_y/F");
431 m_tree->Branch(
"true_primary_vertex_z", &
m_primary_vtx_z,
"true_primary_vertex_z/F");
432 m_tree->Branch(
"true_secondary_vertex_x", &
m_secondary_vtx_x,
"true_secondary_vertex_x/F");
433 m_tree->Branch(
"true_secondary_vertex_y", &
m_secondary_vtx_y,
"true_secondary_vertex_y/F");
434 m_tree->Branch(
"true_secondary_vertex_z", &
m_secondary_vtx_z,
"true_secondary_vertex_z/F");
449 for (
unsigned int iTrack = 0; iTrack <
m_nDaughters; ++iTrack)
476 for (
unsigned int i = 1;
i < decay.size(); ++
i)
485 int trackableParticles[] = {11, 13, 211, 321, 2212};
488 for (
unsigned int i = 1;
i < decay.size(); ++
i)
491 std::abs(decay[
i].second)) !=
std::end(trackableParticles))
500 return TDatabasePDG::Instance()->GetParticle(PDGID)->GetName();
505 return TDatabasePDG::Instance()->GetParticle(PDGID)->Mass();
511 std::cout <<
"\n--------------- Heavy Flavor Tracking Efficiency ---------------" << std::endl;
516 std::cout <<
"----------------------------------------------------------------\n"