3 |
// |
// |
4 |
#include <fstream> |
#include <fstream> |
5 |
#include <string.h> |
#include <string.h> |
6 |
|
#include <iomanip> |
7 |
// |
// |
8 |
// ROOT headers |
// ROOT headers |
9 |
// |
// |
205 |
extern struct ToFInput tofinput_; |
extern struct ToFInput tofinput_; |
206 |
extern struct ToFOutput tofoutput_; |
extern struct ToFOutput tofoutput_; |
207 |
// |
// |
208 |
|
// WM variables perform dE/dx II order corrections |
209 |
|
// |
210 |
|
Float_t dedx_corr_m[100][48],dedx_corr[48]; |
211 |
|
Double_t mtime[100],t1,t2,tm; |
212 |
|
Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2; |
213 |
|
Float_t xmean1,xwidth1; |
214 |
|
Int_t ical,ii,wj,jj; |
215 |
|
// |
216 |
// Let's start! |
// Let's start! |
217 |
// |
// |
218 |
// |
// |
549 |
// |
// |
550 |
}; |
}; |
551 |
// |
// |
552 |
|
// WM reading parameter file for dE/dx II order corrections |
553 |
|
// |
554 |
|
memset(dedx_corr_m,0,100*48*sizeof(Float_t)); |
555 |
|
memset(dedx_corr,0,48*sizeof(Float_t)); |
556 |
|
memset(mtime,0,100*sizeof(Double_t)); |
557 |
|
// |
558 |
|
// Query the DB to get the file |
559 |
|
// |
560 |
|
Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,203,dbc); // parameters stored in DB in GL_PRAM table |
561 |
|
if ( error<0 ) { |
562 |
|
code = error; |
563 |
|
goto closeandexit; |
564 |
|
}; |
565 |
|
// |
566 |
|
if ( verbose ) printf(" Reading ToF dE/dx II order correction parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
567 |
|
// |
568 |
|
ical=0; // counter set to zero if first-time reading |
569 |
|
//----------------------------------------------------------- |
570 |
|
// Here I read the dEdx_korr parameters |
571 |
|
//----------------------------------------------------------- |
572 |
|
jj=0; |
573 |
|
ifstream fin((glparam->PATH+glparam->NAME).Data()); |
574 |
|
while ( !fin.eof() ){ |
575 |
|
fin>>t1>>tm>>t2; |
576 |
|
if ( verbose ) cout << setiosflags(ios::fixed) << setw(10) << setprecision(3) << tm << endl; |
577 |
|
if ( tm >= (runinfo->RUNHEADER_TIME-100000) && tm <= (runinfo->RUNTRAILER_TIME+100000) ){ |
578 |
|
mtime[jj]=tm; |
579 |
|
}; |
580 |
|
for (ii=0; ii<48;ii++){ |
581 |
|
fin>>wj>>xmean1>>xwidth1; |
582 |
|
if ( tm >= (runinfo->RUNHEADER_TIME-100000) && tm <= (runinfo->RUNTRAILER_TIME+100000) ){ |
583 |
|
dedx_corr_m[jj][ii]=xmean1; |
584 |
|
}; |
585 |
|
}; |
586 |
|
if ( tm >= (runinfo->RUNHEADER_TIME-100000) && tm <= (runinfo->RUNTRAILER_TIME+100000) ){ |
587 |
|
jj++; |
588 |
|
}; |
589 |
|
if ( jj >= 100 ){ |
590 |
|
code = -318; |
591 |
|
goto closeandexit; |
592 |
|
}; |
593 |
|
}; |
594 |
|
// |
595 |
|
fin.close(); |
596 |
|
Bool_t ff = false; |
597 |
|
while ( runinfo->RUNHEADER_TIME > mtime[ical] && ical < 100 ) { |
598 |
|
ical = ical+1; |
599 |
|
ff = true; |
600 |
|
}; |
601 |
|
if ( ff ) ical = ical-1; |
602 |
|
if ( verbose ) cout<<"rh time "<<runinfo->RUNHEADER_TIME<<" rt time "<<runinfo->RUNTRAILER_TIME<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<< " jj " << jj<< endl; |
603 |
|
if ( ical < 0 || ical >= 98 ){ |
604 |
|
code = -315; |
605 |
|
goto closeandexit; |
606 |
|
}; |
607 |
|
// |
608 |
// run over all the events of the run |
// run over all the events of the run |
609 |
// |
// |
610 |
if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n"); |
if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n"); |
638 |
// |
// |
639 |
// paranoid check |
// paranoid check |
640 |
// |
// |
641 |
if ( atime > runinfo->RUNTRAILER_TIME || atime < runinfo->RUNHEADER_TIME ) { |
if ( atime > (runinfo->RUNTRAILER_TIME+1) || atime < (runinfo->RUNHEADER_TIME-1) ) { |
642 |
if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n"); |
if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n"); |
643 |
jumped++; |
jumped++; |
644 |
goto jumpev; |
goto jumpev; |
671 |
// |
// |
672 |
// start processing |
// start processing |
673 |
// |
// |
674 |
|
// dE/dx II order correction: check time limits and interpolate time correction |
675 |
|
//================================================================== |
676 |
|
//== if time is outside time limits: |
677 |
|
//================================================================== |
678 |
|
if ( atime<mtime[ical] || atime>mtime[ical+1] ){ |
679 |
|
if ( verbose ) cout<<"Checking Time Limits!"<<endl; |
680 |
|
ical=0; |
681 |
|
while ( atime > mtime[ical] && ical < 100 ){ |
682 |
|
ical = ical+1; |
683 |
|
} |
684 |
|
ical = ical-1; |
685 |
|
if ( ical < 0 || ical >= 98 ){ |
686 |
|
code = -317; |
687 |
|
goto closeandexit; |
688 |
|
}; |
689 |
|
if ( verbose ) cout<<"abs time "<<atime<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl; |
690 |
|
}; |
691 |
|
//================================================================== |
692 |
|
//== interpolate betwen time limits |
693 |
|
//================================================================== |
694 |
|
thelp1 = mtime[ical]; |
695 |
|
thelp2 = mtime[ical+1]; |
696 |
|
for (ii=0; ii<48;ii++) { |
697 |
|
yhelp1 = dedx_corr_m[ical][ii]; |
698 |
|
yhelp2 = dedx_corr_m[ical+1][ii]; |
699 |
|
slope = (yhelp2-yhelp1)/(thelp2-thelp1); |
700 |
|
inter = yhelp1 - slope*thelp1; |
701 |
|
dedx_corr[ii] = slope*atime + inter; |
702 |
|
if ( fabs(dedx_corr[ii]) <= 0.0000001 ){ |
703 |
|
code = -316; |
704 |
|
goto closeandexit; |
705 |
|
}; |
706 |
|
}; |
707 |
|
//================================================================ |
708 |
|
//================================================================ |
709 |
// |
// |
710 |
// Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure |
// Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure |
711 |
|
// |
712 |
for (Int_t gg=0; gg<4;gg++){ |
for (Int_t gg=0; gg<4;gg++){ |
713 |
for (Int_t hh=0; hh<12;hh++){ |
for (Int_t hh=0; hh<12;hh++){ |
714 |
tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh]; |
tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh]; |
715 |
tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh]; |
tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh]; |
716 |
}; |
}; |
717 |
}; |
}; |
718 |
|
// |
719 |
for (Int_t hh=0; hh<5;hh++){ |
for (Int_t hh=0; hh<5;hh++){ |
720 |
tofinput_.patterntrig[hh]=trig->patterntrig[hh]; |
tofinput_.patterntrig[hh]=trig->patterntrig[hh]; |
721 |
}; |
}; |
756 |
for (Int_t hh=0; hh<12;hh++){ |
for (Int_t hh=0; hh<12;hh++){ |
757 |
for (Int_t kk=0; kk<4;kk++){ |
for (Int_t kk=0; kk<4;kk++){ |
758 |
if ( tofoutput_.adctof_c[hh][kk] < 1000 ){ |
if ( tofoutput_.adctof_c[hh][kk] < 1000 ){ |
|
t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc); |
|
759 |
pmt_id = tof->GetPMTid(kk,hh); |
pmt_id = tof->GetPMTid(kk,hh); |
760 |
|
t_tof->dedx.AddAt((tofoutput_.adctof_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); |
761 |
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
762 |
t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 |
t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 |
763 |
t_tof->npmtadc++; |
t_tof->npmtadc++; |
850 |
for (Int_t hh=0; hh<12;hh++){ |
for (Int_t hh=0; hh<12;hh++){ |
851 |
for (Int_t kk=0; kk<4;kk++){ |
for (Int_t kk=0; kk<4;kk++){ |
852 |
if ( tofoutput_.adc_c[hh][kk] < 1000 ){ |
if ( tofoutput_.adc_c[hh][kk] < 1000 ){ |
|
t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc); |
|
853 |
pmt_id = tof->GetPMTid(kk,hh); |
pmt_id = tof->GetPMTid(kk,hh); |
854 |
|
t_tof->dedx.AddAt((tofoutput_.adc_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); |
855 |
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
856 |
t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 |
t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 |
857 |
t_tof->npmtadc++; |
t_tof->npmtadc++; |