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