--- tof/flight/ToFReprocessing/ToFreproc.cpp 2008/11/28 14:58:50 1.1 +++ tof/flight/ToFReprocessing/ToFreproc.cpp 2009/11/23 09:38:05 1.3 @@ -57,6 +57,7 @@ TString OUTF; TString LIST; TString OPTIONS; +TString CALIBF; PamLevel2 *pam_event = NULL; @@ -72,11 +73,12 @@ // read input file/list // -------------------- pam_event = new PamLevel2(ddir,list,options); + pam_event->SetSELLI(2); TTree::SetMaxTreeSize(1000*Long64_t(2000000000)); - // - TString outfile_t =0; + // + TString outfile_t = ""; outfile_t = OUTF; - outfile_t.Append("b.root"); + outfile_t.Append(".root"); TFile *outft = (TFile*)gROOT->FindObject(outfile_t); if (outft) outft->Close(); outft = new TFile(outfile_t,"RECREATE"); @@ -88,6 +90,7 @@ // outft->cd(); ToFLevel2 *tof = new ToFLevel2(); + ToFdEdx *tofdedx = new ToFdEdx(); TTree *toft = new TTree("ToF","PAMELA Level2 ToF data"); toft->SetAutoSave(900000000000000LL); tof->Set();//ELENA **TEMPORANEO?** @@ -145,7 +148,7 @@ for(ULong64_t iev=0; ievGetRunInfo()->RUNHEADER_TIME,(int)myrun,(int)mysrun); mysrun = myrun; // - Int_t error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table + + + + + Int_t error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,204,dbc); // parameters stored in DB in GL_PRAM table + if ( error<0 ) { + return(1); + }; + // + tofdedx->ReadParAtt((glparam->PATH+glparam->NAME).Data()); + + // + error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,205,dbc); // parameters stored in DB in GL_PRAM table + if ( error<0 ) { + return(1); + }; + // + tofdedx->ReadParPos((glparam->PATH+glparam->NAME).Data()); + + // + error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,206,dbc); // parameters stored in DB in GL_PRAM table + if ( error<0 ) { + return(1); + }; + // + tofdedx->ReadParBBneg((glparam->PATH+glparam->NAME).Data()); + + // + error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,207,dbc); // parameters stored in DB in GL_PRAM table + if ( error<0 ) { + return(1); + }; + // + tofdedx->ReadParBBpos((glparam->PATH+glparam->NAME).Data()); + + // + error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,208,dbc); // parameters stored in DB in GL_PRAM table + if ( error<0 ) { + return(1); + }; + // + tofdedx->ReadParDesatBB((glparam->PATH+glparam->NAME).Data()); + + + tofdedx->CheckConnectors(pam_event->GetRunInfo()->RUNHEADER_TIME,glparam,dbc); + + + + error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table if ( error<0 ) { return(1); }; @@ -182,104 +233,114 @@ // -//================================================================ -//================================================================== -//--- Define absolute time - Float_t tabs=pam_event->GetOrbitalInfo()->absTime; - -//================================================================== -Float_t dedx_corr_m[2000][48],dedx_corr[48]; -Double_t mtime[2000],t1,t2,tm; -Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2; -Float_t xmean1,xwidth1; - -Int_t ical,ii,j,jj; - -if (iev==0) { - -ical=0; // counter set to zero if first-time reading - -//----------------------------------------------------------- -// Here I read the dEdx_korr parameters -//----------------------------------------------------------- - -jj=0; - -ifstream fin("adcmonitor.7th.100k.cut.dat"); - -while (! fin.eof()) { -fin>>t1>>tm>>t2; -//cout<>j>>xmean1>>xwidth1; -dedx_corr_m[jj][ii]=xmean1; - } -jj=jj+1; -} - -fin.close(); - - -while (tabs > mtime[ical]) { -ical = ical+1; - } -ical = ical-1; -cout<<"abs time "<mtime[ical+1]) { -cout<<"Checking Time Limits!"< mtime[ical]) { -ical = ical+1; - } -ical = ical-1; -cout<<"abs time "<GetOrbitalInfo()->absTime; + + printf(" ATIME %u re %u \n",(Int_t)tabs,(UInt_t)iev); + + //================================================================== + Float_t dedx_corr_m[2000][48],dedx_corr[48]; + Double_t mtime[2000],t1,t2,tm; + Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2; + Float_t xmean1,xwidth1; + + Int_t ical,ii,j,jj; + + if (iev==0) { + + ical=0; // counter set to zero if first-time reading + + //----------------------------------------------------------- + // Here I read the dEdx_korr parameters + //----------------------------------------------------------- + + jj=0; + + ifstream fin(CALIBF.Data()); + + while (! fin.eof()) { + fin>>t1>>tm>>t2; + // cout<>j>>xmean1>>xwidth1; + dedx_corr_m[jj][ii]=xmean1; + } + jj=jj+1; + // printf(" kk %i \n",jj); + } + // printf(" 1ical %i \n",ical); + + fin.close(); + + + while (tabs mtime[ical+1]) { + // printf(" ical %i \n",ical); + ical = ical+1; + } + // ical = ical-1; + cout<<"abs time "<mtime[ical+1]) { + cout<<"Checking Time Limits!"< mtime[ical+1] || tabsntrk() ; pm++){ ToFTrkVar *ttf = tofl2->GetToFTrkVar(pm); for ( Int_t nc=0; nc < ttf->npmttdc; nc++){ - if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1; + if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1; }; for ( Int_t nc=0; nc < ttf->npmtadc; nc++){ - if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1; + if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1; }; }; // @@ -300,27 +361,30 @@ ToFPMT *pmt = tofl2->GetToFPMT(pm); tofl2->GetPMTIndex(pmt->pmt_id, gg, hh); if ( adcf[pmt->pmt_id] == 0 ){ - tofinput_.adc[gg][hh] = (int)pmt->adc; - adc[hh][gg] = (int)pmt->adc; + tofinput_.adc[gg][hh] = (int)pmt->adc; + adc[hh][gg] = (int)pmt->adc; }; if ( tdcf[pmt->pmt_id] == 0 ){ - tofinput_.tdc[gg][hh] = (int)pmt->tdc; - tdc[hh][gg] = (int)pmt->tdc; + tofinput_.tdc[gg][hh] = (int)pmt->tdc; + tdc[hh][gg] = (int)pmt->tdc; }; tdcc[hh][gg] = (float)pmt->tdc_tw; // Int_t pppid = tof->GetPMTid(hh,gg); // printf(" pm %i pmt_id %i pppid %i hh %i gg %i tdcc %f tdc %f adc %f \n",pm,pmt->pmt_id,pppid,hh,gg,pmt->tdc_tw,pmt->tdc,pmt->adc); }; - - -// for (Int_t pm=0; pm <48 ; pm++){ -// tof->GetPMTIndex(pm, gg, hh); -// tofinput_.tdc[hh][gg] = (int)500.; -// tofinput_.adc[hh][gg] = (int)500.; -// tdc[hh][gg] = (int)500.; -// adc[hh][gg] = (int)500.; -// // printf(" hh %i gg %i tdc %f adc %f \n",hh,gg,pmt->tdc,pmt->adc); -// }; + for (Int_t hh=0; hh<12;hh++){ + for (Int_t kk=0; kk<4;kk++){ + tofdedx->Init(kk,hh,adc[kk][hh]); + }; + }; + // for (Int_t pm=0; pm <48 ; pm++){ + // tof->GetPMTIndex(pm, gg, hh); + // tofinput_.tdc[hh][gg] = (int)500.; + // tofinput_.adc[hh][gg] = (int)500.; + // tdc[hh][gg] = (int)500.; + // adc[hh][gg] = (int)500.; + // // printf(" hh %i gg %i tdc %f adc %f \n",hh,gg,pmt->tdc,pmt->adc); + // }; // for (Int_t hh=0; hh<5;hh++){ tofinput_.patterntrig[hh]=pam_event->GetTrigLevel2()->patterntrig[hh]; @@ -368,24 +432,43 @@ t_tof->beta[kk] = tofoutput_.betatof_a[kk]; } // + memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); + memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); + memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); + memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); + { + Float_t xtof_temp[6]={0.,t_tof->xtofpos[0],t_tof->xtofpos[1],0.,0.,t_tof->xtofpos[2]}; + Float_t ytof_temp[6]={t_tof->ytofpos[0],0.,0.,t_tof->ytofpos[1],t_tof->ytofpos[2],0.}; + tofdedx->Process(pam_event->GetOrbitalInfo()->absTime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp); + } t_tof->npmtadc = 0; + + for (Int_t hh=0; hh<12;hh++){ for (Int_t kk=0; kk<4;kk++){ - if ( tofoutput_.adctof_c[hh][kk] < 1000 ){ - // t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc); // EMILIANO - pmt_id = tof->GetPMTid(kk,hh); - t_tof->dedx.AddAt((tofoutput_.adctof_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO + pmt_id = tof->GetPMTid(kk,hh); + if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. ){ + t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc); t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); - t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 + t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07 t_tof->npmtadc++; }; }; }; +// for (Int_t hh=0; hh<12;hh++){ +// for (Int_t kk=0; kk<4;kk++){ +// if ( tofoutput_.adctof_c[hh][kk] < 1000 ){ +// // t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc); // EMILIANO +// pmt_id = tof->GetPMTid(kk,hh); +// t_tof->dedx.AddAt((tofoutput_.adctof_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO +// t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); +// t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 +// t_tof->npmtadc++; +// }; +// }; +// }; // - memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); - memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); - memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); - memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); + // new(t[ntrkentry]) ToFTrkVar(*t_tof); ntrkentry++; @@ -397,8 +480,8 @@ // for (Int_t hh=0; hh<12;hh++){ for (Int_t kk=0; kk<4;kk++){ - // new WM -// if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){ + // new WM + // if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){ if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){ // t_pmt->pmt_id = tof->GetPMTid(kk,hh); @@ -435,7 +518,7 @@ // Get tracker related variables for this track // toftrk(); -// toftrk(thelp); + // toftrk(thelp); // // Copy values in the class from the structure (we need to use a temporary class to store variables). // @@ -454,24 +537,41 @@ t_tof->beta[kk] = tofoutput_.beta_a[kk]; }; // + memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); + memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); + memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); + memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); + // + tofdedx->Process(pam_event->GetOrbitalInfo()->absTime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof); t_tof->npmtadc = 0; for (Int_t hh=0; hh<12;hh++){ for (Int_t kk=0; kk<4;kk++){ - if ( tofoutput_.adc_c[hh][kk] < 1000 ){ - // t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc); // EMILIANO - pmt_id = tof->GetPMTid(kk,hh); - t_tof->dedx.AddAt((tofoutput_.adc_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO + pmt_id = tof->GetPMTid(kk,hh); + if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. ){ + t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc); t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); - t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 + t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07 + printf(" nt %i npmtadc %i dedx %f dedx corr %f\n",nt,t_tof->npmtadc,(tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),dedx_corr[pmt_id]); t_tof->npmtadc++; }; + }; }; +// t_tof->npmtadc = 0; +// for (Int_t hh=0; hh<12;hh++){ +// for (Int_t kk=0; kk<4;kk++){ +// if ( tofoutput_.adc_c[hh][kk] < 1000 ){ +// // t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc); // EMILIANO +// pmt_id = tof->GetPMTid(kk,hh); +// t_tof->dedx.AddAt((tofoutput_.adc_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO +// t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); +// t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 +// t_tof->npmtadc++; +// }; +// }; +// }; // - memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); - memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); - memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); - memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); + // // Store the tracker track number in order to be sure to have shyncronized data during analysis // @@ -526,87 +626,96 @@ void usage(){ - cout << "------------------------------------------------------------"< create an output file with histograms \n"; - cout << " fillTree --> create an output file with trees storing the selected events \n "; - cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; - cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; - cout << "------------------------------------------------------------"< create an output file with histograms \n"; + cout << " fillTree --> create an output file with trees storing the selected events \n "; + cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; + cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; + cout << "------------------------------------------------------------"<1){ + if(argc>1){ - if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ - usage(); - return(1); - }; -// ----------------------- -// Read input parameters -// ----------------------- - DIR = gSystem->WorkingDirectory(); - LIST = ""; - OUTF = "myfile"; - OPTIONS = "+AUTO -TOF"; + if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ + usage(); + return(1); + }; + // ----------------------- + // Read input parameters + // ----------------------- + DIR = gSystem->WorkingDirectory(); + LIST = ""; + OUTF = "myfile"; + OPTIONS = "+AUTO -TOF"; - for (int i = 1; i < argc; i++){ - // -----------------------------------------------------// - if (!strcmp(argv[i], "-processDir")){ - if (++i >= argc) throw -1; - DIR = argv[i]; - cout << "processDir "<= argc) throw -1; - LIST = argv[i]; - cout << "processList "<= argc) throw -1; - OUTF = argv[i]; - cout << "outputFile "<= argc) throw -1; - OPTIONS = argv[i]; - if( OPTIONS.Contains("[") ){ - do{ - if (++i >= argc) throw -1; - OPTIONS.Append(argv[i]); - }while(!OPTIONS.Contains("]")); - }else cout << "wrong option format --> ignoring " << endl; - } - else{ - cout << "Unidentified input parameter. Ignored."<< endl; - }; - }; - }else{ - usage(); - return(1); + for (int i = 1; i < argc; i++){ + // -----------------------------------------------------// + if (!strcmp(argv[i], "-processDir")){ + if (++i >= argc) throw -1; + DIR = argv[i]; + cout << "processDir "<= argc) throw -1; + LIST = argv[i]; + cout << "processList "<= argc) throw -1; + OUTF = argv[i]; + cout << "outputFile "<= argc) throw -1; + CALIBF = argv[i]; + cout << "calibFile "<= argc) throw -1; + OPTIONS = argv[i]; + if( OPTIONS.Contains("[") ){ + do{ + if (++i >= argc) throw -1; + OPTIONS.Append(argv[i]); + }while(!OPTIONS.Contains("]")); + }else cout << "wrong option format --> ignoring " << endl; + } + else{ + cout << "Unidentified input parameter. Ignored."<< endl; + }; }; -// ----------------------- -// Check input parameters -// ----------------------- + }else{ + usage(); + return(1); + }; + // ----------------------- + // Check input parameters + // ----------------------- - return(0); + return(0); }; // @@ -614,14 +723,14 @@ int main(int argc, char **argv) { - if( HandleInputPar(argc,argv) )return(1); + if( HandleInputPar(argc,argv) )return(1); - cout << "OPTIONS "<