/[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.20 by pam-fi, Tue Jan 15 14:29:46 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  TrkParams::TrkParams(){  TrkParams::TrkParams(){
43    
# Line 50  float anint(float f){ Line 57  float anint(float f){
57      ret1=(float)ret;      ret1=(float)ret;
58      return ret1;              return ret1;        
59  }  }
60    
61  /**  /**
62   * Static method to set the calibration to be loaded.   * Static method to open a DB connection.
63     * HOST, USER and PASSWORD are taken from enviroment variables $PAM_DBHOST,
64     * $PAM_DBUSER and $PAM_DBPSW
65     * NB! The method create a new connection, which has to be closed by the user.
66     */
67    TSQLServer* TrkParams::SetDBConnection(){
68    
69        TString host = "mysql://localhost/pamelaprod";
70        TString user = "anonymous";
71        TString psw = "";
72        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
73        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
74        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
75        if ( !pamdbhost ) pamdbhost = "";
76        if ( !pamdbuser ) pamdbuser = "";
77        if ( !pamdbpsw ) pamdbpsw = "";
78        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
79        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
80        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
81        if(TrkParams::VerboseMode()){
82            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
83            cout<<"Connecting to DB"<<endl;
84            cout<<"HOST "<<host<<endl;
85            cout<<"USER "<<user<<endl;
86            cout<<"PSW  "<<psw<<endl;
87        }
88        TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
89        if( !dbc )return NULL;
90        if( !dbc->IsConnected() )return NULL;    
91        stringstream myquery;  // EMILIANO
92        myquery.str("");  // EMILIANO
93        myquery << "SET time_zone='+0:00'";  // EMILIANO
94        dbc->Query(myquery.str().c_str());  // EMILIANO
95        if(TrkParams::VerboseMode()){
96            cout << " ...done"<<endl;
97            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
98        }
99        
100        return dbc;
101    }
102    /**
103     * \brief Static method to set the calibration to be loaded.
104    
105   * It retrieves the calibration associated to a given run, from   * It retrieves the calibration associated to a given run, from
106   * 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 118  Bool_t TrkParams::SetCalib( GL_RUN *glru
118          glrun->RUNHEADER_TIME > calib.TO_TIME     ||          glrun->RUNHEADER_TIME > calib.TO_TIME     ||
119          false ){          false ){
120    
121    
122          GL_TRK_CALIB q2;          GL_TRK_CALIB q2;
123          GL_ROOT q3;          GL_ROOT q3;
124          GL_PARAM q4;          GL_PARAM q4;
125    
126    
127            bool LOCAL_CONNECTION = false;
128            if( !dbc || (dbc && !dbc->IsConnected()) ){
129    
130                if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
131                dbc = TrkParams::SetDBConnection();
132                if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;
133    
134            }
135    
136                    
137          if(TrkParams::VerboseMode()){          if(TrkParams::VerboseMode()){
138              cout << "--------------------------------------"<<endl;              cout << "--------------------------------------"<<endl;
# Line 98  Bool_t TrkParams::SetCalib( GL_RUN *glru Line 159  Bool_t TrkParams::SetCalib( GL_RUN *glru
159              calibpatht = q4.PATH + q4.NAME;              calibpatht = q4.PATH + q4.NAME;
160          }          }
161                    
162            if(LOCAL_CONNECTION){
163                dbc->Close();
164                delete dbc;
165            }
166    
167  //    return TrkParams::LoadCalib();  //    return TrkParams::LoadCalib();
168          return true;          return true;
# Line 112  Bool_t TrkParams::SetCalib( GL_RUN *glru Line 177  Bool_t TrkParams::SetCalib( GL_RUN *glru
177   */   */
178  UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){  UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){
179    
180        UInt_t validate = 1;
181      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};
182  //    UInt_t timeaftercalib=120000; //2000;  //    UInt_t timeaftercalib=120000; //2000;
183      TString classname = caltrk->GetName();      TString classname = caltrk->GetName();
# Line 126  UInt_t TrkParams::ValidateTrkCalib( Cali Line 192  UInt_t TrkParams::ValidateTrkCalib( Cali
192                  if(TrkParams::WarningMode())cout<<"(CRC Header)";                  if(TrkParams::WarningMode())cout<<"(CRC Header)";
193  //              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;    
194  //              return 0; // :-(  //              return 0; // :-(
195                    validate = 0;
196              }              }
197              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] ){
198                  if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")";                  if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")";
199  //              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;    
200  //              return 0; // :-(  //              return 0; // :-(
201                    validate = 0;
202              }              }
203          }          }
204      }      }
# Line 180  UInt_t TrkParams::ValidateTrkCalib( Cali Line 248  UInt_t TrkParams::ValidateTrkCalib( Cali
248              build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );              build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
249          };          };
250      }      }
251      if( npkts==6 )return 1; // :-)      if( npkts==6 ){}//return 1; // :-)
252      else {      else {
253          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;    
254            validate = 0;
255      }      }
256  //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;  //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
257    
# Line 232  UInt_t TrkParams::ValidateTrkCalib( Cali Line 301  UInt_t TrkParams::ValidateTrkCalib( Cali
301  //       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;
302  //       return 0; // :-(  //       return 0; // :-(
303  //      }  //      }
304        return 1; // :-)  
305    //      return 1; // :-)
306    
307    //    cout << validate << endl;
308        return validate;
309    
310  }  }
311  /**  /**
# Line 241  UInt_t TrkParams::ValidateTrkCalib( Cali Line 314  UInt_t TrkParams::ValidateTrkCalib( Cali
314  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){
315    
316      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
317        ca->Reset();
318    
319      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
320      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 254  void TrkParams::FillACalibFrom(TFile* f0 Line 328  void TrkParams::FillACalibFrom(TFile* f0
328      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
329    
330      // --- TEST TEST TEST TEST --- //      // --- TEST TEST TEST TEST --- //
331      TrkParams::ValidateTrkCalib(calibdata1);  //    TrkParams::ValidateTrkCalib(calibdata1);
332      TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //    TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
333            
334        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
335        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
336        if( !test1 || !test2 ){
337            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
338            TrkParams::calib.VALIDATION = 0;
339        }
340        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
341    
342      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
343          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
344          dspn2=calibdata2->DSPnumber[i]-1;          dspn2=calibdata2->DSPnumber[i]-1;
345          /*     cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl; */  //      cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl;      
346          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
347              Int_t j=(ii/128);              Int_t j=(ii/128);
348              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
349              ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];              if(dspn1>=0 && dspn1<12){
350              ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
351              ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
352              ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
353              ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
354              ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];                  if(calibdata1->DSPbad_par[i][ii]==0)
355              ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);                      ca->bad[jj][j][dspn1]=1;
356              ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);                  else if(calibdata1->DSPbad_par[i][ii]==1)
357              //        cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;                      ca->bad[jj][j][dspn1]=0;
358              //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
359              //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;                  //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
360              //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;              }
361            
362              //              if(dspn2>=0 && dspn2<12){
363              // invert the bad                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
364              //                  ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
365              if(calibdata1->DSPbad_par[i][ii]==0)                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
366                  ca->bad[jj][j][dspn1]=1;                  ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
367              else if(calibdata1->DSPbad_par[i][ii]==1)                  if(calibdata2->DSPbad_par[i][ii]==0)
368                  ca->bad[jj][j][dspn1]=0;                      ca->bad[jj][j][dspn2]=1;
369              if(calibdata2->DSPbad_par[i][ii]==0)                  else if(calibdata2->DSPbad_par[i][ii]==1)
370                  ca->bad[jj][j][dspn2]=1;                      ca->bad[jj][j][dspn2]=0;
371              else if(calibdata2->DSPbad_par[i][ii]==1)                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
372                  ca->bad[jj][j][dspn2]=0;                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
373                }
374          };          };
375      };      };
376                    
# Line 300  void TrkParams::FillACalibFrom(TFile* f0 Line 383  void TrkParams::FillACalibFrom(TFile* f0
383  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){
384    
385      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
386    //    ca->Reset();
387    
388      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
389      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 313  void TrkParams::FillFCalibFrom(TFile* f0 Line 397  void TrkParams::FillFCalibFrom(TFile* f0
397      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
398    
399      // --- TEST TEST TEST TEST --- //      // --- TEST TEST TEST TEST --- //
400      TrkParams::ValidateTrkCalib(calibdata1);  //     TrkParams::ValidateTrkCalib(calibdata1);
401      TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
402        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
403        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
404        if( !test1 || !test2 ){
405            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
406            TrkParams::calib.VALIDATION = 0;
407        }
408        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
409                    
410      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
411          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 323  void TrkParams::FillFCalibFrom(TFile* f0 Line 414  void TrkParams::FillFCalibFrom(TFile* f0
414          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
415              Int_t j=(ii/128);              Int_t j=(ii/128);
416              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
417              ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];              if(dspn1>=0 && dspn1<12){
418              ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
419              ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
420              ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];                  if(calibdata1->DSPbad_par[i][ii]==0)
421              //        cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;                      ca->bad[jj][j][dspn1]=1;
422              //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;                  else if(calibdata1->DSPbad_par[i][ii]==1)
423              //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;                      ca->bad[jj][j][dspn1]=0;
424              //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
425                            //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
426              //              }
427              // invert the bad              if(dspn2>=0 && dspn2<12){
428              //                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
429              if(calibdata1->DSPbad_par[i][ii]==0)                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
430                  ca->bad[jj][j][dspn1]=1;                  if(calibdata2->DSPbad_par[i][ii]==0)
431              else if(calibdata1->DSPbad_par[i][ii]==1)                      ca->bad[jj][j][dspn2]=1;
432                  ca->bad[jj][j][dspn1]=0;                  else if(calibdata2->DSPbad_par[i][ii]==1)
433              if(calibdata2->DSPbad_par[i][ii]==0)                      ca->bad[jj][j][dspn2]=0;
434                  ca->bad[jj][j][dspn2]=1;                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
435              else if(calibdata2->DSPbad_par[i][ii]==1)                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
436                  ca->bad[jj][j][dspn2]=0;              }
437          };          };
438      };      };
439                    
# Line 355  void TrkParams::FillFCalibFrom(TFile* f0 Line 446  void TrkParams::FillFCalibFrom(TFile* f0
446  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){
447    
448      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
449    //    ca->Reset();
450    
451      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
452      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 368  void TrkParams::FillTCalibFrom(TFile* f0 Line 460  void TrkParams::FillTCalibFrom(TFile* f0
460      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
461                    
462      // --- TEST TEST TEST TEST --- //      // --- TEST TEST TEST TEST --- //
463      TrkParams::ValidateTrkCalib(calibdata1);  //     TrkParams::ValidateTrkCalib(calibdata1);
464      TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
465        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
466        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
467        if( !test1 || !test2 ){
468            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
469            TrkParams::calib.VALIDATION = 0;
470        }
471        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
472    
473      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
474          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 378  void TrkParams::FillTCalibFrom(TFile* f0 Line 477  void TrkParams::FillTCalibFrom(TFile* f0
477          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
478              Int_t j=(ii/128);              Int_t j=(ii/128);
479              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
480              ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);              if(dspn1>=0 && dspn1<12){
481              ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
482              ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
483              ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);                  }
484                if(dspn2>=0 && dspn2<12){
485                    ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
486                    ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
487                }  
488          };          };
489      };      };
490                    
# Line 404  void TrkParams::FillTCalibFrom(TString p Line 507  void TrkParams::FillTCalibFrom(TString p
507  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){
508            
509      cTrkMask *ma = &mask_;      cTrkMask *ma = &mask_;
510        ma->Reset();
511    
512      TrkCalib *calib = new TrkCalib();      TrkCalib *calib = new TrkCalib();
513    
# Line 426  void TrkParams::FillMask(TFile* f0, Int_ Line 530  void TrkParams::FillMask(TFile* f0, Int_
530              tr->GetEntry(ev_reg2);              tr->GetEntry(ev_reg2);
531          }          }
532          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){
533              for(Int_t ivk=0; ivk<NVK; ivk++){              Int_t view   = calib->GetView(ipkt);
534                  Int_t view   = calib->GetView(ipkt);              if( (view-1)>= 0 && (view-1)<12 ){
535                  Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);                  for(Int_t ivk=0; ivk<NVK; ivk++){
536                  Float_t sigmin = 0.;                      Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);
537                  if(view%2)sigmin = 6.5;                      Float_t sigmin = 0.;
538                  else      sigmin = 2.5;                      if(view%2)sigmin = 6.5;
539                  Int_t mask = 1;                      else      sigmin = 2.5;
540                  if( sigm<sigmin )mask = 0;                      Int_t mask = 1;
541                                    if( sigm<sigmin )mask = 0;              
542                  ma->mask_vk_run[ivk][view-1] = mask;                      ma->mask_vk_run[ivk][view-1] = mask;                    
543                                }      
544  //              if(mask==0)cout<< " VIEW "<<view<<" VK "<<ivk+1<<" -- <SIG> "<<sigm<<" ---> MASKED!"<<endl;              }
             }    
545          }          }
546          if(tr)tr->Delete();          if(tr)tr->Delete();
547      }      }
548    
549        if(TrkParams::VerboseMode()){
550            for(Int_t iv=0; iv<NVIEW; iv++){
551                cout<<"view "<<setw(3)<<iv<<": ";
552                for(Int_t ivk=0; ivk<NVK; ivk++)cout<<ma->mask_vk_run[ivk][iv];
553                cout << endl;
554            }
555        }
556    
557      if(calib)calib->Delete();      if(calib)calib->Delete();
558    
559  };  };
# Line 455  void TrkParams::FillMask(TFile* f0, Int_ Line 566  void TrkParams::FillMask(TFile* f0, Int_
566    
567    
568  /**  /**
569   * Static method to load calibration.   * \brief Static method to load calibration.
570   * 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.  
571   */   */
572  Bool_t TrkParams::LoadCalib( ){  Bool_t TrkParams::LoadCalib( ){
573    
# Line 532  Int_t TrkParams::GetIndex( UInt_t type ) Line 641  Int_t TrkParams::GetIndex( UInt_t type )
641   * @param dbc   Database   * @param dbc   Database
642   * @param type  Parameter type   * @param type  Parameter type
643   * @return FALSE if parameter set fails.   * @return FALSE if parameter set fails.
644   * 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.
645   * If dbc==NULL, try to open a connection taking DB-connection   * If dbc==NULL, try to open a connection taking DB-connection
646   * parameters from PAMELA environment variables.   * parameters from PAMELA environment variables.
647   */   */
# Line 542  Bool_t TrkParams::Set( GL_RUN* glrun , T Line 651  Bool_t TrkParams::Set( GL_RUN* glrun , T
651      UInt_t index = TrkParams::GetIndex( type );      UInt_t index = TrkParams::GetIndex( type );
652      if(index < 0)return false;      if(index < 0)return false;
653    
654        UInt_t runheadtime=0;
655        UInt_t runid=0;
656    //    UInt_t runheadtime = numeric_limits<UInt_t>::max();
657        if(glrun){
658            runheadtime = glrun->RUNHEADER_TIME;
659            runid       = glrun->ID;
660        }else cout <<"Bool_t TrkParams::Set(GL_RUN*,TSQLServer*,UInt_t) >> Missing run info -- taking first entry (**WARNING** check that this is ok!! )"<<endl;
661    
662    //    if(TrkParams::VerboseMode())
663        cout << "<< set TrkParams type "<<type<<" from DB << RUN "<<runid<<endl;
664    
665    
666      if( !TrkParams::IsLoaded(type) ||      if( !TrkParams::IsLoaded(type) ||
667          glrun->RUNHEADER_TIME < gl[index].FROM_TIME   ||          runheadtime < gl[index].FROM_TIME   ||
668          glrun->RUNHEADER_TIME > gl[index].TO_TIME     ||                  runheadtime > gl[index].TO_TIME     ||  
669          false ){          false ){
670    
671            bool LOCAL_CONNECTION = false;
672          if( !dbc || (dbc && !dbc->IsConnected()) ){          if( !dbc || (dbc && !dbc->IsConnected()) ){
673    
674              if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;              if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
675              TString host = "mysql://localhost/pamelaprod";              dbc = TrkParams::SetDBConnection();
676              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;  
             }  
         }  
677    
678            }
         UInt_t runheadtime = numeric_limits<UInt_t>::max();  
         if(glrun)runheadtime = glrun->RUNHEADER_TIME;  
         else cout <<"Missing run info -- taking last entry "<<endl;  
679    
680          GL_PARAM q4;          GL_PARAM q4;
681          if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;          if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;      
682            if(LOCAL_CONNECTION){
683                dbc->Close();
684                delete dbc;
685            }
686          gl[index]     = q4;          gl[index]     = q4;
687          glpath[index] = q4.PATH+q4.NAME;          glpath[index] = q4.PATH+q4.NAME;
688          glload[index] = false;          glload[index] = false;
689          if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl;  
690          return true;          return true;
691    
692      }      }
# Line 609  Bool_t TrkParams::Set( TString path , UI Line 706  Bool_t TrkParams::Set( TString path , UI
706    
707      gl[index].TYPE= type;      gl[index].TYPE= type;
708      glpath[index] = path;      glpath[index] = path;
709      if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl;      if(TrkParams::VerboseMode())
710            cout << "<< set TrkParams type "<<type<<" from path << "<<path<<endl;
711      glload[index] = false;      glload[index] = false;
712    
713  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
# Line 625  Bool_t TrkParams::Set( TString path , UI Line 723  Bool_t TrkParams::Set( TString path , UI
723   */   */
724  Bool_t TrkParams::Set(UInt_t type){  Bool_t TrkParams::Set(UInt_t type){
725    
     UInt_t index = TrkParams::GetIndex( type );  
     if(index < 0)return false;  
726    
727      gl[index].TYPE= type;      return Set(0,0,type);
     glload[index] = false;  
728    
     // -----------------------------------------  
     // 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;  
729    
730  };  };
731  /**  /**
# Line 681  Bool_t TrkParams::Set(UInt_t type){ Line 736  Bool_t TrkParams::Set(UInt_t type){
736   */   */
737  Bool_t  TrkParams::Set( ){  Bool_t  TrkParams::Set( ){
738    
     Bool_t connected = false;  
739    
740  //    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;  
741    
742      return true;      return true;
743  }  }
# Line 854  float TrkParams::GetBZ(float* v){ Line 880  float TrkParams::GetBZ(float* v){
880  }  }
881    
882    
   
883  /**  /**
884   * \brief Set tracking mode (0=standard. 1=???)   * \brief Set tracking mode (0=standard. 1=???)
885   */   */
886  void TrkParams::SetTrackingMode(int trackmode) {  void TrkParams::SetTrackingMode(int trackmode) {
887      init__mini_trackmode = trackmode;      init__mini_trackmode = trackmode;
888      SetTrackingMode();      SetTrackingMode(); //fill F77 common
889  };  };
890  /**  /**
891   * \brief Set fit-precision factor (typical value fact=100.)   * \brief Set fit-precision factor (typical value fact=100.)
892   */   */
893  void TrkParams::SetPrecisionFactor(double fact){  void TrkParams::SetPrecisionFactor(double fact){
894      init__mini_fact      = fact;      init__mini_fact      = fact;
895      SetPrecisionFactor();      SetPrecisionFactor(); //fill F77 common
896  };  };
897  /**  /**
898   * \brief Set minimum number of step in track fitting   * \brief Set minimum number of step in track fitting
899   */   */
900  void TrkParams::SetStepMin(int istepmin){  void TrkParams::SetStepMin(int istepmin){
901      init__mini_istepmin  = istepmin;      init__mini_istepmin  = istepmin;
902      SetStepMin();      SetStepMin(); //fill F77 common
903    };
904    /**
905     * \brief Set deltaB parameters (id=0,1)
906     */
907    void TrkParams::SetDeltaB(int id,double db){
908        if(id!=0 && id!=1)cout << "void TrkParams::SetDeltaB(int id,double db) -- wrong input parameters: "<<id<<" "<<db<<endl;
909        if(id==0)init__deltab_0 = db;
910        if(id==1)init__deltab_1 = db;
911        SetDeltaB(); //fill F77 common
912    };
913    /**
914     * \brief Set DLT-grkuta precision factor (default 1.e-4)
915     */
916    void TrkParams::SetDLT(double fact){
917        init__dlt               = fact;
918        SetDLT(); //fill F77 common
919  };  };
920    
921  /**  /**
922     * \brief Fill F77 commons with PFA settings
923     */
924    void TrkParams::SetPFA(){
925        sw_.pfaid = init__pfa;    
926        for(int i=0; i<6; i++){
927            pfa_.e234ax[i] = init__pfa_e234ax[i];
928            pfa_.e234ay[i] = init__pfa_e234ay[i];
929        }
930    };
931    /**
932   * \brief Set p.f.a.   * \brief Set p.f.a.
933   *   *
934   * Implemented algorythms:   * Implemented algorythms:
935   * 0  ETA (default)   * 0  ETA
936   * 1  ---   * 1  ---
937   * 2  ETA2   * 2  ETA2
938   * 3  ETA3   * 3  ETA3
939   * 4  ETA4   * 4  ETA4
940     * 5  ETAL ==> ETA+LANDI
941   * 10 COG   * 10 COG
942   * 11 COG1   * 11 COG1
943   * 12 COG2   * 12 COG2
# Line 894  void TrkParams::SetStepMin(int istepmin) Line 946  void TrkParams::SetStepMin(int istepmin)
946   */   */
947  void TrkParams::SetPFA(int pfaid){  void TrkParams::SetPFA(int pfaid){
948      init__pfa  = pfaid;      init__pfa  = pfaid;
949      SetPFA();      SetPFA(); //fill F77 common
950    };
951    /**
952     * \brief Set p.f.a. angular intervals
953     *
954     * This methods allows to set amgular intervals to apply ETA2,ETA3 or ETA4
955     * algorythm, in case ETA or ETAL is set (see TrkParams::SetPFA(int pfaid)).
956     * @param v Pointer to a vector of 12 components, which represent the
957     * angular limits for ETA2,ETA3 and ETA4, for x and y views, respectivelly.
958     *
959     */
960    void TrkParams::SetPFA(float *v){
961        for(int i=0; i<6; i++){
962            init__pfa_e234ax[i]  = v[i];
963            init__pfa_e234ay[i]  = v[i+6];
964        }
965        SetPFA(); //fill F77 common
966  };  };
967    
968    
969  /**  /**
970   * \brief Get spatial resolution.   * \brief Get spatial resolution.
971   *   *
# Line 918  float TrkParams::GetResolution(int view, Line 988  float TrkParams::GetResolution(int view,
988    
989    
990    
991    
992  ClassImp(TrkParams);  ClassImp(TrkParams);

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

  ViewVC Help
Powered by ViewVC 1.1.23