Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:01

0001 #ifndef CALO_CALIB_H
0002 #define CALO_CALIB_H
0003 
0004 #include <caloreco/CaloTowerCalib.h>
0005 #include <caloreco/CaloTowerStatus.h>
0006 #include <caloreco/RawClusterBuilderTemplate.h>
0007 #include <caloreco/RawClusterDeadHotMask.h>
0008 #include <caloreco/RawClusterPositionCorrection.h>
0009 
0010 #include <ffamodules/CDBInterface.h>
0011 #include <ffamodules/FlagHandler.h>
0012 
0013 #include <fun4all/Fun4AllInputManager.h>
0014 #include <fun4all/Fun4AllRunNodeInputManager.h>
0015 #include <fun4all/Fun4AllServer.h>  // for Fun4AllServer
0016 
0017 #include <phool/recoConsts.h>
0018 
0019 #include <TSystem.h>  // for gSystem
0020 
0021 R__LOAD_LIBRARY(libcalo_reco.so)
0022 R__LOAD_LIBRARY(libffamodules.so)
0023 R__LOAD_LIBRARY(libfun4allutils.so)
0024 
0025 void Process_Calo_Calib()
0026 {
0027   Fun4AllServer *se = Fun4AllServer::instance();
0028   recoConsts *rc = recoConsts::instance();
0029 
0030   /////////////////
0031   // set MC or data
0032   bool isSim = true;
0033   int data_sim_runnumber_thres = 1000;
0034   if (rc->get_uint64Flag("TIMESTAMP") > data_sim_runnumber_thres)
0035   {
0036     isSim = false;
0037   }
0038   std::cout << "Calo Calib uses runnumber " << rc->get_uint64Flag("TIMESTAMP") << std::endl;
0039 
0040   //////////////////////
0041   // Input geometry node
0042   std::cout << "Adding Geometry file" << std::endl;
0043   Fun4AllInputManager *ingeo = new Fun4AllRunNodeInputManager("DST_GEO");
0044   std::string geoLocation = CDBInterface::instance()->getUrl("calo_geo");
0045   ingeo->AddFile(geoLocation);
0046   se->registerInputManager(ingeo);
0047 
0048   //////////////////////////////
0049   // set statuses on raw towers
0050   std::cout << "status setters" << std::endl;
0051   CaloTowerStatus *statusEMC = new CaloTowerStatus("CEMCSTATUS");
0052   statusEMC->set_detector_type(CaloTowerDefs::CEMC);
0053   statusEMC->set_time_cut(1);
0054   // MC Towers Status
0055   if(isSim) {
0056     // Uses threshold of 50% for towers be considered frequently bad.
0057     std::string calibName_hotMap = "CEMC_hotTowers_status";
0058     /* Systematic options (to be used as needed). */
0059     /* Uses threshold of 40% for towers be considered frequently bad. */
0060     // std::string calibName_hotMap = "CEMC_hotTowers_status_40";
0061 
0062     /* Uses threshold of 60% for towers be considered frequently bad. */
0063     // std::string calibName_hotMap = "CEMC_hotTowers_status_60";
0064 
0065     std::string calibdir = CDBInterface::instance()->getUrl(calibName_hotMap);
0066     statusEMC->set_directURL_hotMap(calibdir);
0067   }
0068   se->registerSubsystem(statusEMC);
0069 
0070   CaloTowerStatus *statusHCalIn = new CaloTowerStatus("HCALINSTATUS");
0071   statusHCalIn->set_detector_type(CaloTowerDefs::HCALIN);
0072   statusHCalIn->set_time_cut(2);
0073   se->registerSubsystem(statusHCalIn);
0074 
0075   CaloTowerStatus *statusHCALOUT = new CaloTowerStatus("HCALOUTSTATUS");
0076   statusHCALOUT->set_detector_type(CaloTowerDefs::HCALOUT);
0077   statusHCALOUT->set_time_cut(2);
0078   se->registerSubsystem(statusHCALOUT);
0079 
0080   ////////////////////
0081   // Calibrate towers
0082   std::cout << "Calibrating EMCal" << std::endl;
0083   CaloTowerCalib *calibEMC = new CaloTowerCalib("CEMCCALIB");
0084   calibEMC->set_detector_type(CaloTowerDefs::CEMC);
0085   se->registerSubsystem(calibEMC);
0086 
0087   std::cout << "Calibrating OHcal" << std::endl;
0088   CaloTowerCalib *calibOHCal = new CaloTowerCalib("HCALOUT");
0089   calibOHCal->set_detector_type(CaloTowerDefs::HCALOUT);
0090   se->registerSubsystem(calibOHCal);
0091 
0092   std::cout << "Calibrating IHcal" << std::endl;
0093   CaloTowerCalib *calibIHCal = new CaloTowerCalib("HCALIN");
0094   calibIHCal->set_detector_type(CaloTowerDefs::HCALIN);
0095   se->registerSubsystem(calibIHCal);
0096 
0097   ////////////////
0098   // MC Calibration
0099   if (isSim && rc->get_uint64Flag("TIMESTAMP")<28) //in run28 and beyond we moved the MC calibration into the waveformsim module for data embedding
0100   {
0101     std::string MC_Calib = CDBInterface::instance()->getUrl("CEMC_MC_RECALIB");
0102     if (MC_Calib.empty())
0103     {
0104       std::cout << "No MC calibration found :( )" << std::endl;
0105       gSystem->Exit(0);
0106     }
0107     CaloTowerCalib *calibEMC_MC = new CaloTowerCalib("CEMCCALIB_MC");
0108     calibEMC_MC->set_detector_type(CaloTowerDefs::CEMC);
0109     calibEMC_MC->set_inputNodePrefix("TOWERINFO_CALIB_");
0110     calibEMC_MC->set_outputNodePrefix("TOWERINFO_CALIB_");
0111     calibEMC_MC->set_directURL(MC_Calib);
0112     calibEMC_MC->set_doCalibOnly(true);
0113     se->registerSubsystem(calibEMC_MC);
0114   }
0115 
0116   //////////////////
0117   // Clusters
0118   std::cout << "Building clusters" << std::endl;
0119   RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("EmcRawClusterBuilderTemplate");
0120   ClusterBuilder->Detector("CEMC");
0121   ClusterBuilder->set_threshold_energy(0.070);  // for when using basic calibration
0122   std::string emc_prof = getenv("CALIBRATIONROOT");
0123   emc_prof += "/EmcProfile/CEMCprof_Thresh30MeV.root";
0124   ClusterBuilder->LoadProfile(emc_prof);
0125   ClusterBuilder->set_UseTowerInfo(1);  // to use towerinfo objects rather than old RawTower
0126   ClusterBuilder->set_UseAltZVertex(1); // Use MBD Vertex for vertex-based corrections
0127   se->registerSubsystem(ClusterBuilder);
0128 
0129   // currently NOT included!
0130   // std::cout << "Applying Position Dependent Correction" << std::endl;
0131   // RawClusterPositionCorrection *clusterCorrection = new RawClusterPositionCorrection("CEMC");
0132   // clusterCorrection->set_UseTowerInfo(1);  // to use towerinfo objects rather than old RawTower
0133   // se->registerSubsystem(clusterCorrection);
0134 }
0135 
0136 #endif