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

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

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

revision 1.1 by pam-fi, Fri Feb 16 14:56:01 2007 UTC revision 1.19 by pam-fi, Tue Nov 27 11:43:50 2007 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 16  TString      TrkParams::calibpatht = ""; Line 17  TString      TrkParams::calibpatht = "";
17  TString      TrkParams::calibpathf = "";  TString      TrkParams::calibpathf = "";
18  Bool_t       TrkParams::calib104   = 0;  Bool_t       TrkParams::calib104   = 0;
19  Bool_t       TrkParams::calibload  = false;  Bool_t       TrkParams::calibload  = false;
20    // -------------------------
21    // PARAMETERS loaded from DB
22    // -------------------------
23  UInt_t       TrkParams::trkparamtype[] = {1,2,3,4,5,6,7};  UInt_t       TrkParams::trkparamtype[] = {1,2,3,4,5,6,7};
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};
27    // ----------------
28    // other parameters
29    // ----------------
30    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;
34    int    TrkParams::init__mini_istepmin  = 5; //3;
35    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    
41  TrkParams::TrkParams(){  TrkParams::TrkParams(){
42    
# Line 39  float anint(float f){ Line 56  float anint(float f){
56      ret1=(float)ret;      ret1=(float)ret;
57      return ret1;              return ret1;        
58  }  }
59    
60    /**
61     * Static method to open a DB connection.
62     * HOST, USER and PASSWORD are taken from enviroment variables $PAM_DBHOST,
63     * $PAM_DBUSER and $PAM_DBPSW
64     * NB! The method create a new connection, which has to be closed by the user.
65     */
66    TSQLServer* TrkParams::SetDBConnection(){
67    
68        TString host = "mysql://localhost/pamelaprod";
69        TString user = "anonymous";
70        TString psw = "";
71        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
72        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
73        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
74        if ( !pamdbhost ) pamdbhost = "";
75        if ( !pamdbuser ) pamdbuser = "";
76        if ( !pamdbpsw ) pamdbpsw = "";
77        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
78        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
79        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
80        if(TrkParams::VerboseMode()){
81            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
82            cout<<"Connecting to DB"<<endl;
83            cout<<"HOST "<<host<<endl;
84            cout<<"USER "<<user<<endl;
85            cout<<"PSW  "<<psw<<endl;
86        }
87        TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
88        if( !dbc )return NULL;
89        if( !dbc->IsConnected() )return NULL;    
90        stringstream myquery;  // EMILIANO
91        myquery.str("");  // EMILIANO
92        myquery << "SET time_zone='+0:00'";  // EMILIANO
93        dbc->Query(myquery.str().c_str());  // EMILIANO
94        if(TrkParams::VerboseMode()){
95            cout << " ...done"<<endl;
96            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
97        }
98        
99        return dbc;
100    }
101  /**  /**
102   * Static method to set the calibration to be loaded.   * \brief Static method to set the calibration to be loaded.
103    
104   * It retrieves the calibration associated to a given run, from   * It retrieves the calibration associated to a given run, from
105   * a given DB. It fills the F77 common.   * a given DB. It fills the F77 common.
# Line 49  float anint(float f){ Line 108  float anint(float f){
108   */   */
109  Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){  Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){
110    
111      GL_TRK_CALIB q2;  //    cout << "glrun-> RUNHEADER_TIME "<<glrun->RUNHEADER_TIME <<endl;
112      GL_ROOT q3;  
113      GL_PARAM q4;      if( !CalibIsLoaded()                          ||
114            (glrun->TRK_CALIB_USED==104 && !calib104) ||
115      if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) )return false;          (glrun->TRK_CALIB_USED!=104 && calib104)  ||
116      if(q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2)          glrun->RUNHEADER_TIME < calib.FROM_TIME   ||
117          printf("WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2);            glrun->RUNHEADER_TIME > calib.TO_TIME     ||
118      if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) )return false;          false ){
119    
120      calib      = q2;  
121      calibpathf = q3.PATH + q3.NAME;          GL_TRK_CALIB q2;
122      calib104   = (glrun->TRK_CALIB_USED==104);          GL_ROOT q3;
123      calibload  = kFALSE;          GL_PARAM q4;
124      if(calib104){  
125          if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false;  
126          calibpatht = q4.PATH + q4.NAME;          bool LOCAL_CONNECTION = false;
127      }          if( !dbc || (dbc && !dbc->IsConnected()) ){
128    
129                if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
130                dbc = TrkParams::SetDBConnection();
131                if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;
132    
133            }
134    
135            
136            if(TrkParams::VerboseMode()){
137                cout << "--------------------------------------"<<endl;
138                cout << "UPDATING calibration -- run-header time "<< glrun->RUNHEADER_TIME <<endl;
139            }
140            if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) ){
141                cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_TRK_CALIB "<<endl;
142                return false;
143            }
144            if( q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2 )
145                printf(" WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2);    
146            if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) ){
147                cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_ROOT "<<endl;
148                return false;
149            }
150    
151            if(TrkParams::VerboseMode())cout << "selected DB entry "<<q2.ID<<" from_time "<<q2.FROM_TIME<<" to time "<<q2.TO_TIME<<" --> VALIDATION "<<q2.VALIDATION<<endl;
152            calib      = q2;
153            calibpathf = q3.PATH + q3.NAME;
154            calib104   = (glrun->TRK_CALIB_USED==104);
155            calibload  = kFALSE;
156            if(calib104){
157                if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false;
158                calibpatht = q4.PATH + q4.NAME;
159            }
160            
161            if(LOCAL_CONNECTION){
162                dbc->Close();
163                delete dbc;
164            }
165    
166  //    return TrkParams::LoadCalib();  //    return TrkParams::LoadCalib();
167      return true;          return true;
168        }
169    
170        return false;
171  };  };
172    
173  /**  /**
174     * Method to "validate" tracker calibration. Implemented for test purpose. Effective implementation
175     * in YodaProfiler.
176     */
177    UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){
178    
179        UInt_t validate = 1;
180        Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
181    //    UInt_t timeaftercalib=120000; //2000;
182        TString classname = caltrk->GetName();
183    //  ----------
184    //  Check CRCs
185    //  ----------
186        if(TrkParams::VerboseMode())cout << " DSP: ";
187        for(Int_t ipkt=0; ipkt<6; ipkt++){
188            if(TrkParams::VerboseMode())cout <<" "<<caltrk->DSPnumber[ipkt];
189            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
190                if( caltrk->crc_hcal[ipkt] ){
191                    if(TrkParams::WarningMode())cout<<"(CRC Header)";
192    //              if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl;    
193    //              return 0; // :-(
194                    validate = 0;
195                }
196                for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){
197                    if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")";
198    //              if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl;    
199    //              return 0; // :-(
200                    validate = 0;
201                }
202            }
203        }
204        if(TrkParams::VerboseMode())cout << endl;;
205    //  -----------------------
206    //  Check missing packets:
207    //  -----------------------
208    //    Readout order:
209    //    ------------------
210    //    DSP   packet board
211    //    ------------------
212    //    12    0      1
213    //    10    1      1
214    //     8    2      1
215    //     4    3      1
216    //     6    4      1
217    //     2    5      1
218    //    ------------------
219    //    11    0      2
220    //     9    1      2
221    //     7    2      2
222    //     3    3      2
223    //     5    4      2
224    //     1    5      2
225    //    ------------------
226    //  -------------------------------------------------
227    //  Check if it is first or second calibration packet
228    //  -------------------------------------------------
229        UInt_t build=0;
230        UInt_t base=0;
231        UInt_t mask=0;
232        if(classname.Contains("CalibTrk1Event")){
233            base=12;
234            mask=0x03F000;
235        }
236        if(classname.Contains("CalibTrk2Event")){
237            base=18;
238            mask=0xFC0000;
239        }
240    //  -------------------------------------------------
241    //  Count number of packets and set build variable
242    //  -------------------------------------------------
243        Int_t  npkts=0;
244        for(Int_t ipkt=0; ipkt<6; ipkt++){
245            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
246                npkts++;
247                build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
248            };
249        }
250        if( npkts==6 ){}//return 1; // :-)
251        else {
252            if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-(  ( "<<npkts<<" instead of 6 ) --> "<<endl;    
253            validate = 0;
254        }
255    //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
256    
257    //  -----------------------------------------------
258    //  If missing packets: check the acq configuration
259    //  (some DSPs might be excluded from acquisition)
260    //  -----------------------------------------------
261    
262    //  -----------------------------------------------
263    //  retrieve the first run header after calib
264    //  -----------------------------------------------
265    //      PacketType *pctp;
266    //      EventCounter *cod;
267    //      cod = eh->GetCounter();
268    //      Int_t irun = cod->Get(pctp->RunHeader);
269    //      TTree *rh=(TTree*)file->Get("RunHeader");
270    //      if ( !rh || rh->IsZombie() ) throw -17;
271    //      if( rh->GetEntries() == irun ){
272    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;
273    //       return 0; // :-(
274    //      }
275    
276    //      RunHeaderEvent *run  = 0;
277    //      EventHeader    *hrun = 0;
278    //      rh->SetBranchAddress("RunHeader", &run);
279    //      rh->SetBranchAddress("Header", &hrun);
280    //      rh->GetEntry(irun);
281    // //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
282    
283    //      if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
284    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
285    //       return 0; // :-(
286    //      }
287        
288    //      if( !run->RM_ACQ_AFTER_CALIB ){
289    //        if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;
290    //       return 0; // :-(
291    //      }
292    
293    //      UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
294    //      if( dtime > timeaftercalib ){
295    //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
296    //       return 0; // :-(
297    //      }
298        
299    //      if( (run->ACQ_BUILD_INFO & mask) != build ){
300    //       if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
301    //       return 0; // :-(
302    //      }
303    
304    //      return 1; // :-)
305    
306    //    cout << validate << endl;
307        return validate;
308    
309    }
310    /**
311   * Method to fill the tracker calibration-parameter struct from on-line calibrations   * Method to fill the tracker calibration-parameter struct from on-line calibrations
312   */   */
313  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){
314    
315      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
316        ca->Reset();
317    
318      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
319      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 89  void TrkParams::FillACalibFrom(TFile* f0 Line 325  void TrkParams::FillACalibFrom(TFile* f0
325      tr1->GetEntry(ev_reg1);      tr1->GetEntry(ev_reg1);
326      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
327      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
328            
329        // --- TEST TEST TEST TEST --- //
330    //    TrkParams::ValidateTrkCalib(calibdata1);
331    //    TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
332    
333        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
334        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
335        if( !test1 || !test2 ){
336            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
337            TrkParams::calib.VALIDATION = 0;
338        }
339        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
340    
341      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
342          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
343          dspn2=calibdata2->DSPnumber[i]-1;          dspn2=calibdata2->DSPnumber[i]-1;
344          /*     cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl; */  //      cout<<"dspn1= "<<dspn1<<"   dspn2= "<<dspn2<<endl;      
345          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
346              Int_t j=(ii/128);              Int_t j=(ii/128);
347              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
348              ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];              if(dspn1>=0 && dspn1<12){
349              ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
350              ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
351              ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
352              ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
353              ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];                  if(calibdata1->DSPbad_par[i][ii]==0)
354              ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);                      ca->bad[jj][j][dspn1]=1;
355              ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);                  else if(calibdata1->DSPbad_par[i][ii]==1)
356              //        cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;                      ca->bad[jj][j][dspn1]=0;
357              //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
358              //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;                  //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
359              //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;              }
360            
361              //              if(dspn2>=0 && dspn2<12){
362              // invert the bad                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
363              //                  ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
364              if(calibdata1->DSPbad_par[i][ii]==0)                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
365                  ca->bad[jj][j][dspn1]=1;                  ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
366              else if(calibdata1->DSPbad_par[i][ii]==1)                  if(calibdata2->DSPbad_par[i][ii]==0)
367                  ca->bad[jj][j][dspn1]=0;                      ca->bad[jj][j][dspn2]=1;
368              if(calibdata2->DSPbad_par[i][ii]==0)                  else if(calibdata2->DSPbad_par[i][ii]==1)
369                  ca->bad[jj][j][dspn2]=1;                      ca->bad[jj][j][dspn2]=0;
370              else if(calibdata2->DSPbad_par[i][ii]==1)                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
371                  ca->bad[jj][j][dspn2]=0;                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
372                }
373          };          };
374      };      };
375                    
# Line 133  void TrkParams::FillACalibFrom(TFile* f0 Line 382  void TrkParams::FillACalibFrom(TFile* f0
382  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){
383    
384      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
385    //    ca->Reset();
386    
387      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
388      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 144  void TrkParams::FillFCalibFrom(TFile* f0 Line 394  void TrkParams::FillFCalibFrom(TFile* f0
394      tr1->GetEntry(ev_reg1);      tr1->GetEntry(ev_reg1);
395      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
396      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
397    
398        // --- TEST TEST TEST TEST --- //
399    //     TrkParams::ValidateTrkCalib(calibdata1);
400    //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
401        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
402        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
403        if( !test1 || !test2 ){
404            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
405            TrkParams::calib.VALIDATION = 0;
406        }
407        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
408                    
409      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
410          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
# Line 152  void TrkParams::FillFCalibFrom(TFile* f0 Line 413  void TrkParams::FillFCalibFrom(TFile* f0
413          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
414              Int_t j=(ii/128);              Int_t j=(ii/128);
415              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
416              ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];              if(dspn1>=0 && dspn1<12){
417              ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];                  ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
418              ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];                  ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
419              ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];                  if(calibdata1->DSPbad_par[i][ii]==0)
420              //        cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;                      ca->bad[jj][j][dspn1]=1;
421              //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;                  else if(calibdata1->DSPbad_par[i][ii]==1)
422              //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;                      ca->bad[jj][j][dspn1]=0;
423              //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;                  //            cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
424                            //        cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
425              //              }
426              // invert the bad              if(dspn2>=0 && dspn2<12){
427              //                  ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
428              if(calibdata1->DSPbad_par[i][ii]==0)                  ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
429                  ca->bad[jj][j][dspn1]=1;                  if(calibdata2->DSPbad_par[i][ii]==0)
430              else if(calibdata1->DSPbad_par[i][ii]==1)                      ca->bad[jj][j][dspn2]=1;
431                  ca->bad[jj][j][dspn1]=0;                  else if(calibdata2->DSPbad_par[i][ii]==1)
432              if(calibdata2->DSPbad_par[i][ii]==0)                      ca->bad[jj][j][dspn2]=0;
433                  ca->bad[jj][j][dspn2]=1;                  //        cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
434              else if(calibdata2->DSPbad_par[i][ii]==1)                  //        cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
435                  ca->bad[jj][j][dspn2]=0;              }
436          };          };
437      };      };
438                    
# Line 184  void TrkParams::FillFCalibFrom(TFile* f0 Line 445  void TrkParams::FillFCalibFrom(TFile* f0
445  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){
446    
447      cTrkCalib *ca = &pedsigbad_;      cTrkCalib *ca = &pedsigbad_;
448    //    ca->Reset();
449    
450      TTree *tr1 = (TTree*)f0->Get("CalibTrk1");        TTree *tr1 = (TTree*)f0->Get("CalibTrk1");  
451      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");      TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
# Line 196  void TrkParams::FillTCalibFrom(TFile* f0 Line 458  void TrkParams::FillTCalibFrom(TFile* f0
458      tr2->GetEntry(ev_reg2);      tr2->GetEntry(ev_reg2);
459      Int_t dspn1(0),dspn2(0);      Int_t dspn1(0),dspn2(0);
460                    
461        // --- TEST TEST TEST TEST --- //
462    //     TrkParams::ValidateTrkCalib(calibdata1);
463    //     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
464        UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1);
465        UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
466        if( !test1 || !test2 ){
467            if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl;
468            TrkParams::calib.VALIDATION = 0;
469        }
470        if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl;
471    
472      for(Int_t i=0;i<6;i++){      for(Int_t i=0;i<6;i++){
473          dspn1=calibdata1->DSPnumber[i]-1;          dspn1=calibdata1->DSPnumber[i]-1;
474          dspn2=calibdata2->DSPnumber[i]-1;          dspn2=calibdata2->DSPnumber[i]-1;
# Line 203  void TrkParams::FillTCalibFrom(TFile* f0 Line 476  void TrkParams::FillTCalibFrom(TFile* f0
476          for(Int_t ii=0;ii<3072;ii++){          for(Int_t ii=0;ii<3072;ii++){
477              Int_t j=(ii/128);              Int_t j=(ii/128);
478              Int_t jj=ii-j*128;              Int_t jj=ii-j*128;
479              ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);              if(dspn1>=0 && dspn1<12){
480              ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);                  ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
481              ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);                  ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
482              ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);                  }
483                if(dspn2>=0 && dspn2<12){
484                    ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
485                    ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
486                }  
487          };          };
488      };      };
489                    
# Line 229  void TrkParams::FillTCalibFrom(TString p Line 506  void TrkParams::FillTCalibFrom(TString p
506  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){
507            
508      cTrkMask *ma = &mask_;      cTrkMask *ma = &mask_;
509        ma->Reset();
510    
511      TrkCalib *calib = new TrkCalib();      TrkCalib *calib = new TrkCalib();
512    
# Line 251  void TrkParams::FillMask(TFile* f0, Int_ Line 529  void TrkParams::FillMask(TFile* f0, Int_
529              tr->GetEntry(ev_reg2);              tr->GetEntry(ev_reg2);
530          }          }
531          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){          for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){
532              for(Int_t ivk=0; ivk<NVK; ivk++){              Int_t view   = calib->GetView(ipkt);
533                  Int_t view   = calib->GetView(ipkt);              if( (view-1)>= 0 && (view-1)<12 ){
534                  Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);                  for(Int_t ivk=0; ivk<NVK; ivk++){
535                  Float_t sigmin = 0.;                      Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);
536                  if(view%2)sigmin = 6.5;                      Float_t sigmin = 0.;
537                  else      sigmin = 2.5;                      if(view%2)sigmin = 6.5;
538                  Int_t mask = 1;                      else      sigmin = 2.5;
539                  if( sigm<sigmin )mask = 0;                      Int_t mask = 1;
540                                    if( sigm<sigmin )mask = 0;              
541                  ma->mask_vk_run[ivk][view-1] = mask;                      ma->mask_vk_run[ivk][view-1] = mask;                    
542                                }      
543  //              if(mask==0)cout<< " VIEW "<<view<<" VK "<<ivk+1<<" -- <SIG> "<<sigm<<" ---> MASKED!"<<endl;              }
             }    
544          }          }
545          if(tr)tr->Delete();          if(tr)tr->Delete();
546      }      }
547    
548        if(TrkParams::VerboseMode()){
549            for(Int_t iv=0; iv<NVIEW; iv++){
550                cout<<"view "<<setw(3)<<iv<<": ";
551                for(Int_t ivk=0; ivk<NVK; ivk++)cout<<ma->mask_vk_run[ivk][iv];
552                cout << endl;
553            }
554        }
555    
556      if(calib)calib->Delete();      if(calib)calib->Delete();
557    
558  };  };
559    
560    // Bool_t TrkParams::CalibIsLoaded(UInt_t time){
561    
562    //     if( !calibload ) return false;
563    
564    // };
565    
566    
567  /**  /**
568   * Static method to load calibration.   * \brief Static method to load calibration.
569   * 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.  
570   */   */
571  Bool_t TrkParams::LoadCalib( ){  Bool_t TrkParams::LoadCalib( ){
572    
573      if( TrkParams::CalibIsLoaded() )return false;      if( TrkParams::CalibIsLoaded() )return false;
574    
 //    cTrkCalib *ca = new cTrkCalib; //&pedsigbad_;  
   
 //     extern cTrkCalib   pedsigbad_;  
 //     extern cTrkMask    mask_;  
   
     cout << "--------------------------------------"<<endl;  
     cout << "Retrieve calibration (PED-SIG-BAD) ..."<<endl;  
575      // =============================================================      // =============================================================
576      // retrieve calibration file needed to reduce data      // retrieve calibration file needed to reduce data
577      // =============================================================      // =============================================================
578      // if run OBT is > last calibration "expiration date"      // if run OBT is > last calibration "expiration date"
579      //  - search for new calibration packet      //  - search for new calibration packet
580      //  - load calibration parameters (full + truncated)          //  - load calibration parameters (full + truncated)    
581      cout << "Full pedestals for cluster finding:";      if(TrkParams::VerboseMode()){
582      cout << " >> Loading from LEVEL0 file: "<< calibpathf << endl;          cout << "--------------------------------------"<<endl;
583            cout << "Retrieve calibration (PED-SIG-BAD) ..."<<endl;
584            cout << " Full pedestals for cluster finding:";
585            cout << " >> loading from LEVEL0 file: "<< calibpathf << endl;
586        }
587      FileStat_t t;      FileStat_t t;
588      if( gSystem->GetPathInfo(calibpathf.Data(),t) )return false;      if( gSystem->GetPathInfo(calibpathf.Data(),t) )return false;
589        
590      TFile *f0_c = new TFile(calibpathf);      bool alreadyopened = false;
591        TFile *f0_c=0;
592        f0_c = (TFile*)gROOT->GetListOfFiles()->FindObject(calibpathf);
593        if(f0_c)alreadyopened=true;
594        else f0_c = new TFile(calibpathf);
595      if ( !f0_c ) return false;      if ( !f0_c ) return false;
596      cout << " calibration entries "<< calib.EV_ROOT_CALIBTRK1 << " " << calib.EV_ROOT_CALIBTRK2;  
597      cout << " (from time "<< calib.FROM_TIME <<" to time "<< calib.TO_TIME <<")"<<endl;      if(TrkParams::VerboseMode()){
598  //    ca->FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);          cout << " calibration entry "<< calib.EV_ROOT_CALIBTRK1 << " " << calib.EV_ROOT_CALIBTRK2;
599            cout << " (from time "<< calib.FROM_TIME <<" to time "<< calib.TO_TIME <<")"<<endl;
600            cout << " - full+truncated parameters "<<endl;
601        }
602      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
603        if(TrkParams::VerboseMode())cout << " - VK-mask "<<endl;
604      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);      TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
 //    mask_.Set(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);  
605    
 //    };  
606      // =============================================================      // =============================================================
607      // retrieve calibration file needed to uncompress data      // retrieve calibration file needed to uncompress data
608      // =============================================================      // =============================================================
609      // if the run was compressed using default calib      // if the run was compressed using default calib
610      // load truncated pedestals from default      // load truncated pedestals from default
611      // otherwise reload them from on-line calibration      // otherwise reload them from on-line calibration
612      cout << "Truncated pedestals for uncompression:";      if(TrkParams::VerboseMode())cout << " Truncated pedestals for uncompression:";
613      if( calib104 ){      if( calib104 ){
614    
615          cout << " >> Loading default calibration: "<< calibpatht << endl;          if(TrkParams::VerboseMode())cout << " >> loading default calibration: "<< calibpatht << endl;
 //      ca->FillTCalibFrom(calibpatht);  
616          TrkParams::FillTCalibFrom(calibpatht);          TrkParams::FillTCalibFrom(calibpatht);
617                            
618      }else{      }else{
619    
620          if ( !f0_c ) return false;  //      if ( !f0_c ) return false;
621          cout << ">> Loading on-line calibration " << endl;          if(TrkParams::VerboseMode())cout << ">> already loaded " << endl;
622  //      ca->FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);  //      TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
         TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);  
623      };      };
624      f0_c->Close();      if(!alreadyopened)f0_c->Close();
625  //    delete f0_c;      if(TrkParams::VerboseMode())cout << "--------------------------------------"<<endl;
     cout << "--------------------------------------"<<endl;  
626            
627      calibload = kTRUE;      calibload = kTRUE;
628      return true;      return true;
# Line 350  Int_t TrkParams::GetIndex( UInt_t type ) Line 640  Int_t TrkParams::GetIndex( UInt_t type )
640   * @param dbc   Database   * @param dbc   Database
641   * @param type  Parameter type   * @param type  Parameter type
642   * @return FALSE if parameter set fails.   * @return FALSE if parameter set fails.
643   * 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.
644   * If dbc==NULL, try to open a connection taking DB-connection   * If dbc==NULL, try to open a connection taking DB-connection
645   * parameters from PAMELA environment variables.   * parameters from PAMELA environment variables.
646   */   */
647  Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type){  Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type){
648    
 //    if( !dbc )return false;  
   
   
     if( !dbc || (dbc && !dbc->IsConnected()) ){  
   
         cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;  
         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;  
         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;      
         cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
   
     }  
649    
650      UInt_t index = TrkParams::GetIndex( type );      UInt_t index = TrkParams::GetIndex( type );
651      if(index < 0)return false;      if(index < 0)return false;
652    
653      UInt_t runheadtime = numeric_limits<UInt_t>::max();      UInt_t runheadtime=0;
654      if(glrun)runheadtime = glrun->RUNHEADER_TIME;      UInt_t runid=0;
655      else cout <<"Missing run info -- taking last entry "<<endl;  //    UInt_t runheadtime = numeric_limits<UInt_t>::max();
656        if(glrun){
657            runheadtime = glrun->RUNHEADER_TIME;
658            runid       = glrun->ID;
659        }else cout <<"Bool_t TrkParams::Set(GL_RUN*,TSQLServer*,UInt_t) >> Missing run info -- taking first entry (**WARNING** check that this is ok!! )"<<endl;
660    
661    //    if(TrkParams::VerboseMode())
662        cout << "<< set TrkParams type "<<type<<" from DB << RUN "<<runid<<endl;
663    
664    
665        if( !TrkParams::IsLoaded(type) ||
666            runheadtime < gl[index].FROM_TIME   ||
667            runheadtime > gl[index].TO_TIME     ||  
668            false ){
669    
670            bool LOCAL_CONNECTION = false;
671            if( !dbc || (dbc && !dbc->IsConnected()) ){
672    
673                if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
674                dbc = TrkParams::SetDBConnection();
675                if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true;
676    
677      GL_PARAM q4;          }
     if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;  
678    
679      gl[index]     = q4;          GL_PARAM q4;
680      glpath[index] = q4.PATH+q4.NAME;          if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;      
681      glload[index] = false;          if(LOCAL_CONNECTION){
682      cout << "<< set TrkParams type "<<type<<" >>"<<endl;              dbc->Close();
683      return true;              delete dbc;
684  //    return TrkParams::Load(type);          }
685            gl[index]     = q4;
686            glpath[index] = q4.PATH+q4.NAME;
687            glload[index] = false;
688    
689            return true;
690    
691        }
692        return false;
693    
694  };  };
695  /**  /**
696   * Set tracker parameters proper for the run, from the from input.   * Set tracker parameters proper for the run, from input.
697   * @param path  Path to parameters directory   * @param path  Path to parameters directory
698   * @param type  Parameter type   * @param type  Parameter type
699   * @return FALSE if parameter set fails.   * @return FALSE if parameter set fails.
# Line 417  Bool_t TrkParams::Set( TString path , UI Line 705  Bool_t TrkParams::Set( TString path , UI
705    
706      gl[index].TYPE= type;      gl[index].TYPE= type;
707      glpath[index] = path;      glpath[index] = path;
708      cout << "<< set TrkParams type "<<type<<" >>"<<endl;      if(TrkParams::VerboseMode())
709            cout << "<< set TrkParams type "<<type<<" from path << "<<path<<endl;
710      glload[index] = false;      glload[index] = false;
711    
712  //    return TrkParams::Load(type);  //    return TrkParams::Load(type);
# Line 433  Bool_t TrkParams::Set( TString path , UI Line 722  Bool_t TrkParams::Set( TString path , UI
722   */   */
723  Bool_t TrkParams::Set(UInt_t type){  Bool_t TrkParams::Set(UInt_t type){
724    
     UInt_t index = TrkParams::GetIndex( type );  
     if(index < 0)return false;  
725    
726      gl[index].TYPE= type;      return Set(0,0,type);
     glload[index] = false;  
727    
     // -----------------------------------------  
     // 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;  
           
     }  
   
     cout << "<< set TrkParams type "<<type<<" >>"<<endl;  
 //    return TrkParams::Load(type);  
     return true;  
728    
729  };  };
730  /**  /**
# Line 489  Bool_t TrkParams::Set(UInt_t type){ Line 735  Bool_t TrkParams::Set(UInt_t type){
735   */   */
736  Bool_t  TrkParams::Set( ){  Bool_t  TrkParams::Set( ){
737    
     Bool_t connected = false;  
738    
739      cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;      for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false;
740      TString host = "mysql://localhost/pamelaprod";  
741      TString user = "anonymous";      return 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;  
     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 << " >> FAILED!!!"<<endl;  
     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;  
742  }  }
743    
744  /**  /**
# Line 536  Bool_t TrkParams::Load(UInt_t type){ Line 757  Bool_t TrkParams::Load(UInt_t type){
757      switch( type ){      switch( type ){
758      //------------------------------------------      //------------------------------------------
759      case 1:          case 1:    
760          cout <<type<<" -- Loading magnetic field "<<glpath[index]<<endl;          if(TrkParams::VerboseMode())cout <<type<<" -- Loading magnetic field "<<glpath[index]<<endl;
761          strcpy(path_.path,glpath[index].Data());          strcpy(path_.path,glpath[index].Data());
762          path_.pathlen = glpath[index].Length();          path_.pathlen = glpath[index].Length();
763          path_.error   = 0;          path_.error   = 0;
# Line 546  Bool_t TrkParams::Load(UInt_t type){ Line 767  Bool_t TrkParams::Load(UInt_t type){
767          break;          break;
768      //------------------------------------------      //------------------------------------------
769      case 2:          case 2:    
770          cout <<type<<" -- Loading ADC-to-MIP conversion parameters "<<glpath[index]<<endl;          if(TrkParams::VerboseMode())cout <<type<<" -- Loading ADC-to-MIP conversion parameters "<<glpath[index]<<endl;
771          strcpy(path_.path,glpath[index].Data());          strcpy(path_.path,glpath[index].Data());
772          path_.pathlen = glpath[index].Length();          path_.pathlen = glpath[index].Length();
773          path_.error   = 0;          path_.error   = 0;
# Line 556  Bool_t TrkParams::Load(UInt_t type){ Line 777  Bool_t TrkParams::Load(UInt_t type){
777          break;          break;
778      //------------------------------------------      //------------------------------------------
779      case 3:          case 3:    
780          cout <<type<<" -- Loading charge-correlation parameters "<<glpath[index]<<endl;          if(TrkParams::VerboseMode())cout <<type<<" -- Loading charge-correlation parameters "<<glpath[index]<<endl;
781          strcpy(path_.path,glpath[index].Data());          strcpy(path_.path,glpath[index].Data());
782          path_.pathlen = glpath[index].Length();          path_.pathlen = glpath[index].Length();
783          path_.error   = 0;          path_.error   = 0;
# Line 566  Bool_t TrkParams::Load(UInt_t type){ Line 787  Bool_t TrkParams::Load(UInt_t type){
787          break;          break;
788      //------------------------------------------      //------------------------------------------
789      case 4:          case 4:    
790          cout <<type<<" -- Loading p.f.a. parameters "<<glpath[index]<<endl;          if(TrkParams::VerboseMode())cout <<type<<" -- Loading p.f.a. parameters "<<glpath[index]<<endl;
791          strcpy(path_.path,glpath[index].Data());          strcpy(path_.path,glpath[index].Data());
792          path_.pathlen = glpath[index].Length();          path_.pathlen = glpath[index].Length();
793          path_.error   = 0;          path_.error   = 0;
# Line 576  Bool_t TrkParams::Load(UInt_t type){ Line 797  Bool_t TrkParams::Load(UInt_t type){
797          break;          break;
798      //------------------------------------------      //------------------------------------------
799      case 5:          case 5:    
800          cout <<type<<" -- Loading alignment parameters "<<glpath[index]<<endl;          if(TrkParams::VerboseMode())cout <<type<<" -- Loading alignment parameters "<<glpath[index]<<endl;
801          strcpy(path_.path,glpath[index].Data());          strcpy(path_.path,glpath[index].Data());
802          path_.pathlen = glpath[index].Length();          path_.pathlen = glpath[index].Length();
803          path_.error   = 0;          path_.error   = 0;
# Line 586  Bool_t TrkParams::Load(UInt_t type){ Line 807  Bool_t TrkParams::Load(UInt_t type){
807          break;          break;
808      //------------------------------------------      //------------------------------------------
809      case 6:          case 6:    
810          cout <<type<<" -- Loading VK-mask parameters "<<glpath[index]<<endl;          if(TrkParams::VerboseMode())cout <<type<<" -- Loading VK-mask parameters "<<glpath[index]<<endl;
811          strcpy(path_.path,glpath[index].Data());          strcpy(path_.path,glpath[index].Data());
812          path_.pathlen = glpath[index].Length();          path_.pathlen = glpath[index].Length();
813          path_.error   = 0;          path_.error   = 0;
# Line 596  Bool_t TrkParams::Load(UInt_t type){ Line 817  Bool_t TrkParams::Load(UInt_t type){
817          break;          break;
818      //------------------------------------------      //------------------------------------------
819      case 7:          case 7:    
820          cout <<type<<" -- Loading default calibration "<<glpath[index]<<endl;          if(TrkParams::VerboseMode())cout <<type<<" -- Loading default calibration "<<glpath[index]<<endl;
821          strcpy(path_.path,glpath[index].Data());          strcpy(path_.path,glpath[index].Data());
822          path_.pathlen = glpath[index].Length();          path_.pathlen = glpath[index].Length();
823          path_.error   = 0;          path_.error   = 0;
824  //      fillpedsigfromdefault_();  //      fillpedsigfromdefault_();
825          cout << ">> not implemented <<"<<endl;          if(TrkParams::VerboseMode())cout << ">> not implemented <<"<<endl;
826          if(path_.error) return false;          if(path_.error) return false;
827          glload[index]=true;          glload[index]=true;
828          break;          break;
829      default:      default:
830          cout << " Bool_t TrkParams::Load(UInt_t type) -- type "<< type << "not yet implemented"<<endl;          if(TrkParams::VerboseMode())cout << " Bool_t TrkParams::Load(UInt_t type) -- type "<< type << "not yet implemented"<<endl;
831          return false;          return false;
832      };      };
833    
# Line 622  Bool_t TrkParams::IsLoaded( ){ Line 843  Bool_t TrkParams::IsLoaded( ){
843      return true;      return true;
844  };  };
845    
846    
847    /**
848     * Get BY (kGauss)
849     * @param v (x,y,z) coordinates in cm
850     */
851    float TrkParams::GetBX(float* v){
852        TrkParams::Load(1);
853        if( !TrkParams::IsLoaded(1) )return 0.;
854        float b[3];
855        gufld_(v,b);
856        return b[0]/10.;
857    }
858    /**
859     * Get BY (kGauss)
860     * @param v (x,y,z) coordinates in cm
861     */
862    float TrkParams::GetBY(float* v){
863        TrkParams::Load(1);
864        if( !TrkParams::IsLoaded(1) )return 0.;
865        float b[3];
866        gufld_(v,b);
867        return b[1]/10.;
868    }
869    /**
870     * Get BY (kGauss)
871     * @param v (x,y,z) coordinates in cm
872     */
873    float TrkParams::GetBZ(float* v){
874        TrkParams::Load(1);
875        if( !TrkParams::IsLoaded(1) )return 0.;
876        float b[3];
877        gufld_(v,b);
878        return b[2]/10.;
879    }
880    
881    
882    /**
883     * \brief Set tracking mode (0=standard. 1=???)
884     */
885    void TrkParams::SetTrackingMode(int trackmode) {
886        init__mini_trackmode = trackmode;
887        SetTrackingMode(); //fill F77 common
888    };
889    /**
890     * \brief Set fit-precision factor (typical value fact=100.)
891     */
892    void TrkParams::SetPrecisionFactor(double fact){
893        init__mini_fact      = fact;
894        SetPrecisionFactor(); //fill F77 common
895    };
896    /**
897     * \brief Set minimum number of step in track fitting
898     */
899    void TrkParams::SetStepMin(int istepmin){
900        init__mini_istepmin  = istepmin;
901        SetStepMin(); //fill F77 common
902    };
903    /**
904     * \brief Set deltaB parameters (id=0,1)
905     */
906    void TrkParams::SetDeltaB(int id,double db){
907        if(id!=0 && id!=1)cout << "void TrkParams::SetDeltaB(int id,double db) -- wrong input parameters: "<<id<<" "<<db<<endl;
908        if(id==0)init__deltab_0 = db;
909        if(id==1)init__deltab_1 = db;
910        SetDeltaB(); //fill F77 common
911    };
912    
913    /**
914     * \brief Fill F77 commons with PFA settings
915     */
916    void TrkParams::SetPFA(){
917        sw_.pfaid = init__pfa;    
918        for(int i=0; i<6; i++){
919            pfa_.e234ax[i] = init__pfa_e234ax[i];
920            pfa_.e234ay[i] = init__pfa_e234ay[i];
921        }
922    };
923    /**
924     * \brief Set p.f.a.
925     *
926     * Implemented algorythms:
927     * 0  ETA
928     * 1  ---
929     * 2  ETA2
930     * 3  ETA3
931     * 4  ETA4
932     * 5  ETAL ==> ETA+LANDI
933     * 10 COG
934     * 11 COG1
935     * 12 COG2
936     * 13 COG3
937     * 14 COG4
938     */
939    void TrkParams::SetPFA(int pfaid){
940        init__pfa  = pfaid;
941        SetPFA(); //fill F77 common
942    };
943    /**
944     * \brief Set p.f.a. angular intervals
945     *
946     * This methods allows to set amgular intervals to apply ETA2,ETA3 or ETA4
947     * algorythm, in case ETA or ETAL is set (see TrkParams::SetPFA(int pfaid)).
948     * @param v Pointer to a vector of 12 components, which represent the
949     * angular limits for ETA2,ETA3 and ETA4, for x and y views, respectivelly.
950     *
951     */
952    void TrkParams::SetPFA(float *v){
953        for(int i=0; i<6; i++){
954            init__pfa_e234ax[i]  = v[i];
955            init__pfa_e234ay[i]  = v[i+6];
956        }
957        SetPFA(); //fill F77 common
958    };
959    
960    
961    /**
962     * \brief Get spatial resolution.
963     *
964     * Method to retrieve the spatial resolution associated with the
965     * adopted p.f.a.
966     * @param view Tracker view (1-12)
967     * @param angle Track projected angle
968     *
969     * In order to change p.f.a. use the SetPFA(int pfaid) method, eg.:
970     *
971     *  TrkParams::SetPFA(0)  // ETA
972     *
973     */
974    float TrkParams::GetResolution(int view, float angle){
975        float res = 1000;
976        if( init__pfa == 0 )res = riseta_(&view,&angle);
977        else cout << "float TrkParams::GetResolution(int view, float angle) -- PFA "<<init__pfa<<" not yet implemented"<<endl;
978        return res;
979    }
980    
981    
982    
983    
984  ClassImp(TrkParams);  ClassImp(TrkParams);

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

  ViewVC Help
Powered by ViewVC 1.1.23