--- DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2006/08/04 10:31:27 1.3 +++ DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2007/01/23 11:52:25 1.12 @@ -18,7 +18,6 @@ // YODA headers // #include -#include #include #include // @@ -67,16 +66,19 @@ memset(sbase, 0, 2*22*6*sizeof(Float_t)); calopar1 = true; calopar2 = true; - ftcalopar1 = 0ULL; - ttcalopar1 = 0ULL; - ftcalopar2 = 0ULL; - ttcalopar2 = 0ULL; + calopar3 = true; + ftcalopar1 = 0; + ttcalopar1 = 0; + ftcalopar2 = 0; + ttcalopar2 = 0; + ftcalopar3 = 0; + ttcalopar3 = 0; } /** * Initialize CaloProcessing object **/ -void CaloProcessing::ProcessingInit(TSQLServer *dbc, ULong64_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ +void CaloProcessing::ProcessingInit(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ // debug = isdeb; verbose = isverb; @@ -92,26 +94,31 @@ GL_CALO_CALIB *glcalo = new GL_CALO_CALIB(); // sgnl = 0; + UInt_t uptime = 0; // for (Int_t s = 0; s < 4; s++){ - idcalib[s] = 0ULL; - fromtime[s] = 0ULL; - totime[s] = 0ULL; + idcalib[s] = 0; + fromtime[s] = 0; + totime[s] = 0; calibno[s] = 0; ClearCalibVals(s); -// - sgnl = glcalo->Query_GL_CALO_CALIB(hs,s,dbc); + // + sgnl = glcalo->Query_GL_CALO_CALIB(hs,uptime,s,dbc); if ( sgnl < 0 ){ if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); return; }; -// - idcalib[s] = glcalo->ID_REG_CALIBCALPED; + // + idcalib[s] = glcalo->ID_ROOT_L0; fromtime[s] = glcalo->FROM_TIME; - totime[s] = glcalo->TO_TIME; - calibno[s] = glcalo->EV_REG_CALIBCALPED; -// - if ( totime[s] == 0ULL){ + if ( glcalo->TO_TIME < hs ){ // calibration is corrupted and we are using the one that preceed the good one + totime[s] = uptime; + } else { + totime[s] = glcalo->TO_TIME; + }; + calibno[s] = glcalo->EV_ROOT; + // + if ( totime[s] == 0 ){ if ( verbose ) printf(" CALORIMETER - WARNING: data with no associated calibration\n"); ClearCalibVals(s); sgnl = 100; @@ -124,23 +131,23 @@ if ( verbose ) printf("\n"); for (Int_t s = 0; s < 4; s++){ if ( verbose ) printf(" ** SECTION %i **\n",s); - if ( totime[s] > 0ULL ){ -// + if ( totime[s] > 0 ){ + // sgnl = glroot->Query_GL_ROOT(idcalib[s],dbc); if ( sgnl < 0 ){ if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); return; }; -// + // stringstream name; name.str(""); name << glroot->PATH.Data() << "/"; name << glroot->NAME.Data(); // fcalname[s] = (TString)name.str().c_str(); - if ( verbose ) printf(" - runheader at time %llu. From time %llu to time %llu \n use file %s \n calibration at entry %i \n\n",hs,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]); + if ( verbose ) printf(" - runheader at time %u. From time %u to time %u \n use file %s \n calibration at entry %i \n\n",hs,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]); } else { - if ( verbose ) printf(" - runheader at time %llu. NO CALIBRATION INCLUDE THE RUNHEADER! ",hs); + if ( verbose ) printf(" - runheader at time %u. NO CALIBRATION INCLUDE THE RUNHEADER! ",hs); }; sgnl = LoadCalib(s); if ( sgnl ) break; @@ -153,10 +160,11 @@ // } -Int_t CaloProcessing::ChkCalib(TSQLServer *dbc, ULong64_t atime){ +Int_t CaloProcessing::ChkCalib(TSQLServer *dbc, UInt_t atime){ 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); }; @@ -164,11 +172,13 @@ return(sgnl); } -Int_t CaloProcessing::ChkParam(TSQLServer *dbc, ULong64_t runheader){ +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 ) ){ @@ -179,7 +189,7 @@ if ( verbose ) printf(" Querying DB for calorimeter parameters files...\n"); // error = 0; - error = glparam->Query_GL_PARAM(runheader,"Calorimeter ADC to MIP",dbc); + error = glparam->Query_GL_PARAM(runheader,101,dbc); if ( error < 0 ) return(error); // calfile.str(""); @@ -212,7 +222,7 @@ // // error = 0; - error = glparam->Query_GL_PARAM(runheader,"Calorimeter alignement",dbc); + error = glparam->Query_GL_PARAM(runheader,102,dbc); if ( error < 0 ) return(error); // aligfile.str(""); @@ -221,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"); @@ -240,8 +250,56 @@ 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; - // delete f; // return(0); } @@ -253,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]; }; @@ -305,14 +363,29 @@ Int_t val = 0; Int_t del = 1100; 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 ){ + clevel2->wartrig = 0.; clevel2->trigty = 3.; + ck = true; break; }; }; + 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 ){ + clevel2->wartrig = 0.; + ck = true; + }; + }; + if ( !ck ) clevel2->wartrig = 100.; }; // Int_t se = 5; @@ -336,6 +409,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++){ @@ -392,6 +474,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; @@ -400,12 +483,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]; }; }; }; @@ -413,6 +498,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++){ @@ -473,6 +559,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. ){ @@ -504,7 +591,13 @@ clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; }; }; - }; + }; + // + if ( ener0 == 0. && cbase0 == 0. && !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); + pproblem = true; + pe++; + }; // Int_t j4 = -4; Int_t jjj = -3; @@ -524,20 +617,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++; }; }; @@ -591,23 +724,31 @@ 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)); - // if ( trkseqno == -1 ){ - ca->impx = clevel2->impx; - ca->impy = clevel2->impy; - ca->tanx = clevel2->tanx; - ca->tany = clevel2->tany; + // ca->impx = clevel2->impx; + // ca->impy = clevel2->impy; + ca->tanx[1] = clevel2->tanx; + ca->tany[1] = clevel2->tany; ca->elen = clevel2->elen; ca->selen = clevel2->selen; - memcpy(ca->cibar,clevel2->cibar,sizeof(clevel2->cibar)); - memcpy(ca->cbar,clevel2->cbar,sizeof(clevel2->cbar)); + // memcpy(ca->cibar,clevel2->cibar,sizeof(clevel2->cibar)); + // memcpy(ca->cbar,clevel2->cbar,sizeof(clevel2->cbar)); + memcpy(t_ca->tibar,clevel2->cibar,sizeof(clevel2->cibar)); + memcpy(t_ca->tbar,clevel2->cbar,sizeof(clevel2->cbar)); memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); - memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit)); - memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit)); + ca->varcfit[2] = clevel2->varcfit[0]; + ca->varcfit[3] = clevel2->varcfit[1]; + ca->npcfit[2] = clevel2->npcfit[0]; + ca->npcfit[3] = clevel2->npcfit[1]; + // memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit)); + // memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit)); + } else { + memcpy(t_ca->tibar,clevel2->tibar,sizeof(clevel2->tibar)); + memcpy(t_ca->tbar,clevel2->tbar,sizeof(clevel2->tbar)); }; + // // + if ( !(ca->CaloTrk) ) ca->CaloTrk = new TClonesArray("CaloTrkVar",1); //ELENA TClonesArray &t = *ca->CaloTrk; new(t[nutrk]) CaloTrkVar(*t_ca); // @@ -620,7 +761,7 @@ calol2cm(); } -void CaloProcessing::FillCommonVar(CaloLevel2 *ca){ +void CaloProcessing::FillCommonVar(CaloLevel1 *c1, CaloLevel2 *ca){ // ca->good = clevel2->good; if ( clevel2->trigty == 2. ){ @@ -628,29 +769,41 @@ } else { ca->selftrigger = 0; }; + // + ca->selftrigger += (Int_t)clevel2->wartrig; + // 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; - ca->impy = clevel2->impy; - ca->tanx = clevel2->tanx; - ca->tany = clevel2->tany; + // ca->impx = clevel2->impx; + // ca->impy = clevel2->impy; + ca->tanx[0] = clevel2->tanx; + ca->tany[0] = clevel2->tany; ca->nx22 = (Int_t)clevel2->nx22; ca->qx22 = clevel2->qx22; 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)); - memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit)); + ca->varcfit[0] = clevel2->varcfit[0]; + ca->varcfit[1] = clevel2->varcfit[1]; + ca->npcfit[0] = clevel2->npcfit[0]; + ca->npcfit[1] = clevel2->npcfit[1]; + ca->fitmode[0] = clevel2->fmode[0]; + ca->fitmode[1] = clevel2->fmode[1]; + // memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit)); + // memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit)); 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(){ @@ -707,13 +860,14 @@ void CaloProcessing::ClearCommonVar(){ istrip = 0; clevel2->trigty = -1.; + clevel2->wartrig = 0.; clevel2->good = 0; clevel2->nstrip = 0.; clevel2->qtot = 0.; - clevel2->impx = 0.; - clevel2->impy = 0.; - clevel2->tanx = 0.; - clevel2->tany = 0.; + // clevel2->impx = 0.; + // clevel2->impy = 0.; + clevel2->tanx = 0.; // this is correct since it refers to the fortran structure + clevel2->tany = 0.; // this is correct since it refers to the fortran structure clevel2->qmax = 0.; clevel2->nx22 = 0.; clevel2->qx22 = 0.; @@ -721,9 +875,10 @@ memset(clevel2->swerr, 0, 4*sizeof(Int_t)); memset(clevel2->crc, 0, 4*sizeof(Int_t)); memset(clevel2->qq, 0, 4*sizeof(Int_t)); - memset(clevel2->varcfit, 0, 2*sizeof(Float_t)); - memset(clevel2->npcfit, 0, 2*sizeof(Int_t)); + memset(clevel2->varcfit, 0, 4*sizeof(Float_t)); + memset(clevel2->npcfit, 0, 4*sizeof(Int_t)); memset(clevel2->planemax, 0, 2*sizeof(Int_t)); + memset(clevel2->fmode, 0, 2*sizeof(Int_t)); memset(clevel2->cibar, 0, 2*22*sizeof(Int_t)); memset(clevel2->cbar, 0, 2*22*sizeof(Float_t)); } @@ -779,7 +934,7 @@ return; } -Int_t CaloProcessing::Update(TSQLServer *dbc, ULong64_t atime, Int_t s){ +Int_t CaloProcessing::Update(TSQLServer *dbc, UInt_t atime, Int_t s){ // Int_t sgnl = 0; // @@ -787,24 +942,31 @@ // sgnl = 0; // - idcalib[s] = 0ULL; - fromtime[s] = 0ULL; - totime[s] = 0ULL; + idcalib[s] = 0; + fromtime[s] = 0; + totime[s] = 0; calibno[s] = 0; ClearCalibVals(s); // - sgnl = glcalo->Query_GL_CALO_CALIB(atime,s,dbc); + UInt_t uptime = 0; + // + sgnl = glcalo->Query_GL_CALO_CALIB(atime,uptime,s,dbc); if ( sgnl < 0 ){ if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); return(sgnl); }; // - idcalib[s] = glcalo->ID_REG_CALIBCALPED; + idcalib[s] = glcalo->ID_ROOT_L0; fromtime[s] = glcalo->FROM_TIME; - totime[s] = glcalo->TO_TIME; - calibno[s] = glcalo->EV_REG_CALIBCALPED; + if ( glcalo->TO_TIME < atime ){ // calibration is corrupted and we are using the one that preceed the good one + totime[s] = uptime; + } else { + totime[s] = glcalo->TO_TIME; + }; + // totime[s] = glcalo->TO_TIME; + calibno[s] = glcalo->EV_ROOT; // - if ( totime[s] == 0ULL){ + if ( totime[s] == 0 ){ if ( verbose ) printf(" CALORIMETER - WARNING: data with no associated calibration\n"); ClearCalibVals(s); sgnl = 100; @@ -828,7 +990,7 @@ name << glroot->NAME.Data(); // fcalname[s] = (TString)name.str().c_str(); - if ( verbose ) printf(" - event at time %llu. From time %llu to time %llu \n use file %s \n calibration at entry %i \n\n",atime,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]); + if ( verbose ) printf(" - event at time %u. From time %u to time %u \n use file %s \n calibration at entry %i \n\n",atime,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]); // sgnl = LoadCalib(s); // @@ -854,21 +1016,16 @@ TTree *tr = (TTree*)File->Get("CalibCalPed"); if ( !tr ) return(-109); // - TBranch *registry = tr->GetBranch("Registry"); TBranch *calo = tr->GetBranch("CalibCalPed"); // - pamela::RegistryEvent *reg = 0; pamela::CalibCalPedEvent *ce = 0; tr->SetBranchAddress("CalibCalPed", &ce); - tr->SetBranchAddress("Registry", ®); // - Long64_t ncalibs = registry->GetEntries(); + Long64_t ncalibs = calo->GetEntries(); // if ( !ncalibs ) return(-110); // - registry->GetEntry(calibno[s]); - // - calo->GetEntry(reg->event); + calo->GetEntry(calibno[s]); // if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { for ( Int_t d=0 ; d<11 ;d++ ){