ATLAS Offline Software
Loading...
Searching...
No Matches
EgammaReSamp1Fex.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ********************************************************************
6//
7// NAME: EgammaReSamp1Fex.cxx
8// PACKAGE: Trigger/TrigAlgorithms/TrigT2CaloEgamma
9//
10// AUTHOR: M.P. Casado
11//
12// Energy Ratio calculation modifications by Steve Armstrong
13// 8 May 2003
14//
15// ********************************************************************
16
17#include "EgammaReSamp1Fex.h"
18#include "CaloGeoHelpers/CaloSampling.h"
21
22// simple function that gives the distance to the closest point in the grid
23// defined with the position of the cells (basically a snap to the shortest distance
24// tool)
25inline double proxim(double b, double a)
26{
27 return b + 2. * M_PI * round((a - b) * (1. / (2. * M_PI)));
28}
29
30EgammaReSamp1Fex::EgammaReSamp1Fex(const std::string& type, const std::string& name,
31 const IInterface* parent) :
32 IReAlgToolCalo(type, name, parent)
33{}
34
35StatusCode EgammaReSamp1Fex::execute(xAOD::TrigEMCluster& rtrigEmCluster, const IRoiDescriptor& roi,
36 const CaloDetDescrElement*& caloDDE,
37 const EventContext& context) const
38{
39 bool cluster_in_barrel = true;
40 if (caloDDE) cluster_in_barrel = caloDDE->is_lar_em_barrel();
41
42 ATH_MSG_DEBUG("in execute(TrigEMCluster &)");
43
44 // Region Selector, sampling 1
45 int sampling = 1;
46
48 ATH_CHECK( m_dataSvc->loadCollections(context, roi, TTEM, sampling, sel) );
49
50 double totalEnergy = 0;
51 double etaEnergyS1 = 0;
53
54 double energyEta = rtrigEmCluster.eta();
55 double energyPhi = rtrigEmCluster.phi();
56 if (caloDDE) {
57 energyEta = caloDDE->eta();
58 energyPhi = caloDDE->phi();
59 }
60
61 // begin SRA mod: set regions via LAr way
62
63 // Fix for 3x7 cluster size
64 double z_etamin = energyEta - (0.075 / 2.); // 3 middle layer cells (cell size 0.025) half distance (hence /2)
65 double z_etamax = energyEta + (0.075 / 2.); //
66 // in phi, the cluster size uses 7 cells of size {2*pi/64=(0.09817477)}/4 (middle layer cell size)
67 double z_phimin = energyPhi - (7.0 * 0.09817477 / 4.0) / 2.0;
68 double z_phimax = energyPhi + (7.0 * 0.09817477 / 4.0) / 2.0;
69 // Fix for 5x5 clusters
70 if (!cluster_in_barrel) {
71 z_etamin = energyEta - (0.125 / 2.); // see comments above, endcap cluster is 5x5
72 z_etamax = energyEta + (0.125 / 2.);
73 z_phimin = energyPhi - (5.0 * 0.09817477 / 4.0) / 2.0;
74 z_phimax = energyPhi + (5.0 * 0.09817477 / 4.0) / 2.0;
75 }
76
77 double z_eta = z_etamin + (z_etamax - z_etamin) * 0.5;
78 double z_phi = z_phimin + (z_phimax - z_phimin) * 0.5;
79
80 // Make sure these boundaries are valid
81
82 if (z_etamin < -2.4) z_etamin = -2.4;
83 if (z_etamin < -1.4 && z_etamin > -1.5) z_etamin = -1.4;
84 if (z_etamin > 1.4 && z_etamin < 1.5) z_etamin = 1.5;
85
86 if (z_etamax > 2.4) z_etamax = 2.4;
87 if (z_etamax < -1.4 && z_etamax > -1.5) z_etamax = -1.5;
88 if (z_etamax > 1.4 && z_etamax < 1.5) z_etamax = 1.4;
89
90 bool signals = false;
91 if ((z_etamin < 0) && (z_etamax > 0)) signals = true;
92
93 // identify region in which the detector change granularity for this layer
94 // and we have to compensate. This is documented in LAr TDR
95 double etareg[6] = {-2.4, -2.0, -1.8, 1.8, 2.0, 2.4};
96 double etagra[5] = {0.025 / 4, 0.025 / 6, 0.025 / 8, 0.025 / 6, 0.025 / 4};
97 int imax = -9;
98 int icrk = 1;
99 double dgra = 0.;
100 // find the region, and check if the eta range cross region.
101 for (int ir = 0; ir < 5; ir++) {
102 // make sure you're not outside acceptance of 2.4
103 if (std::abs(z_eta) < 2.4 && z_eta >= etareg[ir] && z_eta <= etareg[ir + 1]) {
104 dgra = etagra[ir];
105 imax = ir;
106 if (z_etamin >= etareg[ir] && z_etamax <= etareg[ir + 1]) icrk = 0;
107 }
108 }
109 const double inv_dgra = dgra != 0 ? 1. / dgra : 1;
110
111 // begin SRA mod: pick the eta around which to scan
112 int strip_border;
113 double etanew;
114 double aeta = std::abs(z_eta);
115 if (aeta <= 1.4) {
116 strip_border = (int)rint(aeta * inv_dgra);
117 // this is -0.5 in atrecon: qgcshap.F .. Makes more sense to be +0.5
118 etanew = ((double)strip_border - 0.5) * dgra;
119 }
120 if (aeta <= 1.5) {
121 etanew = -99.;
122 }
123 if (aeta <= 1.8) {
124 strip_border = (int)rint(aeta * inv_dgra);
125 // this is -0.5 in atrecon: qgcshap.F .. Makes more sense to be +0.5
126 etanew = ((double)strip_border - 0.5) * dgra;
127 }
128 else if (aeta <= 2.0) {
129 strip_border = (int)rint((aeta - 1.8) * inv_dgra);
130 etanew = 1.8 + ((double)strip_border - 0.5) * dgra;
131 }
132 else if (aeta <= 2.4) {
133 strip_border = (int)rint((aeta - 2.0) * inv_dgra);
134 etanew = 2.0 + ((double)strip_border - 0.5) * dgra;
135 }
136 else {
137 etanew = -99.;
138 }
139
140 etanew = (z_eta < 0.) ? -etanew : etanew;
141
142 // check border crossing.
143 int ibin = 0;
144 double dgra1 = 0.;
145 int iadd = 0;
146 if ((icrk == 1) && (imax != -9)) {
147 if (imax > 0 && z_etamin > etareg[imax - 1] && z_etamin <= etareg[imax]) {
148 dgra1 = etagra[imax - 1];
149 ibin = (int)rint((etareg[imax] + 0.5 * dgra - etanew) * inv_dgra) + 20;
150 iadd = 0;
151 }
152 else {
153 if (imax < 4 && z_etamax > etareg[imax + 1] && z_etamax <= etareg[imax + 2]) {
154 dgra1 = etagra[imax + 1];
155 ibin = (int)rint((etareg[imax + 1] - 0.5 * dgra - etanew) * inv_dgra) + 20;
156 iadd = 1;
157 }
158 }
159 if (imax == 0) {
160 dgra1 = etagra[0];
161 ibin = (int)rint((etareg[0] + 0.5 * dgra - etanew) * inv_dgra) + 20;
162 iadd = 1;
163 }
164 if (imax == 4) {
165 dgra1 = etagra[4];
166 ibin = (int)rint((etareg[5] - 0.5 * dgra - etanew) * inv_dgra) + 20;
167 iadd = 0;
168 }
169 }
170 const double inv_dgra1 = dgra1 != 0 ? 1. / dgra1 : 1;
171
172 // end SRA mod
173
174 double z_enecell[40]; // SRA
175 double z_etacell[40]; // SRA
176
177 for (int iii = 0; iii < 40; iii++) {
178 z_enecell[iii] = 0.;
179 z_etacell[iii] = 0.;
180 }
181
182 int ncells = 0;
183
184 for (const LArCell* larcell : sel) { // Should be revised for London scheme
185 ncells++;
186 double etaCell = larcell->caloDDE()->eta_raw();
187 double phiCell = larcell->phi();
188 double energyCell = larcell->energy();
189
190 if (std::abs(etanew) != 99.) {
191
192 double eta_cell = etaCell; // SRA
193 // double eta_cell = larcell->eta(); //SRA
194
195 // begin SRA mod
196 if (eta_cell >= z_etamin && eta_cell <= z_etamax) {
197 // adjust for possible 2*pi offset.
198 double phi_cell0 = larcell->phi();
199 double phi_cell = proxim(phi_cell0, z_phi);
200 if (phi_cell >= z_phimin && phi_cell <= z_phimax) {
201 int ieta; // SRA
202 if (icrk == 0) {
203 // single region
204 ieta = (int)rint((eta_cell - etanew) * inv_dgra) + 20;
205 // correction for eta=0 spacing
206 if (signals && eta_cell < 0)
207 ieta = (int)rint((eta_cell - etanew + 0.007) * inv_dgra) + 20;
208 }
209 else {
210 if (eta_cell > etareg[imax] && eta_cell < etareg[imax + 1]) {
211 // same region
212 ieta = (int)rint((eta_cell - etanew) * inv_dgra) + 20;
213 }
214 else {
215 // different region
216 ieta = (int)rint((eta_cell - etareg[imax + iadd] - (0.5 - iadd) * dgra1) *
217 inv_dgra1) +
218 ibin;
219 }
220 } // icrk==0
221
222 double z_e = energyCell;
223
224 if (ieta >= 1 && ieta <= 40) {
225 z_enecell[ieta - 1] += z_e;
226 z_etacell[ieta - 1] = eta_cell;
227 }
228 } // phi range
229 } // eta range
230 // end SRA mod
231 } // endif for veto of clusters in crack outside acceptance
232
233 // Find the standard em cluster energy (3*7 cell, now sampling 1)
234 double deta = std::abs(etaCell - energyEta);
235 double dphi = std::abs(phiCell - energyPhi);
236 if (dphi > M_PI) dphi = 2. * M_PI - dphi; // wrap (pi - 2pi)->(-pi - 0)
237
238 bool condition37 = cluster_in_barrel && (deta <= 0.0375 && dphi <= 0.0875);
239 bool condition55 = (!cluster_in_barrel) && (deta <= 0.0625 && dphi <= 0.0625);
240
241 if (condition37 || condition55) {
242 totalEnergy += energyCell;
243 etaEnergyS1 += energyCell * etaCell;
244 // samp = CaloSampling::getSampling(*larcell);
245 samp = larcell->caloDDE()->getSampling();
246 rtrigEmCluster.setEnergy(samp, rtrigEmCluster.energy(samp) + energyCell);
247 rtrigEmCluster.setRawEnergy(samp, rtrigEmCluster.rawEnergy(samp) + energyCell);
248 }
249
250 } // end of loop over sampling 1
251
252 // SRA mod: Emax!
253 double z_emax = -999.0;
254 int z_ncmax = -999;
255 for (int ic = 0; ic < 40; ic++) {
256 if (z_enecell[ic] > z_emax) {
257 z_emax = z_enecell[ic];
258 z_ncmax = ic;
259 }
260 }
261
262 // Include now setWstot
263 double wtot = 0.;
264 double etot = 0.;
265 double wstot = -9999.;
266 double wstot_deta = (z_etamax - z_etamin) * 0.5;
267 // cppcheck-suppress negativeIndex
268 double eta_center = z_etacell[z_ncmax];
269 if (caloDDE != 0) {
270 eta_center = caloDDE->eta();
271 wstot_deta = caloDDE->deta() * 2.5;
272 }
273
274 for (int ic = 0; ic < 40; ic++) {
275 if ((z_etacell[ic] >= (eta_center - wstot_deta)) &&
276 (z_etacell[ic] <= (eta_center + wstot_deta))) {
277 wtot += z_enecell[ic] * (ic - z_ncmax) * (ic - z_ncmax);
278 etot += z_enecell[ic];
279 }
280 }
281 if (etot > 0) {
282 wtot = wtot / etot;
283 wstot = wtot > 0 ? sqrt(wtot) : -9999.;
284 }
285
286 // SRA mod: Emax2!
287 // int z_ncsec1=0;
288 double z_esec1 = -999.0; // energy of strip with second max 2
289
290 double ecand1;
291
292 for (int iic = 1; iic < 39; iic++) {
293 if ((z_enecell[iic] > z_enecell[iic - 1]) && (z_enecell[iic] > z_enecell[iic + 1])) {
294 if (iic != z_ncmax) {
295 ecand1 = z_enecell[iic];
296 if (ecand1 > z_esec1) {
297 z_esec1 = ecand1;
298 // z_ncsec1=iic;
299 }
300 }
301 }
302 }
303
304 if ((z_emax + z_esec1) < 0.) z_emax = -(100. / 98.) * z_esec1;
305
306 // do frac73 calculation: sum energies +-3 strips
307 // and +-1 strip around highest energy strip
308 double strip7 = 0.; // temporary variables to sum energy
309 double strip3 = 0.;
310 double frac73 = 0.; // (E7-E3)/E3 in layer 1
311
312 // use Steve's array to calculate frac73 MW
313 //
314 int smax = z_ncmax;
315 if (z_ncmax > 2 && z_ncmax < 37) {
316 strip7 = z_enecell[smax - 3] + z_enecell[smax - 2] + z_enecell[smax - 1] + z_enecell[smax + 1] +
317 z_enecell[smax + 2] + z_enecell[smax + 3] + z_enecell[smax];
318 strip3 = z_enecell[smax - 1] + z_enecell[smax] + z_enecell[smax + 1];
319 }
320 else if (z_ncmax == 2) {
321 strip7 = z_enecell[smax - 2] + z_enecell[smax - 1] + z_enecell[smax + 1] + z_enecell[smax + 2] +
322 z_enecell[smax + 3] + z_enecell[smax];
323 strip3 = z_enecell[smax - 1] + z_enecell[smax] + z_enecell[smax + 1];
324 }
325 else if (z_ncmax == 37) {
326 strip7 = z_enecell[smax - 3] + z_enecell[smax - 2] + z_enecell[smax - 1] + z_enecell[smax + 1] +
327 z_enecell[smax + 2] + z_enecell[smax];
328 strip3 = z_enecell[smax - 1] + z_enecell[smax] + z_enecell[smax + 1];
329 }
330 else if (z_ncmax == 1) {
331 strip7 = z_enecell[smax - 1] + z_enecell[smax + 1] + z_enecell[smax + 2] + z_enecell[smax + 3] +
332 z_enecell[smax];
333 strip3 = z_enecell[smax - 1] + z_enecell[smax] + z_enecell[smax + 1];
334 }
335 else if (z_ncmax == 38) {
336 strip7 = z_enecell[smax - 3] + z_enecell[smax - 2] + z_enecell[smax - 1] + z_enecell[smax + 1] +
337 z_enecell[smax];
338 strip3 = z_enecell[smax - 1] + z_enecell[smax] + z_enecell[smax + 1];
339 }
340 strip3 > 1.e-6 ? // protect against small values of strip3
341 frac73 = (strip7 - strip3) / strip3
342 : frac73 = 99.;
343
344 // Update Cluster Variables
345
346 rtrigEmCluster.setNCells(ncells + rtrigEmCluster.nCells());
347 rtrigEmCluster.setEmaxs1(z_emax);
348 rtrigEmCluster.setWstot(wstot);
349 rtrigEmCluster.setE2tsts1(z_esec1);
350 rtrigEmCluster.setFracs1(frac73);
351 if (totalEnergy != 0.0)
352 rtrigEmCluster.setEta1(etaEnergyS1 / totalEnergy);
353 else
354 rtrigEmCluster.setEta1(99.0);
355 rtrigEmCluster.setRawEnergy(rtrigEmCluster.rawEnergy() + totalEnergy);
356
357
358 return StatusCode::SUCCESS;
359}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
double proxim(double b, double a)
static Double_t a
@ TTEM
Definition RegSelEnums.h:28
int imax(int i, int j)
This class groups all DetDescr information related to a CaloCell.
bool is_lar_em_barrel() const
cell belongs to EM barrel
EgammaReSamp1Fex(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode execute(xAOD::TrigEMCluster &rtrigEmCluster, const IRoiDescriptor &roi, const CaloDetDescrElement *&caloDDE, const EventContext &context) const override
execute feature extraction for the EM Calorimeter second layer
IReAlgToolCalo(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
ServiceHandle< ITrigCaloDataAccessSvc > m_dataSvc
Describes the API of the Region of Ineterest geometry.
Data object for LAr calorimeter readout cell.
Definition LArCell.h:53
void setNCells(int)
set number of cells used from RoI
float rawEnergy() const
get Raw Energy (no calibration)
int nCells() const
get number of cells used from RoI
void setRawEnergy(float)
set Raw Energy (no calibration)
float eta() const
get Eta (calibrated)
void setEnergy(float energy)
set Energy (calibrated)
void setE2tsts1(float)
set second maximum energy in sampling 1 (strip layer)
float phi() const
get Phi (calibrated)
void setEmaxs1(float)
set maximum energy in sampling 1 (strip layer)
void setFracs1(float)
set Energy in a 7 strips (around hottest strip) minus energy in 3 strips divided by energy in 3 strip...
void setWstot(float)
set width in first layer
float energy() const
get Energy (calibrated)
void setEta1(float)
set Eta sampling 1 (strip layer)
int ir
counter of the current depth
Definition fastadd.cxx:49
TrigEMCluster_v1 TrigEMCluster
Define the latest version of the trigger EM cluster class.
double proxim(double b, double a)
Definition proxim.h:17