| 95 |
/** |
/** |
| 96 |
* Initialize CaloLevel0 object |
* Initialize CaloLevel0 object |
| 97 |
**/ |
**/ |
| 98 |
|
void CaloLevel0::ProcessingInit(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
| 99 |
|
if ( !dbc->IsConnected() ) throw -116; |
| 100 |
|
this->InitDo(dbc,hs,sgnl,l0tree,isdeb,isverb); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
/** |
| 104 |
|
* Initialize CaloLevel0 object |
| 105 |
|
**/ |
| 106 |
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){ |
| 107 |
// |
// |
| 108 |
const TString host = glt->CGetHost(); |
const TString host = glt->CGetHost(); |
| 110 |
const TString psw = glt->CGetPsw(); |
const TString psw = glt->CGetPsw(); |
| 111 |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 112 |
if ( !dbc->IsConnected() ) throw -116; |
if ( !dbc->IsConnected() ) throw -116; |
| 113 |
|
this->InitDo(dbc,hs,sgnl,l0tree,isdeb,isverb); |
| 114 |
|
dbc->Close(); |
| 115 |
|
delete dbc; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
void CaloLevel0::InitDo(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
| 120 |
stringstream myquery; |
stringstream myquery; |
| 121 |
myquery.str(""); |
myquery.str(""); |
| 122 |
myquery << "SET time_zone='+0:00'"; |
myquery << "SET time_zone='+0:00'"; |
| 197 |
// |
// |
| 198 |
delete glcalo; |
delete glcalo; |
| 199 |
delete glroot; |
delete glroot; |
|
dbc->Close(); |
|
|
delete dbc; |
|
| 200 |
// |
// |
| 201 |
return; |
return; |
| 202 |
// |
// |
| 213 |
return(sgnl); |
return(sgnl); |
| 214 |
} |
} |
| 215 |
|
|
| 216 |
|
Int_t CaloLevel0::ChkParam(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){ |
| 217 |
|
Int_t sig = this->ChkParamDo(dbc,runheader,mechal); |
| 218 |
|
return(sig); |
| 219 |
|
} |
| 220 |
|
|
| 221 |
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){ |
| 222 |
const TString host = glt->CGetHost(); |
const TString host = glt->CGetHost(); |
| 223 |
const TString user = glt->CGetUser(); |
const TString user = glt->CGetUser(); |
| 229 |
myquery << "SET time_zone='+0:00'"; |
myquery << "SET time_zone='+0:00'"; |
| 230 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
| 231 |
// |
// |
| 232 |
|
Int_t sig = this->ChkParamDo(dbc,runheader,mechal); |
| 233 |
|
dbc->Close(); |
| 234 |
|
delete dbc; |
| 235 |
|
return(sig); |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
Int_t CaloLevel0::ChkParamDo(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){ |
| 239 |
|
// |
| 240 |
stringstream calfile; |
stringstream calfile; |
| 241 |
stringstream bmfile; |
stringstream bmfile; |
| 242 |
stringstream aligfile; |
stringstream aligfile; |
| 247 |
// |
// |
| 248 |
if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){ |
if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){ |
| 249 |
// |
// |
|
// |
|
|
// |
|
| 250 |
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); |
| 251 |
// |
// |
| 252 |
calopar1 = false; |
calopar1 = false; |
| 284 |
}; |
}; |
| 285 |
// |
// |
| 286 |
if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){ |
if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){ |
| 287 |
|
// |
| 288 |
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); |
| 289 |
calopar2 = false; |
calopar2 = false; |
| 290 |
// |
// |
| 392 |
}; |
}; |
| 393 |
// |
// |
| 394 |
delete glparam; |
delete glparam; |
|
dbc->Close(); |
|
|
delete dbc; |
|
| 395 |
// |
// |
| 396 |
return(0); |
return(0); |
| 397 |
} |
} |
| 398 |
|
|
| 399 |
|
Int_t CaloLevel0::CalcCrossTalkCorr(TSQLServer *dbc, UInt_t runheader){ |
| 400 |
|
Int_t sig = CalcCrossTalkCorrDo(dbc,runheader); |
| 401 |
|
return(sig); |
| 402 |
|
} |
| 403 |
|
|
| 404 |
Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){ |
Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){ |
|
// |
|
|
if ( ctground ) return(0); |
|
|
// |
|
| 405 |
const TString host = glt->CGetHost(); |
const TString host = glt->CGetHost(); |
| 406 |
const TString user = glt->CGetUser(); |
const TString user = glt->CGetUser(); |
| 407 |
const TString psw = glt->CGetPsw(); |
const TString psw = glt->CGetPsw(); |
| 412 |
myquery << "SET time_zone='+0:00'"; |
myquery << "SET time_zone='+0:00'"; |
| 413 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
| 414 |
// |
// |
| 415 |
|
Int_t sig = CalcCrossTalkCorrDo(dbc,runheader); |
| 416 |
|
dbc->Close(); |
| 417 |
|
delete dbc; |
| 418 |
|
// |
| 419 |
|
return(sig); |
| 420 |
|
// |
| 421 |
|
} |
| 422 |
|
|
| 423 |
|
Int_t CaloLevel0::CalcCrossTalkCorrDo(TSQLServer *dbc, UInt_t runheader){ |
| 424 |
|
// |
| 425 |
|
if ( ctground ) return(0); |
| 426 |
|
// |
| 427 |
stringstream bmfile; |
stringstream bmfile; |
| 428 |
Int_t error = 0; |
Int_t error = 0; |
| 429 |
ifstream badfile; |
ifstream badfile; |
| 651 |
// |
// |
| 652 |
// |
// |
| 653 |
delete glp; |
delete glp; |
|
dbc->Close(); |
|
|
delete dbc; |
|
| 654 |
// |
// |
| 655 |
// Ok, now we can try to calculate the cross-talk correction for each pre-amplifier |
// Ok, now we can try to calculate the cross-talk correction for each pre-amplifier |
| 656 |
// |
// |
| 786 |
// |
// |
| 787 |
Float_t minstrip = 100000.; |
Float_t minstrip = 100000.; |
| 788 |
Float_t rms = 0.; |
Float_t rms = 0.; |
| 789 |
base[l][m][pre] = 0.; |
Int_t process = 0; |
| 790 |
qp = 0.; |
Int_t onlmask[16]; |
| 791 |
// |
memset(onlmask, 0, 16*sizeof(Int_t)); |
| 792 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
// |
| 793 |
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.) { |
while ( process < 2 ){ |
| 794 |
minstrip = dexy[l][m][e]-calped[l][m][e]; |
// |
| 795 |
rms = calthr[l][m][pre]; |
minstrip = 100000.; |
| 796 |
}; |
rms = 0.; |
| 797 |
qp += (dexy[l][m][e]-calped[l][m][e]-sbase[l][m][e]); |
base[l][m][pre] = 0.; |
| 798 |
}; |
qp = 0.; |
| 799 |
// |
// |
| 800 |
if ( debug && l==1 ){ |
Int_t spos = -1; |
| 801 |
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); |
Int_t ee = 0; |
|
}; |
|
|
if ( minstrip != 100000. ) { |
|
|
Float_t strip6s = 0.; |
|
| 802 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
| 803 |
if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) { |
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 ) { |
| 804 |
strip6s += 1.; |
minstrip = dexy[l][m][e]-calped[l][m][e]; |
| 805 |
base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]); |
rms = calthr[l][m][pre]; |
| 806 |
}; |
spos = ee; |
|
// |
|
|
// 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]; |
|
| 807 |
}; |
}; |
| 808 |
|
ee++; |
| 809 |
|
qp += (dexy[l][m][e]-calped[l][m][e]-sbase[l][m][e]); |
| 810 |
}; |
}; |
| 811 |
// |
// |
| 812 |
nst = (Int_t)strip6s; |
if ( debug && l==0 ){ |
| 813 |
// |
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); |
|
if ( debug && l==1 ){ |
|
|
printf(" strip6s %f \n",strip6s); |
|
| 814 |
}; |
}; |
| 815 |
// if ( strip6s >= 9. ){ |
if ( minstrip != 100000. ) { |
| 816 |
if ( strip6s >= 2. ){ |
Float_t strip6s = 0.; |
| 817 |
Double_t arro = base[l][m][pre]/strip6s; |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
| 818 |
Float_t deci = 1000.*((float)arro - float(int(arro))); |
if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) { |
| 819 |
if ( deci < 500. ) { |
strip6s += 1.; |
| 820 |
arro = double(int(arro)); |
base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]); |
| 821 |
} else { |
}; |
| 822 |
arro = 1. + double(int(arro)); |
// |
| 823 |
|
// compression |
| 824 |
|
// |
| 825 |
|
// if ( abs((int)(dexy[l][m][e]-calped[l][m][e])) <= (minstrip+rms) ) { |
| 826 |
|
// dexyc[l][m][e] = 0.; |
| 827 |
|
// } else { |
| 828 |
|
dexyc[l][m][e] = dexy[l][m][e]; |
| 829 |
|
// }; |
| 830 |
}; |
}; |
|
base[l][m][pre] = arro; |
|
|
// |
|
|
// 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 |
|
| 831 |
// |
// |
| 832 |
if ( debug && l==1 ) printf(" Calculated baseline: base %f sbase*1.02 %f \n",base[l][m][pre],1.02*sbase[l][m][pre]); |
if ( strip6s == 1. && process < 1 ){ |
| 833 |
|
onlmask[spos] = 1; |
| 834 |
|
process++; |
| 835 |
|
continue; |
| 836 |
|
}; |
| 837 |
|
process += 2; |
| 838 |
|
nst = (Int_t)strip6s; |
| 839 |
// |
// |
| 840 |
if ( strip6s < 4 && base[l][m][pre] > 1.02*sbase[l][m][pre] && sbase[l][m][pre] > 0. ){ |
if ( debug && l==1 ){ |
| 841 |
if ( debug ) printf(" Suspicious calculated baseline: base %f sbase*1.02 %f strip6s %i \n",base[l][m][pre],1.02*sbase[l][m][pre],(Int_t)strip6s); |
printf(" strip6s %f \n",strip6s); |
| 842 |
base[l][m][pre] = 31000.; |
}; |
| 843 |
|
// if ( strip6s >= 9. ){ |
| 844 |
|
if ( (strip6s >= 2. && process == 2) || (strip6s >= 9. && process > 2) ){ |
| 845 |
|
Double_t arro = base[l][m][pre]/strip6s; |
| 846 |
|
Float_t deci = 1000.*((float)arro - float(int(arro))); |
| 847 |
|
if ( deci < 500. ) { |
| 848 |
|
arro = double(int(arro)); |
| 849 |
|
} else { |
| 850 |
|
arro = 1. + double(int(arro)); |
| 851 |
|
}; |
| 852 |
|
base[l][m][pre] = arro; |
| 853 |
|
// |
| 854 |
|
// 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 |
| 855 |
|
// |
| 856 |
|
if ( debug && l==1 ) printf(" Calculated baseline: base %f sbase*1.02 %f \n",base[l][m][pre],1.02*sbase[l][m][pre]); |
| 857 |
|
// |
| 858 |
|
if ( strip6s < 4 && base[l][m][pre] > 1.02*sbase[l][m][pre] && sbase[l][m][pre] > 0. ){ |
| 859 |
|
if ( debug ) printf(" Suspicious calculated baseline: base %f sbase*1.02 %f strip6s %i \n",base[l][m][pre],1.02*sbase[l][m][pre],(Int_t)strip6s); |
| 860 |
|
base[l][m][pre] = 31000.; |
| 861 |
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
| 862 |
|
dexyc[l][m][e] = dexy[l][m][e]; |
| 863 |
|
}; |
| 864 |
|
}; |
| 865 |
|
} else { |
| 866 |
|
base[l][m][pre] = 31000.; |
| 867 |
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
| 868 |
|
dexyc[l][m][e] = dexy[l][m][e]; |
| 869 |
|
}; |
| 870 |
}; |
}; |
| 871 |
} else { |
} else { |
| 872 |
|
process += 2; |
| 873 |
base[l][m][pre] = 31000.; |
base[l][m][pre] = 31000.; |
| 874 |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
| 875 |
dexyc[l][m][e] = dexy[l][m][e]; |
dexyc[l][m][e] = dexy[l][m][e]; |
| 876 |
}; |
}; |
| 877 |
}; |
}; |
|
} else { |
|
|
base[l][m][pre] = 31000.; |
|
| 878 |
}; |
}; |
| 879 |
} |
} |
| 880 |
|
|
| 1015 |
Int_t nstt[2]; |
Int_t nstt[2]; |
| 1016 |
Float_t rqp[2]; |
Float_t rqp[2]; |
| 1017 |
for (Int_t i = 0; i < 3; i++){ |
for (Int_t i = 0; i < 3; i++){ |
| 1018 |
nstt[0] = 0; |
// nstt[0] = 0; // BUG |
| 1019 |
nstt[1] = 0; |
// nstt[1] = 0; // BUG |
| 1020 |
|
nstt[0] = 1000; |
| 1021 |
|
nstt[1] = 1000; |
| 1022 |
rqp[0] = 0.; |
rqp[0] = 0.; |
| 1023 |
rqp[1] = 0.; |
rqp[1] = 0.; |
| 1024 |
for (Int_t j = 0; j < 2; j++){ |
for (Int_t j = 0; j < 2; j++){ |
| 1047 |
// |
// |
| 1048 |
// 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 |
// 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 |
| 1049 |
// |
// |
| 1050 |
if ( nstt[0] < 4 && nstt[1] >= 4 ) base[l][m][pre-1] = 31000.; |
if ( nstt[0] < 4 && nstt[1] >= 4 && nstt[0] != 1000 && nstt[1] != 1000 ) base[l][m][pre-1] = 31000.; |
| 1051 |
if ( nstt[0] >= 4 && nstt[1] < 4 ) base[l][m][pre] = 31000.; |
if ( nstt[0] >= 4 && nstt[1] < 4 && nstt[0] != 1000 && nstt[1] != 1000 ) base[l][m][pre] = 31000.; |
| 1052 |
|
// if ( nstt[0] < 4 && nstt[1] >= 4 ) base[l][m][pre-1] = 31000.; // BUG |
| 1053 |
|
// if ( nstt[0] >= 4 && nstt[1] < 4 ) base[l][m][pre] = 31000.; // BUG |
| 1054 |
// // |
// // |
| 1055 |
// // 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 |
// // 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 |
| 1056 |
// // |
// // |
| 1095 |
ck[pre] = 3; |
ck[pre] = 3; |
| 1096 |
}; |
}; |
| 1097 |
}; |
}; |
| 1098 |
done = 1; |
// done = 1; |
| 1099 |
}; |
}; |
| 1100 |
|
done = 1; |
| 1101 |
}; |
}; |
| 1102 |
// |
// |
| 1103 |
// CALIBRATION ALGORITHM |
// CALIBRATION ALGORITHM |
| 1166 |
// }; |
// }; |
| 1167 |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
| 1168 |
if ( !ctground ){ |
if ( !ctground ){ |
| 1169 |
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * ctprecor[l][m][ip[i]]; |
clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre] - qpre[ip[i]] * ctprecor[l][m][ip[i]]; |
| 1170 |
} else { |
} else { |
| 1171 |
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; |
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; |
| 1172 |
}; |
}; |
| 1174 |
}; |
}; |
| 1175 |
if (ck[pre] == 2 && ck[pre-1] == 2){ |
if (ck[pre] == 2 && ck[pre-1] == 2){ |
| 1176 |
for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ |
for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ |
| 1177 |
ipre = j/16 + 1; |
// ipre = j/16 + 1; |
| 1178 |
|
ipre = j/16 ; |
| 1179 |
if ( !ctground ){ |
if ( !ctground ){ |
| 1180 |
clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre]; |
clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre]; |
| 1181 |
} else { |
} else { |