Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-18 09:22:11

0001 #ifndef FUN4ALL_EMCAL_C
0002 #define FUN4ALL_EMCAL_C
0003 
0004 
0005 #include <cdbobjects/CDBTTree.h>  // for CDBTTree
0006 
0007 #include <litecaloeval/LiteCaloEval.h>
0008 
0009 #include <calib_emc_pi0/pi0EtaByEta.h>
0010 
0011 #include <zdcinfo/ZdcReco.h>
0012 
0013 #include<caloana/CaloTemp.h>
0014 
0015 #include <calotrigger/MinimumBiasClassifier.h>
0016 #include <calotrigger/TriggerRunInfoReco.h>
0017 
0018 #include <caloreco/CaloTowerCalib.h>
0019 #include <caloreco/CaloTowerStatus.h>
0020 #include <caloreco/RawClusterBuilderTemplate.h>
0021 #include <caloreco/RawClusterPositionCorrection.h>
0022 #include <caloreco/CaloTowerBuilder.h>
0023 
0024 #include <centrality/CentralityInfo.h>
0025 
0026 #include <ffamodules/CDBInterface.h>
0027 #include <ffamodules/FlagHandler.h>
0028 #include <ffamodules/HeadReco.h>
0029 #include <ffamodules/SyncReco.h>
0030 
0031 #include <fun4allraw/Fun4AllPrdfInputManager.h>
0032 
0033 #include <fun4all/Fun4AllDstInputManager.h>
0034 #include <fun4all/Fun4AllDstOutputManager.h>
0035 #include <fun4all/Fun4AllInputManager.h>
0036 #include <fun4all/Fun4AllRunNodeInputManager.h>
0037 #include <fun4all/Fun4AllServer.h>
0038 #include <fun4all/Fun4AllUtils.h>
0039 #include <fun4all/SubsysReco.h>
0040 
0041 #include <phool/recoConsts.h>
0042 
0043 #include <Rtypes.h> // for R__LOAD_LIBRARY macro
0044 #include <TSystem.h>
0045 
0046 #include <format>
0047 #include <fstream>
0048 
0049 R__LOAD_LIBRARY(libcdbobjects)
0050 R__LOAD_LIBRARY(libfun4all.so)
0051 R__LOAD_LIBRARY(libfun4allraw.so)
0052 R__LOAD_LIBRARY(libcalo_reco.so)
0053 R__LOAD_LIBRARY(libffamodules.so)
0054 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
0055 R__LOAD_LIBRARY(libcalibCaloEmc_pi0.so)
0056 R__LOAD_LIBRARY(libcalotrigger.so)
0057 R__LOAD_LIBRARY(libcentrality.so)
0058 R__LOAD_LIBRARY(libzdcinfo.so)
0059 R__LOAD_LIBRARY(libcalotemp.so)
0060 
0061 void createLocalEMCalCalibFile(const std::string &fname, int runNumber);
0062 std::string findCosmicCalib(int runnumber);
0063 std::string findCosmicCalib_ihcal(int runnumber);
0064 std::string findRunByRunCalib(int runnumber);
0065 
0066 
0067 
0068 void Fun4All_HCal(int nevents = 1e3, const std::string &fname = "inputdata.txt")
0069 {
0070 
0071   Fun4AllServer *se = Fun4AllServer::instance();
0072   se->Verbosity(0);
0073   CDBInterface::instance()->Verbosity(1);
0074 
0075   // se->Verbosity(verbosity);
0076   recoConsts *rc = recoConsts::instance();
0077 
0078   std::ifstream file(fname);
0079   std::string first_file;
0080   getline(file, first_file);
0081 
0082   //===============
0083   // conditions DB flags
0084   //===============
0085   std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first_file);
0086   int runnumber = runseg.first;
0087   std::cout << "run number = " << runnumber << std::endl;
0088 
0089   rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024");
0090   rc->set_uint64Flag("TIMESTAMP", runnumber);
0091 
0092   Fun4AllInputManager *in = new Fun4AllDstInputManager("DST_TOWERS");
0093   in->AddListFile(fname);
0094   se->registerInputManager(in);
0095 
0096   //std::string calib_fname = findCosmicCalib(runnumber); 
0097   std::string calib_fname = findRunByRunCalib(runnumber); 
0098 
0099 
0100   //////////////////////
0101   // calibrate towers - takes raw towers and calibrate thems
0102   CaloTowerCalib *calibEMC = new CaloTowerCalib("CEMCCALIB");
0103   calibEMC->set_detector_type(CaloTowerDefs::HCALOUT);
0104   //calibEMC->setFieldName("ohcal_cosmic_calibration");
0105   //calibEMC->set_directURL(calib_fname.c_str());
0106   se->registerSubsystem(calibEMC);
0107 
0108   // get file paths for local calibrations
0109   calib_fname = findCosmicCalib_ihcal(runnumber); 
0110 
0111   CaloTowerCalib *calibIhcal= new CaloTowerCalib("CEMCCALIB");
0112   calibIhcal->set_detector_type(CaloTowerDefs::HCALIN);
0113   //calibIhcal->setFieldName("ihcal_cosmic_calibration"); // change fild if needed 
0114   //calibIhcal->set_directURL(calib_fname.c_str());
0115   se->registerSubsystem(calibIhcal);
0116 
0117   std::string filename = first_file.substr(first_file.find_last_of("/\\") + 1);
0118   std::string OutFile = std::format("OUTHIST_OHCAL_{}" , filename);
0119   std::string OutFile2 = std::format("OUTHIST_IHCAL_{}" , filename);
0120 
0121   ///////////////////
0122   // Histmakers
0123   // makes tower energy spectra for general use and 
0124   // the tower slope code.
0125   LiteCaloEval *eval7e = new LiteCaloEval("CEMCEVALUATOR1", "CEMC",OutFile);
0126   eval7e->CaloType(LiteCaloEval::HCALOUT);
0127   eval7e->setInputTowerNodeName("TOWERINFO_CALIB_HCALOUT");
0128   eval7e->set_reqMinBias(true);
0129   se->registerSubsystem(eval7e);
0130 
0131   LiteCaloEval *eval7e2 = new LiteCaloEval("CEMCEVALUATOR2", "CEMC2",OutFile2);
0132   eval7e2->CaloType(LiteCaloEval::HCALIN);
0133   eval7e2->setInputTowerNodeName("TOWERINFO_CALIB_HCALIN");
0134   eval7e2->set_reqMinBias(true);
0135   se->registerSubsystem(eval7e2);
0136 
0137 
0138   /////////////////////////////////////////
0139   // Use this handy code to get a temperature hist of
0140   // the requested hcal for the log closest to the start
0141   // of the trun. Because many DB calls seem to colide, only
0142   // submit 1 job per a run. 
0143   //////////////////////////////////////////
0144   //  CaloTemp* calotemp = new CaloTemp("CALOTEMP",std::format("ohcal_temp_hist_{}.root",runnumber));
0145   //  calotemp->Detector("HCALOUT");
0146   //  se->registerSubsystem(calotemp);
0147 
0148   //  CaloTemp* calotemp2 = new CaloTemp("CALOTEMP",std::format("ihcal_temp_hist_{}.root",runnumber));
0149   //  calotemp2->Detector("HCALIN");
0150   //  se->registerSubsystem(calotemp2);
0151   // se->run(1);
0152   // se->End();
0153   // return;
0154 
0155   se->run(nevents);
0156   se->End();
0157   se->PrintTimer();
0158   delete se;
0159 
0160   gSystem->Exec("echo DONE > DONE.txt");
0161 
0162   gSystem->Exit(0);
0163 }
0164 
0165 
0166 
0167 std::string findCosmicCalib(int runnumber){
0168 
0169   int cos_run[14] = {
0170     44732,
0171     45767,
0172     48795,
0173     49170,
0174     49478,
0175     50572,
0176     50758,
0177     51020,
0178     52930,
0179     53321,
0180     53883,
0181     54608,
0182     55061,
0183     55349
0184   };
0185 
0186  int target = 0;
0187   for (int ir=0; ir<14; ir++){
0188     if(runnumber < cos_run[ir]) break; 
0189     target=ir;
0190   }
0191   std::string path = std::format("/sphenix/u/bseidlitz/work/macros/calibrations/calo/hcal_towerSlope_y2/cosmicCalibFiles/ohcal_cosmic_calibration_%d.root",cos_run[target]); 
0192  std::cout << "path to calib " << path << std::endl;
0193 
0194  return path;
0195 }
0196 
0197 
0198 std::string findCosmicCalib_ihcal(int runnumber){
0199 
0200   int cos_run[14] = {
0201     44732,
0202     45767,
0203     48795,
0204     53883,
0205     54608
0206   };
0207 
0208  int target = 0;
0209   for (int ir=0; ir<14; ir++){
0210     if(runnumber < cos_run[ir]) break; 
0211     target=ir;
0212   }
0213   std::string path = std::format("/sphenix/u/bseidlitz/work/macros/calibrations/calo/hcal_towerSlope_y2/cosmicCalibFiles/ihcal_cosmic_calibration_%d.root",cos_run[target]); 
0214  std::cout << "path to calib " << path << std::endl;
0215 
0216  return path;
0217 }
0218 
0219 
0220 std::string findRunByRunCalib(int runnumber){
0221 
0222   std::ifstream runlist("/sphenix/u/bseidlitz/work/macros/calibrations/calo/hcal_towerSlope_y2/runDeptCalib/cdbFiles/runList.txt");
0223   if (!runlist){
0224     std::cout << "did not find runList for calibraiton" << std::endl;
0225   }
0226   std::string line;
0227 
0228   int minDelta = 10000000;
0229   int calibRunnumber = 0;
0230   while(getline(runlist,line))
0231   {
0232     int runnumber_calib = stoi(line);
0233     int delta = abs(runnumber - runnumber_calib);
0234 
0235     if( delta < minDelta){
0236      minDelta = delta;
0237      calibRunnumber = runnumber_calib;
0238    }
0239   }
0240   std::string cdbFile = std::format("/sphenix/u/bseidlitz/work/macros/calibrations/calo/hcal_towerSlope_y2/runDeptCalib/cdbFiles/cdb_ohcal_tsc_temp_cosmic_hh_{}.root",calibRunnumber);
0241  std::cout << " using run-by-run calibration " << cdbFile << std::endl;
0242   return cdbFile;
0243 }
0244 
0245 
0246 
0247 
0248 #endif