Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:07

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