4 #include <calobase/RawCluster.h>
5 #include <calobase/RawClusterContainer.h>
6 #include <calobase/RawClusterUtility.h>
7 #include <calobase/RawTower.h>
8 #include <calobase/RawTowerContainer.h>
9 #include <calobase/RawTowerGeom.h>
10 #include <calobase/RawTowerGeomContainer.h>
11 #include <calotrigger/CaloTriggerInfo.h>
18 #include <calobase/RawCluster.h>
19 #include <calobase/RawClusterContainer.h>
20 #include <calobase/RawTower.h>
21 #include <calobase/RawTowerContainer.h>
22 #include <calobase/RawTowerGeomContainer.h>
38 #include <HepMC/GenEvent.h>
39 #include <HepMC/GenVertex.h>
87 , m_outfilename(filename)
91 , m_analyzeTracks(
true)
92 , m_analyzeClusters(
true)
94 , m_analyzeTruth(
false)
116 cout <<
"Beginning Init in eIDMLInterface" << endl;
121 m_phi_h =
new TH1D(
"phi_h",
";Counts;#phi [rad]", 50, -6, 6);
122 m_eta_phi_h =
new TH2F(
"phi_eta_h",
";#eta;#phi [rad]", 10, -1, 1, 50, -6, 6);
135 cout <<
"Beginning process_event in eIDMLInterface" << endl;
140 SvtxTrackMap *trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"TrackMap");
145 <<
"PHG4TruthInfoContainer node is missing, can't collect G4 truth particles"
154 iter != range.second;
176 if (m_trutheta < m_etaRange.first or m_trutheta >
m_etaRange.second)
continue;
185 if (
Verbosity() > 1) cout << __PRETTY_FUNCTION__ <<
"TRACKmap size " << trackmap->size() << std::endl;
187 track_itr != trackmap->end();
196 std::cout <<
"PHG4TrackFastSimEval::fill_track_tree - ignore track that is not a SvtxTrack_FastSim:";
201 if (
Verbosity() > 1) cout << __PRETTY_FUNCTION__ <<
" PARTICLE!" << std::endl;
236 std::string detector(calo_name);
237 int detector_layer = -1;
240 if (calo_name.find(
"LFHCAL") == 0)
243 detector_layer = std::stoi(
245 calo_name.find(
"_") + 1));
247 static set<string> known_calo_name;
248 if (known_calo_name.find(calo_name) == known_calo_name.end())
250 known_calo_name.insert(calo_name);
252 cout << __PRETTY_FUNCTION__ <<
" : Found new LFHCAL " << calo_name <<
" which is parsed as "
253 <<
"detector = " << detector <<
", detector_layer = " << detector_layer << endl;
257 std::string towernodename =
"TOWER_CALIB_" + detector;
263 std::cout <<
PHWHERE <<
": Could not find node " << towernodename
267 std::string towergeomnodename =
"TOWERGEOM_" + detector;
269 topNode, towergeomnodename);
272 std::cout <<
PHWHERE <<
": Could not find node " << towergeomnodename
277 bool has_projection(
false);
283 if (
Verbosity() > 1) cout << __PRETTY_FUNCTION__ <<
" checking " << trkstates->second->get_name() << endl;
284 if (trkstates->second->get_name().compare(detector) == 0)
286 if (
Verbosity() > 1) cout << __PRETTY_FUNCTION__ <<
" found " << trkstates->second->get_name() << endl;
287 has_projection =
true;
290 for (
int i = 0; i < 3; i++)
292 m_CaloDataMap[calo_name].m_TTree_proj_vec[i] = trkstates->second->get_pos(i);
293 m_CaloDataMap[calo_name].m_TTree_proj_p_vec[i] = trkstates->second->get_mom(i);
296 m_CaloDataMap[calo_name].m_TTree_proj_vec[3] = trkstates->first;
303 TVector3 vec_proj(
m_CaloDataMap[calo_name].m_TTree_proj_vec[0],
307 const double eta_proj = vec_proj.Eta();
308 const double phi_proj = vec_proj.Phi();
310 double min_tower_r2 = 1000;
314 int minBinPhi = 10000;
319 titer != range.second;
326 if (detector_layer >= 0)
329 if (layer != detector_layer)
continue;
334 if (maxBinPhi < binphi) maxBinPhi = binphi;
335 if (minBinPhi > binphi) minBinPhi = binphi;
342 const double deta = eta_proj - vec_tower.Eta();
343 double dphi = phi_proj - vec_tower.Phi();
348 const double r2 = dphi * dphi + deta * deta;
350 if (r2 < min_tower_r2)
353 central_tower_key = titer->first;
354 central_tower = titer->second;
359 if (central_tower ==
nullptr)
continue;
360 if (central_tower_key < 0)
continue;
364 cout << __PRETTY_FUNCTION__ <<
" / " << calo_name <<
" found central tower " << central_tower_key <<
": ";
365 cout <<
" min_tower_r2 = " << min_tower_r2;
371 cout <<
" minBinPhi = " << minBinPhi;
372 cout <<
" maxBinPhi = " << maxBinPhi;
379 const int central_tower_eta = central_tower->
get_bineta();
380 const int central_tower_phi = central_tower->
get_binphi();
381 const int size_half_tower_patch = (
m_CaloDataMap[calo_name].m_sizeTowerPatch - 1) / 2;
382 size_t tower_index_patch = 0;
384 m_CaloDataMap[calo_name].m_centralTowerBinEta = central_tower_eta;
385 m_CaloDataMap[calo_name].m_centralTowerBinPhi = central_tower_phi;
387 for (
int ieta_patch = -size_half_tower_patch;
388 ieta_patch <= +size_half_tower_patch;
391 const int bin_eta = central_tower_eta + ieta_patch;
393 for (
int iphi_patch = -size_half_tower_patch;
394 iphi_patch <= +size_half_tower_patch;
397 assert(tower_index_patch <
m_CaloDataMap[calo_name].m_TTree_Tower_E.size());
399 int bin_phi = central_tower_phi + iphi_patch;
401 if (bin_phi < minBinPhi) bin_phi = bin_phi - minBinPhi + maxBinPhi + 1;
402 if (bin_phi > maxBinPhi) bin_phi = bin_phi - maxBinPhi + minBinPhi - 1;
404 m_CaloDataMap[calo_name].m_TTree_Tower_iEta_patch[tower_index_patch] = ieta_patch;
405 m_CaloDataMap[calo_name].m_TTree_Tower_iPhi_patch[tower_index_patch] = iphi_patch;
410 if (detector_layer == -1)
412 if (bin_eta >= 0xFFF or bin_phi >= 0xFFF or bin_eta < 0 or bin_phi < 0)
416 cout << __PRETTY_FUNCTION__ <<
" / " << calo_name <<
" invalid tower geom " << central_tower_key <<
": ";
417 cout <<
" bin_eta = " << bin_eta;
418 cout <<
" bin_phi = " << bin_phi;
419 cout <<
" central_tower_eta = " << central_tower_eta;
420 cout <<
" central_tower_phi = " << central_tower_phi;
421 cout <<
" central_tower_key = " << central_tower_key;
422 cout <<
" min_tower_r2 = " << min_tower_r2;
425 cout <<
" minBinPhi = " << minBinPhi;
426 cout <<
" maxBinPhi = " << maxBinPhi;
441 if (bin_eta >= 0x3FF or bin_phi >= 0x3FF or bin_eta < 0 or bin_phi < 0)
445 cout << __PRETTY_FUNCTION__ <<
" / " << calo_name <<
" invalid tower geom " << central_tower_key <<
": ";
446 cout <<
" bin_eta = " << bin_eta;
447 cout <<
" bin_phi = " << bin_phi;
448 cout <<
" central_tower_eta = " << central_tower_eta;
449 cout <<
" central_tower_phi = " << central_tower_phi;
450 cout <<
" central_tower_key = " << central_tower_key;
451 cout <<
" min_tower_r2 = " << min_tower_r2;
454 cout <<
" minBinPhi = " << minBinPhi;
455 cout <<
" maxBinPhi = " << maxBinPhi;
475 const double deta = eta_proj - vec_tower.Eta();
476 double dphi = phi_proj - vec_tower.Phi();
478 m_CaloDataMap[calo_name].m_TTree_Tower_dEta[tower_index_patch] = deta;
479 m_CaloDataMap[calo_name].m_TTree_Tower_dPhi[tower_index_patch] = dphi;
483 cout << __PRETTY_FUNCTION__ <<
" / " << calo_name <<
" process tower geom " << tower_key <<
": ";
484 cout <<
" ieta_patch = " << ieta_patch;
485 cout <<
" iphi_patch = " << iphi_patch;
486 cout <<
" bin_eta = " << bin_eta;
487 cout <<
" bin_phi = " << bin_phi;
488 cout <<
" deta = " << deta;
489 cout <<
" dphi = " << dphi;
507 cout << __PRETTY_FUNCTION__ <<
" / " << calo_name <<
" process tower " << tower_key <<
": ";
508 cout <<
" ieta_patch = " << ieta_patch;
509 cout <<
" iphi_patch = " << iphi_patch;
510 cout <<
" bin_eta = " << bin_eta;
511 cout <<
" bin_phi = " << bin_phi;
512 cout <<
" energy = " <<
energy;
550 cout <<
"Ending eIDMLInterface analysis package" << endl;
569 cout <<
"Finished eIDMLInterface analysis package" << endl;
584 PHHepMCGenEventMap *hepmceventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
590 <<
"HEPMC event map node is missing, can't collected HEPMC truth particles"
598 cout <<
"Getting HEPMC truth particles " << endl;
604 eventIter != hepmceventmap->
end();
613 HepMC::GenEvent *truthevent = hepmcevent->
getEvent();
617 <<
"no evt pointer under phhepmvgeneventmap found "
623 HepMC::PdfInfo *pdfinfo = truthevent->pdf_info();
628 m_x1 = pdfinfo->x1();
629 m_x2 = pdfinfo->x2();
632 m_mpi = truthevent->mpi();
639 cout <<
" Iterating over an event" << endl;
642 for (HepMC::GenEvent::particle_const_iterator iter = truthevent->particles_begin();
643 iter != truthevent->particles_end();
650 m_trutheta = (*iter)->momentum().pseudoRapidity();
679 <<
"PHG4TruthInfoContainer node is missing, can't collect G4 truth particles"
689 iter != range.second;
724 SvtxTrackMap *trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"TrackMap");
725 EICPIDParticleContainer *pidcontainer = findNode::getClass<EICPIDParticleContainer>(topNode,
"EICPIDParticleMap");
727 if (
Verbosity() > 1 and pidcontainer ==
nullptr)
729 cout <<
"EICPIDParticleContainer named EICPIDParticleMap does not exist. Skip saving PID info" << endl;
735 <<
"TrackMap node is missing, can't collect tracks"
745 cout <<
"Get the tracks" << endl;
748 iter != trackmap->
end();
781 std::cout <<
"Skipping non fast track sim object..." << std::endl;
809 pidcontainer->findEICPIDParticle(track->
get_id());
832 cout <<
"get the truth jets" << endl;
836 JetMap *truth_jets = findNode::getClass<JetMap>(topNode,
"AntiKt_Truth_r05");
839 JetMap *reco_jets = findNode::getClass<JetMap>(topNode,
"AntiKt_Tower_r05");
851 <<
"Truth jet node is missing, can't collect truth jets"
858 iter != truth_jets->
end();
861 Jet *truthJet = iter->second;
865 std::set<PHG4Particle *> truthjetcomp =
867 int ntruthconstituents = 0;
869 for (std::set<PHG4Particle *>::iterator iter2 = truthjetcomp.begin();
870 iter2 != truthjetcomp.end();
877 cout <<
"no truth particles in the jet??" << endl;
881 ntruthconstituents++;
884 if (ntruthconstituents < 3)
907 float closestjet = 9999;
910 recoIter != reco_jets->end();
913 const Jet *recoJet = recoIter->second;
923 cout <<
"matching by distance jet" << endl;
927 if (dphi > TMath::Pi())
928 dphi -= TMath::Pi() * 2.;
929 if (dphi < -1 * TMath::Pi())
930 dphi += TMath::Pi() * 2.;
935 m_dR = sqrt(pow(dphi, 2.) + pow(deta, 2.));
939 if (m_dR < truth_jets->get_par() &&
m_dR < closestjet)
963 JetMap *reco_jets = findNode::getClass<JetMap>(topNode,
"AntiKt_Tower_r05");
965 JetMap *truth_jets = findNode::getClass<JetMap>(topNode,
"AntiKt_Truth_r05");
977 <<
"Reconstructed jet node is missing, can't collect reconstructed jets"
984 cout <<
"Get all Reco Jets" << endl;
989 recoIter != reco_jets->
end();
992 Jet *recoJet = recoIter->second;
1010 cout <<
"matching by distance jet" << endl;
1039 else if (truth_jets)
1043 float closestjet = 9999;
1045 truthIter != truth_jets->end();
1048 const Jet *truthJet = truthIter->second;
1050 float thisjetpt = truthJet->
get_pt();
1054 float thisjeteta = truthJet->
get_eta();
1055 float thisjetphi = truthJet->
get_phi();
1058 if (dphi > TMath::Pi())
1059 dphi -= TMath::Pi() * 2.;
1060 if (dphi < -1. * TMath::Pi())
1061 dphi += TMath::Pi() * 2.;
1066 m_dR = sqrt(pow(dphi, 2.) + pow(deta, 2.));
1070 if (m_dR < reco_jets->get_par() &&
m_dR < closestjet)
1100 RawClusterContainer *clusters = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_BECAL");
1105 <<
"EMCal cluster node is missing, can't collect EMCal clusters"
1111 GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode,
"GlobalVertexMap");
1114 cout <<
"eIDMLInterface::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." << endl;
1120 if (vertexmap->
empty())
1122 cout <<
"eIDMLInterface::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." << endl;
1131 CaloTriggerInfo *trigger = findNode::getClass<CaloTriggerInfo>(topNode,
"CaloTriggerInfo");
1142 for (clusIter = begin_end.first;
1143 clusIter != begin_end.second;
1147 const RawCluster *cluster = clusIter->second;
1156 m_cluseta = E_vec_cluster.pseudoRapidity();
1244 m_truthtree =
new TTree(
"T",
"A tree one enetry for a truth g4 particles matched with reco objects");
1270 const string xyzt[] = {
"x",
"y",
"z",
"t"};
1274 for (
int i = 0; i < 4; i++)
1276 string bname = calo_name +
"_proj_" + xyzt[i];
1277 string bdef = bname +
"/F";
1282 bdef = calo_name +
"_proj_path_length" +
"/F";
1288 for (
int i = 0; i < 3; i++)
1290 string bname = calo_name +
"_proj_p" + xyzt[i];
1291 string bdef = bname +
"/F";
1296 m_truthtree->Branch((calo_name +
"_Tower_E3x3").c_str(), &
m_CaloDataMap[calo_name].m_E3x3, (calo_name +
"_Tower_E3x3/F").c_str());
1297 m_truthtree->Branch((calo_name +
"_Tower_E5x5").c_str(), &
m_CaloDataMap[calo_name].m_E5x5, (calo_name +
"_Tower_E5x5/F").c_str());
1298 m_truthtree->Branch((calo_name +
"_Tower_E7x7").c_str(), &
m_CaloDataMap[calo_name].m_E7x7, (calo_name +
"_Tower_E7x7/F").c_str());
1299 m_truthtree->Branch((calo_name +
"_centralTowerBinEta").c_str(), &
m_CaloDataMap[calo_name].m_centralTowerBinEta, (calo_name +
"_centralTowerBinEta/I").c_str());
1300 m_truthtree->Branch((calo_name +
"_centralTowerBinPhi").c_str(), &
m_CaloDataMap[calo_name].m_centralTowerBinPhi, (calo_name +
"_centralTowerBinPhi/I").c_str());
1301 m_truthtree->Branch((calo_name +
"_nTowerInPatch").c_str(), &
m_CaloDataMap[calo_name].nTowerInPatch, (calo_name +
"_nTowerInPatch/I").c_str());
1302 m_truthtree->Branch((calo_name +
"_Tower_dEta").c_str(),
m_CaloDataMap[calo_name].m_TTree_Tower_dEta.data(), (calo_name +
"_Tower_dEta[" + calo_name +
"_nTowerInPatch]/F").c_str());
1303 m_truthtree->Branch((calo_name +
"_Tower_dPhi").c_str(),
m_CaloDataMap[calo_name].m_TTree_Tower_dPhi.data(), (calo_name +
"_Tower_dPhi[" + calo_name +
"_nTowerInPatch]/F").c_str());
1304 m_truthtree->Branch((calo_name +
"_Tower_iEta_patch").c_str(),
m_CaloDataMap[calo_name].m_TTree_Tower_iEta_patch.data(), (calo_name +
"_Tower_iEta_patch[" + calo_name +
"_nTowerInPatch]/I").c_str());
1305 m_truthtree->Branch((calo_name +
"_Tower_iPhi_patch").c_str(),
m_CaloDataMap[calo_name].m_TTree_Tower_iPhi_patch.data(), (calo_name +
"_Tower_iPhi_patch[" + calo_name +
"_nTowerInPatch]/I").c_str());
1306 m_truthtree->Branch((calo_name +
"_Tower_E").c_str(),
m_CaloDataMap[calo_name].m_TTree_Tower_E.data(), (calo_name +
"_Tower_E[" + calo_name +
"_nTowerInPatch]/F").c_str());