--- DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2006/05/19 13:15:49 1.1.1.1 +++ DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2006/09/07 09:47:07 1.5 @@ -18,7 +18,6 @@ // YODA headers // #include -#include #include #include // @@ -46,75 +45,11 @@ // CaloProcessing::~CaloProcessing(){ + delete de; delete this; } CaloProcessing::CaloProcessing(){ - e_clevel1 = new struct FlCaLevel1; - e_clevel2 = new struct FlCaLevel2; - e_clevel2->ncore = 0; - e_clevel2->qcore = 0.; - e_clevel2->noint = 0.; - e_clevel2->ncyl = 0.; - e_clevel2->qcyl = 0.; - e_clevel2->qtrack = 0.; - e_clevel2->qtrackx = 0.; - e_clevel2->qtracky = 0.; - e_clevel2->dxtrack = 0.; - e_clevel2->dytrack = 0.; - e_clevel2->qlast = 0.; - e_clevel2->nlast = 0.; - e_clevel2->qpre = 0.; - e_clevel2->npre = 0.; - e_clevel2->qpresh = 0.; - e_clevel2->npresh = 0.; - e_clevel2->qlow = 0.; - e_clevel2->nlow = 0.; - e_clevel2->qtr = 0.; - e_clevel2->ntr = 0.; - e_clevel2->elen = 0.; - e_clevel2->selen = 0.; - e_clevel1->good2 = 0; - e_clevel1->trkchi2 = 0; - for (Int_t il = 0; il<2 ; il++){ - for ( Int_t jl = 0; jl<22; jl++){ - if ( jl < 5 ) e_clevel1->al_p[jl][il] = 0.; - for ( Int_t ml = 0; ml<96; ml++){ - e_clevel1->estrip[ml][jl][il] = 0.; - }; - }; - }; - e_clevel2->trigty = 0.; - e_clevel2->good = 0; - e_clevel2->nstrip = 0.; - e_clevel2->qtot = 0.; - e_clevel2->impx = 0.; - e_clevel2->impy = 0.; - e_clevel2->tanx = 0.; - e_clevel2->tany = 0.; - e_clevel2->qmax = 0.; - e_clevel2->nx22 = 0.; - e_clevel2->qx22 = 0.; - e_clevel2->planetot = 0.; - e_clevel2->qmean = 0.; - e_clevel2->dX0l = 0.; - for (Int_t il = 0; il<4 ; il++){ - e_clevel2->perr[il] = 0; - e_clevel2->swerr[il] = 0; - e_clevel2->crc[il] = 0; - e_clevel2->qq[il] = 0.; - if ( il < 2 ){ - e_clevel2->varcfit[il] = 0.; - e_clevel2->planemax[il] = 0; - e_clevel2->npcfit[il] = 0; - for ( Int_t jl = 0; jl<22; jl++){ - e_clevel2->cibar[jl][il] = 0; - e_clevel2->tibar[jl][il] = 0; - e_clevel2->cbar[jl][il] = 0.; - e_clevel2->tbar[jl][il] = 0.; - }; - }; - }; // extern struct FlCaLevel1 clevel1_; extern struct FlCaLevel2 clevel2_; @@ -123,31 +58,24 @@ // trkseqno = 0; ClearStructs(); - for ( Int_t l = 0; l < 2; l++ ){ - for ( Int_t m = 0; m < 22; m++ ){ - for ( Int_t n = 0; n < 96; n++ ){ - dexy[l][m][n] = 0.; - dexyc[l][m][n] = 0.; - mip[l][m][n] = 0.; - if ( n < 6 ){ - base[l][m][n] = 0.; - sbase[l][m][n] = 0.; - }; - }; - }; - }; + // + memset(dexy, 0, 2*22*96*sizeof(Float_t)); + memset(dexyc, 0, 2*22*96*sizeof(Float_t)); + memset(mip, 0, 2*22*96*sizeof(Float_t)); + memset(base, 0, 2*22*6*sizeof(Float_t)); + memset(sbase, 0, 2*22*6*sizeof(Float_t)); calopar1 = true; calopar2 = true; - ftcalopar1 = 0ULL; - ttcalopar1 = 0ULL; - ftcalopar2 = 0ULL; - ttcalopar2 = 0ULL; + ftcalopar1 = 0; + ttcalopar1 = 0; + ftcalopar2 = 0; + ttcalopar2 = 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; @@ -163,26 +91,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; @@ -195,33 +128,36 @@ 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; }; // + delete glcalo; + delete glroot; + // return; // } -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] ){ @@ -232,7 +168,7 @@ return(sgnl); } -Int_t CaloProcessing::ChkParam(TSQLServer *dbc, ULong64_t runheader){ +Int_t CaloProcessing::ChkParam(TSQLServer *dbc, UInt_t runheader){ stringstream calfile; stringstream aligfile; Int_t error = 0; @@ -247,7 +183,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(""); @@ -280,7 +216,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(""); @@ -308,6 +244,8 @@ fclose(f); }; // + delete glparam; + // return(0); } @@ -487,7 +425,7 @@ doneb = 0; donec = 0; pre++; - qpre[pre] = 0; + qpre[pre] = 0.; }; // // baseline check and calculation @@ -560,13 +498,13 @@ ipre = ip[i] - 1; }; for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ - clevel1->estrip[j][m][l] = clevel1->estrip[j][m][l] + (qpre[ipre] - qpre[ip[i]]) * 0.00478; + clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; }; }; if (ck == 2){ for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ ipre = j/16 + 1; - clevel1->estrip[j][m][l] = clevel1->estrip[j][m][l] + qpre[ipre] * 0.00478; + clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; }; }; }; @@ -580,12 +518,12 @@ j4++; if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; if ( jj >= 0 && jj < 96 ){ - if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] = ene[jj-1] - clevel1->estrip[jj][m][l] * 0.01581; - if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] = ene[jj+1] - clevel1->estrip[jj][m][l] * 0.01581; + if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * 0.01581; + if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * 0.01581; }; if ( jjj >= 0 && jjj < 96 ){ - if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] = clevel1->estrip[jjj-1][m][l] - ene[jjj] * 0.01581; - if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] = clevel1->estrip[jjj+1][m][l] - ene[jjj] * 0.01581; + if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * 0.01581; + if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * 0.01581; }; if ( j4 >= 0 && j4 < 96 ){ // @@ -676,6 +614,8 @@ TClonesArray &t = *ca->CaloTrk; new(t[nutrk]) CaloTrkVar(*t_ca); // + delete t_ca; + // ClearTrkVar(); } @@ -724,18 +664,12 @@ void CaloProcessing::RunClose(){ l0tr->Delete(); ClearStructs(); - for ( Int_t l = 0; l < 2; l++ ){ - for ( Int_t m = 0; m < 22; m++ ){ - for ( Int_t n = 0; n < 96; n++ ){ - dexy[l][m][n] = 0.; - dexyc[l][m][n] = 0.; - if ( n < 6 ){ - base[l][m][n] = 0.; - sbase[l][m][n] = 0.; - }; - }; - }; - }; + // + memset(dexy, 0, 2*22*96*sizeof(Float_t)); + memset(dexyc, 0, 2*22*96*sizeof(Float_t)); + memset(base, 0, 2*22*6*sizeof(Float_t)); + memset(sbase, 0, 2*22*6*sizeof(Float_t)); + // } // @@ -768,9 +702,9 @@ clevel2->dX0l = 0.; clevel2->elen = 0.; clevel2->selen = 0.; - memcpy(clevel1->al_p,e_clevel1->al_p,sizeof(clevel1->al_p)); - memcpy(clevel2->tibar,e_clevel2->tibar,sizeof(clevel2->tibar)); - memcpy(clevel2->tbar,e_clevel2->tbar,sizeof(clevel2->tbar)); + memset(clevel1->al_p, 0, 5*2*sizeof(Double_t)); + memset(clevel2->tibar, 0, 2*22*sizeof(Int_t)); + memset(clevel2->tbar, 0, 2*22*sizeof(Float_t)); } void CaloProcessing::ClearCommonVar(){ @@ -786,15 +720,15 @@ clevel2->qmax = 0.; clevel2->nx22 = 0.; clevel2->qx22 = 0.; - memcpy(clevel2->perr,e_clevel2->perr,sizeof(clevel2->perr)); - memcpy(clevel2->swerr,e_clevel2->swerr,sizeof(clevel2->swerr)); - memcpy(clevel2->crc,e_clevel2->crc,sizeof(clevel2->crc)); - memcpy(clevel2->qq,e_clevel2->qq,sizeof(clevel2->qq)); - memcpy(clevel2->planemax,e_clevel2->planemax,sizeof(clevel2->planemax)); - memcpy(clevel2->varcfit,e_clevel2->varcfit,sizeof(clevel2->varcfit)); - memcpy(clevel2->npcfit,e_clevel2->npcfit,sizeof(clevel2->npcfit)); - memcpy(clevel2->cibar,e_clevel2->cibar,sizeof(clevel2->cibar)); - memcpy(clevel2->cbar,e_clevel2->cbar,sizeof(clevel2->cbar)); + memset(clevel2->perr, 0, 4*sizeof(Int_t)); + 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->planemax, 0, 2*sizeof(Int_t)); + memset(clevel2->cibar, 0, 2*22*sizeof(Int_t)); + memset(clevel2->cbar, 0, 2*22*sizeof(Float_t)); } void CaloProcessing::ClearCalibVals(Int_t s){ @@ -848,7 +782,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; // @@ -856,24 +790,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; @@ -897,11 +838,13 @@ 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); // if ( sgnl != 0 ) return(sgnl); + delete glcalo; + delete glroot; // return(0); // @@ -921,21 +864,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++ ){