Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_EMCal.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_EMCal.C
1 #ifndef FUN4ALL_EMCAL_C
2 #define FUN4ALL_EMCAL_C
3 
4 #include <caloreco/CaloTowerCalib.h>
5 #include <caloreco/RawClusterBuilderTemplate.h>
6 #include <caloreco/RawClusterPositionCorrection.h>
7 
9 #include <ffamodules/HeadReco.h>
10 #include <ffamodules/SyncReco.h>
11 
13 
18 #include <fun4all/Fun4AllServer.h>
19 #include <fun4all/Fun4AllUtils.h>
20 #include <fun4all/SubsysReco.h>
21 
22 #include <phool/recoConsts.h>
23 
24 #include <cdbobjects/CDBTTree.h> // for CDBTTree
26 #include <GlobalVariables.C>
27 
28 #include <litecaloeval/LiteCaloEval.h>
29 #include <calib_emc_pi0/pi0EtaByEta.h>
30 
31 R__LOAD_LIBRARY(libcdbobjects)
32 R__LOAD_LIBRARY(libfun4all.so)
33 R__LOAD_LIBRARY(libfun4allraw.so)
34 R__LOAD_LIBRARY(libcalo_reco.so)
35 R__LOAD_LIBRARY(libffamodules.so)
36 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
37 R__LOAD_LIBRARY(libcalibCaloEmc_pi0.so)
38 
39 void createLocalEMCalCalibFile(const string fname, int runNumber);
40 
41 
42 
43 
44 void Fun4All_EMCal(int nevents = 0, const std::string &fname = "inputdata.txt",int iter = 2, const std::string &calib_fname="local_calib_copy.root")
45 {
46  bool enableMasking = 0;
47 
48  bool doFit = 0;
49  bool doHistMake = 1;
50 
52  se->Verbosity(0);
53 
54  // se->Verbosity(verbosity);
56 
57  ifstream file(fname);
58  string first_file;
59  getline(file, first_file);
60 
61  //===============
62  // conditions DB flags
63  //===============
64  pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first_file);
65  int runnumber = runseg.first;
66  cout << "run number = " << runnumber << endl;
67 
68  // global tag
69  rc->set_StringFlag("CDB_GLOBALTAG", "MDC2");
70  // // 64 bit timestamp
71  rc->set_uint64Flag("TIMESTAMP", runnumber);
72 
73  Fun4AllInputManager *in = new Fun4AllDstInputManager("DST_TOWERS");
74  in->AddListFile(fname);
75  se->registerInputManager(in);
76 
77  std::string filename = first_file.substr(first_file.find_last_of("/\\") + 1);
78  std::string OutFile = Form("OUTHIST_iter%d_%s",iter , filename.c_str());
79 
80 
81  if (iter == 0)
82  {
83  createLocalEMCalCalibFile(calib_fname.c_str(), runnumber);
84  cout << "creating " << calib_fname.c_str() << " and exiting" << endl;
85  gSystem->Exit(0);
86  }
87 
89  // Calibrate towers
90 
91  std::cout << "Calibrating EMCal" << std::endl;
92  CaloTowerCalib *calibEMC = new CaloTowerCalib("CEMCCALIB");
94  calibEMC->set_directURL(calib_fname.c_str());
95  se->registerSubsystem(calibEMC);
96 
97 
99  // Clusters
100  std::cout << "Building clusters" << std::endl;
101  RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("EmcRawClusterBuilderTemplate");
102  ClusterBuilder->Detector("CEMC");
103  ClusterBuilder->set_threshold_energy(0.20); // for when using basic calibration
104  std::string emc_prof = getenv("CALIBRATIONROOT");
105  emc_prof += "/EmcProfile/CEMCprof_Thresh30MeV.root";
106  ClusterBuilder->LoadProfile(emc_prof);
107  ClusterBuilder->set_UseTowerInfo(1); // to use towerinfo objects rather than old RawTower
108  ClusterBuilder->setOutputClusterNodeName("CLUSTERINFO_CEMC2");
109  se->registerSubsystem(ClusterBuilder);
110 
111 /*
112  std::cout << "Applying Position Dependent Correction" << std::endl;
113  RawClusterPositionCorrection *clusterCorrection = new RawClusterPositionCorrection("CEMC");
114  clusterCorrection->set_UseTowerInfo(1); // to use towerinfo objects rather than old RawTower
115  se->registerSubsystem(clusterCorrection);
116 */
117 
119  // analysis modules
120  if (iter==1){
121  LiteCaloEval *eval7e = new LiteCaloEval("CEMCEVALUATOR2", "CEMC",OutFile);
122  eval7e->CaloType(LiteCaloEval::CEMC);
123  eval7e->setInputTowerNodeName("TOWERINFO_CALIB_CEMC");
124  se->registerSubsystem(eval7e);
125  }
126 
127  if (iter>1){
128  pi0EtaByEta *ca = new pi0EtaByEta("calomodulename", OutFile);
129  ca->set_timing_cut_width(16);
130  ca->apply_vertex_cut(false);
131  ca->set_vertex_cut(20.);
132  se->registerSubsystem(ca);
133  }
134 
135  se->run(nevents);
136  se->End();
137  se->PrintTimer();
138  delete se;
139 
140  TFile* f_done_signal = new TFile("DONE.root","recreate");
141  std::cout << "All done!" << std::endl;
142  gSystem->Exit(0);
143 }
144 
145 
146 
147 
148 void createLocalEMCalCalibFile(const string fname, int runNumber)
149 {
150  string default_time_independent_calib = "cemc_pi0_twrSlope_v1_default";
151  string m_calibName = "cemc_pi0_twrSlope_v1";
152 
153  string calibdir = CDBInterface::instance()->getUrl(m_calibName);
154  string filePath;
155 
156  if (!calibdir.empty())
157  {
158  filePath = calibdir;
159  // cdbttree = new CDBTTree(calibdir);
160  }
161  else
162  {
163  calibdir = CDBInterface::instance()->getUrl(default_time_independent_calib);
164 
165  if (calibdir.empty())
166  {
167  std::cout << "No EMCal Calibration NOT even a default" << std::endl;
168  exit(1);
169  }
170  filePath = calibdir;
171  // cdbttree = new CDBTTree(calibdir);
172  std::cout << "No specific file for " << m_calibName << " found, using default calib " << default_time_independent_calib << std::endl;
173  }
174 
175  TFile *f_cdb = new TFile(filePath.c_str());
176  f_cdb->Cp(fname.c_str());
177 
178  std::cout << "created local Calib file for run " << runNumber << " named " << fname << std::endl;
179 
180  delete f_cdb;
181 }
182 
183 #endif