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