/[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.19 - (show annotations) (download)
Tue Nov 27 11:43:50 2007 UTC (17 years ago) by pam-fi
Branch: MAIN
Changes since 1.18: +19 -9 lines
implemented m.field deformation, for alignment purpouse

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

  ViewVC Help
Powered by ViewVC 1.1.23