Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:23

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