/[PAMELA software]/DarthVader/TrackerLevel2/src/TrkParams.cpp
ViewVC logotype

Diff of /DarthVader/TrackerLevel2/src/TrkParams.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by pam-fi, Fri Feb 16 14:56:01 2007 UTC revision 1.5 by pam-fi, Wed Mar 21 11:05:39 2007 UTC
# Line 49  float anint(float f){ Line 49  float anint(float f){
49   */   */
50  Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){  Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){
51    
52      GL_TRK_CALIB q2;      if( !CalibIsLoaded()                          ||
53      GL_ROOT q3;          (glrun->TRK_CALIB_USED==104 && !calib104) ||
54      GL_PARAM q4;          (glrun->TRK_CALIB_USED!=104 && calib104)  ||
55            glrun->RUNHEADER_TIME < calib.FROM_TIME   ||
56      if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) )return false;          glrun->RUNHEADER_TIME > calib.TO_TIME     ||
57      if(q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2)          false ){
58          printf("WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2);    
59      if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) )return false;          GL_TRK_CALIB q2;
60            GL_ROOT q3;
61      calib      = q2;          GL_PARAM q4;
62      calibpathf = q3.PATH + q3.NAME;          
63      calib104   = (glrun->TRK_CALIB_USED==104);          cout << " UPDATING calibration -- run-header time "<< glrun->RUNHEADER_TIME <<endl;
64      calibload  = kFALSE;          if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) ){
65      if(calib104){              cout << "Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_TRK_CALIB "<<endl;
66          if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false;              return false;
67          calibpatht = q4.PATH + q4.NAME;          }
68      }          if( q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2 )
69                printf("WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2);      
70            if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) ){
71                cout << "Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_ROOT "<<endl;
72                return false;
73            }
74    
75            cout << "selected "<<q2.ID<<" from_time "<<q2.FROM_TIME<<" to time "<<q2.TO_TIME<<" --> VALIDATION "<<q2.VALIDATION<<endl;
76            calib      = q2;
77            calibpathf = q3.PATH + q3.NAME;
78            calib104   = (glrun->TRK_CALIB_USED==104);
79            calibload  = kFALSE;
80            if(calib104){
81                if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false;
82                calibpatht = q4.PATH + q4.NAME;
83            }
84            
85    
86  //    return TrkParams::LoadCalib();  //    return TrkParams::LoadCalib();
87      return true;          return true;
88        }
89    
90        return false;
91  };  };
92    
93  /**  /**
94     * Method to "validate" tracker calibration. Implemented for test purpose. Effective implementation
95     * in YodaProfiler.
96     */
97    UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){
98    
99        Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
100    //    UInt_t timeaftercalib=120000; //2000;
101        TString classname = caltrk->GetName();
102    //  ----------
103    //  Check CRCs
104    //  ----------
105        for(Int_t ipkt=0; ipkt<6; ipkt++){
106            cout << "DSP n. "<<caltrk->DSPnumber[ipkt]<<endl;
107            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
108                if( caltrk->crc_hcal[ipkt] ){
109                    cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl;    
110    //              return 0; // :-(
111                }
112                for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){
113                    cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl;    
114    //              return 0; // :-(
115                }
116            }
117        }
118    //  -----------------------
119    //  Check missing packets:
120    //  -----------------------
121    //    Readout order:
122    //    ------------------
123    //    DSP   packet board
124    //    ------------------
125    //    12    0      1
126    //    10    1      1
127    //     8    2      1
128    //     4    3      1
129    //     6    4      1
130    //     2    5      1
131    //    ------------------
132    //    11    0      2
133    //     9    1      2
134    //     7    2      2
135    //     3    3      2
136    //     5    4      2
137    //     1    5      2
138    //    ------------------
139    //  -------------------------------------------------
140    //  Check if it is first or second calibration packet
141    //  -------------------------------------------------
142        UInt_t build=0;
143        UInt_t base=0;
144        UInt_t mask=0;
145        if(classname.Contains("CalibTrk1Event")){
146            base=12;
147            mask=0x03F000;
148        }
149        if(classname.Contains("CalibTrk2Event")){
150            base=18;
151            mask=0xFC0000;
152        }
153    //  -------------------------------------------------
154    //  Count number of packets and set build variable
155    //  -------------------------------------------------
156        Int_t  npkts=0;
157        for(Int_t ipkt=0; ipkt<6; ipkt++){
158            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
159                npkts++;
160                build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
161            };
162        }
163        if( npkts==6 )return 1; // :-)
164        else cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-(  ( "<<npkts<<" instead of 6 ) --> "<<endl;    
165    
166    //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
167    
168    //  -----------------------------------------------
169    //  If missing packets: check the acq configuration
170    //  (some DSPs might be excluded from acquisition)
171    //  -----------------------------------------------
172    
173    //  -----------------------------------------------
174    //  retrieve the first run header after calib
175    //  -----------------------------------------------
176    //      PacketType *pctp;
177    //      EventCounter *cod;
178    //      cod = eh->GetCounter();
179    //      Int_t irun = cod->Get(pctp->RunHeader);
180    //      TTree *rh=(TTree*)file->Get("RunHeader");
181    //      if ( !rh || rh->IsZombie() ) throw -17;
182    //      if( rh->GetEntries() == irun ){
183    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;
184    //       return 0; // :-(
185    //      }
186    
187    //      RunHeaderEvent *run  = 0;
188    //      EventHeader    *hrun = 0;
189    //      rh->SetBranchAddress("RunHeader", &run);
190    //      rh->SetBranchAddress("Header", &hrun);
191    //      rh->GetEntry(irun);
192    // //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
193    
194    //      if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
195    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
196    //       return 0; // :-(
197    //      }
198        
199    //      if( !run->RM_ACQ_AFTER_CALIB ){
200    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;
201    //       return 0; // :-(
202    //      }
203    
204    //      UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
205    //      if( dtime > timeaftercalib ){
206    //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
207    //       return 0; // :-(
208    //      }
209        
210    //      if( (run->ACQ_BUILD_INFO & mask) != build ){
211    //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
212    //       return 0; // :-(
213    //      }
214          return 1; // :-)
215    
216    }
217    /**
218   * Method to fill the tracker calibration-parameter struct from on-line calibrations   * Method to fill the tracker calibration-parameter struct from on-line calibrations
219   */   */
220  void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){  void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
# Line 89  void TrkParams::FillACalibFrom(TFile* f0 Line 231  void TrkParams::FillACalibFrom(TFile* f0
231      tr1->GetEntry(ev_reg1);      tr1->GetEntry(ev_reg1);
232      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
233      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
234    
235        // --- TEST TEST TEST TEST --- //
236        TrkParams::ValidateTrkCalib(calibdata1);
237        TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
238                    
239      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
240          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 144  void TrkParams::FillFCalibFrom(TFile* f0 Line 290  void TrkParams::FillFCalibFrom(TFile* f0
290      tr1->GetEntry(ev_reg1);      tr1->GetEntry(ev_reg1);
291      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
292      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
293    
294        // --- TEST TEST TEST TEST --- //
295        TrkParams::ValidateTrkCalib(calibdata1);
296        TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
297                    
298      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
299          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 196  void TrkParams::FillTCalibFrom(TFile* f0 Line 346  void TrkParams::FillTCalibFrom(TFile* f0
346      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
347      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
348                    
349        // --- TEST TEST TEST TEST --- //
350        TrkParams::ValidateTrkCalib(calibdata1);
351        TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
352    
353      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
354          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
355          dspn2=calibdata2->DSPnumber[i]-1;          dspn2=calibdata2->DSPnumber[i]-1;
# Line 272  void TrkParams::FillMask(TFile* f0, Int_ Line 426  void TrkParams::FillMask(TFile* f0, Int_
426    
427  };  };
428    
429    // Bool_t TrkParams::CalibIsLoaded(UInt_t time){
430    
431    //     if( !calibload ) return false;
432    
433    // };
434    
435    
436  /**  /**
437   * Static method to load calibration.   * Static method to load calibration.
438   * Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the   * Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the
# Line 308  Bool_t TrkParams::LoadCalib( ){ Line 469  Bool_t TrkParams::LoadCalib( ){
469      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
470      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
471  //    mask_.Set(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);  //    mask_.Set(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
472    //    for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal[64][12][i] << endl;
473    
474  //    };  //    };
475      // =============================================================      // =============================================================
# Line 330  Bool_t TrkParams::LoadCalib( ){ Line 492  Bool_t TrkParams::LoadCalib( ){
492  //      ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);  //      ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
493          TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);          TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
494      };      };
495    //    for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal_t[64][12][i] << endl;
496      f0_c->Close();      f0_c->Close();
497  //    delete f0_c;  //    delete f0_c;
498      cout << "--------------------------------------"<<endl;      cout << "--------------------------------------"<<endl;
# Line 399  Bool_t TrkParams::Set( GL_RUN* glrun , T Line 562  Bool_t TrkParams::Set( GL_RUN* glrun , T
562      gl[index]     = q4;      gl[index]     = q4;
563      glpath[index] = q4.PATH+q4.NAME;      glpath[index] = q4.PATH+q4.NAME;
564      glload[index] = false;      glload[index] = false;
565      cout << "<< set TrkParams type "<<type<<" >>"<<endl;      cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl;
566      return true;      return true;
567  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
568    
569  };  };
570  /**  /**
571   * Set tracker parameters proper for the run, from the from input.   * Set tracker parameters proper for the run, from input.
572   * @param path  Path to parameters directory   * @param path  Path to parameters directory
573   * @param type  Parameter type   * @param type  Parameter type
574   * @return FALSE if parameter set fails.   * @return FALSE if parameter set fails.
# Line 417  Bool_t TrkParams::Set( TString path , UI Line 580  Bool_t TrkParams::Set( TString path , UI
580    
581      gl[index].TYPE= type;      gl[index].TYPE= type;
582      glpath[index] = path;      glpath[index] = path;
583      cout << "<< set TrkParams type "<<type<<" >>"<<endl;      cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl;
584      glload[index] = false;      glload[index] = false;
585    
586  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
# Line 476  Bool_t TrkParams::Set(UInt_t type){ Line 639  Bool_t TrkParams::Set(UInt_t type){
639                    
640      }      }
641    
642      cout << "<< set TrkParams type "<<type<<" >>"<<endl;      cout << "<< set TrkParams type "<<type<<" (from env var PAM_CALIB) >>"<<endl;
643  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
644      return true;      return true;
645    
# Line 518  Bool_t  TrkParams::Set( ){ Line 681  Bool_t  TrkParams::Set( ){
681          if ( !TrkParams::Set(0,dbc) )return false;          if ( !TrkParams::Set(0,dbc) )return false;
682          dbc->Close();          dbc->Close();
683      }else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false;      }else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false;
684    
685        return true;
686  }  }
687    
688  /**  /**

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.23