Back to home page

sPhenix code displayed by LXR

 
 

    


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

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/RawClusterLikelihoodProfile.h>
0008 #include <caloreco/RawClusterPositionCorrection.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 <cdbobjects/CDBTTree.h>  // for CDBTTree
0030 #include <ffamodules/CDBInterface.h>
0031 //#include <GlobalVariables.C>
0032 
0033 #include <litecaloeval/LiteCaloEval.h>
0034 #include <calib_emc_pi0/pi0EtaByEta.h>
0035 #include <calotrigger/MinimumBiasClassifier.h>
0036 #include <calotrigger/TriggerRunInfoReco.h>
0037 
0038 #include <mbd/MbdReco.h>
0039 #include <globalvertex/GlobalVertexReco.h>
0040 
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(libmbd.so)
0054 R__LOAD_LIBRARY(libglobalvertex.so)
0055 
0056 
0057 void createLocalEMCalCalibFile(const string fname, int runNumber);
0058 
0059 
0060 void Fun4All_EMCal(int nevents = 1e2, const std::string &fname = "inputdata.txt",int iter = 2, const std::string &calib_fname="base/local_calib_copy.root")
0061 {
0062 
0063   Fun4AllServer *se = Fun4AllServer::instance();
0064   se->Verbosity(0);
0065   CDBInterface::instance()->Verbosity(1);
0066 
0067   recoConsts *rc = recoConsts::instance();
0068 
0069   ifstream file(fname);
0070   string first_file;
0071   getline(file, first_file);
0072 
0073   //===============
0074   // conditions DB flags
0075   //===============
0076   pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first_file);
0077   int runnumber = runseg.first;
0078   cout << "run number = " << runnumber << endl;
0079 
0080   rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024");
0081   rc->set_uint64Flag("TIMESTAMP",runnumber);// runnumber);
0082 
0083   Fun4AllInputManager *in = new Fun4AllDstInputManager("DST_TOWERS");
0084   in->AddListFile(fname);
0085   se->registerInputManager(in);
0086 
0087   std::string filename = first_file.substr(first_file.find_last_of("/\\") + 1);
0088   std::string OutFile = Form("OUTHIST_iter%d_%s",iter , filename.c_str());
0089 
0090 
0091   if (iter == 0)
0092   {
0093     createLocalEMCalCalibFile(calib_fname.c_str(), runnumber);
0094     cout << "creating " << calib_fname.c_str() << " and exiting" << endl;
0095     gSystem->Exit(0);
0096   }
0097 
0098   /////////////////////
0099   // mbd/vertex
0100   // MBD/BBC Reconstruction
0101   MbdReco *mbdreco = new MbdReco();
0102   se->registerSubsystem(mbdreco);
0103 
0104   // Official vertex storage
0105   GlobalVertexReco *gvertex = new GlobalVertexReco();
0106   se->registerSubsystem(gvertex);
0107 
0108 
0109 
0110   /////////////////////
0111   // Geometry
0112   std::cout << "Adding Geometry file" << std::endl;
0113   Fun4AllInputManager *intrue2 = new Fun4AllRunNodeInputManager("DST_GEO");
0114   std::string geoLocation = CDBInterface::instance()->getUrl("calo_geo");
0115   intrue2->AddFile(geoLocation);
0116   se->registerInputManager(intrue2);
0117 
0118 
0119   ////////////////////
0120   // Calibrate towers
0121   CaloTowerStatus *statusEMC = new CaloTowerStatus("CEMCSTATUS");
0122   statusEMC->set_detector_type(CaloTowerDefs::CEMC);
0123   //statusEMC->set_doAbortNoHotMap();
0124   statusEMC->set_directURL_hotMap("/sphenix/u/bseidlitz/work/forChris/caloStatusCDB_y2/moreMaps/EMCalHotMap_new_2024p006-48837cdb.root");
0125   se->registerSubsystem(statusEMC);
0126 
0127   CaloTowerCalib *calibEMC = new CaloTowerCalib("CEMCCALIB");
0128   calibEMC->set_detector_type(CaloTowerDefs::CEMC);
0129   calibEMC->set_directURL(calib_fname.c_str());
0130   se->registerSubsystem(calibEMC);
0131 
0132 
0133   //////////////////
0134   // Clusters
0135   std::cout << "Building clusters" << std::endl;
0136   RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("EmcRawClusterBuilderTemplate");
0137   ClusterBuilder->Detector("CEMC");
0138   ClusterBuilder->set_threshold_energy(0.07);  // for when using basic calibration
0139   std::string emc_prof = getenv("CALIBRATIONROOT");
0140   emc_prof += "/EmcProfile/CEMCprof_Thresh30MeV.root";
0141   ClusterBuilder->LoadProfile(emc_prof);
0142   ClusterBuilder->set_UseTowerInfo(1);  // to use towerinfo objects rather than old RawTower
0143   ClusterBuilder->setOutputClusterNodeName("CLUSTERINFO_CEMC");
0144   ClusterBuilder->set_UseAltZVertex(1); 
0145   se->registerSubsystem(ClusterBuilder);
0146 
0147 /*
0148   string clusternodename = "CLUSTERINFO_CEMC";
0149   // cluster new prob
0150   RawClusterLikelihoodProfile *ClusterProleBuilder = new RawClusterLikelihoodProfile("RawClusterLikelihoodProleGamma");
0151   ClusterProleBuilder->set_profile_filepath("/sphenix/user/jpark4/CDBfiles/EMCalProb/EMCal_ProfileLikelihoodD2_Thres70MeV.root"); // default set to single gamma
0152   ClusterProleBuilder->set_outputNodeName("CLUSTERINFO_CEMC");                                                                    // could keep the same name to overwrite with new prob. values
0153   ClusterProleBuilder->set_profile_dimension(3);                                                                                  // 5x5
0154   ClusterProleBuilder->set_min_cluster_e(1);
0155   //se->registerSubsystem(ClusterProleBuilder);
0156  */
0157   
0158 
0159   pi0EtaByEta *ca = new pi0EtaByEta("calomodulename", OutFile);
0160   const vector<int> triggerList = {10,12};
0161   //const vector<int> triggerList = {24,25,26};
0162   //ca->set_reqTrig(true,triggerList);
0163   ca->set_RunTowByTow(false); // to decide if we want to run tbt (default is true)
0164   ca->set_RunTBTCompactMode(true);
0165   ca->apply_vertex_cut(true);
0166   ca->set_pt1BaseClusCut(1.0);
0167   ca->set_pt2BaseClusCut(1.0);
0168   ca->set_NclusDeptFac(0.0);
0169   se->registerSubsystem(ca);
0170 
0171   se->run(nevents);
0172   se->End();
0173   se->PrintTimer();
0174   delete se;
0175 
0176   gSystem->Exec("echo DONE >> DONE.txt");
0177   gSystem->Exit(0);
0178 }
0179 
0180 
0181 
0182 
0183 void createLocalEMCalCalibFile(const string fname, int runNumber)
0184 {
0185   string default_time_independent_calib = "CEMC_calib_ADC_to_ETower_default";
0186   //string m_calibName = "cemc_pi0_twrSlope_v1";
0187   string m_calibName = "getdefault";
0188 
0189   string calibdir = CDBInterface::instance()->getUrl(m_calibName);
0190   string filePath;
0191 
0192   if (!calibdir.empty())
0193   {
0194     filePath = calibdir;
0195   }
0196   else
0197   {
0198     calibdir = CDBInterface::instance()->getUrl(default_time_independent_calib);
0199 
0200     if (calibdir.empty())
0201     {
0202       std::cout << "No EMCal Calibration NOT even a default" << std::endl;
0203       exit(1);
0204     }
0205     filePath = calibdir;
0206     std::cout << "No specific file for " << m_calibName << " found, using default calib " << default_time_independent_calib << std::endl;
0207   }
0208 
0209   TFile *f_cdb = new TFile(filePath.c_str());
0210   f_cdb->Cp(fname.c_str());
0211   f_cdb->Cp("initial_calib.root");
0212 
0213   std::cout << "created local Calib file for run " << runNumber << " named " << fname << std::endl;
0214 
0215   delete f_cdb;
0216 }
0217 
0218 #endif