5 |
|
|
6 |
#include <TrkParams.h> |
#include <TrkParams.h> |
7 |
#include <iostream> |
#include <iostream> |
8 |
|
#include <iomanip> |
9 |
using namespace std; |
using namespace std; |
10 |
|
|
11 |
|
|
17 |
TString TrkParams::calibpathf = ""; |
TString TrkParams::calibpathf = ""; |
18 |
Bool_t TrkParams::calib104 = 0; |
Bool_t TrkParams::calib104 = 0; |
19 |
Bool_t TrkParams::calibload = false; |
Bool_t TrkParams::calibload = false; |
20 |
|
// ------------------------- |
21 |
|
// PARAMETERS loaded from DB |
22 |
|
// ------------------------- |
23 |
UInt_t TrkParams::trkparamtype[] = {1,2,3,4,5,6,7}; |
UInt_t TrkParams::trkparamtype[] = {1,2,3,4,5,6,7}; |
24 |
GL_PARAM TrkParams::gl[] = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()}; |
GL_PARAM TrkParams::gl[] = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()}; |
25 |
TString TrkParams::glpath[] = {"","","","","","",""}; |
TString TrkParams::glpath[] = {"","","","","","",""}; |
26 |
Bool_t TrkParams::glload[] = {false,false,false,false,false,false,false}; |
Bool_t TrkParams::glload[] = {false,false,false,false,false,false,false}; |
27 |
cDbg TrkParams::dbg_mode = {0,0,0}; |
// ---------------- |
28 |
|
// other parameters |
29 |
|
// ---------------- |
30 |
|
cDbg TrkParams::init__dbg_mode = {0,0,0}; |
31 |
|
//int TrkParams::init__pfa = 14;//COG4 |
32 |
|
int TrkParams::init__pfa = 5;//ETAL |
33 |
|
int TrkParams::init__mini_trackmode = 0; |
34 |
|
int TrkParams::init__mini_istepmin = 5; //3; |
35 |
|
double TrkParams::init__mini_fact = 1.e4; //100.; |
36 |
|
float TrkParams::init__pfa_e234ax[] = {0.,10.,10.,15.,15.,90.}; |
37 |
|
float TrkParams::init__pfa_e234ay[] = {0.,20.,90.,90.,90.,90.}; |
38 |
|
double TrkParams::init__deltab_0 = 0.; |
39 |
|
double TrkParams::init__deltab_1 = 0.; |
40 |
|
|
41 |
TrkParams::TrkParams(){ |
TrkParams::TrkParams(){ |
42 |
|
|
43 |
// cout<<"TrkParams::TrkParams()"<<endl; |
cout<<"TrkParams::TrkParams()"<<endl; |
44 |
|
|
45 |
} |
} |
46 |
float aint(float f){ |
float aint(float f){ |
56 |
ret1=(float)ret; |
ret1=(float)ret; |
57 |
return ret1; |
return ret1; |
58 |
} |
} |
59 |
|
|
60 |
|
/** |
61 |
|
* Static method to open a DB connection. |
62 |
|
* HOST, USER and PASSWORD are taken from enviroment variables $PAM_DBHOST, |
63 |
|
* $PAM_DBUSER and $PAM_DBPSW |
64 |
|
* NB! The method create a new connection, which has to be closed by the user. |
65 |
|
*/ |
66 |
|
TSQLServer* TrkParams::SetDBConnection(){ |
67 |
|
|
68 |
|
TString host = "mysql://localhost/pamelaprod"; |
69 |
|
TString user = "anonymous"; |
70 |
|
TString psw = ""; |
71 |
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
72 |
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
73 |
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
74 |
|
if ( !pamdbhost ) pamdbhost = ""; |
75 |
|
if ( !pamdbuser ) pamdbuser = ""; |
76 |
|
if ( !pamdbpsw ) pamdbpsw = ""; |
77 |
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
78 |
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
79 |
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
80 |
|
if(TrkParams::VerboseMode()){ |
81 |
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
82 |
|
cout<<"Connecting to DB"<<endl; |
83 |
|
cout<<"HOST "<<host<<endl; |
84 |
|
cout<<"USER "<<user<<endl; |
85 |
|
cout<<"PSW "<<psw<<endl; |
86 |
|
} |
87 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
88 |
|
if( !dbc )return NULL; |
89 |
|
if( !dbc->IsConnected() )return NULL; |
90 |
|
stringstream myquery; // EMILIANO |
91 |
|
myquery.str(""); // EMILIANO |
92 |
|
myquery << "SET time_zone='+0:00'"; // EMILIANO |
93 |
|
dbc->Query(myquery.str().c_str()); // EMILIANO |
94 |
|
if(TrkParams::VerboseMode()){ |
95 |
|
cout << " ...done"<<endl; |
96 |
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
97 |
|
} |
98 |
|
|
99 |
|
return dbc; |
100 |
|
} |
101 |
/** |
/** |
102 |
* Static method to set the calibration to be loaded. |
* \brief Static method to set the calibration to be loaded. |
103 |
|
|
104 |
* It retrieves the calibration associated to a given run, from |
* It retrieves the calibration associated to a given run, from |
105 |
* a given DB. It fills the F77 common. |
* a given DB. It fills the F77 common. |
117 |
glrun->RUNHEADER_TIME > calib.TO_TIME || |
glrun->RUNHEADER_TIME > calib.TO_TIME || |
118 |
false ){ |
false ){ |
119 |
|
|
120 |
|
|
121 |
GL_TRK_CALIB q2; |
GL_TRK_CALIB q2; |
122 |
GL_ROOT q3; |
GL_ROOT q3; |
123 |
GL_PARAM q4; |
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()){ |
if(TrkParams::VerboseMode()){ |
137 |
cout << "--------------------------------------"<<endl; |
cout << "--------------------------------------"<<endl; |
158 |
calibpatht = q4.PATH + q4.NAME; |
calibpatht = q4.PATH + q4.NAME; |
159 |
} |
} |
160 |
|
|
161 |
|
if(LOCAL_CONNECTION){ |
162 |
|
dbc->Close(); |
163 |
|
delete dbc; |
164 |
|
} |
165 |
|
|
166 |
// return TrkParams::LoadCalib(); |
// return TrkParams::LoadCalib(); |
167 |
return true; |
return true; |
176 |
*/ |
*/ |
177 |
UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){ |
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}; |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
181 |
// UInt_t timeaftercalib=120000; //2000; |
// UInt_t timeaftercalib=120000; //2000; |
182 |
TString classname = caltrk->GetName(); |
TString classname = caltrk->GetName(); |
185 |
// ---------- |
// ---------- |
186 |
if(TrkParams::VerboseMode())cout << " DSP: "; |
if(TrkParams::VerboseMode())cout << " DSP: "; |
187 |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
188 |
cout <<" "<<caltrk->DSPnumber[ipkt]; |
if(TrkParams::VerboseMode())cout <<" "<<caltrk->DSPnumber[ipkt]; |
189 |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
190 |
if( caltrk->crc_hcal[ipkt] ){ |
if( caltrk->crc_hcal[ipkt] ){ |
191 |
if(TrkParams::WarningMode())cout<<"(CRC Header)"; |
if(TrkParams::WarningMode())cout<<"(CRC Header)"; |
192 |
// if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl; |
// if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl; |
193 |
// return 0; // :-( |
// return 0; // :-( |
194 |
|
validate = 0; |
195 |
} |
} |
196 |
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
197 |
if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")"; |
if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")"; |
198 |
// if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl; |
// if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl; |
199 |
// return 0; // :-( |
// return 0; // :-( |
200 |
|
validate = 0; |
201 |
} |
} |
202 |
} |
} |
203 |
} |
} |
247 |
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
248 |
}; |
}; |
249 |
} |
} |
250 |
if( npkts==6 )return 1; // :-) |
if( npkts==6 ){}//return 1; // :-) |
251 |
else { |
else { |
252 |
if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-( ( "<<npkts<<" instead of 6 ) --> "<<endl; |
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; |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
256 |
|
|
300 |
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
301 |
// return 0; // :-( |
// return 0; // :-( |
302 |
// } |
// } |
303 |
return 1; // :-) |
|
304 |
|
// return 1; // :-) |
305 |
|
|
306 |
|
// cout << validate << endl; |
307 |
|
return validate; |
308 |
|
|
309 |
} |
} |
310 |
/** |
/** |
313 |
void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
314 |
|
|
315 |
cTrkCalib *ca = &pedsigbad_; |
cTrkCalib *ca = &pedsigbad_; |
316 |
|
ca->Reset(); |
317 |
|
|
318 |
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
319 |
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
327 |
Int_t dspn1(0),dspn2(0); |
Int_t dspn1(0),dspn2(0); |
328 |
|
|
329 |
// --- TEST TEST TEST TEST --- // |
// --- TEST TEST TEST TEST --- // |
330 |
TrkParams::ValidateTrkCalib(calibdata1); |
// TrkParams::ValidateTrkCalib(calibdata1); |
331 |
TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
// TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
332 |
|
|
333 |
|
UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); |
334 |
|
UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
335 |
|
if( !test1 || !test2 ){ |
336 |
|
if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl; |
337 |
|
TrkParams::calib.VALIDATION = 0; |
338 |
|
} |
339 |
|
if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl; |
340 |
|
|
341 |
for(Int_t i=0;i<6;i++){ |
for(Int_t i=0;i<6;i++){ |
342 |
dspn1=calibdata1->DSPnumber[i]-1; |
dspn1=calibdata1->DSPnumber[i]-1; |
343 |
dspn2=calibdata2->DSPnumber[i]-1; |
dspn2=calibdata2->DSPnumber[i]-1; |
344 |
/* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */ |
// cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; |
345 |
for(Int_t ii=0;ii<3072;ii++){ |
for(Int_t ii=0;ii<3072;ii++){ |
346 |
Int_t j=(ii/128); |
Int_t j=(ii/128); |
347 |
Int_t jj=ii-j*128; |
Int_t jj=ii-j*128; |
348 |
ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii]; |
if(dspn1>=0 && dspn1<12){ |
349 |
ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii]; |
ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii]; |
350 |
ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]); |
ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]); |
351 |
ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]); |
ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii]; |
352 |
ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii]; |
ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]); |
353 |
ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii]; |
if(calibdata1->DSPbad_par[i][ii]==0) |
354 |
ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]); |
ca->bad[jj][j][dspn1]=1; |
355 |
ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]); |
else if(calibdata1->DSPbad_par[i][ii]==1) |
356 |
// cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl; |
ca->bad[jj][j][dspn1]=0; |
357 |
// cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl; |
// cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl; |
358 |
// cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
// cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl; |
359 |
// cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
} |
360 |
|
|
361 |
// |
if(dspn2>=0 && dspn2<12){ |
362 |
// invert the bad |
ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii]; |
363 |
// |
ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]); |
364 |
if(calibdata1->DSPbad_par[i][ii]==0) |
ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii]; |
365 |
ca->bad[jj][j][dspn1]=1; |
ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]); |
366 |
else if(calibdata1->DSPbad_par[i][ii]==1) |
if(calibdata2->DSPbad_par[i][ii]==0) |
367 |
ca->bad[jj][j][dspn1]=0; |
ca->bad[jj][j][dspn2]=1; |
368 |
if(calibdata2->DSPbad_par[i][ii]==0) |
else if(calibdata2->DSPbad_par[i][ii]==1) |
369 |
ca->bad[jj][j][dspn2]=1; |
ca->bad[jj][j][dspn2]=0; |
370 |
else if(calibdata2->DSPbad_par[i][ii]==1) |
// cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
371 |
ca->bad[jj][j][dspn2]=0; |
// cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
372 |
|
} |
373 |
}; |
}; |
374 |
}; |
}; |
375 |
|
|
382 |
void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
383 |
|
|
384 |
cTrkCalib *ca = &pedsigbad_; |
cTrkCalib *ca = &pedsigbad_; |
385 |
|
// ca->Reset(); |
386 |
|
|
387 |
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
388 |
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
396 |
Int_t dspn1(0),dspn2(0); |
Int_t dspn1(0),dspn2(0); |
397 |
|
|
398 |
// --- TEST TEST TEST TEST --- // |
// --- TEST TEST TEST TEST --- // |
399 |
TrkParams::ValidateTrkCalib(calibdata1); |
// TrkParams::ValidateTrkCalib(calibdata1); |
400 |
TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
// TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
401 |
|
UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); |
402 |
|
UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
403 |
|
if( !test1 || !test2 ){ |
404 |
|
if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl; |
405 |
|
TrkParams::calib.VALIDATION = 0; |
406 |
|
} |
407 |
|
if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl; |
408 |
|
|
409 |
for(Int_t i=0;i<6;i++){ |
for(Int_t i=0;i<6;i++){ |
410 |
dspn1=calibdata1->DSPnumber[i]-1; |
dspn1=calibdata1->DSPnumber[i]-1; |
413 |
for(Int_t ii=0;ii<3072;ii++){ |
for(Int_t ii=0;ii<3072;ii++){ |
414 |
Int_t j=(ii/128); |
Int_t j=(ii/128); |
415 |
Int_t jj=ii-j*128; |
Int_t jj=ii-j*128; |
416 |
ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii]; |
if(dspn1>=0 && dspn1<12){ |
417 |
ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii]; |
ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii]; |
418 |
ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii]; |
ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii]; |
419 |
ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii]; |
if(calibdata1->DSPbad_par[i][ii]==0) |
420 |
// cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl; |
ca->bad[jj][j][dspn1]=1; |
421 |
// cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl; |
else if(calibdata1->DSPbad_par[i][ii]==1) |
422 |
// cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
ca->bad[jj][j][dspn1]=0; |
423 |
// cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
// cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl; |
424 |
|
// cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl; |
425 |
// |
} |
426 |
// invert the bad |
if(dspn2>=0 && dspn2<12){ |
427 |
// |
ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii]; |
428 |
if(calibdata1->DSPbad_par[i][ii]==0) |
ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii]; |
429 |
ca->bad[jj][j][dspn1]=1; |
if(calibdata2->DSPbad_par[i][ii]==0) |
430 |
else if(calibdata1->DSPbad_par[i][ii]==1) |
ca->bad[jj][j][dspn2]=1; |
431 |
ca->bad[jj][j][dspn1]=0; |
else if(calibdata2->DSPbad_par[i][ii]==1) |
432 |
if(calibdata2->DSPbad_par[i][ii]==0) |
ca->bad[jj][j][dspn2]=0; |
433 |
ca->bad[jj][j][dspn2]=1; |
// cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
434 |
else if(calibdata2->DSPbad_par[i][ii]==1) |
// cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
435 |
ca->bad[jj][j][dspn2]=0; |
} |
436 |
}; |
}; |
437 |
}; |
}; |
438 |
|
|
445 |
void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
446 |
|
|
447 |
cTrkCalib *ca = &pedsigbad_; |
cTrkCalib *ca = &pedsigbad_; |
448 |
|
// ca->Reset(); |
449 |
|
|
450 |
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
451 |
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
459 |
Int_t dspn1(0),dspn2(0); |
Int_t dspn1(0),dspn2(0); |
460 |
|
|
461 |
// --- TEST TEST TEST TEST --- // |
// --- TEST TEST TEST TEST --- // |
462 |
TrkParams::ValidateTrkCalib(calibdata1); |
// TrkParams::ValidateTrkCalib(calibdata1); |
463 |
TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
// TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
464 |
|
UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); |
465 |
|
UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
466 |
|
if( !test1 || !test2 ){ |
467 |
|
if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl; |
468 |
|
TrkParams::calib.VALIDATION = 0; |
469 |
|
} |
470 |
|
if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl; |
471 |
|
|
472 |
for(Int_t i=0;i<6;i++){ |
for(Int_t i=0;i<6;i++){ |
473 |
dspn1=calibdata1->DSPnumber[i]-1; |
dspn1=calibdata1->DSPnumber[i]-1; |
476 |
for(Int_t ii=0;ii<3072;ii++){ |
for(Int_t ii=0;ii<3072;ii++){ |
477 |
Int_t j=(ii/128); |
Int_t j=(ii/128); |
478 |
Int_t jj=ii-j*128; |
Int_t jj=ii-j*128; |
479 |
ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]); |
if(dspn1>=0 && dspn1<12){ |
480 |
ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]); |
ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]); |
481 |
ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]); |
ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]); |
482 |
ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]); |
} |
483 |
|
if(dspn2>=0 && dspn2<12){ |
484 |
|
ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]); |
485 |
|
ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]); |
486 |
|
} |
487 |
}; |
}; |
488 |
}; |
}; |
489 |
|
|
506 |
void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
507 |
|
|
508 |
cTrkMask *ma = &mask_; |
cTrkMask *ma = &mask_; |
509 |
|
ma->Reset(); |
510 |
|
|
511 |
TrkCalib *calib = new TrkCalib(); |
TrkCalib *calib = new TrkCalib(); |
512 |
|
|
529 |
tr->GetEntry(ev_reg2); |
tr->GetEntry(ev_reg2); |
530 |
} |
} |
531 |
for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){ |
for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){ |
532 |
for(Int_t ivk=0; ivk<NVK; ivk++){ |
Int_t view = calib->GetView(ipkt); |
533 |
Int_t view = calib->GetView(ipkt); |
if( (view-1)>= 0 && (view-1)<12 ){ |
534 |
Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1); |
for(Int_t ivk=0; ivk<NVK; ivk++){ |
535 |
Float_t sigmin = 0.; |
Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1); |
536 |
if(view%2)sigmin = 6.5; |
Float_t sigmin = 0.; |
537 |
else sigmin = 2.5; |
if(view%2)sigmin = 6.5; |
538 |
Int_t mask = 1; |
else sigmin = 2.5; |
539 |
if( sigm<sigmin )mask = 0; |
Int_t mask = 1; |
540 |
|
if( sigm<sigmin )mask = 0; |
541 |
ma->mask_vk_run[ivk][view-1] = mask; |
ma->mask_vk_run[ivk][view-1] = mask; |
542 |
|
} |
543 |
// if(mask==0)cout<< " VIEW "<<view<<" VK "<<ivk+1<<" -- <SIG> "<<sigm<<" ---> MASKED!"<<endl; |
} |
|
} |
|
544 |
} |
} |
545 |
if(tr)tr->Delete(); |
if(tr)tr->Delete(); |
546 |
} |
} |
547 |
|
|
548 |
|
if(TrkParams::VerboseMode()){ |
549 |
|
for(Int_t iv=0; iv<NVIEW; iv++){ |
550 |
|
cout<<"view "<<setw(3)<<iv<<": "; |
551 |
|
for(Int_t ivk=0; ivk<NVK; ivk++)cout<<ma->mask_vk_run[ivk][iv]; |
552 |
|
cout << endl; |
553 |
|
} |
554 |
|
} |
555 |
|
|
556 |
if(calib)calib->Delete(); |
if(calib)calib->Delete(); |
557 |
|
|
558 |
}; |
}; |
565 |
|
|
566 |
|
|
567 |
/** |
/** |
568 |
* Static method to load calibration. |
* \brief Static method to load calibration. |
569 |
* Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens the |
* Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens after the method TrkParams::SetCalib(***) is called. |
|
* first time the method is called (but it does not work becouse I didn't set any |
|
|
* default calibration for the moment) or after the method TrkParams::SetCalib(***) is called. |
|
570 |
*/ |
*/ |
571 |
Bool_t TrkParams::LoadCalib( ){ |
Bool_t TrkParams::LoadCalib( ){ |
572 |
|
|
640 |
* @param dbc Database |
* @param dbc Database |
641 |
* @param type Parameter type |
* @param type Parameter type |
642 |
* @return FALSE if parameter set fails. |
* @return FALSE if parameter set fails. |
643 |
* If glrun==NULL the last parameter entry from GL_PARAM table is set. |
* If glrun==NULL the first parameter entry from GL_PARAM table is set. |
644 |
* If dbc==NULL, try to open a connection taking DB-connection |
* If dbc==NULL, try to open a connection taking DB-connection |
645 |
* parameters from PAMELA environment variables. |
* parameters from PAMELA environment variables. |
646 |
*/ |
*/ |
650 |
UInt_t index = TrkParams::GetIndex( type ); |
UInt_t index = TrkParams::GetIndex( type ); |
651 |
if(index < 0)return false; |
if(index < 0)return false; |
652 |
|
|
653 |
|
UInt_t runheadtime=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) || |
if( !TrkParams::IsLoaded(type) || |
666 |
glrun->RUNHEADER_TIME < gl[index].FROM_TIME || |
runheadtime < gl[index].FROM_TIME || |
667 |
glrun->RUNHEADER_TIME > gl[index].TO_TIME || |
runheadtime > gl[index].TO_TIME || |
668 |
false ){ |
false ){ |
669 |
|
|
670 |
|
bool LOCAL_CONNECTION = false; |
671 |
if( !dbc || (dbc && !dbc->IsConnected()) ){ |
if( !dbc || (dbc && !dbc->IsConnected()) ){ |
672 |
|
|
673 |
if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl; |
if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl; |
674 |
TString host = "mysql://localhost/pamelaprod"; |
dbc = TrkParams::SetDBConnection(); |
675 |
TString user = "anonymous"; |
if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true; |
|
TString psw = ""; |
|
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
|
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
|
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
|
|
if ( !pamdbhost ) pamdbhost = ""; |
|
|
if ( !pamdbuser ) pamdbuser = ""; |
|
|
if ( !pamdbpsw ) pamdbpsw = ""; |
|
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
|
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
|
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
|
|
if(TrkParams::VerboseMode()){ |
|
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
|
|
cout<<"Connecting to DB"<<endl; |
|
|
cout<<"HOST "<<host<<endl; |
|
|
cout<<"USER "<<user<<endl; |
|
|
cout<<"PSW "<<psw<<endl; |
|
|
} |
|
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
|
|
if( !dbc )return false; |
|
|
if( !dbc->IsConnected() )return false; |
|
|
if(TrkParams::VerboseMode()){ |
|
|
cout << " ...done"<<endl; |
|
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
|
|
} |
|
|
} |
|
676 |
|
|
677 |
|
} |
|
UInt_t runheadtime = numeric_limits<UInt_t>::max(); |
|
|
if(glrun)runheadtime = glrun->RUNHEADER_TIME; |
|
|
else cout <<"Missing run info -- taking last entry "<<endl; |
|
678 |
|
|
679 |
GL_PARAM q4; |
GL_PARAM q4; |
680 |
if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false; |
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; |
gl[index] = q4; |
686 |
glpath[index] = q4.PATH+q4.NAME; |
glpath[index] = q4.PATH+q4.NAME; |
687 |
glload[index] = false; |
glload[index] = false; |
688 |
if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from DB) "<<endl; |
|
689 |
return true; |
return true; |
690 |
|
|
691 |
} |
} |
705 |
|
|
706 |
gl[index].TYPE= type; |
gl[index].TYPE= type; |
707 |
glpath[index] = path; |
glpath[index] = path; |
708 |
if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" >> (from input) "<<endl; |
if(TrkParams::VerboseMode()) |
709 |
|
cout << "<< set TrkParams type "<<type<<" from path << "<<path<<endl; |
710 |
glload[index] = false; |
glload[index] = false; |
711 |
|
|
712 |
// return TrkParams::Load(type); |
// return TrkParams::Load(type); |
722 |
*/ |
*/ |
723 |
Bool_t TrkParams::Set(UInt_t type){ |
Bool_t TrkParams::Set(UInt_t type){ |
724 |
|
|
|
UInt_t index = TrkParams::GetIndex( type ); |
|
|
if(index < 0)return false; |
|
725 |
|
|
726 |
gl[index].TYPE= type; |
return Set(0,0,type); |
|
glload[index] = false; |
|
|
|
|
|
// ----------------------------------------- |
|
|
// check if enviroment variables are defined |
|
|
// ----------------------------------------- |
|
|
glpath[index] = gSystem->Getenv("PAM_CALIB"); |
|
|
|
|
|
if( !glpath[index].IsNull() ){ |
|
|
|
|
|
switch(type){ |
|
|
case 1: |
|
|
glpath[index].Append("/trk-param/field_param-0/"); |
|
|
break; |
|
|
case 2: |
|
|
glpath[index].Append("/trk-param/mip_param-0/"); |
|
|
break; |
|
|
case 3: |
|
|
glpath[index].Append("/trk-param/charge_param-1/"); |
|
|
break; |
|
|
case 4: |
|
|
glpath[index].Append("/trk-param/eta_param-0/"); |
|
|
break; |
|
|
case 5: |
|
|
glpath[index].Append("/trk-param/align_param-0/"); |
|
|
break; |
|
|
case 6: |
|
|
glpath[index].Append("/trk-param/mask_param-1/"); |
|
|
break; |
|
|
case 7: |
|
|
glpath[index].Append("/trk-param/default_calib/"); |
|
|
break; |
|
|
} |
|
|
|
|
|
}else{ |
|
|
cout << " TrkParams::Set( UInt_t type) ==> No PAMELA environment variables defined "<<endl; |
|
|
return false; |
|
|
|
|
|
} |
|
727 |
|
|
|
if(TrkParams::VerboseMode())cout << "<< set TrkParams type "<<type<<" (from env var PAM_CALIB) >>"<<endl; |
|
|
// return TrkParams::Load(type); |
|
|
return true; |
|
728 |
|
|
729 |
}; |
}; |
730 |
/** |
/** |
735 |
*/ |
*/ |
736 |
Bool_t TrkParams::Set( ){ |
Bool_t TrkParams::Set( ){ |
737 |
|
|
|
Bool_t connected = false; |
|
738 |
|
|
739 |
// cout <<" Missing DB connection -- check PAMELA environment variables "<<endl; |
for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false; |
|
TString host = "mysql://localhost/pamelaprod"; |
|
|
TString user = "anonymous"; |
|
|
TString psw = ""; |
|
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
|
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
|
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
|
|
if ( !pamdbhost ) pamdbhost = ""; |
|
|
if ( !pamdbuser ) pamdbuser = ""; |
|
|
if ( !pamdbpsw ) pamdbpsw = ""; |
|
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
|
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
|
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
|
|
if(TrkParams::VerboseMode()){ |
|
|
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
|
|
cout<<"Connecting to DB"<<endl; |
|
|
cout<<"HOST "<<host<<endl; |
|
|
cout<<"USER "<<user<<endl; |
|
|
cout<<"PSW "<<psw<<endl; |
|
|
} |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
|
|
if( dbc || dbc->IsConnected() )connected = true; |
|
|
else cout << " >> DB connection FAILED!!!"<<endl; |
|
|
if(TrkParams::VerboseMode())cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
|
|
|
|
|
if(connected){ |
|
|
if ( !TrkParams::Set(0,dbc) )return false; |
|
|
dbc->Close(); |
|
|
}else for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false; |
|
740 |
|
|
741 |
return true; |
return true; |
742 |
} |
} |
843 |
return true; |
return true; |
844 |
}; |
}; |
845 |
|
|
846 |
|
|
847 |
|
/** |
848 |
|
* Get BY (kGauss) |
849 |
|
* @param v (x,y,z) coordinates in cm |
850 |
|
*/ |
851 |
|
float TrkParams::GetBX(float* v){ |
852 |
|
TrkParams::Load(1); |
853 |
|
if( !TrkParams::IsLoaded(1) )return 0.; |
854 |
|
float b[3]; |
855 |
|
gufld_(v,b); |
856 |
|
return b[0]/10.; |
857 |
|
} |
858 |
|
/** |
859 |
|
* Get BY (kGauss) |
860 |
|
* @param v (x,y,z) coordinates in cm |
861 |
|
*/ |
862 |
|
float TrkParams::GetBY(float* v){ |
863 |
|
TrkParams::Load(1); |
864 |
|
if( !TrkParams::IsLoaded(1) )return 0.; |
865 |
|
float b[3]; |
866 |
|
gufld_(v,b); |
867 |
|
return b[1]/10.; |
868 |
|
} |
869 |
|
/** |
870 |
|
* Get BY (kGauss) |
871 |
|
* @param v (x,y,z) coordinates in cm |
872 |
|
*/ |
873 |
|
float TrkParams::GetBZ(float* v){ |
874 |
|
TrkParams::Load(1); |
875 |
|
if( !TrkParams::IsLoaded(1) )return 0.; |
876 |
|
float b[3]; |
877 |
|
gufld_(v,b); |
878 |
|
return b[2]/10.; |
879 |
|
} |
880 |
|
|
881 |
|
|
882 |
|
/** |
883 |
|
* \brief Set tracking mode (0=standard. 1=???) |
884 |
|
*/ |
885 |
|
void TrkParams::SetTrackingMode(int trackmode) { |
886 |
|
init__mini_trackmode = trackmode; |
887 |
|
SetTrackingMode(); //fill F77 common |
888 |
|
}; |
889 |
|
/** |
890 |
|
* \brief Set fit-precision factor (typical value fact=100.) |
891 |
|
*/ |
892 |
|
void TrkParams::SetPrecisionFactor(double fact){ |
893 |
|
init__mini_fact = fact; |
894 |
|
SetPrecisionFactor(); //fill F77 common |
895 |
|
}; |
896 |
|
/** |
897 |
|
* \brief Set minimum number of step in track fitting |
898 |
|
*/ |
899 |
|
void TrkParams::SetStepMin(int istepmin){ |
900 |
|
init__mini_istepmin = istepmin; |
901 |
|
SetStepMin(); //fill F77 common |
902 |
|
}; |
903 |
|
/** |
904 |
|
* \brief Set deltaB parameters (id=0,1) |
905 |
|
*/ |
906 |
|
void TrkParams::SetDeltaB(int id,double db){ |
907 |
|
if(id!=0 && id!=1)cout << "void TrkParams::SetDeltaB(int id,double db) -- wrong input parameters: "<<id<<" "<<db<<endl; |
908 |
|
if(id==0)init__deltab_0 = db; |
909 |
|
if(id==1)init__deltab_1 = db; |
910 |
|
SetDeltaB(); //fill F77 common |
911 |
|
}; |
912 |
|
|
913 |
|
/** |
914 |
|
* \brief Fill F77 commons with PFA settings |
915 |
|
*/ |
916 |
|
void TrkParams::SetPFA(){ |
917 |
|
sw_.pfaid = init__pfa; |
918 |
|
for(int i=0; i<6; i++){ |
919 |
|
pfa_.e234ax[i] = init__pfa_e234ax[i]; |
920 |
|
pfa_.e234ay[i] = init__pfa_e234ay[i]; |
921 |
|
} |
922 |
|
}; |
923 |
|
/** |
924 |
|
* \brief Set p.f.a. |
925 |
|
* |
926 |
|
* Implemented algorythms: |
927 |
|
* 0 ETA |
928 |
|
* 1 --- |
929 |
|
* 2 ETA2 |
930 |
|
* 3 ETA3 |
931 |
|
* 4 ETA4 |
932 |
|
* 5 ETAL ==> ETA+LANDI |
933 |
|
* 10 COG |
934 |
|
* 11 COG1 |
935 |
|
* 12 COG2 |
936 |
|
* 13 COG3 |
937 |
|
* 14 COG4 |
938 |
|
*/ |
939 |
|
void TrkParams::SetPFA(int pfaid){ |
940 |
|
init__pfa = pfaid; |
941 |
|
SetPFA(); //fill F77 common |
942 |
|
}; |
943 |
|
/** |
944 |
|
* \brief Set p.f.a. angular intervals |
945 |
|
* |
946 |
|
* This methods allows to set amgular intervals to apply ETA2,ETA3 or ETA4 |
947 |
|
* algorythm, in case ETA or ETAL is set (see TrkParams::SetPFA(int pfaid)). |
948 |
|
* @param v Pointer to a vector of 12 components, which represent the |
949 |
|
* angular limits for ETA2,ETA3 and ETA4, for x and y views, respectivelly. |
950 |
|
* |
951 |
|
*/ |
952 |
|
void TrkParams::SetPFA(float *v){ |
953 |
|
for(int i=0; i<6; i++){ |
954 |
|
init__pfa_e234ax[i] = v[i]; |
955 |
|
init__pfa_e234ay[i] = v[i+6]; |
956 |
|
} |
957 |
|
SetPFA(); //fill F77 common |
958 |
|
}; |
959 |
|
|
960 |
|
|
961 |
|
/** |
962 |
|
* \brief Get spatial resolution. |
963 |
|
* |
964 |
|
* Method to retrieve the spatial resolution associated with the |
965 |
|
* adopted p.f.a. |
966 |
|
* @param view Tracker view (1-12) |
967 |
|
* @param angle Track projected angle |
968 |
|
* |
969 |
|
* In order to change p.f.a. use the SetPFA(int pfaid) method, eg.: |
970 |
|
* |
971 |
|
* TrkParams::SetPFA(0) // ETA |
972 |
|
* |
973 |
|
*/ |
974 |
|
float TrkParams::GetResolution(int view, float angle){ |
975 |
|
float res = 1000; |
976 |
|
if( init__pfa == 0 )res = riseta_(&view,&angle); |
977 |
|
else cout << "float TrkParams::GetResolution(int view, float angle) -- PFA "<<init__pfa<<" not yet implemented"<<endl; |
978 |
|
return res; |
979 |
|
} |
980 |
|
|
981 |
|
|
982 |
|
|
983 |
|
|
984 |
ClassImp(TrkParams); |
ClassImp(TrkParams); |