Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:01

0001 #ifndef FUN4ALL_HCALCOSMICSQA_C
0002 #define FUN4ALL_HCALCOSMICSQA_C
0003 
0004 #include <calovalid/CaloValid.h>
0005 
0006 #include <litecaloeval/HCalCosmics.h>
0007 
0008 #include <caloreco/CaloTowerBuilder.h>
0009 #include <caloreco/CaloTowerCalib.h>
0010 #include <caloreco/CaloTowerStatus.h>
0011 #include <caloreco/CaloWaveformProcessing.h>
0012 
0013 #include <ffamodules/CDBInterface.h>
0014 #include <ffamodules/FlagHandler.h>
0015 #include <ffamodules/HeadReco.h>
0016 #include <ffamodules/SyncReco.h>
0017 
0018 #include <fun4allraw/Fun4AllPrdfInputManager.h>
0019 
0020 #include <fun4all/Fun4AllDstInputManager.h>
0021 #include <fun4all/Fun4AllDstOutputManager.h>
0022 #include <fun4all/Fun4AllInputManager.h>
0023 #include <fun4all/Fun4AllRunNodeInputManager.h>
0024 #include <fun4all/Fun4AllServer.h>
0025 #include <fun4all/Fun4AllUtils.h>
0026 #include <fun4all/SubsysReco.h>
0027 
0028 #include <phool/recoConsts.h>
0029 
0030 #include <Rtypes.h>
0031 #include <TSystem.h>
0032 
0033 #include <format>
0034 #include <fstream>
0035 
0036 R__LOAD_LIBRARY(libfun4all.so)
0037 R__LOAD_LIBRARY(libfun4allraw.so)
0038 R__LOAD_LIBRARY(libcalo_reco.so)
0039 R__LOAD_LIBRARY(libcentrality.so)
0040 R__LOAD_LIBRARY(libffamodules.so)
0041 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
0042 
0043 void Fun4All_HCalCosmicsQA(int nEvents = 100,
0044                              const std::string& inlist = "files.list",
0045                              const std::string &outfile_hist1 = "HIST_COSMIC_HCALOUT_run2auau_ana487_2024p018_v001",
0046                              const std::string &outfile_hist2 = "HIST_COSMIC_HCALIN_run2auau_ana487_2024p018_v001",
0047                              const std::string &dbtag = "ProdA_2024")
0048 {
0049   bool useDSTRAW = true;
0050   // v1 uncomment:
0051   // CaloTowerDefs::BuilderType buildertype = CaloTowerDefs:::kPRDFTowerv1;
0052   // v2 uncomment:
0053   CaloTowerDefs::BuilderType buildertype = CaloTowerDefs::kWaveformTowerv2;
0054   // v3 uncomment:
0055 
0056   Fun4AllServer *se = Fun4AllServer::instance();
0057   se->Verbosity(1);
0058   se->VerbosityDownscale(1000);
0059 
0060   recoConsts *rc = recoConsts::instance();
0061 
0062   // conditions DB global tag
0063   rc->set_StringFlag("CDB_GLOBALTAG", dbtag);
0064   CDBInterface::instance()->Verbosity(1);
0065 
0066   FlagHandler *flag = new FlagHandler();
0067   se->registerSubsystem(flag);
0068 
0069   /////////////////
0070   // build towers
0071   CaloTowerBuilder *ctbIHCal = new CaloTowerBuilder("HCALINBUILDER");
0072   ctbIHCal->set_detector_type(CaloTowerDefs::HCALIN);
0073   ctbIHCal->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0074   ctbIHCal->set_builder_type(buildertype);
0075   ctbIHCal->set_nsamples(12);
0076   if (useDSTRAW) ctbIHCal->set_offlineflag();
0077   ctbIHCal->set_softwarezerosuppression(true, 200);
0078   se->registerSubsystem(ctbIHCal);
0079 
0080   CaloTowerBuilder *ctbOHCal = new CaloTowerBuilder("HCALOUTBUILDER");
0081   ctbOHCal->set_detector_type(CaloTowerDefs::HCALOUT);
0082   ctbOHCal->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0083   ctbOHCal->set_builder_type(buildertype);
0084   ctbOHCal->set_nsamples(12);
0085   if (useDSTRAW) ctbOHCal->set_offlineflag();
0086   ctbOHCal->set_softwarezerosuppression(true, 200);
0087   se->registerSubsystem(ctbOHCal);
0088 
0089   CaloTowerStatus *statusHCalIn = new CaloTowerStatus("HCALINSTATUS");
0090   statusHCalIn->set_detector_type(CaloTowerDefs::HCALIN);
0091   statusHCalIn->set_time_cut(10);
0092   se->registerSubsystem(statusHCalIn);
0093 
0094   CaloTowerStatus *statusHCALOUT = new CaloTowerStatus("HCALOUTSTATUS");
0095   statusHCALOUT->set_detector_type(CaloTowerDefs::HCALOUT);
0096   statusHCALOUT->set_time_cut(10);
0097   se->registerSubsystem(statusHCALOUT);
0098 
0099   ////////////////////
0100   // Calibrate towers
0101   std::cout << "Calibrating OHcal" << std::endl;
0102   CaloTowerCalib *calibOHCal = new CaloTowerCalib("HCALOUT");
0103   calibOHCal->set_detector_type(CaloTowerDefs::HCALOUT);
0104   se->registerSubsystem(calibOHCal);
0105 
0106   std::cout << "Calibrating IHcal" << std::endl;
0107   CaloTowerCalib *calibIHCal = new CaloTowerCalib("HCALIN");
0108   calibIHCal->set_detector_type(CaloTowerDefs::HCALIN);
0109   se->registerSubsystem(calibIHCal);
0110 
0111   // loop over all files in file list and create an input manager for each one
0112   Fun4AllInputManager *In = nullptr;
0113   std::ifstream infile;
0114   infile.open(inlist);
0115   int iman = 0;
0116   std::string line;
0117   bool first{true};
0118   int runnumber = 0;
0119   int segment = 99999;
0120   if (infile.is_open())
0121   {
0122     while (std::getline(infile, line))
0123     {
0124       if (line[0] == '#')
0125       {
0126         std::cout << "found commented out line " << line << std::endl;
0127         continue;
0128       }
0129       // extract run number from first not commented out file in list
0130       if (first)
0131       {
0132     std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(line);
0133         runnumber = runseg.first;
0134         segment = runseg.second;
0135         rc->set_uint64Flag("TIMESTAMP", runnumber);
0136         first = false;
0137       }
0138       std::string magname = "DSTin_" + std::to_string(iman);
0139       In = new Fun4AllDstInputManager(magname);
0140       In->Verbosity(1);
0141       In->AddFile(line);
0142       se->registerInputManager(In);
0143       iman++;
0144     }
0145     infile.close();
0146   }
0147   std::cout << "Adding Geometry file" << std::endl;
0148   Fun4AllInputManager *intrue2 = new Fun4AllRunNodeInputManager("DST_GEO");
0149   std::string geoLocation = CDBInterface::instance()->getUrl("calo_geo");
0150   intrue2->AddFile(geoLocation);
0151   se->registerInputManager(intrue2);
0152 
0153   ///////////////////////////////////////////
0154   // Cosmics histMaker
0155   std::string outfile_hist = std::format("{}-{:08}-{:05}.root",outfile_hist2, runnumber, segment);
0156   HCalCosmics *wt2 = new HCalCosmics("HCalCalib_HCALIN", outfile_hist);
0157   wt2->set_tower_threshold(0.2498); 
0158   wt2->set_vert_threshold(0.2498);  
0159   wt2->set_veto_threshold(0.17486); 
0160   wt2->HistBinWidth(0.01);
0161   wt2->Detector("HCALIN");
0162   wt2->TowerPrefix("TOWERINFO_CALIB_");
0163   se->registerSubsystem(wt2);
0164 
0165   outfile_hist = std::format("{}-{:08}-{:05}.root",outfile_hist1, runnumber, segment);
0166   HCalCosmics *wt3 = new HCalCosmics("HCalCosmics_HCALOUT", outfile_hist);
0167   wt3->set_tower_threshold(1.665); 
0168   wt3->set_vert_threshold(1.665);  
0169   wt3->set_veto_threshold(1.1655); 
0170   wt3->HistBinWidth(0.05);
0171   wt3->Detector("HCALOUT");
0172   wt3->TowerPrefix("TOWERINFO_CALIB_");
0173   se->registerSubsystem(wt3);
0174 
0175 
0176   se->run(nEvents);
0177   se->End();
0178   CDBInterface::instance()->Print();  // print used DB files
0179   se->PrintTimer();
0180   delete se;
0181 
0182   std::cout << "All done!" << std::endl;
0183   gSystem->Exit(0);
0184 }
0185 
0186 #endif