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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Mon May 14 11:03:05 2007 UTC (17 years, 7 months ago) by pam-fi
Branch: MAIN
Changes since 1.7: +90 -1 lines
implemented method to reprocess a track, starting from cluster positions

1 pam-fi 1.1 /**
2     * \file TrkParams.cpp
3     * \author Elena Vannuccini
4     */
5    
6     #include <TrkParams.h>
7     #include <iostream>
8     using namespace std;
9    
10    
11     // -------------------------
12     // CALIBRATION (PED,SIG,BAD)
13     // -------------------------
14     GL_TRK_CALIB TrkParams::calib = GL_TRK_CALIB();
15     TString TrkParams::calibpatht = "";
16     TString TrkParams::calibpathf = "";
17     Bool_t TrkParams::calib104 = 0;
18     Bool_t TrkParams::calibload = false;
19 pam-fi 1.8 // -------------------------
20     // PARAMETERS loaded from DB
21     // -------------------------
22 pam-fi 1.1 UInt_t TrkParams::trkparamtype[] = {1,2,3,4,5,6,7};
23     GL_PARAM TrkParams::gl[] = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()};
24     TString TrkParams::glpath[] = {"","","","","","",""};
25     Bool_t TrkParams::glload[] = {false,false,false,false,false,false,false};
26 pam-fi 1.6 cDbg TrkParams::dbg_mode = {0,0,0};
27 pam-fi 1.8 // ----------------
28     // other parameters
29     // ----------------
30     int TrkParams::init__pfa = 14;//COG4
31     int TrkParams::init__mini_trackmode = 0;
32     int TrkParams::init__mini_istepmin = 3;
33     double TrkParams::init__mini_fact = 100.;
34 pam-fi 1.1
35     TrkParams::TrkParams(){
36    
37 pam-fi 1.8 cout<<"TrkParams::TrkParams()"<<endl;
38 pam-fi 1.1
39     }
40     float aint(float f){
41     int ret = (int)f;
42     float ret1 = 0;
43     ret1=(float)ret;
44     return ret1;
45     }
46    
47     float anint(float f){
48     int ret = (int)(f+0.5);
49     float ret1 = 0;
50     ret1=(float)ret;
51     return ret1;
52     }
53     /**
54     * Static method to set the calibration to be loaded.
55    
56     * It retrieves the calibration associated to a given run, from
57     * a given DB. It fills the F77 common.
58     * @param glrun Pointer to a GL_RUN row
59     * @param dbc Pointer to a DB connection
60     */
61     Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){
62    
63 pam-fi 1.6 // cout << "glrun-> RUNHEADER_TIME "<<glrun->RUNHEADER_TIME <<endl;
64    
65 pam-fi 1.3 if( !CalibIsLoaded() ||
66     (glrun->TRK_CALIB_USED==104 && !calib104) ||
67     (glrun->TRK_CALIB_USED!=104 && calib104) ||
68     glrun->RUNHEADER_TIME < calib.FROM_TIME ||
69     glrun->RUNHEADER_TIME > calib.TO_TIME ||
70     false ){
71    
72     GL_TRK_CALIB q2;
73     GL_ROOT q3;
74     GL_PARAM q4;
75    
76 pam-fi 1.6 if(TrkParams::VerboseMode()){
77     cout << "--------------------------------------"<<endl;
78     cout << "UPDATING calibration -- run-header time "<< glrun->RUNHEADER_TIME <<endl;
79     }
80 pam-fi 1.3 if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) ){
81 pam-fi 1.6 cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_TRK_CALIB "<<endl;
82 pam-fi 1.3 return false;
83     }
84     if( q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2 )
85 pam-fi 1.6 printf(" WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2);
86 pam-fi 1.3 if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) ){
87 pam-fi 1.6 cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_ROOT "<<endl;
88 pam-fi 1.3 return false;
89     }
90    
91 pam-fi 1.6 if(TrkParams::VerboseMode())cout << "selected DB entry "<<q2.ID<<" from_time "<<q2.FROM_TIME<<" to time "<<q2.TO_TIME<<" --> VALIDATION "<<q2.VALIDATION<<endl;
92 pam-fi 1.3 calib = q2;
93     calibpathf = q3.PATH + q3.NAME;
94     calib104 = (glrun->TRK_CALIB_USED==104);
95     calibload = kFALSE;
96     if(calib104){
97     if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false;
98     calibpatht = q4.PATH + q4.NAME;
99     }
100    
101 pam-fi 1.1
102 pam-fi 1.3 // return TrkParams::LoadCalib();
103     return true;
104 pam-fi 1.1 }
105    
106 pam-fi 1.3 return false;
107 pam-fi 1.1 };
108    
109     /**
110 pam-fi 1.4 * Method to "validate" tracker calibration. Implemented for test purpose. Effective implementation
111     * in YodaProfiler.
112     */
113     UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){
114    
115     Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
116     // UInt_t timeaftercalib=120000; //2000;
117     TString classname = caltrk->GetName();
118     // ----------
119     // Check CRCs
120     // ----------
121 pam-fi 1.6 if(TrkParams::VerboseMode())cout << " DSP: ";
122 pam-fi 1.4 for(Int_t ipkt=0; ipkt<6; ipkt++){
123 pam-fi 1.7 if(TrkParams::VerboseMode())cout <<" "<<caltrk->DSPnumber[ipkt];
124 pam-fi 1.5 if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
125     if( caltrk->crc_hcal[ipkt] ){
126 pam-fi 1.6 if(TrkParams::WarningMode())cout<<"(CRC Header)";
127     // if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl;
128 pam-fi 1.5 // return 0; // :-(
129     }
130     for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){
131 pam-fi 1.6 if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")";
132     // if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl;
133 pam-fi 1.5 // return 0; // :-(
134     }
135 pam-fi 1.4 }
136     }
137 pam-fi 1.6 if(TrkParams::VerboseMode())cout << endl;;
138 pam-fi 1.4 // -----------------------
139     // Check missing packets:
140     // -----------------------
141     // Readout order:
142     // ------------------
143     // DSP packet board
144     // ------------------
145     // 12 0 1
146     // 10 1 1
147     // 8 2 1
148     // 4 3 1
149     // 6 4 1
150     // 2 5 1
151     // ------------------
152     // 11 0 2
153     // 9 1 2
154     // 7 2 2
155     // 3 3 2
156     // 5 4 2
157     // 1 5 2
158     // ------------------
159     // -------------------------------------------------
160     // Check if it is first or second calibration packet
161     // -------------------------------------------------
162     UInt_t build=0;
163     UInt_t base=0;
164     UInt_t mask=0;
165     if(classname.Contains("CalibTrk1Event")){
166     base=12;
167     mask=0x03F000;
168     }
169     if(classname.Contains("CalibTrk2Event")){
170     base=18;
171     mask=0xFC0000;
172     }
173     // -------------------------------------------------
174     // Count number of packets and set build variable
175     // -------------------------------------------------
176     Int_t npkts=0;
177     for(Int_t ipkt=0; ipkt<6; ipkt++){
178     if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
179     npkts++;
180     build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
181     };
182     }
183     if( npkts==6 )return 1; // :-)
184 pam-fi 1.6 else {
185     if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-( ( "<<npkts<<" instead of 6 ) --> "<<endl;
186     }
187 pam-fi 1.4 // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
188    
189     // -----------------------------------------------
190     // If missing packets: check the acq configuration
191     // (some DSPs might be excluded from acquisition)
192     // -----------------------------------------------
193    
194     // -----------------------------------------------
195     // retrieve the first run header after calib
196     // -----------------------------------------------
197     // PacketType *pctp;
198     // EventCounter *cod;
199     // cod = eh->GetCounter();
200     // Int_t irun = cod->Get(pctp->RunHeader);
201     // TTree *rh=(TTree*)file->Get("RunHeader");
202     // if ( !rh || rh->IsZombie() ) throw -17;
203     // if( rh->GetEntries() == irun ){
204     // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl;
205     // return 0; // :-(
206     // }
207    
208     // RunHeaderEvent *run = 0;
209     // EventHeader *hrun = 0;
210     // rh->SetBranchAddress("RunHeader", &run);
211     // rh->SetBranchAddress("Header", &hrun);
212     // rh->GetEntry(irun);
213     // // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
214    
215     // if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
216     // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
217     // return 0; // :-(
218     // }
219    
220     // if( !run->RM_ACQ_AFTER_CALIB ){
221     // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl;
222     // return 0; // :-(
223     // }
224    
225     // UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
226     // if( dtime > timeaftercalib ){
227     // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
228     // return 0; // :-(
229     // }
230    
231     // if( (run->ACQ_BUILD_INFO & mask) != build ){
232     // if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
233     // return 0; // :-(
234     // }
235     return 1; // :-)
236    
237     }
238     /**
239 pam-fi 1.1 * Method to fill the tracker calibration-parameter struct from on-line calibrations
240     */
241     void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
242    
243     cTrkCalib *ca = &pedsigbad_;
244    
245     TTree *tr1 = (TTree*)f0->Get("CalibTrk1");
246     TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
247    
248     CalibTrk1Event *calibdata1 = 0;
249     CalibTrk2Event *calibdata2 = 0;
250     tr1->SetBranchAddress("CalibTrk1",&calibdata1);
251     tr2->SetBranchAddress("CalibTrk2",&calibdata2);
252     tr1->GetEntry(ev_reg1);
253     tr2->GetEntry(ev_reg2);
254     Int_t dspn1(0),dspn2(0);
255 pam-fi 1.4
256     // --- TEST TEST TEST TEST --- //
257     TrkParams::ValidateTrkCalib(calibdata1);
258     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
259 pam-fi 1.1
260     for(Int_t i=0;i<6;i++){
261     dspn1=calibdata1->DSPnumber[i]-1;
262     dspn2=calibdata2->DSPnumber[i]-1;
263     /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */
264     for(Int_t ii=0;ii<3072;ii++){
265     Int_t j=(ii/128);
266     Int_t jj=ii-j*128;
267     ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
268     ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
269     ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
270     ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
271     ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
272     ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
273     ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
274     ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
275     // cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
276     // cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
277     // cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
278     // cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
279    
280     //
281     // invert the bad
282     //
283     if(calibdata1->DSPbad_par[i][ii]==0)
284     ca->bad[jj][j][dspn1]=1;
285     else if(calibdata1->DSPbad_par[i][ii]==1)
286     ca->bad[jj][j][dspn1]=0;
287     if(calibdata2->DSPbad_par[i][ii]==0)
288     ca->bad[jj][j][dspn2]=1;
289     else if(calibdata2->DSPbad_par[i][ii]==1)
290     ca->bad[jj][j][dspn2]=0;
291     };
292     };
293    
294     tr1->Delete();
295     tr2->Delete();
296     };
297     /**
298     * Method to fill the tracker calibration-parameter struct from on-line calibrations
299     */
300     void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
301    
302     cTrkCalib *ca = &pedsigbad_;
303    
304     TTree *tr1 = (TTree*)f0->Get("CalibTrk1");
305     TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
306    
307     CalibTrk1Event *calibdata1 = 0;
308     CalibTrk2Event *calibdata2 = 0;
309     tr1->SetBranchAddress("CalibTrk1",&calibdata1);
310     tr2->SetBranchAddress("CalibTrk2",&calibdata2);
311     tr1->GetEntry(ev_reg1);
312     tr2->GetEntry(ev_reg2);
313     Int_t dspn1(0),dspn2(0);
314 pam-fi 1.4
315     // --- TEST TEST TEST TEST --- //
316     TrkParams::ValidateTrkCalib(calibdata1);
317     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
318 pam-fi 1.1
319     for(Int_t i=0;i<6;i++){
320     dspn1=calibdata1->DSPnumber[i]-1;
321     dspn2=calibdata2->DSPnumber[i]-1;
322     /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */
323     for(Int_t ii=0;ii<3072;ii++){
324     Int_t j=(ii/128);
325     Int_t jj=ii-j*128;
326     ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii];
327     ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii];
328     ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii];
329     ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii];
330     // cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl;
331     // cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl;
332     // cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl;
333     // cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl;
334    
335     //
336     // invert the bad
337     //
338     if(calibdata1->DSPbad_par[i][ii]==0)
339     ca->bad[jj][j][dspn1]=1;
340     else if(calibdata1->DSPbad_par[i][ii]==1)
341     ca->bad[jj][j][dspn1]=0;
342     if(calibdata2->DSPbad_par[i][ii]==0)
343     ca->bad[jj][j][dspn2]=1;
344     else if(calibdata2->DSPbad_par[i][ii]==1)
345     ca->bad[jj][j][dspn2]=0;
346     };
347     };
348    
349     tr1->Delete();
350     tr2->Delete();
351     };
352     /**
353     * Method to fill the tracker calibration-parameter struct from on-line calibrations
354     */
355     void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
356    
357     cTrkCalib *ca = &pedsigbad_;
358    
359     TTree *tr1 = (TTree*)f0->Get("CalibTrk1");
360     TTree *tr2 = (TTree*)f0->Get("CalibTrk2");
361    
362     CalibTrk1Event *calibdata1 = 0;
363     CalibTrk2Event *calibdata2 = 0;
364     tr1->SetBranchAddress("CalibTrk1",&calibdata1);
365     tr2->SetBranchAddress("CalibTrk2",&calibdata2);
366     tr1->GetEntry(ev_reg1);
367     tr2->GetEntry(ev_reg2);
368     Int_t dspn1(0),dspn2(0);
369    
370 pam-fi 1.4 // --- TEST TEST TEST TEST --- //
371     TrkParams::ValidateTrkCalib(calibdata1);
372     TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2);
373    
374 pam-fi 1.1 for(Int_t i=0;i<6;i++){
375     dspn1=calibdata1->DSPnumber[i]-1;
376     dspn2=calibdata2->DSPnumber[i]-1;
377     /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */
378     for(Int_t ii=0;ii<3072;ii++){
379     Int_t j=(ii/128);
380     Int_t jj=ii-j*128;
381     ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]);
382     ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]);
383     ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]);
384     ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]);
385     };
386     };
387    
388     tr1->Delete();
389     tr2->Delete();
390     };
391     /**
392     * Method to fill the tracker calibration-parameter struct from default calibration
393     */
394     void TrkParams::FillTCalibFrom(TString path){
395    
396     path_.FillWith(path);
397     fillpedsigfromdefault_();
398     if(path_.error) throw -216;
399    
400     };
401     /**
402     * Method to fill the tracker VA1-mask struct from calibration
403     */
404     void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){
405    
406     cTrkMask *ma = &mask_;
407    
408     TrkCalib *calib = new TrkCalib();
409    
410     for(Int_t i=0; i<2; i++){
411     TTree *tr=0;
412     if(i==0){
413     //-------------------------
414     //read calibration packet 1
415     //-------------------------
416     tr = (TTree*)f0->Get("CalibTrk1");
417     tr->SetBranchAddress("CalibTrk1",calib->GetPointerTo());
418     tr->GetEntry(ev_reg1);
419     }
420     if(i==1){
421     //-------------------------
422     //read calibration packet 2
423     //-------------------------
424     tr = (TTree*)f0->Get("CalibTrk2");
425     tr->SetBranchAddress("CalibTrk2",calib->GetPointerTo());
426     tr->GetEntry(ev_reg2);
427     }
428     for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){
429     for(Int_t ivk=0; ivk<NVK; ivk++){
430     Int_t view = calib->GetView(ipkt);
431     Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1);
432     Float_t sigmin = 0.;
433     if(view%2)sigmin = 6.5;
434     else sigmin = 2.5;
435     Int_t mask = 1;
436     if( sigm<sigmin )mask = 0;
437    
438     ma->mask_vk_run[ivk][view-1] = mask;
439    
440     // if(mask==0)cout<< " VIEW "<<view<<" VK "<<ivk+1<<" -- <SIG> "<<sigm<<" ---> MASKED!"<<endl;
441     }
442     }
443     if(tr)tr->Delete();
444     }
445    
446     if(calib)calib->Delete();
447    
448     };
449    
450 pam-fi 1.3 // Bool_t TrkParams::CalibIsLoaded(UInt_t time){
451    
452     // if( !calibload ) return false;
453    
454     // };
455    
456    
457 pam-fi 1.1 /**
458     * Static method to load calibration.
459     * Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the
460     * first time the method is called (but it does not work becouse I didn't set any
461     * default calibration for the moment) or after the method TrkParams::SetCalib(***) is called.
462     */
463     Bool_t TrkParams::LoadCalib( ){
464    
465     if( TrkParams::CalibIsLoaded() )return false;
466    
467     // =============================================================
468     // retrieve calibration file needed to reduce data
469     // =============================================================
470     // if run OBT is > last calibration "expiration date"
471     // - search for new calibration packet
472     // - load calibration parameters (full + truncated)
473 pam-fi 1.6 if(TrkParams::VerboseMode()){
474     cout << "--------------------------------------"<<endl;
475     cout << "Retrieve calibration (PED-SIG-BAD) ..."<<endl;
476     cout << " Full pedestals for cluster finding:";
477     cout << " >> loading from LEVEL0 file: "<< calibpathf << endl;
478     }
479 pam-fi 1.1 FileStat_t t;
480     if( gSystem->GetPathInfo(calibpathf.Data(),t) )return false;
481    
482 pam-fi 1.6 bool alreadyopened = false;
483     TFile *f0_c=0;
484     f0_c = (TFile*)gROOT->GetListOfFiles()->FindObject(calibpathf);
485     if(f0_c)alreadyopened=true;
486     else f0_c = new TFile(calibpathf);
487 pam-fi 1.1 if ( !f0_c ) return false;
488 pam-fi 1.6
489     if(TrkParams::VerboseMode()){
490     cout << " calibration entry "<< calib.EV_ROOT_CALIBTRK1 << " " << calib.EV_ROOT_CALIBTRK2;
491     cout << " (from time "<< calib.FROM_TIME <<" to time "<< calib.TO_TIME <<")"<<endl;
492     cout << " - full+truncated parameters "<<endl;
493     }
494 pam-fi 1.1 TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
495 pam-fi 1.6 if(TrkParams::VerboseMode())cout << " - VK-mask "<<endl;
496 pam-fi 1.1 TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
497    
498     // =============================================================
499     // retrieve calibration file needed to uncompress data
500     // =============================================================
501     // if the run was compressed using default calib
502     // load truncated pedestals from default
503     // otherwise reload them from on-line calibration
504 pam-fi 1.6 if(TrkParams::VerboseMode())cout << " Truncated pedestals for uncompression:";
505 pam-fi 1.1 if( calib104 ){
506    
507 pam-fi 1.6 if(TrkParams::VerboseMode())cout << " >> loading default calibration: "<< calibpatht << endl;
508 pam-fi 1.1 TrkParams::FillTCalibFrom(calibpatht);
509    
510     }else{
511    
512 pam-fi 1.6 // if ( !f0_c ) return false;
513     if(TrkParams::VerboseMode())cout << ">> already loaded " << endl;
514     // TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2);
515 pam-fi 1.1 };
516 pam-fi 1.6 if(!alreadyopened)f0_c->Close();
517     if(TrkParams::VerboseMode())cout << "--------------------------------------"<<endl;
518 pam-fi 1.1
519     calibload = kTRUE;
520     return true;
521     };
522    
523     Int_t TrkParams::GetIndex( UInt_t type ){
524     Int_t index = -1;
525     for (Int_t i=0; i< NTYPES; i++)if( type == trkparamtype[i] )index=i;
526     return index;
527     };
528    
529     /**
530     * Set tracker parameters proper for a run querying the DB.
531     * @param glrun Input run info
532     * @param dbc Database
533     * @param type Parameter type
534     * @return FALSE if parameter set fails.
535     * If glrun==NULL the last parameter entry from GL_PARAM table is set.
536     * If dbc==NULL, try to open a connection taking DB-connection
537     * parameters from PAMELA environment variables.
538     */
539     Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type){
540    
541    
542 pam-fi 1.6 UInt_t index = TrkParams::GetIndex( type );
543     if(index < 0)return false;
544    
545     if( !TrkParams::IsLoaded(type) ||
546     glrun->RUNHEADER_TIME < gl[index].FROM_TIME ||
547     glrun->RUNHEADER_TIME > gl[index].TO_TIME ||
548     false ){
549 pam-fi 1.1
550 pam-fi 1.6 if( !dbc || (dbc && !dbc->IsConnected()) ){
551 pam-fi 1.1
552 pam-fi 1.6 if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
553     TString host = "mysql://localhost/pamelaprod";
554     TString user = "anonymous";
555     TString psw = "";
556     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
557     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
558     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
559     if ( !pamdbhost ) pamdbhost = "";
560     if ( !pamdbuser ) pamdbuser = "";
561     if ( !pamdbpsw ) pamdbpsw = "";
562     if ( strcmp(pamdbhost,"") ) host = pamdbhost;
563     if ( strcmp(pamdbuser,"") ) user = pamdbuser;
564     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
565     if(TrkParams::VerboseMode()){
566     cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
567     cout<<"Connecting to DB"<<endl;
568     cout<<"HOST "<<host<<endl;
569     cout<<"USER "<<user<<endl;
570     cout<<"PSW "<<psw<<endl;
571     }
572     dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
573     if( !dbc )return false;
574     if( !dbc->IsConnected() )return false;
575     if(TrkParams::VerboseMode()){
576     cout << " ...done"<<endl;
577     cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
578     }
579     }
580 pam-fi 1.1
581    
582 pam-fi 1.6 UInt_t runheadtime = numeric_limits<UInt_t>::max();
583     if(glrun)runheadtime = glrun->RUNHEADER_TIME;
584     else cout <<"Missing run info -- taking last entry "<<endl;
585 pam-fi 1.1
586 pam-fi 1.6 GL_PARAM q4;
587     if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false;
588 pam-fi 1.1
589 pam-fi 1.6 gl[index] = q4;
590     glpath[index] = q4.PATH+q4.NAME;
591     glload[index] = false;
592     if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl;
593     return true;
594 pam-fi 1.1
595 pam-fi 1.6 }
596     return false;
597 pam-fi 1.1
598     };
599     /**
600 pam-fi 1.2 * Set tracker parameters proper for the run, from input.
601 pam-fi 1.1 * @param path Path to parameters directory
602     * @param type Parameter type
603     * @return FALSE if parameter set fails.
604     */
605     Bool_t TrkParams::Set( TString path , UInt_t type){
606    
607     UInt_t index = TrkParams::GetIndex( type );
608     if(index < 0)return false;
609    
610     gl[index].TYPE= type;
611     glpath[index] = path;
612 pam-fi 1.6 if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl;
613 pam-fi 1.1 glload[index] = false;
614    
615     // return TrkParams::Load(type);
616     return true;
617    
618     };
619    
620     /**
621     * Set and load tracker parameters.
622     * @param type Parameter type
623     * If no path as been yet specified, it set a default path.
624     * @return FALSE if parameter set fails.
625     */
626     Bool_t TrkParams::Set(UInt_t type){
627    
628     UInt_t index = TrkParams::GetIndex( type );
629     if(index < 0)return false;
630    
631     gl[index].TYPE= type;
632     glload[index] = false;
633    
634     // -----------------------------------------
635     // check if enviroment variables are defined
636     // -----------------------------------------
637     glpath[index] = gSystem->Getenv("PAM_CALIB");
638    
639     if( !glpath[index].IsNull() ){
640    
641     switch(type){
642     case 1:
643     glpath[index].Append("/trk-param/field_param-0/");
644     break;
645     case 2:
646     glpath[index].Append("/trk-param/mip_param-0/");
647     break;
648     case 3:
649     glpath[index].Append("/trk-param/charge_param-1/");
650     break;
651     case 4:
652     glpath[index].Append("/trk-param/eta_param-0/");
653     break;
654     case 5:
655     glpath[index].Append("/trk-param/align_param-0/");
656     break;
657     case 6:
658     glpath[index].Append("/trk-param/mask_param-1/");
659     break;
660     case 7:
661     glpath[index].Append("/trk-param/default_calib/");
662     break;
663     }
664    
665     }else{
666     cout << " TrkParams::Set( UInt_t type) ==> No PAMELA environment variables defined "<<endl;
667     return false;
668    
669     }
670    
671 pam-fi 1.6 if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" (from env var PAM_CALIB) >>"<<endl;
672 pam-fi 1.1 // return TrkParams::Load(type);
673     return true;
674    
675     };
676     /**
677     * Set tracker parameters.
678     * If no path as been yet specified, try to read from DB
679     * otherwise it set a default path.
680     * @return FALSE if parameter set fails.
681     */
682     Bool_t TrkParams::Set( ){
683    
684     Bool_t connected = false;
685    
686 pam-fi 1.6 // cout <<" Missing DB connection -- check PAMELA environment variables "<<endl;
687 pam-fi 1.1 TString host = "mysql://localhost/pamelaprod";
688     TString user = "anonymous";
689     TString psw = "";
690     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
691     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
692     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
693     if ( !pamdbhost ) pamdbhost = "";
694     if ( !pamdbuser ) pamdbuser = "";
695     if ( !pamdbpsw ) pamdbpsw = "";
696     if ( strcmp(pamdbhost,"") ) host = pamdbhost;
697     if ( strcmp(pamdbuser,"") ) user = pamdbuser;
698     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
699 pam-fi 1.6 if(TrkParams::VerboseMode()){
700     cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
701     cout<<"Connecting to DB"<<endl;
702     cout<<"HOST "<<host<<endl;
703     cout<<"USER "<<user<<endl;
704     cout<<"PSW "<<psw<<endl;
705     }
706 pam-fi 1.1 TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
707     if( dbc || dbc->IsConnected() )connected = true;
708 pam-fi 1.6 else cout << " >> DB connection FAILED!!!"<<endl;
709     if(TrkParams::VerboseMode())cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
710 pam-fi 1.1
711     if(connected){
712     if ( !TrkParams::Set(0,dbc) )return false;
713     dbc->Close();
714     }else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false;
715 pam-fi 1.3
716     return true;
717 pam-fi 1.1 }
718    
719     /**
720     * Load tracker parameter, if not already loaded.
721     * @param type Parameter type
722     * ( Any call to TrkParams::Set(...) forces reloading )
723     */
724     Bool_t TrkParams::Load(UInt_t type){
725    
726     Int_t index = TrkParams::GetIndex( type );
727     if( index<0 )return false;
728     if( glload[index] )return true;
729    
730     if( glpath[index].IsNull() )TrkParams::Set(type);
731    
732     switch( type ){
733     //------------------------------------------
734     case 1:
735 pam-fi 1.6 if(TrkParams::VerboseMode())cout <<type<<" -- Loading magnetic field "<<glpath[index]<<endl;
736 pam-fi 1.1 strcpy(path_.path,glpath[index].Data());
737     path_.pathlen = glpath[index].Length();
738     path_.error = 0;
739     readb_();
740     if(path_.error) return false;
741     glload[index]=true;
742     break;
743     //------------------------------------------
744     case 2:
745 pam-fi 1.6 if(TrkParams::VerboseMode())cout <<type<<" -- Loading ADC-to-MIP conversion parameters "<<glpath[index]<<endl;
746 pam-fi 1.1 strcpy(path_.path,glpath[index].Data());
747     path_.pathlen = glpath[index].Length();
748     path_.error = 0;
749     readmipparam_();
750     if(path_.error) return false;
751     glload[index]=true;
752     break;
753     //------------------------------------------
754     case 3:
755 pam-fi 1.6 if(TrkParams::VerboseMode())cout <<type<<" -- Loading charge-correlation parameters "<<glpath[index]<<endl;
756 pam-fi 1.1 strcpy(path_.path,glpath[index].Data());
757     path_.pathlen = glpath[index].Length();
758     path_.error = 0;
759     readchargeparam_();
760     if(path_.error) return false;
761     glload[index]=true;
762     break;
763     //------------------------------------------
764     case 4:
765 pam-fi 1.6 if(TrkParams::VerboseMode())cout <<type<<" -- Loading p.f.a. parameters "<<glpath[index]<<endl;
766 pam-fi 1.1 strcpy(path_.path,glpath[index].Data());
767     path_.pathlen = glpath[index].Length();
768     path_.error = 0;
769     readetaparam_();
770     if(path_.error) return false;
771     glload[index]=true;
772     break;
773     //------------------------------------------
774     case 5:
775 pam-fi 1.6 if(TrkParams::VerboseMode())cout <<type<<" -- Loading alignment parameters "<<glpath[index]<<endl;
776 pam-fi 1.1 strcpy(path_.path,glpath[index].Data());
777     path_.pathlen = glpath[index].Length();
778     path_.error = 0;
779     readalignparam_();
780     if(path_.error) return false;
781     glload[index]=true;
782     break;
783     //------------------------------------------
784     case 6:
785 pam-fi 1.6 if(TrkParams::VerboseMode())cout <<type<<" -- Loading VK-mask parameters "<<glpath[index]<<endl;
786 pam-fi 1.1 strcpy(path_.path,glpath[index].Data());
787     path_.pathlen = glpath[index].Length();
788     path_.error = 0;
789     readvkmask_();
790     if(path_.error) return false;
791     glload[index]=true;
792     break;
793     //------------------------------------------
794     case 7:
795 pam-fi 1.6 if(TrkParams::VerboseMode())cout <<type<<" -- Loading default calibration "<<glpath[index]<<endl;
796 pam-fi 1.1 strcpy(path_.path,glpath[index].Data());
797     path_.pathlen = glpath[index].Length();
798     path_.error = 0;
799     // fillpedsigfromdefault_();
800 pam-fi 1.6 if(TrkParams::VerboseMode())cout << ">> not implemented <<"<<endl;
801 pam-fi 1.1 if(path_.error) return false;
802     glload[index]=true;
803     break;
804     default:
805 pam-fi 1.6 if(TrkParams::VerboseMode())cout << " Bool_t TrkParams::Load(UInt_t type) -- type "<< type << "not yet implemented"<<endl;
806 pam-fi 1.1 return false;
807     };
808    
809     return true;
810     }
811    
812     Bool_t TrkParams::Load( ){
813     for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )if( !TrkParams::Load(trkparamtype[i]) )return false;
814     return true;
815     };
816     Bool_t TrkParams::IsLoaded( ){
817     for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )return false;
818     return true;
819     };
820    
821 pam-fi 1.8
822     /**
823     * Get BY (kGauss)
824     * @param v (x,y,z) coordinates in cm
825     */
826     float TrkParams::GetBX(float* v){
827     TrkParams::Load(1);
828     if( !TrkParams::IsLoaded(1) )return 0.;
829     float b[3];
830     gufld_(v,b);
831     return b[0]/10.;
832     }
833     /**
834     * Get BY (kGauss)
835     * @param v (x,y,z) coordinates in cm
836     */
837     float TrkParams::GetBY(float* v){
838     TrkParams::Load(1);
839     if( !TrkParams::IsLoaded(1) )return 0.;
840     float b[3];
841     gufld_(v,b);
842     return b[1]/10.;
843     }
844     /**
845     * Get BY (kGauss)
846     * @param v (x,y,z) coordinates in cm
847     */
848     float TrkParams::GetBZ(float* v){
849     TrkParams::Load(1);
850     if( !TrkParams::IsLoaded(1) )return 0.;
851     float b[3];
852     gufld_(v,b);
853     return b[2]/10.;
854     }
855    
856     /**
857     * \brief Set tracking mode (0=standard. 1=???)
858     */
859     void TrkParams::SetTrackingMode(int trackmode) {
860     init__mini_trackmode = trackmode;
861     SetTrackingMode();
862     };
863     /**
864     * \brief Set fit-precision factor (typical value fact=100.)
865     */
866     void TrkParams::SetPrecisionFactor(double fact){
867     init__mini_fact = fact;
868     SetPrecisionFactor();
869     };
870     /**
871     * \brief Set minimum number of step in track fitting
872     */
873     void TrkParams::SetStepMin(int istepmin){
874     init__mini_istepmin = istepmin;
875     SetStepMin();
876     };
877    
878     /**
879     * \brief Set p.f.a.
880     *
881     * Implemented algorythms:
882     * 0 ETA (default)
883     * 1 ---
884     * 2 ETA2
885     * 3 ETA3
886     * 4 ETA4
887     * 10 COG
888     * 11 COG1
889     * 12 COG2
890     * 13 COG3
891     * 14 COG4
892     */
893     void TrkParams::SetPFA(int pfaid){
894     init__pfa = pfaid;
895     SetStepMin();
896     };
897    
898    
899    
900 pam-fi 1.1 ClassImp(TrkParams);

  ViewVC Help
Powered by ViewVC 1.1.23