--- DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2008/06/19 20:05:44 1.22 +++ DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2014/10/14 14:07:10 1.37 @@ -56,6 +56,31 @@ clevel1 = &clevel1_; clevel2 = &clevel2_; // +// extern struct FlEventi eventi_; +// extern struct FlGruppo gruppo_; +// extern struct FlGruppo2 gruppo2_; +// extern struct FlGruppo4 gruppo4_; +// extern struct FlTaglioen taglioen_; +// extern struct FlAngolo angolo_; +// extern struct FlWhere where_; +// extern struct FlGeneral general_; +// extern struct FlCh ch_; +// extern struct FlCalofit calofit_; +// extern struct FlPawcd pawcd_; +// extern struct FlQuestd questd_; +// eventi = &eventi_; +// gruppo = &gruppo_; +// gruppo2 = &gruppo2_; +// gruppo4 = &gruppo4_; +// taglioen = &taglioen_; +// angolo = &angolo_; +// where = &where_; +// general = &general_; +// ch = &ch_; +// calofit = &calofit_; +// pawcd = &pawcd_; +// questd = &questd_; + // trkseqno = 0; ClearStructs(); // @@ -75,6 +100,7 @@ calopar4 = true; calopar5 = true; crosst = true; + mask18 = false; ftcalopar1 = 0; ttcalopar1 = 0; ftcalopar2 = 0; @@ -132,14 +158,16 @@ this->InitDo(dbc,hs,sgnl,l0tree,isdeb,isverb); dbc->Close(); delete dbc; + dbc = 0; } void CaloLevel0::InitDo(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; - dbc->Query(myquery.str().c_str()); + myquery << "SET time_zone='+0:00';"; + delete dbc->Query(myquery.str().c_str()); + delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); // debug = isdeb; verbose = isverb; @@ -245,12 +273,14 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; - dbc->Query(myquery.str().c_str()); + myquery << "SET time_zone='+0:00';"; + delete dbc->Query(myquery.str().c_str()); + delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); // Int_t sig = this->ChkParamDo(dbc,runheader,mechal); dbc->Close(); delete dbc; + dbc = 0; return(sig); } @@ -570,12 +600,14 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; - dbc->Query(myquery.str().c_str()); + myquery << "SET time_zone='+0:00';"; + delete dbc->Query(myquery.str().c_str()); + delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); // Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,usetable); dbc->Close(); delete dbc; + dbc = 0; // return(sig); // @@ -589,12 +621,14 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; - dbc->Query(myquery.str().c_str()); + myquery << "SET time_zone='+0:00';"; + delete dbc->Query(myquery.str().c_str()); + delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); // Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,true); dbc->Close(); delete dbc; + dbc = 0; // return(sig); // @@ -715,7 +749,7 @@ // if ( !ncalibs ) return(-110); // - calo->GetEntry(calibno); + if ( calo->GetEntry(calibno) <= 0) throw -36; if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); // // retrieve calibration table @@ -796,7 +830,7 @@ // if ( !ncalibs ) return(-110); // - calo1->GetEntry(calibno); + if ( calo1->GetEntry(calibno) <= 0 ) throw -36; if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); // // retrieve calibration table @@ -1134,17 +1168,25 @@ if ( strip6s < 4 && base[l][m][pre] > (-0.015*qp+sbase[l][m][pre]) && sbase[l][m][pre] > 0. ){ 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); base[l][m][pre] = 31000.; + nst = 0; // 9RED BUG + qp = 0.; // 9RED BUG for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ dexyc[l][m][e] = dexy[l][m][e]; }; }; } else { + if ( debug ) printf(" reset baseline here if ! ( (strip6s >=2 && process == 2) || (strip6s >= 9 and process > 2) ) \n"); base[l][m][pre] = 31000.; + nst = 0; // 9RED BUG + qp = 0.; // 9RED BUG for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ dexyc[l][m][e] = dexy[l][m][e]; }; }; } else { + if ( debug ) printf(" reset baseline here if no minimum find\n"); + nst = 0; // 9RED BUG + qp = 0.; // 9RED BUG process += 2; base[l][m][pre] = 31000.; for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ @@ -1152,19 +1194,20 @@ }; }; }; + 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); } Int_t CaloLevel0::Calibrate(Int_t ei){ // // get entry ei // - l0calo->GetEntry(ei); + if ( l0calo->GetEntry(ei) <= 0 ) throw -36; // // if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3. // clevel2->nsatstrip = 0.; Int_t val = 0; - Int_t del = 1100; + Int_t del = 1000; for (Int_t sec = 0; sec < 4; sec++){ for (Int_t dsec = 0; dsec < 7; dsec++){ val = (Int_t)de->calselftrig[sec][dsec]; @@ -1173,26 +1216,26 @@ }; }; val = 0; - del = 1100; - if ( clevel2->trigty != 2. ){ - Bool_t ck = false; + del = 1000; + if ( clevel2->trigty < 2. ){ + // Bool_t ck = false; for (Int_t sec = 0; sec < 4; sec++){ val = (Int_t)de->calselftrig[sec][6]; del = delay(val); - if ( del < 1100 ){ + if ( del < 1000 ){ clevel2->wartrig = 0.; clevel2->trigty = 3.; - ck = true; + // ck = true; break; }; }; - if ( !ck ) clevel2->wartrig = 100.; + // if ( !ck ) clevel2->wartrig = 100.; } else { Bool_t ck = false; for (Int_t sec = 0; sec < 4; sec++){ val = (Int_t)de->calselftrig[sec][6]; del = delay(val); - if ( del < 1100 ){ + if ( del < 1000 ){ clevel2->wartrig = 0.; ck = true; }; @@ -1203,8 +1246,8 @@ Int_t se = 5; Int_t done = 0; Int_t pre = -1; - Bool_t isCOMP = false; - Bool_t isFULL = false; + // Bool_t isCOMP = false; + // Bool_t isFULL = false; Bool_t isRAW = false; Float_t ener; Int_t doneb = 0; @@ -1227,6 +1270,8 @@ // Float_t ener0 = 0.; Float_t cbase0 = 0.; + Float_t totbase = 0.; + Float_t totped = 0.; Bool_t pproblem = false; Bool_t negbase = false; // @@ -1251,11 +1296,11 @@ // // determine what kind of event we are going to analyze // - isCOMP = false; - isFULL = false; + // isCOMP = false; + // isFULL = false; isRAW = false; - if ( de->stwerr[se] & (1 << 16) ) isCOMP = true; - if ( de->stwerr[se] & (1 << 17) ) isFULL = true; + // if ( de->stwerr[se] & (1 << 16) ) isCOMP = true; + // if ( de->stwerr[se] & (1 << 17) ) isFULL = true; if ( de->stwerr[se] & (1 << 3) ) isRAW = true; if ( !chdone[se] ){ // @@ -1268,7 +1313,7 @@ }; clevel2->perr[se] = 0; if ( de->perror[se] != 0 ){ - clevel2->perr[se] = 1; + clevel2->perr[se] = (Int_t)de->perror[se]; pe++; }; clevel2->swerr[se] = 0; @@ -1341,6 +1386,8 @@ // pre = -1; ener0 = 0.; + totbase = 0.; + totped = 0.; for (Int_t i = 0 ; i < 3 ; i++){ ip[i] = 0; for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ @@ -1358,6 +1405,7 @@ // no suitable new baseline, use old ones! // if ( !done ){ + 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]); if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){ ck[l][m][pre] = 1; if (pre%2 == 0) { @@ -1408,6 +1456,8 @@ ener = dexyc[l][m][n]; ener0 += ener; clevel1->estrip[n][m][l] = 0.; + totbase += de->base[l][m][pre]/96.; + totped += fabs(calped[l][m][n]); if ( de->base[l][m][pre] < 0 ) negbase = true; if ( base0>0 && base0 < 30000. ){ // @@ -1422,6 +1472,7 @@ // // 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) // + 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]); if ( clevel1->estrip[n][m][l] > 0. ) qpre[l][m][pre] += clevel1->estrip[n][m][l]; // // @@ -1431,9 +1482,10 @@ }; // // check if there were problems with 5.7 or glitches in the power supply - // - if ( ((ener0 == 0. && cbase0 == 0.) || negbase ) && !pproblem && clevel2->perr[se] == 0){ - 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); + // + // 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.] + 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.] + 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); pproblem = true; pe++; }; @@ -1465,7 +1517,7 @@ // // Cross-talk corrections // - if ( crosst ){ + if ( crosst ){ // // energy on silicon ladders // @@ -1482,7 +1534,9 @@ if ( noselfct ){ for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ ipre = j/16 ; + 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]); if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] -= clevel1->estrip[j][m][l] * ctprecor[l][m][ipre]; + 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]); }; }; // @@ -1504,12 +1558,14 @@ // if ( debug ) printf(" CK1 Limit for while: 0.07 \n"); for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ + 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]); if ( !ctground ){ if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * ctprecor[l][m][ipp]; } else { if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += - qpre[l][m][ipp] * 0.00478; }; if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; + 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]); }; qpre[l][m][ipre] = nqpre; nqpre = 0.; @@ -1520,6 +1576,7 @@ while ( it < 10 && deltaqpre > 0.07 ){ nqpre = 0.; for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ + 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]); if ( !ctground ){ 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]); if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * ctprecor[l][m][ipre]; @@ -1527,6 +1584,7 @@ if ( clevel1->estrip[j][m][l] != 0. ) clevel1->estrip[j][m][l] += deltaqpre * 0.00478; }; if ( clevel1->estrip[j][m][l] > 0. ) nqpre += clevel1->estrip[j][m][l] ; + 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]); }; if ( ctground ) it = 100; it++; @@ -1633,6 +1691,7 @@ nqpre[0] = 0.; nqpre[1] = 0.; for (Int_t j = ladder*32 ; j < (ladder+1)*32 ; j++){ + 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]); ipre = 0; if ( j > (ladder*32)+15 ) ipre = 1; jpre = j/16 ; @@ -1648,13 +1707,22 @@ }; if ( clevel1->estrip[j][m][l] > 0. ) nqsi += clevel1->estrip[j][m][l] ; if ( clevel1->estrip[j][m][l] > 0. ) nqpre[ipre] += clevel1->estrip[j][m][l] ; + 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]); }; if ( ctground ) it = 100; deltaqsi = nqsi-snqsi; - snqsi = nqsi; - it++; deltaqpre[0] = nqpre[0] - qpre[l][m][pre-1]; deltaqpre[1] = nqpre[1] - qpre[l][m][pre]; + // + // Check for divergence and stop if it happens! [9RED bug noticed with plane 18X] + // + if ( deltaqpre[0] > qpre[l][m][pre-1] || deltaqpre[1] > qpre[l][m][pre] || deltaqsi >snqsi ){ + 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); + it = 1000; + }; + // + snqsi = nqsi; + it++; if ( debug ) printf(" BEFORE: qpre 0 %f qpre 1 %f \n",qpre[l][m][pre-1],qpre[l][m][pre]); qpre[l][m][pre-1] = nqpre[0]; qpre[l][m][pre] = nqpre[1]; @@ -1690,7 +1758,7 @@ jjj++; j4++; if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; - if ( crosst ){ + if ( crosst ){ // // "Real" crosstalk effect on the neighbour strips respect to the one which have seen the energy deposit // @@ -1720,20 +1788,32 @@ // CALOLEVEL1 CODING AND FILLING // // - // NOTICE: THE FOLLOWING LINE EXCLUDE ALL STRIPS FOR WHICH THE RMS*4 IS GREATER THAN 26 !!! <=============== IMPORTANT! =================> + // 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 // - 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] ){ + 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 ) ){ clevel1->estrip[j4][m][l] = 0.; }; // + if ( debug ) printf(" STRIP: view %i plane %i strip %i energy: %f \n",l,m,j4,clevel1->estrip[j4][m][l]); + // // code and save the energy for each strip in svstrip // if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ // Float_t savel1 = clevel1->estrip[j4][m][l]; + // + if ( m == 18 && l == 0 ){ + if ( debug ) printf(" Resetting plane 18X for variable calculation: view %i plane %i strip %i \n",l,m,j4); + clevel1->estrip[j4][m][l] = 0.; // SAVE STRIPS VALUE FOR PLANE 18 X but DO NOT USE IT FOR VARIABLE CALCULATION + }; + if ( debug ) printf(" HIT STRIP: view %i plane %i strip %i energy: %f \n",l,m,j4,clevel1->estrip[j4][m][l]); // if ( dexyc[l][m][j4] == 32767. ){ - if ( dexyc[l][m][j4] > 32000. ){ - savel1 += 5000.; + if ( dexyc[l][m][j4] > 32000. || savel1 > 5000.){ // CaloLevel1 bug with plane 18X [9RED 14/04/2010] + if ( savel1 > 5000 ){ + if ( debug ) printf(" Absurd plane 18X energy... resetting value to 1100 MIP \n"); + savel1 = 1100.; // CaloLevel1 bug with plane 18x [9RED 14/04/2010] + }; + savel1 += 5000.; clevel2->nsatstrip += 1.; }; // @@ -1776,6 +1856,7 @@ } else { svstrip[istrip] = -(fbi*1000000000 + plo*10000000 + j4*100000 + cle); }; + if ( debug ) printf(" svstrip[%i] = %i fbi %i plo %i j4 %i cle %i \n",istrip,svstrip[istrip],fbi,plo,j4,cle); // istrip++; }; @@ -1865,6 +1946,47 @@ ClearTrkVar(); } +void CaloLevel0::FillTrkVar(TClonesArray *tcl, Int_t nutrk){ + // + CaloTrkVar *t_ca = new CaloTrkVar(); + // + t_ca->trkseqno = trkseqno; + t_ca->ncore = (Int_t)clevel2->ncore; + t_ca->qcore = clevel2->qcore; + t_ca->noint = (Int_t)clevel2->noint; + t_ca->ncyl = (Int_t)clevel2->ncyl; + t_ca->qcyl = clevel2->qcyl; + t_ca->qtrack = clevel2->qtrack; + t_ca->qtrackx = clevel2->qtrackx; + t_ca->qtracky = clevel2->qtracky; + t_ca->dxtrack = clevel2->dxtrack; + t_ca->dytrack = clevel2->dytrack; + t_ca->qlast = clevel2->qlast; + t_ca->nlast = (Int_t)clevel2->nlast; + t_ca->qpre = clevel2->qpre; + t_ca->npre = (Int_t)clevel2->npre; + t_ca->qpresh = clevel2->qpresh; + t_ca->npresh = (Int_t)clevel2->npresh; + t_ca->qtr = clevel2->qtr; + t_ca->ntr = (Int_t)clevel2->ntr; + t_ca->planetot = (Int_t)clevel2->planetot; + t_ca->qmean = clevel2->qmean; + t_ca->dX0l = clevel2->dX0l; + t_ca->qlow = clevel2->qlow; + t_ca->nlow = (Int_t)clevel2->nlow; + // + memcpy(t_ca->tibar,clevel2->tibar,sizeof(clevel2->tibar)); + memcpy(t_ca->tbar,clevel2->tbar,sizeof(clevel2->tbar)); + // + // + TClonesArray &t = *tcl; + new(t[nutrk]) CaloTrkVar(*t_ca); + // + delete t_ca; + // + ClearTrkVar(); +} + void CaloLevel0::GetCommonVar(){ calol2cm(); } @@ -1872,13 +1994,13 @@ void CaloLevel0::FillCommonVar(CaloLevel1 *c1, CaloLevel2 *ca){ // ca->good = clevel2->good; - if ( clevel2->trigty == 2. ){ - ca->selftrigger = 1; - } else { - ca->selftrigger = 0; - }; +// if ( clevel2->trigty == 2. ){ +// ca->selftrigger = 1; +// } else { +// ca->selftrigger = 0; +// }; // - ca->selftrigger += (Int_t)clevel2->wartrig; + ca->selftrigger = (Int_t)clevel2->trigty + (Int_t)clevel2->wartrig; // memcpy(ca->perr,clevel2->perr,sizeof(clevel2->perr)); memcpy(ca->swerr,clevel2->swerr,sizeof(clevel2->swerr)); @@ -1915,6 +2037,13 @@ }; // } +void CaloLevel0::FillCommonVar(CaloLevel1 *c1){ + if ( c1 ){ + c1->istrip = istrip; + c1->estrip = TArrayI(istrip,svstrip); + }; + // +} void CaloLevel0::ClearStructs(){ ClearTrkVar(); @@ -2064,8 +2193,9 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; - dbc->Query(myquery.str().c_str()); + myquery << "SET time_zone='+0:00';"; + delete dbc->Query(myquery.str().c_str()); + delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); Int_t sgnl = 0; // GL_CALO_CALIB *glcalo = new GL_CALO_CALIB(); @@ -2155,7 +2285,7 @@ // if ( !ncalibs ) return(-110); // - calo->GetEntry(calibno[s]); + if ( calo->GetEntry(calibno[s]) <= 0 ) throw -36; // if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { for ( Int_t d=0 ; d<11 ;d++ ){