--- DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2007/05/10 10:12:52 1.3 +++ DarthVader/CalorimeterLevel2/src/CaloLevel0.cpp 2008/02/07 20:02:09 1.16 @@ -64,6 +64,10 @@ 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)); + memset(obadmask, 0, 2*22*96*sizeof(Int_t)); + memset(obadpulsemask, 0, 2*22*6*sizeof(Int_t)); + memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); + memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); calopar1 = true; calopar2 = true; calopar3 = true; @@ -78,16 +82,30 @@ void CaloLevel0::SetCrossTalk(Bool_t ct){ crosst = ct; -}; +} + +void CaloLevel0::SetCrossTalkType(Bool_t ct){ + ctground = ct; +} void CaloLevel0::SetVerbose(Bool_t ct){ verbose = ct; -}; +} /** * Initialize CaloLevel0 object **/ -void CaloLevel0::ProcessingInit(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ +void CaloLevel0::ProcessingInit(GL_TABLES *glt, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ + // + const TString host = glt->CGetHost(); + const TString user = glt->CGetUser(); + const TString psw = glt->CGetPsw(); + TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); + if ( !dbc->IsConnected() ) throw -116; + stringstream myquery; + myquery.str(""); + myquery << "SET time_zone='+0:00'"; + dbc->Query(myquery.str().c_str()); // debug = isdeb; verbose = isverb; @@ -164,24 +182,35 @@ // delete glcalo; delete glroot; + dbc->Close(); + delete dbc; // return; // } -Int_t CaloLevel0::ChkCalib(TSQLServer *dbc, UInt_t atime){ +Int_t CaloLevel0::ChkCalib(GL_TABLES *glt, 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); + sgnl = Update(glt,atime,s); if ( sgnl < 0 ) return(sgnl); }; }; return(sgnl); } -Int_t CaloLevel0::ChkParam(TSQLServer *dbc, UInt_t runheader, Bool_t mechal){ +Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){ + const TString host = glt->CGetHost(); + const TString user = glt->CGetUser(); + const TString psw = glt->CGetPsw(); + TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); + if ( !dbc->IsConnected() ) throw -116; + stringstream myquery; + myquery.str(""); + myquery << "SET time_zone='+0:00'"; + dbc->Query(myquery.str().c_str()); + // stringstream calfile; stringstream bmfile; stringstream aligfile; @@ -223,6 +252,7 @@ for (Int_t k = 0; k < 22; k++ ){ for (Int_t l = 0; l < 96; l++ ){ fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f); + if ( debug ) printf(" %f \n",mip[m][k][l]); }; }; }; @@ -277,6 +307,7 @@ fread(&tmp,sizeof(clevel1->xalig),1,f); fread(&tmp,sizeof(clevel1->yalig),1,f); fread(&tmp,sizeof(clevel1->zalig),1,f); + // clevel1->zalig = -265.82; // }; fread(&clevel1->emin,sizeof(clevel1->emin),1,f); @@ -336,11 +367,373 @@ }; // delete glparam; + dbc->Close(); + delete dbc; // return(0); } +Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){ + // + if ( ctground ) return(0); + // + const TString host = glt->CGetHost(); + const TString user = glt->CGetUser(); + const TString psw = glt->CGetPsw(); + TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); + if ( !dbc->IsConnected() ) throw -116; + stringstream myquery; + myquery.str(""); + myquery << "SET time_zone='+0:00'"; + dbc->Query(myquery.str().c_str()); + // + stringstream bmfile; + Int_t error = 0; + ifstream badfile; + GL_PARAM *glparam = new GL_PARAM(); + // + // determine where I can find file with offline bad pulser mask + // + error = 0; + error = glparam->Query_GL_PARAM(runheader,105,dbc); + if ( error < 0 ) return(error); + // + bmfile.str(""); + bmfile << glparam->PATH.Data() << "/"; + bmfile << glparam->NAME.Data(); + // + if ( verbose ) printf("\n Using bad pulser 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 pulser offline mask file!\n"); + return(-115); + }; + // + Bool_t isdone = false; + Int_t bad = 0; + Int_t view = 1; + Int_t pre = 0; + Int_t plane = 21; + while ( !isdone ) { + badfile >> bad; + obadpulsemask[view][plane][pre] = bad; + if ( debug && bad ) printf(" SETTING view %i plane %i pre %i BAD = %i \n",view,plane,pre,bad); + pre++; + if ( pre > 5 ){ + pre = 0; + plane--; + if ( plane < 0 ){ + plane = 21; + view--; + }; + if ( view < 0 ) isdone = true; + }; + }; + // + delete glparam; + badfile.close(); + // + // Let's start with cross-talk correction calculation + // + GL_CALOPULSE_CALIB *glp = new GL_CALOPULSE_CALIB(); + Float_t adcp[2][22][96]; + Float_t adcpcal[2][22][96]; + memset(adcp , 0, 2*22*96*sizeof(Float_t)); + memset(adcpcal , 0, 2*22*96*sizeof(Float_t)); + // + UInt_t pampli = 0; + for (Int_t s=0; s<4; s++){ + // + // Save into matrix adcp the values of the highest pulse calibration (pulse amplitude = 2) + // + pampli = 2; + error = 0; + error = glp->Query_GL_CALOPULSE_CALIB(runheader,s,pampli,dbc); + if ( error < 0 ){ + if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); + return(error); + }; + // + UInt_t idcalib = glp->ID_ROOT_L0; + UInt_t fromtime = glp->FROM_TIME; + UInt_t calibno = glp->EV_ROOT; + // + // determine path and name and entry of the calibration file + // + GL_ROOT *glroot = new GL_ROOT(); + if ( verbose ) printf("\n"); + if ( verbose ) printf(" ** SECTION %i **\n",s); + // + error = 0; + error = glroot->Query_GL_ROOT(idcalib,dbc); + if ( error < 0 ){ + if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); + return(error); + }; + // + stringstream name; + name.str(""); + name << glroot->PATH.Data() << "/"; + name << glroot->NAME.Data(); + // + TString fcalname = (TString)name.str().c_str(); + ifstream myfile; + myfile.open(fcalname.Data()); + if ( !myfile ){ + return(-107); + }; + myfile.close(); + // + TFile *File = new TFile(fcalname.Data()); + if ( !File ) return(-108); + TTree *tr = (TTree*)File->Get("CalibCalPulse2"); + if ( !tr ) return(-119); + // + TBranch *calo = tr->GetBranch("CalibCalPulse2"); + // + pamela::CalibCalPulse2Event *ce = 0; + tr->SetBranchAddress("CalibCalPulse2", &ce); + // + Long64_t ncalibs = calo->GetEntries(); + // + if ( !ncalibs ) return(-110); + // + calo->GetEntry(calibno); + if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); + // + // retrieve calibration table + // + if ( ce->pstwerr[s] && ce->pperror[s] == 0 && ce->unpackError == 0 ){ + for ( Int_t d=0 ; d<11 ;d++ ){ + for ( Int_t j=0; j<96 ;j++){ + if ( s == 2 ){ + adcp[0][2*d+1][j] = ce->calpuls[3][d][j]; + }; + if ( s == 3 ){ + adcp[0][2*d][j] = ce->calpuls[1][d][j]; + }; + if ( s == 0 ){ + adcp[1][2*d][j] = ce->calpuls[0][d][j]; + }; + if ( s == 1 ){ + adcp[1][2*d+1][j] = ce->calpuls[2][d][j]; + }; + }; + }; + } else { + if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); + return(-111); + }; + // + File->Close(); + delete glroot; + // + // Save into matrix adcpcal the calibrated values of the pulse calibration (subtraction of pulse amplitude = 0 relative to the pulse2 calibration used) + // + pampli = 0; + error = 0; + error = glp->Query_GL_CALOPULSE_CALIB(fromtime,s,pampli,dbc); + if ( error < 0 ){ + if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); + return(error); + }; + // + idcalib = glp->ID_ROOT_L0; + calibno = glp->EV_ROOT; + // + // determine path and name and entry of the calibration file + // + glroot = new GL_ROOT(); + if ( verbose ) printf("\n"); + if ( verbose ) printf(" ** SECTION %i **\n",s); + // + error = 0; + error = glroot->Query_GL_ROOT(idcalib,dbc); + if ( error < 0 ){ + if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); + return(error); + }; + // + name.str(""); + name << glroot->PATH.Data() << "/"; + name << glroot->NAME.Data(); + // + fcalname = (TString)name.str().c_str(); + myfile.open(fcalname.Data()); + if ( !myfile ){ + return(-107); + }; + myfile.close(); + // + TFile *File1 = new TFile(fcalname.Data()); + if ( !File1 ) return(-108); + TTree *tr1 = (TTree*)File1->Get("CalibCalPulse1"); + if ( !tr1 ) return(-120); + // + TBranch *calo1 = tr1->GetBranch("CalibCalPulse1"); + // + pamela::CalibCalPulse1Event *ce1 = 0; + tr1->SetBranchAddress("CalibCalPulse1", &ce1); + // + ncalibs = calo1->GetEntries(); + // + if ( !ncalibs ) return(-110); + // + calo1->GetEntry(calibno); + if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); + // + // retrieve calibration table + // + if ( ce1->pstwerr[s] && ce1->pperror[s] == 0 && ce1->unpackError == 0 ){ + for ( Int_t d=0 ; d<11 ;d++ ){ + for ( Int_t j=0; j<96 ;j++){ + if ( s == 2 ){ + adcpcal[0][2*d+1][j] = adcp[0][2*d+1][j] - ce1->calpuls[3][d][j]; + }; + if ( s == 3 ){ + adcpcal[0][2*d][j] = adcp[0][2*d][j] - ce1->calpuls[1][d][j]; + }; + if ( s == 0 ){ + adcpcal[1][2*d][j] = adcp[1][2*d][j] - ce1->calpuls[0][d][j]; + }; + if ( s == 1 ){ + adcpcal[1][2*d+1][j] = adcp[1][2*d+1][j] - ce1->calpuls[2][d][j]; + }; + }; + }; + } else { + if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); + return(-111); + }; + // + File1->Close(); + // + delete glroot; + // + };// loop on the four sections + // + // + delete glp; + dbc->Close(); + delete dbc; + // + // Ok, now we can try to calculate the cross-talk correction for each pre-amplifier + // + for ( Int_t v=0; v<2; v++){ + if ( debug ) printf(" \n\n NEW VIEW \n"); + for ( Int_t p=0; p<22; p++){ + for ( Int_t npre=0; npre<6; npre++){ + ctprecor[v][p][npre] = 1000.; + ctneigcor[v][p][npre] = 1000.; + Int_t str0=npre*16; + Int_t str16= -1 + (1+npre)*16; + // + UInt_t neigc = 0; + UInt_t farc = 0; + UInt_t pulsc = 0; + Float_t sigpulsed = 0.; + Float_t neigbase = 0.; + Float_t farbase = 0.; + // + // Loop over the strip of the pre and sum all signal far away from pulsed strip, signal in the neighbour(s) strip(s) and save the pulsed signal + // moreover count the number of strips in each case + // + for (Int_t s=str0; s<=str16; s++){ + if ( adcpcal[v][p][s] > 10000.){ + sigpulsed = adcpcal[v][p][s]; + pulsc++; + if ( s > str0 ){ + neigbase += adcpcal[v][p][s-1]; + neigc++; + farbase -= adcpcal[v][p][s-1]; + farc--; + }; + if ( s < str16 ){ + neigbase += adcpcal[v][p][s+1]; + neigc++; + farbase -= adcpcal[v][p][s+1]; + farc--; + }; + } else { + farc++; + farbase += adcpcal[v][p][s]; + }; + }; + // + // Now calculate the corrections + // + Float_t avefarbase = 0.; + if ( farc ) avefarbase = farbase/(Float_t)farc; + Float_t aveneigbase = 0.; + if ( neigc ) aveneigbase = neigbase/(Float_t)neigc; + // + if ( pulsc == 1 && farc && neigc ){ + ctprecor[v][p][npre] = -avefarbase/(sigpulsed+fabs(avefarbase)); + ctneigcor[v][p][npre] = fabs(aveneigbase-avefarbase)/(sigpulsed+fabs(avefarbase)); + if ( debug ) printf(" Cross-talk correction View %i Plane %i Pre %i : pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); + } else { + // + // did not find the pulsed strip or more than one pulsed strip found! + // + if ( debug ) printf(" Problems finding the cross-talk corrections: \n View %i Plane %i Pre %i number of pulsed strip %i \n Average faraway baseline %f number of strips %i Average neighbour baseline %f number of neighbour strips %i \n",v,p,npre,pulsc,avefarbase,farc,aveneigbase,neigc); + // + }; + }; + if ( debug ) printf(" \n ==================== \n"); + }; + }; + // + // Check the calculated corrections + // + Int_t opre=0; + Int_t ppre=0; + Bool_t found = false; + for ( Int_t v=0; v<2; v++){ + for ( Int_t p=0; p<22; p++){ + for ( Int_t npre=0; npre<6; npre++){ + if ( ctprecor[v][p][npre] == 1000. || ctneigcor[v][p][npre] == 1000. || obadpulsemask[v][p][npre] != 0 ){ + if ( debug ) printf(" Cross-talk correction CHANGED for view %i Plane %i Pre %i\n BEFORE: pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); + if ( npre%2 ){ + opre = npre-1; + } else { + opre = npre+1; + }; + if ( ctprecor[v][p][opre] == 1000. || ctneigcor[v][p][opre] == 1000. || obadpulsemask[v][p][opre] != 0 ){ + ppre=0; + found = false; + while ( ppre < 6 ){ + if ( ctprecor[v][p][ppre] != 1000. && ctneigcor[v][p][ppre] != 1000. && !obadpulsemask[v][p][ppre] ){ + found = true; + ctprecor[v][p][npre] = ctprecor[v][p][ppre]; + ctneigcor[v][p][npre] = ctneigcor[v][p][ppre]; + break; + }; + ppre++; + }; + if ( !found ){ + if ( verbose ) printf(" WARNING: cannot find a good cross-talk correction for view %i plane %i pre %i \n Setting to default values 0.002 0.002\n",v,p,npre); + ctprecor[v][p][npre] = 0.002; + ctneigcor[v][p][npre] = 0.002; + }; + } else { + ctprecor[v][p][npre] = ctprecor[v][p][opre]; + ctneigcor[v][p][npre] = ctneigcor[v][p][opre]; + }; + if ( debug ) printf(" AFTER: pre-correction: %f neighbour strips correction %f \n",ctprecor[v][p][npre],ctneigcor[v][p][npre]); + }; + }; + }; + }; + // + return(0); +} +void CaloLevel0::FindBaseCompress(Int_t l, Int_t m, Int_t pre){ + for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ + dexy[l][m][e] = dexyc[l][m][e]; + }; + this->FindBaseRaw(l,m,pre); +} void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre){ Float_t minstrip = 100000.; @@ -352,6 +745,9 @@ rms = calthr[l][m][pre]; }; }; + if ( debug && l==1 ){ + printf("\n BASELINE CALCULATION for view %i pl %i pre %i: \n => minstrip %f rms %f \n",l,m,pre,minstrip,rms); + }; if ( minstrip != 100000. ) { Float_t strip6s = 0.; for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ @@ -368,7 +764,11 @@ dexyc[l][m][e] = dexy[l][m][e]; }; }; - if ( strip6s >= 9. ){ + if ( debug && l==1 ){ + printf(" strip6s %f \n",strip6s); + }; + // if ( strip6s >= 9. ){ + if ( strip6s >= 2. ){ Double_t arro = base[l][m][pre]/strip6s; Float_t deci = 1000.*((float)arro - float(int(arro))); if ( deci < 500. ) { @@ -396,8 +796,18 @@ // // if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3. // + clevel2->nsatstrip = 0.; Int_t val = 0; Int_t del = 1100; + for (Int_t sec = 0; sec < 4; sec++){ + for (Int_t dsec = 0; dsec < 7; dsec++){ + val = (Int_t)de->calselftrig[sec][dsec]; + del = delay(val); + clevel2->selfdelay[sec][dsec] = del; + }; + }; + val = 0; + del = 1100; if ( clevel2->trigty != 2. ){ Bool_t ck = false; for (Int_t sec = 0; sec < 4; sec++){ @@ -517,8 +927,12 @@ // // baseline check and calculation // - if ( !isRAW ) { - base[l][m][pre] = de->base[l][m][pre] ; + if ( !isRAW ){ + if ( de->base[l][m][pre] != 0. && de->base[l][m][pre]<31000. ) { + base[l][m][pre] = de->base[l][m][pre] ; + } else { + FindBaseCompress(l,m,pre); + }; cbase0 += base[l][m][pre]; } else { // @@ -578,22 +992,22 @@ case 0: base0 = base[l][m][pre]; base2 = calbase[l][m][pre]; - if ( debug ) printf(" base0 = base l m pre = %f base2 = calbase l m pre = %f \n",base[l][m][pre],calbase[l][m][pre]); + if ( debug ) printf(" base0 = base l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,base[l][m][pre],calbase[l][m][pre]); break; case 1: base0 = base[l][m][ip[i]]; base2 = calbase[l][m][ip[i]]; - if ( debug ) printf(" base0 = base l m ip(i) = %f base2 = calbase l m ip(i) = %f \n",base[l][m][ip[i]],calbase[l][m][ip[i]]); + if ( debug ) printf(" base0 = base l%i m%i ip(i)%i = %f base2 = calbase l m ip(i) = %f \n",l,m,ip[i],base[l][m][ip[i]],calbase[l][m][ip[i]]); break; case 2: base0 = sbase[l][m][pre]; base2 = calbase[l][m][pre]; - if ( debug ) printf(" base0 = sbase l m pre = %f base2 = calbase l m pre = %f \n",sbase[l][m][pre],calbase[l][m][pre]); + if ( debug ) printf(" base0 = sbase l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,sbase[l][m][pre],calbase[l][m][pre]); break; case 3: base0 = calbase[l][m][pre]; base2 = calbase[l][m][pre]; - if ( debug ) printf(" base0 = calbase l m pre = %f base2 = calbase l m pre = %f \n",calbase[l][m][pre],calbase[l][m][pre]); + if ( debug ) printf(" base0 = calbase l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,calbase[l][m][pre],calbase[l][m][pre]); break; }; base1 = calbase[l][m][pre]; @@ -628,13 +1042,21 @@ 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 ( !ctground ){ + clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * ctprecor[l][m][ipre]; + } else { + 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] += qpre[ipre] * 0.00478; + if ( !ctground ){ + clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre]; + } else { + clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; + }; }; }; }; @@ -649,19 +1071,33 @@ Int_t j4 = -4; Int_t jjj = -3; Int_t jj = -2; - for (Int_t j = 0 ; j < 100 ; j++){ + Int_t jjpre = -1; + Int_t jjjpre = -1; + for (Int_t j = 0 ; j < 100 ; j++){ jj++; jjj++; j4++; if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; 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 ( !ctground ){ + if ( jj%16 == 0 ) jjpre++; + if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; + if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; + } else { + 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 ( !ctground ){ + if ( jjj%16 == 0 ) jjjpre++; + if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; + if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; + } else { + 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 ){ @@ -671,41 +1107,47 @@ 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 ){ // + Float_t savel1 = clevel1->estrip[j4][m][l]; + if ( dexyc[l][m][j4] == 32767. ){ + savel1 += 5000.; + clevel2->nsatstrip += 1.; + }; + // tim = 100000.; plo = m; fbi = 0; - if ( clevel1->estrip[j4][m][l] > 0.99995 ){ + if ( savel1 > 0.99995 ){ tim = 10000.; plo = m; fbi = 1; }; - if ( clevel1->estrip[j4][m][l] > 9.9995 ){ + if ( savel1 > 9.9995 ){ tim = 1000.; plo = 22 + m; fbi = 1; }; - if ( clevel1->estrip[j4][m][l] > 99.995 ){ + if ( savel1 > 99.995 ){ tim = 100.; plo = 22 + m; fbi = 0; }; - if ( clevel1->estrip[j4][m][l] > 999.95 ){ + if ( savel1 > 999.95 ){ tim = 10.; plo = 44 + m; fbi = 0; }; - if ( clevel1->estrip[j4][m][l] > 9999.5 ){ + if ( savel1 > 9999.5 ){ tim = 1.; plo = 66 + m; fbi = 0; }; // - cle = (Int_t)lroundf(tim*clevel1->estrip[j4][m][l]); + cle = (Int_t)lroundf(tim*savel1); // if ( l == 0 ){ // @@ -785,6 +1227,7 @@ 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->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay)); ca->varcfit[2] = clevel2->varcfit[0]; ca->varcfit[3] = clevel2->varcfit[1]; ca->npcfit[2] = clevel2->npcfit[0]; @@ -825,6 +1268,7 @@ memcpy(ca->swerr,clevel2->swerr,sizeof(clevel2->swerr)); memcpy(ca->crc,clevel2->crc,sizeof(clevel2->crc)); ca->nstrip = (Int_t)clevel2->nstrip; + ca->nsatstrip = (Int_t)clevel2->nsatstrip; ca->qtot = clevel2->qtot; // ca->impx = clevel2->impx; // ca->impy = clevel2->impy; @@ -837,6 +1281,7 @@ ca->selen = clevel2->selen; memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq)); memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); + memcpy(ca->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay)); ca->varcfit[0] = clevel2->varcfit[0]; ca->varcfit[1] = clevel2->varcfit[1]; ca->npcfit[0] = clevel2->npcfit[0]; @@ -868,6 +1313,8 @@ 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)); + memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); + memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); // } @@ -912,6 +1359,7 @@ clevel2->wartrig = 0.; clevel2->good = 0; clevel2->nstrip = 0.; + clevel2->nsatstrip = 0.; clevel2->qtot = 0.; // clevel2->impx = 0.; // clevel2->impy = 0.; @@ -927,6 +1375,7 @@ 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->selfdelay, 0, 4*7*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)); @@ -983,8 +1432,17 @@ return; } -Int_t CaloLevel0::Update(TSQLServer *dbc, UInt_t atime, Int_t s){ +Int_t CaloLevel0::Update(GL_TABLES *glt, UInt_t atime, Int_t s){ // + const TString host = glt->CGetHost(); + const TString user = glt->CGetUser(); + const TString psw = glt->CGetPsw(); + TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); + if ( !dbc->IsConnected() ) throw -116; + stringstream myquery; + myquery.str(""); + myquery << "SET time_zone='+0:00'"; + dbc->Query(myquery.str().c_str()); Int_t sgnl = 0; // GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();