/[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.20 by pam-fi, Tue Jan 15 14:29:46 2008 UTC revision 1.32 by mocchiut, Tue Oct 14 14:07:41 2014 UTC
# Line 1  Line 1 
1    
2  /**  /**
3   * \file TrkParams.cpp   * \file TrkParams.cpp
4   * \author Elena Vannuccini   * \author Elena Vannuccini
# Line 9  Line 10 
10  using namespace std;  using namespace std;
11    
12    
13    Bool_t TrkParams::simuflag = kFALSE;
14  // -------------------------  // -------------------------
15  // CALIBRATION (PED,SIG,BAD)  // CALIBRATION (PED,SIG,BAD)
16  // -------------------------  // -------------------------
# Line 17  TString      TrkParams::calibpatht = ""; Line 19  TString      TrkParams::calibpatht = "";
19  TString      TrkParams::calibpathf = "";  TString      TrkParams::calibpathf = "";
20  Bool_t       TrkParams::calib104   = 0;  Bool_t       TrkParams::calib104   = 0;
21  Bool_t       TrkParams::calibload  = false;  Bool_t       TrkParams::calibload  = false;
22    TrkCalib*    TrkParams::calib1 = 0;
23    TrkCalib*    TrkParams::calib2 = 0;
24  // -------------------------  // -------------------------
25  // PARAMETERS loaded from DB  // PARAMETERS loaded from DB
26  // -------------------------  // -------------------------
# Line 38  float  TrkParams::init__pfa_e234ay[]   = Line 42  float  TrkParams::init__pfa_e234ay[]   =
42  double TrkParams::init__deltab_0       = 0.;  double TrkParams::init__deltab_0       = 0.;
43  double TrkParams::init__deltab_1       = 0.;  double TrkParams::init__deltab_1       = 0.;
44  double TrkParams::init__dlt            = 1.e-5;  double TrkParams::init__dlt            = 1.e-5;
45    // ------------------------------------------
46    // nominal z-coordinates to define acceptance
47    // ------------------------------------------
48    int   TrkParams::nGF   = NGF;
49    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};
50    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};
51    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};
52    // 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};
53    // 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};
54    // per i piani interni alla cavita`, gli estremi sono dati dalla cavita` stessa
55    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};
56    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};
57    TString TrkParams::GF_element[] = {"S11","S12","S21","S22","T1","CUF","T2","T3","T4","T5","CLF","T6","S31","S32"};
58    
59  TrkParams::TrkParams(){  TrkParams::TrkParams(){
60    
# Line 58  float anint(float f){ Line 75  float anint(float f){
75      return ret1;              return ret1;        
76  }  }
77    
78    void TrkParams::SetSimuFlag(Bool_t flag){
79      simuflag = flag;
80    }
81    
82    Bool_t TrkParams::GetSimuFlag(){
83      return simuflag;
84    }
85    
86    
87  /**  /**
88   * Static method to open a DB connection.   * Static method to open a DB connection.
89   * HOST, USER and PASSWORD are taken from enviroment variables $PAM_DBHOST,   * HOST, USER and PASSWORD are taken from enviroment variables $PAM_DBHOST,
# Line 78  TSQLServer* TrkParams::SetDBConnection() Line 104  TSQLServer* TrkParams::SetDBConnection()
104      if ( strcmp(pamdbhost,"") ) host = pamdbhost;      if ( strcmp(pamdbhost,"") ) host = pamdbhost;
105      if ( strcmp(pamdbuser,"") ) user = pamdbuser;      if ( strcmp(pamdbuser,"") ) user = pamdbuser;
106      if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;      if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
107      if(TrkParams::VerboseMode()){      if(TrkParams::DebugMode()){
108          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
109          cout<<"Connecting to DB"<<endl;          cout<<"TrkParams::SetDBConnection() >> Connecting to DB"<<endl;
110          cout<<"HOST "<<host<<endl;          cout<<"HOST "<<host<<endl;
111          cout<<"USER "<<user<<endl;          cout<<"USER "<<user<<endl;
112          cout<<"PSW  "<<psw<<endl;          cout<<"PSW  "<<psw<<endl;
# Line 90  TSQLServer* TrkParams::SetDBConnection() Line 116  TSQLServer* TrkParams::SetDBConnection()
116      if( !dbc->IsConnected() )return NULL;          if( !dbc->IsConnected() )return NULL;    
117      stringstream myquery;  // EMILIANO      stringstream myquery;  // EMILIANO
118      myquery.str("");  // EMILIANO      myquery.str("");  // EMILIANO
119      myquery << "SET time_zone='+0:00'";  // EMILIANO      myquery << "SET time_zone='+0:00';";  // EMILIANO
120      dbc->Query(myquery.str().c_str());  // EMILIANO      delete dbc->Query(myquery.str().c_str());  // EMILIANO
121      if(TrkParams::VerboseMode()){      delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");//EM
122        if(TrkParams::DebugMode()){
123          cout << " ...done"<<endl;          cout << " ...done"<<endl;
124          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
125      }      }
# Line 127  Bool_t TrkParams::SetCalib( GL_RUN *glru Line 154  Bool_t TrkParams::SetCalib( GL_RUN *glru
154          bool LOCAL_CONNECTION = false;          bool LOCAL_CONNECTION = false;
155          if( !dbc || (dbc && !dbc->IsConnected()) ){          if( !dbc || (dbc && !dbc->IsConnected()) ){
156    
157              if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;  //          if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
158              dbc = TrkParams::SetDBConnection();              dbc = TrkParams::SetDBConnection();
159              if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;              if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;
160    
# Line 159  Bool_t TrkParams::SetCalib( GL_RUN *glru Line 186  Bool_t TrkParams::SetCalib( GL_RUN *glru
186              calibpatht = q4.PATH + q4.NAME;              calibpatht = q4.PATH + q4.NAME;
187          }          }
188                    
189          if(LOCAL_CONNECTION){          if(LOCAL_CONNECTION&&dbc){
190              dbc->Close();              dbc->Close();
191              delete dbc;              delete dbc;
192                if(TrkParams::DebugMode()){
193                    cout << " DB connection closed."<<endl;
194                }      
195          }          }
196    
197  //    return TrkParams::LoadCalib();  //    return TrkParams::LoadCalib();
# Line 229  UInt_t TrkParams::ValidateTrkCalib( Cali Line 259  UInt_t TrkParams::ValidateTrkCalib( Cali
259  //  -------------------------------------------------  //  -------------------------------------------------
260      UInt_t build=0;      UInt_t build=0;
261      UInt_t base=0;      UInt_t base=0;
262      UInt_t mask=0;      //    UInt_t mask=0;// EM GCC 4.7
263      if(classname.Contains("CalibTrk1Event")){      if(classname.Contains("CalibTrk1Event")){
264          base=12;          base=12;
265          mask=0x03F000;          //      mask=0x03F000; // EM GCC 4.7
266      }      }
267      if(classname.Contains("CalibTrk2Event")){      if(classname.Contains("CalibTrk2Event")){
268          base=18;          base=18;
269          mask=0xFC0000;          //      mask=0xFC0000;  // EM GCC 4.7
270      }      }
271  //  -------------------------------------------------  //  -------------------------------------------------
272  //  Count number of packets and set build variable  //  Count number of packets and set build variable
# Line 319  void TrkParams::FillACalibFrom(TFile* f0 Line 349  void TrkParams::FillACalibFrom(TFile* f0
349      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
350      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
351    
352      CalibTrk1Event *calibdata1 = 0;      if(!calib1)calib1 = new TrkCalib();
353      CalibTrk2Event *calibdata2 = 0;      if(!calib2)calib2 = new TrkCalib();
354      tr1->SetBranchAddress("CalibTrk1",&calibdata1);  //     calibx->Set(calibdata1);
355      tr2->SetBranchAddress("CalibTrk2",&calibdata2);  //     caliby->Set(calibdata2);
356      tr1->GetEntry(ev_reg1);  
357      tr2->GetEntry(ev_reg2);  //     CalibTrk1Event *calibdata1 = 0;
358    //     CalibTrk2Event *calibdata2 = 0;
359    //     tr1->SetBranchAddress("CalibTrk1",&calibdata1);
360    //     tr2->SetBranchAddress("CalibTrk2",&calibdata2);
361        tr1->SetBranchAddress("CalibTrk1",calib1->GetPointerTo());
362        tr2->SetBranchAddress("CalibTrk2",calib2->GetPointerTo());
363        if ( tr1->GetEntry(ev_reg1) <= 0 ) throw -36;//EM
364        if ( tr2->GetEntry(ev_reg2) <= 0 ) throw -36;//EM
365      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
366    
367    
368      // --- TEST TEST TEST TEST --- //      // --- TEST TEST TEST TEST --- //
369  //    TrkParams::ValidateTrkCalib(calibdata1);  //    TrkParams::ValidateTrkCalib(calib1->Get());
370  //    TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //    TrkParams::ValidateTrkCalib((CalibTrk1Event*)calib2->Get());
371    
372      UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);      UInt_t test1 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)(calib1->Get()));
373      UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);      UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)(calib2->Get()));
374      if( !test1 || !test2 ){      if( !test1 || !test2 ){
375          if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;  //      if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
376          TrkParams::calib.VALIDATION = 0;          TrkParams::calib.VALIDATION = 0;
377      }      }
378      if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;  //    if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
379    
380      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
381          dspn1=calibdata1->DSPnumber[i]-1;  
382          dspn2=calibdata2->DSPnumber[i]-1;  
383            dspn1=calib1->Get()->DSPnumber[i]-1;
384            dspn2=calib2->Get()->DSPnumber[i]-1;
385  //      cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl;        //      cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl;      
386          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
387              Int_t j=(ii/128);              Int_t j=(ii/128);
388              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
389              if(dspn1>=0 && dspn1<12){              if(dspn1>=0 && dspn1<12){
390                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn1]=calib1->Get()->DSPped_par[i][ii];
391                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn1]=aint(calib1->Get()->DSPped_par[i][ii]);
392                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];                  ca->sigma[jj][j][dspn1]=calib1->Get()->DSPsig_par[i][ii];
393                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);                  ca->sigma_t[jj][j][dspn1]=anint(calib1->Get()->DSPsig_par[i][ii]);
394                  if(calibdata1->DSPbad_par[i][ii]==0)                  if(calib1->Get()->DSPbad_par[i][ii]==0)
395                      ca->bad[jj][j][dspn1]=1;                      ca->bad[jj][j][dspn1]=1;
396                  else if(calibdata1->DSPbad_par[i][ii]==1)                  else if(calib1->Get()->DSPbad_par[i][ii]==1)
397                      ca->bad[jj][j][dspn1]=0;                      ca->bad[jj][j][dspn1]=0;
398                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
399                  //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;                  //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
400              }              }
401    
402              if(dspn2>=0 && dspn2<12){              if(dspn2>=0 && dspn2<12){
403                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn2]=calib2->Get()->DSPped_par[i][ii];
404                  ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn2]=aint(calib2->Get()->DSPped_par[i][ii]);
405                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];                  ca->sigma[jj][j][dspn2]=calib2->Get()->DSPsig_par[i][ii];
406                  ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);                  ca->sigma_t[jj][j][dspn2]=anint(calib2->Get()->DSPsig_par[i][ii]);
407                  if(calibdata2->DSPbad_par[i][ii]==0)                  if(calib2->Get()->DSPbad_par[i][ii]==0)
408                      ca->bad[jj][j][dspn2]=1;                      ca->bad[jj][j][dspn2]=1;
409                  else if(calibdata2->DSPbad_par[i][ii]==1)                  else if(calib2->Get()->DSPbad_par[i][ii]==1)
410                      ca->bad[jj][j][dspn2]=0;                      ca->bad[jj][j][dspn2]=0;
411                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
412                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
# Line 380  void TrkParams::FillACalibFrom(TFile* f0 Line 420  void TrkParams::FillACalibFrom(TFile* f0
420  /**  /**
421   * Method to fill the tracker calibration-parameter struct from on-line calibrations   * Method to fill the tracker calibration-parameter struct from on-line calibrations
422   */   */
423  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){
424    
425      cTrkCalib *ca = &pedsigbad_;  //     cTrkCalib *ca = &pedsigbad_;
426  //    ca->Reset();  // //    ca->Reset();
427    
428      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");    //     TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
429      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");  //     TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
   
     CalibTrk1Event *calibdata1 = 0;  
     CalibTrk2Event *calibdata2 = 0;  
     tr1->SetBranchAddress("CalibTrk1",&calibdata1);  
     tr2->SetBranchAddress("CalibTrk2",&calibdata2);  
     tr1->GetEntry(ev_reg1);  
     tr2->GetEntry(ev_reg2);  
     Int_t dspn1(0),dspn2(0);  
430    
431      // --- TEST TEST TEST TEST --- //  //     CalibTrk1Event *calibdata1 = 0;
432  //     TrkParams::ValidateTrkCalib(calibdata1);  //     CalibTrk2Event *calibdata2 = 0;
433  //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //     tr1->SetBranchAddress("CalibTrk1",&calibdata1);
434      UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);  //     tr2->SetBranchAddress("CalibTrk2",&calibdata2);
435      UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //     tr1->GetEntry(ev_reg1);
436      if( !test1 || !test2 ){  //     tr2->GetEntry(ev_reg2);
437          if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;  //     Int_t dspn1(0),dspn2(0);
438          TrkParams::calib.VALIDATION = 0;  
439      }  //     // --- TEST TEST TEST TEST --- //
440      if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;  // //     TrkParams::ValidateTrkCalib(calibdata1);
441    // //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
442    //     UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
443    //     UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
444    //     if( !test1 || !test2 ){
445    //      if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
446    //      TrkParams::calib.VALIDATION = 0;
447    //     }
448    //     if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
449                    
450      for(Int_t i=0;i<6;i++){  //     for(Int_t i=0;i<6;i++){
451          dspn1=calibdata1->DSPnumber[i]-1;  //      dspn1=calibdata1->DSPnumber[i]-1;
452          dspn2=calibdata2->DSPnumber[i]-1;  //      dspn2=calibdata2->DSPnumber[i]-1;
453          /*     cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl; */  //      /*     cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl; */
454          for(Int_t ii=0;ii<3072;ii++){  //      for(Int_t ii=0;ii<3072;ii++){
455              Int_t j=(ii/128);  //          Int_t j=(ii/128);
456              Int_t jj=ii-j*128;  //          Int_t jj=ii-j*128;
457              if(dspn1>=0 && dspn1<12){  //          if(dspn1>=0 && dspn1<12){
458                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];  //              ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
459                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];  //              ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
460                  if(calibdata1->DSPbad_par[i][ii]==0)  //              if(calibdata1->DSPbad_par[i][ii]==0)
461                      ca->bad[jj][j][dspn1]=1;  //                  ca->bad[jj][j][dspn1]=1;
462                  else if(calibdata1->DSPbad_par[i][ii]==1)  //              else if(calibdata1->DSPbad_par[i][ii]==1)
463                      ca->bad[jj][j][dspn1]=0;  //                  ca->bad[jj][j][dspn1]=0;
464                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;  //              //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
465                  //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;  //              //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
466              }  //          }
467              if(dspn2>=0 && dspn2<12){  //          if(dspn2>=0 && dspn2<12){
468                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];  //              ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
469                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];  //              ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
470                  if(calibdata2->DSPbad_par[i][ii]==0)  //              if(calibdata2->DSPbad_par[i][ii]==0)
471                      ca->bad[jj][j][dspn2]=1;  //                  ca->bad[jj][j][dspn2]=1;
472                  else if(calibdata2->DSPbad_par[i][ii]==1)  //              else if(calibdata2->DSPbad_par[i][ii]==1)
473                      ca->bad[jj][j][dspn2]=0;  //                  ca->bad[jj][j][dspn2]=0;
474                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;  //              //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
475                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;  //              //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
476              }  //          }
477          };  //      };
478      };  //     };
479                    
480      tr1->Delete();  //     tr1->Delete();
481      tr2->Delete();  //     tr2->Delete();
482  };  // };
483  /**  /**
484   * Method to fill the tracker calibration-parameter struct from on-line calibrations   * Method to fill the tracker calibration-parameter struct from on-line calibrations
485   */   */
486  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){
487    
488      cTrkCalib *ca = &pedsigbad_;  //     cTrkCalib *ca = &pedsigbad_;
489  //    ca->Reset();  // //    ca->Reset();
490    
491      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");    //     TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
492      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");  //     TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
493    
494      CalibTrk1Event *calibdata1 = 0;  //     CalibTrk1Event *calibdata1 = 0;
495      CalibTrk2Event *calibdata2 = 0;  //     CalibTrk2Event *calibdata2 = 0;
496      tr1->SetBranchAddress("CalibTrk1",&calibdata1);  //     tr1->SetBranchAddress("CalibTrk1",&calibdata1);
497      tr2->SetBranchAddress("CalibTrk2",&calibdata2);  //     tr2->SetBranchAddress("CalibTrk2",&calibdata2);
498      tr1->GetEntry(ev_reg1);  //     tr1->GetEntry(ev_reg1);
499      tr2->GetEntry(ev_reg2);  //     tr2->GetEntry(ev_reg2);
500      Int_t dspn1(0),dspn2(0);  //     Int_t dspn1(0),dspn2(0);
501                    
502      // --- TEST TEST TEST TEST --- //  //     // --- TEST TEST TEST TEST --- //
503  //     TrkParams::ValidateTrkCalib(calibdata1);  // //     TrkParams::ValidateTrkCalib(calibdata1);
504  //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  // //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
505      UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);  //     UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
506      UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);  //     UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
507      if( !test1 || !test2 ){  //     if( !test1 || !test2 ){
508          if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;  //      if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
509          TrkParams::calib.VALIDATION = 0;  //      TrkParams::calib.VALIDATION = 0;
510      }  //     }
511      if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;  //     if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
512    
513      for(Int_t i=0;i<6;i++){  //     for(Int_t i=0;i<6;i++){
514          dspn1=calibdata1->DSPnumber[i]-1;  //      dspn1=calibdata1->DSPnumber[i]-1;
515          dspn2=calibdata2->DSPnumber[i]-1;  //      dspn2=calibdata2->DSPnumber[i]-1;
516          /*     cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl; */  //      /*     cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl; */
517          for(Int_t ii=0;ii<3072;ii++){  //      for(Int_t ii=0;ii<3072;ii++){
518              Int_t j=(ii/128);  //          Int_t j=(ii/128);
519              Int_t jj=ii-j*128;  //          Int_t jj=ii-j*128;
520              if(dspn1>=0 && dspn1<12){  //          if(dspn1>=0 && dspn1<12){
521                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);  //              ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
522                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);  //              ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
523              }  //          }
524              if(dspn2>=0 && dspn2<12){  //          if(dspn2>=0 && dspn2<12){
525                  ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);  //              ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
526                  ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);  //              ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
527              }    //          }  
528          };  //      };
529      };  //     };
530                    
531      tr1->Delete();  //     tr1->Delete();
532      tr2->Delete();  //     tr2->Delete();
533  };  // };
534  /**  /**
535   * Method to fill the tracker calibration-parameter struct from default calibration   * Method to fill the tracker calibration-parameter struct from default calibration
536   */   */
# Line 519  void TrkParams::FillMask(TFile* f0, Int_ Line 559  void TrkParams::FillMask(TFile* f0, Int_
559              //-------------------------              //-------------------------
560              tr = (TTree*)f0->Get("CalibTrk1");                tr = (TTree*)f0->Get("CalibTrk1");  
561              tr->SetBranchAddress("CalibTrk1",calib->GetPointerTo());              tr->SetBranchAddress("CalibTrk1",calib->GetPointerTo());
562              tr->GetEntry(ev_reg1);              if ( tr->GetEntry(ev_reg1) <= 0 ) throw -36;//EM
563          }          }
564          if(i==1){          if(i==1){
565              //-------------------------              //-------------------------
# Line 527  void TrkParams::FillMask(TFile* f0, Int_ Line 567  void TrkParams::FillMask(TFile* f0, Int_
567              //-------------------------              //-------------------------
568              tr = (TTree*)f0->Get("CalibTrk2");              tr = (TTree*)f0->Get("CalibTrk2");
569              tr->SetBranchAddress("CalibTrk2",calib->GetPointerTo());              tr->SetBranchAddress("CalibTrk2",calib->GetPointerTo());
570              tr->GetEntry(ev_reg2);              if ( tr->GetEntry(ev_reg2) <= 0 ) throw -36;
571          }          }
572          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){
573              Int_t view   = calib->GetView(ipkt);              Int_t view   = calib->GetView(ipkt);
# Line 601  Bool_t TrkParams::LoadCalib( ){ Line 641  Bool_t TrkParams::LoadCalib( ){
641          cout << " - full+truncated parameters "<<endl;          cout << " - full+truncated parameters "<<endl;
642      }      }
643      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
644      if(TrkParams::VerboseMode())cout << " - VK-mask "<<endl;      if(TrkParams::VerboseMode())cout << " - VK-mask (RUN-by-RUN)"<<endl;
645      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
646    
647      // =============================================================      // =============================================================
# Line 645  Int_t TrkParams::GetIndex( UInt_t type ) Line 685  Int_t TrkParams::GetIndex( UInt_t type )
685   * If dbc==NULL, try to open a connection taking DB-connection   * If dbc==NULL, try to open a connection taking DB-connection
686   * parameters from PAMELA environment variables.   * parameters from PAMELA environment variables.
687   */   */
688  Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type){  Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type, UInt_t abstime){
689    
690    
691      UInt_t index = TrkParams::GetIndex( type );      UInt_t index = TrkParams::GetIndex( type );
692      if(index < 0)return false;      if(index < 0)return false;
693    
694      UInt_t runheadtime=0;      if(TrkParams::VerboseMode())
695          cout <<"Calling Bool_t TrkParams::Set(GL_RUN* "<<glrun<<" ,TSQLServer* "<<dbc<<" ,UInt_t "<<type<<" ,UInt_t " <<abstime << " ) >> (**WARNING** check that this is all ok!! )"<<endl;
696    
697        UInt_t runheadtime=1;
698      UInt_t runid=0;      UInt_t runid=0;
699  //    UInt_t runheadtime = numeric_limits<UInt_t>::max();  //    UInt_t runheadtime = numeric_limits<UInt_t>::max();
700      if(glrun){      if(glrun){
701          runheadtime = glrun->RUNHEADER_TIME;          runheadtime = glrun->RUNHEADER_TIME;
702          runid       = glrun->ID;          runid       = glrun->ID;
703      }else cout <<"Bool_t TrkParams::Set(GL_RUN*,TSQLServer*,UInt_t) >> Missing run info -- taking first entry (**WARNING** check that this is ok!! )"<<endl;      }else
704          cout <<"Bool_t TrkParams::Set(GL_RUN* "<<glrun<<" ,TSQLServer* "<<dbc<<" ,UInt_t "<<type<<" ,UInt_t " <<abstime << " ) >> GL_RUN==NULL -- taking first entry (**WARNING** check that this is ok!! )"<<endl;
 //    if(TrkParams::VerboseMode())  
     cout << "<< set TrkParams type "<<type<<" from DB << RUN "<<runid<<endl;  
   
   
     if( !TrkParams::IsLoaded(type) ||  
         runheadtime < gl[index].FROM_TIME   ||  
         runheadtime > gl[index].TO_TIME     ||    
         false ){  
   
         bool LOCAL_CONNECTION = false;  
         if( !dbc || (dbc && !dbc->IsConnected()) ){  
   
             if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;  
             dbc = TrkParams::SetDBConnection();  
             if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;  
705    
         }  
706    
707          GL_PARAM q4;      if( !abstime || !simuflag ) abstime = runheadtime;// EM: if simu?
         if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;        
         if(LOCAL_CONNECTION){  
             dbc->Close();  
             delete dbc;  
         }  
         gl[index]     = q4;  
         glpath[index] = q4.PATH+q4.NAME;  
         glload[index] = false;  
708    
709          return true;      if(TrkParams::VerboseMode())
710          cout << "TrkParams::IsLoaded(type)=" << TrkParams::IsLoaded(type) << " abstime=" << abstime << " runheadtime=" << runheadtime << " gl[index].FROM_TIME=" << gl[index].FROM_TIME << " gl[index].TO_TIME=" << gl[index].TO_TIME << endl;
711    
712        if( !TrkParams::IsLoaded(type) ||
713            abstime < gl[index].FROM_TIME   ||
714            abstime > gl[index].TO_TIME     ||      
715            false ){
716          
717          if(TrkParams::VerboseMode())
718            cout << "<< set TrkParams type "<<type<<" from DB << RUN "<<runid<<endl;
719          
720          bool LOCAL_CONNECTION = false;
721          if( !dbc || (dbc && !dbc->IsConnected()) ){
722            
723            //          if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
724            dbc = TrkParams::SetDBConnection();
725            if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;
726            
727          }
728          
729          GL_PARAM q4;
730          //        if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;      
731          if( q4.Query_GL_PARAM(abstime,type,dbc) )return false;     //VALERIO  
732          if(LOCAL_CONNECTION){
733            dbc->Close();
734            delete dbc;
735            if(TrkParams::DebugMode()){
736              cout << " DB connection closed."<<endl;
737            }          
738          }
739          gl[index]     = q4;
740          glpath[index] = q4.PATH+q4.NAME;
741          glload[index] = false;
742          
743          //return true;
744          
745      }      }
746      return false;      return true;
747        
748  };  };
749  /**  /**
750   * Set tracker parameters proper for the run, from input.   * Set tracker parameters proper for the run, from input.
# Line 734  Bool_t TrkParams::Set(UInt_t type){ Line 787  Bool_t TrkParams::Set(UInt_t type){
787   * otherwise it set a default path.   * otherwise it set a default path.
788   * @return FALSE if parameter set fails.   * @return FALSE if parameter set fails.
789   */   */
790    
791  Bool_t  TrkParams::Set( ){  Bool_t  TrkParams::Set( ){
792    
793    
# Line 751  Bool_t TrkParams::Load(UInt_t type){ Line 805  Bool_t TrkParams::Load(UInt_t type){
805            
806      Int_t index = TrkParams::GetIndex( type );      Int_t index = TrkParams::GetIndex( type );
807      if( index<0 )return false;      if( index<0 )return false;
808      if( glload[index] )return true;      if( glload[index] )return false;
   
809      if( glpath[index].IsNull() )TrkParams::Set(type);      if( glpath[index].IsNull() )TrkParams::Set(type);
810    
811      switch( type ){      switch( type ){
# Line 836  Bool_t TrkParams::Load(UInt_t type){ Line 889  Bool_t TrkParams::Load(UInt_t type){
889  }  }
890    
891  Bool_t TrkParams::Load( ){  Bool_t TrkParams::Load( ){
892      for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )if( !TrkParams::Load(trkparamtype[i]) )return false;          Bool_t result = true;
893      return true;      for(Int_t i=0 ; i<NTYPES; i++)
894          if(!glload[i] && trkparamtype[i]>0 )
895            if( !TrkParams::Load(trkparamtype[i]) )
896              result = false;
897        return result;
898  };  };
899  Bool_t TrkParams::IsLoaded( ){  Bool_t TrkParams::IsLoaded( ){
900      for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )return false;      for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )return false;
901      return true;      return true;
902  };  };
903    
904    /**
905     * Get ADC-to-MIP conversion parameters
906     * @param nl ladder number (0-2)
907     * @param nv view number (0-11)
908     */
909    float TrkParams::GetMIP(int nl, int nv){
910        TrkParams::Load(2);
911        if( !TrkParams::IsLoaded(2) )return 0.;
912        return adc2mip_.mip[nl][nv];
913    }
914    
915  /**  /**
916   * Get BY (kGauss)   * Get BY (kGauss)
# Line 981  void TrkParams::SetPFA(float *v){ Line 1048  void TrkParams::SetPFA(float *v){
1048   */   */
1049  float TrkParams::GetResolution(int view, float angle){  float TrkParams::GetResolution(int view, float angle){
1050      float res = 1000;      float res = 1000;
1051      if( init__pfa == 0 )res = riseta_(&view,&angle);      if     ( init__pfa == 0 )res = riseta_(&view,&angle);
1052        else if( init__pfa == 5 )res = riseta_(&view,&angle);
1053      else cout << "float TrkParams::GetResolution(int view, float angle) -- PFA "<<init__pfa<<" not yet implemented"<<endl;      else cout << "float TrkParams::GetResolution(int view, float angle) -- PFA "<<init__pfa<<" not yet implemented"<<endl;
1054      return res;      return res;
1055  }  }
1056    
1057    /**
1058     * Returns the number of angular bins for p.f.a. parameters
1059     */
1060    int TrkParams::GetPFA_NbinsAngle(){
1061        TrkParams::Load(4);
1062        if( !TrkParams::IsLoaded(4) ){
1063            cout << "int TrkParams::GetPFA_NbinsAngle() --- ERROR --- p.f.a. parameters  not loaded"<<endl;
1064            return 0;
1065        }
1066        return pfa_.nangbin;
1067    };
1068    /**
1069     * Returns the number of eta bins for p.f.a. parameters
1070     */
1071    int TrkParams::GetPFA_NbinsETA(){
1072        TrkParams::Load(4);
1073        if( !TrkParams::IsLoaded(4) ){
1074            cout << "int TrkParams::GetPFA_NbinsETA() --- ERROR --- p.f.a. parameters  not loaded"<<endl;
1075            return 0;
1076        }
1077        return pfa_.netaval;
1078    };
1079    
1080    /**
1081     * Returns the pointer to a vector ( of size TrkParams::GetPFA_NbinsETA() ),
1082     * with eta-correction values for each eta bin.
1083     * Bin extremes are given by float* TrkParams::GetPFA_ETAabs(pfa,int).
1084     *
1085     * @param pfa "ETA2","ETA3" or "ETA4"
1086     * @param nview View number (0-11)
1087     * @param nladder Ladder number (0-2)
1088     * @param nang Angular bin (@see int TrkParams::GetPFA_NbinsAngle()).
1089     *
1090     * NB! the vector must be deallocated!
1091     * delete [] vname;
1092     */
1093    float* TrkParams::GetPFA_ETAcorr(TString pfa, int nview, int nladder, int nang){
1094    
1095        TrkParams::Load(4);
1096        if( !TrkParams::IsLoaded(4) ){
1097            cout << "float* TrkParams::GetPFA_ETAcorr(TString pfa, int nview, int nladder, int nang) --- ERROR --- p.f.a. parameters  not loaded"<<endl;
1098            return 0;
1099        }
1100      
1101        int nbins = GetPFA_NbinsETA();
1102        if(!nbins)return 0;
1103    
1104        if( nview   <   0 ||
1105            nview   >= 12 ||
1106            nladder <   0 ||
1107            nladder >=  3 ||
1108            nang    <   0 ||
1109            nang    >=  GetPFA_NbinsAngle() ||
1110            false)return 0;
1111    
1112         float *fcorr = new float [nbins];
1113    //    float fcorr[nbins];
1114    
1115        if(!pfa.CompareTo("ETA2",TString::kIgnoreCase)){
1116            for(int ib=0; ib<nbins; ib++){
1117                fcorr[ib] = pfa_.feta2[nang][nladder][nview][ib];
1118    //          cout << pfa_.eta2[nang][ib] << " - " <<  pfa_.feta2[nang][nladder][nview][ib]<<endl;;
1119            }
1120        }else if (!pfa.CompareTo("ETA3",TString::kIgnoreCase)){
1121            for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.feta3[nang][nladder][nview][ib];
1122        }else if (!pfa.CompareTo("ETA4",TString::kIgnoreCase)){
1123            for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.feta4[nang][nladder][nview][ib];
1124        }else{
1125            cout << "float* TrkParams::GetPFA_ETAcorr("<<pfa<<",...) ---  pfa parameters not implemented "<<endl;
1126            return 0;
1127        }    
1128    
1129        return fcorr;
1130    
1131    };
1132    
1133    /**
1134     * Returns the pointer to a vector with eta-bin extremes (@see float* TrkParams::GetPFA_ETAcorr(TString,int,int,int)).
1135     *
1136     * @param pfa "ETA2","ETA3" or "ETA4"
1137     * @param nang Angular bin (@see int TrkParams::GetPFA_NbinsAngle()).
1138     *
1139     * NB the vector must be deallocated
1140     * delete [] vname;
1141     */
1142    float* TrkParams::GetPFA_ETAabs(TString pfa, int nang){
1143      
1144        TrkParams::Load(4);
1145        if( !TrkParams::IsLoaded(4) ){
1146            cout << "float* TrkParams::GetPFA_ETAabs(TString pfa, int nang) --- ERROR --- p.f.a. parameters  not loaded"<<endl;
1147            return 0;
1148        }
1149    
1150        int nbins = GetPFA_NbinsETA();
1151        if(!nbins)return 0;
1152    
1153        float *fcorr = new float [nbins];
1154    //    float fcorr[nbins];
1155        if( nang    <   0 ||
1156            nang    >=  GetPFA_NbinsAngle() ||
1157            false)return 0;
1158    
1159        if(!pfa.CompareTo("ETA2",TString::kIgnoreCase)){
1160            for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta2[nang][ib];
1161        }else if (!pfa.CompareTo("ETA3",TString::kIgnoreCase)){
1162            for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta3[nang][ib];
1163        }else if (!pfa.CompareTo("ETA4",TString::kIgnoreCase)){
1164            for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta4[nang][ib];
1165        }else{
1166            cout << "float* TrkParams::GetPFA_ETAabs("<<pfa<<",...) ---  pfa parameters not implemented "<<endl;
1167            return 0;
1168        }    
1169    
1170        return fcorr;
1171    
1172    };
1173    /**
1174     * Returns the "Landi-correction".
1175     *
1176     * @param nview View number (0-11)
1177     * @param nladder Ladder number (0-2)
1178     * @param nang Angular bin (@see int TrkParams::GetPFA_NbinsAngle()).
1179     */
1180    float TrkParams::GetPFA_ETAlandi(int nview, int nladder, int nang){
1181    
1182    //     TrkParams::Load(4);
1183    //     if( !TrkParams::IsLoaded(4) ){
1184    //      cout << "float* TrkParams::GetPFA_ETAlandi(int nview, int nladder, int nang) --- ERROR --- p.f.a. parameters  not loaded"<<endl;
1185    //      return 0;
1186    //     }
1187        int nbins = GetPFA_NbinsAngle();
1188        if(!nbins)return 0;
1189    
1190        if( nview   <   0 ||
1191            nview   >= 12 ||
1192            nladder <   0 ||
1193            nladder >=  3 ||
1194            nang    <   0 ||
1195            nang    >=  nbins ||
1196            false)return 0;
1197      
1198    
1199        return pfa_.fcorr[nang][nladder][nview];
1200    
1201    };
1202    
1203    /**
1204     * Returns the index (0, n.bin-1) of the angular bin for pfa parameters
1205     * @param angle Effective angle (deg)
1206     */
1207    int TrkParams::GetPFA_AngleBin(float angle){
1208        
1209        int nangbin = TrkParams::GetPFA_NbinsAngle();
1210        int istart = (int)(nangbin/2);
1211        int idbin = -1;
1212    //    cout << angle <<" ??" << endl;
1213        if( angle > pfa_.angR[istart] ){
1214            idbin = nangbin-1;
1215            for(int id=istart+1; id<nangbin; id++ ){
1216    //          cout << id << endl;
1217                if( pfa_.angR[id] >= angle ){
1218                    idbin = id;
1219                    break;
1220                }
1221            }
1222        }else{
1223            idbin = 0;
1224            for(int id=istart; id>=0; id-- ){
1225    //          cout << id << endl;
1226                if( pfa_.angL[id] < angle ){
1227                    idbin = id;
1228                    break;
1229                }
1230            }
1231    
1232        }
1233    //    cout << ">>> "<<idbin<<" "<<pfa_.angL[idbin]<<" "<<pfa_.angR[idbin]<<endl;
1234        return idbin;
1235    }
1236    
1237    
1238    

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

  ViewVC Help
Powered by ViewVC 1.1.23