25 #include <TLorentzVector.h>
29 #include <calobase/RawCluster.h>
30 #include <calobase/RawClusterContainer.h>
31 #include <calobase/RawClusterUtility.h>
32 #include <calobase/RawTowerGeomContainer.h>
33 #include <calobase/RawTower.h>
34 #include <calobase/RawTowerContainer.h>
58 #pragma GCC diagnostic push
59 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
60 #include <HepMC/GenEvent.h>
61 #include <HepMC/GenParticle.h>
62 #include <HepMC/GenVertex.h>
63 #include <HepMC/IteratorRange.h>
64 #include <HepMC/SimpleVector.h>
65 #include <HepMC/GenParticle.h>
66 #pragma GCC diagnostic pop
71 clusters_Towers(nullptr),
72 truth_particles(nullptr),
84 m_cluster_maxE_trackID(0),
85 m_cluster_maxE_PID(0),
86 m_cluster_all_trackIDs(0),
102 m_truth_all_clusterIDs(0),
108 hasPYTHIA(hasPythia),
110 n_primary_photons(0),
113 n_neutral_hadrons(0),
114 n_neutral_hadrons_geant(0),
115 n_neutral_hadrons_pythia(0),
116 n_charged_hadrons(0),
117 n_charged_hadrons_geant(0),
118 n_charged_hadrons_pythia(0),
119 n_pythia_decayed_hadrons(0),
149 std::cout <<
"pythiaEMCalAna::pythiaEMCalAna(const std::string &name) Calling ctor" << std::endl;
154 std::cout <<
"pythiaEMCalAna::~pythiaEMCalAna() Calling dtor" << std::endl;
160 std::cout <<
"pythiaEMCalAna::Init(PHCompositeNode *topNode) Initializing" << std::endl;
164 clusters_Towers =
new TTree(
"TreeClusterTower",
"Tree for cluster and tower information");
183 truth_particles =
new TTree(
"TreeTruthParticles",
"Tree for Truth Particles");
211 std::cout <<
"pythiaEMCalAna::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
221 RawTowerGeomContainer *towergeom = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_CEMC");
224 std::cout <<
PHWHERE <<
"singlePhotonClusterAna::process_event Could not find node TOWERGEOM_CEMC" << std::endl;
232 towerContainer = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_CEMC");
239 if(!towerContainer) {
240 if (
isMonteCarlo) std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event Could not find node TOWER_CALIB_CEMC" << std::endl;
241 else std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event Could not find node TOWERINFO_CALIB_CEMC" << std::endl;
254 std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event cluster eval not available" << std::endl;
264 clusterContainer = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_POS_COR_CEMC");
268 clusterContainer = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTERINFO_POS_COR_CEMC");
270 if(!clusterContainer)
272 if (
isMonteCarlo) std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event - Fatal Error - CLUSTER_POS_COR_CEMC node is missing. " << std::endl;
273 else std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event - Fatal Error - CLUSTERINFO_CEMC node is missing. " << std::endl;
280 truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
282 std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event Could not find node G4TruthInfo" << std::endl;
293 mcVtx = vtxIter->second;
296 GlobalVertexMap *vtxContainer = findNode::getClass<GlobalVertexMap>(topNode,
"GlobalVertexMap");
299 std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event - 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;
303 if (vtxContainer->
empty())
307 std::cout <<
"Info: global vertex map is empty. Using (0,0,0) for vertex\n";
312 gVtx = vtxContainer->
begin()->second;
315 std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event Could not find vtx from vtxContainer" << std::endl;
331 genEventMap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
334 std::cout <<
PHWHERE <<
"pythiaEMCalAna::process_event Could not find PHHepMCGenEventMap" << std::endl;
351 HepMC::GenEvent *theEvent =
nullptr;
354 bool write_towers =
true;
359 int phibin = tower_iter -> second -> get_binphi();
360 int etabin = tower_iter -> second -> get_bineta();
361 double phi = towergeom -> get_phicenter(phibin);
362 double eta = towergeom -> get_etacenter(etabin);
363 double energy = tower_iter -> second -> get_energy();
372 bool write_clusters =
true;
373 bool apply_energy_cut =
false;
374 float clusterMinEnergyCut = 0.3;
375 if (write_clusters) {
378 for(clusterIter = clusterEnd.first; clusterIter != clusterEnd.second; clusterIter++)
380 RawCluster *recoCluster = clusterIter -> second;
384 if (gVtx) vertex = CLHEP::Hep3Vector(gVtx->
get_x(), gVtx->
get_y(), gVtx->
get_z());
385 else vertex = CLHEP::Hep3Vector(0,0,0);
390 float clusEcore = recoCluster->
get_ecore();
391 float clus_eta = E_vec_cluster.pseudoRapidity();
392 float clus_phi = E_vec_cluster.phi();
394 if (apply_energy_cut) {
395 if (clusE < clusterMinEnergyCut)
continue;
409 if (all_parts.empty()) {
413 std::vector<float> all_cluster_trackIDs;
421 std::vector<float> all_cluster_trackIDs;
422 for (
auto& part : all_parts) {
423 all_cluster_trackIDs.push_back(part->get_track_id());
437 for(truthIter = truthRange.first; truthIter != truthRange.second; truthIter++)
443 int embedID = truthinfo->
isEmbeded(track_id);
444 genEvent = genEventMap ->
get(embedID);
446 if (truthPar->
get_pid() != 22) {
462 HepMC::GenVertex* prod_vtx = p->production_vertex();
464 if (prod_vtx->particles_in_size() == 1) {
465 HepMC::GenVertex::particles_in_const_iterator parent = prod_vtx->particles_in_const_begin();
469 if ((*parent)->status() == 2 && abs((*parent)->pdg_id()) >= 100) {
479 std::cout <<
"\nGreg info: weird combination of photon or parent status or PID... photon:\n";
481 std::cout <<
"Parent:\n";
488 std::cout <<
"\nGreg info: in PYTHIA check, found a photon with " << prod_vtx->particles_in_size() <<
" parent(s). Photon:\n";
490 for (HepMC::GenVertex::particles_in_const_iterator parent = prod_vtx->particles_in_const_begin(); parent != prod_vtx->particles_in_const_end(); parent++) {
491 std::cout <<
"Parent:\n";
505 delete caloevalstack;
823 std::cout <<
"pythiaEMCalAna::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
830 std::cout <<
"pythiaEMCalAna::End(PHCompositeNode *topNode) This is the End..." << std::endl;
832 std::cout << Form(
"Total primary particles: %ld\n",
n_primaries);
838 std::cout << Form(
"Total primary leptons: %ld\n",
n_leptons);
841 std::cout <<
"Writing clusters_Towers\n";
844 std::cout <<
"Writing truth_particles\n";
854 std::cout <<
"pythiaEMCalAna::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
861 std::cout <<
"pythiaEMCalAna::Print(const std::string &what) const Printing info for " << what << std::endl;
871 if (abs(pdg_id) > 999 && abs(pdg_id) < 10000) ret =
true;
878 if (!
IsBaryon(pdg_id))
return false;
880 int base_id = abs(pdg_id) % 10000;
883 int q1 = (int)(base_id/1000);
884 int q2 = (int)(base_id/100 % 10);
885 int q3 = (int)(base_id/10 % 10);
888 if (q1%2 == 0) charge += 2./3.;
889 else charge -= 1./3.;
890 if (q2%2 == 0) charge += 2./3.;
891 else charge -= 1./3.;
892 if (q3%2 == 0) charge += 2./3.;
893 else charge -= 1./3.;
895 if (abs(charge) < 0.05)
return true;
902 int base_id = pdg_id % 1000;
906 int q1 = (int)(base_id/100);
907 int q2 = (int)(base_id/10 % 10);
909 if (q1%2 == 0) charge += 2./3.;
910 else charge -= 1./3.;
911 if (q2%2 == 0) charge -= 2./3.;
912 else charge += 1./3.;
914 if (abs(charge) < 0.05)
return true;
926 TLorentzVector truth_momentum;
933 std::cout <<
"\nGreg info: no end vertex found for Geant-decayed primary:\n";
935 std::cout << Form(
"Mass=%f, pT=%f\n\n", truth_momentum.M(), truth_momentum.Pt());
950 if (abs(part->
get_pid()) > 100) {
965 m_truthE.push_back(truth_momentum.E());
966 m_truthEta.push_back(truth_momentum.PseudoRapidity());
968 m_truthPt.push_back(truth_momentum.Pt());
975 float x = end_vtx->
get_x();
976 float y = end_vtx->
get_y();
977 float r = sqrt(x*x + y*y);
980 std::vector<float> allClusterIDs;
983 for (
auto& cl : clusters) {
984 allClusterIDs.push_back(cl->get_id());
992 HepMC::FourVector mom = part->momentum();
993 TLorentzVector truth_momentum;
994 truth_momentum.SetPxPyPzE(mom.px(), mom.py(), mom.pz(), mom.e());
1014 m_truthE.push_back(truth_momentum.E());
1015 m_truthEta.push_back(truth_momentum.PseudoRapidity());
1017 m_truthPt.push_back(truth_momentum.Pt());
1021 HepMC::GenVertex* end_vtx = part->end_vertex();
1024 HepMC::FourVector
position = end_vtx->position();
1030 float x = position.x();
1031 float y = position.y();
1032 float r = sqrt(x*x + y*y);
1037 std::vector<float> allClusterIDs;
1051 std::cout <<
"\t\tGreg info: in isDirectPhoton(), could not find pythia particle with barcode " << part->
get_barcode() <<
"; returning true. (This may be an error!)\n";
1058 HepMC::GenVertex* prod_vtx = genpart->production_vertex();
1059 if (prod_vtx->particles_in_size() == 1) {
1060 HepMC::GenVertex::particles_in_const_iterator parent = prod_vtx->particles_in_const_begin();
1064 if ((*parent)->status() > 2 && abs((*parent)->pdg_id()) < 100) {
1068 bool printHistory =
false;
1072 int generation = -1;
1073 std::cout <<
"\tGeneration " << generation <<
" -- ";
1077 HepMC::GenVertex::particles_in_const_iterator parentparent;
1078 HepMC::GenVertex* parent_prod_vtx = (*parent)->production_vertex();
1079 if (parent_prod_vtx) {
1080 parentparent = parent_prod_vtx->particles_in_const_begin();
1081 std::cout <<
"\tGeneration " << generation <<
": ";
1082 (*parentparent)->print();
1083 parent = parentparent;
1087 parent = prod_vtx->particles_in_const_begin();
1091 else if ((*parent)->status() == 2 && abs((*parent)->pdg_id()) >= 100) {
1102 std::cout <<
"\nGreg info: weird combination of photon or parent status or PID... photon:\n";
1104 std::cout <<
"Parent:\n";
1112 std::cout <<
"Greg info: found a photon with " << prod_vtx->particles_in_size() <<
" parent(s). Photon:\n";
1114 for (HepMC::GenVertex::particles_in_const_iterator parent = prod_vtx->particles_in_const_begin(); parent != prod_vtx->particles_in_const_end(); parent++) {
1115 std::cout <<
"Parent:\n";
1125 for(HepMC::GenEvent::particle_const_iterator
p=theEvent->particles_begin();
p!=theEvent->particles_end(); ++
p)
1133 if ( (*p)->barcode() == barcode ) {
1140 std::cout <<
"\t\tGreg info: in getGenParticle(), could not find correct generated particle!\n";
1145 float max_eta = 1.1;
1147 TLorentzVector truth_momentum;
1149 float eta = truth_momentum.PseudoRapidity();
1150 if (abs(eta) > max_eta)
return false;
1151 if (truth_momentum.E() < min_E)
return false;
1156 float max_eta = 1.1;
1158 HepMC::FourVector mom = part->momentum();
1159 TLorentzVector truth_momentum;
1160 truth_momentum.SetPxPyPzE(mom.px(), mom.py(), mom.pz(), mom.e());
1161 float eta = truth_momentum.PseudoRapidity();
1162 if (abs(eta) > max_eta)
return false;
1163 if (truth_momentum.E() < min_E)
return false;
1171 for(truthIter = truthRange.first; truthIter != truthRange.second; truthIter++)
1175 if (parent_id ==
id) {
1184 for(truthIter = truthRange.first; truthIter != truthRange.second; truthIter++)
1188 if (parent_id ==
id) {
1189 std::cout <<
"\tGreg info: found daughter in *primary* particle range!\n";