/[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.4 by pam-fi, Mon Mar 19 17:24:29 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            if( caltrk->crc_hcal[ipkt] ){
107                cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl;    
108                return 0; // :-(
109            }
110            for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){
111                cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl;    
112                return 0; // :-(
113            }
114        }
115    //  -----------------------
116    //  Check missing packets:
117    //  -----------------------
118    //    Readout order:
119    //    ------------------
120    //    DSP   packet board
121    //    ------------------
122    //    12    0      1
123    //    10    1      1
124    //     8    2      1
125    //     4    3      1
126    //     6    4      1
127    //     2    5      1
128    //    ------------------
129    //    11    0      2
130    //     9    1      2
131    //     7    2      2
132    //     3    3      2
133    //     5    4      2
134    //     1    5      2
135    //    ------------------
136    //  -------------------------------------------------
137    //  Check if it is first or second calibration packet
138    //  -------------------------------------------------
139        UInt_t build=0;
140        UInt_t base=0;
141        UInt_t mask=0;
142        if(classname.Contains("CalibTrk1Event")){
143            base=12;
144            mask=0x03F000;
145        }
146        if(classname.Contains("CalibTrk2Event")){
147            base=18;
148            mask=0xFC0000;
149        }
150    //  -------------------------------------------------
151    //  Count number of packets and set build variable
152    //  -------------------------------------------------
153        Int_t  npkts=0;
154        for(Int_t ipkt=0; ipkt<6; ipkt++){
155            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
156                npkts++;
157                build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
158            };
159        }
160        if( npkts==6 )return 1; // :-)
161        else cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-(  ( "<<npkts<<" instead of 6 ) --> "<<endl;    
162    
163    //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
164    
165    //  -----------------------------------------------
166    //  If missing packets: check the acq configuration
167    //  (some DSPs might be excluded from acquisition)
168    //  -----------------------------------------------
169    
170    //  -----------------------------------------------
171    //  retrieve the first run header after calib
172    //  -----------------------------------------------
173    //      PacketType *pctp;
174    //      EventCounter *cod;
175    //      cod = eh->GetCounter();
176    //      Int_t irun = cod->Get(pctp->RunHeader);
177    //      TTree *rh=(TTree*)file->Get("RunHeader");
178    //      if ( !rh || rh->IsZombie() ) throw -17;
179    //      if( rh->GetEntries() == irun ){
180    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;
181    //       return 0; // :-(
182    //      }
183    
184    //      RunHeaderEvent *run  = 0;
185    //      EventHeader    *hrun = 0;
186    //      rh->SetBranchAddress("RunHeader", &run);
187    //      rh->SetBranchAddress("Header", &hrun);
188    //      rh->GetEntry(irun);
189    // //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
190    
191    //      if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
192    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
193    //       return 0; // :-(
194    //      }
195        
196    //      if( !run->RM_ACQ_AFTER_CALIB ){
197    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;
198    //       return 0; // :-(
199    //      }
200    
201    //      UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
202    //      if( dtime > timeaftercalib ){
203    //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
204    //       return 0; // :-(
205    //      }
206        
207    //      if( (run->ACQ_BUILD_INFO & mask) != build ){
208    //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
209    //       return 0; // :-(
210    //      }
211          return 1; // :-)
212    
213    }
214    /**
215   * Method to fill the tracker calibration-parameter struct from on-line calibrations   * Method to fill the tracker calibration-parameter struct from on-line calibrations
216   */   */
217  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 228  void TrkParams::FillACalibFrom(TFile* f0
228      tr1->GetEntry(ev_reg1);      tr1->GetEntry(ev_reg1);
229      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
230      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
231    
232        // --- TEST TEST TEST TEST --- //
233        TrkParams::ValidateTrkCalib(calibdata1);
234        TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
235                    
236      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
237          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 144  void TrkParams::FillFCalibFrom(TFile* f0 Line 287  void TrkParams::FillFCalibFrom(TFile* f0
287      tr1->GetEntry(ev_reg1);      tr1->GetEntry(ev_reg1);
288      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
289      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
290    
291        // --- TEST TEST TEST TEST --- //
292        TrkParams::ValidateTrkCalib(calibdata1);
293        TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
294                    
295      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
296          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 196  void TrkParams::FillTCalibFrom(TFile* f0 Line 343  void TrkParams::FillTCalibFrom(TFile* f0
343      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
344      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
345                    
346        // --- TEST TEST TEST TEST --- //
347        TrkParams::ValidateTrkCalib(calibdata1);
348        TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
349    
350      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
351          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
352          dspn2=calibdata2->DSPnumber[i]-1;          dspn2=calibdata2->DSPnumber[i]-1;
# Line 272  void TrkParams::FillMask(TFile* f0, Int_ Line 423  void TrkParams::FillMask(TFile* f0, Int_
423    
424  };  };
425    
426    // Bool_t TrkParams::CalibIsLoaded(UInt_t time){
427    
428    //     if( !calibload ) return false;
429    
430    // };
431    
432    
433  /**  /**
434   * Static method to load calibration.   * Static method to load calibration.
435   * 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 466  Bool_t TrkParams::LoadCalib( ){
466      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
467      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
468  //    mask_.Set(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);  //    mask_.Set(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
469    //    for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal[64][12][i] << endl;
470    
471  //    };  //    };
472      // =============================================================      // =============================================================
# Line 330  Bool_t TrkParams::LoadCalib( ){ Line 489  Bool_t TrkParams::LoadCalib( ){
489  //      ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);  //      ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
490          TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);          TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
491      };      };
492    //    for(int i=0; i<12; i++) cout << " DSP "<< i << " "<< pedsigbad_.pedestal_t[64][12][i] << endl;
493      f0_c->Close();      f0_c->Close();
494  //    delete f0_c;  //    delete f0_c;
495      cout << "--------------------------------------"<<endl;      cout << "--------------------------------------"<<endl;
# Line 399  Bool_t TrkParams::Set( GL_RUN* glrun , T Line 559  Bool_t TrkParams::Set( GL_RUN* glrun , T
559      gl[index]     = q4;      gl[index]     = q4;
560      glpath[index] = q4.PATH+q4.NAME;      glpath[index] = q4.PATH+q4.NAME;
561      glload[index] = false;      glload[index] = false;
562      cout << "<< set TrkParams type "<<type<<" >>"<<endl;      cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl;
563      return true;      return true;
564  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
565    
566  };  };
567  /**  /**
568   * Set tracker parameters proper for the run, from the from input.   * Set tracker parameters proper for the run, from input.
569   * @param path  Path to parameters directory   * @param path  Path to parameters directory
570   * @param type  Parameter type   * @param type  Parameter type
571   * @return FALSE if parameter set fails.   * @return FALSE if parameter set fails.
# Line 417  Bool_t TrkParams::Set( TString path , UI Line 577  Bool_t TrkParams::Set( TString path , UI
577    
578      gl[index].TYPE= type;      gl[index].TYPE= type;
579      glpath[index] = path;      glpath[index] = path;
580      cout << "<< set TrkParams type "<<type<<" >>"<<endl;      cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl;
581      glload[index] = false;      glload[index] = false;
582    
583  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
# Line 476  Bool_t TrkParams::Set(UInt_t type){ Line 636  Bool_t TrkParams::Set(UInt_t type){
636                    
637      }      }
638    
639      cout << "<< set TrkParams type "<<type<<" >>"<<endl;      cout << "<< set TrkParams type "<<type<<" (from env var PAM_CALIB) >>"<<endl;
640  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
641      return true;      return true;
642    
# Line 518  Bool_t  TrkParams::Set( ){ Line 678  Bool_t  TrkParams::Set( ){
678          if ( !TrkParams::Set(0,dbc) )return false;          if ( !TrkParams::Set(0,dbc) )return false;
679          dbc->Close();          dbc->Close();
680      }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;
681    
682        return true;
683  }  }
684    
685  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.23