File indexing completed on 2025-12-18 09:22:10
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 <calotrigger/MinimumBiasClassifier.h>
0011 #include <calotrigger/TriggerRunInfoReco.h>
0012
0013
0014 #include <centrality/CentralityInfo.h>
0015
0016 #include <cdbobjects/CDBTTree.h> // for CDBTTree
0017
0018 #include <litecaloeval/LiteCaloEval.h>
0019
0020 #include <calib_emc_pi0/pi0EtaByEta.h>
0021
0022 #include <mbd/MbdReco.h>
0023
0024 #include <globalvertex/GlobalVertexReco.h>
0025
0026 #include <ffamodules/CDBInterface.h>
0027 #include <ffamodules/FlagHandler.h>
0028 #include <ffamodules/HeadReco.h>
0029 #include <ffamodules/SyncReco.h>
0030
0031 #include <fun4allraw/Fun4AllPrdfInputManager.h>
0032
0033 #include <fun4all/Fun4AllDstInputManager.h>
0034 #include <fun4all/Fun4AllDstOutputManager.h>
0035 #include <fun4all/Fun4AllInputManager.h>
0036 #include <fun4all/Fun4AllRunNodeInputManager.h>
0037 #include <fun4all/Fun4AllServer.h>
0038 #include <fun4all/Fun4AllUtils.h>
0039 #include <fun4all/SubsysReco.h>
0040
0041 #include <phool/recoConsts.h>
0042
0043
0044 #include <TSystem.h>
0045
0046 #include <format>
0047 #include <fstream>
0048
0049 R__LOAD_LIBRARY(libcdbobjects)
0050 R__LOAD_LIBRARY(libfun4all.so)
0051 R__LOAD_LIBRARY(libfun4allraw.so)
0052 R__LOAD_LIBRARY(libcalo_reco.so)
0053 R__LOAD_LIBRARY(libffamodules.so)
0054 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
0055 R__LOAD_LIBRARY(libcalibCaloEmc_pi0.so)
0056 R__LOAD_LIBRARY(libcalotrigger.so)
0057 R__LOAD_LIBRARY(libcentrality.so)
0058 R__LOAD_LIBRARY(libzdcinfo.so)
0059 R__LOAD_LIBRARY(libmbd.so)
0060 R__LOAD_LIBRARY(libglobalvertex.so)
0061
0062
0063 void createLocalEMCalCalibFile(const std::string &fname, int runNumber);
0064
0065
0066 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")
0067 {
0068
0069 Fun4AllServer *se = Fun4AllServer::instance();
0070 se->Verbosity(0);
0071 CDBInterface::instance()->Verbosity(1);
0072
0073 recoConsts *rc = recoConsts::instance();
0074
0075 std::ifstream file(fname);
0076 std::string first_file;
0077 getline(file, first_file);
0078
0079
0080
0081
0082 std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first_file);
0083 int runnumber = runseg.first;
0084 std::cout << "run number = " << runnumber << std::endl;
0085
0086 rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024");
0087 rc->set_uint64Flag("TIMESTAMP",runnumber);
0088
0089 Fun4AllInputManager *in = new Fun4AllDstInputManager("DST_TOWERS");
0090 in->AddListFile(fname);
0091 se->registerInputManager(in);
0092
0093 std::string filename = first_file.substr(first_file.find_last_of("/\\") + 1);
0094 std::string OutFile = std::format("OUTHIST_iter{}_{}",iter , filename);
0095
0096
0097 if (iter == 0)
0098 {
0099 createLocalEMCalCalibFile(calib_fname, runnumber);
0100 std::cout << "creating " << calib_fname.c_str() << " and exiting" << std::endl;
0101 gSystem->Exit(0);
0102 }
0103
0104
0105
0106
0107 MbdReco *mbdreco = new MbdReco();
0108 se->registerSubsystem(mbdreco);
0109
0110
0111 GlobalVertexReco *gvertex = new GlobalVertexReco();
0112 se->registerSubsystem(gvertex);
0113
0114
0115
0116
0117
0118 std::cout << "Adding Geometry file" << std::endl;
0119 Fun4AllInputManager *intrue2 = new Fun4AllRunNodeInputManager("DST_GEO");
0120 std::string geoLocation = CDBInterface::instance()->getUrl("calo_geo");
0121 intrue2->AddFile(geoLocation);
0122 se->registerInputManager(intrue2);
0123
0124
0125
0126
0127 CaloTowerStatus *statusEMC = new CaloTowerStatus("CEMCSTATUS");
0128 statusEMC->set_detector_type(CaloTowerDefs::CEMC);
0129
0130 statusEMC->set_directURL_hotMap("/sphenix/u/bseidlitz/work/forChris/caloStatusCDB_y2/moreMaps/EMCalHotMap_new_2024p006-48837cdb.root");
0131 se->registerSubsystem(statusEMC);
0132
0133 CaloTowerCalib *calibEMC = new CaloTowerCalib("CEMCCALIB");
0134 calibEMC->set_detector_type(CaloTowerDefs::CEMC);
0135 calibEMC->set_directURL(calib_fname);
0136 se->registerSubsystem(calibEMC);
0137
0138
0139
0140
0141 std::cout << "Building clusters" << std::endl;
0142 RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("EmcRawClusterBuilderTemplate");
0143 ClusterBuilder->Detector("CEMC");
0144 ClusterBuilder->set_threshold_energy(0.07);
0145 std::string emc_prof = getenv("CALIBRATIONROOT");
0146 emc_prof += "/EmcProfile/CEMCprof_Thresh30MeV.root";
0147 ClusterBuilder->LoadProfile(emc_prof);
0148 ClusterBuilder->set_UseTowerInfo(1);
0149 ClusterBuilder->setOutputClusterNodeName("CLUSTERINFO_CEMC");
0150 ClusterBuilder->set_UseAltZVertex(1);
0151 se->registerSubsystem(ClusterBuilder);
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 pi0EtaByEta *ca = new pi0EtaByEta("calomodulename", OutFile);
0166 const std::vector<int> triggerList = {10,12};
0167
0168
0169 ca->set_RunTowByTow(false);
0170 ca->set_RunTBTCompactMode(true);
0171 ca->apply_vertex_cut(true);
0172 ca->set_pt1BaseClusCut(1.0);
0173 ca->set_pt2BaseClusCut(1.0);
0174 ca->set_NclusDeptFac(0.0);
0175 se->registerSubsystem(ca);
0176
0177 se->run(nevents);
0178 se->End();
0179 se->PrintTimer();
0180 delete se;
0181
0182 gSystem->Exec("echo DONE >> DONE.txt");
0183 gSystem->Exit(0);
0184 }
0185
0186
0187
0188
0189 void createLocalEMCalCalibFile(const std::string &fname, int runNumber)
0190 {
0191 std::string default_time_independent_calib = "CEMC_calib_ADC_to_ETower_default";
0192
0193 std::string m_calibName = "getdefault";
0194
0195 std::string calibdir = CDBInterface::instance()->getUrl(m_calibName);
0196 std::string filePath;
0197
0198 if (!calibdir.empty())
0199 {
0200 filePath = calibdir;
0201 }
0202 else
0203 {
0204 calibdir = CDBInterface::instance()->getUrl(default_time_independent_calib);
0205
0206 if (calibdir.empty())
0207 {
0208 std::cout << "No EMCal Calibration NOT even a default" << std::endl;
0209 exit(1);
0210 }
0211 filePath = calibdir;
0212 std::cout << "No specific file for " << m_calibName << " found, using default calib " << default_time_independent_calib << std::endl;
0213 }
0214
0215 TFile *f_cdb = new TFile(filePath.c_str());
0216 f_cdb->Cp(fname.c_str());
0217 f_cdb->Cp("initial_calib.root");
0218
0219 std::cout << "created local Calib file for run " << runNumber << " named " << fname << std::endl;
0220
0221 delete f_cdb;
0222 }
0223
0224 #endif