1 |
|
2 |
/** |
3 |
* \file TrkParams.cpp |
4 |
* \author Elena Vannuccini |
5 |
*/ |
6 |
|
7 |
#include <TrkParams.h> |
8 |
#include <iostream> |
9 |
#include <iomanip> |
10 |
using namespace std; |
11 |
|
12 |
|
13 |
Bool_t TrkParams::simuflag = kFALSE; |
14 |
// ------------------------- |
15 |
// CALIBRATION (PED,SIG,BAD) |
16 |
// ------------------------- |
17 |
GL_TRK_CALIB TrkParams::calib = GL_TRK_CALIB(); |
18 |
TString TrkParams::calibpatht = ""; |
19 |
TString TrkParams::calibpathf = ""; |
20 |
Bool_t TrkParams::calib104 = 0; |
21 |
Bool_t TrkParams::calibload = false; |
22 |
TrkCalib* TrkParams::calib1 = 0; |
23 |
TrkCalib* TrkParams::calib2 = 0; |
24 |
// ------------------------- |
25 |
// PARAMETERS loaded from DB |
26 |
// ------------------------- |
27 |
UInt_t TrkParams::trkparamtype[] = {1,2,3,4,5,6,7}; |
28 |
GL_PARAM TrkParams::gl[] = {GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM(),GL_PARAM()}; |
29 |
TString TrkParams::glpath[] = {"","","","","","",""}; |
30 |
Bool_t TrkParams::glload[] = {false,false,false,false,false,false,false}; |
31 |
// ---------------- |
32 |
// other parameters |
33 |
// ---------------- |
34 |
cDbg TrkParams::init__dbg_mode = {0,0,0}; |
35 |
//int TrkParams::init__pfa = 14;//COG4 |
36 |
int TrkParams::init__pfa = 5;//ETAL |
37 |
int TrkParams::init__mini_trackmode = 0; |
38 |
int TrkParams::init__mini_istepmin = 5; //3; |
39 |
double TrkParams::init__mini_fact = 1.e4; //100.; |
40 |
float TrkParams::init__pfa_e234ax[] = {0.,10.,10.,15.,15.,90.}; |
41 |
float TrkParams::init__pfa_e234ay[] = {0.,20.,90.,90.,90.,90.}; |
42 |
double TrkParams::init__deltab_0 = 0.; |
43 |
double TrkParams::init__deltab_1 = 0.; |
44 |
double TrkParams::init__dlt = 1.e-5; |
45 |
// ------------------------------------------ |
46 |
// nominal z-coordinates to define acceptance |
47 |
// ------------------------------------------ |
48 |
int TrkParams::nGF = NGF; |
49 |
float TrkParams::zGF[] = {+53.74,+53.04,+23.94,+23.44,+22.29,+21.83,+13.39,+4.49,-4.41,-13.31,-21.83,-22.22,-23.49,-24.34}; |
50 |
float TrkParams::xGF_min[] = {-20.40,-20.40,-9.00,-9.00,-8.07,-8.07,-8.07,-8.07,-8.07,-8.07,-8.07,-8.07,-9.00,-9.00}; |
51 |
float TrkParams::xGF_max[] = {+20.40,+20.40,+9.00,+9.00,+8.07,+8.07,+8.07,+8.07,+8.07,+8.07,+8.07,+8.07,+9.00,+9.00}; |
52 |
// float TrkParams::yGF_min[] = {-16.50,-16.50,-7.50,-7.50,-7.25,-6.57,-7.25,-7.25,-7.25,-7.25,-6.57,-6.75,-7.50,-7.50}; |
53 |
// float TrkParams::yGF_max[] = {+16.50,+16.50,+7.50,+7.50,+6.75,+6.57,+6.75,+6.75,+6.75,+6.75,+6.57,+7.25,+7.50,+7.50}; |
54 |
// per i piani interni alla cavita`, gli estremi sono dati dalla cavita` stessa |
55 |
float TrkParams::yGF_min[] = {-16.50,-16.50,-7.50,-7.50,-7.25,-6.57,-6.57,-6.57,-6.57,-6.57,-6.57,-6.75,-7.50,-7.50}; |
56 |
float TrkParams::yGF_max[] = {+16.50,+16.50,+7.50,+7.50,+6.75,+6.57,+6.57,+6.57,+6.57,+6.57,+6.57,+7.25,+7.50,+7.50}; |
57 |
TString TrkParams::GF_element[] = {"S11","S12","S21","S22","T1","CUF","T2","T3","T4","T5","CLF","T6","S31","S32"}; |
58 |
|
59 |
TrkParams::TrkParams(){ |
60 |
|
61 |
cout<<"TrkParams::TrkParams()"<<endl; |
62 |
|
63 |
} |
64 |
float aint(float f){ |
65 |
int ret = (int)f; |
66 |
float ret1 = 0; |
67 |
ret1=(float)ret; |
68 |
return ret1; |
69 |
} |
70 |
|
71 |
float anint(float f){ |
72 |
int ret = (int)(f+0.5); |
73 |
float ret1 = 0; |
74 |
ret1=(float)ret; |
75 |
return ret1; |
76 |
} |
77 |
|
78 |
void TrkParams::SetSimuFlag(Bool_t flag){ |
79 |
simuflag = flag; |
80 |
} |
81 |
|
82 |
Bool_t TrkParams::GetSimuFlag(){ |
83 |
return simuflag; |
84 |
} |
85 |
|
86 |
|
87 |
/** |
88 |
* Static method to open a DB connection. |
89 |
* HOST, USER and PASSWORD are taken from enviroment variables $PAM_DBHOST, |
90 |
* $PAM_DBUSER and $PAM_DBPSW |
91 |
* NB! The method create a new connection, which has to be closed by the user. |
92 |
*/ |
93 |
TSQLServer* TrkParams::SetDBConnection(){ |
94 |
|
95 |
TString host = "mysql://localhost/pamelaprod"; |
96 |
TString user = "anonymous"; |
97 |
TString psw = ""; |
98 |
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
99 |
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
100 |
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
101 |
if ( !pamdbhost ) pamdbhost = ""; |
102 |
if ( !pamdbuser ) pamdbuser = ""; |
103 |
if ( !pamdbpsw ) pamdbpsw = ""; |
104 |
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
105 |
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
106 |
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
107 |
if(TrkParams::DebugMode()){ |
108 |
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
109 |
cout<<"TrkParams::SetDBConnection() >> Connecting to DB"<<endl; |
110 |
cout<<"HOST "<<host<<endl; |
111 |
cout<<"USER "<<user<<endl; |
112 |
cout<<"PSW "<<psw<<endl; |
113 |
} |
114 |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
115 |
if( !dbc )return NULL; |
116 |
if( !dbc->IsConnected() )return NULL; |
117 |
stringstream myquery; // EMILIANO |
118 |
myquery.str(""); // EMILIANO |
119 |
myquery << "SET time_zone='+0:00';"; // EMILIANO |
120 |
delete dbc->Query(myquery.str().c_str()); // EMILIANO |
121 |
delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");//EM |
122 |
if(TrkParams::DebugMode()){ |
123 |
cout << " ...done"<<endl; |
124 |
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; |
125 |
} |
126 |
|
127 |
return dbc; |
128 |
} |
129 |
/** |
130 |
* \brief Static method to set the calibration to be loaded. |
131 |
|
132 |
* It retrieves the calibration associated to a given run, from |
133 |
* a given DB. It fills the F77 common. |
134 |
* @param glrun Pointer to a GL_RUN row |
135 |
* @param dbc Pointer to a DB connection |
136 |
*/ |
137 |
Bool_t TrkParams::SetCalib( GL_RUN *glrun, TSQLServer* dbc ){ |
138 |
|
139 |
// cout << "glrun-> RUNHEADER_TIME "<<glrun->RUNHEADER_TIME <<endl; |
140 |
|
141 |
if( !CalibIsLoaded() || |
142 |
(glrun->TRK_CALIB_USED==104 && !calib104) || |
143 |
(glrun->TRK_CALIB_USED!=104 && calib104) || |
144 |
glrun->RUNHEADER_TIME < calib.FROM_TIME || |
145 |
glrun->RUNHEADER_TIME > calib.TO_TIME || |
146 |
false ){ |
147 |
|
148 |
|
149 |
GL_TRK_CALIB q2; |
150 |
GL_ROOT q3; |
151 |
GL_PARAM q4; |
152 |
|
153 |
|
154 |
bool LOCAL_CONNECTION = false; |
155 |
if( !dbc || (dbc && !dbc->IsConnected()) ){ |
156 |
|
157 |
// if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl; |
158 |
dbc = TrkParams::SetDBConnection(); |
159 |
if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true; |
160 |
|
161 |
} |
162 |
|
163 |
|
164 |
if(TrkParams::VerboseMode()){ |
165 |
cout << "--------------------------------------"<<endl; |
166 |
cout << "UPDATING calibration -- run-header time "<< glrun->RUNHEADER_TIME <<endl; |
167 |
} |
168 |
if( q2.Query_GL_TRK_CALIB(glrun->RUNHEADER_TIME,dbc) ){ |
169 |
cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_TRK_CALIB "<<endl; |
170 |
return false; |
171 |
} |
172 |
if( q2.EV_ROOT_CALIBTRK1 != q2.EV_ROOT_CALIBTRK2 ) |
173 |
printf(" WARNING!! ---> EV_ROOT_CALIBTRK1=%d it's different from EV_ROOT_CALIBTRK2=%d \n\n",q2.EV_ROOT_CALIBTRK1,q2.EV_ROOT_CALIBTRK2); |
174 |
if( q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc) ){ |
175 |
cout << " Bool_t TrkParams::SetCalib( GL_RUN* , TSQLServer* ) -- ERROR -- failed query to GL_ROOT "<<endl; |
176 |
return false; |
177 |
} |
178 |
|
179 |
if(TrkParams::VerboseMode())cout << "selected DB entry "<<q2.ID<<" from_time "<<q2.FROM_TIME<<" to time "<<q2.TO_TIME<<" --> VALIDATION "<<q2.VALIDATION<<endl; |
180 |
calib = q2; |
181 |
calibpathf = q3.PATH + q3.NAME; |
182 |
calib104 = (glrun->TRK_CALIB_USED==104); |
183 |
calibload = kFALSE; |
184 |
if(calib104){ |
185 |
if (q4.Query_GL_PARAM(glrun->RUNHEADER_TIME,7,dbc) )return false; |
186 |
calibpatht = q4.PATH + q4.NAME; |
187 |
} |
188 |
|
189 |
if(LOCAL_CONNECTION&&dbc){ |
190 |
dbc->Close(); |
191 |
delete dbc; |
192 |
if(TrkParams::DebugMode()){ |
193 |
cout << " DB connection closed."<<endl; |
194 |
} |
195 |
} |
196 |
|
197 |
// return TrkParams::LoadCalib(); |
198 |
return true; |
199 |
} |
200 |
|
201 |
return false; |
202 |
}; |
203 |
|
204 |
/** |
205 |
* Method to "validate" tracker calibration. Implemented for test purpose. Effective implementation |
206 |
* in YodaProfiler. |
207 |
*/ |
208 |
UInt_t TrkParams::ValidateTrkCalib( CalibTrk1Event* caltrk){ |
209 |
|
210 |
UInt_t validate = 1; |
211 |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
212 |
// UInt_t timeaftercalib=120000; //2000; |
213 |
TString classname = caltrk->GetName(); |
214 |
// ---------- |
215 |
// Check CRCs |
216 |
// ---------- |
217 |
if(TrkParams::VerboseMode())cout << " DSP: "; |
218 |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
219 |
if(TrkParams::VerboseMode())cout <<" "<<caltrk->DSPnumber[ipkt]; |
220 |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
221 |
if( caltrk->crc_hcal[ipkt] ){ |
222 |
if(TrkParams::WarningMode())cout<<"(CRC Header)"; |
223 |
// if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration header: pkt "<<ipkt<<endl; |
224 |
// return 0; // :-( |
225 |
validate = 0; |
226 |
} |
227 |
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
228 |
if(TrkParams::WarningMode())cout<<"(CRC Pkt-"<<ilad<<")"; |
229 |
// if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- CRC error in calibration packet: pkt "<<ipkt<<endl; |
230 |
// return 0; // :-( |
231 |
validate = 0; |
232 |
} |
233 |
} |
234 |
} |
235 |
if(TrkParams::VerboseMode())cout << endl;; |
236 |
// ----------------------- |
237 |
// Check missing packets: |
238 |
// ----------------------- |
239 |
// Readout order: |
240 |
// ------------------ |
241 |
// DSP packet board |
242 |
// ------------------ |
243 |
// 12 0 1 |
244 |
// 10 1 1 |
245 |
// 8 2 1 |
246 |
// 4 3 1 |
247 |
// 6 4 1 |
248 |
// 2 5 1 |
249 |
// ------------------ |
250 |
// 11 0 2 |
251 |
// 9 1 2 |
252 |
// 7 2 2 |
253 |
// 3 3 2 |
254 |
// 5 4 2 |
255 |
// 1 5 2 |
256 |
// ------------------ |
257 |
// ------------------------------------------------- |
258 |
// Check if it is first or second calibration packet |
259 |
// ------------------------------------------------- |
260 |
UInt_t build=0; |
261 |
UInt_t base=0; |
262 |
// UInt_t mask=0;// EM GCC 4.7 |
263 |
if(classname.Contains("CalibTrk1Event")){ |
264 |
base=12; |
265 |
// mask=0x03F000; // EM GCC 4.7 |
266 |
} |
267 |
if(classname.Contains("CalibTrk2Event")){ |
268 |
base=18; |
269 |
// mask=0xFC0000; // EM GCC 4.7 |
270 |
} |
271 |
// ------------------------------------------------- |
272 |
// Count number of packets and set build variable |
273 |
// ------------------------------------------------- |
274 |
Int_t npkts=0; |
275 |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
276 |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
277 |
npkts++; |
278 |
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
279 |
}; |
280 |
} |
281 |
if( npkts==6 ){}//return 1; // :-) |
282 |
else { |
283 |
if(TrkParams::WarningMode())cout << "ValidateTrkCalib: "<<classname<<" --WARNING-- there might be some missing packets :-( ( "<<npkts<<" instead of 6 ) --> "<<endl; |
284 |
validate = 0; |
285 |
} |
286 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
287 |
|
288 |
// ----------------------------------------------- |
289 |
// If missing packets: check the acq configuration |
290 |
// (some DSPs might be excluded from acquisition) |
291 |
// ----------------------------------------------- |
292 |
|
293 |
// ----------------------------------------------- |
294 |
// retrieve the first run header after calib |
295 |
// ----------------------------------------------- |
296 |
// PacketType *pctp; |
297 |
// EventCounter *cod; |
298 |
// cod = eh->GetCounter(); |
299 |
// Int_t irun = cod->Get(pctp->RunHeader); |
300 |
// TTree *rh=(TTree*)file->Get("RunHeader"); |
301 |
// if ( !rh || rh->IsZombie() ) throw -17; |
302 |
// if( rh->GetEntries() == irun ){ |
303 |
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
304 |
// return 0; // :-( |
305 |
// } |
306 |
|
307 |
// RunHeaderEvent *run = 0; |
308 |
// EventHeader *hrun = 0; |
309 |
// rh->SetBranchAddress("RunHeader", &run); |
310 |
// rh->SetBranchAddress("Header", &hrun); |
311 |
// rh->GetEntry(irun); |
312 |
// // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
313 |
|
314 |
// if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
315 |
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
316 |
// return 0; // :-( |
317 |
// } |
318 |
|
319 |
// if( !run->RM_ACQ_AFTER_CALIB ){ |
320 |
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
321 |
// return 0; // :-( |
322 |
// } |
323 |
|
324 |
// UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
325 |
// if( dtime > timeaftercalib ){ |
326 |
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
327 |
// return 0; // :-( |
328 |
// } |
329 |
|
330 |
// if( (run->ACQ_BUILD_INFO & mask) != build ){ |
331 |
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
332 |
// return 0; // :-( |
333 |
// } |
334 |
|
335 |
// return 1; // :-) |
336 |
|
337 |
// cout << validate << endl; |
338 |
return validate; |
339 |
|
340 |
} |
341 |
/** |
342 |
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
343 |
*/ |
344 |
void TrkParams::FillACalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
345 |
|
346 |
cTrkCalib *ca = &pedsigbad_; |
347 |
ca->Reset(); |
348 |
|
349 |
TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
350 |
TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
351 |
|
352 |
if(!calib1)calib1 = new TrkCalib(); |
353 |
if(!calib2)calib2 = new TrkCalib(); |
354 |
// calibx->Set(calibdata1); |
355 |
// caliby->Set(calibdata2); |
356 |
|
357 |
// CalibTrk1Event *calibdata1 = 0; |
358 |
// CalibTrk2Event *calibdata2 = 0; |
359 |
// tr1->SetBranchAddress("CalibTrk1",&calibdata1); |
360 |
// tr2->SetBranchAddress("CalibTrk2",&calibdata2); |
361 |
tr1->SetBranchAddress("CalibTrk1",calib1->GetPointerTo()); |
362 |
tr2->SetBranchAddress("CalibTrk2",calib2->GetPointerTo()); |
363 |
if ( tr1->GetEntry(ev_reg1) <= 0 ) throw -36;//EM |
364 |
if ( tr2->GetEntry(ev_reg2) <= 0 ) throw -36;//EM |
365 |
Int_t dspn1(0),dspn2(0); |
366 |
|
367 |
|
368 |
// --- TEST TEST TEST TEST --- // |
369 |
// TrkParams::ValidateTrkCalib(calib1->Get()); |
370 |
// TrkParams::ValidateTrkCalib((CalibTrk1Event*)calib2->Get()); |
371 |
|
372 |
UInt_t test1 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)(calib1->Get())); |
373 |
UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)(calib2->Get())); |
374 |
if( !test1 || !test2 ){ |
375 |
// if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl; |
376 |
TrkParams::calib.VALIDATION = 0; |
377 |
} |
378 |
// if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl; |
379 |
|
380 |
for(Int_t i=0;i<6;i++){ |
381 |
|
382 |
|
383 |
dspn1=calib1->Get()->DSPnumber[i]-1; |
384 |
dspn2=calib2->Get()->DSPnumber[i]-1; |
385 |
// cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; |
386 |
for(Int_t ii=0;ii<3072;ii++){ |
387 |
Int_t j=(ii/128); |
388 |
Int_t jj=ii-j*128; |
389 |
if(dspn1>=0 && dspn1<12){ |
390 |
ca->pedestal[jj][j][dspn1]=calib1->Get()->DSPped_par[i][ii]; |
391 |
ca->pedestal_t[jj][j][dspn1]=aint(calib1->Get()->DSPped_par[i][ii]); |
392 |
ca->sigma[jj][j][dspn1]=calib1->Get()->DSPsig_par[i][ii]; |
393 |
ca->sigma_t[jj][j][dspn1]=anint(calib1->Get()->DSPsig_par[i][ii]); |
394 |
if(calib1->Get()->DSPbad_par[i][ii]==0) |
395 |
ca->bad[jj][j][dspn1]=1; |
396 |
else if(calib1->Get()->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 |
|
402 |
if(dspn2>=0 && dspn2<12){ |
403 |
ca->pedestal[jj][j][dspn2]=calib2->Get()->DSPped_par[i][ii]; |
404 |
ca->pedestal_t[jj][j][dspn2]=aint(calib2->Get()->DSPped_par[i][ii]); |
405 |
ca->sigma[jj][j][dspn2]=calib2->Get()->DSPsig_par[i][ii]; |
406 |
ca->sigma_t[jj][j][dspn2]=anint(calib2->Get()->DSPsig_par[i][ii]); |
407 |
if(calib2->Get()->DSPbad_par[i][ii]==0) |
408 |
ca->bad[jj][j][dspn2]=1; |
409 |
else if(calib2->Get()->DSPbad_par[i][ii]==1) |
410 |
ca->bad[jj][j][dspn2]=0; |
411 |
// cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
412 |
// cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
413 |
} |
414 |
}; |
415 |
}; |
416 |
|
417 |
tr1->Delete(); |
418 |
tr2->Delete(); |
419 |
}; |
420 |
/** |
421 |
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
422 |
*/ |
423 |
// void TrkParams::FillFCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
424 |
|
425 |
// cTrkCalib *ca = &pedsigbad_; |
426 |
// // ca->Reset(); |
427 |
|
428 |
// TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
429 |
// TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
430 |
|
431 |
// CalibTrk1Event *calibdata1 = 0; |
432 |
// CalibTrk2Event *calibdata2 = 0; |
433 |
// tr1->SetBranchAddress("CalibTrk1",&calibdata1); |
434 |
// tr2->SetBranchAddress("CalibTrk2",&calibdata2); |
435 |
// tr1->GetEntry(ev_reg1); |
436 |
// tr2->GetEntry(ev_reg2); |
437 |
// Int_t dspn1(0),dspn2(0); |
438 |
|
439 |
// // --- TEST TEST TEST TEST --- // |
440 |
// // TrkParams::ValidateTrkCalib(calibdata1); |
441 |
// // TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
442 |
// UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); |
443 |
// UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
444 |
// if( !test1 || !test2 ){ |
445 |
// if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl; |
446 |
// TrkParams::calib.VALIDATION = 0; |
447 |
// } |
448 |
// if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl; |
449 |
|
450 |
// for(Int_t i=0;i<6;i++){ |
451 |
// dspn1=calibdata1->DSPnumber[i]-1; |
452 |
// dspn2=calibdata2->DSPnumber[i]-1; |
453 |
// /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */ |
454 |
// for(Int_t ii=0;ii<3072;ii++){ |
455 |
// Int_t j=(ii/128); |
456 |
// Int_t jj=ii-j*128; |
457 |
// if(dspn1>=0 && dspn1<12){ |
458 |
// ca->pedestal[jj][j][dspn1]=calibdata1->DSPped_par[i][ii]; |
459 |
// ca->sigma[jj][j][dspn1]=calibdata1->DSPsig_par[i][ii]; |
460 |
// if(calibdata1->DSPbad_par[i][ii]==0) |
461 |
// ca->bad[jj][j][dspn1]=1; |
462 |
// else if(calibdata1->DSPbad_par[i][ii]==1) |
463 |
// ca->bad[jj][j][dspn1]=0; |
464 |
// // cout<<"sigma trk1= "<<sigma[jj][j][dspn1]<<endl; |
465 |
// // cout<<"sigma_t trk1= "<<sigma_t[jj][j][dspn1]<<endl; |
466 |
// } |
467 |
// if(dspn2>=0 && dspn2<12){ |
468 |
// ca->pedestal[jj][j][dspn2]=calibdata2->DSPped_par[i][ii]; |
469 |
// ca->sigma[jj][j][dspn2]=calibdata2->DSPsig_par[i][ii]; |
470 |
// if(calibdata2->DSPbad_par[i][ii]==0) |
471 |
// ca->bad[jj][j][dspn2]=1; |
472 |
// else if(calibdata2->DSPbad_par[i][ii]==1) |
473 |
// ca->bad[jj][j][dspn2]=0; |
474 |
// // cout<<"sigma trk2= "<<sigma[jj][j][dspn2]<<endl; |
475 |
// // cout<<"sigma_t trk2= "<<sigma_t[jj][j][dspn2]<<endl; |
476 |
// } |
477 |
// }; |
478 |
// }; |
479 |
|
480 |
// tr1->Delete(); |
481 |
// tr2->Delete(); |
482 |
// }; |
483 |
/** |
484 |
* Method to fill the tracker calibration-parameter struct from on-line calibrations |
485 |
*/ |
486 |
// void TrkParams::FillTCalibFrom(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
487 |
|
488 |
// cTrkCalib *ca = &pedsigbad_; |
489 |
// // ca->Reset(); |
490 |
|
491 |
// TTree *tr1 = (TTree*)f0->Get("CalibTrk1"); |
492 |
// TTree *tr2 = (TTree*)f0->Get("CalibTrk2"); |
493 |
|
494 |
// CalibTrk1Event *calibdata1 = 0; |
495 |
// CalibTrk2Event *calibdata2 = 0; |
496 |
// tr1->SetBranchAddress("CalibTrk1",&calibdata1); |
497 |
// tr2->SetBranchAddress("CalibTrk2",&calibdata2); |
498 |
// tr1->GetEntry(ev_reg1); |
499 |
// tr2->GetEntry(ev_reg2); |
500 |
// Int_t dspn1(0),dspn2(0); |
501 |
|
502 |
// // --- TEST TEST TEST TEST --- // |
503 |
// // TrkParams::ValidateTrkCalib(calibdata1); |
504 |
// // TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
505 |
// UInt_t test1 = TrkParams::ValidateTrkCalib(calibdata1); |
506 |
// UInt_t test2 = TrkParams::ValidateTrkCalib((CalibTrk1Event*)calibdata2); |
507 |
// if( !test1 || !test2 ){ |
508 |
// if(TrkParams::calib.VALIDATION==1)cout << "--> modify DB info "<<endl; |
509 |
// TrkParams::calib.VALIDATION = 0; |
510 |
// } |
511 |
// if(TrkParams::calib.VALIDATION==0)cout << " ** WARNING ** Calibration not validated "<<endl; |
512 |
|
513 |
// for(Int_t i=0;i<6;i++){ |
514 |
// dspn1=calibdata1->DSPnumber[i]-1; |
515 |
// dspn2=calibdata2->DSPnumber[i]-1; |
516 |
// /* cout<<"dspn1= "<<dspn1<<" dspn2= "<<dspn2<<endl; */ |
517 |
// for(Int_t ii=0;ii<3072;ii++){ |
518 |
// Int_t j=(ii/128); |
519 |
// Int_t jj=ii-j*128; |
520 |
// if(dspn1>=0 && dspn1<12){ |
521 |
// ca->pedestal_t[jj][j][dspn1]=aint(calibdata1->DSPped_par[i][ii]); |
522 |
// ca->sigma_t[jj][j][dspn1]=anint(calibdata1->DSPsig_par[i][ii]); |
523 |
// } |
524 |
// if(dspn2>=0 && dspn2<12){ |
525 |
// ca->pedestal_t[jj][j][dspn2]=aint(calibdata2->DSPped_par[i][ii]); |
526 |
// ca->sigma_t[jj][j][dspn2]=anint(calibdata2->DSPsig_par[i][ii]); |
527 |
// } |
528 |
// }; |
529 |
// }; |
530 |
|
531 |
// tr1->Delete(); |
532 |
// tr2->Delete(); |
533 |
// }; |
534 |
/** |
535 |
* Method to fill the tracker calibration-parameter struct from default calibration |
536 |
*/ |
537 |
void TrkParams::FillTCalibFrom(TString path){ |
538 |
|
539 |
path_.FillWith(path); |
540 |
fillpedsigfromdefault_(); |
541 |
if(path_.error) throw -216; |
542 |
|
543 |
}; |
544 |
/** |
545 |
* Method to fill the tracker VA1-mask struct from calibration |
546 |
*/ |
547 |
void TrkParams::FillMask(TFile* f0, Int_t ev_reg1, Int_t ev_reg2){ |
548 |
|
549 |
cTrkMask *ma = &mask_; |
550 |
ma->Reset(); |
551 |
|
552 |
TrkCalib *calib = new TrkCalib(); |
553 |
|
554 |
for(Int_t i=0; i<2; i++){ |
555 |
TTree *tr=0; |
556 |
if(i==0){ |
557 |
//------------------------- |
558 |
//read calibration packet 1 |
559 |
//------------------------- |
560 |
tr = (TTree*)f0->Get("CalibTrk1"); |
561 |
tr->SetBranchAddress("CalibTrk1",calib->GetPointerTo()); |
562 |
if ( tr->GetEntry(ev_reg1) <= 0 ) throw -36;//EM |
563 |
} |
564 |
if(i==1){ |
565 |
//------------------------- |
566 |
//read calibration packet 2 |
567 |
//------------------------- |
568 |
tr = (TTree*)f0->Get("CalibTrk2"); |
569 |
tr->SetBranchAddress("CalibTrk2",calib->GetPointerTo()); |
570 |
if ( tr->GetEntry(ev_reg2) <= 0 ) throw -36; |
571 |
} |
572 |
for(Int_t ipkt=0; ipkt<NPLANE; ipkt++){ |
573 |
Int_t view = calib->GetView(ipkt); |
574 |
if( (view-1)>= 0 && (view-1)<12 ){ |
575 |
for(Int_t ivk=0; ivk<NVK; ivk++){ |
576 |
Float_t sigm = calib->GetMean("SIG-BAD",ipkt,ivk+1); |
577 |
Float_t sigmin = 0.; |
578 |
if(view%2)sigmin = 6.5; |
579 |
else sigmin = 2.5; |
580 |
Int_t mask = 1; |
581 |
if( sigm<sigmin )mask = 0; |
582 |
ma->mask_vk_run[ivk][view-1] = mask; |
583 |
} |
584 |
} |
585 |
} |
586 |
if(tr)tr->Delete(); |
587 |
} |
588 |
|
589 |
if(TrkParams::VerboseMode()){ |
590 |
for(Int_t iv=0; iv<NVIEW; iv++){ |
591 |
cout<<"view "<<setw(3)<<iv<<": "; |
592 |
for(Int_t ivk=0; ivk<NVK; ivk++)cout<<ma->mask_vk_run[ivk][iv]; |
593 |
cout << endl; |
594 |
} |
595 |
} |
596 |
|
597 |
if(calib)calib->Delete(); |
598 |
|
599 |
}; |
600 |
|
601 |
// Bool_t TrkParams::CalibIsLoaded(UInt_t time){ |
602 |
|
603 |
// if( !calibload ) return false; |
604 |
|
605 |
// }; |
606 |
|
607 |
|
608 |
/** |
609 |
* \brief Static method to load calibration. |
610 |
* Calibration is loaded ONLY IF TrkParams::CalibLoaded()==kTRUE, which appens after the method TrkParams::SetCalib(***) is called. |
611 |
*/ |
612 |
Bool_t TrkParams::LoadCalib( ){ |
613 |
|
614 |
if( TrkParams::CalibIsLoaded() )return false; |
615 |
|
616 |
// ============================================================= |
617 |
// retrieve calibration file needed to reduce data |
618 |
// ============================================================= |
619 |
// if run OBT is > last calibration "expiration date" |
620 |
// - search for new calibration packet |
621 |
// - load calibration parameters (full + truncated) |
622 |
if(TrkParams::VerboseMode()){ |
623 |
cout << "--------------------------------------"<<endl; |
624 |
cout << "Retrieve calibration (PED-SIG-BAD) ..."<<endl; |
625 |
cout << " Full pedestals for cluster finding:"; |
626 |
cout << " >> loading from LEVEL0 file: "<< calibpathf << endl; |
627 |
} |
628 |
FileStat_t t; |
629 |
if( gSystem->GetPathInfo(calibpathf.Data(),t) )return false; |
630 |
|
631 |
bool alreadyopened = false; |
632 |
TFile *f0_c=0; |
633 |
f0_c = (TFile*)gROOT->GetListOfFiles()->FindObject(calibpathf); |
634 |
if(f0_c)alreadyopened=true; |
635 |
else f0_c = new TFile(calibpathf); |
636 |
if ( !f0_c ) return false; |
637 |
|
638 |
if(TrkParams::VerboseMode()){ |
639 |
cout << " calibration entry "<< calib.EV_ROOT_CALIBTRK1 << " " << calib.EV_ROOT_CALIBTRK2; |
640 |
cout << " (from time "<< calib.FROM_TIME <<" to time "<< calib.TO_TIME <<")"<<endl; |
641 |
cout << " - full+truncated parameters "<<endl; |
642 |
} |
643 |
TrkParams::FillACalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
644 |
if(TrkParams::VerboseMode())cout << " - VK-mask (RUN-by-RUN)"<<endl; |
645 |
TrkParams::FillMask(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
646 |
|
647 |
// ============================================================= |
648 |
// retrieve calibration file needed to uncompress data |
649 |
// ============================================================= |
650 |
// if the run was compressed using default calib |
651 |
// load truncated pedestals from default |
652 |
// otherwise reload them from on-line calibration |
653 |
if(TrkParams::VerboseMode())cout << " Truncated pedestals for uncompression:"; |
654 |
if( calib104 ){ |
655 |
|
656 |
if(TrkParams::VerboseMode())cout << " >> loading default calibration: "<< calibpatht << endl; |
657 |
TrkParams::FillTCalibFrom(calibpatht); |
658 |
|
659 |
}else{ |
660 |
|
661 |
// if ( !f0_c ) return false; |
662 |
if(TrkParams::VerboseMode())cout << ">> already loaded " << endl; |
663 |
// TrkParams::FillTCalibFrom(f0_c,calib.EV_ROOT_CALIBTRK1,calib.EV_ROOT_CALIBTRK2); |
664 |
}; |
665 |
if(!alreadyopened)f0_c->Close(); |
666 |
if(TrkParams::VerboseMode())cout << "--------------------------------------"<<endl; |
667 |
|
668 |
calibload = kTRUE; |
669 |
return true; |
670 |
}; |
671 |
|
672 |
Int_t TrkParams::GetIndex( UInt_t type ){ |
673 |
Int_t index = -1; |
674 |
for (Int_t i=0; i< NTYPES; i++)if( type == trkparamtype[i] )index=i; |
675 |
return index; |
676 |
}; |
677 |
|
678 |
/** |
679 |
* Set tracker parameters proper for a run querying the DB. |
680 |
* @param glrun Input run info |
681 |
* @param dbc Database |
682 |
* @param type Parameter type |
683 |
* @return FALSE if parameter set fails. |
684 |
* If glrun==NULL the first parameter entry from GL_PARAM table is set. |
685 |
* If dbc==NULL, try to open a connection taking DB-connection |
686 |
* parameters from PAMELA environment variables. |
687 |
*/ |
688 |
Bool_t TrkParams::Set( GL_RUN* glrun , TSQLServer* dbc , UInt_t type, UInt_t abstime){ |
689 |
|
690 |
|
691 |
UInt_t index = TrkParams::GetIndex( type ); |
692 |
if(index < 0)return false; |
693 |
|
694 |
if(TrkParams::VerboseMode()) |
695 |
cout <<"Calling Bool_t TrkParams::Set(GL_RUN* "<<glrun<<" ,TSQLServer* "<<dbc<<" ,UInt_t "<<type<<" ,UInt_t " <<abstime << " ) >> (**WARNING** check that this is all ok!! )"<<endl; |
696 |
|
697 |
UInt_t runheadtime=1; |
698 |
UInt_t runid=0; |
699 |
// UInt_t runheadtime = numeric_limits<UInt_t>::max(); |
700 |
if(glrun){ |
701 |
runheadtime = glrun->RUNHEADER_TIME; |
702 |
runid = glrun->ID; |
703 |
}else |
704 |
cout <<"Bool_t TrkParams::Set(GL_RUN* "<<glrun<<" ,TSQLServer* "<<dbc<<" ,UInt_t "<<type<<" ,UInt_t " <<abstime << " ) >> GL_RUN==NULL -- taking first entry (**WARNING** check that this is ok!! )"<<endl; |
705 |
|
706 |
|
707 |
if( !abstime || !simuflag ) abstime = runheadtime;// EM: if simu? |
708 |
|
709 |
if(TrkParams::VerboseMode()) |
710 |
cout << "TrkParams::IsLoaded(type)=" << TrkParams::IsLoaded(type) << " abstime=" << abstime << " runheadtime=" << runheadtime << " gl[index].FROM_TIME=" << gl[index].FROM_TIME << " gl[index].TO_TIME=" << gl[index].TO_TIME << endl; |
711 |
|
712 |
if( !TrkParams::IsLoaded(type) || |
713 |
abstime < gl[index].FROM_TIME || |
714 |
abstime > gl[index].TO_TIME || |
715 |
false ){ |
716 |
|
717 |
if(TrkParams::VerboseMode()) |
718 |
cout << "<< set TrkParams type "<<type<<" from DB << RUN "<<runid<<endl; |
719 |
|
720 |
bool LOCAL_CONNECTION = false; |
721 |
if( !dbc || (dbc && !dbc->IsConnected()) ){ |
722 |
|
723 |
// if(TrkParams::WarningMode())cout <<" Missing DB connection -- check PAMELA environment variables "<<endl; |
724 |
dbc = TrkParams::SetDBConnection(); |
725 |
if(dbc && dbc->IsConnected())LOCAL_CONNECTION = true; |
726 |
|
727 |
} |
728 |
|
729 |
GL_PARAM q4; |
730 |
// if( q4.Query_GL_PARAM(runheadtime,type,dbc) )return false; |
731 |
if( q4.Query_GL_PARAM(abstime,type,dbc) )return false; //VALERIO |
732 |
if(LOCAL_CONNECTION){ |
733 |
dbc->Close(); |
734 |
delete dbc; |
735 |
if(TrkParams::DebugMode()){ |
736 |
cout << " DB connection closed."<<endl; |
737 |
} |
738 |
} |
739 |
gl[index] = q4; |
740 |
glpath[index] = q4.PATH+q4.NAME; |
741 |
glload[index] = false; |
742 |
|
743 |
//return true; |
744 |
|
745 |
} |
746 |
return true; |
747 |
|
748 |
}; |
749 |
/** |
750 |
* Set tracker parameters proper for the run, from input. |
751 |
* @param path Path to parameters directory |
752 |
* @param type Parameter type |
753 |
* @return FALSE if parameter set fails. |
754 |
*/ |
755 |
Bool_t TrkParams::Set( TString path , UInt_t type){ |
756 |
|
757 |
UInt_t index = TrkParams::GetIndex( type ); |
758 |
if(index < 0)return false; |
759 |
|
760 |
gl[index].TYPE= type; |
761 |
glpath[index] = path; |
762 |
if(TrkParams::VerboseMode()) |
763 |
cout << "<< set TrkParams type "<<type<<" from path << "<<path<<endl; |
764 |
glload[index] = false; |
765 |
|
766 |
// return TrkParams::Load(type); |
767 |
return true; |
768 |
|
769 |
}; |
770 |
|
771 |
/** |
772 |
* Set and load tracker parameters. |
773 |
* @param type Parameter type |
774 |
* If no path as been yet specified, it set a default path. |
775 |
* @return FALSE if parameter set fails. |
776 |
*/ |
777 |
Bool_t TrkParams::Set(UInt_t type){ |
778 |
|
779 |
|
780 |
return Set(0,0,type); |
781 |
|
782 |
|
783 |
}; |
784 |
/** |
785 |
* Set tracker parameters. |
786 |
* If no path as been yet specified, try to read from DB |
787 |
* otherwise it set a default path. |
788 |
* @return FALSE if parameter set fails. |
789 |
*/ |
790 |
|
791 |
Bool_t TrkParams::Set( ){ |
792 |
|
793 |
|
794 |
for(Int_t i=0; i<NTYPES; i++)if ( !TrkParams::Set(trkparamtype[i])) return false; |
795 |
|
796 |
return true; |
797 |
} |
798 |
|
799 |
/** |
800 |
* Load tracker parameter, if not already loaded. |
801 |
* @param type Parameter type |
802 |
* ( Any call to TrkParams::Set(...) forces reloading ) |
803 |
*/ |
804 |
Bool_t TrkParams::Load(UInt_t type){ |
805 |
|
806 |
Int_t index = TrkParams::GetIndex( type ); |
807 |
if( index<0 )return false; |
808 |
if( glload[index] )return false; |
809 |
if( glpath[index].IsNull() )TrkParams::Set(type); |
810 |
|
811 |
switch( type ){ |
812 |
//------------------------------------------ |
813 |
case 1: |
814 |
if(TrkParams::VerboseMode())cout <<type<<" -- Loading magnetic field "<<glpath[index]<<endl; |
815 |
strcpy(path_.path,glpath[index].Data()); |
816 |
path_.pathlen = glpath[index].Length(); |
817 |
path_.error = 0; |
818 |
readb_(); |
819 |
if(path_.error) return false; |
820 |
glload[index]=true; |
821 |
break; |
822 |
//------------------------------------------ |
823 |
case 2: |
824 |
if(TrkParams::VerboseMode())cout <<type<<" -- Loading ADC-to-MIP conversion parameters "<<glpath[index]<<endl; |
825 |
strcpy(path_.path,glpath[index].Data()); |
826 |
path_.pathlen = glpath[index].Length(); |
827 |
path_.error = 0; |
828 |
readmipparam_(); |
829 |
if(path_.error) return false; |
830 |
glload[index]=true; |
831 |
break; |
832 |
//------------------------------------------ |
833 |
case 3: |
834 |
if(TrkParams::VerboseMode())cout <<type<<" -- Loading charge-correlation parameters "<<glpath[index]<<endl; |
835 |
strcpy(path_.path,glpath[index].Data()); |
836 |
path_.pathlen = glpath[index].Length(); |
837 |
path_.error = 0; |
838 |
readchargeparam_(); |
839 |
if(path_.error) return false; |
840 |
glload[index]=true; |
841 |
break; |
842 |
//------------------------------------------ |
843 |
case 4: |
844 |
if(TrkParams::VerboseMode())cout <<type<<" -- Loading p.f.a. parameters "<<glpath[index]<<endl; |
845 |
strcpy(path_.path,glpath[index].Data()); |
846 |
path_.pathlen = glpath[index].Length(); |
847 |
path_.error = 0; |
848 |
readetaparam_(); |
849 |
if(path_.error) return false; |
850 |
glload[index]=true; |
851 |
break; |
852 |
//------------------------------------------ |
853 |
case 5: |
854 |
if(TrkParams::VerboseMode())cout <<type<<" -- Loading alignment parameters "<<glpath[index]<<endl; |
855 |
strcpy(path_.path,glpath[index].Data()); |
856 |
path_.pathlen = glpath[index].Length(); |
857 |
path_.error = 0; |
858 |
readalignparam_(); |
859 |
if(path_.error) return false; |
860 |
glload[index]=true; |
861 |
break; |
862 |
//------------------------------------------ |
863 |
case 6: |
864 |
if(TrkParams::VerboseMode())cout <<type<<" -- Loading VK-mask parameters "<<glpath[index]<<endl; |
865 |
strcpy(path_.path,glpath[index].Data()); |
866 |
path_.pathlen = glpath[index].Length(); |
867 |
path_.error = 0; |
868 |
readvkmask_(); |
869 |
if(path_.error) return false; |
870 |
glload[index]=true; |
871 |
break; |
872 |
//------------------------------------------ |
873 |
case 7: |
874 |
if(TrkParams::VerboseMode())cout <<type<<" -- Loading default calibration "<<glpath[index]<<endl; |
875 |
strcpy(path_.path,glpath[index].Data()); |
876 |
path_.pathlen = glpath[index].Length(); |
877 |
path_.error = 0; |
878 |
// fillpedsigfromdefault_(); |
879 |
if(TrkParams::VerboseMode())cout << ">> not implemented <<"<<endl; |
880 |
if(path_.error) return false; |
881 |
glload[index]=true; |
882 |
break; |
883 |
default: |
884 |
if(TrkParams::VerboseMode())cout << " Bool_t TrkParams::Load(UInt_t type) -- type "<< type << "not yet implemented"<<endl; |
885 |
return false; |
886 |
}; |
887 |
|
888 |
return true; |
889 |
} |
890 |
|
891 |
Bool_t TrkParams::Load( ){ |
892 |
Bool_t result = true; |
893 |
for(Int_t i=0 ; i<NTYPES; i++) |
894 |
if(!glload[i] && trkparamtype[i]>0 ) |
895 |
if( !TrkParams::Load(trkparamtype[i]) ) |
896 |
result = false; |
897 |
return result; |
898 |
}; |
899 |
Bool_t TrkParams::IsLoaded( ){ |
900 |
for(Int_t i=0 ; i<NTYPES; i++)if(!glload[i] && trkparamtype[i]>0 )return false; |
901 |
return true; |
902 |
}; |
903 |
|
904 |
/** |
905 |
* Get ADC-to-MIP conversion parameters |
906 |
* @param nl ladder number (0-2) |
907 |
* @param nv view number (0-11) |
908 |
*/ |
909 |
float TrkParams::GetMIP(int nl, int nv){ |
910 |
TrkParams::Load(2); |
911 |
if( !TrkParams::IsLoaded(2) )return 0.; |
912 |
return adc2mip_.mip[nl][nv]; |
913 |
} |
914 |
|
915 |
/** |
916 |
* Get BY (kGauss) |
917 |
* @param v (x,y,z) coordinates in cm |
918 |
*/ |
919 |
float TrkParams::GetBX(float* v){ |
920 |
TrkParams::Load(1); |
921 |
if( !TrkParams::IsLoaded(1) )return 0.; |
922 |
float b[3]; |
923 |
gufld_(v,b); |
924 |
return b[0]/10.; |
925 |
} |
926 |
/** |
927 |
* Get BY (kGauss) |
928 |
* @param v (x,y,z) coordinates in cm |
929 |
*/ |
930 |
float TrkParams::GetBY(float* v){ |
931 |
TrkParams::Load(1); |
932 |
if( !TrkParams::IsLoaded(1) )return 0.; |
933 |
float b[3]; |
934 |
gufld_(v,b); |
935 |
return b[1]/10.; |
936 |
} |
937 |
/** |
938 |
* Get BY (kGauss) |
939 |
* @param v (x,y,z) coordinates in cm |
940 |
*/ |
941 |
float TrkParams::GetBZ(float* v){ |
942 |
TrkParams::Load(1); |
943 |
if( !TrkParams::IsLoaded(1) )return 0.; |
944 |
float b[3]; |
945 |
gufld_(v,b); |
946 |
return b[2]/10.; |
947 |
} |
948 |
|
949 |
|
950 |
/** |
951 |
* \brief Set tracking mode (0=standard. 1=???) |
952 |
*/ |
953 |
void TrkParams::SetTrackingMode(int trackmode) { |
954 |
init__mini_trackmode = trackmode; |
955 |
SetTrackingMode(); //fill F77 common |
956 |
}; |
957 |
/** |
958 |
* \brief Set fit-precision factor (typical value fact=100.) |
959 |
*/ |
960 |
void TrkParams::SetPrecisionFactor(double fact){ |
961 |
init__mini_fact = fact; |
962 |
SetPrecisionFactor(); //fill F77 common |
963 |
}; |
964 |
/** |
965 |
* \brief Set minimum number of step in track fitting |
966 |
*/ |
967 |
void TrkParams::SetStepMin(int istepmin){ |
968 |
init__mini_istepmin = istepmin; |
969 |
SetStepMin(); //fill F77 common |
970 |
}; |
971 |
/** |
972 |
* \brief Set deltaB parameters (id=0,1) |
973 |
*/ |
974 |
void TrkParams::SetDeltaB(int id,double db){ |
975 |
if(id!=0 && id!=1)cout << "void TrkParams::SetDeltaB(int id,double db) -- wrong input parameters: "<<id<<" "<<db<<endl; |
976 |
if(id==0)init__deltab_0 = db; |
977 |
if(id==1)init__deltab_1 = db; |
978 |
SetDeltaB(); //fill F77 common |
979 |
}; |
980 |
/** |
981 |
* \brief Set DLT-grkuta precision factor (default 1.e-4) |
982 |
*/ |
983 |
void TrkParams::SetDLT(double fact){ |
984 |
init__dlt = fact; |
985 |
SetDLT(); //fill F77 common |
986 |
}; |
987 |
|
988 |
/** |
989 |
* \brief Fill F77 commons with PFA settings |
990 |
*/ |
991 |
void TrkParams::SetPFA(){ |
992 |
sw_.pfaid = init__pfa; |
993 |
for(int i=0; i<6; i++){ |
994 |
pfa_.e234ax[i] = init__pfa_e234ax[i]; |
995 |
pfa_.e234ay[i] = init__pfa_e234ay[i]; |
996 |
} |
997 |
}; |
998 |
/** |
999 |
* \brief Set p.f.a. |
1000 |
* |
1001 |
* Implemented algorythms: |
1002 |
* 0 ETA |
1003 |
* 1 --- |
1004 |
* 2 ETA2 |
1005 |
* 3 ETA3 |
1006 |
* 4 ETA4 |
1007 |
* 5 ETAL ==> ETA+LANDI |
1008 |
* 10 COG |
1009 |
* 11 COG1 |
1010 |
* 12 COG2 |
1011 |
* 13 COG3 |
1012 |
* 14 COG4 |
1013 |
*/ |
1014 |
void TrkParams::SetPFA(int pfaid){ |
1015 |
init__pfa = pfaid; |
1016 |
SetPFA(); //fill F77 common |
1017 |
}; |
1018 |
/** |
1019 |
* \brief Set p.f.a. angular intervals |
1020 |
* |
1021 |
* This methods allows to set amgular intervals to apply ETA2,ETA3 or ETA4 |
1022 |
* algorythm, in case ETA or ETAL is set (see TrkParams::SetPFA(int pfaid)). |
1023 |
* @param v Pointer to a vector of 12 components, which represent the |
1024 |
* angular limits for ETA2,ETA3 and ETA4, for x and y views, respectivelly. |
1025 |
* |
1026 |
*/ |
1027 |
void TrkParams::SetPFA(float *v){ |
1028 |
for(int i=0; i<6; i++){ |
1029 |
init__pfa_e234ax[i] = v[i]; |
1030 |
init__pfa_e234ay[i] = v[i+6]; |
1031 |
} |
1032 |
SetPFA(); //fill F77 common |
1033 |
}; |
1034 |
|
1035 |
|
1036 |
/** |
1037 |
* \brief Get spatial resolution. |
1038 |
* |
1039 |
* Method to retrieve the spatial resolution associated with the |
1040 |
* adopted p.f.a. |
1041 |
* @param view Tracker view (1-12) |
1042 |
* @param angle Track projected angle |
1043 |
* |
1044 |
* In order to change p.f.a. use the SetPFA(int pfaid) method, eg.: |
1045 |
* |
1046 |
* TrkParams::SetPFA(0) // ETA |
1047 |
* |
1048 |
*/ |
1049 |
float TrkParams::GetResolution(int view, float angle){ |
1050 |
float res = 1000; |
1051 |
if ( init__pfa == 0 )res = riseta_(&view,&angle); |
1052 |
else if( init__pfa == 5 )res = riseta_(&view,&angle); |
1053 |
else cout << "float TrkParams::GetResolution(int view, float angle) -- PFA "<<init__pfa<<" not yet implemented"<<endl; |
1054 |
return res; |
1055 |
} |
1056 |
|
1057 |
/** |
1058 |
* Returns the number of angular bins for p.f.a. parameters |
1059 |
*/ |
1060 |
int TrkParams::GetPFA_NbinsAngle(){ |
1061 |
TrkParams::Load(4); |
1062 |
if( !TrkParams::IsLoaded(4) ){ |
1063 |
cout << "int TrkParams::GetPFA_NbinsAngle() --- ERROR --- p.f.a. parameters not loaded"<<endl; |
1064 |
return 0; |
1065 |
} |
1066 |
return pfa_.nangbin; |
1067 |
}; |
1068 |
/** |
1069 |
* Returns the number of eta bins for p.f.a. parameters |
1070 |
*/ |
1071 |
int TrkParams::GetPFA_NbinsETA(){ |
1072 |
TrkParams::Load(4); |
1073 |
if( !TrkParams::IsLoaded(4) ){ |
1074 |
cout << "int TrkParams::GetPFA_NbinsETA() --- ERROR --- p.f.a. parameters not loaded"<<endl; |
1075 |
return 0; |
1076 |
} |
1077 |
return pfa_.netaval; |
1078 |
}; |
1079 |
|
1080 |
/** |
1081 |
* Returns the pointer to a vector ( of size TrkParams::GetPFA_NbinsETA() ), |
1082 |
* with eta-correction values for each eta bin. |
1083 |
* Bin extremes are given by float* TrkParams::GetPFA_ETAabs(pfa,int). |
1084 |
* |
1085 |
* @param pfa "ETA2","ETA3" or "ETA4" |
1086 |
* @param nview View number (0-11) |
1087 |
* @param nladder Ladder number (0-2) |
1088 |
* @param nang Angular bin (@see int TrkParams::GetPFA_NbinsAngle()). |
1089 |
* |
1090 |
* NB! the vector must be deallocated! |
1091 |
* delete [] vname; |
1092 |
*/ |
1093 |
float* TrkParams::GetPFA_ETAcorr(TString pfa, int nview, int nladder, int nang){ |
1094 |
|
1095 |
TrkParams::Load(4); |
1096 |
if( !TrkParams::IsLoaded(4) ){ |
1097 |
cout << "float* TrkParams::GetPFA_ETAcorr(TString pfa, int nview, int nladder, int nang) --- ERROR --- p.f.a. parameters not loaded"<<endl; |
1098 |
return 0; |
1099 |
} |
1100 |
|
1101 |
int nbins = GetPFA_NbinsETA(); |
1102 |
if(!nbins)return 0; |
1103 |
|
1104 |
if( nview < 0 || |
1105 |
nview >= 12 || |
1106 |
nladder < 0 || |
1107 |
nladder >= 3 || |
1108 |
nang < 0 || |
1109 |
nang >= GetPFA_NbinsAngle() || |
1110 |
false)return 0; |
1111 |
|
1112 |
float *fcorr = new float [nbins]; |
1113 |
// float fcorr[nbins]; |
1114 |
|
1115 |
if(!pfa.CompareTo("ETA2",TString::kIgnoreCase)){ |
1116 |
for(int ib=0; ib<nbins; ib++){ |
1117 |
fcorr[ib] = pfa_.feta2[nang][nladder][nview][ib]; |
1118 |
// cout << pfa_.eta2[nang][ib] << " - " << pfa_.feta2[nang][nladder][nview][ib]<<endl;; |
1119 |
} |
1120 |
}else if (!pfa.CompareTo("ETA3",TString::kIgnoreCase)){ |
1121 |
for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.feta3[nang][nladder][nview][ib]; |
1122 |
}else if (!pfa.CompareTo("ETA4",TString::kIgnoreCase)){ |
1123 |
for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.feta4[nang][nladder][nview][ib]; |
1124 |
}else{ |
1125 |
cout << "float* TrkParams::GetPFA_ETAcorr("<<pfa<<",...) --- pfa parameters not implemented "<<endl; |
1126 |
return 0; |
1127 |
} |
1128 |
|
1129 |
return fcorr; |
1130 |
|
1131 |
}; |
1132 |
|
1133 |
/** |
1134 |
* Returns the pointer to a vector with eta-bin extremes (@see float* TrkParams::GetPFA_ETAcorr(TString,int,int,int)). |
1135 |
* |
1136 |
* @param pfa "ETA2","ETA3" or "ETA4" |
1137 |
* @param nang Angular bin (@see int TrkParams::GetPFA_NbinsAngle()). |
1138 |
* |
1139 |
* NB the vector must be deallocated |
1140 |
* delete [] vname; |
1141 |
*/ |
1142 |
float* TrkParams::GetPFA_ETAabs(TString pfa, int nang){ |
1143 |
|
1144 |
TrkParams::Load(4); |
1145 |
if( !TrkParams::IsLoaded(4) ){ |
1146 |
cout << "float* TrkParams::GetPFA_ETAabs(TString pfa, int nang) --- ERROR --- p.f.a. parameters not loaded"<<endl; |
1147 |
return 0; |
1148 |
} |
1149 |
|
1150 |
int nbins = GetPFA_NbinsETA(); |
1151 |
if(!nbins)return 0; |
1152 |
|
1153 |
float *fcorr = new float [nbins]; |
1154 |
// float fcorr[nbins]; |
1155 |
if( nang < 0 || |
1156 |
nang >= GetPFA_NbinsAngle() || |
1157 |
false)return 0; |
1158 |
|
1159 |
if(!pfa.CompareTo("ETA2",TString::kIgnoreCase)){ |
1160 |
for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta2[nang][ib]; |
1161 |
}else if (!pfa.CompareTo("ETA3",TString::kIgnoreCase)){ |
1162 |
for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta3[nang][ib]; |
1163 |
}else if (!pfa.CompareTo("ETA4",TString::kIgnoreCase)){ |
1164 |
for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta4[nang][ib]; |
1165 |
}else{ |
1166 |
cout << "float* TrkParams::GetPFA_ETAabs("<<pfa<<",...) --- pfa parameters not implemented "<<endl; |
1167 |
return 0; |
1168 |
} |
1169 |
|
1170 |
return fcorr; |
1171 |
|
1172 |
}; |
1173 |
/** |
1174 |
* Returns the "Landi-correction". |
1175 |
* |
1176 |
* @param nview View number (0-11) |
1177 |
* @param nladder Ladder number (0-2) |
1178 |
* @param nang Angular bin (@see int TrkParams::GetPFA_NbinsAngle()). |
1179 |
*/ |
1180 |
float TrkParams::GetPFA_ETAlandi(int nview, int nladder, int nang){ |
1181 |
|
1182 |
// TrkParams::Load(4); |
1183 |
// if( !TrkParams::IsLoaded(4) ){ |
1184 |
// cout << "float* TrkParams::GetPFA_ETAlandi(int nview, int nladder, int nang) --- ERROR --- p.f.a. parameters not loaded"<<endl; |
1185 |
// return 0; |
1186 |
// } |
1187 |
int nbins = GetPFA_NbinsAngle(); |
1188 |
if(!nbins)return 0; |
1189 |
|
1190 |
if( nview < 0 || |
1191 |
nview >= 12 || |
1192 |
nladder < 0 || |
1193 |
nladder >= 3 || |
1194 |
nang < 0 || |
1195 |
nang >= nbins || |
1196 |
false)return 0; |
1197 |
|
1198 |
|
1199 |
return pfa_.fcorr[nang][nladder][nview]; |
1200 |
|
1201 |
}; |
1202 |
|
1203 |
/** |
1204 |
* Returns the index (0, n.bin-1) of the angular bin for pfa parameters |
1205 |
* @param angle Effective angle (deg) |
1206 |
*/ |
1207 |
int TrkParams::GetPFA_AngleBin(float angle){ |
1208 |
|
1209 |
int nangbin = TrkParams::GetPFA_NbinsAngle(); |
1210 |
int istart = (int)(nangbin/2); |
1211 |
int idbin = -1; |
1212 |
// cout << angle <<" ??" << endl; |
1213 |
if( angle > pfa_.angR[istart] ){ |
1214 |
idbin = nangbin-1; |
1215 |
for(int id=istart+1; id<nangbin; id++ ){ |
1216 |
// cout << id << endl; |
1217 |
if( pfa_.angR[id] >= angle ){ |
1218 |
idbin = id; |
1219 |
break; |
1220 |
} |
1221 |
} |
1222 |
}else{ |
1223 |
idbin = 0; |
1224 |
for(int id=istart; id>=0; id-- ){ |
1225 |
// cout << id << endl; |
1226 |
if( pfa_.angL[id] < angle ){ |
1227 |
idbin = id; |
1228 |
break; |
1229 |
} |
1230 |
} |
1231 |
|
1232 |
} |
1233 |
// cout << ">>> "<<idbin<<" "<<pfa_.angL[idbin]<<" "<<pfa_.angR[idbin]<<endl; |
1234 |
return idbin; |
1235 |
} |
1236 |
|
1237 |
|
1238 |
|
1239 |
ClassImp(TrkParams); |