/[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.11 - (hide annotations) (download)
Fri Aug 17 14:36:05 2007 UTC (17 years, 4 months ago) by pam-fi
Branch: MAIN
Changes since 1.10: +2 -1 lines
mplemented Landi correction

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

  ViewVC Help
Powered by ViewVC 1.1.23