]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #include "Track.h" | |
4 | #include "MCHelixLine.hi" | |
5 | ||
6 | #include <TPolyLine3D.h> | |
7 | #include <TPolyMarker3D.h> | |
8 | #include <TColor.h> | |
9 | ||
10 | // Updates | |
11 | #include <Reve/RGTopFrame.h> | |
12 | #include <TCanvas.h> | |
13 | ||
14 | #include <vector> | |
15 | ||
16 | using namespace Reve; | |
17 | ||
18 | //______________________________________________________________________ | |
19 | // Track | |
20 | // | |
21 | ||
22 | ClassImp(Reve::Track) | |
23 | ||
265ecb21 | 24 | Track::Track() : |
eadaa89b | 25 | Line(), |
5a5a1232 | 26 | |
265ecb21 | 27 | fV(), |
28 | fP(), | |
29 | fBeta(0), | |
30 | fCharge(0), | |
31 | fLabel(0), | |
32 | fPathMarks(), | |
33 | ||
eadaa89b | 34 | fRnrStyle(0) |
265ecb21 | 35 | {} |
36 | ||
3d75306d | 37 | Track::Track(TParticle* t, Int_t label, TrackRnrStyle* rs): |
eadaa89b | 38 | Line(), |
3d75306d | 39 | |
40 | fV(t->Vx(), t->Vy(), t->Vz()), | |
41 | fP(t->Px(), t->Py(), t->Pz()), | |
42 | fBeta(t->P()/t->Energy()), | |
43 | fCharge(0), | |
44 | fLabel(label), | |
45 | fPathMarks(), | |
46 | ||
eadaa89b | 47 | fRnrStyle(rs) |
3d75306d | 48 | { |
49 | fLineColor = fRnrStyle->GetColor(); | |
50 | fMainColorPtr = &fLineColor; | |
51 | ||
52 | TParticlePDG* pdgp = t->GetPDG(); | |
53 | if (pdgp) | |
54 | fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3); | |
eadaa89b | 55 | |
56 | SetName(t->GetName()); | |
3d75306d | 57 | } |
58 | ||
265ecb21 | 59 | Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs): |
eadaa89b | 60 | Line(), |
5a5a1232 | 61 | |
265ecb21 | 62 | fV(t->Vx(), t->Vy(), t->Vz()), |
63 | fP(t->Px(), t->Py(), t->Pz()), | |
64 | fBeta(t->P()/t->Energy()), | |
65 | fCharge(0), | |
66 | fLabel(t->label), | |
67 | fPathMarks(), | |
68 | ||
eadaa89b | 69 | fRnrStyle(rs) |
265ecb21 | 70 | { |
5a5a1232 | 71 | fLineColor = fRnrStyle->GetColor(); |
72 | fMainColorPtr = &fLineColor; | |
73 | ||
5a5a1232 | 74 | TParticlePDG* pdgp = t->GetPDG(); |
75 | if(pdgp == 0) { | |
76 | t->ResetPdgCode(); pdgp = t->GetPDG(); | |
77 | } | |
48dc973d | 78 | fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3); |
eadaa89b | 79 | |
80 | SetName(t->GetName()); | |
5a5a1232 | 81 | } |
82 | ||
265ecb21 | 83 | Track::Track(Reve::RecTrack* t, TrackRnrStyle* rs) : |
eadaa89b | 84 | Line(), |
265ecb21 | 85 | |
86 | fV(t->V), | |
87 | fP(t->P), | |
88 | fBeta(t->beta), | |
89 | fCharge(t->sign), | |
90 | fLabel(t->label), | |
91 | fPathMarks(), | |
92 | ||
eadaa89b | 93 | fRnrStyle(rs) |
5a5a1232 | 94 | { |
5a5a1232 | 95 | fLineColor = fRnrStyle->GetColor(); |
96 | fMainColorPtr = &fLineColor; | |
eadaa89b | 97 | |
98 | SetName(t->GetName()); | |
5a5a1232 | 99 | } |
100 | ||
101 | Track::~Track() | |
265ecb21 | 102 | { |
103 | for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) | |
104 | delete *i; | |
105 | } | |
5a5a1232 | 106 | |
eadaa89b | 107 | /* |
5a5a1232 | 108 | void Track::Reset(Int_t n_points) |
109 | { | |
110 | delete [] TPolyLine3D::fP; TPolyLine3D::fP = 0; | |
111 | fN = n_points; | |
112 | if(fN) TPolyLine3D::fP = new Float_t [3*fN]; | |
113 | memset(TPolyLine3D::fP, 0, 3*fN*sizeof(Float_t)); | |
114 | fLastPoint = -1; | |
115 | } | |
eadaa89b | 116 | */ |
5a5a1232 | 117 | |
118 | /**************************************************************************/ | |
119 | ||
120 | void Track::MakeTrack() | |
121 | { | |
122 | ||
123 | TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle); | |
124 | ||
125 | Float_t px = fP.x, py = fP.y, pz = fP.z; | |
126 | ||
127 | MCVertex mc_v0; | |
128 | mc_v0.x = fV.x; | |
129 | mc_v0.y = fV.y; | |
130 | mc_v0.z = fV.z; | |
131 | mc_v0.t = 0; | |
132 | ||
133 | std::vector<MCVertex> track_points; | |
48dc973d | 134 | Bool_t decay = kFALSE; |
5a5a1232 | 135 | |
136 | if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR)) | |
137 | goto make_polyline; | |
138 | ||
01024c63 | 139 | if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5) { |
140 | ||
141 | // Charged particle in magnetic field | |
5a5a1232 | 142 | |
48dc973d | 143 | Float_t a = RS.fgkB2C * RS.fMagField * fCharge; |
5a5a1232 | 144 | |
145 | MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm | |
146 | helix.Init(TMath::Sqrt(px*px+py*py), pz); | |
147 | ||
148 | if(!fPathMarks.empty()){ | |
149 | for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) { | |
150 | Reve::PathMark* pm = *i; | |
151 | ||
152 | if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){ | |
153 | if(TMath::Abs(pm->V.z) > RS.fMaxZ | |
154 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) | |
155 | goto helix_bounds; | |
156 | ||
157 | //printf("%s fit daughter \n", fName.Data()); | |
158 | helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z); | |
159 | fP.x -= pm->P.x; | |
160 | fP.y -= pm->P.y; | |
161 | fP.z -= pm->P.z; | |
162 | } | |
163 | if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){ | |
164 | ||
165 | if(TMath::Abs(pm->V.z) > RS.fMaxZ | |
166 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) | |
167 | goto helix_bounds; | |
168 | helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z); | |
169 | decay = true; | |
170 | break; | |
171 | } | |
172 | } | |
173 | } | |
174 | helix_bounds: | |
175 | //go to bounds | |
48dc973d | 176 | if(!decay || RS.fFitDecay == kFALSE){ |
5a5a1232 | 177 | helix.LoopToBounds(px,py,pz); |
178 | // printf("%s loop to bounds \n",fName.Data() ); | |
179 | } | |
180 | ||
01024c63 | 181 | } else { |
182 | ||
183 | // Neutral particle or no field | |
5a5a1232 | 184 | |
185 | MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points); | |
186 | ||
187 | if(!fPathMarks.empty()){ | |
188 | for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) { | |
189 | Reve::PathMark* pm = *i; | |
190 | ||
191 | if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){ | |
192 | if(TMath::Abs(pm->V.z) > RS.fMaxZ | |
193 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) | |
194 | goto line_bounds; | |
195 | line.GotoVertex(pm->V.x, pm->V.y, pm->V.z); | |
196 | fP.x -= pm->P.x; | |
197 | fP.y -= pm->P.y; | |
198 | fP.z -= pm->P.z; | |
199 | } | |
200 | ||
201 | if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){ | |
202 | if(TMath::Abs(pm->V.z) > RS.fMaxZ | |
203 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) | |
204 | goto line_bounds; | |
205 | line.GotoVertex(pm->V.x, pm->V.y, pm->V.z); | |
206 | decay = true; | |
207 | break; | |
208 | } | |
209 | } | |
210 | } | |
211 | ||
212 | line_bounds: | |
48dc973d | 213 | if(!decay || RS.fFitDecay == kFALSE) |
5a5a1232 | 214 | line.GotoBounds(px,py,pz); |
215 | ||
216 | } | |
217 | make_polyline: | |
218 | Reset(track_points.size()); | |
219 | for(std::vector<MCVertex>::iterator i=track_points.begin(); i!=track_points.end(); ++i) | |
220 | SetNextPoint(i->x, i->y, i->z); | |
221 | } | |
222 | ||
223 | /**************************************************************************/ | |
224 | ||
48dc973d | 225 | void Track::ImportHits() |
226 | { | |
227 | Reve::LoadMacro("hits_from_label.C"); | |
228 | gROOT->ProcessLine(Form("hits_from_label(%d);", fLabel)); | |
229 | } | |
230 | ||
231 | void Track::ImportClusters() | |
232 | { | |
233 | Reve::LoadMacro("clusters_from_label.C"); | |
234 | gROOT->ProcessLine(Form("clusters_from_label(%d);", fLabel)); | |
235 | } | |
236 | ||
237 | ||
238 | /**************************************************************************/ | |
239 | /**************************************************************************/ | |
240 | ||
5a5a1232 | 241 | //______________________________________________________________________ |
242 | // TrackRnrStyle | |
243 | // | |
244 | ||
245 | ClassImp(Reve::TrackRnrStyle) | |
246 | ||
48dc973d | 247 | Float_t TrackRnrStyle::fgDefMagField = 5; |
248 | const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3; | |
5a5a1232 | 249 | TrackRnrStyle TrackRnrStyle::fgDefStyle; |
250 | ||
265ecb21 | 251 | TrackRnrStyle::TrackRnrStyle() : |
252 | TObject(), | |
5a5a1232 | 253 | |
265ecb21 | 254 | fColor(1), |
2074deef | 255 | fWidth(1), |
265ecb21 | 256 | fMagField(fgDefMagField), |
5a5a1232 | 257 | |
265ecb21 | 258 | fMaxR (350), |
259 | fMaxZ (450), | |
5a5a1232 | 260 | |
265ecb21 | 261 | fMaxOrbs (0.5), |
262 | fMinAng (45), | |
263 | fDelta (0.1), | |
5a5a1232 | 264 | |
265ecb21 | 265 | fFitDaughters(kTRUE), |
266 | fFitDecay (kTRUE) | |
267 | {} | |
5a5a1232 | 268 | |
269 | /**************************************************************************/ | |
270 | /**************************************************************************/ | |
271 | ||
272 | //______________________________________________________________________ | |
273 | // TrackList | |
274 | // | |
275 | ||
276 | ClassImp(Reve::TrackList) | |
277 | ||
278 | void TrackList::Init() | |
279 | { | |
280 | fMarkerStyle = 6; | |
281 | fMarkerColor = 5; | |
282 | // fMarker->SetMarkerSize(0.05); | |
283 | ||
a8600b56 | 284 | if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle; |
285 | SetMainColorPtr(&fRnrStyle->fColor); | |
5a5a1232 | 286 | } |
287 | ||
a8600b56 | 288 | TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) : |
7d42b6c2 | 289 | RenderElementListBase(), |
265ecb21 | 290 | TPolyMarker3D(n_tracks), |
291 | ||
292 | fTitle(), | |
293 | ||
a8600b56 | 294 | fRnrStyle (rs), |
265ecb21 | 295 | fRnrMarkers (kTRUE), |
296 | fRnrTracks (kTRUE) | |
5a5a1232 | 297 | { |
298 | Init(); | |
299 | } | |
300 | ||
a8600b56 | 301 | TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) : |
7d42b6c2 | 302 | RenderElementListBase(), |
265ecb21 | 303 | TPolyMarker3D(n_tracks), |
a8600b56 | 304 | |
265ecb21 | 305 | fTitle(), |
306 | ||
a8600b56 | 307 | fRnrStyle (rs), |
265ecb21 | 308 | fRnrMarkers (kTRUE), |
309 | fRnrTracks (kTRUE) | |
5a5a1232 | 310 | { |
311 | Init(); | |
312 | SetName(name); | |
313 | } | |
314 | ||
315 | void TrackList::Reset(Int_t n_tracks) | |
316 | { | |
317 | delete [] fP; fP = 0; | |
318 | fN = n_tracks; | |
319 | if(fN) fP = new Float_t [3*fN]; | |
320 | memset(fP, 0, 3*fN*sizeof(Float_t)); | |
321 | fLastPoint = -1; | |
322 | } | |
323 | ||
324 | /**************************************************************************/ | |
325 | ||
326 | void TrackList::Paint(Option_t* option) | |
327 | { | |
328 | if(fRnrElement) { | |
329 | if(fRnrMarkers) { | |
330 | TPolyMarker3D::Paint(option); | |
331 | } | |
332 | if(fRnrTracks) { | |
7d42b6c2 | 333 | for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
5a5a1232 | 334 | if((*i)->GetRnrElement()) |
335 | (*i)->GetObject()->Paint(option); | |
336 | } | |
337 | } | |
338 | } | |
339 | } | |
340 | ||
341 | /**************************************************************************/ | |
342 | ||
343 | void TrackList::AddElement(RenderElement* el) | |
344 | { | |
345 | static const Exc_t eH("TrackList::AddElement "); | |
346 | if (dynamic_cast<Track*>(el) == 0) | |
347 | throw(eH + "new element not a Track."); | |
348 | RenderElementListBase::AddElement(el); | |
349 | } | |
350 | ||
351 | /**************************************************************************/ | |
352 | ||
353 | void TrackList::SetRnrMarkers(Bool_t rnr) | |
354 | { | |
355 | fRnrMarkers = rnr; | |
356 | gReve->Redraw3D(); | |
357 | } | |
358 | ||
359 | void TrackList::SetRnrTracks(Bool_t rnr) | |
360 | { | |
361 | ||
362 | fRnrTracks = rnr; | |
363 | gReve->Redraw3D(); | |
364 | } | |
365 | ||
366 | /**************************************************************************/ | |
367 | ||
368 | void TrackList::MakeTracks() | |
369 | { | |
7d42b6c2 | 370 | for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
5a5a1232 | 371 | ((Track*)(*i))->MakeTrack(); |
372 | } | |
373 | gReve->Redraw3D(); | |
374 | } | |
375 | ||
376 | ||
377 | void TrackList::MakeMarkers() | |
378 | { | |
7d42b6c2 | 379 | Reset(fChildren.size()); |
380 | for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) { | |
5a5a1232 | 381 | Track& t = *((Track*)(*i)); |
382 | if(t.GetN() > 0) | |
383 | SetNextPoint(t.fV.x, t.fV.y, t.fV.z); | |
384 | } | |
385 | gReve->Redraw3D(); | |
386 | } | |
387 | ||
388 | /**************************************************************************/ | |
389 | /*************************************************************************/ | |
390 | ||
2074deef | 391 | void TrackList::SetWidth(Width_t w) |
392 | { | |
393 | Width_t oldw = fRnrStyle->fWidth; | |
394 | fRnrStyle->fWidth = w; | |
395 | for (lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) { | |
396 | Track& t = *((Track*)(*i)); | |
397 | if (t.GetLineWidth() == oldw) | |
398 | t.SetLineWidth(w); | |
399 | } | |
400 | } | |
401 | ||
5a5a1232 | 402 | void TrackList::SetMaxR(Float_t x) |
403 | { | |
a8600b56 | 404 | fRnrStyle->fMaxR = x; |
5a5a1232 | 405 | MakeTracks(); |
406 | MakeMarkers(); | |
407 | } | |
408 | ||
409 | void TrackList::SetMaxZ(Float_t x) | |
410 | { | |
a8600b56 | 411 | fRnrStyle->fMaxZ = x; |
5a5a1232 | 412 | MakeTracks(); |
413 | MakeMarkers(); | |
414 | } | |
415 | ||
416 | void TrackList::SetMaxOrbs(Float_t x) | |
417 | { | |
a8600b56 | 418 | fRnrStyle->fMaxOrbs = x; |
5a5a1232 | 419 | MakeTracks(); |
420 | } | |
421 | ||
422 | void TrackList::SetMinAng(Float_t x) | |
423 | { | |
a8600b56 | 424 | fRnrStyle->fMinAng = x; |
5a5a1232 | 425 | MakeTracks(); |
426 | } | |
427 | ||
428 | void TrackList::SetDelta(Float_t x) | |
429 | { | |
a8600b56 | 430 | fRnrStyle->fDelta = x; |
5a5a1232 | 431 | MakeTracks(); |
432 | } | |
433 | ||
434 | void TrackList::SetFitDaughters(Bool_t x) | |
435 | { | |
a8600b56 | 436 | fRnrStyle->fFitDaughters = x; |
5a5a1232 | 437 | MakeTracks(); |
438 | } | |
439 | ||
440 | void TrackList::SetFitDecay(Bool_t x) | |
441 | { | |
a8600b56 | 442 | fRnrStyle->fFitDecay = x; |
5a5a1232 | 443 | MakeTracks(); |
444 | } | |
445 | ||
446 | /**************************************************************************/ | |
447 | /**************************************************************************/ | |
448 | ||
449 | void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt) | |
450 | { | |
451 | Float_t minptsq = min_pt*min_pt; | |
452 | Float_t maxptsq = max_pt*max_pt; | |
453 | Float_t ptsq; | |
454 | ||
7d42b6c2 | 455 | for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
5a5a1232 | 456 | ptsq = ((Track*)(*i))->fP.Perp2(); |
457 | (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq); | |
458 | } | |
459 | } | |
460 | ||
461 | /**************************************************************************/ | |
462 | ||
b99aed53 | 463 | void TrackList::ImportHits() |
5a5a1232 | 464 | { |
7d42b6c2 | 465 | for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
b99aed53 | 466 | ((Track*)(*i))->ImportHits(); |
467 | } | |
5a5a1232 | 468 | } |
469 | ||
b99aed53 | 470 | void TrackList::ImportClusters() |
5a5a1232 | 471 | { |
7d42b6c2 | 472 | for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
b99aed53 | 473 | ((Track*)(*i))->ImportClusters(); |
474 | } | |
5a5a1232 | 475 | } |