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 | |
24 | Track::Track() |
25 | { |
26 | fRnrStyle = 0; |
27 | } |
28 | |
29 | Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs) |
30 | { |
31 | fRnrStyle = rs; |
32 | |
33 | fName = t->GetName(); |
34 | fLineColor = fRnrStyle->GetColor(); |
35 | fMainColorPtr = &fLineColor; |
36 | |
37 | fV.Set(t->Vx(), t->Vy(), t->Vz()); |
38 | fP.Set(t->Px(), t->Py(), t->Pz()); |
39 | fBeta = t->P()/t->Energy(); |
40 | |
41 | TParticlePDG* pdgp = t->GetPDG(); |
42 | if(pdgp == 0) { |
43 | t->ResetPdgCode(); pdgp = t->GetPDG(); |
44 | } |
45 | |
46 | fCharge = (Int_t) pdgp->Charge(); |
47 | fLabel = t->label; |
48 | } |
49 | |
50 | Track::Track(Reve::RecTrack* t, TrackRnrStyle* rs) |
51 | { |
52 | fRnrStyle = rs; |
53 | fName = t->GetName(); |
54 | fLineColor = fRnrStyle->GetColor(); |
55 | fMainColorPtr = &fLineColor; |
56 | |
57 | fV = t->V; |
58 | fP = t->P; |
59 | fBeta = t->beta; |
60 | fCharge = t->sign; |
61 | fLabel = t->label; |
62 | } |
63 | |
64 | Track::~Track() |
65 | {} |
66 | |
67 | void Track::Reset(Int_t n_points) |
68 | { |
69 | delete [] TPolyLine3D::fP; TPolyLine3D::fP = 0; |
70 | fN = n_points; |
71 | if(fN) TPolyLine3D::fP = new Float_t [3*fN]; |
72 | memset(TPolyLine3D::fP, 0, 3*fN*sizeof(Float_t)); |
73 | fLastPoint = -1; |
74 | } |
75 | |
76 | /**************************************************************************/ |
77 | |
78 | void Track::MakeTrack() |
79 | { |
80 | |
81 | TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle); |
82 | |
83 | Float_t px = fP.x, py = fP.y, pz = fP.z; |
84 | |
85 | MCVertex mc_v0; |
86 | mc_v0.x = fV.x; |
87 | mc_v0.y = fV.y; |
88 | mc_v0.z = fV.z; |
89 | mc_v0.t = 0; |
90 | |
91 | std::vector<MCVertex> track_points; |
92 | Bool_t decay = false; |
93 | |
94 | if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR)) |
95 | goto make_polyline; |
96 | |
97 | if (fCharge) { // Charged particle |
98 | |
99 | Float_t a = 0.2998*RS.fMagField*fCharge/300; // m->cm |
100 | |
101 | MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm |
102 | helix.Init(TMath::Sqrt(px*px+py*py), pz); |
103 | |
104 | if(!fPathMarks.empty()){ |
105 | for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) { |
106 | Reve::PathMark* pm = *i; |
107 | |
108 | if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){ |
109 | if(TMath::Abs(pm->V.z) > RS.fMaxZ |
110 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) |
111 | goto helix_bounds; |
112 | |
113 | //printf("%s fit daughter \n", fName.Data()); |
114 | helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z); |
115 | fP.x -= pm->P.x; |
116 | fP.y -= pm->P.y; |
117 | fP.z -= pm->P.z; |
118 | } |
119 | if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){ |
120 | |
121 | if(TMath::Abs(pm->V.z) > RS.fMaxZ |
122 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) |
123 | goto helix_bounds; |
124 | helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z); |
125 | decay = true; |
126 | break; |
127 | } |
128 | } |
129 | } |
130 | helix_bounds: |
131 | //go to bounds |
132 | if(!decay || RS.fFitDecay == false){ |
133 | helix.LoopToBounds(px,py,pz); |
134 | // printf("%s loop to bounds \n",fName.Data() ); |
135 | } |
136 | |
137 | } else { // Neutral particle |
138 | |
139 | MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points); |
140 | |
141 | if(!fPathMarks.empty()){ |
142 | for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) { |
143 | Reve::PathMark* pm = *i; |
144 | |
145 | if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){ |
146 | if(TMath::Abs(pm->V.z) > RS.fMaxZ |
147 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) |
148 | goto line_bounds; |
149 | line.GotoVertex(pm->V.x, pm->V.y, pm->V.z); |
150 | fP.x -= pm->P.x; |
151 | fP.y -= pm->P.y; |
152 | fP.z -= pm->P.z; |
153 | } |
154 | |
155 | if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){ |
156 | if(TMath::Abs(pm->V.z) > RS.fMaxZ |
157 | || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR ) |
158 | goto line_bounds; |
159 | line.GotoVertex(pm->V.x, pm->V.y, pm->V.z); |
160 | decay = true; |
161 | break; |
162 | } |
163 | } |
164 | } |
165 | |
166 | line_bounds: |
167 | if(!decay || RS.fFitDecay == false) |
168 | line.GotoBounds(px,py,pz); |
169 | |
170 | } |
171 | make_polyline: |
172 | Reset(track_points.size()); |
173 | for(std::vector<MCVertex>::iterator i=track_points.begin(); i!=track_points.end(); ++i) |
174 | SetNextPoint(i->x, i->y, i->z); |
175 | } |
176 | |
177 | /**************************************************************************/ |
178 | |
179 | //______________________________________________________________________ |
180 | // TrackRnrStyle |
181 | // |
182 | |
183 | ClassImp(Reve::TrackRnrStyle) |
184 | |
185 | Float_t TrackRnrStyle::fgDefMagField = 0.5; |
186 | TrackRnrStyle TrackRnrStyle::fgDefStyle; |
187 | |
188 | void TrackRnrStyle::Init() |
189 | { |
190 | fMagField = fgDefMagField; |
191 | |
192 | fMaxR = 450; |
193 | fMaxZ = 550; |
194 | |
195 | fMaxOrbs = 2; |
196 | fMinAng = 45; |
197 | |
198 | fFitDaughters = true; |
199 | fFitDecay = true; |
200 | |
201 | fDelta = 0.1; //calculate step size depending on helix radius |
202 | } |
203 | |
204 | /**************************************************************************/ |
205 | /**************************************************************************/ |
206 | |
207 | //______________________________________________________________________ |
208 | // TrackList |
209 | // |
210 | |
211 | ClassImp(Reve::TrackList) |
212 | |
213 | void TrackList::Init() |
214 | { |
215 | fMarkerStyle = 6; |
216 | fMarkerColor = 5; |
217 | // fMarker->SetMarkerSize(0.05); |
218 | |
219 | fRnrMarkers = true; |
220 | fRnrTracks = true; |
221 | |
222 | mRnrStyle = new TrackRnrStyle; |
223 | SetMainColorPtr(&mRnrStyle->fColor); |
224 | } |
225 | |
226 | TrackList::TrackList(Int_t n_tracks) : |
227 | TPolyMarker3D(n_tracks), |
228 | RenderElementListBase() |
229 | { |
230 | Init(); |
231 | } |
232 | |
233 | TrackList::TrackList(const Text_t* name, Int_t n_tracks) : |
234 | TPolyMarker3D(n_tracks), |
235 | RenderElementListBase() |
236 | { |
237 | Init(); |
238 | SetName(name); |
239 | } |
240 | |
241 | void TrackList::Reset(Int_t n_tracks) |
242 | { |
243 | delete [] fP; fP = 0; |
244 | fN = n_tracks; |
245 | if(fN) fP = new Float_t [3*fN]; |
246 | memset(fP, 0, 3*fN*sizeof(Float_t)); |
247 | fLastPoint = -1; |
248 | } |
249 | |
250 | /**************************************************************************/ |
251 | |
252 | void TrackList::Paint(Option_t* option) |
253 | { |
254 | if(fRnrElement) { |
255 | if(fRnrMarkers) { |
256 | TPolyMarker3D::Paint(option); |
257 | } |
258 | if(fRnrTracks) { |
259 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) { |
260 | if((*i)->GetRnrElement()) |
261 | (*i)->GetObject()->Paint(option); |
262 | } |
263 | } |
264 | } |
265 | } |
266 | |
267 | /**************************************************************************/ |
268 | |
269 | void TrackList::AddElement(RenderElement* el) |
270 | { |
271 | static const Exc_t eH("TrackList::AddElement "); |
272 | if (dynamic_cast<Track*>(el) == 0) |
273 | throw(eH + "new element not a Track."); |
274 | RenderElementListBase::AddElement(el); |
275 | } |
276 | |
277 | /**************************************************************************/ |
278 | |
279 | void TrackList::SetRnrMarkers(Bool_t rnr) |
280 | { |
281 | fRnrMarkers = rnr; |
282 | gReve->Redraw3D(); |
283 | } |
284 | |
285 | void TrackList::SetRnrTracks(Bool_t rnr) |
286 | { |
287 | |
288 | fRnrTracks = rnr; |
289 | gReve->Redraw3D(); |
290 | } |
291 | |
292 | /**************************************************************************/ |
293 | |
294 | void TrackList::MakeTracks() |
295 | { |
296 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) { |
297 | ((Track*)(*i))->MakeTrack(); |
298 | } |
299 | gReve->Redraw3D(); |
300 | } |
301 | |
302 | |
303 | void TrackList::MakeMarkers() |
304 | { |
305 | Reset(fList.size()); |
306 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) { |
307 | Track& t = *((Track*)(*i)); |
308 | if(t.GetN() > 0) |
309 | SetNextPoint(t.fV.x, t.fV.y, t.fV.z); |
310 | } |
311 | gReve->Redraw3D(); |
312 | } |
313 | |
314 | /**************************************************************************/ |
315 | /*************************************************************************/ |
316 | |
317 | void TrackList::SetMaxR(Float_t x) |
318 | { |
319 | mRnrStyle->fMaxR = x; |
320 | MakeTracks(); |
321 | MakeMarkers(); |
322 | } |
323 | |
324 | void TrackList::SetMaxZ(Float_t x) |
325 | { |
326 | mRnrStyle->fMaxZ = x; |
327 | MakeTracks(); |
328 | MakeMarkers(); |
329 | } |
330 | |
331 | void TrackList::SetMaxOrbs(Float_t x) |
332 | { |
333 | mRnrStyle->fMaxOrbs = x; |
334 | MakeTracks(); |
335 | } |
336 | |
337 | void TrackList::SetMinAng(Float_t x) |
338 | { |
339 | mRnrStyle->fMinAng = x; |
340 | MakeTracks(); |
341 | } |
342 | |
343 | void TrackList::SetDelta(Float_t x) |
344 | { |
345 | mRnrStyle->fDelta = x; |
346 | MakeTracks(); |
347 | } |
348 | |
349 | void TrackList::SetFitDaughters(Bool_t x) |
350 | { |
351 | mRnrStyle->fFitDaughters = x; |
352 | MakeTracks(); |
353 | } |
354 | |
355 | void TrackList::SetFitDecay(Bool_t x) |
356 | { |
357 | mRnrStyle->fFitDecay = x; |
358 | MakeTracks(); |
359 | } |
360 | |
361 | /**************************************************************************/ |
362 | /**************************************************************************/ |
363 | |
364 | void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt) |
365 | { |
366 | Float_t minptsq = min_pt*min_pt; |
367 | Float_t maxptsq = max_pt*max_pt; |
368 | Float_t ptsq; |
369 | |
370 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) { |
371 | ptsq = ((Track*)(*i))->fP.Perp2(); |
372 | (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq); |
373 | } |
374 | } |
375 | |
376 | /**************************************************************************/ |
377 | |
378 | #include <TGFrame.h> |
379 | #include <TGDoubleSlider.h> |
380 | #include <TGXYLayout.h> |
381 | |
382 | void TrackList::MakePtScrollbar() |
383 | { |
384 | TGMainFrame* mf = new TGMainFrame(gClient->GetRoot(), 320, 60); |
385 | |
386 | TGDoubleHSlider* hs = new TGDoubleHSlider(mf); |
387 | hs->SetRange(0.2, 10); |
388 | hs->SetPosition(0.2, 10); |
389 | hs->Resize(300, 25); |
390 | mf->AddFrame(hs, new TGLayoutHints(kLHintsCenterX, 10, 10, 10, 10)); |
391 | |
392 | hs->Connect("PositionChanged()", "Reve::TrackList", |
393 | this, "HandlePtScrollEvent()"); |
394 | |
395 | mf->SetWindowName("Pt Selector"); |
396 | mf->MapSubwindows(); |
397 | mf->Resize(mf->GetDefaultSize()); // this is used here to init layout algorithm |
398 | mf->MapWindow(); |
399 | } |
400 | |
401 | void TrackList::HandlePtScrollEvent() |
402 | { |
403 | TGDoubleHSlider* hs = (TGDoubleHSlider*)gTQSender; |
404 | |
405 | Float_t min = hs->GetMinPosition(), max = hs->GetMaxPosition(); |
406 | printf("hslidor min=%f max=%f\n", min, max); |
407 | SelectByPt(min, max); |
408 | } |