1 |
/** |
2 |
* \file src/CaloLevel2.cpp |
3 |
* \author Emiliano Mocchiutti |
4 |
* |
5 |
**/ |
6 |
#include <TObject.h> |
7 |
#include <CaloLevel2.h> |
8 |
ClassImp(CaloTrkVar); |
9 |
ClassImp(CaloLevel2); |
10 |
|
11 |
/** |
12 |
* CaloTrkVar constructor |
13 |
**/ |
14 |
CaloTrkVar::CaloTrkVar() { |
15 |
this->Clear(); |
16 |
}; |
17 |
|
18 |
/** |
19 |
* Clear variables |
20 |
**/ |
21 |
void CaloTrkVar::Clear() { |
22 |
trkseqno = 0; |
23 |
noint = 0; |
24 |
ncore = 0; |
25 |
qcore = 0.; |
26 |
ncyl = 0; |
27 |
qcyl = 0.; |
28 |
qtrack = 0.; |
29 |
qtrackx = 0.; |
30 |
qtracky = 0.; |
31 |
dxtrack = 0.; |
32 |
dytrack = 0.; |
33 |
qlast = 0.; |
34 |
nlast = 0; |
35 |
qpre = 0.; |
36 |
npre = 0; |
37 |
qpresh = 0.; |
38 |
npresh = 0; |
39 |
qtr = 0.; |
40 |
ntr = 0; |
41 |
planetot = 0; |
42 |
qmean = 0.; |
43 |
qlow = 0.; |
44 |
nlow = 0; |
45 |
dX0l = 0.; |
46 |
memset(tbar, 0, 2*22*sizeof(Float_t)); |
47 |
memset(tibar, 0, 2*22*sizeof(Int_t)); |
48 |
} |
49 |
|
50 |
/** |
51 |
* Copies from t to this |
52 |
**/ |
53 |
CaloTrkVar::CaloTrkVar(const CaloTrkVar &t){ |
54 |
trkseqno = t.trkseqno; |
55 |
noint = t.noint; |
56 |
ncore = t.ncore; |
57 |
qcore = t.qcore; |
58 |
ncyl = t.ncyl; |
59 |
qcyl = t.qcyl; |
60 |
qtrack = t.qtrack; |
61 |
qtrackx = t.qtrackx; |
62 |
qtracky = t.qtracky; |
63 |
dxtrack = t.dxtrack; |
64 |
dytrack = t.dytrack; |
65 |
qlast = t.qlast; |
66 |
nlast = t.nlast; |
67 |
qpre = t.qpre; |
68 |
npre = t.npre; |
69 |
qpresh = t.qpresh; |
70 |
npresh = t.npresh; |
71 |
qtr = t.qtr; |
72 |
ntr = t.ntr; |
73 |
planetot = t.planetot; |
74 |
qmean = t.qmean; |
75 |
dX0l = t.dX0l; |
76 |
qlow = t.qlow; |
77 |
nlow = t.nlow; |
78 |
memcpy(tibar,t.tibar,sizeof(tibar)); |
79 |
memcpy(tbar,t.tbar,sizeof(tbar)); |
80 |
} |
81 |
|
82 |
/** |
83 |
* CaloLevel2 constructor |
84 |
**/ |
85 |
CaloLevel2::CaloLevel2() { |
86 |
// |
87 |
CaloTrk = new TClonesArray("CaloTrkVar",1); |
88 |
estrip = TArrayI(0,NULL); |
89 |
// |
90 |
this->Clear(); |
91 |
// |
92 |
}; |
93 |
|
94 |
/** |
95 |
* Clear the CaloLevel2 object |
96 |
**/ |
97 |
void CaloLevel2::Clear() { |
98 |
// |
99 |
CaloTrk->Clear(); |
100 |
// |
101 |
nstrip = 0; |
102 |
qtot = 0.; |
103 |
impx = 0.; |
104 |
impy = 0.; |
105 |
tanx = 0.; |
106 |
tany = 0.; |
107 |
qmax = 0.; |
108 |
nx22 = 0; |
109 |
qx22 = 0.; |
110 |
elen = 0.; |
111 |
selen = 0.; |
112 |
memset(perr, 0, 4*sizeof(Int_t)); |
113 |
memset(swerr, 0, 4*sizeof(Int_t)); |
114 |
memset(crc, 0, 4*sizeof(Int_t)); |
115 |
memset(qq, 0, 4*sizeof(Int_t)); |
116 |
memset(varcfit, 0, 2*sizeof(Float_t)); |
117 |
memset(npcfit, 0, 2*sizeof(Int_t)); |
118 |
memset(planemax, 0, 2*sizeof(Int_t)); |
119 |
memset(cibar, 0, 2*22*sizeof(Int_t)); |
120 |
memset(cbar, 0, 2*22*sizeof(Float_t)); |
121 |
good = 0; |
122 |
selftrigger = 0; |
123 |
estrip.Reset(); |
124 |
}; |
125 |
|
126 |
|
127 |
/** |
128 |
* Fills a struct cCaloLevel2 with values from a CaloLevel2 object (to put data into a F77 common). |
129 |
*/ |
130 |
void CaloLevel2::GetLevel2Struct(cCaloLevel2 *l2) const { |
131 |
|
132 |
l2->good = good; |
133 |
l2->selftrigger = selftrigger; |
134 |
l2->nstrip = nstrip; |
135 |
l2->nx22 = nx22; |
136 |
l2->qtot = qtot; |
137 |
l2->qx22 = qx22; |
138 |
l2->qmax = qmax; |
139 |
l2->impx = impx; |
140 |
l2->impy = impy; |
141 |
l2->tanx = tanx; |
142 |
l2->tany = tany; |
143 |
l2->elen = elen; |
144 |
l2->selen = selen; |
145 |
|
146 |
for(Int_t i=0;i<2;i++){ |
147 |
l2->planemax[i] = planemax[i]; |
148 |
l2->varcfit[i] = varcfit[i]; |
149 |
l2->npcfit[i] = npcfit[i]; |
150 |
} |
151 |
for(Int_t i=0;i<4;i++){ |
152 |
l2->perr[i] = perr[i]; |
153 |
l2->swerr[i] = swerr[i]; |
154 |
l2->calcrc[i] = crc[i]; |
155 |
l2->qq[i] = qq[i]; |
156 |
} |
157 |
|
158 |
l2->calntrk = CaloTrk->GetEntries(); |
159 |
|
160 |
for(Int_t i=0;i<l2->calntrk;i++){ |
161 |
l2->caltrkseqno[i] = ((CaloTrkVar *)CaloTrk->At(i))->trkseqno; |
162 |
l2->ncore[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncore; |
163 |
l2->noint[i] = ((CaloTrkVar *)CaloTrk->At(i))->noint; |
164 |
l2->ncyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncyl; |
165 |
l2->nlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlast; |
166 |
l2->npre[i] = ((CaloTrkVar *)CaloTrk->At(i))->npre; |
167 |
l2->npresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->npresh; |
168 |
l2->ntr[i] = ((CaloTrkVar *)CaloTrk->At(i))->ntr; |
169 |
l2->planetot[i] = ((CaloTrkVar *)CaloTrk->At(i))->planetot; |
170 |
l2->nlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlow; |
171 |
l2->qcore[i] =((CaloTrkVar *)CaloTrk->At(i))->qcore ; |
172 |
l2->qcyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->qcyl; |
173 |
l2->qlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlast; |
174 |
l2->qpre[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpre; |
175 |
l2->qpresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpresh; |
176 |
l2->qtr[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtr; |
177 |
l2->qtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrack; |
178 |
l2->qtrackx[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrackx; |
179 |
l2->qtracky[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtracky; |
180 |
l2->dxtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dxtrack; |
181 |
l2->dytrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dytrack; |
182 |
l2->qmean[i] = ((CaloTrkVar *)CaloTrk->At(i))->qmean; |
183 |
l2->qlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlow; |
184 |
l2->dX0l[i] = ((CaloTrkVar *)CaloTrk->At(i))->dX0l; |
185 |
for (Int_t j=0; j<2; j++){ |
186 |
for (Int_t k=0; k<22; k++){ |
187 |
l2->tbar[i][k][j] = ((CaloTrkVar *)CaloTrk->At(i))->tbar[k][j]; |
188 |
}; |
189 |
}; |
190 |
} |
191 |
|
192 |
} |
193 |
|
194 |
/** |
195 |
* Returns the detected energy for the given strip once loaded the event |
196 |
**/ |
197 |
Float_t CaloLevel2::GetEstrip(Int_t sview, Int_t splane, Int_t sstrip){ |
198 |
Int_t view = -1; |
199 |
Int_t plane = -1; |
200 |
Int_t strip = -1; |
201 |
Float_t mip = 0.; |
202 |
// |
203 |
if ( nstrip == 0 ) return(0.); |
204 |
// |
205 |
for (Int_t i = 0; i<nstrip; i++ ){ |
206 |
// |
207 |
mip = DecodeEstrip(i,view,plane,strip); |
208 |
// |
209 |
if ( view == sview && splane == plane && sstrip == strip ) return(mip); |
210 |
// |
211 |
// entry are ordered by strip, plane and view number. Go out if you pass the input strip |
212 |
// |
213 |
if ( view == sview && plane == splane && strip > sstrip ) return(0.); |
214 |
if ( view == sview && plane > splane ) return(0.); |
215 |
if ( view > sview ) return(0.); |
216 |
// |
217 |
}; |
218 |
return(0.); |
219 |
}; |
220 |
|
221 |
/** |
222 |
* Given estrip entry returns energy plus view, plane and strip numbers |
223 |
**/ |
224 |
Float_t CaloLevel2::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip){ |
225 |
// |
226 |
if ( entry>nstrip ) return(0.); |
227 |
// |
228 |
// printf(" num lim %f \n",std::numeric_limits<Float_t>::max()); |
229 |
// printf(" estrip.At(%i) = %i \n",entry,estrip.At(entry)); |
230 |
// |
231 |
Int_t eval = 0; |
232 |
if ( estrip.At(entry) > 0. ){ |
233 |
view = 0; |
234 |
eval = estrip.At(entry); |
235 |
} else { |
236 |
view = 1; |
237 |
eval = -estrip.At(entry); |
238 |
}; |
239 |
// |
240 |
Int_t fbi = 0; |
241 |
fbi = (Int_t)truncf((Float_t)(eval/1000000000)); |
242 |
// |
243 |
Int_t plom = 0; |
244 |
plom = (Int_t)truncf((Float_t)((eval-fbi*1000000000)/10000000)); |
245 |
// |
246 |
Float_t tim = 100000.; |
247 |
plane = plom; |
248 |
if ( fbi == 1 ) tim = 10000.; |
249 |
if ( plom > 21 ){ |
250 |
plane = plom - 22; |
251 |
if ( fbi == 1 ){ |
252 |
tim = 1000.; |
253 |
} else { |
254 |
tim = 100.; |
255 |
}; |
256 |
}; |
257 |
if ( plom > 43 ){ |
258 |
plane = plom - 44; |
259 |
tim = 10.; |
260 |
}; |
261 |
if ( plom > 65 ){ |
262 |
plane = plom - 66; |
263 |
tim = 1.; |
264 |
}; |
265 |
// |
266 |
strip = (Int_t)truncf((Float_t)((eval - fbi*1000000000 -plom*10000000)/100000)); |
267 |
// |
268 |
Float_t mip = ((Float_t)(eval - fbi*1000000000 -plom*10000000 -strip*100000))/tim; |
269 |
// |
270 |
if ( mip > 0. && mip < 99999. ) return(mip); |
271 |
// |
272 |
printf(" WARNING: problems decoding value %i at entry %i \n",estrip.At(entry),entry); |
273 |
// |
274 |
view = -1; |
275 |
plane = -1; |
276 |
strip = -1; |
277 |
return(0.); |
278 |
} |
279 |
|
280 |
/** |
281 |
* Should return the energy in GeV if the particle would be an electron |
282 |
* using a parametrization taken from Monte Carlo simulation |
283 |
**/ |
284 |
void CaloLevel2::GetElectronEnergy(Float_t &energy, Float_t &sigma){ |
285 |
if ( nstrip == 0 ) return; |
286 |
energy = qtot * 40.82 * 0.000106; |
287 |
sigma = 0.; |
288 |
if ( energy > 0. ) sigma = energy * (0.01183 + 0.121/sqrt(energy)); |
289 |
return; |
290 |
}; |
291 |
|
292 |
/** |
293 |
* Returns pointer to the set of track-related variables "itrk" |
294 |
**/ |
295 |
CaloTrkVar *CaloLevel2::GetCaloTrkVar(Int_t itrk){ |
296 |
// |
297 |
if(itrk >= ntrk()){ |
298 |
printf(" CaloLevel2 ERROR: track related variables set %i does not exists! \n",itrk); |
299 |
printf(" stored track related variables = %i \n",ntrk()); |
300 |
return(NULL); |
301 |
} |
302 |
TClonesArray &t = *(CaloTrk); |
303 |
CaloTrkVar *calotrack = (CaloTrkVar*)t[itrk]; |
304 |
return calotrack; |
305 |
} |