Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:24

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     statusEMC->set_isSim(true);
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)
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