--- DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2006/09/07 09:47:07 1.5 +++ DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2007/01/11 09:32:54 1.9 @@ -66,10 +66,13 @@ memset(sbase, 0, 2*22*6*sizeof(Float_t)); calopar1 = true; calopar2 = true; + calopar3 = true; ftcalopar1 = 0; ttcalopar1 = 0; ftcalopar2 = 0; ttcalopar2 = 0; + ftcalopar3 = 0; + ttcalopar3 = 0; } /** @@ -161,6 +164,7 @@ Int_t sgnl = 0; for ( Int_t s = 0; s < 4; s++){ if ( atime > totime[s] ){ + if ( !dbc->IsConnected() ) throw -116; sgnl = Update(dbc,atime,s); if ( sgnl < 0 ) return(sgnl); }; @@ -170,9 +174,11 @@ Int_t CaloProcessing::ChkParam(TSQLServer *dbc, UInt_t runheader){ stringstream calfile; + stringstream bmfile; stringstream aligfile; Int_t error = 0; FILE *f = 0; + ifstream badfile; GL_PARAM *glparam = new GL_PARAM(); // if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){ @@ -225,7 +231,7 @@ ftcalopar2 = glparam->FROM_TIME; ttcalopar2 = glparam->TO_TIME; // - if ( verbose ) printf("\n Using alignment file: \n %s \n\n",aligfile.str().c_str()); + if ( verbose ) printf("\n Using alignment file: \n %s \n",aligfile.str().c_str()); f = fopen(aligfile.str().c_str(),"rb"); if ( !f ){ if ( verbose ) printf(" CALORIMETER - ERROR: no alignement file!\n"); @@ -244,6 +250,55 @@ fclose(f); }; // + // Load offline bad strip mask + // + if ( calopar3 || ( ttcalopar3 != 0 && ttcalopar3 < runheader ) ){ + calopar3 = false; + // + // determine where I can find calorimeter alignment file + // + // + error = 0; + error = glparam->Query_GL_PARAM(runheader,103,dbc); + if ( error < 0 ) return(error); + // + bmfile.str(""); + bmfile << glparam->PATH.Data() << "/"; + bmfile << glparam->NAME.Data(); + ftcalopar3 = glparam->FROM_TIME; + ttcalopar3 = glparam->TO_TIME; + // + if ( verbose ) printf("\n Using bad strip offline mask file: \n %s \n\n",bmfile.str().c_str()); + badfile.open(bmfile.str().c_str()); + if ( !badfile ){ + if ( verbose ) printf(" CALORIMETER - ERROR: no bad strip offline mask file!\n"); + return(-115); + }; + // + Bool_t isdone = false; + Int_t bad = 0; + Int_t view = 1; + Int_t strip = 0; + Int_t plane = 21; + while ( !isdone ) { + badfile >> bad; + obadmask[view][plane][strip] = bad; + if ( debug && bad ) printf(" SETTING view %i plane %i strip %i BAD = %i \n",view,plane,strip,bad); + strip++; + if ( strip > 95 ){ + strip = 0; + plane--; + if ( plane < 0 ){ + plane = 21; + view--; + }; + if ( view < 0 ) isdone = true; + }; + }; + // + badfile.close(); + }; + // delete glparam; // return(0); @@ -256,7 +311,7 @@ Float_t rms = 0.; base[l][m][pre] = 0.; for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ - if ( calgood[l][m][e] == 0. && dexy[l][m][e]-calped[l][m][e] < minstrip && dexy[l][m][e] > 0.) { + 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]; }; @@ -339,6 +394,15 @@ Int_t chdone[4] = {0,0,0,0}; Int_t pe = 0; // + Float_t ener0 = 0.; + Float_t cbase0 = 0.; + Bool_t pproblem = false; + // + Float_t tim = 0.; + Int_t plo = 0; + Int_t fbi = 0; + Int_t cle = 0; + // // run over views and planes // for (Int_t l = 0; l < 2; l++){ @@ -395,6 +459,7 @@ // run over preamplifiers // pre = -1; + cbase0 = 0.; for (Int_t i = 0; i < 3; i++){ for (Int_t j = 0; j < 2; j++){ pre = j + i*2; @@ -403,12 +468,14 @@ // if ( !isRAW ) { base[l][m][pre] = de->base[l][m][pre] ; + cbase0 += base[l][m][pre]; } else { // // if it is a raw event and we haven't checked // yet, calculate the baseline. // FindBaseRaw(l,m,pre); + cbase0 += base[l][m][pre]; }; }; }; @@ -416,6 +483,7 @@ // run over strips // pre = -1; + ener0 = 0.; for (Int_t i = 0 ; i < 3 ; i++){ ip[i] = 0; for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ @@ -476,6 +544,7 @@ doneb = 1; }; ener = dexyc[l][m][n]; + ener0 += ener; clevel1->estrip[n][m][l] = 0.; if ( base0>0 && base0 < 30000. ){ if ( !donec && (base0 - base1 + base2) != 0. ){ @@ -507,7 +576,13 @@ clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; }; }; - }; + }; + // + if ( ener0 == 0. && cbase0 == 0. && !pproblem ){ + if ( verbose ) printf(" Calorimeter power problems! event marked as bad \n"); + pproblem = true; + pe++; + }; // Int_t j4 = -4; Int_t jjj = -3; @@ -527,20 +602,60 @@ }; if ( j4 >= 0 && j4 < 96 ){ // - // NOTICE: THE FOLLOWING LINE EXCLUDE ALL STRIPS FOR WHICH THE RMS*4 IS GREATER THAN 26 !!! <===V============ IMPORTANT! =================> + // NOTICE: THE FOLLOWING LINE EXCLUDE ALL STRIPS FOR WHICH THE RMS*4 IS GREATER THAN 26 !!! <=============== IMPORTANT! =================> // - if ( clevel1->estrip[j4][m][l]!=0. && ( clevel1->estrip[j4][m][l] < clevel1->emin || calrms[l][m][j4] > 26 )){ + if ( obadmask[l][m][j4] == 1 || clevel1->estrip[j4][m][l] <= clevel1->emin || calrms[l][m][j4] > 26 ){ clevel1->estrip[j4][m][l] = 0.; }; + // + // code and save the energy for each strip in svstrip + // if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ + // + tim = 100000.; + plo = m; + fbi = 0; + if ( clevel1->estrip[j4][m][l] > 0.99995 ){ + tim = 10000.; + plo = m; + fbi = 1; + }; + if ( clevel1->estrip[j4][m][l] > 9.9995 ){ + tim = 1000.; + plo = 22 + m; + fbi = 1; + }; + if ( clevel1->estrip[j4][m][l] > 99.995 ){ + tim = 100.; + plo = 22 + m; + fbi = 0; + }; + if ( clevel1->estrip[j4][m][l] > 999.95 ){ + tim = 10.; + plo = 44 + m; + fbi = 0; + }; + if ( clevel1->estrip[j4][m][l] > 9999.5 ){ + tim = 1.; + plo = 66 + m; + fbi = 0; + }; + // + cle = (Int_t)lroundf(tim*clevel1->estrip[j4][m][l]); + // if ( l == 0 ){ // // +-PPSSmmmm.mmmm // - svstrip[istrip] = ((Float_t)m)*1000000. + ((Float_t)j4)*10000. + clevel1->estrip[j4][m][l]; + svstrip[istrip] = fbi*1000000000 + plo*10000000 + j4*100000 + cle; } else { - svstrip[istrip] = -(((Float_t)m)*1000000. + ((Float_t)j4)*10000. + clevel1->estrip[j4][m][l]); + svstrip[istrip] = -(fbi*1000000000 + plo*10000000 + j4*100000 + cle); }; + // + // if ( ei >= -770 ) printf(" j %i l %i m %i estrip %f \n",j4,l,m,clevel1->estrip[j4][m][l]); + // if ( ei >= -770 ) printf(" num lim %i fbi %i tim %f plo %i cle %i \n",numeric_limits::max(),fbi,tim,plo,cle); + // if ( ei >= -770 ) printf(" svstrip %i \n",svstrip[istrip]); + // istrip++; }; }; @@ -611,6 +726,7 @@ memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit)); }; // + if(!(ca->CaloTrk))ca->CaloTrk = new TClonesArray("CaloTrkVar",1); //ELENA TClonesArray &t = *ca->CaloTrk; new(t[nutrk]) CaloTrkVar(*t_ca); // @@ -623,7 +739,7 @@ calol2cm(); } -void CaloProcessing::FillCommonVar(CaloLevel2 *ca){ +void CaloProcessing::FillCommonVar(CaloLevel1 *c1, CaloLevel2 *ca){ // ca->good = clevel2->good; if ( clevel2->trigty == 2. ){ @@ -634,7 +750,6 @@ memcpy(ca->perr,clevel2->perr,sizeof(clevel2->perr)); memcpy(ca->swerr,clevel2->swerr,sizeof(clevel2->swerr)); memcpy(ca->crc,clevel2->crc,sizeof(clevel2->crc)); - ca->estrip = TArrayF(0,svstrip); ca->nstrip = (Int_t)clevel2->nstrip; ca->qtot = clevel2->qtot; ca->impx = clevel2->impx; @@ -646,7 +761,6 @@ ca->qmax = clevel2->qmax; ca->elen = clevel2->elen; ca->selen = clevel2->selen; - ca->estrip = TArrayF(ca->nstrip,svstrip); memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq)); memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit)); @@ -654,6 +768,11 @@ memcpy(ca->cibar,clevel2->cibar,sizeof(clevel2->cibar)); memcpy(ca->cbar,clevel2->cbar,sizeof(clevel2->cbar)); // + if ( c1 ){ + c1->istrip = istrip; + c1->estrip = TArrayI(istrip,svstrip); + }; + // } void CaloProcessing::ClearStructs(){