1 |
/** |
2 |
* \file TrkLevel2.cpp |
3 |
* \author Elena Vannuccini |
4 |
*/ |
5 |
#include <TrkLevel2.h> |
6 |
#include <iostream> |
7 |
using namespace std; |
8 |
//...................................... |
9 |
// F77 routines |
10 |
//...................................... |
11 |
extern "C" { |
12 |
void dotrack_(int*, double*, double*, double*, double*, int*); |
13 |
int readb_(const char*); |
14 |
} |
15 |
//-------------------------------------- |
16 |
// |
17 |
// |
18 |
//-------------------------------------- |
19 |
TrkTrack::TrkTrack(){ |
20 |
image = 0; |
21 |
chi2 = 0; |
22 |
for(int it1=0;it1<5;it1++){ |
23 |
al[it1] = 0; |
24 |
for(int it2=0;it2<5;it2++) |
25 |
coval[it1][it2] = 0; |
26 |
}; |
27 |
for(int ip=0;ip<6;ip++){ |
28 |
xgood[ip] = 0; |
29 |
ygood[ip] = 0; |
30 |
xm[ip] = 0; |
31 |
ym[ip] = 0; |
32 |
zm[ip] = 0; |
33 |
resx[ip] = 0; |
34 |
resy[ip] = 0; |
35 |
xv[ip] = 0; |
36 |
yv[ip] = 0; |
37 |
zv[ip] = 0; |
38 |
axv[ip] = 0; |
39 |
ayv[ip] = 0; |
40 |
dedx_x[ip] = 0; |
41 |
dedx_y[ip] = 0; |
42 |
}; |
43 |
}; |
44 |
//-------------------------------------- |
45 |
// |
46 |
// |
47 |
//-------------------------------------- |
48 |
TrkTrack::TrkTrack(const TrkTrack& t){ |
49 |
image = t.image; |
50 |
chi2 = t.chi2; |
51 |
for(int it1=0;it1<5;it1++){ |
52 |
al[it1] = t.al[it1]; |
53 |
for(int it2=0;it2<5;it2++) |
54 |
coval[it1][it2] = t.coval[it1][it2]; |
55 |
}; |
56 |
for(int ip=0;ip<6;ip++){ |
57 |
xgood[ip] = t.xgood[ip]; |
58 |
ygood[ip] = t.ygood[ip]; |
59 |
xm[ip] = t.xm[ip]; |
60 |
ym[ip] = t.ym[ip]; |
61 |
zm[ip] = t.zm[ip]; |
62 |
resx[ip] = t.resx[ip]; |
63 |
resy[ip] = t.resy[ip]; |
64 |
xv[ip] = t.xv[ip]; |
65 |
yv[ip] = t.yv[ip]; |
66 |
zv[ip] = t.zv[ip]; |
67 |
axv[ip] = t.axv[ip]; |
68 |
ayv[ip] = t.ayv[ip]; |
69 |
dedx_x[ip] = t.dedx_x[ip]; |
70 |
dedx_y[ip] = t.dedx_y[ip]; |
71 |
}; |
72 |
}; |
73 |
//-------------------------------------- |
74 |
// |
75 |
// |
76 |
//-------------------------------------- |
77 |
/** |
78 |
* Evaluates the trajectory in the apparatus associated to the track. |
79 |
* It integrates the equations of motion in the magnetic field. The magnetic field should be previously loaded ( by calling TrkLevel2::LoadField() ), otherwise an error message is returned. |
80 |
* @param t pointer to an object of the class Trajectory, |
81 |
* which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). |
82 |
* @return error flag. |
83 |
*/ |
84 |
int TrkTrack::DoTrack(Trajectory* t){ |
85 |
|
86 |
double *dxout = new double[t->npoint]; |
87 |
double *dyout = new double[t->npoint]; |
88 |
double *dzin = new double[t->npoint]; |
89 |
double dal[5]; |
90 |
|
91 |
int ifail = 0; |
92 |
|
93 |
for (int i=0; i<5; i++) dal[i] = (double)al[i]; |
94 |
for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i]; |
95 |
|
96 |
dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail); |
97 |
|
98 |
for (int i=0; i<t->npoint; i++){ |
99 |
t->x[i] = (float)*dxout++; |
100 |
t->y[i] = (float)*dyout++; |
101 |
} |
102 |
|
103 |
// delete [] dxout; |
104 |
// delete [] dyout; |
105 |
// delete [] dzin; |
106 |
|
107 |
return ifail; |
108 |
}; |
109 |
//-------------------------------------- |
110 |
// |
111 |
// |
112 |
//-------------------------------------- |
113 |
//float TrkTrack::BdL(){ |
114 |
//}; |
115 |
//-------------------------------------- |
116 |
// |
117 |
// |
118 |
//-------------------------------------- |
119 |
Float_t TrkTrack::GetRigidity(){ |
120 |
Float_t rig=0; |
121 |
if(chi2>0)rig=1./al[4]; |
122 |
if(rig<0) rig=-rig; |
123 |
return rig; |
124 |
}; |
125 |
// |
126 |
Float_t TrkTrack::GetDeflection(){ |
127 |
Float_t def=0; |
128 |
if(chi2>0)def=al[4]; |
129 |
return def; |
130 |
}; |
131 |
// |
132 |
Float_t TrkTrack::GetDEDX(){ |
133 |
Float_t dedx=0; |
134 |
for(Int_t i=0; i<6; i++)dedx+=dedx_x[i]*xgood[i]+dedx_y[i]*ygood[i]; |
135 |
dedx = dedx/(this->GetNX()+this->GetNY()); |
136 |
return dedx; |
137 |
}; |
138 |
|
139 |
//-------------------------------------- |
140 |
// |
141 |
// |
142 |
//-------------------------------------- |
143 |
void TrkTrack::Dump(){ |
144 |
cout << endl << "========== Track " ; |
145 |
cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " "; |
146 |
cout << endl << "chi^2 : "<< chi2; |
147 |
cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << xgood[i] ; |
148 |
cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << ygood[i] ; |
149 |
cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " "; |
150 |
cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " "; |
151 |
cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " "; |
152 |
cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " "; |
153 |
cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " "; |
154 |
} |
155 |
//-------------------------------------- |
156 |
// |
157 |
// |
158 |
//-------------------------------------- |
159 |
TrkSinglet::TrkSinglet(){ |
160 |
plane = 0; |
161 |
coord[0] = 0; |
162 |
coord[1] = 0; |
163 |
sgnl = 0; |
164 |
}; |
165 |
//-------------------------------------- |
166 |
// |
167 |
// |
168 |
//-------------------------------------- |
169 |
TrkSinglet::TrkSinglet(const TrkSinglet& s){ |
170 |
plane = s.plane; |
171 |
coord[0] = s.coord[0]; |
172 |
coord[1] = s.coord[1]; |
173 |
sgnl = s.sgnl; |
174 |
}; |
175 |
//-------------------------------------- |
176 |
// |
177 |
// |
178 |
//-------------------------------------- |
179 |
void TrkSinglet::Dump(){ |
180 |
int i=0; |
181 |
cout << endl << "========== Singlet " ; |
182 |
cout << endl << "plane : " << plane; |
183 |
cout << endl << "coord[2] : "; while( i<2 && cout << coord[i] << " ") i++; |
184 |
cout << endl << "sgnl : " << sgnl; |
185 |
} |
186 |
//-------------------------------------- |
187 |
// |
188 |
// |
189 |
//-------------------------------------- |
190 |
TrkLevel2::TrkLevel2(){ |
191 |
good2 = -1; |
192 |
for(Int_t i=0; i<12 ; i++){ |
193 |
crc[i] = -1; |
194 |
}; |
195 |
Track = new TClonesArray("TrkTrack"); |
196 |
SingletX = new TClonesArray("TrkSinglet"); |
197 |
SingletY = new TClonesArray("TrkSinglet"); |
198 |
} |
199 |
//-------------------------------------- |
200 |
// |
201 |
// |
202 |
//-------------------------------------- |
203 |
void TrkLevel2::Dump(){ |
204 |
TClonesArray &t = *Track; |
205 |
TClonesArray &sx = *SingletX; |
206 |
TClonesArray &sy = *SingletY; |
207 |
|
208 |
cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"; |
209 |
cout << endl << "good2 : " << good2; |
210 |
cout << endl << "crc : "; for(int i=0; i<12; i++) cout << crc[i]; |
211 |
cout << endl << "ntrk() : " << this->ntrk() ; |
212 |
cout << endl << "nclsx() : " << this->nclsx(); |
213 |
cout << endl << "nclsy() : " << this->nclsy(); |
214 |
for(int i=0; i<this->ntrk(); i++) ((TrkTrack *)t[i])->Dump(); |
215 |
for(int i=0; i<this->nclsx(); i++) ((TrkSinglet *)sx[i])->Dump(); |
216 |
for(int i=0; i<this->nclsy(); i++) ((TrkSinglet *)sy[i])->Dump(); |
217 |
} |
218 |
//-------------------------------------- |
219 |
// |
220 |
// |
221 |
//-------------------------------------- |
222 |
/** |
223 |
* Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). |
224 |
*/ |
225 |
void TrkLevel2::FillCommonVar(cTrkLevel2 *l2){ |
226 |
// temporary objects: |
227 |
TrkSinglet* t_singlet = new TrkSinglet(); |
228 |
TrkTrack* t_track = new TrkTrack(); |
229 |
// general variables |
230 |
good2 = l2->good2; |
231 |
for(Int_t i=0; i<12 ; i++){ |
232 |
crc[i] = l2->crc[i]; |
233 |
}; |
234 |
// *** TRACKS *** |
235 |
TClonesArray &t = *Track; |
236 |
for(int i=0; i<l2->ntrk; i++){ |
237 |
t_track->image = l2->image[i]-1; |
238 |
t_track->chi2 = l2->chi2_nt[i]; |
239 |
for(int it1=0;it1<5;it1++){ |
240 |
t_track->al[it1] = l2->al_nt[i][it1]; |
241 |
for(int it2=0;it2<5;it2++) |
242 |
t_track->coval[it1][it2] = l2->coval[i][it2][it1]; |
243 |
}; |
244 |
for(int ip=0;ip<6;ip++){ |
245 |
t_track->xgood[ip] = l2->xgood_nt[i][ip]; |
246 |
t_track->ygood[ip] = l2->ygood_nt[i][ip]; |
247 |
t_track->xm[ip] = l2->xm_nt[i][ip]; |
248 |
t_track->ym[ip] = l2->ym_nt[i][ip]; |
249 |
t_track->zm[ip] = l2->zm_nt[i][ip]; |
250 |
t_track->resx[ip] = l2->resx_nt[i][ip]; |
251 |
t_track->resy[ip] = l2->resy_nt[i][ip]; |
252 |
t_track->xv[ip] = l2->xv_nt[i][ip]; |
253 |
t_track->yv[ip] = l2->yv_nt[i][ip]; |
254 |
t_track->zv[ip] = l2->zv_nt[i][ip]; |
255 |
t_track->axv[ip] = l2->axv_nt[i][ip]; |
256 |
t_track->ayv[ip] = l2->ayv_nt[i][ip]; |
257 |
t_track->dedx_x[ip] = l2->dedx_x[i][ip]; |
258 |
t_track->dedx_y[ip] = l2->dedx_y[i][ip]; |
259 |
}; |
260 |
new(t[i]) TrkTrack(*t_track); |
261 |
t_track->Clear(); |
262 |
}; |
263 |
// *** SINGLETS *** |
264 |
TClonesArray &sx = *SingletX; |
265 |
for(int i=0; i<l2->nclsx; i++){ |
266 |
t_singlet->plane = l2->planex[i]; |
267 |
t_singlet->coord[0] = l2->xs[i][0]; |
268 |
t_singlet->coord[1] = l2->xs[i][1]; |
269 |
t_singlet->sgnl = l2->signlxs[i]; |
270 |
new(sx[i]) TrkSinglet(*t_singlet); |
271 |
t_singlet->Clear(); |
272 |
} |
273 |
TClonesArray &sy = *SingletY; |
274 |
for(int i=0; i<l2->nclsy; i++){ |
275 |
t_singlet->plane = l2->planey[i]; |
276 |
t_singlet->coord[0] = l2->ys[i][0]; |
277 |
t_singlet->coord[1] = l2->ys[i][1]; |
278 |
t_singlet->sgnl = l2->signlys[i]; |
279 |
new(sy[i]) TrkSinglet(*t_singlet); |
280 |
t_singlet->Clear(); |
281 |
}; |
282 |
} |
283 |
//-------------------------------------- |
284 |
// |
285 |
// |
286 |
//-------------------------------------- |
287 |
void TrkLevel2::Clear(){ |
288 |
good2 = -1; |
289 |
for(Int_t i=0; i<12 ; i++){ |
290 |
crc[i] = -1; |
291 |
}; |
292 |
Track->RemoveAll(); |
293 |
SingletX->RemoveAll(); |
294 |
SingletY->RemoveAll(); |
295 |
} |
296 |
//-------------------------------------- |
297 |
// |
298 |
// |
299 |
//-------------------------------------- |
300 |
/** |
301 |
* Sort physical tracks and stores them in a TObjectArray, ordering by increasing chi**2 value (in case of track image, it selects the one with lower chi**2). The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it). |
302 |
* This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used. |
303 |
*/ |
304 |
TClonesArray *TrkLevel2::GetTracks(){ |
305 |
|
306 |
TClonesArray *sorted = new TClonesArray("TrkTrack"); |
307 |
TClonesArray &t = *Track; |
308 |
TClonesArray &ts = *sorted; |
309 |
int N=this->ntrk(); |
310 |
vector<int> m(N); for(int i=0; i<N; i++)m[i]=1; |
311 |
|
312 |
int indo=0; |
313 |
int indi=0; |
314 |
while(N != 0){ |
315 |
float chi2ref=1000000; |
316 |
for(int i=0; i<this->ntrk(); i++){ |
317 |
if(((TrkTrack *)t[i])->chi2 < chi2ref && m[i]==1){ |
318 |
chi2ref = ((TrkTrack *)t[i])->chi2; |
319 |
indi = i; |
320 |
} |
321 |
} |
322 |
if( ((TrkTrack *)t[indi])->image != -1 ){ |
323 |
m[((TrkTrack *)t[indi])->image] = 0; |
324 |
N--; |
325 |
} |
326 |
new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]); |
327 |
m[indi] = 0; |
328 |
N--; |
329 |
indo++; |
330 |
} |
331 |
return sorted; |
332 |
} |
333 |
//-------------------------------------- |
334 |
// |
335 |
// |
336 |
//-------------------------------------- |
337 |
/** |
338 |
* Retrieves the is-th stored track. |
339 |
* @param it Track number, ranging from 0 to ntrk(). |
340 |
* Fitted tracks ( images included ) are stored in a TObjectArray ( TrkLevel2::Track ) in the same order they are returned by the F77 fitting routine. |
341 |
*/ |
342 |
TrkTrack *TrkLevel2::GetStoredTrack(int is){ |
343 |
|
344 |
if(is >= this->ntrk()){ |
345 |
cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl; |
346 |
cout << " Stored tracks ntrk() = "<< this->ntrk() << endl; |
347 |
return 0; |
348 |
} |
349 |
TClonesArray &t = *(Track); |
350 |
TrkTrack *track = (TrkTrack*)t[is]; |
351 |
return track; |
352 |
} |
353 |
//-------------------------------------- |
354 |
// |
355 |
// |
356 |
//-------------------------------------- |
357 |
/** |
358 |
* Retrieves the it-th "physical" track, sorted by the method GetNTracks(). |
359 |
* @param it Track number, ranging from 0 to GetNTracks(). |
360 |
*/ |
361 |
TrkTrack *TrkLevel2::GetTrack(int it){ |
362 |
|
363 |
if(it >= this->GetNTracks()){ |
364 |
cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; |
365 |
cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl; |
366 |
return 0; |
367 |
} |
368 |
TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it]; |
369 |
return track; |
370 |
} |
371 |
//-------------------------------------- |
372 |
// |
373 |
// |
374 |
//-------------------------------------- |
375 |
/** |
376 |
* Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks(). |
377 |
* @param it Track number, ranging from 0 to GetNTracks(). |
378 |
*/ |
379 |
TrkTrack *TrkLevel2::GetTrackImage(int it){ |
380 |
|
381 |
if(it >= this->GetNTracks()){ |
382 |
cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; |
383 |
cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl; |
384 |
return 0; |
385 |
} |
386 |
TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it]; |
387 |
if(!track->HasImage()){ |
388 |
cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl; |
389 |
return 0; |
390 |
} |
391 |
TrkTrack *image = (TrkTrack*)(*Track)[track->image]; |
392 |
return image; |
393 |
|
394 |
} |
395 |
//-------------------------------------- |
396 |
// |
397 |
// |
398 |
//-------------------------------------- |
399 |
/** |
400 |
* Loads the magnetic field. |
401 |
* @param s Path of the magnetic-field files. |
402 |
*/ |
403 |
void TrkLevel2::LoadField(TString s){ |
404 |
readb_(s.Data()); |
405 |
}; |
406 |
//-------------------------------------- |
407 |
// |
408 |
// |
409 |
//-------------------------------------- |
410 |
/** |
411 |
* Trajectory constructor. |
412 |
* \param n Number of points |
413 |
*/ |
414 |
Trajectory::Trajectory(int n){ |
415 |
npoint = n; |
416 |
x = new float[npoint]; |
417 |
y = new float[npoint]; |
418 |
z = new float[npoint]; |
419 |
for(int i=0; i<npoint; i++){ |
420 |
x[i] = 0; |
421 |
y[i] = 0; |
422 |
z[i] = 0; |
423 |
} |
424 |
} |
425 |
//-------------------------------------- |
426 |
// |
427 |
// |
428 |
//-------------------------------------- |
429 |
/** |
430 |
* Trajectory constructor. |
431 |
* \param n Number of points |
432 |
* \param pz Pointer to float array, defining z coordinates |
433 |
*/ |
434 |
Trajectory::Trajectory(int n, float* zin){ |
435 |
npoint = n; |
436 |
x = new float[npoint]; |
437 |
y = new float[npoint]; |
438 |
z = new float[npoint]; |
439 |
for(int i=0; i<npoint; i++){ |
440 |
x[i] = 0; |
441 |
y[i] = 0; |
442 |
z[i] = zin[i]; |
443 |
} |
444 |
} |
445 |
//-------------------------------------- |
446 |
// |
447 |
// |
448 |
//-------------------------------------- |
449 |
/** |
450 |
* Dump the trajectory coordinates. |
451 |
*/ |
452 |
void Trajectory::Dump(){ |
453 |
cout <<endl<< "Trajectory ========== "<<endl; |
454 |
for (int i=0; i<npoint; i++){ |
455 |
cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] << endl;; |
456 |
}; |
457 |
} |
458 |
|
459 |
ClassImp(TrkLevel2); |
460 |
ClassImp(TrkSinglet); |
461 |
ClassImp(TrkTrack); |
462 |
ClassImp(Trajectory); |