--- DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2006/05/19 13:15:49 1.1.1.1 +++ DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp 2007/02/13 16:55:08 1.13 @@ -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,32 @@ // 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; + calopar3 = true; + crosst = true; + ftcalopar1 = 0; + ttcalopar1 = 0; + ftcalopar2 = 0; + ttcalopar2 = 0; + ftcalopar3 = 0; + ttcalopar3 = 0; } +void CaloProcessing::SetCrossTalk(Bool_t ct){ + crosst = ct; +}; + /** * 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 +99,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,36 +136,40 @@ 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] ){ + if ( !dbc->IsConnected() ) throw -116; sgnl = Update(dbc,atime,s); if ( sgnl < 0 ) return(sgnl); }; @@ -232,11 +177,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 ) ){ @@ -247,7 +194,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 +227,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(""); @@ -289,7 +236,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"); @@ -308,6 +255,57 @@ 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); } @@ -318,7 +316,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]; }; @@ -370,14 +368,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; @@ -401,6 +414,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++){ @@ -457,6 +479,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; @@ -465,12 +488,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]; }; }; }; @@ -478,6 +503,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++){ @@ -487,7 +513,7 @@ doneb = 0; donec = 0; pre++; - qpre[pre] = 0; + qpre[pre] = 0.; }; // // baseline check and calculation @@ -538,6 +564,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. ){ @@ -553,23 +580,31 @@ }; }; }; - if (ck == 1){ - if (ip[i]%2 == 0) { - ipre = ip[i] + 1; - } else { - 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; + if ( crosst ){ + if (ck == 1){ + if (ip[i]%2 == 0) { + ipre = ip[i] + 1; + } else { + ipre = ip[i] - 1; + }; + for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ + 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; + if (ck == 2){ + for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ + ipre = j/16 + 1; + 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; @@ -579,30 +614,72 @@ jjj++; 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 ( 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 ( crosst ){ + if ( jj >= 0 && jj < 96 ){ + 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] += -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 ){ // - // 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++; }; }; @@ -656,26 +733,36 @@ 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); // + delete t_ca; + // ClearTrkVar(); } @@ -683,7 +770,7 @@ calol2cm(); } -void CaloProcessing::FillCommonVar(CaloLevel2 *ca){ +void CaloProcessing::FillCommonVar(CaloLevel1 *c1, CaloLevel2 *ca){ // ca->good = clevel2->good; if ( clevel2->trigty == 2. ){ @@ -691,29 +778,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(){ @@ -724,18 +823,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,33 +861,35 @@ 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(){ 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.; - 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, 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)); } void CaloProcessing::ClearCalibVals(Int_t s){ @@ -848,7 +943,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 +951,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 +999,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 +1025,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++ ){