Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 08:12:07

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