56 |
clevel1 = &clevel1_; |
clevel1 = &clevel1_; |
57 |
clevel2 = &clevel2_; |
clevel2 = &clevel2_; |
58 |
// |
// |
59 |
|
// extern struct FlEventi eventi_; |
60 |
|
// extern struct FlGruppo gruppo_; |
61 |
|
// extern struct FlGruppo2 gruppo2_; |
62 |
|
// extern struct FlGruppo4 gruppo4_; |
63 |
|
// extern struct FlTaglioen taglioen_; |
64 |
|
// extern struct FlAngolo angolo_; |
65 |
|
// extern struct FlWhere where_; |
66 |
|
// extern struct FlGeneral general_; |
67 |
|
// extern struct FlCh ch_; |
68 |
|
// extern struct FlCalofit calofit_; |
69 |
|
// extern struct FlPawcd pawcd_; |
70 |
|
// extern struct FlQuestd questd_; |
71 |
|
// eventi = &eventi_; |
72 |
|
// gruppo = &gruppo_; |
73 |
|
// gruppo2 = &gruppo2_; |
74 |
|
// gruppo4 = &gruppo4_; |
75 |
|
// taglioen = &taglioen_; |
76 |
|
// angolo = &angolo_; |
77 |
|
// where = &where_; |
78 |
|
// general = &general_; |
79 |
|
// ch = &ch_; |
80 |
|
// calofit = &calofit_; |
81 |
|
// pawcd = &pawcd_; |
82 |
|
// questd = &questd_; |
83 |
|
// |
84 |
trkseqno = 0; |
trkseqno = 0; |
85 |
ClearStructs(); |
ClearStructs(); |
86 |
// |
// |
92 |
memset(obadmask, 0, 2*22*96*sizeof(Int_t)); |
memset(obadmask, 0, 2*22*96*sizeof(Int_t)); |
93 |
memset(obadpulsemask, 0, 2*22*6*sizeof(Int_t)); |
memset(obadpulsemask, 0, 2*22*6*sizeof(Int_t)); |
94 |
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
95 |
|
memset(ctsicor, 0, 2*22*9*sizeof(Float_t)); |
96 |
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
97 |
calopar1 = true; |
calopar1 = true; |
98 |
calopar2 = true; |
calopar2 = true; |
99 |
calopar3 = true; |
calopar3 = true; |
100 |
|
calopar4 = true; |
101 |
|
calopar5 = true; |
102 |
crosst = true; |
crosst = true; |
103 |
|
mask18 = false; |
104 |
ftcalopar1 = 0; |
ftcalopar1 = 0; |
105 |
ttcalopar1 = 0; |
ttcalopar1 = 0; |
106 |
ftcalopar2 = 0; |
ftcalopar2 = 0; |
107 |
ttcalopar2 = 0; |
ttcalopar2 = 0; |
108 |
ftcalopar3 = 0; |
ftcalopar3 = 0; |
109 |
ttcalopar3 = 0; |
ttcalopar3 = 0; |
110 |
|
ftcalopar4 = 0; |
111 |
|
ttcalopar4 = 0; |
112 |
|
ftcalopar5 = 0; |
113 |
|
ttcalopar5 = 0; |
114 |
} |
} |
115 |
|
|
116 |
void CaloLevel0::SetCrossTalk(Bool_t ct){ |
void CaloLevel0::SetCrossTalk(Bool_t ct){ |
121 |
ctground = ct; |
ctground = ct; |
122 |
} |
} |
123 |
|
|
124 |
|
void CaloLevel0::SetCrossTalkType(Int_t ct){ |
125 |
|
if ( ct == 0 ) ctground = true; |
126 |
|
if ( ct == 1 ){ |
127 |
|
ctground = false; |
128 |
|
noselfct = false; |
129 |
|
}; |
130 |
|
if ( ct == 2 ){ |
131 |
|
ctground = false; |
132 |
|
noselfct = true; |
133 |
|
}; |
134 |
|
} |
135 |
|
|
136 |
void CaloLevel0::SetVerbose(Bool_t ct){ |
void CaloLevel0::SetVerbose(Bool_t ct){ |
137 |
verbose = ct; |
verbose = ct; |
138 |
} |
} |
140 |
/** |
/** |
141 |
* Initialize CaloLevel0 object |
* Initialize CaloLevel0 object |
142 |
**/ |
**/ |
143 |
|
void CaloLevel0::ProcessingInit(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
144 |
|
if ( !dbc->IsConnected() ) throw -116; |
145 |
|
this->InitDo(dbc,hs,sgnl,l0tree,isdeb,isverb); |
146 |
|
} |
147 |
|
|
148 |
|
/** |
149 |
|
* Initialize CaloLevel0 object |
150 |
|
**/ |
151 |
void CaloLevel0::ProcessingInit(GL_TABLES *glt, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
void CaloLevel0::ProcessingInit(GL_TABLES *glt, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
152 |
// |
// |
153 |
const TString host = glt->CGetHost(); |
const TString host = glt->CGetHost(); |
155 |
const TString psw = glt->CGetPsw(); |
const TString psw = glt->CGetPsw(); |
156 |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
157 |
if ( !dbc->IsConnected() ) throw -116; |
if ( !dbc->IsConnected() ) throw -116; |
158 |
|
this->InitDo(dbc,hs,sgnl,l0tree,isdeb,isverb); |
159 |
|
dbc->Close(); |
160 |
|
delete dbc; |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
void CaloLevel0::InitDo(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
165 |
stringstream myquery; |
stringstream myquery; |
166 |
myquery.str(""); |
myquery.str(""); |
167 |
myquery << "SET time_zone='+0:00'"; |
myquery << "SET time_zone='+0:00'"; |
242 |
// |
// |
243 |
delete glcalo; |
delete glcalo; |
244 |
delete glroot; |
delete glroot; |
|
dbc->Close(); |
|
|
delete dbc; |
|
245 |
// |
// |
246 |
return; |
return; |
247 |
// |
// |
258 |
return(sgnl); |
return(sgnl); |
259 |
} |
} |
260 |
|
|
261 |
|
Int_t CaloLevel0::ChkParam(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){ |
262 |
|
Int_t sig = this->ChkParamDo(dbc,runheader,mechal); |
263 |
|
return(sig); |
264 |
|
} |
265 |
|
|
266 |
Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){ |
Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){ |
267 |
const TString host = glt->CGetHost(); |
const TString host = glt->CGetHost(); |
268 |
const TString user = glt->CGetUser(); |
const TString user = glt->CGetUser(); |
274 |
myquery << "SET time_zone='+0:00'"; |
myquery << "SET time_zone='+0:00'"; |
275 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
276 |
// |
// |
277 |
|
Int_t sig = this->ChkParamDo(dbc,runheader,mechal); |
278 |
|
dbc->Close(); |
279 |
|
delete dbc; |
280 |
|
return(sig); |
281 |
|
} |
282 |
|
|
283 |
|
Int_t CaloLevel0::ChkParamDo(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){ |
284 |
|
// |
285 |
stringstream calfile; |
stringstream calfile; |
286 |
stringstream bmfile; |
stringstream bmfile; |
287 |
stringstream aligfile; |
stringstream aligfile; |
292 |
// |
// |
293 |
if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){ |
if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){ |
294 |
// |
// |
|
// |
|
|
// |
|
295 |
if ( debug ) printf(" calopar1 %i ftcalopar1 %u ttcalopar1 %u runheader %u \n",calopar1,ftcalopar1,ttcalopar1,runheader); |
if ( debug ) printf(" calopar1 %i ftcalopar1 %u ttcalopar1 %u runheader %u \n",calopar1,ftcalopar1,ttcalopar1,runheader); |
296 |
// |
// |
297 |
|
if ( calopar1 ){ |
298 |
|
// |
299 |
|
// determine where I can find calorimeter ADC to MIP conversion file |
300 |
|
// |
301 |
|
if ( verbose ) printf(" Querying DB for calorimeter parameters files...\n"); |
302 |
|
// |
303 |
|
error = 0; |
304 |
|
error = glparam->Query_GL_PARAM(runheader,101,dbc); |
305 |
|
if ( error < 0 ) return(error); |
306 |
|
// |
307 |
|
calfile.str(""); |
308 |
|
calfile << glparam->PATH.Data() << "/"; |
309 |
|
calfile << glparam->NAME.Data(); |
310 |
|
// |
311 |
|
if ( verbose ) printf("\n Using ADC to MIP conversion file: \n %s \n",calfile.str().c_str()); |
312 |
|
f = fopen(calfile.str().c_str(),"rb"); |
313 |
|
if ( !f ){ |
314 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: no ADC to MIP file!\n"); |
315 |
|
return(-105); |
316 |
|
}; |
317 |
|
// |
318 |
|
for (Int_t m = 0; m < 2 ; m++ ){ |
319 |
|
for (Int_t k = 0; k < 22; k++ ){ |
320 |
|
for (Int_t l = 0; l < 96; l++ ){ |
321 |
|
fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f); |
322 |
|
if ( debug ) printf(" %f \n",mip[m][k][l]); |
323 |
|
}; |
324 |
|
}; |
325 |
|
}; |
326 |
|
fclose(f); |
327 |
|
}; |
328 |
|
// |
329 |
calopar1 = false; |
calopar1 = false; |
330 |
// |
// |
331 |
// determine where I can find calorimeter ADC to MIP conversion file |
// flight extra corrections: |
332 |
// |
// |
333 |
if ( verbose ) printf(" Querying DB for calorimeter parameters files...\n"); |
if ( verbose ) printf(" Querying DB for calorimeter flight ADC to MIP files...\n"); |
334 |
// |
// |
335 |
error = 0; |
error = 0; |
336 |
error = glparam->Query_GL_PARAM(runheader,101,dbc); |
error = glparam->Query_GL_PARAM(runheader,110,dbc); |
337 |
if ( error < 0 ) return(error); |
if ( error < 0 ) return(error); |
338 |
// |
// |
339 |
calfile.str(""); |
calfile.str(""); |
342 |
ftcalopar1 = glparam->FROM_TIME; |
ftcalopar1 = glparam->FROM_TIME; |
343 |
ttcalopar1 = glparam->TO_TIME; |
ttcalopar1 = glparam->TO_TIME; |
344 |
// |
// |
345 |
if ( verbose ) printf("\n Using ADC to MIP conversion file: \n %s \n",calfile.str().c_str()); |
if ( verbose ) printf("\n Using ADC to MIP special conversion file: \n %s \n",calfile.str().c_str()); |
346 |
f = fopen(calfile.str().c_str(),"rb"); |
ifstream spfile; |
347 |
if ( !f ){ |
spfile.open(calfile.str().c_str()); |
348 |
if ( verbose ) printf(" CALORIMETER - ERROR: no ADC to MIP file!\n"); |
if ( !spfile ){ |
349 |
return(-105); |
if ( verbose ) printf(" CALORIMETER - ERROR: no special calibration file!\n"); |
350 |
|
return(-123); |
351 |
}; |
}; |
352 |
|
// |
353 |
|
Int_t vview = 0; |
354 |
|
Int_t vplane = 0; |
355 |
|
Int_t vstrip = 0; |
356 |
|
Float_t vval = 0.; |
357 |
|
while ( spfile >> vview && spfile >> vplane && spfile >> vstrip && spfile >> vval){ |
358 |
|
if ( debug ) printf(" Setting ADC to MIP conversion factor: view %i plane %i strip %i mip %f \n",vview,vplane,vstrip,vval); |
359 |
|
mip[vview][vplane][vstrip] = vval; |
360 |
|
}; |
361 |
// |
// |
|
for (Int_t m = 0; m < 2 ; m++ ){ |
|
|
for (Int_t k = 0; k < 22; k++ ){ |
|
|
for (Int_t l = 0; l < 96; l++ ){ |
|
|
fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f); |
|
|
if ( debug ) printf(" %f \n",mip[m][k][l]); |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
fclose(f); |
|
362 |
}; |
}; |
363 |
// |
// |
364 |
|
// |
365 |
if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){ |
if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){ |
366 |
|
// |
367 |
if ( debug ) printf(" calopar2 %i ftcalopar2 %u ttcalopar2 %u runheader %u \n",calopar2,ftcalopar2,ttcalopar2,runheader); |
if ( debug ) printf(" calopar2 %i ftcalopar2 %u ttcalopar2 %u runheader %u \n",calopar2,ftcalopar2,ttcalopar2,runheader); |
368 |
calopar2 = false; |
calopar2 = false; |
369 |
// |
// |
470 |
badfile.close(); |
badfile.close(); |
471 |
}; |
}; |
472 |
// |
// |
473 |
|
// calopar4 |
474 |
|
// |
475 |
|
if ( calopar4 || ( ttcalopar4 != 0 && ttcalopar4 < runheader ) ){ |
476 |
|
// |
477 |
|
if ( debug ) printf(" calopar4 %i ftcalopar4 %u ttcalopar4 %u runheader %u \n",calopar4,ftcalopar4,ttcalopar4,runheader); |
478 |
|
// |
479 |
|
calopar4 = false; |
480 |
|
// |
481 |
|
// flight extra corrections: |
482 |
|
// |
483 |
|
if ( verbose ) printf(" Querying DB for calorimeter max rms file...\n"); |
484 |
|
// |
485 |
|
error = 0; |
486 |
|
error = glparam->Query_GL_PARAM(runheader,109,dbc); |
487 |
|
if ( error < 0 ) return(error); |
488 |
|
// |
489 |
|
calfile.str(""); |
490 |
|
calfile << glparam->PATH.Data() << "/"; |
491 |
|
calfile << glparam->NAME.Data(); |
492 |
|
ftcalopar4 = glparam->FROM_TIME; |
493 |
|
ttcalopar4 = glparam->TO_TIME; |
494 |
|
// |
495 |
|
if ( verbose ) printf("\n Using calorimeter max rms file: \n %s \n",calfile.str().c_str()); |
496 |
|
ifstream spfile; |
497 |
|
spfile.open(calfile.str().c_str()); |
498 |
|
if ( !spfile ){ |
499 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: no max rms file!\n"); |
500 |
|
return(-124); |
501 |
|
}; |
502 |
|
// |
503 |
|
Int_t vview = 0; |
504 |
|
Int_t vplane = 0; |
505 |
|
Int_t vval = 0; |
506 |
|
for (Int_t l=0; l<2; l++){ |
507 |
|
for (Int_t m=0; m<22; m++){ |
508 |
|
maxrms[l][m] = 26; |
509 |
|
}; |
510 |
|
}; |
511 |
|
while ( spfile >> vview && spfile >> vplane && spfile >> vval){ |
512 |
|
if ( debug ) printf(" Setting view %i plane %i max rms %i \n",vview,vplane,vval); |
513 |
|
maxrms[vview][vplane] = vval; |
514 |
|
}; |
515 |
|
spfile.close(); |
516 |
|
// |
517 |
|
}; |
518 |
|
// |
519 |
|
// calopar5 |
520 |
|
// |
521 |
|
if ( calopar5 || ( ttcalopar5 != 0 && ttcalopar5 < runheader ) ){ |
522 |
|
// |
523 |
|
if ( debug ) printf(" calopar5 %i ftcalopar5 %u ttcalopar5 %u runheader %u \n",calopar5,ftcalopar5,ttcalopar5,runheader); |
524 |
|
// |
525 |
|
calopar5 = false; |
526 |
|
// |
527 |
|
// flight extra corrections: |
528 |
|
// |
529 |
|
if ( verbose ) printf(" Querying DB for calorimeter noise to signal threshold file...\n"); |
530 |
|
// |
531 |
|
error = 0; |
532 |
|
error = glparam->Query_GL_PARAM(runheader,111,dbc); |
533 |
|
if ( error < 0 ) return(error); |
534 |
|
// |
535 |
|
calfile.str(""); |
536 |
|
calfile << glparam->PATH.Data() << "/"; |
537 |
|
calfile << glparam->NAME.Data(); |
538 |
|
ftcalopar5 = glparam->FROM_TIME; |
539 |
|
ttcalopar5 = glparam->TO_TIME; |
540 |
|
// |
541 |
|
if ( verbose ) printf("\n Using calorimeter noise to signal threshold file: \n %s \n",calfile.str().c_str()); |
542 |
|
ifstream spfile; |
543 |
|
spfile.open(calfile.str().c_str()); |
544 |
|
if ( !spfile ){ |
545 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: no noise to signal threshold file!\n"); |
546 |
|
return(-125); |
547 |
|
}; |
548 |
|
// |
549 |
|
Int_t vview = 0; |
550 |
|
Int_t vplane = 0; |
551 |
|
Int_t vstrip = 0; |
552 |
|
Float_t vval = 0.; |
553 |
|
for (Int_t l=0; l<2; l++){ |
554 |
|
for (Int_t m=0; m<22; m++){ |
555 |
|
for (Int_t n=0; n<96; n++){ |
556 |
|
memin[l][m][n] = 0.7; |
557 |
|
}; |
558 |
|
}; |
559 |
|
}; |
560 |
|
while ( spfile >> vview && spfile >> vplane && spfile >> vstrip && spfile >> vval){ |
561 |
|
if ( vstrip == -1 ){ |
562 |
|
for (Int_t ll=0; ll<96; ll++){ |
563 |
|
if ( debug ) printf(" Setting view %i plane %i strip %i noise to signal ratio %f \n",vview,vplane,ll,vval); |
564 |
|
memin[vview][vplane][ll] = vval; |
565 |
|
}; |
566 |
|
} else { |
567 |
|
if ( debug ) printf(" Setting view %i plane %i strip %i noise to signal ratio %f \n",vview,vplane,vstrip,vval); |
568 |
|
memin[vview][vplane][vstrip] = vval; |
569 |
|
}; |
570 |
|
}; |
571 |
|
spfile.close(); |
572 |
|
// |
573 |
|
}; |
574 |
|
// |
575 |
|
// |
576 |
delete glparam; |
delete glparam; |
|
dbc->Close(); |
|
|
delete dbc; |
|
577 |
// |
// |
578 |
return(0); |
return(0); |
579 |
} |
} |
580 |
|
|
581 |
Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){ |
Int_t CaloLevel0::CalcCrossTalkCorr(TSQLServer *dbc, UInt_t runheader, Bool_t ctusetable){ |
582 |
|
Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,ctusetable); |
583 |
|
return(sig); |
584 |
|
}; |
585 |
|
|
586 |
|
Int_t CaloLevel0::CalcCrossTalkCorr(TSQLServer *dbc, UInt_t runheader){ |
587 |
|
Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,true); |
588 |
|
return(sig); |
589 |
|
} |
590 |
|
|
591 |
|
Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader, Bool_t usetable){ |
592 |
|
const TString host = glt->CGetHost(); |
593 |
|
const TString user = glt->CGetUser(); |
594 |
|
const TString psw = glt->CGetPsw(); |
595 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
596 |
|
if ( !dbc->IsConnected() ) throw -116; |
597 |
|
stringstream myquery; |
598 |
|
myquery.str(""); |
599 |
|
myquery << "SET time_zone='+0:00'"; |
600 |
|
dbc->Query(myquery.str().c_str()); |
601 |
// |
// |
602 |
if ( ctground ) return(0); |
Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,usetable); |
603 |
|
dbc->Close(); |
604 |
|
delete dbc; |
605 |
// |
// |
606 |
|
return(sig); |
607 |
|
// |
608 |
|
}; |
609 |
|
|
610 |
|
Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){ |
611 |
const TString host = glt->CGetHost(); |
const TString host = glt->CGetHost(); |
612 |
const TString user = glt->CGetUser(); |
const TString user = glt->CGetUser(); |
613 |
const TString psw = glt->CGetPsw(); |
const TString psw = glt->CGetPsw(); |
618 |
myquery << "SET time_zone='+0:00'"; |
myquery << "SET time_zone='+0:00'"; |
619 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
620 |
// |
// |
621 |
stringstream bmfile; |
Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,true); |
622 |
|
dbc->Close(); |
623 |
|
delete dbc; |
624 |
|
// |
625 |
|
return(sig); |
626 |
|
// |
627 |
|
} |
628 |
|
|
629 |
|
Int_t CaloLevel0::CalcCrossTalkCorrDo(TSQLServer *dbc, UInt_t runheader, Bool_t usetable){ |
630 |
|
// |
631 |
|
if ( ctground ) return(0); |
632 |
|
// |
633 |
Int_t error = 0; |
Int_t error = 0; |
634 |
ifstream badfile; |
GL_PARAM *glparam = new GL_PARAM(); |
|
GL_PARAM *glparam = new GL_PARAM(); |
|
635 |
// |
// |
636 |
// determine where I can find file with offline bad pulser mask |
// determine where I can find file with offline bad pulser mask |
637 |
// |
// |
638 |
|
stringstream bmfile; |
639 |
error = 0; |
error = 0; |
640 |
error = glparam->Query_GL_PARAM(runheader,105,dbc); |
error = glparam->Query_GL_PARAM(runheader,105,dbc); |
641 |
if ( error < 0 ) return(error); |
if ( error < 0 ) return(error); |
644 |
bmfile << glparam->PATH.Data() << "/"; |
bmfile << glparam->PATH.Data() << "/"; |
645 |
bmfile << glparam->NAME.Data(); |
bmfile << glparam->NAME.Data(); |
646 |
// |
// |
647 |
|
ifstream badfile; |
648 |
if ( verbose ) printf("\n Using bad pulser offline mask file: \n %s \n\n",bmfile.str().c_str()); |
if ( verbose ) printf("\n Using bad pulser offline mask file: \n %s \n\n",bmfile.str().c_str()); |
649 |
badfile.open(bmfile.str().c_str()); |
badfile.open(bmfile.str().c_str()); |
650 |
if ( !badfile ){ |
if ( !badfile ){ |
673 |
}; |
}; |
674 |
}; |
}; |
675 |
// |
// |
|
delete glparam; |
|
676 |
badfile.close(); |
badfile.close(); |
677 |
// |
if ( !usetable ){ |
|
// Let's start with cross-talk correction calculation |
|
|
// |
|
|
GL_CALOPULSE_CALIB *glp = new GL_CALOPULSE_CALIB(); |
|
|
Float_t adcp[2][22][96]; |
|
|
Float_t adcpcal[2][22][96]; |
|
|
memset(adcp , 0, 2*22*96*sizeof(Float_t)); |
|
|
memset(adcpcal , 0, 2*22*96*sizeof(Float_t)); |
|
|
// |
|
|
UInt_t pampli = 0; |
|
|
for (Int_t s=0; s<4; s++){ |
|
|
// |
|
|
// Save into matrix adcp the values of the highest pulse calibration (pulse amplitude = 2) |
|
|
// |
|
|
pampli = 2; |
|
|
error = 0; |
|
|
error = glp->Query_GL_CALOPULSE_CALIB(runheader,s,pampli,dbc); |
|
|
if ( error < 0 ){ |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
|
|
return(error); |
|
|
}; |
|
|
// |
|
|
UInt_t idcalib = glp->ID_ROOT_L0; |
|
|
UInt_t fromtime = glp->FROM_TIME; |
|
|
UInt_t calibno = glp->EV_ROOT; |
|
|
// |
|
|
// determine path and name and entry of the calibration file |
|
678 |
// |
// |
679 |
GL_ROOT *glroot = new GL_ROOT(); |
// Let's start with cross-talk correction calculation |
|
if ( verbose ) printf("\n"); |
|
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
|
|
// |
|
|
error = 0; |
|
|
error = glroot->Query_GL_ROOT(idcalib,dbc); |
|
|
if ( error < 0 ){ |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
|
|
return(error); |
|
|
}; |
|
|
// |
|
|
stringstream name; |
|
|
name.str(""); |
|
|
name << glroot->PATH.Data() << "/"; |
|
|
name << glroot->NAME.Data(); |
|
|
// |
|
|
TString fcalname = (TString)name.str().c_str(); |
|
|
ifstream myfile; |
|
|
myfile.open(fcalname.Data()); |
|
|
if ( !myfile ){ |
|
|
return(-107); |
|
|
}; |
|
|
myfile.close(); |
|
|
// |
|
|
TFile *File = new TFile(fcalname.Data()); |
|
|
if ( !File ) return(-108); |
|
|
TTree *tr = (TTree*)File->Get("CalibCalPulse2"); |
|
|
if ( !tr ) return(-119); |
|
|
// |
|
|
TBranch *calo = tr->GetBranch("CalibCalPulse2"); |
|
680 |
// |
// |
681 |
pamela::CalibCalPulse2Event *ce = 0; |
GL_CALOPULSE_CALIB *glp = new GL_CALOPULSE_CALIB(); |
682 |
tr->SetBranchAddress("CalibCalPulse2", &ce); |
Float_t adcp[2][22][96]; |
683 |
|
Float_t adcpcal[2][22][96]; |
684 |
|
memset(adcp , 0, 2*22*96*sizeof(Float_t)); |
685 |
|
memset(adcpcal , 0, 2*22*96*sizeof(Float_t)); |
686 |
// |
// |
687 |
Long64_t ncalibs = calo->GetEntries(); |
UInt_t pampli = 0; |
688 |
|
for (Int_t s=0; s<4; s++){ |
689 |
|
// |
690 |
|
// Save into matrix adcp the values of the highest pulse calibration (pulse amplitude = 2) |
691 |
|
// |
692 |
|
pampli = 2; |
693 |
|
error = 0; |
694 |
|
error = glp->Query_GL_CALOPULSE_CALIB(runheader,s,pampli,dbc); |
695 |
|
if ( error < 0 ){ |
696 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
697 |
|
return(error); |
698 |
|
}; |
699 |
|
// |
700 |
|
UInt_t idcalib = glp->ID_ROOT_L0; |
701 |
|
UInt_t fromtime = glp->FROM_TIME; |
702 |
|
UInt_t calibno = glp->EV_ROOT; |
703 |
|
// |
704 |
|
// determine path and name and entry of the calibration file |
705 |
|
// |
706 |
|
GL_ROOT *glroot = new GL_ROOT(); |
707 |
|
if ( verbose ) printf("\n"); |
708 |
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
709 |
|
// |
710 |
|
error = 0; |
711 |
|
error = glroot->Query_GL_ROOT(idcalib,dbc); |
712 |
|
if ( error < 0 ){ |
713 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
714 |
|
return(error); |
715 |
|
}; |
716 |
|
// |
717 |
|
stringstream name; |
718 |
|
name.str(""); |
719 |
|
name << glroot->PATH.Data() << "/"; |
720 |
|
name << glroot->NAME.Data(); |
721 |
|
// |
722 |
|
TString fcalname = (TString)name.str().c_str(); |
723 |
|
ifstream myfile; |
724 |
|
myfile.open(fcalname.Data()); |
725 |
|
if ( !myfile ){ |
726 |
|
return(-107); |
727 |
|
}; |
728 |
|
myfile.close(); |
729 |
|
// |
730 |
|
TFile *File = new TFile(fcalname.Data()); |
731 |
|
if ( !File ) return(-108); |
732 |
|
TTree *tr = (TTree*)File->Get("CalibCalPulse2"); |
733 |
|
if ( !tr ) return(-119); |
734 |
|
// |
735 |
|
TBranch *calo = tr->GetBranch("CalibCalPulse2"); |
736 |
|
// |
737 |
|
pamela::CalibCalPulse2Event *ce = 0; |
738 |
|
tr->SetBranchAddress("CalibCalPulse2", &ce); |
739 |
|
// |
740 |
|
Long64_t ncalibs = calo->GetEntries(); |
741 |
|
// |
742 |
|
if ( !ncalibs ) return(-110); |
743 |
|
// |
744 |
|
if ( calo->GetEntry(calibno) <= 0) throw -36; |
745 |
|
if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); |
746 |
|
// |
747 |
|
// retrieve calibration table |
748 |
|
// |
749 |
|
if ( ce->pstwerr[s] && ce->pperror[s] == 0 && ce->unpackError == 0 ){ |
750 |
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
751 |
|
for ( Int_t j=0; j<96 ;j++){ |
752 |
|
if ( s == 2 ){ |
753 |
|
adcp[0][2*d+1][j] = ce->calpuls[3][d][j]; |
754 |
|
}; |
755 |
|
if ( s == 3 ){ |
756 |
|
adcp[0][2*d][j] = ce->calpuls[1][d][j]; |
757 |
|
}; |
758 |
|
if ( s == 0 ){ |
759 |
|
adcp[1][2*d][j] = ce->calpuls[0][d][j]; |
760 |
|
}; |
761 |
|
if ( s == 1 ){ |
762 |
|
adcp[1][2*d+1][j] = ce->calpuls[2][d][j]; |
763 |
|
}; |
764 |
|
}; |
765 |
|
}; |
766 |
|
} else { |
767 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
768 |
|
return(-111); |
769 |
|
}; |
770 |
|
// |
771 |
|
File->Close(); |
772 |
|
delete glroot; |
773 |
|
// |
774 |
|
// Save into matrix adcpcal the calibrated values of the pulse calibration (subtraction of pulse amplitude = 0 relative to the pulse2 calibration used) |
775 |
|
// |
776 |
|
pampli = 0; |
777 |
|
error = 0; |
778 |
|
error = glp->Query_GL_CALOPULSE_CALIB(fromtime,s,pampli,dbc); |
779 |
|
if ( error < 0 ){ |
780 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
781 |
|
return(error); |
782 |
|
}; |
783 |
|
// |
784 |
|
idcalib = glp->ID_ROOT_L0; |
785 |
|
calibno = glp->EV_ROOT; |
786 |
|
// |
787 |
|
// determine path and name and entry of the calibration file |
788 |
|
// |
789 |
|
glroot = new GL_ROOT(); |
790 |
|
if ( verbose ) printf("\n"); |
791 |
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
792 |
|
// |
793 |
|
error = 0; |
794 |
|
error = glroot->Query_GL_ROOT(idcalib,dbc); |
795 |
|
if ( error < 0 ){ |
796 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
797 |
|
return(error); |
798 |
|
}; |
799 |
|
// |
800 |
|
name.str(""); |
801 |
|
name << glroot->PATH.Data() << "/"; |
802 |
|
name << glroot->NAME.Data(); |
803 |
|
// |
804 |
|
fcalname = (TString)name.str().c_str(); |
805 |
|
myfile.open(fcalname.Data()); |
806 |
|
if ( !myfile ){ |
807 |
|
return(-107); |
808 |
|
}; |
809 |
|
myfile.close(); |
810 |
|
// |
811 |
|
TFile *File1 = new TFile(fcalname.Data()); |
812 |
|
if ( !File1 ) return(-108); |
813 |
|
TTree *tr1 = (TTree*)File1->Get("CalibCalPulse1"); |
814 |
|
if ( !tr1 ) return(-120); |
815 |
|
// |
816 |
|
TBranch *calo1 = tr1->GetBranch("CalibCalPulse1"); |
817 |
|
// |
818 |
|
pamela::CalibCalPulse1Event *ce1 = 0; |
819 |
|
tr1->SetBranchAddress("CalibCalPulse1", &ce1); |
820 |
|
// |
821 |
|
ncalibs = calo1->GetEntries(); |
822 |
|
// |
823 |
|
if ( !ncalibs ) return(-110); |
824 |
|
// |
825 |
|
if ( calo1->GetEntry(calibno) <= 0 ) throw -36; |
826 |
|
if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); |
827 |
|
// |
828 |
|
// retrieve calibration table |
829 |
|
// |
830 |
|
if ( ce1->pstwerr[s] && ce1->pperror[s] == 0 && ce1->unpackError == 0 ){ |
831 |
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
832 |
|
for ( Int_t j=0; j<96 ;j++){ |
833 |
|
if ( s == 2 ){ |
834 |
|
adcpcal[0][2*d+1][j] = adcp[0][2*d+1][j] - ce1->calpuls[3][d][j]; |
835 |
|
}; |
836 |
|
if ( s == 3 ){ |
837 |
|
adcpcal[0][2*d][j] = adcp[0][2*d][j] - ce1->calpuls[1][d][j]; |
838 |
|
}; |
839 |
|
if ( s == 0 ){ |
840 |
|
adcpcal[1][2*d][j] = adcp[1][2*d][j] - ce1->calpuls[0][d][j]; |
841 |
|
}; |
842 |
|
if ( s == 1 ){ |
843 |
|
adcpcal[1][2*d+1][j] = adcp[1][2*d+1][j] - ce1->calpuls[2][d][j]; |
844 |
|
}; |
845 |
|
}; |
846 |
|
}; |
847 |
|
} else { |
848 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
849 |
|
return(-111); |
850 |
|
}; |
851 |
|
// |
852 |
|
File1->Close(); |
853 |
|
// |
854 |
|
delete glroot; |
855 |
|
// |
856 |
|
};// loop on the four sections |
857 |
// |
// |
|
if ( !ncalibs ) return(-110); |
|
858 |
// |
// |
859 |
calo->GetEntry(calibno); |
delete glp; |
|
if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); |
|
860 |
// |
// |
861 |
// retrieve calibration table |
// Ok, now we can try to calculate the cross-talk correction for each pre-amplifier |
862 |
// |
// |
863 |
if ( ce->pstwerr[s] && ce->pperror[s] == 0 && ce->unpackError == 0 ){ |
for ( Int_t v=0; v<2; v++){ |
864 |
for ( Int_t d=0 ; d<11 ;d++ ){ |
if ( debug ) printf(" \n\n NEW VIEW \n"); |
865 |
for ( Int_t j=0; j<96 ;j++){ |
for ( Int_t p=0; p<22; p++){ |
866 |
if ( s == 2 ){ |
for ( Int_t npre=0; npre<6; npre++){ |
867 |
adcp[0][2*d+1][j] = ce->calpuls[3][d][j]; |
ctprecor[v][p][npre] = 1000.; |
868 |
}; |
ctneigcor[v][p][npre] = 1000.; |
869 |
if ( s == 3 ){ |
Int_t str0=npre*16; |
870 |
adcp[0][2*d][j] = ce->calpuls[1][d][j]; |
Int_t str16= -1 + (1+npre)*16; |
871 |
}; |
// |
872 |
if ( s == 0 ){ |
UInt_t neigc = 0; |
873 |
adcp[1][2*d][j] = ce->calpuls[0][d][j]; |
UInt_t farc = 0; |
874 |
|
UInt_t pulsc = 0; |
875 |
|
Float_t sigpulsed = 0.; |
876 |
|
Float_t neigbase = 0.; |
877 |
|
Float_t farbase = 0.; |
878 |
|
// |
879 |
|
// Loop over the strip of the pre and sum all signal far away from pulsed strip, signal in the neighbour(s) strip(s) and save the pulsed signal |
880 |
|
// moreover count the number of strips in each case |
881 |
|
// |
882 |
|
for (Int_t s=str0; s<=str16; s++){ |
883 |
|
if ( adcpcal[v][p][s] > 10000.){ |
884 |
|
sigpulsed = adcpcal[v][p][s]; |
885 |
|
pulsc++; |
886 |
|
if ( s > str0 ){ |
887 |
|
neigbase += adcpcal[v][p][s-1]; |
888 |
|
neigc++; |
889 |
|
farbase -= adcpcal[v][p][s-1]; |
890 |
|
farc--; |
891 |
|
}; |
892 |
|
if ( s < str16 ){ |
893 |
|
neigbase += adcpcal[v][p][s+1]; |
894 |
|
neigc++; |
895 |
|
farbase -= adcpcal[v][p][s+1]; |
896 |
|
farc--; |
897 |
|
}; |
898 |
|
} else { |
899 |
|
farc++; |
900 |
|
farbase += adcpcal[v][p][s]; |
901 |
|
}; |
902 |
}; |
}; |
903 |
if ( s == 1 ){ |
// |
904 |
adcp[1][2*d+1][j] = ce->calpuls[2][d][j]; |
// Now calculate the corrections |
905 |
|
// |
906 |
|
Float_t avefarbase = 0.; |
907 |
|
if ( farc ) avefarbase = farbase/(Float_t)farc; |
908 |
|
Float_t aveneigbase = 0.; |
909 |
|
if ( neigc ) aveneigbase = neigbase/(Float_t)neigc; |
910 |
|
// |
911 |
|
if ( pulsc == 1 && farc && neigc ){ |
912 |
|
ctprecor[v][p][npre] = -avefarbase/(sigpulsed+fabs(avefarbase)); |
913 |
|
ctneigcor[v][p][npre] = fabs(aveneigbase-avefarbase)/(sigpulsed+fabs(avefarbase)); |
914 |
|
if ( debug ) printf(" Cross-talk correction View %i Plane %i Pre %i : pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
915 |
|
} else { |
916 |
|
// |
917 |
|
// did not find the pulsed strip or more than one pulsed strip found! |
918 |
|
// |
919 |
|
if ( debug ) printf(" Problems finding the cross-talk corrections: \n View %i Plane %i Pre %i number of pulsed strip %i \n Average faraway baseline %f number of strips %i Average neighbour baseline %f number of neighbour strips %i \n",v,p,npre,pulsc,avefarbase,farc,aveneigbase,neigc); |
920 |
|
// |
921 |
}; |
}; |
922 |
}; |
}; |
923 |
|
if ( debug ) printf(" \n ==================== \n"); |
924 |
}; |
}; |
|
} else { |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
|
|
return(-111); |
|
925 |
}; |
}; |
926 |
|
} else { |
927 |
// |
// |
928 |
File->Close(); |
// use pre-amply table |
929 |
delete glroot; |
// |
930 |
// |
// |
931 |
// Save into matrix adcpcal the calibrated values of the pulse calibration (subtraction of pulse amplitude = 0 relative to the pulse2 calibration used) |
// determine where I can find file with offline neighbour correction table |
932 |
// |
// |
933 |
pampli = 0; |
stringstream bmfile2; |
934 |
error = 0; |
error = 0; |
935 |
error = glp->Query_GL_CALOPULSE_CALIB(fromtime,s,pampli,dbc); |
error = glparam->Query_GL_PARAM(runheader,106,dbc); |
936 |
if ( error < 0 ){ |
if ( error < 0 ) return(error); |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
|
|
return(error); |
|
|
}; |
|
|
// |
|
|
idcalib = glp->ID_ROOT_L0; |
|
|
calibno = glp->EV_ROOT; |
|
937 |
// |
// |
938 |
// determine path and name and entry of the calibration file |
bmfile2.str(""); |
939 |
|
bmfile2 << glparam->PATH.Data() << "/"; |
940 |
|
bmfile2 << glparam->NAME.Data(); |
941 |
|
// |
942 |
|
ifstream badfile2; |
943 |
|
if ( verbose ) printf("\n Using pre-amply neighbour crosstalk table file: \n %s \n\n",bmfile2.str().c_str()); |
944 |
|
badfile2.open(bmfile2.str().c_str()); |
945 |
|
if ( !badfile2 ){ |
946 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: no pre-amply neighbour crosstalk table file!\n"); |
947 |
|
return(-121); |
948 |
|
}; |
949 |
|
// |
950 |
|
Int_t vview = 0; |
951 |
|
Int_t vplane = 0; |
952 |
|
Int_t vpre = 0; |
953 |
|
Float_t vcorr = 0.; |
954 |
|
while ( badfile2 >> vview && badfile2 >> vplane && badfile2 >> vpre && badfile2 >> vcorr){ |
955 |
|
if ( debug ) printf(" Pre-amply neighbour correction: view %i plane %i pre %i correction %f \n",vview,vplane,vpre,vcorr); |
956 |
|
ctneigcor[vview][vplane][vpre] = vcorr; |
957 |
|
}; |
958 |
// |
// |
959 |
glroot = new GL_ROOT(); |
// determine where I can find file with offline SECOND neighbour correction table |
|
if ( verbose ) printf("\n"); |
|
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
|
960 |
// |
// |
961 |
|
stringstream bmfile3; |
962 |
error = 0; |
error = 0; |
963 |
error = glroot->Query_GL_ROOT(idcalib,dbc); |
error = glparam->Query_GL_PARAM(runheader,107,dbc); |
964 |
if ( error < 0 ){ |
if ( error < 0 ) return(error); |
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
|
|
return(error); |
|
|
}; |
|
|
// |
|
|
name.str(""); |
|
|
name << glroot->PATH.Data() << "/"; |
|
|
name << glroot->NAME.Data(); |
|
965 |
// |
// |
966 |
fcalname = (TString)name.str().c_str(); |
bmfile3.str(""); |
967 |
myfile.open(fcalname.Data()); |
bmfile3 << glparam->PATH.Data() << "/"; |
968 |
if ( !myfile ){ |
bmfile3 << glparam->NAME.Data(); |
969 |
return(-107); |
// |
970 |
|
ifstream badfile3; |
971 |
|
if ( verbose ) printf("\n Using pre-amply second neighbour crosstalk table file: \n %s \n\n",bmfile3.str().c_str()); |
972 |
|
badfile3.open(bmfile3.str().c_str()); |
973 |
|
if ( !badfile3 ){ |
974 |
|
if ( verbose ) printf(" CALORIMETER - ERROR: no pre-amply second neighbour crosstalk table file!\n"); |
975 |
|
return(-122); |
976 |
}; |
}; |
977 |
myfile.close(); |
// |
978 |
// |
Int_t pview = 0; |
979 |
TFile *File1 = new TFile(fcalname.Data()); |
Int_t pplane = 0; |
980 |
if ( !File1 ) return(-108); |
Int_t ppre = 0; |
981 |
TTree *tr1 = (TTree*)File1->Get("CalibCalPulse1"); |
Float_t pcorr = 0.; |
982 |
if ( !tr1 ) return(-120); |
while ( badfile3 >> pview && badfile3 >> pplane && badfile3 >> ppre && badfile3 >> pcorr){ |
983 |
// |
if ( debug ) printf(" Pre-amply second neighbour correction: view %i plane %i pre %i correction %f \n",pview,pplane,ppre,-pcorr); |
984 |
TBranch *calo1 = tr1->GetBranch("CalibCalPulse1"); |
ctprecor[pview][pplane][ppre] = -pcorr; // data are saved as negatives in the file |
985 |
// |
}; |
|
pamela::CalibCalPulse1Event *ce1 = 0; |
|
|
tr1->SetBranchAddress("CalibCalPulse1", &ce1); |
|
|
// |
|
|
ncalibs = calo1->GetEntries(); |
|
|
// |
|
|
if ( !ncalibs ) return(-110); |
|
986 |
// |
// |
987 |
calo1->GetEntry(calibno); |
// determine where to find the file containing the Silicon crosstalk correction table |
|
if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); |
|
988 |
// |
// |
989 |
// retrieve calibration table |
stringstream bmfile4; |
990 |
|
error = 0; |
991 |
|
error = glparam->Query_GL_PARAM(runheader,108,dbc); |
992 |
|
if ( error < 0 ) return(error); |
993 |
// |
// |
994 |
if ( ce1->pstwerr[s] && ce1->pperror[s] == 0 && ce1->unpackError == 0 ){ |
bmfile4.str(""); |
995 |
for ( Int_t d=0 ; d<11 ;d++ ){ |
bmfile4 << glparam->PATH.Data() << "/"; |
996 |
for ( Int_t j=0; j<96 ;j++){ |
bmfile4 << glparam->NAME.Data(); |
997 |
if ( s == 2 ){ |
// |
998 |
adcpcal[0][2*d+1][j] = adcp[0][2*d+1][j] - ce1->calpuls[3][d][j]; |
ifstream badfile4; |
999 |
}; |
if ( verbose ) printf("\n Using Silicon crosstalk table file: \n %s \n\n",bmfile4.str().c_str()); |
1000 |
if ( s == 3 ){ |
badfile4.open(bmfile4.str().c_str()); |
1001 |
adcpcal[0][2*d][j] = adcp[0][2*d][j] - ce1->calpuls[1][d][j]; |
if ( !badfile4 ){ |
1002 |
}; |
if ( verbose ) printf(" CALORIMETER - ERROR: no Silicon crosstalk table file!\n"); |
1003 |
if ( s == 0 ){ |
return(-125); |
|
adcpcal[1][2*d][j] = adcp[1][2*d][j] - ce1->calpuls[0][d][j]; |
|
|
}; |
|
|
if ( s == 1 ){ |
|
|
adcpcal[1][2*d+1][j] = adcp[1][2*d+1][j] - ce1->calpuls[2][d][j]; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
} else { |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
|
|
return(-111); |
|
1004 |
}; |
}; |
1005 |
|
// |
1006 |
|
Int_t spview = 0; |
1007 |
|
Int_t spplane = 0; |
1008 |
|
Int_t psil = 0; |
1009 |
|
Float_t spcorr = 0.; |
1010 |
|
memset(ctsicor, 0, 2*22*9*sizeof(Float_t)); |
1011 |
|
while ( badfile4 >> spview && badfile4 >> spplane && badfile4 >> psil && badfile4 >> spcorr){ |
1012 |
|
if ( debug ) printf(" Silicon correction: view %i plane %i silicon %i correction %f \n",spview,spplane,psil,-spcorr); |
1013 |
|
ctsicor[spview][spplane][psil] = -spcorr; // data are saved as negatives in the file |
1014 |
|
}; |
1015 |
// |
// |
|
File1->Close(); |
|
|
// |
|
|
delete glroot; |
|
|
// |
|
|
};// loop on the four sections |
|
|
// |
|
|
// |
|
|
delete glp; |
|
|
dbc->Close(); |
|
|
delete dbc; |
|
|
// |
|
|
// Ok, now we can try to calculate the cross-talk correction for each pre-amplifier |
|
|
// |
|
|
for ( Int_t v=0; v<2; v++){ |
|
|
if ( debug ) printf(" \n\n NEW VIEW \n"); |
|
|
for ( Int_t p=0; p<22; p++){ |
|
|
for ( Int_t npre=0; npre<6; npre++){ |
|
|
ctprecor[v][p][npre] = 1000.; |
|
|
ctneigcor[v][p][npre] = 1000.; |
|
|
Int_t str0=npre*16; |
|
|
Int_t str16= -1 + (1+npre)*16; |
|
|
// |
|
|
UInt_t neigc = 0; |
|
|
UInt_t farc = 0; |
|
|
UInt_t pulsc = 0; |
|
|
Float_t sigpulsed = 0.; |
|
|
Float_t neigbase = 0.; |
|
|
Float_t farbase = 0.; |
|
|
// |
|
|
// Loop over the strip of the pre and sum all signal far away from pulsed strip, signal in the neighbour(s) strip(s) and save the pulsed signal |
|
|
// moreover count the number of strips in each case |
|
|
// |
|
|
for (Int_t s=str0; s<=str16; s++){ |
|
|
if ( adcpcal[v][p][s] > 10000.){ |
|
|
sigpulsed = adcpcal[v][p][s]; |
|
|
pulsc++; |
|
|
if ( s > str0 ){ |
|
|
neigbase += adcpcal[v][p][s-1]; |
|
|
neigc++; |
|
|
farbase -= adcpcal[v][p][s-1]; |
|
|
farc--; |
|
|
}; |
|
|
if ( s < str16 ){ |
|
|
neigbase += adcpcal[v][p][s+1]; |
|
|
neigc++; |
|
|
farbase -= adcpcal[v][p][s+1]; |
|
|
farc--; |
|
|
}; |
|
|
} else { |
|
|
farc++; |
|
|
farbase += adcpcal[v][p][s]; |
|
|
}; |
|
|
}; |
|
|
// |
|
|
// Now calculate the corrections |
|
|
// |
|
|
Float_t avefarbase = 0.; |
|
|
if ( farc ) avefarbase = farbase/(Float_t)farc; |
|
|
Float_t aveneigbase = 0.; |
|
|
if ( neigc ) aveneigbase = neigbase/(Float_t)neigc; |
|
|
// |
|
|
if ( pulsc == 1 && farc && neigc ){ |
|
|
ctprecor[v][p][npre] = -avefarbase/(sigpulsed+fabs(avefarbase)); |
|
|
ctneigcor[v][p][npre] = fabs(aveneigbase-avefarbase)/(sigpulsed+fabs(avefarbase)); |
|
|
if ( debug ) printf(" Cross-talk correction View %i Plane %i Pre %i : pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
|
|
} else { |
|
|
// |
|
|
// did not find the pulsed strip or more than one pulsed strip found! |
|
|
// |
|
|
if ( debug ) printf(" Problems finding the cross-talk corrections: \n View %i Plane %i Pre %i number of pulsed strip %i \n Average faraway baseline %f number of strips %i Average neighbour baseline %f number of neighbour strips %i \n",v,p,npre,pulsc,avefarbase,farc,aveneigbase,neigc); |
|
|
// |
|
|
}; |
|
|
}; |
|
|
if ( debug ) printf(" \n ==================== \n"); |
|
|
}; |
|
1016 |
}; |
}; |
1017 |
// |
// |
1018 |
|
delete glparam; |
1019 |
|
// |
1020 |
// Check the calculated corrections |
// Check the calculated corrections |
1021 |
// |
// |
1022 |
Int_t opre=0; |
Int_t opre=0; |
1057 |
}; |
}; |
1058 |
}; |
}; |
1059 |
}; |
}; |
1060 |
}; |
}; |
1061 |
// |
// |
1062 |
return(0); |
return(0); |
1063 |
} |
} |
1064 |
|
|
1065 |
|
void CaloLevel0::FindBaseCompress(Int_t l, Int_t m, Int_t pre){ |
1066 |
|
Int_t n = 0; |
1067 |
|
Float_t q = 0; |
1068 |
|
this->FindBaseCompress(l,m,pre,n,q); |
1069 |
|
} |
1070 |
|
|
1071 |
|
void CaloLevel0::FindBaseCompress(Int_t l, Int_t m, Int_t pre, Int_t &nst, Float_t &qp){ |
1072 |
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1073 |
|
dexy[l][m][e] = dexyc[l][m][e]; |
1074 |
|
}; |
1075 |
|
this->FindBaseRaw(l,m,pre,nst,qp); |
1076 |
|
} |
1077 |
|
|
1078 |
void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre){ |
void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre){ |
1079 |
Float_t minstrip = 100000.; |
Int_t n = 0; |
1080 |
Float_t rms = 0.; |
Float_t q = 0; |
1081 |
|
this->FindBaseRaw(l,m,pre,n,q); |
1082 |
|
} |
1083 |
|
|
1084 |
|
void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre, Int_t &nst, Float_t &qp){ |
1085 |
|
// |
1086 |
|
Float_t minstrip = 100000.; |
1087 |
|
Float_t rms = 0.; |
1088 |
|
Int_t process = 0; |
1089 |
|
Int_t onlmask[16]; |
1090 |
|
memset(onlmask, 0, 16*sizeof(Int_t)); |
1091 |
|
// |
1092 |
|
while ( process < 2 ){ |
1093 |
|
// |
1094 |
|
minstrip = 100000.; |
1095 |
|
rms = 0.; |
1096 |
base[l][m][pre] = 0.; |
base[l][m][pre] = 0.; |
1097 |
|
qp = 0.; |
1098 |
|
// |
1099 |
|
Int_t spos = -1; |
1100 |
|
Int_t ee = 0; |
1101 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1102 |
if ( calgood[l][m][e] == 0. && obadmask[l][m][e] == 0 && dexy[l][m][e]-calped[l][m][e] < minstrip && dexy[l][m][e] > 0.) { |
if ( calgood[l][m][e] == 0. && obadmask[l][m][e] == 0 && dexy[l][m][e]-calped[l][m][e] < minstrip && dexy[l][m][e] > 0. && onlmask[ee] == 0 ) { |
1103 |
minstrip = dexy[l][m][e]-calped[l][m][e]; |
minstrip = dexy[l][m][e]-calped[l][m][e]; |
1104 |
rms = calthr[l][m][pre]; |
rms = calthr[l][m][pre]; |
1105 |
}; |
spos = ee; |
1106 |
|
}; |
1107 |
|
ee++; |
1108 |
|
qp += (dexy[l][m][e]-calped[l][m][e]-sbase[l][m][e]); |
1109 |
|
}; |
1110 |
|
// |
1111 |
|
if ( debug && l==0 ){ |
1112 |
|
printf("\n BASELINE CALCULATION for view %i pl %i pre %i: \n => minstrip %f rms %f \n => qp = %f \n",l,m,pre,minstrip,rms,qp); |
1113 |
}; |
}; |
1114 |
if ( minstrip != 100000. ) { |
if ( minstrip != 100000. ) { |
1115 |
Float_t strip6s = 0.; |
Float_t strip6s = 0.; |
1116 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1117 |
if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) { |
if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) { |
1118 |
strip6s += 1.; |
strip6s += 1.; |
1119 |
base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]); |
base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]); |
|
}; |
|
|
// |
|
|
// compression |
|
|
// |
|
|
if ( abs((int)(dexy[l][m][e]-calped[l][m][e])) <= (minstrip+rms) ) { |
|
|
dexyc[l][m][e] = 0.; |
|
|
} else { |
|
|
dexyc[l][m][e] = dexy[l][m][e]; |
|
|
}; |
|
1120 |
}; |
}; |
1121 |
if ( strip6s >= 9. ){ |
// |
1122 |
Double_t arro = base[l][m][pre]/strip6s; |
// compression |
1123 |
Float_t deci = 1000.*((float)arro - float(int(arro))); |
// |
1124 |
if ( deci < 500. ) { |
// if ( abs((int)(dexy[l][m][e]-calped[l][m][e])) <= (minstrip+rms) ) { |
1125 |
arro = double(int(arro)); |
// dexyc[l][m][e] = 0.; |
1126 |
} else { |
// } else { |
1127 |
arro = 1. + double(int(arro)); |
dexyc[l][m][e] = dexy[l][m][e]; |
1128 |
}; |
// }; |
1129 |
base[l][m][pre] = arro; |
}; |
1130 |
|
// |
1131 |
|
if ( strip6s == 1. && process < 1 ){ |
1132 |
|
onlmask[spos] = 1; |
1133 |
|
process++; |
1134 |
|
if ( debug ) printf(" Warning, only one strip to calculate baseline: minstrip %f rms %f spos %i l %i m %i pre %i \n",minstrip,rms,spos,l,m,pre); |
1135 |
|
continue; |
1136 |
|
}; |
1137 |
|
process += 2; |
1138 |
|
nst = (Int_t)strip6s; |
1139 |
|
// |
1140 |
|
if ( debug ){ |
1141 |
|
printf(" strip6s %f \n",strip6s); |
1142 |
|
}; |
1143 |
|
// if ( strip6s >= 9. ){ |
1144 |
|
if ( (strip6s >= 2. && process == 2) || (strip6s >= 9. && process > 2) ){ |
1145 |
|
//if ( (strip6s >= 4. && process == 2) || (strip6s >= 9. && process > 2) ){ |
1146 |
|
Double_t arro = base[l][m][pre]/strip6s; |
1147 |
|
Float_t deci = 1000.*((float)arro - float(int(arro))); |
1148 |
|
if ( deci < 500. ) { |
1149 |
|
arro = double(int(arro)); |
1150 |
} else { |
} else { |
1151 |
base[l][m][pre] = 31000.; |
arro = 1. + double(int(arro)); |
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
|
|
dexyc[l][m][e] = dexy[l][m][e]; |
|
|
}; |
|
1152 |
}; |
}; |
1153 |
} else { |
base[l][m][pre] = arro; |
1154 |
|
// |
1155 |
|
// if too few strips were used to determine the baseline check if it is comparable with the previous event, if not mark it as bad |
1156 |
|
// |
1157 |
|
if ( debug && process > 2 ) printf(" AGH low strip value was discarded process %i strip6s %f minstrip %f rms %f spos %i\n",process,strip6s,minstrip,rms,spos); |
1158 |
|
if ( debug ) printf(" Calculated baseline: base %f sbase-0.02*qp %f \n",base[l][m][pre],(-qp*0.02+sbase[l][m][pre])); |
1159 |
|
// |
1160 |
|
if ( strip6s < 4 && base[l][m][pre] > (-0.015*qp+sbase[l][m][pre]) && sbase[l][m][pre] > 0. ){ |
1161 |
|
if ( debug ) printf(" Suspicious calculated baseline: base %f sbase-0.02*qp %f strip6s %i \n",base[l][m][pre],(-qp*0.02+sbase[l][m][pre]),(Int_t)strip6s); |
1162 |
|
base[l][m][pre] = 31000.; |
1163 |
|
nst = 0; // 9RED BUG |
1164 |
|
qp = 0.; // 9RED BUG |
1165 |
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1166 |
|
dexyc[l][m][e] = dexy[l][m][e]; |
1167 |
|
}; |
1168 |
|
}; |
1169 |
|
} else { |
1170 |
|
if ( debug ) printf(" reset baseline here if ! ( (strip6s >=2 && process == 2) || (strip6s >= 9 and process > 2) ) \n"); |
1171 |
base[l][m][pre] = 31000.; |
base[l][m][pre] = 31000.; |
1172 |
|
nst = 0; // 9RED BUG |
1173 |
|
qp = 0.; // 9RED BUG |
1174 |
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1175 |
|
dexyc[l][m][e] = dexy[l][m][e]; |
1176 |
|
}; |
1177 |
|
}; |
1178 |
|
} else { |
1179 |
|
if ( debug ) printf(" reset baseline here if no minimum find\n"); |
1180 |
|
nst = 0; // 9RED BUG |
1181 |
|
qp = 0.; // 9RED BUG |
1182 |
|
process += 2; |
1183 |
|
base[l][m][pre] = 31000.; |
1184 |
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
1185 |
|
dexyc[l][m][e] = dexy[l][m][e]; |
1186 |
|
}; |
1187 |
}; |
}; |
1188 |
|
}; |
1189 |
|
if ( debug ) printf(" Baseline calculation: baseline for view %i plane %i pre %i is %f nst %i qp %f \n",l,m,pre,base[l][m][pre],nst,qp); |
1190 |
} |
} |
1191 |
|
|
1192 |
Int_t CaloLevel0::Calibrate(Int_t ei){ |
Int_t CaloLevel0::Calibrate(Int_t ei){ |
1193 |
// |
// |
1194 |
// get entry ei |
// get entry ei |
1195 |
// |
// |
1196 |
l0calo->GetEntry(ei); |
if ( l0calo->GetEntry(ei) <= 0 ) throw -36; |
1197 |
// |
// |
1198 |
// if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3. |
// if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3. |
1199 |
// |
// |
1200 |
clevel2->nsatstrip = 0.; |
clevel2->nsatstrip = 0.; |
1201 |
Int_t val = 0; |
Int_t val = 0; |
1202 |
Int_t del = 1100; |
Int_t del = 1000; |
1203 |
for (Int_t sec = 0; sec < 4; sec++){ |
for (Int_t sec = 0; sec < 4; sec++){ |
1204 |
for (Int_t dsec = 0; dsec < 7; dsec++){ |
for (Int_t dsec = 0; dsec < 7; dsec++){ |
1205 |
val = (Int_t)de->calselftrig[sec][dsec]; |
val = (Int_t)de->calselftrig[sec][dsec]; |
1208 |
}; |
}; |
1209 |
}; |
}; |
1210 |
val = 0; |
val = 0; |
1211 |
del = 1100; |
del = 1000; |
1212 |
if ( clevel2->trigty != 2. ){ |
if ( clevel2->trigty < 2. ){ |
1213 |
Bool_t ck = false; |
Bool_t ck = false; |
1214 |
for (Int_t sec = 0; sec < 4; sec++){ |
for (Int_t sec = 0; sec < 4; sec++){ |
1215 |
val = (Int_t)de->calselftrig[sec][6]; |
val = (Int_t)de->calselftrig[sec][6]; |
1216 |
del = delay(val); |
del = delay(val); |
1217 |
if ( del < 1100 ){ |
if ( del < 1000 ){ |
1218 |
clevel2->wartrig = 0.; |
clevel2->wartrig = 0.; |
1219 |
clevel2->trigty = 3.; |
clevel2->trigty = 3.; |
1220 |
ck = true; |
ck = true; |
1221 |
break; |
break; |
1222 |
}; |
}; |
1223 |
}; |
}; |
1224 |
if ( !ck ) clevel2->wartrig = 100.; |
// if ( !ck ) clevel2->wartrig = 100.; |
1225 |
} else { |
} else { |
1226 |
Bool_t ck = false; |
Bool_t ck = false; |
1227 |
for (Int_t sec = 0; sec < 4; sec++){ |
for (Int_t sec = 0; sec < 4; sec++){ |
1228 |
val = (Int_t)de->calselftrig[sec][6]; |
val = (Int_t)de->calselftrig[sec][6]; |
1229 |
del = delay(val); |
del = delay(val); |
1230 |
if ( del < 1100 ){ |
if ( del < 1000 ){ |
1231 |
clevel2->wartrig = 0.; |
clevel2->wartrig = 0.; |
1232 |
ck = true; |
ck = true; |
1233 |
}; |
}; |
1244 |
Float_t ener; |
Float_t ener; |
1245 |
Int_t doneb = 0; |
Int_t doneb = 0; |
1246 |
Int_t donec = 0; |
Int_t donec = 0; |
1247 |
Int_t ck = 0; |
Int_t ck[2][22][6]; |
1248 |
|
memset(ck, 0, 2*22*6*sizeof(Int_t)); |
1249 |
Int_t ipre = 0; |
Int_t ipre = 0; |
1250 |
Int_t ip[3] = {0}; |
// Int_t ip[3] = {0}; |
1251 |
|
Int_t ip[3] = {0,0,0}; |
1252 |
|
Int_t ipp = 0; |
1253 |
Float_t base0, base1, base2; |
Float_t base0, base1, base2; |
1254 |
base0 = 0.; |
base0 = 0.; |
1255 |
base1 = 0.; |
base1 = 0.; |
1256 |
base2 = 0.; |
base2 = 0.; |
1257 |
Float_t qpre[6] = {0.,0.,0.,0.,0.,0.}; |
Float_t qpre[2][22][6]; |
1258 |
|
memset(qpre, 0, 2*22*6*sizeof(Float_t)); |
1259 |
Float_t ene[96]; |
Float_t ene[96]; |
1260 |
Int_t chdone[4] = {0,0,0,0}; |
Int_t chdone[4] = {0,0,0,0}; |
1261 |
Int_t pe = 0; |
Int_t pe = 0; |
1262 |
// |
// |
1263 |
Float_t ener0 = 0.; |
Float_t ener0 = 0.; |
1264 |
Float_t cbase0 = 0.; |
Float_t cbase0 = 0.; |
1265 |
|
Float_t totbase = 0.; |
1266 |
|
Float_t totped = 0.; |
1267 |
Bool_t pproblem = false; |
Bool_t pproblem = false; |
1268 |
|
Bool_t negbase = false; |
1269 |
// |
// |
1270 |
Float_t tim = 0.; |
Float_t tim = 0.; |
1271 |
Int_t plo = 0; |
Int_t plo = 0; |
1279 |
// |
// |
1280 |
// determine the section number |
// determine the section number |
1281 |
// |
// |
1282 |
|
negbase = false; |
1283 |
se = 5; |
se = 5; |
1284 |
if (l == 0 && m%2 == 0) se = 3; |
if (l == 0 && m%2 == 0) se = 3; |
1285 |
if (l == 0 && m%2 != 0) se = 2; |
if (l == 0 && m%2 != 0) se = 2; |
1305 |
}; |
}; |
1306 |
clevel2->perr[se] = 0; |
clevel2->perr[se] = 0; |
1307 |
if ( de->perror[se] != 0 ){ |
if ( de->perror[se] != 0 ){ |
1308 |
clevel2->perr[se] = 1; |
clevel2->perr[se] = (Int_t)de->perror[se]; |
1309 |
pe++; |
pe++; |
1310 |
}; |
}; |
1311 |
clevel2->swerr[se] = 0; |
clevel2->swerr[se] = 0; |
1321 |
pre = -1; |
pre = -1; |
1322 |
// |
// |
1323 |
for (Int_t nn = 0; nn < 96; nn++){ |
for (Int_t nn = 0; nn < 96; nn++){ |
1324 |
ene[nn] = 0.; |
// ene[nn] = 0.; |
1325 |
dexy[l][m][nn] = de->dexy[l][m][nn] ; |
dexy[l][m][nn] = de->dexy[l][m][nn] ; |
1326 |
dexyc[l][m][nn] = de->dexyc[l][m][nn] ; |
dexyc[l][m][nn] = de->dexyc[l][m][nn] ; |
1327 |
}; |
}; |
1330 |
// |
// |
1331 |
pre = -1; |
pre = -1; |
1332 |
cbase0 = 0.; |
cbase0 = 0.; |
1333 |
|
Int_t nstt[2]; |
1334 |
|
Float_t rqp[2]; |
1335 |
for (Int_t i = 0; i < 3; i++){ |
for (Int_t i = 0; i < 3; i++){ |
1336 |
|
nstt[0] = 1000; |
1337 |
|
nstt[1] = 1000; |
1338 |
|
rqp[0] = 0.; |
1339 |
|
rqp[1] = 0.; |
1340 |
for (Int_t j = 0; j < 2; j++){ |
for (Int_t j = 0; j < 2; j++){ |
1341 |
pre = j + i*2; |
pre = j + i*2; |
1342 |
// |
// |
1343 |
// baseline check and calculation |
// baseline check and calculation |
1344 |
// |
// |
1345 |
if ( !isRAW ) { |
if ( !isRAW ){ |
1346 |
base[l][m][pre] = de->base[l][m][pre] ; |
// |
1347 |
|
// if it is a compress event with fully transmitted pre try to calculate the baseline |
1348 |
|
// |
1349 |
|
if ( de->base[l][m][pre] != 0. && de->base[l][m][pre]<31000. ) { |
1350 |
|
base[l][m][pre] = de->base[l][m][pre] ; |
1351 |
|
} else { |
1352 |
|
FindBaseCompress(l,m,pre,nstt[j],rqp[j]); |
1353 |
|
}; |
1354 |
cbase0 += base[l][m][pre]; |
cbase0 += base[l][m][pre]; |
1355 |
} else { |
} else { |
1356 |
// |
// |
1357 |
// if it is a raw event and we haven't checked |
// if it is a raw event calculate the baseline. |
|
// yet, calculate the baseline. |
|
1358 |
// |
// |
1359 |
FindBaseRaw(l,m,pre); |
FindBaseRaw(l,m,pre,nstt[j],rqp[j]); |
1360 |
cbase0 += base[l][m][pre]; |
cbase0 += base[l][m][pre]; |
1361 |
}; |
}; |
1362 |
}; |
}; |
1363 |
|
// |
1364 |
|
// if we are able to calculate the baseline with more than 3 strips on one pre and not in the other one choose the pre with more calculated strips |
1365 |
|
// |
1366 |
|
if ( nstt[0] < 4 && nstt[1] >= 4 && nstt[0] != 1000 && nstt[1] != 1000 ) base[l][m][pre-1] = 31000.; |
1367 |
|
if ( nstt[0] >= 4 && nstt[1] < 4 && nstt[0] != 1000 && nstt[1] != 1000 ) base[l][m][pre] = 31000.; |
1368 |
|
// // |
1369 |
|
// // if we are NOT able to calculate the baseline with more than 3 strips on both pres take the baseline (if any) of the one which has less energy |
1370 |
|
// // |
1371 |
|
// if ( nstt[0] < 4 && nstt[1] < 4 ){ |
1372 |
|
// if ( rqp[0] >= rqp[1] ) base[l][m][pre-1] = 31000.; |
1373 |
|
// if ( rqp[0] < rqp[1] ) base[l][m][pre] = 31000.; |
1374 |
|
// }; |
1375 |
}; |
}; |
1376 |
// |
// |
1377 |
// run over strips |
// run over strips |
1378 |
// |
// |
1379 |
pre = -1; |
pre = -1; |
1380 |
ener0 = 0.; |
ener0 = 0.; |
1381 |
|
totbase = 0.; |
1382 |
|
totped = 0.; |
1383 |
for (Int_t i = 0 ; i < 3 ; i++){ |
for (Int_t i = 0 ; i < 3 ; i++){ |
1384 |
ip[i] = 0; |
ip[i] = 0; |
1385 |
for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ |
for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ |
1386 |
if (n%16 == 0) { |
if (n%16 == 0) { |
|
ck = 0; |
|
1387 |
done = 0; |
done = 0; |
1388 |
doneb = 0; |
doneb = 0; |
1389 |
donec = 0; |
donec = 0; |
1390 |
pre++; |
pre++; |
1391 |
qpre[pre] = 0.; |
ck[l][m][pre] = 0; |
1392 |
|
qpre[l][m][pre] = 0.; |
1393 |
}; |
}; |
1394 |
// |
// |
1395 |
// baseline check and calculation |
// baseline check and calculation |
1397 |
// no suitable new baseline, use old ones! |
// no suitable new baseline, use old ones! |
1398 |
// |
// |
1399 |
if ( !done ){ |
if ( !done ){ |
1400 |
|
if ( debug ) printf(" l %i m %i pre %i ip[i] %i base %f base ip[i] %f sbase %f \n",l,m,pre,ip[i],base[l][m][pre],base[l][m][ip[i]],sbase[l][m][pre]); |
1401 |
if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){ |
if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){ |
1402 |
ck = 1; |
ck[l][m][pre] = 1; |
1403 |
if (pre%2 == 0) { |
if (pre%2 == 0) { |
1404 |
ip[i] = pre + 1; |
ip[i] = pre + 1; |
1405 |
} else { |
} else { |
1407 |
}; |
}; |
1408 |
if ( (base[l][m][ip[i]] == 31000. || base[l][m][ip[i]] == 0. || !crosst ) ){ |
if ( (base[l][m][ip[i]] == 31000. || base[l][m][ip[i]] == 0. || !crosst ) ){ |
1409 |
// |
// |
1410 |
ck = 2; |
ck[l][m][pre] = 2; |
1411 |
if ( sbase[l][m][pre] == 31000. || sbase[l][m][pre] == 0. ) { |
if ( sbase[l][m][pre] == 31000. || sbase[l][m][pre] == 0. ) { |
1412 |
ck = 3; |
ck[l][m][pre] = 3; |
1413 |
}; |
}; |
1414 |
}; |
}; |
|
done = 1; |
|
1415 |
}; |
}; |
1416 |
|
done = 1; |
1417 |
}; |
}; |
1418 |
// |
// |
1419 |
// CALIBRATION ALGORITHM |
// CALIBRATION ALGORITHM |
1420 |
// |
// |
1421 |
if ( !doneb ){ |
if ( !doneb ){ |
1422 |
if ( debug ) printf(" ck is %i \n",ck); |
if ( debug ) printf(" ck[l][m][pre] is %i \n",ck[l][m][pre]); |
1423 |
switch (ck) { |
switch (ck[l][m][pre]) { |
1424 |
case 0: |
case 0: |
1425 |
base0 = base[l][m][pre]; |
base0 = base[l][m][pre]; |
1426 |
base2 = calbase[l][m][pre]; |
base2 = calbase[l][m][pre]; |
1427 |
if ( debug ) printf(" base0 = base l m pre = %f base2 = calbase l m pre = %f \n",base[l][m][pre],calbase[l][m][pre]); |
if ( debug ) printf(" base0 = base l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,base[l][m][pre],calbase[l][m][pre]); |
1428 |
break; |
break; |
1429 |
case 1: |
case 1: |
1430 |
base0 = base[l][m][ip[i]]; |
base0 = base[l][m][ip[i]]; |
1431 |
base2 = calbase[l][m][ip[i]]; |
base2 = calbase[l][m][ip[i]]; |
1432 |
if ( debug ) printf(" base0 = base l m ip(i) = %f base2 = calbase l m ip(i) = %f \n",base[l][m][ip[i]],calbase[l][m][ip[i]]); |
if ( debug ) printf(" base0 = base l%i m%i ip(i)%i = %f base2 = calbase l m ip(i) = %f \n",l,m,ip[i],base[l][m][ip[i]],calbase[l][m][ip[i]]); |
1433 |
break; |
break; |
1434 |
case 2: |
case 2: |
1435 |
base0 = sbase[l][m][pre]; |
base0 = sbase[l][m][pre]; |
1436 |
base2 = calbase[l][m][pre]; |
base2 = calbase[l][m][pre]; |
1437 |
if ( debug ) printf(" base0 = sbase l m pre = %f base2 = calbase l m pre = %f \n",sbase[l][m][pre],calbase[l][m][pre]); |
if ( debug ) printf(" base0 = sbase l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,sbase[l][m][pre],calbase[l][m][pre]); |
1438 |
break; |
break; |
1439 |
case 3: |
case 3: |
1440 |
base0 = calbase[l][m][pre]; |
base0 = calbase[l][m][pre]; |
1441 |
base2 = calbase[l][m][pre]; |
base2 = calbase[l][m][pre]; |
1442 |
if ( debug ) printf(" base0 = calbase l m pre = %f base2 = calbase l m pre = %f \n",calbase[l][m][pre],calbase[l][m][pre]); |
if ( debug ) printf(" base0 = calbase l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,calbase[l][m][pre],calbase[l][m][pre]); |
1443 |
break; |
break; |
1444 |
}; |
}; |
1445 |
base1 = calbase[l][m][pre]; |
base1 = calbase[l][m][pre]; |
1448 |
ener = dexyc[l][m][n]; |
ener = dexyc[l][m][n]; |
1449 |
ener0 += ener; |
ener0 += ener; |
1450 |
clevel1->estrip[n][m][l] = 0.; |
clevel1->estrip[n][m][l] = 0.; |
1451 |
|
totbase += de->base[l][m][pre]/96.; |
1452 |
|
totped += fabs(calped[l][m][n]); |
1453 |
|
if ( de->base[l][m][pre] < 0 ) negbase = true; |
1454 |
if ( base0>0 && base0 < 30000. ){ |
if ( base0>0 && base0 < 30000. ){ |
1455 |
// if ( !donec && (base0 - base1 + base2) != 0. ){ |
// |
1456 |
// sbase[l][m][pre] = base0 - base1 + base2; |
// save the baseline only if the energy release is "small" |
1457 |
if ( !donec && (base0 + base1 - base2) != 0. ){ |
// |
1458 |
sbase[l][m][pre] = base0 + base1 - base2; |
if ( !donec && (base0 + base1 - base2) != 0. && (n+1)%16==0 ){ |
1459 |
|
if ( qpre[l][m][pre] < 200. ) sbase[l][m][pre] = base0 + base1 - base2; |
1460 |
donec = 1; |
donec = 1; |
1461 |
}; |
}; |
1462 |
if ( ener > 0. ){ |
if ( ener > 0. ){ |
1464 |
// |
// |
1465 |
// OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course) |
// OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course) |
1466 |
// |
// |
1467 |
qpre[pre] += clevel1->estrip[n][m][l]; |
if ( debug && l==0 && (m==17 || m==18) ) printf(" view %i plane %i strip %i ener %f calped %f base0 %f base1 %f base2 %f mip %f ENERGIA %f \n",l,m,n,ener,calped[l][m][n],base0,base1,base2,mip[l][m][n],clevel1->estrip[n][m][l]); |
1468 |
|
if ( clevel1->estrip[n][m][l] > 0. ) qpre[l][m][pre] += clevel1->estrip[n][m][l]; |
1469 |
// |
// |
1470 |
// |
// |
1471 |
}; |
}; |
1472 |
}; |
}; |
1473 |
}; |
}; |
|
if ( crosst ){ |
|
|
if (ck == 1){ |
|
|
if (ip[i]%2 == 0) { |
|
|
ipre = ip[i] + 1; |
|
|
} else { |
|
|
ipre = ip[i] - 1; |
|
|
}; |
|
|
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
|
|
if ( !ctground ){ |
|
|
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * ctprecor[l][m][ipre]; |
|
|
} else { |
|
|
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
if (ck == 2){ |
|
|
for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ |
|
|
ipre = j/16 + 1; |
|
|
if ( !ctground ){ |
|
|
clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre]; |
|
|
} else { |
|
|
clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
1474 |
}; |
}; |
1475 |
// |
// |
1476 |
if ( ener0 == 0. && cbase0 == 0. && !pproblem && clevel2->perr[se] == 0){ |
// check if there were problems with 5.7 or glitches in the power supply |
1477 |
if ( verbose ) printf(" L0 entry %i : calorimeter power problems! event marked as bad perr %f swerr %X view %i plane %i \n",ei,de->perror[se],de->stwerr[se],l,m); |
// |
1478 |
|
// if ( ((ener0 == 0. && cbase0 == 0.) || negbase || totbase > 196600. || totped < 1. ) && !pproblem && clevel2->perr[se] == 0){ // check pedestal and baseline values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.] |
1479 |
|
if ( ((ener0 == 0. && cbase0 == 0.) || negbase || totbase > 32700. || totped < 1. ) && !pproblem && clevel2->perr[se] == 0){ // check pedestal and baseline values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.] |
1480 |
|
if ( verbose ) printf(" L0 entry %i : calorimeter power problems! event marked as bad perr %f swerr %X view %i plane %i negbase %i totbase %f totped %f\n",ei,de->perror[se],de->stwerr[se],l,m, negbase, totbase, totped); |
1481 |
pproblem = true; |
pproblem = true; |
1482 |
pe++; |
pe++; |
1483 |
}; |
}; |
1484 |
// |
// |
1485 |
Int_t j4 = -4; |
} else { |
1486 |
Int_t jjj = -3; |
for (Int_t nn = 0; nn < 96; nn++){ |
1487 |
Int_t jj = -2; |
clevel1->estrip[nn][m][l] = 0.; |
1488 |
Int_t jjpre = -1; |
}; |
1489 |
Int_t jjjpre = -1; |
}; |
1490 |
for (Int_t j = 0 ; j < 100 ; j++){ |
}; |
1491 |
jj++; |
}; |
1492 |
jjj++; |
// |
1493 |
j4++; |
// run over views and planes to apply crosstalk corrections |
1494 |
if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; |
// |
1495 |
if ( crosst ){ |
for (Int_t l = 0; l < 2; l++){ |
1496 |
if ( jj >= 0 && jj < 96 ){ |
for (Int_t m = 0; m < 22; m++){ |
1497 |
if ( !ctground ){ |
// |
1498 |
if ( jj%16 == 0 ) jjpre++; |
// determine the section number |
1499 |
if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
// |
1500 |
if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
se = 5; |
1501 |
} else { |
if (l == 0 && m%2 == 0) se = 3; |
1502 |
if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * 0.01581; |
if (l == 0 && m%2 != 0) se = 2; |
1503 |
if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * 0.01581; |
if (l == 1 && m%2 != 0) se = 1; |
1504 |
|
if (l == 1 && m%2 == 0) se = 0; |
1505 |
|
// |
1506 |
|
// check for any error in the event |
1507 |
|
// |
1508 |
|
if ( clevel2->crc[se] == 0 && (clevel1->good2 == 1 || clevel2->trigty >= 2) ){ |
1509 |
|
// |
1510 |
|
// Cross-talk corrections |
1511 |
|
// |
1512 |
|
if ( crosst ){ |
1513 |
|
// |
1514 |
|
// energy on silicon ladders |
1515 |
|
// |
1516 |
|
Float_t qsi[3]; |
1517 |
|
qsi[0] = qpre[l][m][0]+qpre[l][m][1]; |
1518 |
|
qsi[1] = qpre[l][m][2]+qpre[l][m][3]; |
1519 |
|
qsi[2] = qpre[l][m][4]+qpre[l][m][5]; |
1520 |
|
// |
1521 |
|
for ( pre = 1; pre < 6; pre += 2 ){ |
1522 |
|
Int_t ladder = (pre - 1)/2; |
1523 |
|
// |
1524 |
|
// If the noselfct flag is set the strip doesn't suffer the self crosstalk due to electronics so we must subtract some energy |
1525 |
|
// |
1526 |
|
if ( noselfct ){ |
1527 |
|
for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ |
1528 |
|
ipre = j/16 ; |
1529 |
|
if ( debug ) printf(" CT STEP1 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1530 |
|
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] -= clevel1->estrip[j][m][l] * ctprecor[l][m][ipre]; |
1531 |
|
if ( debug ) printf(" CT STEP2 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1532 |
}; |
}; |
1533 |
}; |
}; |
1534 |
if ( jjj >= 0 && jjj < 96 ){ |
// |
1535 |
if ( !ctground ){ |
// Using the neighbour pre baseline |
1536 |
if ( jjj%16 == 0 ) jjjpre++; |
// |
1537 |
if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
if (ck[l][m][pre] == 1 || ck[l][m][pre-1] == 1){ |
1538 |
if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
// |
1539 |
|
// pre-amplifier effect on baseline when using the neighbour pre (ck=1) |
1540 |
|
// |
1541 |
|
if (ck[l][m][pre] == 1){ |
1542 |
|
ipre = pre; |
1543 |
|
ipp = pre - 1; |
1544 |
} else { |
} else { |
1545 |
if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * 0.01581; |
ipre = pre - 1; |
1546 |
if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * 0.01581; |
ipp = pre; |
1547 |
|
}; |
1548 |
|
Int_t it = 0; |
1549 |
|
Float_t nqpre = 0.; |
1550 |
|
// |
1551 |
|
if ( debug ) printf(" CK1 Limit for while: 0.07 \n"); |
1552 |
|
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
1553 |
|
if ( debug ) printf(" CT STEP3 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipp]); |
1554 |
|
if ( !ctground ){ |
1555 |
|
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * ctprecor[l][m][ipp]; |
1556 |
|
} else { |
1557 |
|
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * 0.00478; |
1558 |
|
}; |
1559 |
|
if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; |
1560 |
|
if ( debug ) printf(" CT STEP4 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipp]); |
1561 |
|
}; |
1562 |
|
qpre[l][m][ipre] = nqpre; |
1563 |
|
nqpre = 0.; |
1564 |
|
Float_t deltaqpre = qpre[l][m][ipre]; |
1565 |
|
// |
1566 |
|
// these values are empirically determined, usually the routine converge due to deltaqsi and the latest applied correction is based on less than 1 mip |
1567 |
|
// |
1568 |
|
while ( it < 10 && deltaqpre > 0.07 ){ |
1569 |
|
nqpre = 0.; |
1570 |
|
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
1571 |
|
if ( debug ) printf(" CT STEP5 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1572 |
|
if ( !ctground ){ |
1573 |
|
if ( debug ) printf(" CK1 pre correction: iteration %i deltaqpre %f ctprecor %f TOTAL CORRECTION %f \n",it,deltaqpre,ctprecor[l][m][ipre],deltaqpre * ctprecor[l][m][ipre]); |
1574 |
|
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * ctprecor[l][m][ipre]; |
1575 |
|
} else { |
1576 |
|
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * 0.00478; |
1577 |
|
}; |
1578 |
|
if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; |
1579 |
|
if ( debug ) printf(" CT STEP6 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctprecor[l][m][ipre]); |
1580 |
|
}; |
1581 |
|
if ( ctground ) it = 100; |
1582 |
|
it++; |
1583 |
|
deltaqpre = nqpre - qpre[l][m][ipre]; |
1584 |
|
if ( debug ) printf(" CK1 BEFORE: qpre %f \n",qpre[l][m][ipre]); |
1585 |
|
qpre[l][m][ipre] = nqpre; |
1586 |
|
if ( debug ) printf(" CK1 AFTER: qpre %f \n",qpre[l][m][ipre]); |
1587 |
}; |
}; |
1588 |
|
// |
1589 |
}; |
}; |
|
}; |
|
|
if ( j4 >= 0 && j4 < 96 ){ |
|
|
// |
|
|
// NOTICE: THE FOLLOWING LINE EXCLUDE ALL STRIPS FOR WHICH THE RMS*4 IS GREATER THAN 26 !!! <=============== IMPORTANT! =================> |
|
1590 |
// |
// |
1591 |
if ( obadmask[l][m][j4] == 1 || clevel1->estrip[j4][m][l] <= clevel1->emin || calrms[l][m][j4] > 26 ){ |
// No baseline calculation due to high energy release |
|
clevel1->estrip[j4][m][l] = 0.; |
|
|
}; |
|
|
// |
|
|
// code and save the energy for each strip in svstrip |
|
1592 |
// |
// |
1593 |
if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ |
if (ck[l][m][pre] == 2 && ck[l][m][pre-1] == 2){ |
1594 |
// |
// |
1595 |
Float_t savel1 = clevel1->estrip[j4][m][l]; |
// y^ |
1596 |
if ( dexyc[l][m][j4] == 32767. ){ |
// | |
1597 |
savel1 += 5000.; |
// | 6 7 8 |
1598 |
clevel2->nsatstrip += 1.; |
// | 3 4 5 |
1599 |
}; |
// | 0 1 2 |
1600 |
|
// | --------------------------------------> x |
1601 |
// |
// |
1602 |
tim = 100000.; |
Int_t si1 = 0; |
1603 |
plo = m; |
Int_t si2 = 0; |
1604 |
fbi = 0; |
Int_t si3 = 0; |
1605 |
if ( savel1 > 0.99995 ){ |
if ( l == 0 ){ |
1606 |
tim = 10000.; |
if ( ladder == 0 ){ |
1607 |
plo = m; |
si1 = 0; |
1608 |
fbi = 1; |
si2 = 3; |
1609 |
}; |
si3 = 6; |
1610 |
if ( savel1 > 9.9995 ){ |
}; |
1611 |
tim = 1000.; |
if ( ladder == 1 ){ |
1612 |
plo = 22 + m; |
si1 = 1; |
1613 |
fbi = 1; |
si2 = 4; |
1614 |
}; |
si3 = 7; |
1615 |
if ( savel1 > 99.995 ){ |
}; |
1616 |
tim = 100.; |
if ( ladder == 2 ){ |
1617 |
plo = 22 + m; |
si1 = 2; |
1618 |
fbi = 0; |
si2 = 5; |
1619 |
|
si3 = 8; |
1620 |
|
}; |
1621 |
|
} else { |
1622 |
|
if ( ladder == 0 ){ |
1623 |
|
si1 = 0; |
1624 |
|
si2 = 1; |
1625 |
|
si3 = 2; |
1626 |
|
}; |
1627 |
|
if ( ladder == 1 ){ |
1628 |
|
si1 = 3; |
1629 |
|
si2 = 4; |
1630 |
|
si3 = 5; |
1631 |
|
}; |
1632 |
|
if ( ladder == 2 ){ |
1633 |
|
si1 = 6; |
1634 |
|
si2 = 7; |
1635 |
|
si3 = 8; |
1636 |
|
}; |
1637 |
}; |
}; |
1638 |
if ( savel1 > 999.95 ){ |
// |
1639 |
tim = 10.; |
// Find the energy distribution along the considered plane looking at the two sandwiching plane of the other view. |
1640 |
plo = 44 + m; |
// |
1641 |
fbi = 0; |
Float_t sied[3] = {0.,0.,0.}; |
1642 |
|
Int_t othv = !l; |
1643 |
|
Int_t othpl1 = m - 1; |
1644 |
|
Int_t othpl2 = m + 1; |
1645 |
|
Float_t oprof[3] = {0.,0.,0.}; |
1646 |
|
for(Int_t s=0; s<3; s++){ |
1647 |
|
for(Int_t t=(s*32); t<32*(s + 1); t++){ |
1648 |
|
if ( othpl1 > -1 ) { |
1649 |
|
oprof[s] += clevel1->estrip[othv][othpl1][t]; |
1650 |
|
}; |
1651 |
|
if ( othpl2 < 22 ) { |
1652 |
|
oprof[s] += clevel1->estrip[othv][othpl2][t]; |
1653 |
|
}; |
1654 |
|
}; |
1655 |
}; |
}; |
1656 |
if ( savel1 > 9999.5 ){ |
Float_t otote = fabs(oprof[0]) + fabs(oprof[1]) + fabs(oprof[2]); |
1657 |
tim = 1.; |
for(Int_t g=0; g<3; g++){ |
1658 |
plo = 66 + m; |
if ( otote > 0. ){ |
1659 |
fbi = 0; |
sied[g] = fabs(oprof[g])/otote; |
1660 |
|
} else { |
1661 |
|
sied[g] = 1./3.; |
1662 |
|
}; |
1663 |
}; |
}; |
1664 |
// |
// |
|
cle = (Int_t)lroundf(tim*savel1); |
|
1665 |
// |
// |
1666 |
if ( l == 0 ){ |
// |
1667 |
|
Int_t it = 0; |
1668 |
|
Int_t jpre = 0; |
1669 |
|
Float_t nqsi = 0.; |
1670 |
|
Float_t snqsi = qsi[ladder]; |
1671 |
|
Float_t nqpre[2] = {0.,0.}; |
1672 |
|
Float_t deltaqsi = qsi[ladder]; |
1673 |
|
Float_t deltaqpre[2]; |
1674 |
|
deltaqpre[0] = qpre[l][m][pre-1]; |
1675 |
|
deltaqpre[1] = qpre[l][m][pre]; |
1676 |
|
// |
1677 |
|
if ( debug ) printf(" Limit for while: 0.07 it < 10 \n"); |
1678 |
|
// |
1679 |
|
// these values are empirically determined, usually the routine converge due to deltaqsi and the latest applied correction is based on less than 1 mip |
1680 |
|
// |
1681 |
|
while ( it < 10 && (deltaqsi > 0.07 || deltaqpre[0] > 0.07 || deltaqpre[1] > 0.07) ){ |
1682 |
|
nqsi = 0.; |
1683 |
|
nqpre[0] = 0.; |
1684 |
|
nqpre[1] = 0.; |
1685 |
|
for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ |
1686 |
|
if ( debug ) printf(" CT STEP6 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctsicor[l][m][si2]); |
1687 |
|
ipre = 0; |
1688 |
|
if ( j > (ladder*32)+15 ) ipre = 1; |
1689 |
|
jpre = j/16 ; |
1690 |
|
// |
1691 |
|
// Silicon effect on the baseline when using the same pre previous baseline (ck = 2) + pre-amply effect |
1692 |
|
// |
1693 |
|
if ( !ctground ){ |
1694 |
|
if ( debug ) printf(" silicon correction: iteration %i deltaqsi[%i] %f ctsicor %f %f %f sied %f %f %f si %i %i %i TOTAL CORRECTION %f \n",it,ladder,deltaqsi,ctsicor[l][m][si1],ctsicor[l][m][si2],ctsicor[l][m][si3],sied[0],sied[1],sied[2],si1,si2,si3,deltaqsi * (ctsicor[l][m][si1] * sied[0] + ctsicor[l][m][si2] * sied[1] + ctsicor[l][m][si3] * sied[2])); |
1695 |
|
if ( debug ) printf(" pre correction: iteration %i deltaqpre[0] %f deltaqpre[1] %f ctprecor %f TOTAL CORRECTION %f \n",it,deltaqpre[0],deltaqpre[1],ctprecor[l][m][jpre],deltaqpre[ipre] * ctprecor[l][m][jpre]); |
1696 |
|
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += (deltaqsi * (ctsicor[l][m][si1] * sied[0] + ctsicor[l][m][si2] * sied[1] + ctsicor[l][m][si3] * sied[2])/mip[l][m][j]) + deltaqpre[ipre] * ctprecor[l][m][jpre]; |
1697 |
|
} else { |
1698 |
|
if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += 0. + qpre[l][m][jpre] * 0.00478; // no correction |
1699 |
|
}; |
1700 |
|
if ( clevel1->estrip[j][m][l] > 0. ) nqsi += clevel1->estrip[j][m][l] ; |
1701 |
|
if ( clevel1->estrip[j][m][l] > 0. ) nqpre[ipre] += clevel1->estrip[j][m][l] ; |
1702 |
|
if ( debug ) printf(" CT STEP7 %i %i %i estrip %f ctprecor %f \n",j,m,l,clevel1->estrip[j][m][l],ctsicor[l][m][si2]); |
1703 |
|
}; |
1704 |
|
if ( ctground ) it = 100; |
1705 |
|
deltaqsi = nqsi-snqsi; |
1706 |
|
deltaqpre[0] = nqpre[0] - qpre[l][m][pre-1]; |
1707 |
|
deltaqpre[1] = nqpre[1] - qpre[l][m][pre]; |
1708 |
// |
// |
1709 |
// +-PPSSmmmm.mmmm |
// Check for divergence and stop if it happens! [9RED bug noticed with plane 18X] |
1710 |
// |
// |
1711 |
svstrip[istrip] = fbi*1000000000 + plo*10000000 + j4*100000 + cle; |
if ( deltaqpre[0] > qpre[l][m][pre-1] || deltaqpre[1] > qpre[l][m][pre] || deltaqsi >snqsi ){ |
1712 |
} else { |
if ( debug ) printf(" WARNING!! DIVERGING CORRECTION EXIT IMMEDIATLY FROM THE LOOP!! dqpre0 %f qpre0 %f // dqpre1 %f qpre1 %f // dqsi %f qsi %f \n",deltaqpre[0],qpre[l][m][pre-1],deltaqpre[1],qpre[l][m][pre],deltaqsi,snqsi); |
1713 |
svstrip[istrip] = -(fbi*1000000000 + plo*10000000 + j4*100000 + cle); |
it = 1000; |
1714 |
|
}; |
1715 |
|
// |
1716 |
|
snqsi = nqsi; |
1717 |
|
it++; |
1718 |
|
if ( debug ) printf(" BEFORE: qpre 0 %f qpre 1 %f \n",qpre[l][m][pre-1],qpre[l][m][pre]); |
1719 |
|
qpre[l][m][pre-1] = nqpre[0]; |
1720 |
|
qpre[l][m][pre] = nqpre[1]; |
1721 |
|
if ( debug ) printf(" AFTER: qpre 0 %f qpre 1 %f \n",qpre[l][m][pre-1],qpre[l][m][pre]); |
1722 |
|
}; |
1723 |
|
// |
1724 |
|
// |
1725 |
|
// |
1726 |
|
// for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ |
1727 |
|
// ipre = j/16 ; |
1728 |
|
// // |
1729 |
|
// // pre-amplifier effect on baseline when using the same pre previous event baseline (ck=2) |
1730 |
|
// // |
1731 |
|
// if ( !ctground ){ |
1732 |
|
// if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += qpre[l][m][ipre] * ctprecor[l][m][ipre]; |
1733 |
|
// } else { |
1734 |
|
// if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += qpre[l][m][ipre] * 0.00478; |
1735 |
|
// }; |
1736 |
|
// }; |
1737 |
|
}; |
1738 |
|
}; |
1739 |
|
}; |
1740 |
|
}; |
1741 |
|
// |
1742 |
|
Int_t j4 = -4; |
1743 |
|
Int_t jjj = -3; |
1744 |
|
Int_t jj = -2; |
1745 |
|
Int_t jjpre = -1; |
1746 |
|
Int_t jjjpre = -1; |
1747 |
|
memset(ene, 0, 96*sizeof(Float_t)); |
1748 |
|
for (Int_t j = 0 ; j < 100 ; j++){ |
1749 |
|
jj++; |
1750 |
|
jjj++; |
1751 |
|
j4++; |
1752 |
|
if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; |
1753 |
|
if ( crosst ){ |
1754 |
|
// |
1755 |
|
// "Real" crosstalk effect on the neighbour strips respect to the one which have seen the energy deposit |
1756 |
|
// |
1757 |
|
if ( jj >= 0 && jj < 96 ){ |
1758 |
|
if ( !ctground ){ |
1759 |
|
if ( jj%16 == 0 ) jjpre++; |
1760 |
|
if ( jj != 0 && jj != 32 && jj != 64 && ene[jj-1] != 0. ) ene[jj-1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
1761 |
|
if ( jj != 31 && jj != 63 && jj != 95 && ene[jj+1] != 0. ) ene[jj+1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
1762 |
|
} else { |
1763 |
|
if ( jj != 0 && jj != 32 && jj != 64 && ene[jj-1] != 0. ) ene[jj-1] += -clevel1->estrip[jj][m][l] * 0.01581; |
1764 |
|
if ( jj != 31 && jj != 63 && jj != 95 && ene[jj+1] != 0. ) ene[jj+1] += -clevel1->estrip[jj][m][l] * 0.01581; |
1765 |
|
}; |
1766 |
|
}; |
1767 |
|
if ( jjj >= 0 && jjj < 96 ){ |
1768 |
|
if ( !ctground ){ |
1769 |
|
if ( jjj%16 == 0 ) jjjpre++; |
1770 |
|
if ( jjj != 0 && jjj != 32 && jjj != 64 && clevel1->estrip[jjj-1][m][l] != 0. ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
1771 |
|
if ( jjj != 31 && jjj != 63 && jjj != 95 && clevel1->estrip[jjj+1][m][l] !=0. ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
1772 |
|
} else { |
1773 |
|
if ( jjj != 0 && jjj != 32 && jjj != 64 && clevel1->estrip[jjj-1][m][l] != 0. ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * 0.01581; |
1774 |
|
if ( jjj != 31 && jjj != 63 && jjj != 95 && clevel1->estrip[jjj+1][m][l] != 0. ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * 0.01581; |
1775 |
|
}; |
1776 |
|
}; |
1777 |
|
}; |
1778 |
|
if ( j4 >= 0 && j4 < 96 ){ |
1779 |
|
// |
1780 |
|
// CALOLEVEL1 CODING AND FILLING |
1781 |
|
// |
1782 |
|
// |
1783 |
|
// NOTICE: THE FOLLOWING LINE EXCLUDE ALL STRIPS FOR WHICH THE RMS*4 IS GREATER THAN 26 !!! <=============== IMPORTANT! =================> // not true anymore, now it trust parameter files |
1784 |
|
// |
1785 |
|
if ( obadmask[l][m][j4] == 1 || clevel1->estrip[j4][m][l] <= clevel1->emin || clevel1->estrip[j4][m][l] <= memin[l][m][j4] || calrms[l][m][j4] > maxrms[l][m] || (l==0 && m == 18 && mask18 ) ){ |
1786 |
|
clevel1->estrip[j4][m][l] = 0.; |
1787 |
|
}; |
1788 |
|
// |
1789 |
|
if ( debug ) printf(" STRIP: view %i plane %i strip %i energy: %f \n",l,m,j4,clevel1->estrip[j4][m][l]); |
1790 |
|
// |
1791 |
|
// code and save the energy for each strip in svstrip |
1792 |
|
// |
1793 |
|
if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ |
1794 |
|
// |
1795 |
|
Float_t savel1 = clevel1->estrip[j4][m][l]; |
1796 |
|
// |
1797 |
|
if ( m == 18 && l == 0 ){ |
1798 |
|
if ( debug ) printf(" Resetting plane 18X for variable calculation: view %i plane %i strip %i \n",l,m,j4); |
1799 |
|
clevel1->estrip[j4][m][l] = 0.; // SAVE STRIPS VALUE FOR PLANE 18 X but DO NOT USE IT FOR VARIABLE CALCULATION |
1800 |
|
}; |
1801 |
|
if ( debug ) printf(" HIT STRIP: view %i plane %i strip %i energy: %f \n",l,m,j4,clevel1->estrip[j4][m][l]); |
1802 |
|
// if ( dexyc[l][m][j4] == 32767. ){ |
1803 |
|
if ( dexyc[l][m][j4] > 32000. || savel1 > 5000.){ // CaloLevel1 bug with plane 18X [9RED 14/04/2010] |
1804 |
|
if ( savel1 > 5000 ){ |
1805 |
|
if ( debug ) printf(" Absurd plane 18X energy... resetting value to 1100 MIP \n"); |
1806 |
|
savel1 = 1100.; // CaloLevel1 bug with plane 18x [9RED 14/04/2010] |
1807 |
}; |
}; |
1808 |
|
savel1 += 5000.; |
1809 |
|
clevel2->nsatstrip += 1.; |
1810 |
|
}; |
1811 |
|
// |
1812 |
|
tim = 100000.; |
1813 |
|
plo = m; |
1814 |
|
fbi = 0; |
1815 |
|
if ( savel1 > 0.99995 ){ |
1816 |
|
tim = 10000.; |
1817 |
|
plo = m; |
1818 |
|
fbi = 1; |
1819 |
|
}; |
1820 |
|
if ( savel1 > 9.9995 ){ |
1821 |
|
tim = 1000.; |
1822 |
|
plo = 22 + m; |
1823 |
|
fbi = 1; |
1824 |
|
}; |
1825 |
|
if ( savel1 > 99.995 ){ |
1826 |
|
tim = 100.; |
1827 |
|
plo = 22 + m; |
1828 |
|
fbi = 0; |
1829 |
|
}; |
1830 |
|
if ( savel1 > 999.95 ){ |
1831 |
|
tim = 10.; |
1832 |
|
plo = 44 + m; |
1833 |
|
fbi = 0; |
1834 |
|
}; |
1835 |
|
if ( savel1 > 9999.5 ){ |
1836 |
|
tim = 1.; |
1837 |
|
plo = 66 + m; |
1838 |
|
fbi = 0; |
1839 |
|
}; |
1840 |
|
// |
1841 |
|
cle = (Int_t)lroundf(tim*savel1); |
1842 |
|
// |
1843 |
|
if ( l == 0 ){ |
1844 |
// |
// |
1845 |
// if ( ei >= -770 ) printf(" j %i l %i m %i estrip %f \n",j4,l,m,clevel1->estrip[j4][m][l]); |
// +-PPSSmmmm.mmmm |
|
// if ( ei >= -770 ) printf(" num lim %i fbi %i tim %f plo %i cle %i \n",numeric_limits<Int_t>::max(),fbi,tim,plo,cle); |
|
|
// if ( ei >= -770 ) printf(" svstrip %i \n",svstrip[istrip]); |
|
1846 |
// |
// |
1847 |
istrip++; |
svstrip[istrip] = fbi*1000000000 + plo*10000000 + j4*100000 + cle; |
1848 |
|
} else { |
1849 |
|
svstrip[istrip] = -(fbi*1000000000 + plo*10000000 + j4*100000 + cle); |
1850 |
}; |
}; |
1851 |
|
if ( debug ) printf(" svstrip[%i] = %i fbi %i plo %i j4 %i cle %i \n",istrip,svstrip[istrip],fbi,plo,j4,cle); |
1852 |
|
// |
1853 |
|
istrip++; |
1854 |
}; |
}; |
1855 |
}; |
}; |
|
// |
|
|
} else { |
|
|
for (Int_t nn = 0; nn < 96; nn++){ |
|
|
clevel1->estrip[nn][m][l] = 0.; |
|
|
}; |
|
1856 |
}; |
}; |
1857 |
|
// |
1858 |
}; |
}; |
1859 |
}; |
}; |
1860 |
|
// |
1861 |
|
// store goodness flag |
1862 |
|
// |
1863 |
if ( !pe ){ |
if ( !pe ){ |
1864 |
clevel2->good = 1; |
clevel2->good = 1; |
1865 |
} else { |
} else { |
1866 |
clevel2->good = 0; |
clevel2->good = 0; |
1867 |
}; |
}; |
1868 |
|
// |
1869 |
|
// done |
1870 |
|
// |
1871 |
return(0); |
return(0); |
1872 |
} |
} |
1873 |
|
|
1945 |
void CaloLevel0::FillCommonVar(CaloLevel1 *c1, CaloLevel2 *ca){ |
void CaloLevel0::FillCommonVar(CaloLevel1 *c1, CaloLevel2 *ca){ |
1946 |
// |
// |
1947 |
ca->good = clevel2->good; |
ca->good = clevel2->good; |
1948 |
if ( clevel2->trigty == 2. ){ |
// if ( clevel2->trigty == 2. ){ |
1949 |
ca->selftrigger = 1; |
// ca->selftrigger = 1; |
1950 |
} else { |
// } else { |
1951 |
ca->selftrigger = 0; |
// ca->selftrigger = 0; |
1952 |
}; |
// }; |
1953 |
// |
// |
1954 |
ca->selftrigger += (Int_t)clevel2->wartrig; |
ca->selftrigger = (Int_t)clevel2->trigty + (Int_t)clevel2->wartrig; |
1955 |
// |
// |
1956 |
memcpy(ca->perr,clevel2->perr,sizeof(clevel2->perr)); |
memcpy(ca->perr,clevel2->perr,sizeof(clevel2->perr)); |
1957 |
memcpy(ca->swerr,clevel2->swerr,sizeof(clevel2->swerr)); |
memcpy(ca->swerr,clevel2->swerr,sizeof(clevel2->swerr)); |
1994 |
ClearCommonVar(); |
ClearCommonVar(); |
1995 |
} |
} |
1996 |
|
|
1997 |
|
void CaloLevel0::Delete(Option_t *t){ |
1998 |
|
if ( de ) delete de; |
1999 |
|
delete this; |
2000 |
|
} |
2001 |
|
|
2002 |
|
|
2003 |
void CaloLevel0::RunClose(){ |
void CaloLevel0::RunClose(){ |
2004 |
l0tr->Delete(); |
l0tr->Delete(); |
2005 |
ClearStructs(); |
ClearStructs(); |
2009 |
memset(base, 0, 2*22*6*sizeof(Float_t)); |
memset(base, 0, 2*22*6*sizeof(Float_t)); |
2010 |
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
2011 |
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
2012 |
|
memset(ctsicor, 0, 2*22*9*sizeof(Float_t)); |
2013 |
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
2014 |
// |
// |
2015 |
} |
} |
2228 |
// |
// |
2229 |
if ( !ncalibs ) return(-110); |
if ( !ncalibs ) return(-110); |
2230 |
// |
// |
2231 |
calo->GetEntry(calibno[s]); |
if ( calo->GetEntry(calibno[s]) <= 0 ) throw -36; |
2232 |
// |
// |
2233 |
if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { |
if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { |
2234 |
for ( Int_t d=0 ; d<11 ;d++ ){ |
for ( Int_t d=0 ; d<11 ;d++ ){ |