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