File indexing completed on 2025-12-16 09:18:08
0001 #include "CaloOnly.h"
0002
0003 #include <calobase/RawTowerContainer.h>
0004 #include <calobase/RawTower.h>
0005 #include <calobase/RawClusterContainer.h>
0006 #include <calobase/RawTowerGeomContainer.h>
0007 #include <calobase/RawCluster.h>
0008 #include <calobase/RawClusterUtility.h>
0009 #include <calobase/RawTowerDefs.h>
0010 #include <calobase/RawTowerGeom.h>
0011 #include <calobase/TowerInfoContainer.h>
0012 #include <calobase/TowerInfo.h>
0013 #include <calobase/TowerInfoDefs.h>
0014
0015 #include <fun4all/Fun4AllReturnCodes.h>
0016
0017 #include <globalvertex/GlobalVertex.h>
0018 #include <globalvertex/GlobalVertexMap.h>
0019 #include <globalvertex/SvtxVertexMap.h>
0020 #include <globalvertex/SvtxVertex.h>
0021
0022 #include <phool/getClass.h>
0023 #include <phool/PHCompositeNode.h>
0024
0025 #include <trackbase/TrkrCluster.h>
0026 #include <trackbase/TrkrClusterContainer.h>
0027 #include <trackbase/TrkrDefs.h>
0028 #include <trackbase_historic/SvtxTrackMap.h>
0029 #include <trackbase_historic/SvtxTrackState_v1.h>
0030 #include <trackbase_historic/TrackSeedContainer.h>
0031 #include <trackbase_historic/TrackSeed.h>
0032 #include <trackreco/ActsPropagator.h>
0033
0034 #include <Acts/Geometry/GeometryIdentifier.hpp>
0035 #include <Acts/MagneticField/ConstantBField.hpp>
0036 #include <Acts/MagneticField/MagneticFieldProvider.hpp>
0037 #include <Acts/Surfaces/CylinderSurface.hpp>
0038 #include <Acts/Surfaces/PerigeeSurface.hpp>
0039 #include <Acts/Geometry/TrackingGeometry.hpp>
0040
0041 #include <CLHEP/Vector/ThreeVector.h>
0042 #include <math.h>
0043 #include <vector>
0044
0045 #include <TFile.h>
0046 #include <TTree.h>
0047 #include <TH1F.h>
0048 #include <TH2F.h>
0049
0050
0051 CaloOnly::CaloOnly(const std::string &name, const std::string &file):
0052 SubsysReco(name),
0053 _outfilename(file),
0054 _outfile(nullptr),
0055 _tree(nullptr)
0056 {
0057 std::cout << "CaloOnly::CaloOnly(const std::string &name) Calling ctor" << std::endl;
0058 }
0059
0060
0061 CaloOnly::~CaloOnly()
0062 {
0063 std::cout << "CaloOnly::~CaloOnly() Calling dtor" << std::endl;
0064 }
0065
0066
0067 int CaloOnly::Init(PHCompositeNode *topNode)
0068 {
0069 std::cout << topNode << std::endl;
0070 std::cout << "CaloOnly::Init(PHCompositeNode *topNode) Initializing" << std::endl;
0071 _outfile = new TFile(_outfilename.c_str(), "RECREATE");
0072 delete _tree;
0073
0074 _tree = new TTree("tree", "A tree with track/calo info");
0075 _tree->Branch("_run_test", &_run_test);
0076
0077 _tree->Branch("_emcalgeo_id", &_emcalgeo_id);
0078 _tree->Branch("_emcalgeo_phibin", &_emcalgeo_phibin);
0079 _tree->Branch("_emcalgeo_etabin", &_emcalgeo_etabin);
0080
0081 _tree->Branch("_emcal_e", &_emcal_e);
0082 _tree->Branch("_emcal_phi", &_emcal_phi);
0083 _tree->Branch("_emcal_eta", &_emcal_eta);
0084 _tree->Branch("_emcal_iphi", &_emcal_iphi);
0085 _tree->Branch("_emcal_ieta", &_emcal_ieta);
0086 _tree->Branch("_emcal_time", &_emcal_time);
0087 _tree->Branch("_emcal_chi2", &_emcal_chi2);
0088 _tree->Branch("_emcal_pedestal", &_emcal_pedestal);
0089
0090 _tree->Branch("_ihcal_e", &_ihcal_e);
0091 _tree->Branch("_ihcal_phi", &_ihcal_phi);
0092 _tree->Branch("_ihcal_eta", &_ihcal_eta);
0093 _tree->Branch("_ihcal_iphi", &_ihcal_iphi);
0094 _tree->Branch("_ihcal_ieta", &_ihcal_ieta);
0095 _tree->Branch("_ihcal_time", &_ihcal_time);
0096 _tree->Branch("_ihcal_chi2", &_ihcal_chi2);
0097 _tree->Branch("_ihcal_pedestal", &_ihcal_pedestal);
0098
0099 _tree->Branch("_ohcal_e", &_ohcal_e);
0100 _tree->Branch("_ohcal_phi", &_ohcal_phi);
0101 _tree->Branch("_ohcal_eta", &_ohcal_eta);
0102 _tree->Branch("_ohcal_iphi", &_ohcal_iphi);
0103 _tree->Branch("_ohcal_ieta", &_ohcal_ieta);
0104 _tree->Branch("_ohcal_time", &_ohcal_time);
0105 _tree->Branch("_ohcal_chi2", &_ohcal_chi2);
0106 _tree->Branch("_ohcal_pedestal", &_ohcal_pedestal);
0107
0108
0109 _tree->Branch("_emcal_cluster_id", &_emcal_cluster_id);
0110 _tree->Branch("_emcal_cluster_e", &_emcal_cluster_e);
0111 _tree->Branch("_emcal_cluster_phi", &_emcal_cluster_phi);
0112 _tree->Branch("_emcal_cluster_eta", &_emcal_cluster_eta);
0113 _tree->Branch("_emcal_cluster_x", &_emcal_cluster_x);
0114 _tree->Branch("_emcal_cluster_y", &_emcal_cluster_y);
0115 _tree->Branch("_emcal_cluster_z", &_emcal_cluster_z);
0116 _tree->Branch("_emcal_cluster_R", &_emcal_cluster_R);
0117 _tree->Branch("_emcal_cluster_ecore", &_emcal_cluster_ecore);
0118 _tree->Branch("_emcal_cluster_chi2", &_emcal_cluster_chi2);
0119 _tree->Branch("_emcal_cluster_prob", &_emcal_cluster_prob);
0120
0121 _tree->Branch("_emcal_clusfull_e", &_emcal_clusfull_e);
0122 _tree->Branch("_emcal_clusfull_eta", &_emcal_clusfull_eta);
0123 _tree->Branch("_emcal_clusfull_phi", &_emcal_clusfull_phi);
0124 _tree->Branch("_emcal_clusfull_x", &_emcal_clusfull_x);
0125 _tree->Branch("_emcal_clusfull_y", &_emcal_clusfull_y);
0126 _tree->Branch("_emcal_clusfull_z", &_emcal_clusfull_z);
0127 _tree->Branch("_emcal_clusfull_R", &_emcal_clusfull_R);
0128 _tree->Branch("_emcal_clusfull_pt", &_emcal_clusfull_pt);
0129
0130 _tree->Branch("_emcal_cluscore_e", &_emcal_cluscore_e);
0131 _tree->Branch("_emcal_cluscore_eta", &_emcal_cluscore_eta);
0132 _tree->Branch("_emcal_cluscore_phi", &_emcal_cluscore_phi);
0133 _tree->Branch("_emcal_cluscore_x", &_emcal_cluscore_x);
0134 _tree->Branch("_emcal_cluscore_y", &_emcal_cluscore_y);
0135 _tree->Branch("_emcal_cluscore_z", &_emcal_cluscore_z);
0136 _tree->Branch("_emcal_cluscore_R", &_emcal_cluscore_R);
0137 _tree->Branch("_emcal_cluscore_pt", &_emcal_cluscore_pt);
0138
0139 _tree->Branch("_mbd_z", &_mbd_z);
0140
0141 return Fun4AllReturnCodes::EVENT_OK;
0142 }
0143
0144
0145 int CaloOnly::process_event(PHCompositeNode *topNode)
0146 {
0147 bool hasMBDvertex = true;
0148
0149 GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
0150 if (!vertexmap)
0151 {
0152 std::cout << "CaloOnly::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;
0153
0154
0155 hasMBDvertex = false;
0156 }
0157
0158 if (vertexmap->empty())
0159 {
0160 std::cout << "CaloOnly::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;
0161
0162 hasMBDvertex = false;
0163 }
0164
0165 GlobalVertex *vtx = vertexmap->begin()->second;
0166 if (vtx == nullptr)
0167 {
0168 hasMBDvertex = false;
0169 }
0170
0171 if(hasMBDvertex == true)
0172 {
0173 _mbd_z.push_back(vtx->get_z());
0174 }
0175
0176
0177
0178
0179
0180
0181 towerGeom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
0182 if (!towerGeom)
0183 {
0184 std::cout << "CaloOnly::process_event: Cannot find CEMC RawTowerGeomContainer!" << std::endl;
0185 }
0186
0187
0188 clustersEM = findNode::getClass<RawClusterContainer>(topNode, "CLUSTERINFO_CEMC");
0189 if (!clustersEM)
0190 {
0191 std::cout << "CaloOnly::process_event: cannot find cluster container " << "CLUSTERINFO_CEMC" << std::endl;
0192 }
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 EMCAL_Container = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC");
0209 if(!EMCAL_Container)
0210 {
0211 std::cout << "CaloOnly::process_event: TOWERINFO_CALIB_CEMC not found!!!" << std::endl;
0212 }
0213
0214 IHCAL_Container = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN");
0215 if(!IHCAL_Container)
0216 {
0217 std::cout << "CaloOnly::process_event: TOWERINFO_CALIB_HCALIN not found! Aborting!" << std::endl;
0218 return Fun4AllReturnCodes::ABORTEVENT;
0219 }
0220
0221 OHCAL_Container = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT");
0222 if(!OHCAL_Container)
0223 {
0224 std::cout << "OHCAL_Container not found! Aborting!" << std::endl;
0225 return Fun4AllReturnCodes::ABORTEVENT;
0226 }
0227
0228
0229
0230 EMCalGeo = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
0231 if(!EMCalGeo)
0232 {
0233 std::cout << "CaloOnly::process_event: TOWERGEOM_CEMC not found!!!" << std::endl;
0234 }
0235
0236 IHCalGeo = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
0237 if(!IHCalGeo)
0238 {
0239 std::cout << "CaloOnly::process_event: TOWERGEOM_HCALIN not found!!!" << std::endl;
0240 }
0241
0242 OHCalGeo = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
0243 if(!OHCalGeo)
0244 {
0245 std::cout << "CaloOnly::process_event: TOWERGEOM_HCALOUT not found!!!" << std::endl;
0246 }
0247
0248
0249
0250
0251
0252
0253
0254
0255 ResetTreeVectors();
0256
0257 _run_test.push_back(1);
0258 FillTree();
0259
0260
0261
0262 return Fun4AllReturnCodes::EVENT_OK;
0263 }
0264
0265
0266 int CaloOnly::End(PHCompositeNode *topNode)
0267 {
0268 std::cout << topNode << std::endl;
0269 _outfile->cd();
0270 _outfile->Write();
0271 _outfile->Close();
0272 return Fun4AllReturnCodes::EVENT_OK;
0273 }
0274
0275 void CaloOnly::ResetTreeVectors()
0276 {
0277 _run_test.clear();
0278
0279 _emcalgeo_id.clear();
0280 _emcalgeo_phibin.clear();
0281 _emcalgeo_etabin.clear();
0282
0283 _emcal_e.clear();
0284 _emcal_phi.clear();
0285 _emcal_eta.clear();
0286 _emcal_iphi.clear();
0287 _emcal_ieta.clear();
0288 _emcal_time.clear();
0289 _emcal_chi2.clear();
0290 _emcal_pedestal.clear();
0291
0292
0293 _ihcal_e.clear();
0294 _ihcal_phi.clear();
0295 _ihcal_eta.clear();
0296 _ihcal_iphi.clear();
0297 _ihcal_ieta.clear();
0298 _ihcal_time.clear();
0299 _ihcal_chi2.clear();
0300 _ihcal_pedestal.clear();
0301
0302
0303 _ohcal_e.clear();
0304 _ohcal_phi.clear();
0305 _ohcal_eta.clear();
0306 _ohcal_iphi.clear();
0307 _ohcal_ieta.clear();
0308 _ohcal_time.clear();
0309 _ohcal_chi2.clear();
0310 _ohcal_pedestal.clear();
0311
0312
0313 _emcal_cluster_id.clear();
0314 _emcal_cluster_e.clear();
0315 _emcal_cluster_phi.clear();
0316 _emcal_cluster_eta.clear();
0317 _emcal_cluster_x.clear();
0318 _emcal_cluster_y.clear();
0319 _emcal_cluster_z.clear();
0320 _emcal_cluster_ecore.clear();
0321 _emcal_cluster_chi2.clear();
0322 _emcal_cluster_prob.clear();
0323
0324
0325 _emcal_clusfull_e.clear();
0326 _emcal_clusfull_eta.clear();
0327 _emcal_clusfull_phi.clear();
0328 _emcal_clusfull_x.clear();
0329 _emcal_clusfull_y.clear();
0330 _emcal_clusfull_z.clear();
0331 _emcal_clusfull_pt.clear();
0332
0333
0334 _emcal_cluscore_e.clear();
0335 _emcal_cluscore_eta.clear();
0336 _emcal_cluscore_phi.clear();
0337 _emcal_cluscore_x.clear();
0338 _emcal_cluscore_y.clear();
0339 _emcal_cluscore_z.clear();
0340 _emcal_cluscore_pt.clear();
0341 }
0342
0343
0344
0345 void CaloOnly::FillTree()
0346 {
0347 if (!clustersEM || !EMCAL_Container || !EMCalGeo || !IHCalGeo || !OHCalGeo || !IHCAL_Container || !OHCAL_Container )
0348 {
0349 std::cout << PHWHERE << "missing node trees, can't continue with track calo matching"
0350 << std::endl;
0351 return;
0352 }
0353
0354
0355 for (unsigned int i = 0; i < EMCalGeo->size(); i++)
0356 {
0357 RawTowerGeom* geom = EMCalGeo->get_tower_geometry(i);
0358 if (!geom) continue;
0359 std::cout<<"rawtower id is: "<<geom->get_id()<<std::endl;
0360
0361 std::cout << "Tower ID: " << i
0362 << std::endl;
0363 }
0364
0365
0366 TowerInfo *tInfo = nullptr;
0367
0368 for(unsigned int iem = 0; iem < EMCAL_Container->size(); iem++)
0369 {
0370 tInfo = EMCAL_Container->get_tower_at_channel(iem);
0371
0372 if(!tInfo)
0373 {
0374 continue;
0375 }
0376
0377 if(!tInfo->get_isGood())
0378 {
0379 continue;
0380 }
0381
0382
0383
0384 unsigned int towerinfo_key = EMCAL_Container->encode_key(iem);
0385 int ti_ieta = EMCAL_Container->getTowerEtaBin(towerinfo_key);
0386 int ti_iphi = EMCAL_Container->getTowerPhiBin(towerinfo_key);
0387
0388 const RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(RawTowerDefs::CalorimeterId::CEMC, ti_ieta, ti_iphi);
0389 RawTowerGeom *tower_geom = EMCalGeo->get_tower_geometry(key);
0390
0391
0392
0393
0394
0395
0396 _emcal_e.push_back(tInfo->get_energy());
0397 _emcal_phi.push_back(tower_geom->get_phi());
0398 _emcal_eta.push_back(tower_geom->get_eta());
0399 _emcal_iphi.push_back(ti_iphi);
0400 _emcal_ieta.push_back(ti_ieta);
0401 _emcal_time.push_back(tInfo->get_time());
0402 _emcal_chi2.push_back(tInfo->get_chi2());
0403 _emcal_pedestal.push_back(tInfo->get_pedestal());
0404 }
0405
0406 for(unsigned int ihcal = 0; ihcal < IHCAL_Container->size(); ihcal++)
0407 {
0408 tInfo = IHCAL_Container->get_tower_at_channel(ihcal);
0409
0410 if(!tInfo)
0411 {
0412 continue;
0413 }
0414
0415 if(!tInfo->get_isGood())
0416 {
0417 continue;
0418 }
0419
0420
0421
0422 unsigned int towerinfo_key = IHCAL_Container->encode_key(ihcal);
0423 int ti_ieta = IHCAL_Container->getTowerEtaBin(towerinfo_key);
0424 int ti_iphi = IHCAL_Container->getTowerPhiBin(towerinfo_key);
0425
0426 const RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(RawTowerDefs::CalorimeterId::HCALIN, ti_ieta, ti_iphi);
0427 RawTowerGeom *tower_geom = IHCalGeo->get_tower_geometry(key);
0428
0429 _ihcal_e.push_back(tInfo->get_energy());
0430 _ihcal_phi.push_back(tower_geom->get_phi());
0431 _ihcal_eta.push_back(tower_geom->get_eta());
0432 _ihcal_iphi.push_back(ti_iphi);
0433 _ihcal_ieta.push_back(ti_ieta);
0434 _ihcal_time.push_back(tInfo->get_time());
0435 _ihcal_chi2.push_back(tInfo->get_chi2());
0436 _ihcal_pedestal.push_back(tInfo->get_pedestal());
0437 }
0438
0439 for(unsigned int ohcal = 0; ohcal < OHCAL_Container->size(); ohcal++)
0440 {
0441 tInfo = OHCAL_Container->get_tower_at_channel(ohcal);
0442
0443 if(!tInfo)
0444 {
0445 continue;
0446 }
0447
0448 if(!tInfo->get_isGood())
0449 {
0450 continue;
0451 }
0452
0453
0454
0455 unsigned int towerinfo_key = OHCAL_Container->encode_key(ohcal);
0456 int ti_ieta = OHCAL_Container->getTowerEtaBin(towerinfo_key);
0457 int ti_iphi = OHCAL_Container->getTowerPhiBin(towerinfo_key);
0458
0459 const RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(RawTowerDefs::CalorimeterId::HCALOUT, ti_ieta, ti_iphi);
0460 RawTowerGeom *tower_geom = OHCalGeo->get_tower_geometry(key);
0461
0462 _ohcal_e.push_back(tInfo->get_energy());
0463 _ohcal_phi.push_back(tower_geom->get_phi());
0464 _ohcal_eta.push_back(tower_geom->get_eta());
0465 _ohcal_iphi.push_back(ti_iphi);
0466 _ohcal_ieta.push_back(ti_ieta);
0467 _ohcal_time.push_back(tInfo->get_time());
0468 _ohcal_chi2.push_back(tInfo->get_chi2());
0469 _ohcal_pedestal.push_back(tInfo->get_pedestal());
0470 }
0471
0472
0473 CLHEP::Hep3Vector vertex(0., 0., 0.);
0474
0475 RawCluster *cluster = nullptr;
0476
0477 RawClusterContainer::Range begin_end_EMC = clustersEM->getClusters();
0478 RawClusterContainer::Iterator clusIter_EMC;
0479 for (clusIter_EMC = begin_end_EMC.first; clusIter_EMC != begin_end_EMC.second; ++clusIter_EMC)
0480 {
0481 cluster = clusIter_EMC->second;
0482 if(cluster->get_energy() < m_emcal_e_low_cut) continue;
0483
0484
0485 _emcal_cluster_id.push_back(clusIter_EMC->first);
0486 _emcal_cluster_e.push_back(cluster->get_energy());
0487 _emcal_cluster_phi.push_back(RawClusterUtility::GetAzimuthAngle(*cluster, vertex));
0488 _emcal_cluster_eta.push_back(RawClusterUtility::GetPseudorapidity(*cluster, vertex));
0489 _emcal_cluster_x.push_back(cluster->get_x());
0490 _emcal_cluster_y.push_back(cluster->get_y());
0491 _emcal_cluster_z.push_back(cluster->get_z());
0492 _emcal_cluster_ecore.push_back(cluster->get_ecore());
0493 _emcal_cluster_chi2.push_back(cluster->get_chi2());
0494 _emcal_cluster_prob.push_back(cluster->get_prob());
0495
0496
0497 CLHEP::Hep3Vector E_vec_cluster_Full = RawClusterUtility::GetEVec(*cluster, vertex);
0498 float clusE = E_vec_cluster_Full.mag();
0499 float clus_eta = E_vec_cluster_Full.pseudoRapidity();
0500 float clus_phi = E_vec_cluster_Full.phi();
0501 float clus_x = E_vec_cluster_Full.x();
0502 float clus_y = E_vec_cluster_Full.y();
0503 float clus_z = E_vec_cluster_Full.z();
0504 float clus_pt = E_vec_cluster_Full.perp();
0505
0506 _emcal_clusfull_e.push_back(clusE);
0507 _emcal_clusfull_eta.push_back(clus_eta);
0508 _emcal_clusfull_phi.push_back(clus_phi);
0509 _emcal_clusfull_x.push_back(clus_x);
0510 _emcal_clusfull_y.push_back(clus_y);
0511 _emcal_clusfull_z.push_back(clus_z);
0512 _emcal_clusfull_pt.push_back(clus_pt);
0513
0514
0515
0516
0517 CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*cluster, vertex);
0518 float clusEcore = E_vec_cluster.mag();
0519 float clus_coreeta = E_vec_cluster.pseudoRapidity();
0520 float clus_corephi = E_vec_cluster.phi();
0521 float clus_corex = E_vec_cluster.x();
0522 float clus_corey = E_vec_cluster.y();
0523 float clus_corez = E_vec_cluster.z();
0524 float clus_corept = E_vec_cluster.perp();
0525
0526 _emcal_cluscore_e.push_back(clusEcore);
0527 _emcal_cluscore_eta.push_back(clus_coreeta);
0528 _emcal_cluscore_phi.push_back(clus_corephi);
0529 _emcal_cluscore_x.push_back(clus_corex);
0530 _emcal_cluscore_y.push_back(clus_corey);
0531 _emcal_cluscore_z.push_back(clus_corez);
0532 _emcal_cluscore_pt.push_back(clus_corept);
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551 }
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614 _tree->Fill();
0615 }
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655