18 #include <TLorentzVector.h>
21 #include <calobase/RawCluster.h>
22 #include <calobase/RawClusterContainer.h>
23 #include <calobase/RawClusterUtility.h>
24 #include <calobase/RawTowerGeomContainer.h>
25 #include <calobase/RawTower.h>
26 #include <calobase/RawTowerContainer.h>
33 #include <g4vertex/GlobalVertex.h>
34 #include <g4vertex/GlobalVertexMap.h>
39 #include <trackbase_historic/SvtxVertex.h>
40 #include <trackbase_historic/SvtxVertexMap.h>
45 #include </gpfs/mnt/gpfs02/sphenix/user/ahodges/macros_git/coresoftware/generators/phhepmc/PHHepMCGenEvent.h>
46 #include </gpfs/mnt/gpfs02/sphenix/user/ahodges/macros_git/coresoftware/generators/phhepmc/PHHepMCGenEventMap.h>
49 #include <HepMC/GenEvent.h>
50 #include <HepMC/GenParticle.h>
51 #include <HepMC/GenVertex.h>
52 #include <HepMC/IteratorRange.h>
53 #include <HepMC/SimpleVector.h>
54 #include <HepMC/GenParticle.h>
55 #include <CLHEP/Geometry/Point3D.h>
66 std::cout <<
"cemcReco::cemcReco(const std::string &name) Constructor" << std::endl;
88 for(
int i = 0;
i < 2;
i++)
117 std::cout <<
"cemcReco::~cemcReco() Calling dtor" << std::endl;
123 std::cout <<
"cemcReco::Init(PHCompositeNode *topNode) Initializing Histos" << std::endl;
126 photonE =
new TH1F(
"photonE_Reco",
"Reco Energy",200,0,20);
128 clusterChi2 =
new TH2F(
"clusterChi2",
"Cluster chi2",100,0,20,200,0,20);
130 clusterProbPhoton =
new TH2F(
"clusterProbPhoton",
"Cluster template probability",100,0,1,200,0,20);
132 isoPhoE =
new TH1F(
"isoPhotonE_Reco_Tru",
"Isolated Photon Energy",200,0,20);
134 isoPhoChi2 =
new TH2F(
"isoPhotonChi2",
"Isolated Photon Chi2 v. E",100,0,20,200,0,20);
136 isoPhoProb =
new TH2F(
"isoPhotonProb2",
"Isolated Photon Prob v. E",100,0,1,200,0,20);
138 deltaR_E_invMass =
new TH3F(
"deltaREinvMass",
"Opening Angle v. E v. InvMass",100,0,1,200,0,20,100,0,1);
140 tsp_E =
new TH2F(
"tspE",
"Transverse Shower Profile v. E",100,0,1,200,0,20);
142 tsp_E_iso =
new TH2F(
"tspEiso",
"Transverse Shower Profile Iso v. E",100,0,1,200,0,20);
144 asym_E_invMass =
new TH3F(
"asymEinvMass",
"Asymmetry v. E v. Invariant Mass",100,0,1,200,0,20,100,0,1);
148 truth_eta_E =
new TH1F(
"truthEtaE",
"truth eta energy",200,0,20);
150 truth_dpho_E =
new TH1F(
"truthDphoE",
"truth direct photon energy",200,0,20);
152 deltaR_E_truth_pi0 =
new TH2F(
"deltaREtruthpi0",
"Opening angle truth pi0",100,0,1,500,0,50);
154 asym_E_truth_pi0 =
new TH2F(
"asymEtruthpi0",
"Photon asymmetry truth pi0",100,0,1,200,0,20);
158 invMass_eta =
new TH3F(
"invMassEtaE",
"Invariant Mass vs. psuedorapidity bin",100,0,1,200,-1.2,1.2,200,0,20);
160 eFrac_dr_primary =
new TH2F(
"eFrac_dr_primary",
"Reco/Truth vs dr. primary",100,0,1,100,0,4);
162 eFrac_dr_secondary =
new TH2F(
"eFrac_dr_secondary",
"Reco/Truth vs dr. secondary",100,0,1,100,0,4);
167 for(
int i = 0;
i < 2;
i++)
171 ePi0InvMassEcut[
i][
j] =
new TH3F(Form(
"ePi0InvMassEcut_%dMatch_Eta%d",
i,
j),Form(
"Pi0 energy vs. Inv Mass vs. Min pho Energy %dMatched Eta%d",
i,
j), 500,0,50,500,-0.1,1,200,0,20);
175 dPhoChi2 =
new TH3F(
"dphoChi2",
"Direct Photon Chi2 vs. Cluster Energy vs. Mother energy",100,0,20,200,0,20,200,0,20);
176 dPhoProb =
new TH3F(
"dphoProb",
"Direct Photon Prob vs. Cluster Energy vs. Mother energy",100,0,1,200,0,20,200,0,20);
178 pi0Chi2 =
new TH3F(
"pi0Chi2",
"Pi0 Daughter Chi2 vs. Cluster Energy vs. Mother energy",100,0,20,200,0,20,200,0,20);
179 pi0Prob =
new TH3F(
"pi0Prob",
"Pi0 Daughter Prob vs. Cluster Energy vs. Mother energy",100,0,1,200,0,20,200,0,20);
181 etaChi2 =
new TH3F(
"etaChi2",
"Eta Daughter Chi2 vs. Cluster Energy vs. Mother energy",100,0,20,200,0,20,200,0,20);
182 etaProb =
new TH3F(
"etaProb",
"Eta Daughter Prob vs. Cluster Energy vs. Mother energy",100,0,1,200,0,20,200,0,20);
184 electronChi2 =
new TH3F(
"eChi2",
"Electron Chi2 vs. Cluster Energy vs. Mother energy",100,0,20,200,0,20,200,0,20);
185 electronProb =
new TH3F(
"eProb",
"Electron Prob vs. Cluster Energy vs. Mother energy",100,0,1,200,0,20,200,0,20);
187 hadronChi2 =
new TH3F(
"hChi2",
"Hadron Chi2 vs. Cluster Energy vs. Mother energy",100,0,20,200,0,20,200,0,20);
188 hadronProb =
new TH3F(
"hProb",
"Hadron Prob vs. Cluster Energy vs. Mother energy",100,0,1,200,0,20,200,0,20);
190 etaFrac =
new TH2F(
"etaClusterEFrac",
"clusters from eta fractional energy",200,0,1.5,500,0,50);
192 pi0Frac =
new TH2F(
"pi0ClusterEFrac",
"clusters from pi0 fractional energy",200,0,1.5,500,0,50);
194 invMassEPhi =
new TH3F(
"invMassEPhi",
"invariant mass vs. Truth Energy vs. phi",500,-0.1,1,500,0,50,200,-M_PI,M_PI);
196 unmatchedLocale =
new TH3F(
"unmatchedLocale",
"location of unmatched truth photons",200,-5,5,180,-M_PI,M_PI,500,0,50);
197 unmatchedE =
new TH1F(
"unmatchedE",
"energy of unmatched truth photons",250,0,50);
199 invMassPhoPi0 =
new TH3F(
"invMassPhoPi0",
"invariant mass vs. Photon energy scale vs. pi0 energy scale",500,-0.1,1,100,0,2,100,0,2);
203 se ->
Print(
"NODETREE");
206 se -> registerHistoManager(
hm);
220 for(
int i = 0;
i < 2;
i++)
222 for(
int j = 0;
j < 2;
j++)
257 std::cout <<
"cemcReco::InitRun(PHCompositeNode *topNode) No run dependence, doing nothing." << std::endl;
268 std::cout <<
"Processing Event: " <<
nEvent << std::endl;
272 EventHeader *evtInfo = findNode::getClass<EventHeader>(topNode,
"EventHeader");
275 std::cout <<
PHWHERE <<
"cemc::process_event: EventHeader not in node tree" << std::endl;
280 RawClusterContainer *clusterContainer = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_POS_COR_CEMC");
282 if(!clusterContainer)
284 std::cout <<
PHWHERE <<
"cemc::process_event - Fatal Error - CLUSTER_POS_COR_CEMC node is missing. " << std::endl;
291 GlobalVertexMap *vtxContainer = findNode::getClass<GlobalVertexMap>(topNode,
"GlobalVertexMap");
294 std::cout <<
PHWHERE <<
"cemc::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;
300 if (vtxContainer->
empty())
302 std::cout <<
PHWHERE <<
"cemc::process_event - 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;
311 std::cout <<
PHWHERE <<
"cemc::process_event Could not find vtx from vtxContainer" << std::endl;
316 SvtxTrackMap *trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
319 if(
trackErrorCount < 4)std::cout <<
PHWHERE <<
"cemc::process_event Could not find node SvtxTrackMap, not aborting, but reco direct photon information will not be available" << std::endl;
320 if(
trackErrorCount == 4)std::cout <<
PHWHERE <<
"cemc::process_event Could not find node SvtxTrackMap for four events, it's probably missing from your file list, this message will no longer display" << std::endl;
326 RawTowerGeomContainer *towergeom = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_CEMC");
329 std::cout <<
PHWHERE <<
"cemc::process_event Could not find node TOWERGEOM_CEMC" << std::endl;
334 RawTowerContainer *towerContainer = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_CEMC");
337 std::cout <<
PHWHERE <<
"cemc::process_event Could not find node TOWER_CALIB_CEMC" << std::endl;
345 std::cout <<
PHWHERE <<
"cemc::process_event Could not find node G4TruthInfo" << std::endl;
350 PHHepMCGenEventMap *genEventMap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
353 std::cout <<
PHWHERE <<
"cemc::process_event Could not find PHHepMCGenEventMap" << std::endl;
360 std::cout <<
PHWHERE <<
"cemc::process_event Could not find PHHepMCGenEvent" << std::endl;
364 HepMC::GenEvent *theEvent = genEvent -> getEvent();
370 std::cout <<
PHWHERE <<
"cemc::process_event cluster eval not available" << std::endl;
374 float mesonEtaMax = 0.3;
375 float photonEtaMax = 1.1;
382 std::vector<RawCluster*> goodRecoCluster;
385 float isoConeRadius = 3;
386 for(clusterIter = clusterEnd.first; clusterIter != clusterEnd.second; clusterIter++)
388 RawCluster *recoCluster = clusterIter -> second;
392 float clusE = E_vec_cluster.mag();
393 float clus_eta = E_vec_cluster.pseudoRapidity();
394 float clus_pt = E_vec_cluster.perp();
397 if(clusE < minE)
continue;
399 maxPrimary = clustereval -> max_truth_primary_particle_by_energy(recoCluster);
403 if(maxPrimary -> get_pid() == 11 || maxPrimary -> get_pid() == -11)
405 electronChi2 ->
Fill(recoCluster -> get_chi2(), clusE, maxPrimary -> get_e());
406 electronProb ->
Fill(recoCluster -> get_prob(), clusE, maxPrimary -> get_e());
408 else if(maxPrimary -> get_pid() == 211 || maxPrimary -> get_pid() == -211)
410 hadronChi2 ->
Fill(recoCluster -> get_chi2(), clusE, maxPrimary -> get_e());
411 hadronProb ->
Fill(recoCluster -> get_prob(), clusE, maxPrimary -> get_e());
413 if(maxPrimary -> get_pid() == 22)
415 for(HepMC::GenEvent::particle_const_iterator
p = theEvent -> particles_begin();
p != theEvent -> particles_end(); ++
p)
419 if((*p) -> barcode() == maxPrimary -> get_barcode())
421 for(HepMC::GenVertex::particle_iterator mother = (*p)->production_vertex()->particles_begin(HepMC::parents);
422 mother != (*p)->production_vertex()->particles_end(HepMC::parents); ++mother)
424 HepMC::FourVector moMomentum = (*mother) ->
momentum();
425 float e = moMomentum.e();
427 if((*mother) -> pdg_id() == 22)
432 else if((*mother) -> pdg_id() == 111)
434 pi0Chi2 ->
Fill(recoCluster -> get_chi2(), clusE, e);
435 pi0Prob ->
Fill(recoCluster -> get_prob(), clusE, e);
438 else if((*mother) -> pdg_id() == 221)
440 etaChi2 ->
Fill(recoCluster -> get_chi2(), clusE, e);
441 etaProb ->
Fill(recoCluster -> get_prob(), clusE, e);
461 float tsp =
calculateTSP(recoCluster, clusterContainer, towerContainer, towergeom, vtx);
467 if(clus_pt > minDirpT)
472 if((fabs(clus_eta) < 1.0 - isoConeRadius) && trackmap)
474 float energyInCone =
coneSum(recoCluster,clusterContainer, trackmap, isoConeRadius, vtx);
476 if(energyInCone < 0.1*clusE)
486 goodRecoCluster.push_back(recoCluster);
491 for(
int i = 0;
i < (int)goodRecoCluster.size();
i++)
497 TLorentzVector pho1, pho2, pi0;
498 pho1.SetPtEtaPhiE(E_vec_cluster1.perp(), E_vec_cluster1.pseudoRapidity(), E_vec_cluster1.getPhi(), E_vec_cluster1.mag());
502 for(
int j = 0;
j <(int)goodRecoCluster.size();
j++)
508 pho2.SetPtEtaPhiE(E_vec_cluster2.perp(), E_vec_cluster2.pseudoRapidity(), E_vec_cluster2.getPhi(), E_vec_cluster2.mag());
514 float asym = abs(pho1.Energy() - pho2.Energy())/pi0.Energy();
520 if(abs(pho2.PseudoRapidity()) < photonEtaMax && abs(pho1.PseudoRapidity()) < photonEtaMax && pi0.PseudoRapidity() < mesonEtaMax)
523 if(pho1.Energy() >= pho2.Energy()) etaBin =
getEtaBin(pho1.PseudoRapidity());
524 else etaBin =
getEtaBin(pho2.PseudoRapidity());
539 std::vector<PHG4Particle*> phoPi0;
540 std::vector<PHG4Particle*> phoEta;
542 std::vector<int> mBarCodePi0;
543 std::vector<HepMC::GenVertex*> vtxIDpi0;
545 std::vector<int> mBarCodeEta;
546 std::vector<HepMC::GenVertex*> vtxIDEta;
552 for(truthIter = truthRange.first; truthIter != truthRange.second; truthIter++)
555 if(truthPar -> get_pid() != 22)
continue;
556 if(truthinfo -> isEmbeded(truthPar -> get_track_id()) != 1)
continue;
558 for(HepMC::GenEvent::particle_const_iterator
p = theEvent -> particles_begin();
p != theEvent -> particles_end(); ++
p)
561 if((*p) -> pdg_id() != 22)
continue;
563 if((*p) -> barcode() == truthPar -> get_barcode())
566 for (HepMC::GenVertex::particle_iterator mother = (*p)->production_vertex()->particles_begin(HepMC::parents);
567 mother != (*p)->production_vertex()->particles_end(HepMC::parents); ++mother)
570 HepMC::FourVector moMomentum = (*mother) ->
momentum();
571 float e = moMomentum.e();
572 float eta = moMomentum.pseudoRapidity();
573 if((*mother) -> pdg_id() == 22 && abs(eta) < photonEtaMax)
579 else if((*mother) -> pdg_id() == 111 )
582 phoPi0.push_back(truthPar);
583 vtxIDpi0.push_back((*mother) -> production_vertex());
585 mBarCodePi0.push_back((*mother) -> barcode());
587 else if((*mother) -> pdg_id() == 221 )
591 phoEta.push_back(truthPar);
592 vtxIDEta.push_back((*mother) -> production_vertex());
593 mBarCodeEta.push_back((*mother) -> barcode());
602 truthRange = truthinfo -> GetSecondaryParticleRange();
603 for(truthIter = truthRange.first; truthIter != truthRange.second; truthIter++)
607 while(truthPar -> get_parent_id() != 0)
610 PHG4Particle *parent = truthinfo -> GetParticle(truthPar -> get_parent_id());
611 if(parent -> get_parent_id() == 0)
break;
615 if(truthPar -> get_pid() != 22 )
620 PHG4Particle *pi0 = truthinfo -> GetParticle(truthPar -> get_parent_id());
621 if(pi0 -> get_pid() != 111)
626 if(abs(
getEta(pi0)) > mesonEtaMax)
631 if(abs(
getEta(truthPar)) > photonEtaMax)
continue;
641 if(
checkBarcode(pi0 -> get_barcode(), mBarCodePi0))
continue;
643 mBarCodePi0.push_back(pi0 -> get_barcode());
644 phoPi0.push_back(truthPar);
652 for(
int i = 0;
i < (int)phoPi0.size();
i++)
654 for(
int j = 0;
j < (int)phoPi0.size();
j++)
660 if(mBarCodePi0.at(
i) != mBarCodePi0.at(
j))
664 if(abs(
getEta(phoPi0.at(
i))) >= photonEtaMax || abs(
getEta(phoPi0.at(
j))) >= photonEtaMax)
670 TLorentzVector e1Vec, e2Vec;
671 e1Vec.SetPxPyPzE(phoPi0.at(
i) -> get_px(),phoPi0.at(
i) -> get_py(), phoPi0.at(
i) -> get_pz(), phoPi0.at(
i) -> get_e());
672 e2Vec.SetPxPyPzE(phoPi0.at(
j) -> get_px(),phoPi0.at(
j) -> get_py(), phoPi0.at(
j) -> get_pz(), phoPi0.at(
j) -> get_e());
675 float dr = e1Vec.DeltaR(e2Vec);
678 e1 = phoPi0.at(
i) -> get_e();
679 e2 = phoPi0.at(
j) -> get_e();
681 float asym = abs(e1-e2)/(e1+e2);
683 TLorentzVector pi0 = e1Vec + e2Vec;
684 if(abs(pi0.PseudoRapidity()) >= mesonEtaMax)
689 if(e1Vec.Energy() >= e2Vec.Energy()) etaBin =
getEtaBin(e1Vec.PseudoRapidity());
690 else etaBin =
getEtaBin(e2Vec.PseudoRapidity());
697 RawCluster *best_cluster1 = clustereval -> best_cluster_from(phoPi0.at(
i));
698 RawCluster *best_cluster2 = clustereval -> best_cluster_from(phoPi0.at(
j));
700 if(!best_cluster1 || !best_cluster2)
715 if(e1Vec.Energy() >= e2Vec.Energy()) etaBin =
getEtaBin(e1Vec.PseudoRapidity());
716 else etaBin =
getEtaBin(e2Vec.PseudoRapidity());
722 if(best_cluster1 -> get_id() == best_cluster2 -> get_id())
continue;
728 TLorentzVector clusE1, clusE2, clusPi0;
729 clusE1.SetPtEtaPhiE(E_vec_cluster1.perp(), E_vec_cluster1.pseudoRapidity(), E_vec_cluster1.getPhi(), E_vec_cluster1.mag());
730 clusE2.SetPtEtaPhiE(E_vec_cluster2.perp(), E_vec_cluster2.pseudoRapidity(), E_vec_cluster2.getPhi(), E_vec_cluster2.mag());
732 clusPi0 = clusE1 + clusE2;
735 if(clusE1.Energy() >= clusE2.Energy()) etaBin =
getEtaBin(clusE1.PseudoRapidity());
736 else etaBin =
getEtaBin(clusE2.PseudoRapidity());
743 invMassPhoPi0 ->
Fill(clusPi0.M(), clusPi0.Energy()/pi0.Energy(), clusE1.Energy()/e1Vec.Energy());
744 invMassPhoPi0 ->
Fill(clusPi0.M(), clusPi0.Energy()/pi0.Energy(), clusE2.Energy()/e2Vec.Energy());
770 for(truthIterDecay1 = truthRangeDecay1.first; truthIterDecay1 != truthRangeDecay1.second; truthIterDecay1++)
774 if(truthDecay1 -> get_parent_id() != 0 && truthDecay1 -> get_pid() == 111 && abs(
getEta(truthDecay1)) < mesonEtaMax)
784 goodRecoCluster.clear();
805 std::cout <<
"cemcReco::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
812 std::cout <<
"cemcReco::End(PHCompositeNode *topNode) This is the End..." << std::endl;
836 for(
int i = 0;
i < 2;
i++)
873 std::cout <<
"cemcReco::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
880 std::cout <<
"cemcReco::Print(const std::string &what) const Printing info for " << what << std::endl;
889 float energyptsum = 0;
897 for (clusiter = begin_end.first;
898 clusiter != begin_end.second;
911 float cone_pt = E_vec_conecluster.perp();
917 float cone_eta = E_vec_conecluster.pseudoRapidity();
918 float cone_phi = E_vec_conecluster.getPhi();
926 float deta = E_vec_cluster.pseudoRapidity() - cone_eta;
928 float radius = sqrt(dphi * dphi + deta * deta);
930 if (radius < coneradius)
932 energyptsum += cone_e;
940 float trackpx = track->
get_px();
941 float trackpy = track->
get_py();
942 float trackpt = sqrt(trackpx * trackpx + trackpy * trackpy);
945 float trackphi = track->
get_phi();
946 float tracketa = track->
get_eta();
947 float dphi = E_vec_cluster.getPhi() - trackphi;
948 float deta = E_vec_cluster.pseudoRapidity() - tracketa;
949 float radius = sqrt(dphi * dphi + deta * deta);
951 if (radius < coneradius)
953 energyptsum += trackpt;
971 float clusE = E_vec_cluster.mag();
972 float clusEta = E_vec_cluster.pseudoRapidity();
974 float clusPhi = E_vec_cluster.getPhi();
980 for (toweriter = towers.first; toweriter != towers.second; ++toweriter)
996 float r = sqrt(pow(clusEta - eta,2) + pow(clusPhi - phi,2));
997 denom += towerEnergy*pow(r,1.5);
1031 float g4vtxz, g4vtxy, g4vtxx;
1032 g4vtxx = g4vtx -> get_x();
1033 g4vtxy = g4vtx -> get_y();
1034 g4vtxz = g4vtx -> get_z();
1035 std::cout <<
"g4 x: " << g4vtxx <<
"; g4 y: " << g4vtxy <<
"; g4 z: " << g4vtxz << std::endl;
1037 float hepVtxx, hepVtxy, hepVtxz;
1038 hepVtxx = hepMCvtx.x();
1039 hepVtxy = hepMCvtx.y();
1040 hepVtxz = hepMCvtx.z();
1041 std::cout <<
"hep x: " << hepVtxx <<
"; hep y: " << hepVtxy <<
"; hep z: " << hepVtxz << std::endl;
1044 if(g4vtxx != hepVtxx || g4vtxy != hepVtxy || g4vtxz != hepVtxz )
return false;
1061 float px = particle -> get_px();
1062 float py = particle -> get_py();
1063 float pz = particle -> get_pz();
1064 float p = sqrt(pow(px,2) + pow(py,2) + pow(pz,2));
1066 return 0.5*log((p+pz)/(p-pz));
1071 float phi = atan2(particle -> get_py(),particle -> get_px());
1077 bool isRepeated =
false;
1078 for(
int i = 0;
i < (int)motherBarcodes.size();
i++)
1080 if(motherBarcode == motherBarcodes.at(
i)) isRepeated =
true;
1088 bool isRepeated =
false;
1090 for(
int i = 0;
i < (int)motherBarcodes.size();
i++)
1092 if(motherBarcode == motherBarcodes.at(
i) -> get_barcode()) isRepeated =
true;
1102 if(abs(eta) < (
i+1)/(
float)(nEtaBins-1) * 1.1 && abs(eta) >= (
i+1-1)/(
float)(nEtaBins-1) * 1.1)