File indexing completed on 2025-08-05 08:15:01
0001 #include "singlePhotonClusterAna.h"
0002
0003
0004 #include <fun4all/Fun4AllReturnCodes.h>
0005 #include <fun4all/Fun4AllServer.h>
0006 #include <fun4all/Fun4AllHistoManager.h>
0007 #include <phool/PHCompositeNode.h>
0008 #include <phool/getClass.h>
0009 #include <phool/phool.h>
0010 #include <ffaobjects/EventHeader.h>
0011
0012
0013 #include <TH1F.h>
0014 #include <TH2F.h>
0015 #include <TH3F.h>
0016 #include <TFile.h>
0017 #include <TLorentzVector.h>
0018 #include <TTree.h>
0019
0020
0021 #include <calobase/RawCluster.h>
0022 #include <calobase/RawClusterContainer.h>
0023 #include <calobase/RawClusterUtility.h>
0024 #include <calobase/RawTowerGeomContainer.h>
0025 #include <calobase/RawTower.h>
0026 #include <calobase/RawTowerContainer.h>
0027
0028
0029 #include <globalvertex/GlobalVertex.h>
0030 #include <globalvertex/GlobalVertexMap.h>
0031
0032
0033 #include <trackbase_historic/SvtxTrack.h>
0034 #include <trackbase_historic/SvtxTrackMap.h>
0035 #include <trackbase_historic/SvtxVertex.h>
0036 #include <trackbase_historic/SvtxVertexMap.h>
0037
0038
0039 #include <g4main/PHG4TruthInfoContainer.h>
0040 #include <g4main/PHG4Particle.h>
0041 #include <g4main/PHG4VtxPoint.h>
0042 #pragma GCC diagnostic push
0043 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
0044 #include <HepMC/GenEvent.h>
0045 #include <HepMC/GenParticle.h>
0046 #include <HepMC/GenVertex.h>
0047 #include <HepMC/IteratorRange.h>
0048 #include <HepMC/SimpleVector.h>
0049 #include <HepMC/GenParticle.h>
0050 #pragma GCC diagnostic pop
0051 #include <CLHEP/Geometry/Point3D.h>
0052
0053
0054
0055 singlePhotonClusterAna::singlePhotonClusterAna(const std::string &name, const std::string &outName = "singlePhotonClusterAnaOut"):
0056 SubsysReco(name)
0057 , clusters_Towers(nullptr)
0058 , truth_photon(nullptr)
0059 , conversion(nullptr)
0060
0061 , m_eta_center()
0062 , m_phi_center()
0063 , m_tower_energy()
0064 , m_cluster_eta()
0065 , m_cluster_phi()
0066 , m_cluster_e()
0067 , m_cluster_ecore()
0068 , m_cluster_chi2()
0069 , m_cluster_prob()
0070 , m_cluster_nTowers()
0071 , m_photon_E()
0072 , m_photon_eta()
0073 , m_photon_phi()
0074 , m_electron_E()
0075 , m_electron_eta()
0076 , m_electron_phi()
0077 , m_positron_E()
0078 , m_positron_eta()
0079 , m_positron_phi()
0080 , m_vtx_x()
0081 , m_vtx_y()
0082 , m_vtx_z()
0083 , m_vtx_t()
0084 , m_vtx_r()
0085 , m_isConversionEvent()
0086 , Outfile(outName)
0087
0088 {
0089
0090
0091 std::cout << "singlePhotonClusterAna::singlePhotonClusterAna(const std::string &name) Calling ctor" << std::endl;
0092 }
0093
0094
0095 singlePhotonClusterAna::~singlePhotonClusterAna()
0096 {
0097 std::cout << "singlePhotonClusterAna::~singlePhotonClusterAna() Calling dtor" << std::endl;
0098 }
0099
0100
0101 int singlePhotonClusterAna::Init(PHCompositeNode *topNode)
0102 {
0103
0104 clusters_Towers = new TTree("TreeClusterTower","Tree for cluster and tower information");
0105 clusters_Towers -> Branch("towerEtaCEnter",&m_eta_center);
0106 clusters_Towers -> Branch("towerPhiCenter",& m_phi_center);
0107 clusters_Towers -> Branch("towerEnergy",&m_tower_energy);
0108 clusters_Towers -> Branch("clusterEta",&m_cluster_eta);
0109 clusters_Towers -> Branch("clusterPhi", &m_cluster_phi);
0110 clusters_Towers -> Branch("clusterE",&m_cluster_e);
0111 clusters_Towers -> Branch("clusterEcore",&m_cluster_ecore);
0112 clusters_Towers -> Branch("clusterChi2",&m_cluster_chi2);
0113 clusters_Towers -> Branch("clusterProb",&m_cluster_prob);
0114 clusters_Towers -> Branch("clusterNTowers",&m_cluster_nTowers);
0115
0116 truth_photon = new TTree("TreeTruthPhoton", "Tree for Truth Photon");
0117 truth_photon -> Branch("photonE",&m_photon_E);
0118 truth_photon -> Branch("photon_phi",&m_photon_phi);
0119 truth_photon -> Branch("photon_eta",&m_photon_eta);
0120
0121 conversion = new TTree("TreeConversion", "Tree for Photon Conversion Info");
0122 conversion -> Branch("electronE",&m_electron_E);
0123 conversion -> Branch("electron_phi",&m_electron_phi);
0124 conversion -> Branch("electron_eta",&m_electron_eta);
0125 conversion -> Branch("positronE",&m_positron_E);
0126 conversion -> Branch("positron_phi",&m_positron_phi);
0127 conversion -> Branch("positron_eta",&m_positron_eta);
0128 conversion -> Branch("vtx_x",&m_vtx_x);
0129 conversion -> Branch("vtx_y",&m_vtx_y);
0130 conversion -> Branch("vtx_z",&m_vtx_z);
0131 conversion -> Branch("vtx_t",&m_vtx_t);
0132 conversion -> Branch("vtx_r",&m_vtx_r);
0133 conversion -> Branch("isConversionEvent",&m_isConversionEvent);
0134
0135
0136 Fun4AllServer *se = Fun4AllServer::instance();
0137 se -> Print("NODETREE");
0138 hm = new Fun4AllHistoManager("MYHISTOS");
0139
0140 se -> registerHistoManager(hm);
0141
0142 se -> registerHisto(truth_photon -> GetName(), truth_photon);
0143 se -> registerHisto(clusters_Towers -> GetName(), clusters_Towers);
0144
0145 out = new TFile(Outfile.c_str(),"RECREATE");
0146
0147 std::cout << "singlePhotonClusterAna::Init(PHCompositeNode *topNode) Initializing" << std::endl;
0148 return Fun4AllReturnCodes::EVENT_OK;
0149 }
0150
0151
0152 int singlePhotonClusterAna::InitRun(PHCompositeNode *topNode)
0153 {
0154 std::cout << "singlePhotonClusterAna::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
0155
0156 return Fun4AllReturnCodes::EVENT_OK;
0157 }
0158
0159
0160 int singlePhotonClusterAna::process_event(PHCompositeNode *topNode)
0161 {
0162
0163
0164 RawClusterContainer *clusterContainer = findNode::getClass<RawClusterContainer>(topNode,"CLUSTER_POS_COR_CEMC");
0165
0166 if(!clusterContainer)
0167 {
0168 std::cout << PHWHERE << "singlePhotonClusterAna::process_event - Fatal Error - CLUSTER_CEMC node is missing. " << std::endl;
0169
0170 return 0;
0171 }
0172
0173
0174
0175 GlobalVertexMap *vtxContainer = findNode::getClass<GlobalVertexMap>(topNode,"GlobalVertexMap");
0176 if (!vtxContainer)
0177 {
0178 std::cout << PHWHERE << "singlePhotonClusterAna::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;
0179 assert(vtxContainer);
0180
0181 return 0;
0182 }
0183
0184 if (vtxContainer->empty())
0185 {
0186 std::cout << PHWHERE << "singlePhotonClusterAna::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;
0187 return 0;
0188 }
0189
0190
0191 GlobalVertex *vtx = vtxContainer->begin()->second;
0192 if(!vtx)
0193 {
0194
0195 std::cout << PHWHERE << "singlePhotonClusterAna::process_event Could not find vtx from vtxContainer" << std::endl;
0196 return Fun4AllReturnCodes::ABORTEVENT;
0197 }
0198
0199
0200 RawTowerGeomContainer *towergeom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
0201 if (!towergeom)
0202 {
0203 std::cout << PHWHERE << "singlePhotonClusterAna::process_event Could not find node TOWERGEOM_CEMC" << std::endl;
0204 return Fun4AllReturnCodes::ABORTEVENT;
0205 }
0206
0207
0208 RawTowerContainer *towerContainer = findNode::getClass<RawTowerContainer>(topNode,"TOWER_CALIB_CEMC");
0209 if(!towerContainer)
0210 {
0211 std::cout << PHWHERE << "singlePhotonClusterAna::process_event Could not find node TOWER_CALIB_CEMC" << std::endl;
0212 return Fun4AllReturnCodes::ABORTEVENT;
0213 }
0214
0215
0216 PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
0217 if(!truthinfo)
0218 {
0219 std::cout << PHWHERE << "singlePhotonClusterAna::process_event Could not find node G4TruthInfo" << std::endl;
0220 return Fun4AllReturnCodes::ABORTEVENT;
0221 }
0222
0223
0224 float photonEta = -99999;
0225 float photonEtaMax = 1.1;
0226 TLorentzVector photon;
0227
0228 PHG4TruthInfoContainer::Range truthRange = truthinfo->GetPrimaryParticleRange();
0229 PHG4TruthInfoContainer::ConstIterator truthIter;
0230
0231 PHG4Particle *truthPar = NULL;
0232
0233 for(truthIter = truthRange.first; truthIter != truthRange.second; truthIter++)
0234 {
0235 truthPar = truthIter->second;
0236
0237
0238 if(truthPar -> get_pid() == 22 && truthPar -> get_parent_id() == 0)
0239 {
0240 photonEta = getEta(truthPar);
0241 if(abs(photonEta) >= photonEtaMax)
0242 {
0243 return 0;
0244 }
0245
0246
0247
0248
0249
0250
0251
0252 photon.SetPxPyPzE(truthPar -> get_px(), truthPar -> get_py(), truthPar -> get_pz(), truthPar -> get_e());
0253 }
0254 }
0255
0256
0257 int decay_vtx_idx = 0;
0258 int decay_vtx_idx1 = 0;
0259 int decay_vtx_idx2 = 0;
0260 bool first_decay_particle = false;
0261 bool second_decay_particle = false;
0262 bool decay_electron = false;
0263 bool decay_positron = false;
0264 int n_children = 0;
0265 TLorentzVector electron;
0266 TLorentzVector positron;
0267 bool isGoodEvent = true;
0268
0269 PHG4TruthInfoContainer::Range truthRangeDecay1 = truthinfo->GetSecondaryParticleRange();
0270 PHG4TruthInfoContainer::ConstIterator truthIterDecay1;
0271
0272
0273
0274 for(truthIterDecay1 = truthRangeDecay1.first; truthIterDecay1 != truthRangeDecay1.second; truthIterDecay1++)
0275 {
0276 PHG4Particle *decay = truthIterDecay1 -> second;
0277
0278 int dumparentid = decay -> get_parent_id();
0279 if(dumparentid == 1) {
0280 n_children++;
0281 if (! first_decay_particle) {
0282 first_decay_particle = true;
0283 decay_vtx_idx1 = decay->get_vtx_id();
0284 }
0285 else {
0286 second_decay_particle = true;
0287 decay_vtx_idx2 = decay->get_vtx_id();
0288 }
0289
0290
0291
0292
0293
0294
0295 }
0296 }
0297
0298 if (n_children != 2) isGoodEvent = false;
0299 if (!(first_decay_particle && second_decay_particle)) isGoodEvent = false;
0300 if (decay_vtx_idx1 != decay_vtx_idx2) isGoodEvent = false;
0301
0302
0303 for(truthIterDecay1 = truthRangeDecay1.first; truthIterDecay1 != truthRangeDecay1.second; truthIterDecay1++)
0304 {
0305 PHG4Particle *decay = truthIterDecay1 -> second;
0306
0307 int dumtruthpid = decay -> get_pid();
0308 int dumparentid = decay -> get_parent_id();
0309 if(dumparentid == 1) {
0310 if (dumtruthpid == 11) {
0311
0312 decay_electron = true;
0313 electron.SetPxPyPzE(decay -> get_px(), decay -> get_py(), decay -> get_pz(), decay -> get_e());
0314 }
0315 if (dumtruthpid == -11) {
0316
0317 decay_positron = true;
0318 positron.SetPxPyPzE(decay -> get_px(), decay -> get_py(), decay -> get_pz(), decay -> get_e());
0319 }
0320 }
0321 }
0322
0323 if (!(decay_electron && decay_positron)) isGoodEvent = false;
0324
0325
0326
0327
0328
0329
0330
0331 if (isGoodEvent) {
0332 m_photon_E.push_back(photon.Energy());
0333 m_photon_eta.push_back(photon.PseudoRapidity());
0334 m_photon_phi.push_back(photon.Phi());
0335 m_electron_E.push_back(electron.Energy());
0336 m_electron_eta.push_back(electron.PseudoRapidity());
0337 m_electron_phi.push_back(electron.Phi());
0338 m_positron_E.push_back(positron.Energy());
0339 m_positron_eta.push_back(positron.PseudoRapidity());
0340 m_positron_phi.push_back(positron.Phi());
0341
0342 decay_vtx_idx = decay_vtx_idx1;
0343 PHG4VtxPoint* decay_vtx = truthinfo->GetVtx(decay_vtx_idx);
0344 m_vtx_x.push_back(decay_vtx->get_x());
0345 m_vtx_y.push_back(decay_vtx->get_y());
0346 m_vtx_z.push_back(decay_vtx->get_z());
0347 m_vtx_t.push_back(decay_vtx->get_t());
0348 float vtx_x = decay_vtx->get_x();
0349 float vtx_y = decay_vtx->get_y();
0350 float vtx_r = sqrt(vtx_x*vtx_x + vtx_y*vtx_y);
0351 m_vtx_r.push_back(vtx_r);
0352 bool isConversionEvent = false;
0353 float EMCal_inner_radius = 95;
0354 if (vtx_r < EMCal_inner_radius) isConversionEvent = true;
0355 m_isConversionEvent.push_back(isConversionEvent);
0356
0357
0358
0359 }
0360 else {
0361 std::cout << "\nGreg info:\nBad conversion event\n";
0362 std::cout << "n_children = " << n_children << "\n";
0363 std::cout << "first_decay_particle = " << first_decay_particle << "; second_decay_particle = " << second_decay_particle << "\n";
0364 std::cout << "decay_vtx_idx1 = " << decay_vtx_idx1 << "; decay_vtx_idx2 = " << decay_vtx_idx2 << "\n";
0365 std::cout << "decay_electron = " << decay_electron << "; decay_positron = " << decay_positron << "\n";
0366 return 0;
0367 }
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440 RawTowerContainer::ConstRange tower_range = towerContainer -> getTowers();
0441 for(RawTowerContainer::ConstIterator tower_iter = tower_range.first; tower_iter!= tower_range.second; tower_iter++)
0442 {
0443 int phibin = tower_iter -> second -> get_binphi();
0444 int etabin = tower_iter -> second -> get_bineta();
0445 double phi = towergeom -> get_phicenter(phibin);
0446 double eta = towergeom -> get_etacenter(etabin);
0447 double energy = tower_iter -> second -> get_energy();
0448
0449 m_phi_center.push_back(phi);
0450 m_eta_center.push_back(eta);
0451 m_tower_energy.push_back(energy);
0452 }
0453
0454
0455 RawClusterContainer::ConstRange clusterEnd = clusterContainer -> getClusters();
0456 RawClusterContainer::ConstIterator clusterIter;
0457
0458 for(clusterIter = clusterEnd.first; clusterIter != clusterEnd.second; clusterIter++)
0459 {
0460 RawCluster *recoCluster = clusterIter -> second;
0461
0462 CLHEP::Hep3Vector vertex(vtx->get_x(), vtx->get_y(), vtx->get_z());
0463
0464 CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*recoCluster, vertex);
0465 float clusE = E_vec_cluster.mag();
0466 float clusEcore = recoCluster->get_ecore();
0467 float clus_eta = E_vec_cluster.pseudoRapidity();
0468 float clus_phi = E_vec_cluster.phi();
0469
0470 m_cluster_eta.push_back(clus_eta);
0471 m_cluster_phi.push_back(clus_phi);
0472 m_cluster_e.push_back(clusE);
0473 m_cluster_ecore.push_back(clusEcore);
0474
0475 m_cluster_chi2.push_back(recoCluster -> get_chi2());
0476 m_cluster_prob.push_back(recoCluster -> get_prob());
0477 m_cluster_nTowers.push_back(recoCluster -> getNTowers());
0478 }
0479
0480
0481 clusters_Towers -> Fill();
0482 truth_photon -> Fill();
0483 conversion -> Fill();
0484
0485
0486 return Fun4AllReturnCodes::EVENT_OK;
0487 }
0488
0489
0490 int singlePhotonClusterAna::ResetEvent(PHCompositeNode *topNode)
0491 {
0492
0493
0494 m_eta_center.clear();
0495 m_phi_center.clear();
0496 m_tower_energy.clear();
0497 m_cluster_eta.clear();
0498 m_cluster_phi.clear();
0499 m_cluster_e.clear();
0500 m_cluster_chi2.clear();
0501 m_cluster_prob.clear();
0502 m_cluster_nTowers.clear();
0503 m_photon_E.clear();
0504 m_photon_eta.clear();
0505 m_photon_phi.clear();
0506 m_electron_E.clear();
0507 m_electron_eta.clear();
0508 m_electron_phi.clear();
0509 m_positron_E.clear();
0510 m_positron_eta.clear();
0511 m_positron_phi.clear();
0512 m_vtx_x.clear();
0513 m_vtx_y.clear();
0514 m_vtx_z.clear();
0515 m_vtx_t.clear();
0516 m_vtx_r.clear();
0517 m_isConversionEvent.clear();
0518 return Fun4AllReturnCodes::EVENT_OK;
0519 }
0520
0521
0522 int singlePhotonClusterAna::EndRun(const int runnumber)
0523 {
0524 std::cout << "singlePhotonClusterAna::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
0525 return Fun4AllReturnCodes::EVENT_OK;
0526 }
0527
0528
0529 int singlePhotonClusterAna::End(PHCompositeNode *topNode)
0530 {
0531 std::cout << "singlePhotonClusterAna::End(PHCompositeNode *topNode) This is the End..." << std::endl;
0532 out -> cd();
0533
0534 truth_photon -> Write();
0535 clusters_Towers -> Write();
0536 conversion -> Write();
0537
0538 out -> Close();
0539 delete out;
0540
0541 hm -> dumpHistos(Outfile.c_str(),"UPDATE");
0542
0543
0544 return Fun4AllReturnCodes::EVENT_OK;
0545 }
0546
0547
0548 int singlePhotonClusterAna::Reset(PHCompositeNode *topNode)
0549 {
0550 std::cout << "singlePhotonClusterAna::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
0551 return Fun4AllReturnCodes::EVENT_OK;
0552 }
0553
0554
0555 void singlePhotonClusterAna::Print(const std::string &what) const
0556 {
0557 std::cout << "singlePhotonClusterAna::Print(const std::string &what) const Printing info for " << what << std::endl;
0558 }
0559
0560 float singlePhotonClusterAna::getEta(PHG4Particle *particle)
0561 {
0562 float px = particle -> get_px();
0563 float py = particle -> get_py();
0564 float pz = particle -> get_pz();
0565 float p = sqrt(pow(px,2) + pow(py,2) + pow(pz,2));
0566
0567 return 0.5*log((p+pz)/(p-pz));
0568 }