1 |
// |
// |
2 |
// Check the calorimter calibrations - Emiliano Mocchiutti |
// Check the calorimter calibrations - Emiliano Mocchiutti |
3 |
// |
// |
4 |
// FCaloCHKCALIB.c version 1.13 (2006-09-22) |
// FCaloCHKCALIB.c version 1.14 (2007-07-18) |
5 |
// |
// |
6 |
// The only input needed is the path to the directory created by YODA for the data file you want to analyze. |
// The only input needed is the path to the directory created by YODA for the data file you want to analyze. |
7 |
// |
// |
8 |
// Changelog: |
// Changelog: |
9 |
// |
// |
10 |
|
// 1.12 - 1.14 (2007-07-18): 05953 bug fixed (infinite loop). |
11 |
|
// |
12 |
// 1.12 - 1.13 (2006-09-22): Set upper limit in calvar plot. |
// 1.12 - 1.13 (2006-09-22): Set upper limit in calvar plot. |
13 |
// |
// |
14 |
// 1.07 - 1.12 (2006-08-04): bugs fixed. |
// 1.07 - 1.12 (2006-08-04): bugs fixed. |
34 |
#include <iostream> |
#include <iostream> |
35 |
#include <fstream> |
#include <fstream> |
36 |
// |
// |
37 |
|
#include <TROOT.h> |
38 |
#include <TTree.h> |
#include <TTree.h> |
39 |
#include <TObject.h> |
#include <TObject.h> |
40 |
#include <TString.h> |
#include <TString.h> |
199 |
cpuhe->SetBranchAddress("Header",&ch); |
cpuhe->SetBranchAddress("Header",&ch); |
200 |
// |
// |
201 |
Long64_t ncalibs = tr->GetEntries();//cerca il ramo Entries (calibrazioni) |
Long64_t ncalibs = tr->GetEntries();//cerca il ramo Entries (calibrazioni) |
202 |
if ( ncalibs == 0 ){ |
if ( ncalibs == 0 || cpuhe->GetEntries() == 0){ |
203 |
printf(" No calibrations in this files! \n Exiting... \n"); |
printf(" No calibrations in this files! \n Exiting... \n"); |
204 |
return; |
return; |
205 |
}; |
}; |
206 |
|
// |
207 |
|
UInt_t cpuhead[1000]; |
208 |
|
memset(cpuhead, 0, 1000*sizeof(UInt_t)); |
209 |
|
for (Int_t i=0; i<cpuhe->GetEntries(); i++){ |
210 |
|
cpuhe->GetEntry(i); |
211 |
|
if ( i < 1000 ) cpuhead[i]=ch->GetPscuHeader()->GetOrbitalTime(); |
212 |
|
if ( i > 1000 ){ |
213 |
|
printf(" ERROR: too many calibrations in this file, cannot handle it \n Exiting... \n"); |
214 |
|
return; |
215 |
|
}; |
216 |
|
}; |
217 |
|
// |
218 |
printf("\n This file contains %i entries which corrispond to %i calibrations \n\n",(int)ncalibs,(int)ncalibs/4); |
printf("\n This file contains %i entries which corrispond to %i calibrations \n\n",(int)ncalibs,(int)ncalibs/4); |
219 |
Long64_t minev = 0; |
Long64_t minev = 0; |
220 |
Long64_t maxev = ncalibs; |
Long64_t maxev = ncalibs; |
255 |
stringstream figsave; //definisco stringhe i/o |
stringstream figsave; //definisco stringhe i/o |
256 |
stringstream figsave1; |
stringstream figsave1; |
257 |
stringstream figsave2; |
stringstream figsave2; |
258 |
|
if ( !strcmp(format,"ps") ) { |
259 |
|
figsave.str(""); |
260 |
|
figsave << outdir << "/" ; |
261 |
|
figsave << figrec << "_CaloCHKCALIB."; |
262 |
|
figsave << format; |
263 |
|
figsave << "("; |
264 |
|
}; |
265 |
// |
// |
266 |
|
|
267 |
//-----------------inizio CHECK per ricerca errori dal calorimetro------------------- |
//-----------------inizio CHECK per ricerca errori dal calorimetro------------------- |
270 |
Bool_t check = false;//azzera flag presenza errori |
Bool_t check = false;//azzera flag presenza errori |
271 |
|
|
272 |
// |
// |
273 |
|
Int_t hi = (minev/4)-1; |
274 |
//inizio loop su tutti gli header degli eventi di calibrazione |
//inizio loop su tutti gli header degli eventi di calibrazione |
275 |
for (Int_t ci = minev; ci < maxev ; ci+=4){ |
// for (Int_t ci = minev; ci < maxev ; ci+=4){ |
276 |
|
Int_t ci = minev; |
277 |
|
while ( ci < maxev ){ |
278 |
//scorre i pacchetti di 4 in 4 (cioe scorre le calibrazioni) |
//scorre i pacchetti di 4 in 4 (cioe scorre le calibrazioni) |
279 |
Int_t incalrms = 0; |
Int_t incalrms = 0; |
280 |
Int_t outcalrms = 0; |
Int_t outcalrms = 0; |
288 |
Int_t incalbas = 0; |
Int_t incalbas = 0; |
289 |
Int_t outcalbas = 0; |
Int_t outcalbas = 0; |
290 |
//dall'albero calibheader, cerco obt dell cpu |
//dall'albero calibheader, cerco obt dell cpu |
291 |
cpuhe->GetEntry(ci/4); |
// cpuhe->GetEntry(ci/4); |
292 |
cpuobt=ch->GetPscuHeader()->GetOrbitalTime(); |
hi++; |
293 |
|
// cpuobt=ch->GetPscuHeader()->GetOrbitalTime(); |
294 |
|
cpuobt=cpuhead[hi]; |
295 |
obt0=0; |
obt0=0; |
296 |
obt1=0; |
obt1=0; |
297 |
obt2=0; |
obt2=0; |
298 |
obt3=0; |
obt3=0; |
299 |
|
// |
300 |
|
calib.iev=0; |
301 |
|
memset(calib.cstwerr,0,4*sizeof(Int_t)); |
302 |
|
memset(calib.cperror,0,4*sizeof(Float_t)); |
303 |
|
memset(calib.calped,0,2*22*96*sizeof(Float_t)); |
304 |
|
memset(calib.calgood,0,2*22*96*sizeof(Float_t)); |
305 |
|
memset(calib.calrms,0,2*22*96*sizeof(Float_t)); |
306 |
|
memset(calib.calpuls,0,2*22*96*sizeof(Float_t)); |
307 |
|
memset(calib.calthr,0,2*22*6*sizeof(Float_t)); |
308 |
|
memset(calib.calvar,0,2*22*6*sizeof(Float_t)); |
309 |
|
memset(calib.calbase,0,2*22*6*sizeof(Float_t)); |
310 |
|
// |
311 |
//inizio loop su i 4 pacchetti per ogni calibrazione (scorre 4 successivi) |
//inizio loop su i 4 pacchetti per ogni calibrazione (scorre 4 successivi) |
312 |
for ( Int_t s=0 ; s<4 ;s++ ){ |
// for ( Int_t s=0 ; s<4 ;s++ ){ |
313 |
|
Int_t s = 0; |
314 |
|
obt = cpuhead[hi]; |
315 |
|
// printf(" qui cpu header : %i hi %i entry %i \n",obt,hi,ci); |
316 |
|
if ( !obt ) break; |
317 |
|
while ( (labs((Int_t)(obt-cpuhead[hi])) < 100000 && ci < maxev) || !cpuobt ){ |
318 |
|
|
319 |
tr->GetEntry(ci+s);//sceglie la entry (calibrazione)del tree in cui ho tutte le sottostrutture |
tr->GetEntry(ci);//sceglie la entry (calibrazione)del tree in cui ho tutte le sottostrutture |
320 |
|
// tr->GetEntry(ci+s);//sceglie la entry (calibrazione)del tree in cui ho tutte le sottostrutture |
321 |
|
|
322 |
|
//trovo l'OBT della entry (pacchetto) |
|
//trovo l'OBT della entry (pacchetto) |
|
323 |
obt=eh->GetPscuHeader()->GetOrbitalTime();//cerca orbitaltime all'interno di Pscu |
obt=eh->GetPscuHeader()->GetOrbitalTime();//cerca orbitaltime all'interno di Pscu |
324 |
/// |
// |
325 |
|
//printf(" qui pkt header : %i \n",obt); |
326 |
|
|
327 |
|
ci++; |
328 |
|
|
329 |
|
if ( labs((Int_t)(obt-cpuhead[hi])) < 100000 ){ |
330 |
|
|
331 |
calib.iev = ce->iev; |
// s++; |
332 |
cestw = 0; |
if ( ce->cstwerr[0] ) s = 0; |
333 |
//cstwerr e' tutto l'header della sezione, mi interessano gli ultimi 2 Byte(errori del calorimetro) |
if ( ce->cstwerr[1] ) s = 1; |
334 |
if ( ce->cstwerr[s] ){ |
if ( ce->cstwerr[2] ) s = 2; |
335 |
cestw = ce->cstwerr[s] & cmask ; //confronto con la maschera per tenere solo gli |
if ( ce->cstwerr[3] ) s = 3; |
336 |
ver[s][16]++;// ultimi 2 Byte (assegnati a cestw) |
//printf(" qua pkt header : %i s = %i hi %i \n",obt,s,hi); |
337 |
}; |
// |
338 |
if ( cestw ){//errori dal calorimetro |
calib.iev = ce->iev; |
339 |
if ( cestw & (1 << 0) ) ver[s][6]++ ;//spostati di uno e confronto se diverso 0 |
cestw = 0; |
340 |
if ( cestw & (1 << 1) ) ver[s][5]++ ; |
//cstwerr e' tutto l'header della sezione, mi interessano gli ultimi 2 Byte(errori del calorimetro) |
341 |
if ( cestw & (1 << 2) ) ver[s][4]++ ; |
if ( ce->cstwerr[s] ){ |
342 |
if ( cestw & (1 << 3) ) ver[s][3]++ ; |
cestw = ce->cstwerr[s] & cmask ; //confronto con la maschera per tenere solo gli |
343 |
if ( cestw & (1 << 4) ) ver[s][2]++ ; |
ver[s][16]++;// ultimi 2 Byte (assegnati a cestw) |
|
if ( cestw & (1 << 5) ) ver[s][1]++ ; |
|
|
if ( cestw & (1 << 6) ) ver[s][0]++ ; |
|
|
}; |
|
|
if ( ce->cperror[s] != 0. ){//errori dallo spacchettamento |
|
|
if (ce->cperror[s] == 128) ver[s][7]++ ; |
|
|
if (ce->cperror[s] == 129) ver[s][8]++ ; |
|
|
if (ce->cperror[s] == 130) { |
|
|
ver[s][9]++ ; |
|
|
ver[s][16]--; |
|
344 |
}; |
}; |
345 |
if (ce->cperror[s] == 132) ver[s][11]++ ; |
if ( cestw ){//errori dal calorimetro |
346 |
if (ce->cperror[s] == 140) ver[s][19]++ ; |
if ( cestw & (1 << 0) ) ver[s][6]++ ;//spostati di uno e confronto se diverso 0 |
347 |
if (ce->cperror[s] == 141) ver[s][20]++ ; |
if ( cestw & (1 << 1) ) ver[s][5]++ ; |
348 |
if (ce->cperror[s] == 142) ver[s][22]++ ; |
if ( cestw & (1 << 2) ) ver[s][4]++ ; |
349 |
}; |
if ( cestw & (1 << 3) ) ver[s][3]++ ; |
350 |
//lato oscuro :p |
if ( cestw & (1 << 4) ) ver[s][2]++ ; |
351 |
for ( Int_t d=0 ; d<11 ;d++ ){ |
if ( cestw & (1 << 5) ) ver[s][1]++ ; |
352 |
Int_t pre = -1; |
if ( cestw & (1 << 6) ) ver[s][0]++ ; |
353 |
for ( Int_t j=0; j<96 ;j++){ |
}; |
354 |
if ( j%16 == 0 ) pre++; |
if ( ce->cperror[s] != 0. ){//errori dallo spacchettamento |
355 |
if ( s == 2 ){ |
if (ce->cperror[s] == 128) ver[s][7]++ ; |
356 |
//aggiungo obt del pacchetto che sta leggendo(obt) |
if (ce->cperror[s] == 129) ver[s][8]++ ; |
357 |
obt2=obt; |
if (ce->cperror[s] == 130) { |
358 |
calib.calped[0][2*d+1][j] = ce->calped[3][d][j]; |
ver[s][9]++ ; |
359 |
calib.cstwerr[3] = ce->cstwerr[3]; |
ver[s][16]--; |
|
calib.cperror[3] = ce->cperror[3]; |
|
|
calib.calgood[0][2*d+1][j] = ce->calgood[3][d][j]; |
|
|
calib.calthr[0][2*d+1][pre] = ce->calthr[3][d][pre]; |
|
|
calib.calrms[0][2*d+1][j] = ce->calrms[3][d][j]; |
|
|
calib.calbase[0][2*d+1][pre] = ce->calbase[3][d][pre]; |
|
|
calib.calvar[0][2*d+1][pre] = ce->calvar[3][d][pre]; |
|
|
}; |
|
|
if ( s == 3 ){ |
|
|
obt3=obt; |
|
|
calib.calped[0][2*d][j] = ce->calped[1][d][j]; |
|
|
calib.cstwerr[1] = ce->cstwerr[1]; |
|
|
calib.cperror[1] = ce->cperror[1]; |
|
|
calib.calgood[0][2*d][j] = ce->calgood[1][d][j]; |
|
|
calib.calthr[0][2*d][pre] = ce->calthr[1][d][pre]; |
|
|
calib.calrms[0][2*d][j] = ce->calrms[1][d][j]; |
|
|
calib.calbase[0][2*d][pre] = ce->calbase[1][d][pre]; |
|
|
calib.calvar[0][2*d][pre] = ce->calvar[1][d][pre]; |
|
|
}; |
|
|
if ( s == 0 ){ |
|
|
obt0=obt; |
|
|
calib.calped[1][2*d][j] = ce->calped[0][d][j]; |
|
|
calib.cstwerr[0] = ce->cstwerr[0]; |
|
|
calib.cperror[0] = ce->cperror[0]; |
|
|
calib.calgood[1][2*d][j] = ce->calgood[0][d][j]; |
|
|
calib.calthr[1][2*d][pre] = ce->calthr[0][d][pre]; |
|
|
calib.calrms[1][2*d][j] = ce->calrms[0][d][j]; |
|
|
calib.calbase[1][2*d][pre] = ce->calbase[0][d][pre]; |
|
|
calib.calvar[1][2*d][pre] = ce->calvar[0][d][pre]; |
|
|
}; |
|
|
if ( s == 1 ){ |
|
|
obt1=obt; |
|
|
calib.calped[1][2*d+1][j] = ce->calped[2][d][j]; |
|
|
calib.cstwerr[2] = ce->cstwerr[2]; |
|
|
calib.cperror[2] = ce->cperror[2]; |
|
|
calib.calgood[1][2*d+1][j] = ce->calgood[2][d][j]; |
|
|
calib.calthr[1][2*d+1][pre] = ce->calthr[2][d][pre]; |
|
|
calib.calrms[1][2*d+1][j] = ce->calrms[2][d][j]; |
|
|
calib.calbase[1][2*d+1][pre] = ce->calbase[2][d][pre]; |
|
|
calib.calvar[1][2*d+1][pre] = ce->calvar[2][d][pre]; |
|
360 |
}; |
}; |
361 |
|
if (ce->cperror[s] == 132) ver[s][11]++ ; |
362 |
|
if (ce->cperror[s] == 140) ver[s][19]++ ; |
363 |
|
if (ce->cperror[s] == 141) ver[s][20]++ ; |
364 |
|
if (ce->cperror[s] == 142) ver[s][22]++ ; |
365 |
}; |
}; |
366 |
};//chiuso for su si(sezioni) |
//lato oscuro :p |
367 |
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
368 |
|
Int_t pre = -1; |
369 |
|
for ( Int_t j=0; j<96 ;j++){ |
370 |
|
if ( j%16 == 0 ) pre++; |
371 |
|
if ( s == 2 ){ |
372 |
|
//aggiungo obt del pacchetto che sta leggendo(obt) |
373 |
|
obt2=obt; |
374 |
|
calib.calped[0][2*d+1][j] = ce->calped[3][d][j]; |
375 |
|
calib.cstwerr[3] = ce->cstwerr[3]; |
376 |
|
calib.cperror[3] = ce->cperror[3]; |
377 |
|
calib.calgood[0][2*d+1][j] = ce->calgood[3][d][j]; |
378 |
|
calib.calthr[0][2*d+1][pre] = ce->calthr[3][d][pre]; |
379 |
|
calib.calrms[0][2*d+1][j] = ce->calrms[3][d][j]; |
380 |
|
calib.calbase[0][2*d+1][pre] = ce->calbase[3][d][pre]; |
381 |
|
calib.calvar[0][2*d+1][pre] = ce->calvar[3][d][pre]; |
382 |
|
}; |
383 |
|
if ( s == 3 ){ |
384 |
|
obt3=obt; |
385 |
|
calib.calped[0][2*d][j] = ce->calped[1][d][j]; |
386 |
|
calib.cstwerr[1] = ce->cstwerr[1]; |
387 |
|
calib.cperror[1] = ce->cperror[1]; |
388 |
|
calib.calgood[0][2*d][j] = ce->calgood[1][d][j]; |
389 |
|
calib.calthr[0][2*d][pre] = ce->calthr[1][d][pre]; |
390 |
|
calib.calrms[0][2*d][j] = ce->calrms[1][d][j]; |
391 |
|
calib.calbase[0][2*d][pre] = ce->calbase[1][d][pre]; |
392 |
|
calib.calvar[0][2*d][pre] = ce->calvar[1][d][pre]; |
393 |
|
}; |
394 |
|
if ( s == 0 ){ |
395 |
|
obt0=obt; |
396 |
|
calib.calped[1][2*d][j] = ce->calped[0][d][j]; |
397 |
|
calib.cstwerr[0] = ce->cstwerr[0]; |
398 |
|
calib.cperror[0] = ce->cperror[0]; |
399 |
|
calib.calgood[1][2*d][j] = ce->calgood[0][d][j]; |
400 |
|
calib.calthr[1][2*d][pre] = ce->calthr[0][d][pre]; |
401 |
|
calib.calrms[1][2*d][j] = ce->calrms[0][d][j]; |
402 |
|
calib.calbase[1][2*d][pre] = ce->calbase[0][d][pre]; |
403 |
|
calib.calvar[1][2*d][pre] = ce->calvar[0][d][pre]; |
404 |
|
}; |
405 |
|
if ( s == 1 ){ |
406 |
|
obt1=obt; |
407 |
|
calib.calped[1][2*d+1][j] = ce->calped[2][d][j]; |
408 |
|
calib.cstwerr[2] = ce->cstwerr[2]; |
409 |
|
calib.cperror[2] = ce->cperror[2]; |
410 |
|
calib.calgood[1][2*d+1][j] = ce->calgood[2][d][j]; |
411 |
|
calib.calthr[1][2*d+1][pre] = ce->calthr[2][d][pre]; |
412 |
|
calib.calrms[1][2*d+1][j] = ce->calrms[2][d][j]; |
413 |
|
calib.calbase[1][2*d+1][pre] = ce->calbase[2][d][pre]; |
414 |
|
calib.calvar[1][2*d+1][pre] = ce->calvar[2][d][pre]; |
415 |
|
}; |
416 |
|
|
417 |
|
}; |
418 |
|
};//chiuso for su si(sezioni) |
419 |
|
} else { |
420 |
|
ci--; |
421 |
|
}; |
422 |
};//chiuso for su ci(eventi) |
};//chiuso for su ci(eventi) |
423 |
// |
// |
424 |
//fine CHECK |
//fine CHECK |
425 |
|
|
426 |
// |
// |
427 |
// Book the histograms: |
// Book the histograms: |
428 |
Int_t i = (ci-minev)/4; |
// Int_t i = (ci-minev)/4; |
429 |
|
Int_t i = hi; |
430 |
xviewev.str(""); |
xviewev.str(""); |
431 |
xviewev << "x-view event " << (i+1); |
xviewev << "x-view event " << (i+1); |
432 |
yviewev.str(""); |
yviewev.str(""); |
592 |
incalvar++; |
incalvar++; |
593 |
}; |
}; |
594 |
calbase->Fill((float)g,(float)calib.calbase[l][m][n]);//controlla baseline |
calbase->Fill((float)g,(float)calib.calbase[l][m][n]);//controlla baseline |
595 |
if ( calib.calbase[l][m][n] > 4500. || calib.calbase[l][m][n] < 2000. ){ |
if ( calib.calbase[l][m][n] > 5500. || calib.calbase[l][m][n] < 2000. ){ |
596 |
outcalbas++; |
outcalbas++; |
597 |
} else { |
} else { |
598 |
incalbas++; |
incalbas++; |
944 |
calbase->SetYTitle("ADC channels"); |
calbase->SetYTitle("ADC channels"); |
945 |
calbase->Draw(); |
calbase->Draw(); |
946 |
Double_t xg[4] = {0.,264.,264.,0.}; |
Double_t xg[4] = {0.,264.,264.,0.}; |
947 |
Double_t yg[4] = {2000.,2000.,4500.,4500.}; |
Double_t yg[4] = {2000.,2000.,5500.,5500.}; |
948 |
banda1 = new TPolyLine(4,xg,yg); |
banda1 = new TPolyLine(4,xg,yg); |
949 |
banda1->SetLineColor(5); |
banda1->SetLineColor(5); |
950 |
banda1->SetFillColor(5); |
banda1->SetFillColor(5); |
959 |
// |
// |
960 |
//file output |
//file output |
961 |
if ( !strcmp(format,"ps") ) { |
if ( !strcmp(format,"ps") ) { |
|
if ( ci == minev ) { |
|
|
figsave.str(""); |
|
|
figsave << outdir << "/" ; |
|
|
figsave << figrec << "_CaloCHKCALIB."; |
|
|
figsave << format; |
|
|
figsave << "("; |
|
|
}; |
|
962 |
if ( figmatra ) { |
if ( figmatra ) { |
963 |
figura2->Print(figsave.str().c_str(),"Portrait"); |
figura2->Print(figsave.str().c_str(),"Portrait"); |
964 |
if ( ci == minev ) { |
if ( ci == minev ) { |