Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloRecoUtility.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloRecoUtility.cc
1 #include "CaloRecoUtility.h"
2 
3 #include "BEmcCluster.h"
4 #include "BEmcRec.h" // for BEmcRec
5 #include "BEmcRecCEMC.h"
6 
7 #include <calobase/RawCluster.h>
8 #include <calobase/RawTowerDefs.h> // for decode_index1, decode_index2
9 
11 
12 #include <phool/phool.h> // for PHWHERE
13 
14 #include <cmath> // for atan2, log, cos, fabs, sin, sqrt
15 #include <cstdlib> // for exit, getenv
16 #include <iostream>
17 #include <map> // for _Rb_tree_const_iterator, operat...
18 #include <string>
19 #include <utility> // for pair
20 #include <vector> // for vector
21 
23 {
24  //
25 
26  float xA = clus->get_x();
27  float yA = clus->get_y();
28  float zA = clus->get_z();
29 
30  float zC = zA;
31 
32  // bemcC.CorrectShowerDepth(clus->get_energy(),xt,yt,zt,xC,yC, zC);
33  // Correction in z
34  // Just tuned for sim data ... don't fully understand why it works like that
35 
36  float logE = log(0.1);
37  if (clus->get_energy() > 0.1)
38  {
39  logE = std::log(clus->get_energy());
40  }
41 
42  float rA = std::sqrt(xA * xA + yA * yA);
43  // float theta_twr = GetTowerTheta(xA,yA,zA);
44  float theta_twr;
45  if (std::fabs(zA) <= 15)
46  {
47  theta_twr = 0;
48  }
49  else if (zA > 15)
50  {
51  theta_twr = std::atan2(zA - 15, rA);
52  }
53  else
54  {
55  theta_twr = std::atan2(zA + 15, rA);
56  }
57 
58  // fVz = 0;
59 
60  float theta_tr = std::atan2(zA - vz, rA);
61  float L = -1.3 + 0.7 * logE; // Shower CG in long. direction
62  float dz = L * std::sin(theta_tr - theta_twr) / std::cos(theta_twr);
63 
64  dz -= vz * 0.10;
65 
66  zC = zA - dz;
67 
68  clus->set_z(zC);
69 }
70 
72 {
73  if (!_profLoaded)
74  {
75  LoadProfile();
76  }
77 
78  float vvv[3];
79  vvv[0] = 0;
80  vvv[1] = 0;
81  vvv[2] = vz;
82 
83  _bemc->SetVertex(vvv);
84  // construct hitlist, which is just the towers hit in the EmcModule data structure format
85  // (for this cluster)
86 
87  EmcModule vhit;
88  std::vector<EmcModule> HitList;
89  HitList.erase(HitList.begin(), HitList.end());
90  int ich;
91 
92  RawCluster::TowerConstRange towers = clus->get_towers();
94 
95  for (toweriter = towers.first; toweriter != towers.second; ++toweriter)
96  {
97  int ix = RawTowerDefs::decode_index2(toweriter->first); // index2 is phi in CYL
98  int iy = RawTowerDefs::decode_index1(toweriter->first); // index1 is eta in CYL
99  /*
100  ix -= BINX0;
101  iy -= BINY0;
102 
103  if (ix >= 0 && ix < NBINX && iy >= 0 && iy < NBINY)
104  {
105 
106  */
107  // ich = iy * NBINX+ ix;
108  ich = iy * 256 + ix;
109  // add key field to vhit
110  vhit.ich = ich;
111  vhit.amp = toweriter->second;
112  // vhit.amp = tower->get_energy() * fEnergyNorm; // !!! Global Calibration
113  vhit.tof = 0.01; // not used
114 
115  HitList.push_back(vhit);
116 
117  //} // if check NBINS
118  }
119 
120  float chi2 = 0;
121  int ndf = 0;
122  float prob = _bemc->GetProb(HitList, clus->get_energy(), clus->get_x(), clus->get_y(), clus->get_z(), chi2, ndf);
123 
124  clus->set_prob(prob);
125  if (ndf > 0)
126  {
127  clus->set_chi2(chi2 / ndf);
128  }
129  else
130  {
131  clus->set_chi2(0);
132  }
133 }
134 
136 {
137  const char* calibroot = getenv("CALIBRATIONROOT");
138 
139  if (calibroot == nullptr)
140  {
141  std::cout << PHWHERE << "CALIBRATIONROOT env var not set" << std::endl;
142  exit(1);
143  }
144  std::string fname_emc_prof = calibroot;
145  fname_emc_prof += "/EmcProfile/CEMCprof_Thresh30MeV.root";
146 
147  std::cout << "CaloRecoUtility:::loading emc_prof from " << fname_emc_prof << std::endl;
148 
149  std::string url = CDBInterface::instance()->getUrl("EMCPROFILE", fname_emc_prof);
150  _bemc->LoadProfile(url);
151 
152  _profLoaded = true;
153 }
154 
156  : _profLoaded(false)
157 {
158  _bemc = new BEmcRecCEMC();
159 
160  _bemc->SetDim(256, 96);
161 
162  _bemc->SetTowerThreshold(0.030);
163 
164  float fProbNoiseParam = 0.04;
165  _bemc->SetProbNoiseParam(fProbNoiseParam);
166 }
167 
168 // this two stupid functions are only here because of a
169 // cppcheck warning that should have been suppressed
170 // "recommended to have a copy constructor/op= because of
171 // dynamic alloc resource"
173 {
174  _profLoaded = false;
175 
176  if (cru._bemc == nullptr)
177  {
178  _bemc = nullptr;
179  return;
180  }
181 
182  _bemc = new BEmcRecCEMC();
183 
184  _bemc->SetDim(256, 96);
185 
186  _bemc->SetTowerThreshold(0.030);
187 
188  float fProbNoiseParam = 0.04;
189  _bemc->SetProbNoiseParam(fProbNoiseParam);
190 }
191 
193 {
194  if (this == &cru)
195  {
196  return *this;
197  }
198 
199  _profLoaded = false;
200  if (cru._bemc == nullptr)
201  {
202  _bemc = nullptr;
203  return *this;
204  }
205 
206  _bemc = new BEmcRecCEMC();
207 
208  _bemc->SetDim(256, 96);
209 
210  _bemc->SetTowerThreshold(0.030);
211 
212  float fProbNoiseParam = 0.04;
213  _bemc->SetProbNoiseParam(fProbNoiseParam);
214 
215  return *this;
216 }
217 
219 {
220  delete _bemc;
221 }