File indexing completed on 2025-08-03 08:13:03
0001
0002 #include "EpFinderEval.h"
0003
0004 #include <phool/phool.h>
0005 #include <phool/getClass.h>
0006
0007 #include <fun4all/Fun4AllReturnCodes.h>
0008 #include <fun4all/PHTFileServer.h>
0009 #include <fun4all/Fun4AllServer.h>
0010
0011 #include <g4main/PHG4HitContainer.h>
0012 #include <g4main/PHG4Hit.h>
0013 #include <g4main/PHG4TruthInfoContainer.h>
0014 #include <g4main/PHG4VtxPoint.h>
0015 #include <g4main/PHG4Particle.h>
0016
0017 #include <calobase/RawTowerDefs.h>
0018 #include <calobase/RawTowerContainer.h>
0019 #include <calobase/RawTower.h>
0020 #include <calobase/RawTowerGeomContainer.h>
0021 #include <calobase/RawTowerGeom.h>
0022 #include <calobase/RawClusterContainer.h>
0023 #include <calobase/RawCluster.h>
0024
0025 #include <phhepmc/PHHepMCGenEventMap.h>
0026 #include <phhepmc/PHHepMCGenEvent.h>
0027 #include <HepMC/GenEvent.h>
0028 #include <HepMC/GenParticle.h>
0029 #include <HepMC/HeavyIon.h>
0030
0031 #include <TTree.h>
0032 #include <TH2D.h>
0033 #include <TVector3.h>
0034 #include <TRandom3.h>
0035 #include <TMath.h>
0036
0037 #include <iostream>
0038 #include <utility>
0039
0040 #define TOWER_E_CUT 0.0
0041
0042 #include "EpFinder.h"
0043
0044 using namespace std;
0045
0046 double XYtoPhi(double x, double y)
0047 {
0048
0049 Double_t phi = atan2(y,x);
0050 if(phi<-TMath::Pi()) phi += TMath::TwoPi();
0051 if(phi>=TMath::Pi()) phi -= TMath::TwoPi();
0052 return phi;
0053 }
0054
0055 double XYtoPhi_02PI(double x, double y)
0056 {
0057
0058 Double_t phi = atan2(y,x);
0059 if(phi<0.0) phi += TMath::TwoPi();
0060 if(phi>=TMath::TwoPi()) phi -= TMath::TwoPi();
0061 return phi;
0062 }
0063
0064 double getEta(double pt, double pz){
0065 float theta = XYtoPhi(pz,pt);
0066 float eta = -log(tan(theta/2.0));
0067 return eta;
0068 }
0069
0070 double DeltaPhi(double phi1, double phi2){
0071 Double_t dphi;
0072 dphi = phi1 - phi2;
0073 if(dphi<-TMath::Pi()) dphi += TMath::TwoPi();
0074 if(dphi>=TMath::Pi()) dphi -= TMath::TwoPi();
0075 return dphi;
0076 }
0077
0078
0079
0080
0081
0082
0083 EpFinderEval::EpFinderEval(const string &name) :
0084 SubsysReco(name), _eval_tree_event(NULL) {
0085
0086 _event = 0;
0087 _outfile_name = "EpFinder_Eval.root";
0088 RpFinder = NULL;
0089 RpFinderL = NULL;
0090 RpFinderR = NULL;
0091 primRpFinder = NULL;
0092 fprimRpFinder = NULL;
0093
0094 }
0095
0096
0097
0098
0099
0100 int EpFinderEval::Init(PHCompositeNode *topNode) {
0101
0102 cout << PHWHERE << " Opening file " << _outfile_name << endl;
0103 PHTFileServer::get().open(_outfile_name, "RECREATE");
0104
0105 _eval_tree_event = new TTree("event", "FastSim Eval => event parameters");
0106 _eval_tree_event->Branch("event", &_event, "_event/I");
0107 _eval_tree_event->Branch("rplane_angle", &rplane_angle, "rplane_angle/F");
0108 _eval_tree_event->Branch("bimpact", &bimpact, "bimpact/F");
0109 _eval_tree_event->Branch("prim_rplane_angle", &prim_rplane_angle, "prim_rplane_angle/F");
0110
0111 _eval_tree_event->Branch("fprim_rplane_angle", &fprim_rplane_angle, "fprim_rplane_angle/F");
0112 _eval_tree_event->Branch("fprim_phiweighted_rplane_angle", &fprim_phiweighted_rplane_angle, "fprim_phiweighted_rplane_angle/F");
0113 _eval_tree_event->Branch("fprim_phiweightedandshifted_rplane_angle", &fprim_phiweightedandshifted_rplane_angle, "fprim_phiweightedandshifted_rplane_angle/F");
0114
0115 _eval_tree_event->Branch("rfprim_rplane_angle", &rfprim_rplane_angle, "rfprim_rplane_angle/F");
0116 _eval_tree_event->Branch("rfprim_phiweighted_rplane_angle", &rfprim_phiweighted_rplane_angle, "rfprim_phiweighted_rplane_angle/F");
0117 _eval_tree_event->Branch("rfprim_phiweightedandshifted_rplane_angle", &rfprim_phiweightedandshifted_rplane_angle, "rfprim_phiweightedandshifted_rplane_angle/F");
0118
0119 _eval_tree_event->Branch("femc_raw_rplane_angle", &femc_raw_rplane_angle, "femc_raw_rplane_angle/F");
0120 _eval_tree_event->Branch("femc_phiweighted_rplane_angle", &femc_phiweighted_rplane_angle, "femc_phiweighted_rplane_angle/F");
0121 _eval_tree_event->Branch("femc_phiweightedandshifted_rplane_angle", &femc_phiweightedandshifted_rplane_angle, "femc_phiweightedandshifted_rplane_angle/F");
0122
0123 _eval_tree_event->Branch("rfemc_raw_rplane_angle", &rfemc_raw_rplane_angle, "rfemc_raw_rplane_angle/F");
0124 _eval_tree_event->Branch("rfemc_phiweighted_rplane_angle", &rfemc_phiweighted_rplane_angle, "rfemc_phiweighted_rplane_angle/F");
0125 _eval_tree_event->Branch("rfemc_phiweightedandshifted_rplane_angle", &rfemc_phiweightedandshifted_rplane_angle, "rfemc_phiweightedandshifted_rplane_angle/F");
0126
0127 _eval_tree_event->Branch("femcL_raw_rplane_angle", &femcL_raw_rplane_angle, "femcL_raw_rplane_angle/F");
0128 _eval_tree_event->Branch("femcL_phiweighted_rplane_angle", &femcL_phiweighted_rplane_angle, "femcL_phiweighted_rplane_angle/F");
0129 _eval_tree_event->Branch("femcL_phiweightedandshifted_rplane_angle", &femcL_phiweightedandshifted_rplane_angle, "femcL_phiweightedandshifted_rplane_angle/F");
0130
0131 _eval_tree_event->Branch("femcR_raw_rplane_angle", &femcR_raw_rplane_angle, "femcR_raw_rplane_angle/F");
0132 _eval_tree_event->Branch("femcR_phiweighted_rplane_angle", &femcR_phiweighted_rplane_angle, "femcR_phiweighted_rplane_angle/F");
0133 _eval_tree_event->Branch("femcR_phiweightedandshifted_rplane_angle", &femcR_phiweightedandshifted_rplane_angle, "femcR_phiweightedandshifted_rplane_angle/F");
0134
0135 RpFinder = new EpFinder(4,"EpFinderCorrectionHistograms_OUTPUT.root", "EpFinderCorrectionHistograms_INPUT.root", 181, 181);
0136 RpFinder->SetnMipThreshold(0.0);
0137 RpFinder->SetMaxTileWeight(100.0);
0138 cout << RpFinder->Report() << endl;
0139
0140 rRpFinder = new EpFinder(4,"rEpFinderCorrectionHistograms_OUTPUT.root", "rEpFinderCorrectionHistograms_INPUT.root", 181, 181);
0141 rRpFinder->SetnMipThreshold(0.0);
0142 rRpFinder->SetMaxTileWeight(100.0);
0143 cout << rRpFinder->Report() << endl;
0144
0145 RpFinderL = new EpFinder(4, "L_EpFinderCorrectionHistograms_OUTPUT.root", "L_EpFinderCorrectionHistograms_INPUT.root", 181, 181);
0146 RpFinderL->SetnMipThreshold(0.0);
0147 RpFinderL->SetMaxTileWeight(100.0);
0148 cout << RpFinderL->Report() << endl;
0149
0150 RpFinderR = new EpFinder(4, "R_EpFinderCorrectionHistograms_OUTPUT.root", "R_EpFinderCorrectionHistograms_INPUT.root", 181, 181);
0151 RpFinderR->SetnMipThreshold(0.0);
0152 RpFinderR->SetMaxTileWeight(100.0);
0153 cout << RpFinderR->Report() << endl;
0154
0155 primRpFinder = new EpFinder(1, "primEpFinderCorrectionHistograms_OUTPUT.root", "primEpFinderCorrectionHistograms_INPUT.root");
0156 cout << primRpFinder->Report() << endl;
0157
0158 fprimRpFinder = new EpFinder(1, "fprimEpFinderCorrectionHistograms_OUTPUT.root", "fprimEpFinderCorrectionHistograms_INPUT.root",
0159 FPRIM_PHI_BINS, FPRIM_ETA_BINS);
0160 cout << fprimRpFinder->Report() << endl;
0161
0162 rfprimRpFinder = new EpFinder(1, "rfprimEpFinderCorrectionHistograms_OUTPUT.root", "rfprimEpFinderCorrectionHistograms_INPUT.root",
0163 FPRIM_PHI_BINS, RFPRIM_ETA_BINS);
0164 cout << rfprimRpFinder->Report() << endl;
0165
0166 return Fun4AllReturnCodes::EVENT_OK;
0167 }
0168
0169 int EpFinderEval::InitRun(PHCompositeNode *topNode) {
0170
0171
0172 return Fun4AllReturnCodes::EVENT_OK;
0173
0174 }
0175
0176
0177
0178
0179
0180
0181
0182 int EpFinderEval::process_event(PHCompositeNode *topNode) {
0183 _event++;
0184
0185 GetNodes(topNode);
0186
0187 fill_tree(topNode);
0188
0189 return Fun4AllReturnCodes::EVENT_OK;
0190 }
0191
0192
0193
0194
0195
0196 int EpFinderEval::End(PHCompositeNode *topNode) {
0197
0198 PHTFileServer::get().cd(_outfile_name);
0199
0200 _eval_tree_event->Write();
0201
0202 RpFinder->Finish();
0203 rRpFinder->Finish();
0204 RpFinderL->Finish();
0205 RpFinderR->Finish();
0206 primRpFinder->Finish();
0207 fprimRpFinder->Finish();
0208
0209 delete RpFinder;
0210 delete rRpFinder;
0211 delete RpFinderL;
0212 delete RpFinderR;
0213 delete primRpFinder;
0214 delete fprimRpFinder;
0215
0216 return Fun4AllReturnCodes::EVENT_OK;
0217 }
0218
0219 int EpFinderEval::GetPhiBin(float tphi, float numPhiDivisions)
0220 {
0221
0222
0223
0224 float sphi = (TMath::TwoPi()/numPhiDivisions);
0225
0226 if(tphi>=TMath::TwoPi()){
0227 tphi -= TMath::TwoPi();
0228 }
0229 else if(tphi<0.0){
0230 tphi += TMath::TwoPi();
0231 }
0232
0233 return (int)(tphi/sphi);
0234
0235 }
0236
0237 int EpFinderEval::GetEtaBin(float teta, float eta_low, float eta_high, float numEtaDivisions)
0238 {
0239
0240
0241
0242 float seta = fabs((eta_high-eta_low)/numEtaDivisions);
0243
0244 return (int)((teta-eta_low)/seta);
0245
0246 }
0247
0248
0249
0250
0251
0252
0253
0254 void EpFinderEval::fill_tree(PHCompositeNode *topNode) {
0255
0256
0257
0258 static bool first = true;
0259
0260 if(first){
0261
0262 for(int i=0; i<PHI_BINS; i++){
0263 phi_list[i].clear();
0264 rphi_list[i].clear();
0265 }
0266
0267 for(int i=0; i<FPRIM_PHI_BINS; i++){
0268 fprim_phi_list[i].clear();
0269 rfprim_phi_list[i].clear();
0270 }
0271
0272
0273
0274
0275
0276 RawTowerDefs::CalorimeterId calo_id_ = RawTowerDefs::convert_name_to_caloid( "FEMC" );
0277
0278 for (int twr_j = 0; twr_j< 181; twr_j++){
0279 for (int twr_k = 0; twr_k< 181; twr_k++){
0280 RawTowerDefs::keytype towerid = RawTowerDefs::encode_towerid( calo_id_, twr_j+500, twr_k+500 );
0281 RawTowerGeom *tgeo = towergeom->get_tower_geometry(towerid);
0282 if(tgeo){
0283 int idx = GetPhiBin(tgeo->get_phi(), PHI_BINS);
0284 std::pair<int,int> newPair(tgeo->get_column()-500,tgeo->get_row()-500);
0285 phi_list[idx].push_back(newPair);
0286 if(tgeo->get_eta()<2.4) rphi_list[idx].push_back(newPair);
0287 }
0288 }
0289 }
0290
0291
0292
0293 for(int i=0; i<FPRIM_PHI_BINS; i++){
0294 for(int j=0; j<FPRIM_ETA_BINS; j++){
0295 std::pair<int,int> newPair(i,j);
0296 fprim_phi_list[i].push_back(newPair);
0297 }
0298 for(int j=0; j<RFPRIM_ETA_BINS; j++){
0299 std::pair<int,int> newPair(i,j);
0300 rfprim_phi_list[i].push_back(newPair);
0301 }
0302 }
0303
0304 first = false;
0305 }
0306
0307
0308
0309 rplane_angle = -9999.0;
0310
0311 PHNodeIterator iter(topNode);
0312 PHHepMCGenEventMap *genevent_map = findNode::getClass<PHHepMCGenEventMap>(topNode,"PHHepMCGenEventMap");
0313 if(genevent_map){
0314
0315 PHHepMCGenEvent *genevent = (genevent_map->begin())->second;
0316 if(genevent){
0317 HepMC::GenEvent *event = genevent->getEvent();
0318 HepMC::HeavyIon *hi = event->heavy_ion();
0319 rplane_angle = hi->event_plane_angle();
0320 bimpact = hi->impact_parameter();
0321 }
0322 }
0323
0324
0325
0326
0327
0328 std::vector<EpHit> phits;
0329 phits.clear();
0330
0331 std::vector<EpHit> fphits;
0332 fphits.clear();
0333
0334 std::vector<EpHit> rfphits;
0335 rfphits.clear();
0336
0337 PHG4TruthInfoContainer::ConstRange range = _truth_container->GetPrimaryParticleRange();
0338
0339 for (PHG4TruthInfoContainer::ConstIterator truth_itr = range.first;
0340 truth_itr != range.second; ++truth_itr) {
0341
0342 PHG4Particle* g4particle = truth_itr->second;
0343 if(!g4particle) {
0344 continue;
0345 }
0346
0347
0348
0349
0350
0351
0352
0353 if ((abs(g4particle->get_pid()) >= 12) && (abs( g4particle->get_pid()) <= 16)) continue;
0354
0355
0356 if ((g4particle->get_px() == 0.0) && (g4particle->get_px() == 0.0)) continue;
0357
0358 TVector3 partMom(g4particle->get_px(),g4particle->get_py(),g4particle->get_pz());
0359 if ( (partMom.Eta() >= -1.0) &&
0360 (partMom.Eta() <= 1.0)) {
0361
0362 EpHit newHit;
0363
0364 newHit.nMip = 1;
0365 newHit.phi = partMom.Phi();
0366 newHit.samePhi = NULL;
0367
0368 phits.push_back(newHit);
0369 }
0370
0371 if ( (partMom.Eta() >= 1.4) &&
0372 (partMom.Eta() < 4.0)) {
0373
0374 EpHit newHit;
0375
0376 newHit.nMip = 1;
0377 newHit.phi = partMom.Phi();
0378 newHit.ix = GetPhiBin(partMom.Phi(), FPRIM_PHI_BINS);
0379 newHit.iy = GetEtaBin(partMom.Eta(), 1.4, 4.0, FPRIM_ETA_BINS);
0380 newHit.samePhi = &fprim_phi_list[newHit.ix];
0381
0382 fphits.push_back(newHit);
0383 }
0384
0385 if ( (partMom.Eta() >= 1.4) &&
0386 (partMom.Eta() < 2.4)) {
0387
0388 EpHit newHit;
0389
0390 newHit.nMip = 1;
0391 newHit.phi = partMom.Phi();
0392 newHit.ix = GetPhiBin(partMom.Phi(), FPRIM_PHI_BINS);
0393 newHit.iy = GetEtaBin(partMom.Eta(), 1.4, 2.4, RFPRIM_ETA_BINS);
0394 newHit.samePhi = &rfprim_phi_list[newHit.ix];
0395
0396 rfphits.push_back(newHit);
0397 }
0398
0399
0400 }
0401
0402 EpInfo primRpResult = primRpFinder->Results(&phits,0);
0403
0404 prim_rplane_angle = primRpResult.RawPsi(2);
0405
0406 EpInfo fprimRpResult = fprimRpFinder->Results(&fphits,0);
0407
0408 fprim_rplane_angle = fprimRpResult.RawPsi(2);
0409 fprim_phiweighted_rplane_angle = fprimRpResult.PhiWeightedPsi(2);
0410 fprim_phiweightedandshifted_rplane_angle = fprimRpResult.PhiWeightedAndShiftedPsi(2);
0411
0412 EpInfo rfprimRpResult = rfprimRpFinder->Results(&rfphits,0);
0413
0414 rfprim_rplane_angle = rfprimRpResult.RawPsi(2);
0415 rfprim_phiweighted_rplane_angle = rfprimRpResult.PhiWeightedPsi(2);
0416 rfprim_phiweightedandshifted_rplane_angle = rfprimRpResult.PhiWeightedAndShiftedPsi(2);
0417
0418 phits.clear();
0419 fphits.clear();
0420 rfphits.clear();
0421
0422
0423
0424
0425
0426 std::vector<EpHit> hits;
0427 hits.clear();
0428
0429 std::vector<EpHit> rhits;
0430 rhits.clear();
0431
0432 std::vector<EpHit> hitsL;
0433 hitsL.clear();
0434
0435 std::vector<EpHit> hitsR;
0436 hitsR.clear();
0437
0438 RawTowerContainer::ConstRange begin_end = towers->getTowers();
0439 RawTowerContainer::ConstIterator itr = begin_end.first;
0440 for (; itr != begin_end.second; ++itr) {
0441 RawTowerDefs::keytype towerid = itr->first;
0442 RawTower *rawtower = towers->getTower(towerid);
0443 if(rawtower) {
0444 if(rawtower->get_energy()>TOWER_E_CUT) {
0445
0446 RawTowerGeom *tgeo = towergeom->get_tower_geometry(towerid);
0447
0448 EpHit newHit;
0449
0450
0451 newHit.nMip = rawtower->get_energy();
0452 newHit.phi = tgeo->get_phi();
0453 newHit.ix = tgeo->get_column() - 500;
0454 newHit.iy = tgeo->get_row() - 500;
0455
0456 int idx = GetPhiBin(tgeo->get_phi(), PHI_BINS);
0457 newHit.samePhi = &phi_list[idx];
0458
0459 hits.push_back(newHit);
0460 if((idx>=(PHI_BINS/4))&&(idx<(3*PHI_BINS/4)))
0461 hitsL.push_back(newHit);
0462 else
0463 hitsR.push_back(newHit);
0464
0465 if( tgeo->get_eta()<2.4 ) {
0466 newHit.samePhi = &rphi_list[idx];
0467 rhits.push_back(newHit);
0468 }
0469
0470 }
0471 }
0472
0473 }
0474
0475
0476
0477 int ev_class = 0;
0478 if((bimpact>=0.0) && (bimpact<4.0))
0479 ev_class = 0;
0480 else if((bimpact>=4.0)&&(bimpact<8.0))
0481 ev_class = 1;
0482 else if((bimpact>=8.0)&&(bimpact<14.0))
0483 ev_class = 2;
0484 else
0485 ev_class = 3;
0486
0487
0488
0489 EpInfo RpResult = RpFinder->Results(&hits,ev_class);
0490
0491 femc_raw_rplane_angle = RpResult.RawPsi(2);
0492 femc_phiweighted_rplane_angle = RpResult.PhiWeightedPsi(2);
0493 femc_phiweightedandshifted_rplane_angle = RpResult.PhiWeightedAndShiftedPsi(2);
0494
0495 EpInfo rRpResult = rRpFinder->Results(&rhits,ev_class);
0496
0497 rfemc_raw_rplane_angle = rRpResult.RawPsi(2);
0498 rfemc_phiweighted_rplane_angle = rRpResult.PhiWeightedPsi(2);
0499 rfemc_phiweightedandshifted_rplane_angle = rRpResult.PhiWeightedAndShiftedPsi(2);
0500
0501 EpInfo RpResultL = RpFinderL->Results(&hitsL,ev_class);
0502
0503 femcL_raw_rplane_angle = RpResultL.RawPsi(2);
0504 femcL_phiweighted_rplane_angle = RpResultL.PhiWeightedPsi(2);
0505 femcL_phiweightedandshifted_rplane_angle = RpResultL.PhiWeightedAndShiftedPsi(2);
0506
0507 EpInfo RpResultR = RpFinderR->Results(&hitsR,ev_class);
0508
0509 femcR_raw_rplane_angle = RpResultR.RawPsi(2);
0510 femcR_phiweighted_rplane_angle = RpResultR.PhiWeightedPsi(2);
0511 femcR_phiweightedandshifted_rplane_angle = RpResultR.PhiWeightedAndShiftedPsi(2);
0512
0513 _eval_tree_event->Fill();
0514
0515 hits.clear();
0516 hitsL.clear();
0517 hitsR.clear();
0518
0519 return;
0520
0521 }
0522
0523
0524
0525
0526
0527 int EpFinderEval::GetNodes(PHCompositeNode * topNode) {
0528
0529
0530 _truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode,
0531 "G4TruthInfo");
0532 if (!_truth_container) {
0533 cout << PHWHERE << " PHG4TruthInfoContainer node not found on node tree"
0534 << endl;
0535 return Fun4AllReturnCodes::ABORTEVENT;
0536 }
0537
0538 string towernodename = "TOWER_CALIB_FEMC";
0539
0540 towers = findNode::getClass<RawTowerContainer>(topNode, towernodename.c_str());
0541 if (!towers)
0542 {
0543 std::cout << PHWHERE << ": Could not find node " << towernodename.c_str() << std::endl;
0544 return Fun4AllReturnCodes::ABORTEVENT;
0545 }
0546
0547 string towergeomnodename = "TOWERGEOM_FEMC";
0548 towergeom = findNode::getClass<RawTowerGeomContainer>(topNode, towergeomnodename.c_str());
0549 if (!towergeom)
0550 {
0551 cout << PHWHERE << ": Could not find node " << towergeomnodename.c_str() << endl;
0552 return Fun4AllReturnCodes::ABORTEVENT;
0553 }
0554
0555 return Fun4AllReturnCodes::EVENT_OK;
0556 }
0557