--- DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2008/02/07 20:02:09 1.16 +++ DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2008/04/18 18:55:47 1.20 @@ -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){ @@ -843,9 +872,10 @@ Float_t ener; Int_t doneb = 0; Int_t donec = 0; - Int_t ck = 0; + Int_t ck[6] = {0,0,0,0,0,0}; Int_t ipre = 0; - Int_t ip[3] = {0}; + // Int_t ip[3] = {0}; + Int_t ip[3] = {0,0,0}; Float_t base0, base1, base2; base0 = 0.; base1 = 0.; @@ -921,28 +951,48 @@ // 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; // // baseline check and calculation // if ( !isRAW ){ + // + // if it is a compress event with fully transmitted pre try to calculate the baseline + // 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 @@ -953,11 +1003,11 @@ ip[i] = 0; for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ if (n%16 == 0) { - ck = 0; done = 0; doneb = 0; donec = 0; pre++; + ck[pre] = 0; qpre[pre] = 0.; }; // @@ -967,7 +1017,7 @@ // if ( !done ){ if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){ - ck = 1; + ck[pre] = 1; if (pre%2 == 0) { ip[i] = pre + 1; } else { @@ -975,9 +1025,9 @@ }; if ( (base[l][m][ip[i]] == 31000. || base[l][m][ip[i]] == 0. || !crosst ) ){ // - ck = 2; + ck[pre] = 2; if ( sbase[l][m][pre] == 31000. || sbase[l][m][pre] == 0. ) { - ck = 3; + ck[pre] = 3; }; }; done = 1; @@ -987,8 +1037,8 @@ // CALIBRATION ALGORITHM // if ( !doneb ){ - if ( debug ) printf(" ck is %i \n",ck); - switch (ck) { + if ( debug ) printf(" ck[pre] is %i \n",ck[pre]); + switch (ck[pre]) { case 0: base0 = base[l][m][pre]; base2 = calbase[l][m][pre]; @@ -1035,23 +1085,31 @@ }; }; if ( crosst ){ - if (ck == 1){ - if (ip[i]%2 == 0) { - ipre = ip[i] + 1; + if (ck[pre] == 1 || ck[pre-1] == 1){ + if (ck[pre] == 1){ + ipre = pre; + ip[i] = pre - 1; } else { - ipre = ip[i] - 1; + ipre = pre - 1; + ip[i] = pre; }; + // 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]; + clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre] - qpre[ip[i]] * ctprecor[l][m][ip[i]]; } else { clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; }; }; }; - if (ck == 2){ + if (ck[pre] == 2 && ck[pre-1] == 2){ for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ - ipre = j/16 + 1; + // ipre = j/16 + 1; + ipre = j/16 ; if ( !ctground ){ clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre]; } else {