Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef FUN4ALL_NEW_HCALCOSMICS_C
0002 #define FUN4ALL_NEW_HCALCOSMICS_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> // for R__LOAD_LIBRARY
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_New_HCalCosmics(int nEvents = 100,
0044                              const std::string& inlist = "files.list",
0045                              const std::string &outfile = "DST_CALOFITTING_run2auau_ana487_2024p018_v001",
0046                              const std::string &outfile_hist1 = "HIST_COSMIC_HCALOUT_run2auau_ana487_2024p018_v001",
0047                              const std::string &outfile_hist2 = "HIST_COSMIC_HCALIN_run2auau_ana487_2024p018_v001",
0048                              const std::string &dbtag = "ProdA_2024")
0049 {
0050   bool useDSTRAW = true;
0051   // v1 uncomment:
0052   // CaloTowerDefs::BuilderType buildertype = CaloTowerDefs:::kPRDFTowerv1;
0053   // v2 uncomment:
0054   CaloTowerDefs::BuilderType buildertype = CaloTowerDefs::kWaveformTowerv2;
0055   // v3 uncomment:
0056 
0057   Fun4AllServer *se = Fun4AllServer::instance();
0058   se->Verbosity(1);
0059   se->VerbosityDownscale(1000);
0060 
0061   recoConsts *rc = recoConsts::instance();
0062 
0063   // conditions DB global tag
0064   rc->set_StringFlag("CDB_GLOBALTAG", dbtag);
0065   CDBInterface::instance()->Verbosity(1);
0066 
0067   FlagHandler *flag = new FlagHandler();
0068   se->registerSubsystem(flag);
0069 
0070   /////////////////
0071   // build towers
0072   CaloTowerBuilder *ctbIHCal = new CaloTowerBuilder("HCALINBUILDER");
0073   ctbIHCal->set_detector_type(CaloTowerDefs::HCALIN);
0074   ctbIHCal->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0075   ctbIHCal->set_builder_type(buildertype);
0076   ctbIHCal->set_nsamples(12);
0077   if (useDSTRAW) ctbIHCal->set_offlineflag();
0078   ctbIHCal->set_softwarezerosuppression(true, 200);
0079   se->registerSubsystem(ctbIHCal);
0080 
0081   CaloTowerBuilder *ctbOHCal = new CaloTowerBuilder("HCALOUTBUILDER");
0082   ctbOHCal->set_detector_type(CaloTowerDefs::HCALOUT);
0083   ctbOHCal->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0084   ctbOHCal->set_builder_type(buildertype);
0085   ctbOHCal->set_nsamples(12);
0086   if (useDSTRAW) ctbOHCal->set_offlineflag();
0087   ctbOHCal->set_softwarezerosuppression(true, 200);
0088   se->registerSubsystem(ctbOHCal);
0089 
0090   CaloTowerStatus *statusHCalIn = new CaloTowerStatus("HCALINSTATUS");
0091   statusHCalIn->set_detector_type(CaloTowerDefs::HCALIN);
0092   statusHCalIn->set_time_cut(10);
0093   se->registerSubsystem(statusHCalIn);
0094 
0095   CaloTowerStatus *statusHCALOUT = new CaloTowerStatus("HCALOUTSTATUS");
0096   statusHCALOUT->set_detector_type(CaloTowerDefs::HCALOUT);
0097   statusHCALOUT->set_time_cut(10);
0098   se->registerSubsystem(statusHCALOUT);
0099 
0100   ////////////////////
0101   // Calibrate towers
0102   std::cout << "Calibrating OHcal" << std::endl;
0103   CaloTowerCalib *calibOHCal = new CaloTowerCalib("HCALOUT");
0104   calibOHCal->set_detector_type(CaloTowerDefs::HCALOUT);
0105   se->registerSubsystem(calibOHCal);
0106 
0107   std::cout << "Calibrating IHcal" << std::endl;
0108   CaloTowerCalib *calibIHCal = new CaloTowerCalib("HCALIN");
0109   calibIHCal->set_detector_type(CaloTowerDefs::HCALIN);
0110   se->registerSubsystem(calibIHCal);
0111 
0112   // loop over all files in file list and create an input manager for each one
0113   Fun4AllInputManager *In = nullptr;
0114   std::ifstream infile;
0115   infile.open(inlist);
0116   int iman = 0;
0117   std::string line;
0118   bool first{true};
0119   int runnumber = 0;
0120   int segment = 99999;
0121   if (infile.is_open())
0122   {
0123     while (std::getline(infile, line))
0124     {
0125       if (line[0] == '#')
0126       {
0127         std::cout << "found commented out line " << line << std::endl;
0128         continue;
0129       }
0130       // extract run number from first not commented out file in list
0131       if (first)
0132       {
0133     std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(line);
0134         runnumber = runseg.first;
0135         segment = runseg.second;
0136         rc->set_uint64Flag("TIMESTAMP", runnumber);
0137         first = false;
0138       }
0139       std::string magname = "DSTin_" + std::to_string(iman);
0140       In = new Fun4AllDstInputManager(magname);
0141       In->Verbosity(1);
0142       In->AddFile(line);
0143       se->registerInputManager(In);
0144       iman++;
0145     }
0146     infile.close();
0147   }
0148   std::cout << "Adding Geometry file" << std::endl;
0149   Fun4AllInputManager *intrue2 = new Fun4AllRunNodeInputManager("DST_GEO");
0150   std::string geoLocation = CDBInterface::instance()->getUrl("calo_geo");
0151   intrue2->AddFile(geoLocation);
0152   se->registerInputManager(intrue2);
0153 
0154   ///////////////////////////////////////////
0155   // Cosmics histMaker
0156  std::string outfile_hist = std::format("{}-{:08}-{:05}.root",outfile_hist2, runnumber, segment);
0157   HCalCosmics *wt2 = new HCalCosmics("HCalCalib_HCALIN", outfile_hist);
0158   wt2->set_tower_threshold(0.2498);  // 500*0.0004996=0.2498
0159   wt2->set_vert_threshold(0.2498);   // 500*0.0004996=0.2498
0160   wt2->set_veto_threshold(0.17486);  // 350*0.0004996=0.17486
0161   wt2->HistBinWidth(0.01);
0162   wt2->Detector("HCALIN");
0163   wt2->TowerPrefix("TOWERINFO_CALIB_");
0164   se->registerSubsystem(wt2);
0165 
0166   outfile_hist = std::format("{}-{:08}-{:05}.root",outfile_hist1, runnumber, segment);
0167   HCalCosmics *wt3 = new HCalCosmics("HCalCosmics_HCALOUT", outfile_hist);
0168   wt3->set_tower_threshold(1.665);  // 500*0.00333=1.665
0169   wt3->set_vert_threshold(1.665);   // 500*0.00333=1.665
0170   wt3->set_veto_threshold(1.1655);  // 350*0.00333=1.1655
0171   wt3->HistBinWidth(0.05);
0172   wt3->Detector("HCALOUT");
0173   wt3->TowerPrefix("TOWERINFO_CALIB_");
0174   se->registerSubsystem(wt3);
0175 
0176   // this strips all nodes under the Packets PHCompositeNode
0177   // (means removes all offline packets)
0178   std::string dstoutfile = std::format("{}-{:08}-{:05}.root", outfile, runnumber, segment);
0179   Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", dstoutfile);
0180   out->StripCompositeNode("Packets");
0181   se->registerOutputManager(out);
0182 
0183   se->run(nEvents);
0184   se->End();
0185   CDBInterface::instance()->Print();  // print used DB files
0186   se->PrintTimer();
0187   delete se;
0188 
0189   std::cout << "All done!" << std::endl;
0190   gSystem->Exit(0);
0191 }
0192 
0193 #endif