Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:20

0001 #ifndef FUN4ALL_YEAR1_C
0002 #define FUN4ALL_YEAR1_C
0003 
0004 #include <caloreco/CaloTowerCalib.h>
0005 #include <caloreco/RawClusterBuilderTemplate.h>
0006 #include <caloreco/RawClusterDeadHotMask.h>
0007 #include <caloreco/RawClusterPositionCorrection.h>
0008 #include <caloreco/TowerInfoDeadHotMask.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 <globalvertex/GlobalVertexReco.h>
0025 #include <mbd/MbdReco.h>
0026 
0027 #include <phool/recoConsts.h>
0028 
0029 #include <cdbobjects/CDBTTree.h>  // for CDBTTree
0030 #include <ffamodules/CDBInterface.h>
0031 #include <GlobalVariables.C>
0032 
0033 #include <litecaloeval/LiteCaloEval.h>
0034 
0035 R__LOAD_LIBRARY(libcdbobjects)
0036 
0037 R__LOAD_LIBRARY(libfun4all.so)
0038 R__LOAD_LIBRARY(libfun4allraw.so)
0039 R__LOAD_LIBRARY(libcalo_reco.so)
0040 R__LOAD_LIBRARY(libffamodules.so)
0041 R__LOAD_LIBRARY(libmbd.so)
0042 R__LOAD_LIBRARY(libglobalvertex.so)
0043 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
0044 
0045 #include <caloana/CaloAna.h>
0046 R__LOAD_LIBRARY(libcaloana.so)
0047 
0048 void createLocalEMCalCalibFile(const string fname, int runNumber);
0049 
0050 
0051 
0052 
0053 void Fun4All_EMCal(int nevents = 0, const std::string &fname = "inputdata.txt",int iter = 0, const std::string &calib_fname="local_calib_copy.root")
0054 {
0055   bool enableMasking = 0;
0056 
0057   bool doFit = 0;
0058   bool doHistMake = 1;
0059 
0060   Fun4AllServer *se = Fun4AllServer::instance();
0061   se->Verbosity(0);
0062 
0063   // se->Verbosity(verbosity);
0064   recoConsts *rc = recoConsts::instance();
0065 
0066   ifstream file(fname);
0067   string first_file;
0068   getline(file, first_file);
0069 
0070   //===============
0071   // conditions DB flags
0072   //===============
0073   pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first_file);
0074   int runnumber = runseg.first;
0075   cout << "run number = " << runnumber << endl;
0076 
0077   // global tag
0078   rc->set_StringFlag("CDB_GLOBALTAG", "MDC2");
0079   // // 64 bit timestamp
0080   rc->set_uint64Flag("TIMESTAMP", runnumber);
0081 
0082   Fun4AllInputManager *in = new Fun4AllDstInputManager("DST_TOWERS");
0083   in->AddListFile(fname);
0084   se->registerInputManager(in);
0085 
0086   std::string filename = first_file.substr(first_file.find_last_of("/\\") + 1);
0087   std::string OutFile = Form("OUTHIST_iter%d_%s",iter , filename.c_str());
0088 
0089 
0090   if (iter == 0)
0091   {
0092     createLocalEMCalCalibFile(calib_fname.c_str(), runnumber);
0093     cout << "creating " << calib_fname.c_str() << " and exiting" << endl;
0094     return;
0095   }
0096 
0097   ////////////////////
0098   // Calibrate towers
0099   
0100   std::cout << "Calibrating EMCal" << std::endl;
0101   CaloTowerCalib *calibEMC = new CaloTowerCalib("CEMCCALIB");
0102   calibEMC->set_detector_type(CaloTowerDefs::CEMC);
0103   calibEMC->set_directURL(calib_fname.c_str());
0104   se->registerSubsystem(calibEMC);
0105 
0106 
0107   //////////////////
0108   // Clusters
0109   std::cout << "Building clusters" << std::endl;
0110   RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("EmcRawClusterBuilderTemplate");
0111   ClusterBuilder->Detector("CEMC");
0112   ClusterBuilder->set_threshold_energy(0.20);  // for when using basic calibration
0113   std::string emc_prof = getenv("CALIBRATIONROOT");
0114   emc_prof += "/EmcProfile/CEMCprof_Thresh30MeV.root";
0115   ClusterBuilder->LoadProfile(emc_prof);
0116   ClusterBuilder->set_UseTowerInfo(1);  // to use towerinfo objects rather than old RawTower
0117   ClusterBuilder->setOutputClusterNodeName("CLUSTERINFO_CEMC2");
0118   se->registerSubsystem(ClusterBuilder);
0119   
0120 /*
0121   std::cout << "Applying Position Dependent Correction" << std::endl;
0122   RawClusterPositionCorrection *clusterCorrection = new RawClusterPositionCorrection("CEMC");
0123   clusterCorrection->set_UseTowerInfo(1);  // to use towerinfo objects rather than old RawTower
0124   se->registerSubsystem(clusterCorrection);
0125 */
0126 
0127   ///////////////////
0128   // analysis modules
0129   if (iter==1){
0130     LiteCaloEval *eval7e = new LiteCaloEval("CEMCEVALUATOR2", "CEMC",OutFile);
0131     eval7e->CaloType(LiteCaloEval::CEMC);
0132     eval7e->setInputTowerNodeName("TOWERINFO_CALIB_CEMC");
0133     se->registerSubsystem(eval7e);
0134   }
0135 
0136   if (iter>1){
0137     CaloAna *ca = new CaloAna("calomodulename", OutFile);
0138     ca->set_timing_cut_width(16);
0139     ca->apply_vertex_cut(false);
0140     ca->set_vertex_cut(20.);
0141     se->registerSubsystem(ca);
0142   }
0143 
0144   se->run(nevents);
0145   se->End();
0146   se->PrintTimer();
0147   delete se;
0148 
0149   TFile* f_done_signal = new TFile("DONE.root","recreate");
0150   std::cout << "All done!" << std::endl;
0151   gSystem->Exit(0);
0152 }
0153 
0154 
0155 
0156 
0157 void createLocalEMCalCalibFile(const string fname, int runNumber)
0158 {
0159   string default_time_independent_calib = "cemc_pi0_twrSlope_v1_default";
0160   string m_calibName = "cemc_pi0_twrSlope_v1";
0161 
0162   string calibdir = CDBInterface::instance()->getUrl(m_calibName);
0163   string filePath;
0164 
0165   if (!calibdir.empty())
0166   {
0167     filePath = calibdir;
0168     // cdbttree = new CDBTTree(calibdir);
0169   }
0170   else
0171   {
0172     calibdir = CDBInterface::instance()->getUrl(default_time_independent_calib);
0173 
0174     if (calibdir.empty())
0175     {
0176       std::cout << "No EMCal Calibration NOT even a default" << std::endl;
0177       exit(1);
0178     }
0179     filePath = calibdir;
0180     // cdbttree = new CDBTTree(calibdir);
0181     std::cout << "No specific file for " << m_calibName << " found, using default calib " << default_time_independent_calib << std::endl;
0182   }
0183 
0184   TFile *f_cdb = new TFile(filePath.c_str());
0185   f_cdb->Cp(fname.c_str());
0186 
0187   std::cout << "created local Calib file for run " << runNumber << " named " << fname << std::endl;
0188 
0189   delete f_cdb;
0190 }
0191 
0192 #endif