--- DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2010/01/29 05:49:24 1.30 +++ DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2014/10/10 13:35:05 1.36 @@ -158,13 +158,14 @@ 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'"; + myquery << "SET time_zone='+0:00'; SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"; dbc->Query(myquery.str().c_str()); // debug = isdeb; @@ -271,12 +272,13 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; + myquery << "SET time_zone='+0:00'; SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"; dbc->Query(myquery.str().c_str()); // Int_t sig = this->ChkParamDo(dbc,runheader,mechal); dbc->Close(); delete dbc; + dbc = 0; return(sig); } @@ -596,12 +598,13 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; + myquery << "SET time_zone='+0:00'; SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"; dbc->Query(myquery.str().c_str()); // Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,usetable); dbc->Close(); delete dbc; + dbc = 0; // return(sig); // @@ -615,12 +618,13 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; + myquery << "SET time_zone='+0:00'; SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"; dbc->Query(myquery.str().c_str()); // Int_t sig = CalcCrossTalkCorrDo(dbc,runheader,true); dbc->Close(); delete dbc; + dbc = 0; // return(sig); // @@ -1160,17 +1164,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++){ @@ -1178,6 +1190,7 @@ }; }; }; + 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){ @@ -1201,14 +1214,14 @@ val = 0; del = 1000; if ( clevel2->trigty < 2. ){ - Bool_t ck = false; + // Bool_t ck = false; for (Int_t sec = 0; sec < 4; sec++){ val = (Int_t)de->calselftrig[sec][6]; del = delay(val); if ( del < 1000 ){ clevel2->wartrig = 0.; clevel2->trigty = 3.; - ck = true; + // ck = true; break; }; }; @@ -1229,8 +1242,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; @@ -1279,11 +1292,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] ){ // @@ -1388,6 +1401,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) { @@ -1454,6 +1468,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]; // // @@ -1498,7 +1513,7 @@ // // Cross-talk corrections // - if ( crosst ){ + if ( crosst ){ // // energy on silicon ladders // @@ -1515,7 +1530,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]); }; }; // @@ -1537,12 +1554,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.; @@ -1553,6 +1572,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]; @@ -1560,6 +1580,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++; @@ -1666,6 +1687,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 ; @@ -1681,13 +1703,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]; @@ -1723,7 +1754,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 // @@ -1773,8 +1804,12 @@ }; 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.; }; // @@ -1817,6 +1852,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++; }; @@ -1906,6 +1942,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(); } @@ -1956,6 +2033,13 @@ }; // } +void CaloLevel0::FillCommonVar(CaloLevel1 *c1){ + if ( c1 ){ + c1->istrip = istrip; + c1->estrip = TArrayI(istrip,svstrip); + }; + // +} void CaloLevel0::ClearStructs(){ ClearTrkVar(); @@ -2105,7 +2189,7 @@ if ( !dbc->IsConnected() ) throw -116; stringstream myquery; myquery.str(""); - myquery << "SET time_zone='+0:00'"; + myquery << "SET time_zone='+0:00'; SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"; dbc->Query(myquery.str().c_str()); Int_t sgnl = 0; //