/[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.9 by pam-fi, Tue May 15 16:22:19 2007 UTC revision 1.21 by pam-fi, Wed Mar 5 17:00:19 2008 UTC
# Line 5  Line 5 
5    
6  #include <TrkParams.h>  #include <TrkParams.h>
7  #include <iostream>  #include <iostream>
8    #include <iomanip>
9  using namespace std;  using namespace std;
10    
11    
# Line 23  UInt_t       TrkParams::trkparamtype[] = Line 24  UInt_t       TrkParams::trkparamtype[] =
24  GL_PARAM     TrkParams::gl[]           = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()};  GL_PARAM     TrkParams::gl[]           = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()};
25  TString      TrkParams::glpath[]       = {"","","","","","",""};  TString      TrkParams::glpath[]       = {"","","","","","",""};
26  Bool_t       TrkParams::glload[]       = {false,false,false,false,false,false,false};  Bool_t       TrkParams::glload[]       = {false,false,false,false,false,false,false};
 cDbg         TrkParams::dbg_mode       = {0,0,0};  
27  // ----------------  // ----------------
28  // other parameters  // other parameters
29  // ----------------  // ----------------
30  int    TrkParams::init__pfa            = 14;//COG4  cDbg   TrkParams::init__dbg_mode       = {0,0,0};
31    //int    TrkParams::init__pfa            = 14;//COG4
32    int    TrkParams::init__pfa            = 5;//ETAL
33  int    TrkParams::init__mini_trackmode = 0;  int    TrkParams::init__mini_trackmode = 0;
34  int    TrkParams::init__mini_istepmin  = 3;  int    TrkParams::init__mini_istepmin  = 5; //3;
35  double TrkParams::init__mini_fact      = 100.;  double TrkParams::init__mini_fact      = 1.e4; //100.;
36    float  TrkParams::init__pfa_e234ax[]   = {0.,10.,10.,15.,15.,90.};
37    float  TrkParams::init__pfa_e234ay[]   = {0.,20.,90.,90.,90.,90.};
38    double TrkParams::init__deltab_0       = 0.;
39    double TrkParams::init__deltab_1       = 0.;
40    double TrkParams::init__dlt            = 1.e-5;
41    // ------------------------------------------
42    // nominal z-coordinates to define acceptance
43    // ------------------------------------------
44    int   TrkParams::nGF   = NGF;
45    float TrkParams::zGF[] = {+53.74,+53.04,+23.94,+23.44,+22.29,+21.83,+13.39,+4.49,-4.41,-13.31,-21.83,-22.22,-23.49,-24.34};
46    float TrkParams::xGF_min[] = {-20.40,-20.40,-9.00,-9.00,-8.07,-8.07,-8.07,-8.07,-8.07,-8.07,-8.07,-8.07,-9.00,-9.00};
47    float TrkParams::xGF_max[] = {+20.40,+20.40,+9.00,+9.00,+8.07,+8.07,+8.07,+8.07,+8.07,+8.07,+8.07,+8.07,+9.00,+9.00};
48    // float TrkParams::yGF_min[] = {-16.50,-16.50,-7.50,-7.50,-7.25,-6.57,-7.25,-7.25,-7.25,-7.25,-6.57,-6.75,-7.50,-7.50};
49    // float TrkParams::yGF_max[] = {+16.50,+16.50,+7.50,+7.50,+6.75,+6.57,+6.75,+6.75,+6.75,+6.75,+6.57,+7.25,+7.50,+7.50};
50    // per i piani interni alla cavita`, gli estremi sono dati dalla cavita` stessa
51    float TrkParams::yGF_min[] = {-16.50,-16.50,-7.50,-7.50,-7.25,-6.57,-6.57,-6.57,-6.57,-6.57,-6.57,-6.75,-7.50,-7.50};
52    float TrkParams::yGF_max[] = {+16.50,+16.50,+7.50,+7.50,+6.75,+6.57,+6.57,+6.57,+6.57,+6.57,+6.57,+7.25,+7.50,+7.50};
53    TString TrkParams::GF_element[] = {"S11","S12","S21","S22","T1","CUF","T2","T3","T4","T5","CLF","T6","S31","S32"};
54    
55  TrkParams::TrkParams(){  TrkParams::TrkParams(){
56    
# Line 50  float anint(float f){ Line 70  float anint(float f){
70      ret1=(float)ret;      ret1=(float)ret;
71      return ret1;              return ret1;        
72  }  }
73    
74  /**  /**
75   * Static method to set the calibration to be loaded.   * Static method to open a DB connection.
76     * HOST, USER and PASSWORD are taken from enviroment variables $PAM_DBHOST,
77     * $PAM_DBUSER and $PAM_DBPSW
78     * NB! The method create a new connection, which has to be closed by the user.
79     */
80    TSQLServer* TrkParams::SetDBConnection(){
81    
82        TString host = "mysql://localhost/pamelaprod";
83        TString user = "anonymous";
84        TString psw = "";
85        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
86        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
87        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
88        if ( !pamdbhost ) pamdbhost = "";
89        if ( !pamdbuser ) pamdbuser = "";
90        if ( !pamdbpsw ) pamdbpsw = "";
91        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
92        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
93        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
94        if(TrkParams::VerboseMode()){
95            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
96            cout<<"Connecting to DB"<<endl;
97            cout<<"HOST "<<host<<endl;
98            cout<<"USER "<<user<<endl;
99            cout<<"PSW  "<<psw<<endl;
100        }
101        TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
102        if( !dbc )return NULL;
103        if( !dbc->IsConnected() )return NULL;    
104        stringstream myquery;  // EMILIANO
105        myquery.str("");  // EMILIANO
106        myquery << "SET time_zone='+0:00'";  // EMILIANO
107        dbc->Query(myquery.str().c_str());  // EMILIANO
108        if(TrkParams::VerboseMode()){
109            cout << " ...done"<<endl;
110            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
111        }
112        
113        return dbc;
114    }
115    /**
116     * \brief Static method to set the calibration to be loaded.
117    
118   * It retrieves the calibration associated to a given run, from   * It retrieves the calibration associated to a given run, from
119   * a given DB. It fills the F77 common.   * a given DB. It fills the F77 common.
# Line 69  Bool_t TrkParams::SetCalib( GL_RUN *glru Line 131  Bool_t TrkParams::SetCalib( GL_RUN *glru
131          glrun->RUNHEADER_TIME > calib.TO_TIME     ||          glrun->RUNHEADER_TIME > calib.TO_TIME     ||
132          false ){          false ){
133    
134    
135          GL_TRK_CALIB q2;          GL_TRK_CALIB q2;
136          GL_ROOT q3;          GL_ROOT q3;
137          GL_PARAM q4;          GL_PARAM q4;
138    
139    
140            bool LOCAL_CONNECTION = false;
141            if( !dbc || (dbc && !dbc->IsConnected()) ){
142    
143                if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
144                dbc = TrkParams::SetDBConnection();
145                if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;
146    
147            }
148    
149                    
150          if(TrkParams::VerboseMode()){          if(TrkParams::VerboseMode()){
151              cout << "--------------------------------------"<<endl;              cout << "--------------------------------------"<<endl;
# Line 98  Bool_t TrkParams::SetCalib( GL_RUN *glru Line 172  Bool_t TrkParams::SetCalib( GL_RUN *glru
172              calibpatht = q4.PATH + q4.NAME;              calibpatht = q4.PATH + q4.NAME;
173          }          }
174                    
175            if(LOCAL_CONNECTION){
176                dbc->Close();
177                delete dbc;
178            }
179    
180  //    return TrkParams::LoadCalib();  //    return TrkParams::LoadCalib();
181          return true;          return true;
# Line 112  Bool_t TrkParams::SetCalib( GL_RUN *glru Line 190  Bool_t TrkParams::SetCalib( GL_RUN *glru
190   */   */
191  UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){  UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){
192    
193        UInt_t validate = 1;
194      Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};      Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
195  //    UInt_t timeaftercalib=120000; //2000;  //    UInt_t timeaftercalib=120000; //2000;
196      TString classname = caltrk->GetName();      TString classname = caltrk->GetName();
# Line 126  UInt_t TrkParams::ValidateTrkCalib( Cali Line 205  UInt_t TrkParams::ValidateTrkCalib( Cali
205                  if(TrkParams::WarningMode())cout<<"(CRC Header)";                  if(TrkParams::WarningMode())cout<<"(CRC Header)";
206  //              if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl;      //              if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl;    
207  //              return 0; // :-(  //              return 0; // :-(
208                    validate = 0;
209              }              }
210              for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){              for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){
211                  if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")";                  if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")";
212  //              if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl;      //              if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl;    
213  //              return 0; // :-(  //              return 0; // :-(
214                    validate = 0;
215              }              }
216          }          }
217      }      }
# Line 180  UInt_t TrkParams::ValidateTrkCalib( Cali Line 261  UInt_t TrkParams::ValidateTrkCalib( Cali
261              build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );              build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
262          };          };
263      }      }
264      if( npkts==6 )return 1; // :-)      if( npkts==6 ){}//return 1; // :-)
265      else {      else {
266          if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-(  ( "<<npkts<<" instead of 6 ) --> "<<endl;              if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-(  ( "<<npkts<<" instead of 6 ) --> "<<endl;    
267            validate = 0;
268      }      }
269  //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;  //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
270    
# Line 232  UInt_t TrkParams::ValidateTrkCalib( Cali Line 314  UInt_t TrkParams::ValidateTrkCalib( Cali
314  //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;  //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
315  //       return 0; // :-(  //       return 0; // :-(
316  //      }  //      }
317        return 1; // :-)  
318    //      return 1; // :-)
319    
320    //    cout << validate << endl;
321        return validate;
322    
323  }  }
324  /**  /**
# Line 241  UInt_t TrkParams::ValidateTrkCalib( Cali Line 327  UInt_t TrkParams::ValidateTrkCalib( Cali
327  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){
328    
329      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
330        ca->Reset();
331    
332      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
333      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 254  void TrkParams::FillACalibFrom(TFile* f0 Line 341  void TrkParams::FillACalibFrom(TFile* f0
341      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
342    
343      // --- TEST TEST TEST TEST --- //      // --- TEST TEST TEST TEST --- //
344      TrkParams::ValidateTrkCalib(calibdata1);  //    TrkParams::ValidateTrkCalib(calibdata1);
345      TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //    TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
346            
347        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
348        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
349        if( !test1 || !test2 ){
350            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
351            TrkParams::calib.VALIDATION = 0;
352        }
353        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
354    
355      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
356          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
357          dspn2=calibdata2->DSPnumber[i]-1;          dspn2=calibdata2->DSPnumber[i]-1;
358          /*     cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl; */  //      cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl;      
359          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
360              Int_t j=(ii/128);              Int_t j=(ii/128);
361              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
362              ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];              if(dspn1>=0 && dspn1<12){
363              ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
364              ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
365              ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
366              ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
367              ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];                  if(calibdata1->DSPbad_par[i][ii]==0)
368              ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);                      ca->bad[jj][j][dspn1]=1;
369              ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);                  else if(calibdata1->DSPbad_par[i][ii]==1)
370              //        cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;                      ca->bad[jj][j][dspn1]=0;
371              //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
372              //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;                  //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
373              //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;              }
374            
375              //              if(dspn2>=0 && dspn2<12){
376              // invert the bad                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
377              //                  ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
378              if(calibdata1->DSPbad_par[i][ii]==0)                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
379                  ca->bad[jj][j][dspn1]=1;                  ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
380              else if(calibdata1->DSPbad_par[i][ii]==1)                  if(calibdata2->DSPbad_par[i][ii]==0)
381                  ca->bad[jj][j][dspn1]=0;                      ca->bad[jj][j][dspn2]=1;
382              if(calibdata2->DSPbad_par[i][ii]==0)                  else if(calibdata2->DSPbad_par[i][ii]==1)
383                  ca->bad[jj][j][dspn2]=1;                      ca->bad[jj][j][dspn2]=0;
384              else if(calibdata2->DSPbad_par[i][ii]==1)                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
385                  ca->bad[jj][j][dspn2]=0;                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
386                }
387          };          };
388      };      };
389                    
# Line 300  void TrkParams::FillACalibFrom(TFile* f0 Line 396  void TrkParams::FillACalibFrom(TFile* f0
396  void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){  void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
397    
398      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
399    //    ca->Reset();
400    
401      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
402      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 313  void TrkParams::FillFCalibFrom(TFile* f0 Line 410  void TrkParams::FillFCalibFrom(TFile* f0
410      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
411    
412      // --- TEST TEST TEST TEST --- //      // --- TEST TEST TEST TEST --- //
413      TrkParams::ValidateTrkCalib(calibdata1);  //     TrkParams::ValidateTrkCalib(calibdata1);
414      TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
415        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
416        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
417        if( !test1 || !test2 ){
418            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
419            TrkParams::calib.VALIDATION = 0;
420        }
421        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
422                    
423      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
424          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 323  void TrkParams::FillFCalibFrom(TFile* f0 Line 427  void TrkParams::FillFCalibFrom(TFile* f0
427          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
428              Int_t j=(ii/128);              Int_t j=(ii/128);
429              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
430              ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];              if(dspn1>=0 && dspn1<12){
431              ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
432              ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
433              ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];                  if(calibdata1->DSPbad_par[i][ii]==0)
434              //        cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;                      ca->bad[jj][j][dspn1]=1;
435              //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;                  else if(calibdata1->DSPbad_par[i][ii]==1)
436              //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;                      ca->bad[jj][j][dspn1]=0;
437              //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
438                            //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
439              //              }
440              // invert the bad              if(dspn2>=0 && dspn2<12){
441              //                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
442              if(calibdata1->DSPbad_par[i][ii]==0)                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
443                  ca->bad[jj][j][dspn1]=1;                  if(calibdata2->DSPbad_par[i][ii]==0)
444              else if(calibdata1->DSPbad_par[i][ii]==1)                      ca->bad[jj][j][dspn2]=1;
445                  ca->bad[jj][j][dspn1]=0;                  else if(calibdata2->DSPbad_par[i][ii]==1)
446              if(calibdata2->DSPbad_par[i][ii]==0)                      ca->bad[jj][j][dspn2]=0;
447                  ca->bad[jj][j][dspn2]=1;                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
448              else if(calibdata2->DSPbad_par[i][ii]==1)                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
449                  ca->bad[jj][j][dspn2]=0;              }
450          };          };
451      };      };
452                    
# Line 355  void TrkParams::FillFCalibFrom(TFile* f0 Line 459  void TrkParams::FillFCalibFrom(TFile* f0
459  void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){  void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
460    
461      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
462    //    ca->Reset();
463    
464      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
465      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 368  void TrkParams::FillTCalibFrom(TFile* f0 Line 473  void TrkParams::FillTCalibFrom(TFile* f0
473      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
474                    
475      // --- TEST TEST TEST TEST --- //      // --- TEST TEST TEST TEST --- //
476      TrkParams::ValidateTrkCalib(calibdata1);  //     TrkParams::ValidateTrkCalib(calibdata1);
477      TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
478        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
479        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
480        if( !test1 || !test2 ){
481            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
482            TrkParams::calib.VALIDATION = 0;
483        }
484        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
485    
486      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
487          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 378  void TrkParams::FillTCalibFrom(TFile* f0 Line 490  void TrkParams::FillTCalibFrom(TFile* f0
490          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
491              Int_t j=(ii/128);              Int_t j=(ii/128);
492              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
493              ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);              if(dspn1>=0 && dspn1<12){
494              ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
495              ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
496              ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);                  }
497                if(dspn2>=0 && dspn2<12){
498                    ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
499                    ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
500                }  
501          };          };
502      };      };
503                    
# Line 404  void TrkParams::FillTCalibFrom(TString p Line 520  void TrkParams::FillTCalibFrom(TString p
520  void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){  void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
521            
522      cTrkMask *ma = &mask_;      cTrkMask *ma = &mask_;
523        ma->Reset();
524    
525      TrkCalib *calib = new TrkCalib();      TrkCalib *calib = new TrkCalib();
526    
# Line 426  void TrkParams::FillMask(TFile* f0, Int_ Line 543  void TrkParams::FillMask(TFile* f0, Int_
543              tr->GetEntry(ev_reg2);              tr->GetEntry(ev_reg2);
544          }          }
545          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){
546              for(Int_t ivk=0; ivk<NVK; ivk++){              Int_t view   = calib->GetView(ipkt);
547                  Int_t view   = calib->GetView(ipkt);              if( (view-1)>= 0 && (view-1)<12 ){
548                  Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);                  for(Int_t ivk=0; ivk<NVK; ivk++){
549                  Float_t sigmin = 0.;                      Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);
550                  if(view%2)sigmin = 6.5;                      Float_t sigmin = 0.;
551                  else      sigmin = 2.5;                      if(view%2)sigmin = 6.5;
552                  Int_t mask = 1;                      else      sigmin = 2.5;
553                  if( sigm<sigmin )mask = 0;                      Int_t mask = 1;
554                                    if( sigm<sigmin )mask = 0;              
555                  ma->mask_vk_run[ivk][view-1] = mask;                      ma->mask_vk_run[ivk][view-1] = mask;                    
556                                }      
557  //              if(mask==0)cout<< " VIEW "<<view<<" VK "<<ivk+1<<" -- <SIG> "<<sigm<<" ---> MASKED!"<<endl;              }
             }    
558          }          }
559          if(tr)tr->Delete();          if(tr)tr->Delete();
560      }      }
561    
562        if(TrkParams::VerboseMode()){
563            for(Int_t iv=0; iv<NVIEW; iv++){
564                cout<<"view "<<setw(3)<<iv<<": ";
565                for(Int_t ivk=0; ivk<NVK; ivk++)cout<<ma->mask_vk_run[ivk][iv];
566                cout << endl;
567            }
568        }
569    
570      if(calib)calib->Delete();      if(calib)calib->Delete();
571    
572  };  };
# Line 455  void TrkParams::FillMask(TFile* f0, Int_ Line 579  void TrkParams::FillMask(TFile* f0, Int_
579    
580    
581  /**  /**
582   * Static method to load calibration.   * \brief Static method to load calibration.
583   * Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the   * Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens after the method TrkParams::SetCalib(***) is called.
  * first time the method is called (but it does not work becouse I didn't set any  
  * default calibration for the moment) or  after the method TrkParams::SetCalib(***) is called.  
584   */   */
585  Bool_t TrkParams::LoadCalib( ){  Bool_t TrkParams::LoadCalib( ){
586    
# Line 492  Bool_t TrkParams::LoadCalib( ){ Line 614  Bool_t TrkParams::LoadCalib( ){
614          cout << " - full+truncated parameters "<<endl;          cout << " - full+truncated parameters "<<endl;
615      }      }
616      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
617      if(TrkParams::VerboseMode())cout << " - VK-mask "<<endl;      if(TrkParams::VerboseMode())cout << " - VK-mask (RUN-by-RUN)"<<endl;
618      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
619    
620      // =============================================================      // =============================================================
# Line 532  Int_t TrkParams::GetIndex( UInt_t type ) Line 654  Int_t TrkParams::GetIndex( UInt_t type )
654   * @param dbc   Database   * @param dbc   Database
655   * @param type  Parameter type   * @param type  Parameter type
656   * @return FALSE if parameter set fails.   * @return FALSE if parameter set fails.
657   * If glrun==NULL the last parameter entry from GL_PARAM table is set.   * If glrun==NULL the first parameter entry from GL_PARAM table is set.
658   * If dbc==NULL, try to open a connection taking DB-connection   * If dbc==NULL, try to open a connection taking DB-connection
659   * parameters from PAMELA environment variables.   * parameters from PAMELA environment variables.
660   */   */
# Line 542  Bool_t TrkParams::Set( GL_RUN* glrun , T Line 664  Bool_t TrkParams::Set( GL_RUN* glrun , T
664      UInt_t index = TrkParams::GetIndex( type );      UInt_t index = TrkParams::GetIndex( type );
665      if(index < 0)return false;      if(index < 0)return false;
666    
667        UInt_t runheadtime=0;
668        UInt_t runid=0;
669    //    UInt_t runheadtime = numeric_limits<UInt_t>::max();
670        if(glrun){
671            runheadtime = glrun->RUNHEADER_TIME;
672            runid       = glrun->ID;
673        }else cout <<"Bool_t TrkParams::Set(GL_RUN*,TSQLServer*,UInt_t) >> Missing run info -- taking first entry (**WARNING** check that this is ok!! )"<<endl;
674    
675    //    if(TrkParams::VerboseMode())
676        if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" from DB << RUN "<<runid<<endl;
677    
678    
679      if( !TrkParams::IsLoaded(type) ||      if( !TrkParams::IsLoaded(type) ||
680          glrun->RUNHEADER_TIME < gl[index].FROM_TIME   ||          runheadtime < gl[index].FROM_TIME   ||
681          glrun->RUNHEADER_TIME > gl[index].TO_TIME     ||                  runheadtime > gl[index].TO_TIME     ||  
682          false ){          false ){
683    
684            bool LOCAL_CONNECTION = false;
685          if( !dbc || (dbc && !dbc->IsConnected()) ){          if( !dbc || (dbc && !dbc->IsConnected()) ){
686    
687              if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;              if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
688              TString host = "mysql://localhost/pamelaprod";              dbc = TrkParams::SetDBConnection();
689              TString user = "anonymous";              if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;
             TString psw = "";  
             const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");  
             const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");  
             const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");  
             if ( !pamdbhost ) pamdbhost = "";  
             if ( !pamdbuser ) pamdbuser = "";  
             if ( !pamdbpsw ) pamdbpsw = "";  
             if ( strcmp(pamdbhost,"") ) host = pamdbhost;  
             if ( strcmp(pamdbuser,"") ) user = pamdbuser;  
             if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;  
             if(TrkParams::VerboseMode()){  
                 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
                 cout<<"Connecting to DB"<<endl;  
                 cout<<"HOST "<<host<<endl;  
                 cout<<"USER "<<user<<endl;  
                 cout<<"PSW  "<<psw<<endl;  
             }  
             dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());  
             if( !dbc )return false;  
             if( !dbc->IsConnected() )return false;      
             if(TrkParams::VerboseMode()){  
                 cout << " ...done"<<endl;  
                 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
             }  
         }  
690    
691            }
         UInt_t runheadtime = numeric_limits<UInt_t>::max();  
         if(glrun)runheadtime = glrun->RUNHEADER_TIME;  
         else cout <<"Missing run info -- taking last entry "<<endl;  
692    
693          GL_PARAM q4;          GL_PARAM q4;
694          if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;          if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;      
695            if(LOCAL_CONNECTION){
696                dbc->Close();
697                delete dbc;
698            }
699          gl[index]     = q4;          gl[index]     = q4;
700          glpath[index] = q4.PATH+q4.NAME;          glpath[index] = q4.PATH+q4.NAME;
701          glload[index] = false;          glload[index] = false;
702          if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl;  
703          return true;          return true;
704    
705      }      }
# Line 609  Bool_t TrkParams::Set( TString path , UI Line 719  Bool_t TrkParams::Set( TString path , UI
719    
720      gl[index].TYPE= type;      gl[index].TYPE= type;
721      glpath[index] = path;      glpath[index] = path;
722      if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl;      if(TrkParams::VerboseMode())
723            cout << "<< set TrkParams type "<<type<<" from path << "<<path<<endl;
724      glload[index] = false;      glload[index] = false;
725    
726  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
# Line 625  Bool_t TrkParams::Set( TString path , UI Line 736  Bool_t TrkParams::Set( TString path , UI
736   */   */
737  Bool_t TrkParams::Set(UInt_t type){  Bool_t TrkParams::Set(UInt_t type){
738    
     UInt_t index = TrkParams::GetIndex( type );  
     if(index < 0)return false;  
739    
740      gl[index].TYPE= type;      return Set(0,0,type);
     glload[index] = false;  
741    
     // -----------------------------------------  
     // check if enviroment variables are defined  
     // -----------------------------------------  
     glpath[index] = gSystem->Getenv("PAM_CALIB");  
   
     if( !glpath[index].IsNull() ){  
       
         switch(type){  
         case 1:  
             glpath[index].Append("/trk-param/field_param-0/");  
             break;  
         case 2:  
             glpath[index].Append("/trk-param/mip_param-0/");  
             break;  
         case 3:  
             glpath[index].Append("/trk-param/charge_param-1/");  
             break;  
         case 4:  
             glpath[index].Append("/trk-param/eta_param-0/");  
             break;  
         case 5:  
             glpath[index].Append("/trk-param/align_param-0/");  
             break;  
         case 6:  
             glpath[index].Append("/trk-param/mask_param-1/");  
             break;  
         case 7:  
             glpath[index].Append("/trk-param/default_calib/");  
             break;  
         }  
           
     }else{  
         cout << " TrkParams::Set( UInt_t type) ==> No PAMELA environment variables defined "<<endl;  
         return false;  
           
     }  
   
     if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" (from env var PAM_CALIB) >>"<<endl;  
 //    return TrkParams::Load(type);  
     return true;  
742    
743  };  };
744  /**  /**
# Line 681  Bool_t TrkParams::Set(UInt_t type){ Line 749  Bool_t TrkParams::Set(UInt_t type){
749   */   */
750  Bool_t  TrkParams::Set( ){  Bool_t  TrkParams::Set( ){
751    
     Bool_t connected = false;  
752    
753  //    cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;      for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false;
     TString host = "mysql://localhost/pamelaprod";  
     TString user = "anonymous";  
     TString psw = "";  
     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");  
     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");  
     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");  
     if ( !pamdbhost ) pamdbhost = "";  
     if ( !pamdbuser ) pamdbuser = "";  
     if ( !pamdbpsw ) pamdbpsw = "";  
     if ( strcmp(pamdbhost,"") ) host = pamdbhost;  
     if ( strcmp(pamdbuser,"") ) user = pamdbuser;  
     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;  
     if(TrkParams::VerboseMode()){  
         cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
         cout<<"Connecting to DB"<<endl;  
         cout<<"HOST "<<host<<endl;  
         cout<<"USER "<<user<<endl;  
         cout<<"PSW  "<<psw<<endl;  
     }  
     TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());  
     if( dbc || dbc->IsConnected() )connected = true;  
     else cout << " >> DB connection FAILED!!!"<<endl;  
     if(TrkParams::VerboseMode())cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
       
     if(connected){  
         if ( !TrkParams::Set(0,dbc) )return false;  
         dbc->Close();  
     }else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false;  
754    
755      return true;      return true;
756  }  }
# Line 854  float TrkParams::GetBZ(float* v){ Line 893  float TrkParams::GetBZ(float* v){
893  }  }
894    
895    
   
896  /**  /**
897   * \brief Set tracking mode (0=standard. 1=???)   * \brief Set tracking mode (0=standard. 1=???)
898   */   */
899  void TrkParams::SetTrackingMode(int trackmode) {  void TrkParams::SetTrackingMode(int trackmode) {
900      init__mini_trackmode = trackmode;      init__mini_trackmode = trackmode;
901      SetTrackingMode();      SetTrackingMode(); //fill F77 common
902  };  };
903  /**  /**
904   * \brief Set fit-precision factor (typical value fact=100.)   * \brief Set fit-precision factor (typical value fact=100.)
905   */   */
906  void TrkParams::SetPrecisionFactor(double fact){  void TrkParams::SetPrecisionFactor(double fact){
907      init__mini_fact      = fact;      init__mini_fact      = fact;
908      SetPrecisionFactor();      SetPrecisionFactor(); //fill F77 common
909  };  };
910  /**  /**
911   * \brief Set minimum number of step in track fitting   * \brief Set minimum number of step in track fitting
912   */   */
913  void TrkParams::SetStepMin(int istepmin){  void TrkParams::SetStepMin(int istepmin){
914      init__mini_istepmin  = istepmin;      init__mini_istepmin  = istepmin;
915      SetStepMin();      SetStepMin(); //fill F77 common
916    };
917    /**
918     * \brief Set deltaB parameters (id=0,1)
919     */
920    void TrkParams::SetDeltaB(int id,double db){
921        if(id!=0 && id!=1)cout << "void TrkParams::SetDeltaB(int id,double db) -- wrong input parameters: "<<id<<" "<<db<<endl;
922        if(id==0)init__deltab_0 = db;
923        if(id==1)init__deltab_1 = db;
924        SetDeltaB(); //fill F77 common
925    };
926    /**
927     * \brief Set DLT-grkuta precision factor (default 1.e-4)
928     */
929    void TrkParams::SetDLT(double fact){
930        init__dlt               = fact;
931        SetDLT(); //fill F77 common
932  };  };
933    
934  /**  /**
935     * \brief Fill F77 commons with PFA settings
936     */
937    void TrkParams::SetPFA(){
938        sw_.pfaid = init__pfa;    
939        for(int i=0; i<6; i++){
940            pfa_.e234ax[i] = init__pfa_e234ax[i];
941            pfa_.e234ay[i] = init__pfa_e234ay[i];
942        }
943    };
944    /**
945   * \brief Set p.f.a.   * \brief Set p.f.a.
946   *   *
947   * Implemented algorythms:   * Implemented algorythms:
948   * 0  ETA (default)   * 0  ETA
949   * 1  ---   * 1  ---
950   * 2  ETA2   * 2  ETA2
951   * 3  ETA3   * 3  ETA3
952   * 4  ETA4   * 4  ETA4
953     * 5  ETAL ==> ETA+LANDI
954   * 10 COG   * 10 COG
955   * 11 COG1   * 11 COG1
956   * 12 COG2   * 12 COG2
# Line 894  void TrkParams::SetStepMin(int istepmin) Line 959  void TrkParams::SetStepMin(int istepmin)
959   */   */
960  void TrkParams::SetPFA(int pfaid){  void TrkParams::SetPFA(int pfaid){
961      init__pfa  = pfaid;      init__pfa  = pfaid;
962      SetPFA();      SetPFA(); //fill F77 common
963    };
964    /**
965     * \brief Set p.f.a. angular intervals
966     *
967     * This methods allows to set amgular intervals to apply ETA2,ETA3 or ETA4
968     * algorythm, in case ETA or ETAL is set (see TrkParams::SetPFA(int pfaid)).
969     * @param v Pointer to a vector of 12 components, which represent the
970     * angular limits for ETA2,ETA3 and ETA4, for x and y views, respectivelly.
971     *
972     */
973    void TrkParams::SetPFA(float *v){
974        for(int i=0; i<6; i++){
975            init__pfa_e234ax[i]  = v[i];
976            init__pfa_e234ay[i]  = v[i+6];
977        }
978        SetPFA(); //fill F77 common
979  };  };
980    
981    
982  /**  /**
983   * \brief Get spatial resolution.   * \brief Get spatial resolution.
984   *   *
# Line 918  float TrkParams::GetResolution(int view, Line 1001  float TrkParams::GetResolution(int view,
1001    
1002    
1003    
1004    
1005  ClassImp(TrkParams);  ClassImp(TrkParams);

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.23