1 |
#include <stdlib.h> |
2 |
#include <iostream> |
3 |
#include <iomanip> |
4 |
// |
5 |
#include <TString.h> |
6 |
#include <TH1F.h> |
7 |
#include <TH2F.h> |
8 |
#include <TMatrixD.h> |
9 |
#include <TMatrixF.h> |
10 |
#include <TArrayF.h> |
11 |
#include <TArrayI.h> |
12 |
// |
13 |
#include <PamLevel2.h> |
14 |
#include <CaloFranzini.h> |
15 |
// |
16 |
using namespace std; |
17 |
// |
18 |
extern Bool_t MATRIX; |
19 |
extern Bool_t FULL; |
20 |
extern Bool_t SIMU; |
21 |
extern Bool_t CRIG; |
22 |
extern Bool_t SRIG; |
23 |
CaloFranzini *cf; |
24 |
Int_t nbin; |
25 |
Float_t rig[18]; |
26 |
Float_t rmean[17]; |
27 |
Int_t ntot[17]; |
28 |
//Float_t qqplane[17][43]; |
29 |
//Int_t nnqplane[17][43]; |
30 |
|
31 |
TArrayF *qplane[17]; |
32 |
TArrayI *nqplane[17]; |
33 |
TMatrixD *matrix[17]; |
34 |
TMatrixD *nmat[17]; |
35 |
|
36 |
TMatrixD *fqplane[17]; |
37 |
TMatrixD *fnqplane[17]; |
38 |
TMatrixF *fmatrix[17]; |
39 |
TMatrixF *fnmat[17]; |
40 |
|
41 |
|
42 |
//=============================================================================== |
43 |
bool Select( PamLevel2* event ){ |
44 |
|
45 |
//--------------------------------------------------------- |
46 |
// single track |
47 |
//--------------------------------------------------------- |
48 |
if( event->GetTrkLevel2()->GetNTracks()!=1 ) return false; |
49 |
PamTrack *track = event->GetTrack(0); |
50 |
if(!track)return false; |
51 |
|
52 |
//------------------------------------------------------------------ |
53 |
// tracker pre-selection |
54 |
//------------------------------------------------------------------ |
55 |
TrkTrack *trk = track->GetTrkTrack(); |
56 |
float rigidity = trk->GetRigidity(); |
57 |
if ( CRIG ) rigidity = event->GetCaloLevel2()->qtot/260.; |
58 |
if ( SRIG ) rigidity = event->GetGPamela()->P0; |
59 |
bool TRACK__OK = false; |
60 |
if( |
61 |
trk->chi2 >0 && |
62 |
trk->GetNX()>=4 && |
63 |
trk->GetNY()>=3 && |
64 |
trk->GetLeverArmX()>=5 && |
65 |
true ) TRACK__OK = true; |
66 |
|
67 |
if( !TRACK__OK )return false; |
68 |
|
69 |
//------------------------------------------------------------------ |
70 |
// TOF pre-selection |
71 |
//------------------------------------------------------------------ |
72 |
bool TOF__OK = false; |
73 |
if( |
74 |
event->GetToFLevel2()->GetNHitPaddles(0) == 1 && |
75 |
event->GetToFLevel2()->GetNHitPaddles(1) == 1 && |
76 |
event->GetToFLevel2()->GetNHitPaddles(2) == 1 && |
77 |
event->GetToFLevel2()->GetNHitPaddles(3) == 1 && |
78 |
event->GetToFLevel2()->GetNHitPaddles(4) >= 1 && |
79 |
event->GetToFLevel2()->GetNHitPaddles(5) >= 1 && |
80 |
event->GetToFLevel2()->npmt() <= 18 && |
81 |
!event->GetAcLevel2()->CARDhit() && |
82 |
!event->GetAcLevel2()->CAThit() && |
83 |
true ) TOF__OK = true; |
84 |
if( !TOF__OK && !SIMU)return false; |
85 |
//------------------------------------------------------ |
86 |
// no albedo |
87 |
//------------------------------------------------------ |
88 |
if( !SIMU && (track->GetToFTrack()->beta[12]<=0.2 || |
89 |
track->GetToFTrack()->beta[12] >= 1.5) ) return false; |
90 |
|
91 |
//------------------------------------------------------ |
92 |
bool CUT1 = false; |
93 |
if( |
94 |
trk->nstep<100 && |
95 |
rigidity<400. && |
96 |
rigidity>0.1 && |
97 |
trk->resx[0]<0.001 && |
98 |
trk->resx[5]<0.001 && |
99 |
track->IsSolved() && |
100 |
trk->IsInsideCavity() && |
101 |
true ) CUT1 = true; |
102 |
//------------------------------------------------------ |
103 |
if( !CUT1 )return false; |
104 |
if ( trk->GetDeflection()>0. && !SIMU ) return false; |
105 |
|
106 |
// |
107 |
// ELENA'S CUT |
108 |
// |
109 |
// |
110 |
// lever-arm 6 |
111 |
//==================================================== |
112 |
bool LX6=false; |
113 |
if( |
114 |
track->GetTrkTrack()->GetLeverArmX()==6 && |
115 |
!track->GetTrkTrack()->IsBad(0,0) && |
116 |
!track->GetTrkTrack()->IsBad(5,0) && |
117 |
track->GetTrkTrack()->resx[0]<0.001 && |
118 |
track->GetTrkTrack()->resx[5]<0.001 && |
119 |
track->GetTrkTrack()->IsInsideCavity() && |
120 |
true ) LX6 = true; |
121 |
|
122 |
//==================================================== |
123 |
// lever-arm 5 |
124 |
//==================================================== |
125 |
bool LX5=false; |
126 |
if( |
127 |
track->GetTrkTrack()->GetLeverArmX()==5 && |
128 |
true ){ |
129 |
if( |
130 |
track->GetTrkTrack()->XGood(0) && track->GetTrkTrack()->XGood(4) |
131 |
){ |
132 |
|
133 |
if( |
134 |
!track->GetTrkTrack()->IsBad(0,0) && |
135 |
!track->GetTrkTrack()->IsBad(4,0) && |
136 |
track->GetTrkTrack()->resx[0]<0.001 && |
137 |
track->GetTrkTrack()->resx[4]<0.001 && |
138 |
track->GetTrkTrack()->IsInsideCavity() && |
139 |
true) LX5 = true; |
140 |
}else if ( |
141 |
track->GetTrkTrack()->XGood(1) && track->GetTrkTrack()->XGood(5) |
142 |
){ |
143 |
|
144 |
if( |
145 |
!track->GetTrkTrack()->IsBad(1,0) && |
146 |
!track->GetTrkTrack()->IsBad(5,0) && |
147 |
track->GetTrkTrack()->resx[1]<0.001 && |
148 |
track->GetTrkTrack()->resx[5]<0.001 && |
149 |
track->GetTrkTrack()->IsInsideCavity() && |
150 |
true) LX5 = true; |
151 |
} |
152 |
} |
153 |
if ( !LX5 && !LX6 ) return false; |
154 |
Float_t defl = trk->GetDeflection(); |
155 |
float p0 = 1.111588e+00; |
156 |
float p1 = 1.707656e+00; |
157 |
float p2 = 1.489693e-01; |
158 |
float chi2m025 = p0 + fabs(defl)*p1 + defl*defl*p2; |
159 |
|
160 |
float def_0 = 0.07; |
161 |
float chi2m025_0 = p0 + fabs(def_0)*p1 + def_0*def_0*p2; |
162 |
|
163 |
// int nchi2cut=5; |
164 |
float chi2cut=3.; |
165 |
float chi2m = pow( chi2m025-chi2m025_0+pow(chi2cut,0.25), 4.); |
166 |
bool CUT2 = false; |
167 |
if( |
168 |
track->GetTrkTrack()->chi2 < chi2m && |
169 |
true ) CUT2 = true; |
170 |
if ( !CUT2 ) return false; |
171 |
float dedxtrk = trk->GetDEDX(); |
172 |
// float zcutn = 9. + 20./(rigidity*rigidity); |
173 |
float zcut2 = 3. + 4.3/(rigidity*rigidity); |
174 |
float zcut1 = 0.52 + 0.455/(rigidity*rigidity); |
175 |
Bool_t Z1 = false; |
176 |
if(dedxtrk > zcut1 && dedxtrk < zcut2){ |
177 |
Z1=true; |
178 |
} |
179 |
if ( !Z1 && !SIMU ) return false; |
180 |
//------------------------------------------------------ |
181 |
// |
182 |
// energy momentum match |
183 |
// |
184 |
Float_t qtotimp = event->GetCaloLevel2()->qtot / trk->GetRigidity(); |
185 |
Float_t qcut2 = (-0.5 * trk->GetRigidity() + 150.) * 1.1; |
186 |
if ( qcut2 < 55. ) qcut2 = 55.; |
187 |
if ( qtotimp <= qcut2 ) return false; |
188 |
// |
189 |
for (Int_t i=0; i < 22; i++){ |
190 |
if ( track->GetCaloTrack()->tibar[i][1] < 0 || track->GetCaloTrack()->tibar[i][0] < 0 ){ |
191 |
return false; |
192 |
}; |
193 |
}; |
194 |
// |
195 |
if ( event->GetCaloLevel2()->qtot == 0. ) return false; |
196 |
if ( rigidity>5. && track->GetCaloTrack()->qtrack/event->GetCaloLevel2()->qtot < 0.4 ) return false; |
197 |
if ( rigidity<1. && track->GetToFTrack()->beta[12] < 0.8 ) return false; |
198 |
if ( rigidity>50. ){ |
199 |
if ( trk->GetNX()<5 && |
200 |
trk->GetNY()<4 ) return false; |
201 |
// |
202 |
Bool_t sphit = false; |
203 |
for ( Int_t plane = 0; plane < 6; plane++){ |
204 |
if ( !trk->XGood(plane) ){ |
205 |
for (Int_t sing = 0; sing < event->GetTrkLevel2()->nclsx(); sing++){ |
206 |
TClonesArray &t = *(event->GetTrkLevel2()->SingletX); |
207 |
TrkSinglet *singlet = (TrkSinglet*)t[sing]; |
208 |
if ( (singlet->plane-1) == plane ){ |
209 |
Float_t x = (singlet->coord[0]+singlet->coord[1])/2.; |
210 |
if ( fabs(track->GetTrkTrack()->xv[plane] - x) < 1. ) sphit = true; |
211 |
}; |
212 |
}; |
213 |
}; |
214 |
if ( !trk->YGood(plane) ){ |
215 |
for (Int_t sing = 0; sing < event->GetTrkLevel2()->nclsy(); sing++){ |
216 |
TClonesArray &t = *(event->GetTrkLevel2()->SingletY); |
217 |
TrkSinglet *singlet = (TrkSinglet*)t[sing]; |
218 |
if ( (singlet->plane-1) == plane ){ |
219 |
Float_t x1 = (singlet->coord[0]); |
220 |
Float_t x2 = (singlet->coord[1]); |
221 |
if ( fabs(track->GetTrkTrack()->yv[plane] - x1) < 1. ) sphit = true; |
222 |
if ( fabs(track->GetTrkTrack()->yv[plane] - x2) < 1. ) sphit = true; |
223 |
}; |
224 |
}; |
225 |
}; |
226 |
}; |
227 |
if ( sphit ) return false; // spurious hit along the track |
228 |
}; |
229 |
// |
230 |
Int_t ti0 = track->GetCaloTrack()->tibar[0][1]-1; |
231 |
|
232 |
Int_t view = 0; |
233 |
Int_t plane = 0; |
234 |
Int_t strip = 0; |
235 |
Float_t mip = 0.; |
236 |
// |
237 |
for ( Int_t i=0; i<event->GetCaloLevel1()->istrip; i++ ){ |
238 |
// |
239 |
mip = event->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); |
240 |
if ( view == 1 && plane == 0 && strip == ti0 && mip > 4.) return false; |
241 |
if ( view == 1 && (plane >0 || strip > ti0) ) break; |
242 |
}; |
243 |
// if ( event->GetCaloLevel1()->qtotpl(0) > 7. ) return false; |
244 |
// |
245 |
return true; |
246 |
} |
247 |
//=============================================================== |
248 |
// Create histograms |
249 |
// |
250 |
// |
251 |
// |
252 |
// |
253 |
// |
254 |
//=============================================================== |
255 |
void CreateHistos( PamLevel2* event , TString file){ |
256 |
|
257 |
cf = new CaloFranzini(event); |
258 |
// |
259 |
if ( MATRIX ){ |
260 |
cf->UpdateMatrixFile(file.Data()); |
261 |
cf->LoadBin(); |
262 |
if ( !FULL ){ |
263 |
cf->LoadLong(); |
264 |
} else { |
265 |
cf->LoadFull(); |
266 |
}; |
267 |
} else { |
268 |
cf->CreateMatrixFile(file.Data()); |
269 |
}; |
270 |
// |
271 |
// |
272 |
nbin = 18; |
273 |
rig[0] = 0.1; |
274 |
rig[1] = 0.5; |
275 |
rig[2] = 1.; |
276 |
rig[3] = 1.5; |
277 |
rig[4] = 2.2; |
278 |
rig[5] = 3.; |
279 |
rig[6] = 4.; |
280 |
rig[7] = 5.; |
281 |
rig[8] = 6.; |
282 |
rig[9] = 8.; |
283 |
rig[10] = 10.; |
284 |
rig[11] = 15.; |
285 |
rig[12] = 25.; |
286 |
rig[13] = 35.; |
287 |
rig[14] = 50.; |
288 |
rig[15] = 100.; |
289 |
rig[16] = 200.; |
290 |
rig[17] = 400.; |
291 |
// |
292 |
memset(rmean, 0, 17*sizeof(Float_t)); |
293 |
memset(ntot, 0, 17*sizeof(Int_t)); |
294 |
// |
295 |
for (Int_t i=0; i < 17 ; i++){ |
296 |
if ( !FULL ){ |
297 |
matrix[i] = new TMatrixD(43,43); |
298 |
qplane[i] = new TArrayF(43); |
299 |
nqplane[i] = new TArrayI(43); |
300 |
nmat[i] = new TMatrixD(43,43); |
301 |
} else { |
302 |
if ( MATRIX ){ |
303 |
fmatrix[i] = new TMatrixF(4128,4128); |
304 |
fnmat[i] = new TMatrixF(4128,4128); |
305 |
//fnmat[i] = new TMatrixI(8213,8213); |
306 |
} else { |
307 |
fqplane[i] = new TMatrixD(43,191); // 43 planes x 191 strip (= 1 + 95 x 2, one strip is the one transversed by the track that could be on the extreme right or left) |
308 |
fnqplane[i] = new TMatrixD(43,191);// |
309 |
}; |
310 |
}; |
311 |
}; |
312 |
// |
313 |
} |
314 |
|
315 |
//=============================================================== |
316 |
void FindAverage( PamLevel2* L2, int iev ){ |
317 |
// |
318 |
Float_t erig = L2->GetTrack(0)->GetTrkTrack()->GetRigidity(); |
319 |
if ( SRIG ) erig = L2->GetGPamela()->P0; |
320 |
if ( CRIG ) erig = L2->GetCaloLevel2()->qtot/260.; |
321 |
// |
322 |
Int_t rbi = 0; |
323 |
for (Int_t i = 0; i<nbin-1; i++){ |
324 |
if ( erig>=rig[i] && erig < rig[i+1] ){ |
325 |
rbi = i; |
326 |
break; |
327 |
}; |
328 |
}; |
329 |
// |
330 |
if ( erig < rig[0] ) return; |
331 |
if ( erig >= rig[nbin-1] ) return; |
332 |
// |
333 |
rmean[rbi] += erig; |
334 |
ntot[rbi]++; |
335 |
// |
336 |
if (!FULL ){ |
337 |
Int_t dgf = 43; |
338 |
// |
339 |
for (Int_t i=0; i<dgf; i++){ |
340 |
(*nqplane[rbi])[i]++; |
341 |
}; |
342 |
// |
343 |
// Fill the estrip matrix |
344 |
// |
345 |
Int_t nplane = 0; |
346 |
Int_t view = 0; |
347 |
Int_t plane = 0; |
348 |
Int_t strip = 0; |
349 |
Float_t mip = 0.; |
350 |
// |
351 |
for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){ |
352 |
// |
353 |
mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); |
354 |
// |
355 |
nplane = 1 - view + 2 * plane; |
356 |
if ( erig > 4. && nplane == 0 && mip > 15. ) printf(" IEV %i erig %f OBT %u pkt %u file %s \n",iev,erig,L2->GetOrbitalInfo()->OBT,L2->GetOrbitalInfo()->pkt_num,L2->GetPamTree()->GetFile()->GetName()); |
357 |
//printf(" IEV %i OBT %u pkt %u file %s \n",iev,L2->GetOrbitalInfo()->OBT,L2->GetOrbitalInfo()->pkt_num,L2->GetPamTree()->GetFile()->GetName()); |
358 |
if ( nplane > 37 ) nplane--; |
359 |
if ( nplane < dgf ){ |
360 |
(*qplane[rbi])[nplane] += mip; |
361 |
}; |
362 |
// |
363 |
}; |
364 |
} else { |
365 |
// |
366 |
// FULL CALORIMETER |
367 |
// |
368 |
CaloTrkVar *ct = L2->GetTrack(0)->GetCaloTrack(); |
369 |
// |
370 |
Int_t nplane = 0; |
371 |
Int_t view = 0; |
372 |
Int_t plane = 0; |
373 |
Int_t strip = 0; |
374 |
Float_t mip = 0.; |
375 |
// |
376 |
Int_t cs = 0; |
377 |
Int_t cd = 0; |
378 |
Int_t mstrip = 0; |
379 |
// |
380 |
for (Int_t j=0; j<2; j++){ |
381 |
for (Int_t i=0; i<21; i++){ |
382 |
nplane = 1 - j + 2*i; |
383 |
if ( nplane > 37 ) nplane--; |
384 |
// |
385 |
cs = ct->tibar[i][j] - 1; |
386 |
// |
387 |
cd = 95 - cs; |
388 |
// |
389 |
for (Int_t k=0; k<191; k++){ |
390 |
mstrip = cd + k; |
391 |
if ( mstrip < (191-cs) ) (*fnqplane[rbi])[nplane][mstrip] += 1.; |
392 |
}; |
393 |
}; |
394 |
}; |
395 |
// |
396 |
// |
397 |
for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){ |
398 |
// |
399 |
mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); |
400 |
// |
401 |
nplane = 1 - view + 2 * plane; |
402 |
if ( nplane > 37 ) nplane--; |
403 |
// |
404 |
cs = ct->tibar[plane][view] - 1; |
405 |
// |
406 |
cd = 95 - cs; |
407 |
// |
408 |
mstrip = cd + strip; |
409 |
// |
410 |
(*fqplane[rbi])[nplane][mstrip] += mip; |
411 |
// |
412 |
}; |
413 |
|
414 |
// |
415 |
}; |
416 |
} |
417 |
|
418 |
void CalculateAverage(){ |
419 |
// |
420 |
if ( !FULL ){ |
421 |
for (Int_t i=0; i<nbin-1; i++){ |
422 |
if ( (*nqplane[i])[0] > 0 ) rmean[i] /= (Float_t)(*nqplane[i])[0]; |
423 |
for (Int_t j=0; j<43 ; j++){ |
424 |
if ( (*nqplane[i])[j] > 0 ){ |
425 |
(*qplane[i])[j] /= (Float_t)(*nqplane[i])[j]; |
426 |
} else { |
427 |
(*qplane[i])[j] = 0.; |
428 |
}; |
429 |
printf(" BIN %i plane %i average energy %f qplane %f nqplane %i \n",i,j,rmean[i],(*qplane[i])[j],(*nqplane[i])[j]); |
430 |
}; |
431 |
}; |
432 |
for (Int_t i=0; i<nbin-1; i++){ |
433 |
// |
434 |
cf->WriteLongMean(qplane[i], i); |
435 |
// |
436 |
}; |
437 |
} else { |
438 |
|
439 |
for (Int_t i=0; i<nbin-1; i++){ |
440 |
if ( ntot[i] > 0 ) rmean[i] /= (Float_t)(ntot[i]); |
441 |
// |
442 |
for (Int_t j=0; j<43 ; j++){ |
443 |
for (Int_t k=0; k<191; k++){ |
444 |
if ( (*fnqplane[i])[j][k] > 0 ){ |
445 |
(*fqplane[i])[j][k] /= (Float_t)(*fnqplane[i])[j][k]; |
446 |
} else { |
447 |
(*fqplane[i])[j][k] = 0.; |
448 |
}; |
449 |
printf(" BIN %i plane %i strip %i average energy %f qplane %f nqplane %f \n",i,j,k,rmean[i],(*fqplane[i])[j][k],(*fnqplane[i])[j][k]); |
450 |
}; |
451 |
}; |
452 |
}; |
453 |
for (Int_t i=0; i<nbin-1; i++){ |
454 |
// |
455 |
cf->WriteFullMean(fqplane[i], i); |
456 |
// |
457 |
}; |
458 |
}; |
459 |
// |
460 |
cf->WriteNumBin(nbin); |
461 |
// |
462 |
TArrayF *rigbin = new TArrayF(18, rig); |
463 |
cf->WriteRigBin(rigbin); |
464 |
// |
465 |
TArrayF *rmeanbin = new TArrayF(17, rmean); |
466 |
TFile *file = cf->GetFile(); |
467 |
file->cd(); |
468 |
file->WriteObject(&(*rmeanbin), "binrigmean"); |
469 |
// |
470 |
// |
471 |
} |
472 |
|
473 |
//=============================================================== |
474 |
void FindMatrix( PamLevel2* L2, int iev ){ |
475 |
// |
476 |
Float_t erig = L2->GetTrack(0)->GetTrkTrack()->GetRigidity(); |
477 |
if ( SRIG ) erig = L2->GetGPamela()->P0; |
478 |
if ( CRIG ) erig = L2->GetCaloLevel2()->qtot/260.; |
479 |
// |
480 |
Int_t rbi = 0; |
481 |
for (Int_t i = 0; i<nbin-1; i++){ |
482 |
if ( erig>=rig[i] && erig < rig[i+1] ){ |
483 |
rbi = i; |
484 |
break; |
485 |
}; |
486 |
}; |
487 |
// |
488 |
if ( erig < rig[0] ) return; |
489 |
if ( erig >= rig[nbin-1] ) return; |
490 |
// |
491 |
if ( !FULL ){ |
492 |
Int_t dgf = 43; |
493 |
// |
494 |
for (Int_t i=0; i<dgf; i++){ |
495 |
for (Int_t j=0; j<dgf; j++){ |
496 |
(*nmat[rbi])[i][j] += 1.; |
497 |
}; |
498 |
}; |
499 |
// |
500 |
// Fill the estrip matrix |
501 |
// |
502 |
Int_t nplane = 0; |
503 |
Int_t view = 0; |
504 |
Int_t plane = 0; |
505 |
Int_t strip = 0; |
506 |
Float_t mip = 0.; |
507 |
Float_t hpl[43]; |
508 |
memset(hpl,0,43*sizeof(Float_t)); |
509 |
for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){ |
510 |
// |
511 |
mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); |
512 |
// |
513 |
nplane = 1 - view + 2 * plane; |
514 |
if ( nplane > 37 ) nplane--; |
515 |
if ( nplane < dgf ){ |
516 |
hpl[nplane] += mip; |
517 |
}; |
518 |
// |
519 |
}; |
520 |
// |
521 |
for (Int_t i=0; i<dgf; i++){ |
522 |
for (Int_t j=0; j<dgf; j++){ |
523 |
(*matrix[rbi])[i][j] += (hpl[i] - cf->GetAverageAt(i,erig)) * (hpl[j] - cf->GetAverageAt(j,erig)); |
524 |
}; |
525 |
}; |
526 |
} else { |
527 |
// |
528 |
// FULL CALORIMETER |
529 |
// |
530 |
CaloTrkVar *ct = L2->GetTrack(0)->GetCaloTrack(); |
531 |
// |
532 |
Int_t nplane = 0; |
533 |
Int_t view = 0; |
534 |
Int_t plane = 0; |
535 |
Int_t strip = 0; |
536 |
Float_t mip = 0.; |
537 |
// |
538 |
Int_t mindgf = 48; |
539 |
Int_t dgf = 143; |
540 |
Int_t cs = 0; |
541 |
Int_t cd = 0; |
542 |
Int_t mstrip = 0; |
543 |
// |
544 |
Float_t mipv[43][191]; |
545 |
memset(mipv,0,43*191*sizeof(Float_t)); |
546 |
// |
547 |
for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){ |
548 |
// |
549 |
mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); |
550 |
// |
551 |
nplane = 1 - view + 2 * plane; |
552 |
if ( nplane > 37 ) nplane--; |
553 |
// |
554 |
cs = ct->tibar[plane][view] - 1; |
555 |
// |
556 |
cd = 95 - cs; |
557 |
// |
558 |
mstrip = cd + strip; |
559 |
// |
560 |
mipv[nplane][mstrip] = mip; |
561 |
// |
562 |
}; |
563 |
// |
564 |
Float_t mip1; |
565 |
Int_t cs1; |
566 |
Int_t cd1; |
567 |
Float_t mip2; |
568 |
Int_t cs2; |
569 |
Int_t cd2; |
570 |
Int_t mi = -1; |
571 |
Int_t mj = -1; |
572 |
Int_t nn1 = 0; |
573 |
Int_t pl1 = 0; |
574 |
Int_t vi1 = 0; |
575 |
Int_t nn2 = 0; |
576 |
Int_t pl2 = 0; |
577 |
Int_t vi2 = 0; |
578 |
Int_t mstrip1min = 0; |
579 |
Int_t mstrip1max = 0; |
580 |
Int_t mstrip2min = 0; |
581 |
Int_t mstrip2max = 0; |
582 |
// |
583 |
for (Int_t nplane1=0; nplane1<43; nplane1++){ |
584 |
for (Int_t mstrip1=0; mstrip1<191; mstrip1++){ |
585 |
mj = -1; |
586 |
// |
587 |
if ( nplane1 >= 37 ) nn1 = nplane1 + 1; |
588 |
vi1 = 1; |
589 |
if ( nn1%2 ) vi1 = 0; |
590 |
pl1 = (nn1 - 1 + vi1)/2; |
591 |
// |
592 |
cs1 = ct->tibar[pl1][vi1] - 1; // convertire nplane in pl1 e vi1 |
593 |
// |
594 |
cd1 = 95 - cs1; |
595 |
// |
596 |
mstrip1min = cd1 + 0; |
597 |
mstrip1max = cd1 + 95; |
598 |
mip1 = mipv[nplane1][mstrip1]; |
599 |
// |
600 |
if ( mstrip1 >= mindgf && mstrip1 <= dgf ){ |
601 |
mi++; |
602 |
// |
603 |
for (Int_t nplane2=0; nplane2<43; nplane2++){ |
604 |
for (Int_t mstrip2=0; mstrip2<191; mstrip2++){ |
605 |
// |
606 |
if ( nplane2 >= 37 ) nn2 = nplane2 + 1; |
607 |
vi2 = 1; |
608 |
if ( nn2%2 ) vi2 = 0; |
609 |
pl1 = (nn2 - 1 + vi2)/2; |
610 |
// |
611 |
cs2 = ct->tibar[pl2][vi2] - 1; |
612 |
// |
613 |
cd2 = 95 - cs2; |
614 |
// |
615 |
mstrip2min = cd2 + 0; |
616 |
mstrip2max = cd2 + 95; |
617 |
// |
618 |
mip2 = mipv[nplane2][mstrip2]; |
619 |
// |
620 |
if ( mstrip2 >= mindgf && mstrip2 <= dgf ){ |
621 |
mj++; |
622 |
(*fmatrix[rbi])[mi][mj] += (mipv[nplane1][mstrip1] - cf->GetFullAverageAt(nplane1,mstrip1,erig)) * (mipv[nplane2][mstrip2] - cf->GetFullAverageAt(nplane2,mstrip2,erig)); |
623 |
if ( mstrip1 >= mstrip1min && mstrip1 <= mstrip1max && mstrip2 >= mstrip2min && mstrip2 <= mstrip2max){ |
624 |
(*fnmat[rbi])[mi][mj] += 1.; |
625 |
}; |
626 |
}; |
627 |
}; |
628 |
}; |
629 |
}; |
630 |
}; |
631 |
}; |
632 |
// |
633 |
}; |
634 |
} |
635 |
|
636 |
//=============================================================== |
637 |
// Save histograms |
638 |
// |
639 |
// |
640 |
// |
641 |
// |
642 |
// |
643 |
//=============================================================== |
644 |
void SaveHistos(){ |
645 |
// |
646 |
if ( MATRIX ){ |
647 |
// |
648 |
printf("Finished, calculating average and inverting matrices\n"); |
649 |
// |
650 |
if ( !FULL ){ |
651 |
for (Int_t i=0; i<nbin-1; i++){ |
652 |
// |
653 |
// determine the average matrix |
654 |
// |
655 |
for (Int_t ii=0; ii<43; ii++){ |
656 |
for (Int_t j=0; j<43; j++){ |
657 |
if ( (*nmat[i])[ii][j] > 0. ){ |
658 |
(*matrix[i])[ii][j] /= (*nmat[i])[ii][j]; |
659 |
} else { |
660 |
(*matrix[i])[ii][j] = 0.; |
661 |
}; |
662 |
}; |
663 |
}; |
664 |
// |
665 |
cf->WriteLongMatrix(matrix[i],i); |
666 |
// |
667 |
if ( matrix[i]->Determinant() == 0. ){ |
668 |
printf("\n"); |
669 |
for (Int_t ii=0; ii<43; ii++){ |
670 |
for (Int_t j=0; j<43; j++){ |
671 |
printf(" %.f",(*matrix[i])[ii][j]); |
672 |
}; |
673 |
printf("\n"); |
674 |
}; |
675 |
printf("\n"); |
676 |
printf(" ERROR: the matrix at bin %i is singular, determinant = 0., it cannot be inverted! \n",i); |
677 |
} else { |
678 |
Double_t det = 0.; |
679 |
TMatrixD invmatrix = (TMatrixD)(matrix[i]->Invert(&det)); |
680 |
printf(" Bin %i determinant is %f \n",i,det); |
681 |
cf->WriteInvertedLongMatrix((TMatrixD)invmatrix,i); |
682 |
}; |
683 |
}; |
684 |
} else { |
685 |
// |
686 |
// FULL |
687 |
// |
688 |
for (Int_t i=0; i<nbin-1; i++){ |
689 |
// |
690 |
// determine the average matrix |
691 |
// |
692 |
for (Int_t ii=0; ii<4171; ii++){ |
693 |
for (Int_t j=0; j<4171; j++){ |
694 |
if ( (*fnmat[i])[ii][j] > 0. ){ |
695 |
(*fmatrix[i])[ii][j] /= (*fnmat[i])[ii][j]; |
696 |
} else { |
697 |
(*fmatrix[i])[ii][j] = 0.; |
698 |
}; |
699 |
}; |
700 |
}; |
701 |
// |
702 |
cf->WriteFullMatrix(fmatrix[i],i); |
703 |
// |
704 |
if ( fmatrix[i]->Determinant() == 0. ){ |
705 |
printf(" ERROR: the matrix at bin %i is singular, determinant = 0., it cannot be inverted! \n",i); |
706 |
} else { |
707 |
Double_t det = 0.; |
708 |
TMatrixF invmatrix = (TMatrixF)(fmatrix[i]->Invert(&det)); |
709 |
printf(" Bin %i determinant is %f \n",i,det); |
710 |
cf->WriteInvertedFullMatrix((TMatrixF)invmatrix,i); |
711 |
}; |
712 |
}; |
713 |
}; |
714 |
// |
715 |
printf(" done, closing file and exiting\n"); |
716 |
// |
717 |
}; |
718 |
// |
719 |
cf->CloseMatrixFile(); |
720 |
// |
721 |
cf->Delete(); |
722 |
// |
723 |
} |