Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:42

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