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