--- DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2008/02/07 20:02:09 1.16 +++ DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2008/02/08 11:55:32 1.17 @@ -729,63 +729,92 @@ } void CaloLevel0::FindBaseCompress(Int_t l, Int_t m, Int_t pre){ + Int_t n = 0; + Float_t q = 0; + this->FindBaseCompress(l,m,pre,n,q); +} + +void CaloLevel0::FindBaseCompress(Int_t l, Int_t m, Int_t pre, Int_t &nst, Float_t &qp){ for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ dexy[l][m][e] = dexyc[l][m][e]; }; - this->FindBaseRaw(l,m,pre); + this->FindBaseRaw(l,m,pre,nst,qp); } void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre){ - Float_t minstrip = 100000.; - Float_t rms = 0.; - base[l][m][pre] = 0.; + Int_t n = 0; + Float_t q = 0; + this->FindBaseRaw(l,m,pre,n,q); +} + +void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre, Int_t &nst, Float_t &qp){ + // + Float_t minstrip = 100000.; + Float_t rms = 0.; + base[l][m][pre] = 0.; + qp = 0.; + // + for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ + 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.) { + minstrip = dexy[l][m][e]-calped[l][m][e]; + rms = calthr[l][m][pre]; + }; + qp += (dexy[l][m][e]-calped[l][m][e]-sbase[l][m][e]); + }; + // + if ( debug && l==1 ){ + 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 ( minstrip != 100000. ) { + Float_t strip6s = 0.; for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ - 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.) { - minstrip = dexy[l][m][e]-calped[l][m][e]; - rms = calthr[l][m][pre]; - }; + if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) { + strip6s += 1.; + 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]; + }; }; + // + nst = (Int_t)strip6s; + // if ( debug && l==1 ){ - printf("\n BASELINE CALCULATION for view %i pl %i pre %i: \n => minstrip %f rms %f \n",l,m,pre,minstrip,rms); + printf(" strip6s %f \n",strip6s); }; - if ( minstrip != 100000. ) { - Float_t strip6s = 0.; - for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ - if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) { - strip6s += 1.; - 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]; - }; - }; - if ( debug && l==1 ){ - printf(" strip6s %f \n",strip6s); - }; - // if ( strip6s >= 9. ){ - if ( strip6s >= 2. ){ - Double_t arro = base[l][m][pre]/strip6s; - Float_t deci = 1000.*((float)arro - float(int(arro))); - if ( deci < 500. ) { - arro = double(int(arro)); - } else { - arro = 1. + double(int(arro)); - }; - base[l][m][pre] = arro; - } else { - base[l][m][pre] = 31000.; - for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ - dexyc[l][m][e] = dexy[l][m][e]; - }; - }; + // if ( strip6s >= 9. ){ + if ( strip6s >= 2. ){ + Double_t arro = base[l][m][pre]/strip6s; + Float_t deci = 1000.*((float)arro - float(int(arro))); + if ( deci < 500. ) { + arro = double(int(arro)); + } else { + arro = 1. + double(int(arro)); + }; + 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 + // + 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 < 4 && base[l][m][pre] > 1.02*sbase[l][m][pre] && sbase[l][m][pre] > 0. ){ + 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); + base[l][m][pre] = 31000.; + }; } else { - base[l][m][pre] = 31000.; + base[l][m][pre] = 31000.; + for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ + dexyc[l][m][e] = dexy[l][m][e]; + }; }; + } else { + base[l][m][pre] = 31000.; + }; } Int_t CaloLevel0::Calibrate(Int_t ei){ @@ -921,7 +950,13 @@ // pre = -1; cbase0 = 0.; + Int_t nstt[2]; + Float_t rqp[2]; for (Int_t i = 0; i < 3; i++){ + nstt[0] = 0; + nstt[1] = 0; + rqp[0] = 0.; + rqp[1] = 0.; for (Int_t j = 0; j < 2; j++){ pre = j + i*2; // @@ -931,18 +966,29 @@ if ( de->base[l][m][pre] != 0. && de->base[l][m][pre]<31000. ) { base[l][m][pre] = de->base[l][m][pre] ; } else { - FindBaseCompress(l,m,pre); + FindBaseCompress(l,m,pre,nstt[j],rqp[j]); }; cbase0 += base[l][m][pre]; } else { // - // if it is a raw event and we haven't checked - // yet, calculate the baseline. + // if it is a raw event calculate the baseline. // - FindBaseRaw(l,m,pre); + FindBaseRaw(l,m,pre,nstt[j],rqp[j]); cbase0 += base[l][m][pre]; }; }; + // + // 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 ( nstt[0] < 4 && nstt[1] >= 4 ) base[l][m][pre-1] = 31000.; + if ( nstt[0] >= 4 && nstt[1] < 4 ) base[l][m][pre] = 31000.; +// // +// // 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 ( nstt[0] < 4 && nstt[1] < 4 ){ +// if ( rqp[0] >= rqp[1] ) base[l][m][pre-1] = 31000.; +// if ( rqp[0] < rqp[1] ) base[l][m][pre] = 31000.; +// }; }; // // run over strips