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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (show annotations) (download)
Tue Jan 15 14:29:46 2008 UTC (17 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.19: +8 -0 lines
tracking optimization

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

  ViewVC Help
Powered by ViewVC 1.1.23