]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/VSDSelector.cxx
Merged EVE-dev-after-merge to EVE-dev into HEAD. Requires ROOT-5.17.04.
[u/mrichter/AliRoot.git] / EVE / Reve / VSDSelector.cxx
1
2 #include "VSDSelector.h"
3 #include "VSDEvent.h"
4 #include "ReveManager.h"
5
6 #include <Reve/Track.h>
7 #include <Reve/PointSet.h>
8
9 #include <Reve/PODs.h>
10 #include <Reve/TTreeTools.h>
11
12 #include <TEventList.h>
13 #include <TGLabel.h>
14 #include <TGXYLayout.h>
15 #include <TGClient.h>
16
17 using namespace Reve;
18
19 using Reve::Exc_t;
20
21 VSDSelector::VSDSelector(TGCompositeFrame *tFrame) :
22   VSD(),
23
24   mParticleSelection(0),
25   fRecursiveSelect(0),
26
27   mHitSelection(0),   
28   mClusterSelection(0), 
29   mRecSelection(0)
30 {
31   //create gui
32   TGGroupFrame *gframe = new TGGroupFrame(tFrame, "Options", kVerticalFrame);
33   TGLayoutHints* lh0 = new TGLayoutHints(kLHintsTop | kLHintsLeft |  kLHintsExpandX | kLHintsExpandY  , 5, 5, 5, 5);
34   gframe->SetTitlePos(TGGroupFrame::kRight); // right aligned
35   tFrame->AddFrame(gframe, lh0);
36   
37   TGXYLayout* xyl = new TGXYLayout(gframe);
38   gframe->SetLayoutManager(xyl);
39   xyl->Layout();
40
41   TGXYLayoutHints* lh;
42
43   UInt_t wH     = 2;
44   UInt_t labelw = 15;
45   UInt_t entryw = 39;
46   UInt_t butw   = 10;
47
48   Float_t x = 2, y = 2;
49
50   {
51     // particles
52     TGLabel* label = new TGLabel(gframe, "ParticleSelection");
53     label->Resize(labelw, wH);
54     label->SetTextJustify(kTextLeft | kTextCenterY);
55     lh = new TGXYLayoutHints(x, y, labelw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
56     gframe->AddFrame(label,lh);
57     x += labelw ;
58   
59     mParticleSelection = new TGTextEntry(gframe, "fMother[0] == -1 && Pt() > 1");
60     mParticleSelection->Resize(entryw, wH);
61     lh = new TGXYLayoutHints(x, y, entryw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
62     gframe->AddFrame(mParticleSelection,lh);
63     x += entryw+1;
64   
65     TGTextButton* but = new TGTextButton(gframe, "Select");
66     but->Resize(butw, wH);
67     but->SetTextJustify(kTextCenterX | kTextCenterY);
68     lh = new TGXYLayoutHints(x, y, butw, wH,0);  lh->SetPadLeft(4); lh->SetPadRight(2);
69     gframe->AddFrame(but,lh);
70     but->Connect("Pressed()", "Reve::VSDSelector", this, "SelectParticles()");
71    
72     UInt_t rbw = 11;
73     x = x + butw + 0.5;
74     fRecursiveSelect = new TGCheckButton(gframe, "Recursive");
75     fRecursiveSelect->Resize(rbw, wH);
76     lh = new TGXYLayoutHints(x, y, rbw, wH,0);  lh->SetPadLeft(4); lh->SetPadRight(2);
77     gframe->AddFrame(fRecursiveSelect,lh);
78   }
79   x = 2.;
80   y+= wH;  y+= 1.;
81
82
83   {    // hits
84     TGLabel* label = new TGLabel(gframe, "HitSelection");
85     label->Resize(labelw, wH);
86     label->SetTextJustify(kTextLeft | kTextCenterY);
87     lh = new TGXYLayoutHints(x, y, labelw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
88     gframe->AddFrame(label,lh);
89     x += labelw;
90   
91     mHitSelection  = new TGTextEntry(gframe, "det_id == 0");
92     mHitSelection->Resize(entryw, wH);
93     lh = new TGXYLayoutHints(x, y, entryw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
94     gframe->AddFrame(mHitSelection,lh);
95     x += entryw +1;
96   
97     TGTextButton* but = new TGTextButton(gframe, "Select");
98     but->Resize(butw, wH);
99     but->SetTextJustify(kTextCenterX | kTextCenterY);
100     lh = new TGXYLayoutHints(x, y, butw, wH,0);  lh->SetPadLeft(4); lh->SetPadRight(2);
101     gframe->AddFrame(but,lh);
102     but->Connect("Pressed()", "Reve::VSDSelector", this, "SelectHits()");
103
104   }
105
106   x = 2.;
107   y+= wH;  y+= 1.;
108
109   {    // particle selection
110     TGLabel* label = new TGLabel(gframe, "ClusterSelection");
111     label->Resize(labelw, wH);
112     label->SetTextJustify(kTextLeft | kTextCenterY);
113     lh = new TGXYLayoutHints(x, y, labelw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
114     gframe->AddFrame(label,lh);
115     x += labelw;
116   
117     mClusterSelection = new TGTextEntry(gframe, "C.V.R() > 70");
118     mClusterSelection->Resize(entryw, wH);
119     lh = new TGXYLayoutHints(x, y, entryw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
120     gframe->AddFrame(mClusterSelection,lh);
121     x += entryw +1;
122   
123     TGTextButton* but = new TGTextButton(gframe, "Select");
124     but->Resize(butw, wH);
125     but->SetTextJustify(kTextCenterX | kTextCenterY);
126     lh = new TGXYLayoutHints(x, y, butw, wH,0);  lh->SetPadLeft(4); lh->SetPadRight(2);
127     gframe->AddFrame(but,lh);
128     but->Connect("Pressed()", "Reve::VSDSelector", this, "SelectClusters()");
129   }
130
131   x = 2.;
132   y+= wH;  y+= 1.;
133
134   {    // reconstructed tracks selection
135     TGLabel* label = new TGLabel(gframe, "RecSelection");
136     label->Resize(labelw, wH);
137     label->SetTextJustify(kTextLeft | kTextCenterY);
138     lh = new TGXYLayoutHints(x, y, labelw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
139     gframe->AddFrame(label,lh);
140     x += labelw;
141   
142     mRecSelection = new TGTextEntry(gframe, "Pt() > 1");
143     mRecSelection->Resize(entryw, wH);
144     lh = new TGXYLayoutHints(x, y, entryw, wH,0);  lh->SetPadLeft(2); lh->SetPadRight(2);
145     gframe->AddFrame(mRecSelection,lh);
146     x += entryw +1;
147   
148     TGTextButton* but = new TGTextButton(gframe, "Select");
149     but->Resize(butw, wH);
150     but->SetTextJustify(kTextCenterX | kTextCenterY);
151     lh = new TGXYLayoutHints(x, y, butw, wH,0);  lh->SetPadLeft(4); lh->SetPadRight(2);
152     gframe->AddFrame(but,lh);
153     but->Connect("Pressed()", "Reve::VSDSelector", this, "SelectRecTracks()");
154   }
155
156   gframe->Resize(60, 30); // resize to default size 
157   gframe->MapSubwindows();
158   gframe->MapWindow();
159   tFrame->MapSubwindows();
160
161 }
162
163 /**************************************************************************/
164
165 void VSDSelector::LoadVSD(const Text_t* vsd_file_name,
166                           const Text_t* dir_name)
167 {
168   VSD::LoadVSD(vsd_file_name, dir_name);
169   // !!!! Should create VSDEvent ... but it is not done yet.
170   EventBase* ev = new EventBase(vsd_file_name, dir_name);
171   gReve->AddEvent(ev); 
172 }
173
174 /**************************************************************************/
175 //  selection methods
176 /**************************************************************************/
177
178 void VSDSelector::SelectParticles(const Text_t* selection)
179 {
180   static const Exc_t eH("VSDSelector::SelectParticles ");
181
182   if(mTreeK == 0) 
183     throw (eH + "kinematics not available.");
184
185   if(selection == 0)
186     selection = mParticleSelection->GetText();
187
188   TTreeQuery evl;
189   Int_t n = evl.Select(mTreeK, selection);
190   // printf("%d entries in selection '%s'.\n", n,  selection);
191
192   if(n == 0)
193     throw (eH + "no entries found for selection in kinematics.");
194
195   TrackList* cont   = new TrackList();
196   cont->SetMainColor(4);
197
198   gReve->AddRenderElement(cont);
199
200   if(n > 0) {
201     for(Int_t i=0; i<n; i++) {
202       Int_t label = evl.GetEntry(i);
203       mTreeK->GetEntry(label);
204       Track* track = new Track(mpK, cont->GetRnrStyle());
205       track->SetName(Form("%s daughters:%d", mK.GetName(), mK.GetNDaughters()));
206       gReve->AddRenderElement(track, cont);
207
208       // printf("select daugters %s selection %s\n",mpK->GetName(),Form("fMother[0] == %d", track->GetLabel()));
209       if(fRecursiveSelect->IsOn()) {
210         if(mK.GetNDaughters())
211           ImportDaughtersRec(track, cont, mK.GetFirstDaughter(), mK.GetLastDaughter());
212         // add decay point to path marks
213         if(mK.decayed) {
214           Reve::PathMark* pm = new Reve::PathMark(Reve::PathMark::Decay);
215           pm->V.x = mK.V_decay.x;
216           pm->V.y = mK.V_decay.y;
217           pm->V.z = mK.V_decay.z;
218           track->AddPathMark(pm);
219         }
220       }
221       track->MakeTrack();
222     }
223   }
224 }
225
226 void VSDSelector::ImportDaughtersRec(RenderElement* parent, TrackList* cont,
227                                      Int_t first, Int_t last)
228 {
229   Track* mother = dynamic_cast<Track*>(parent);
230
231   for(Int_t i=first; i<=last; i++) {
232     mTreeK->GetEntry(i); 
233     Track* track = new Track(mpK, cont->GetRnrStyle());
234     track->SetName(Form("%s daughters:%d", mK.GetName(), mK.GetNDaughters()));
235     gReve->AddRenderElement(track, parent);
236     cont->AddElement(track); // ?? is this ok ??
237     if(mK.GetNDaughters())
238       ImportDaughtersRec(track, cont, mK.GetFirstDaughter(), mK.GetLastDaughter());
239
240     // add daughter mark to mother
241     Reve::PathMark* dam = new Reve::PathMark(Reve::PathMark::Daughter);
242     dam->V.x = mK.Vx();
243     dam->V.y = mK.Vy();
244     dam->V.z = mK.Vz();
245     mother->AddPathMark(dam);
246
247     if(mK.decayed) {
248       Reve::PathMark* decm = new Reve::PathMark(Reve::PathMark::Decay);
249       decm->V.x = mK.V_decay.x;
250       decm->V.y = mK.V_decay.y;
251       decm->V.z = mK.V_decay.z;
252       track->AddPathMark(decm);
253
254     }
255     track->MakeTrack();
256   }
257 }
258
259 /**************************************************************************/
260 /**************************************************************************/
261
262 void VSDSelector::SelectHits()
263 {
264   static const Exc_t eH("VSDSelector::SelectHits ");
265
266   if(mTreeH == 0) 
267     throw (eH + "hits not available.");
268
269   const Text_t* selection;
270   if(mHitSelection)
271     selection  = mHitSelection->GetText();
272   else 
273     selection  ="1";
274
275   TTreeQuery evl;
276   Int_t n = evl.Select(mTreeH, selection);
277   // printf("ImportHitsWithSelection %d entries for selection %s\n", n, selection);
278   
279   if(n==0)
280     throw(eH + "no hits matching selection.");
281
282   PointSet* container = new PointSet
283     (Form("Hits %s", selection), n);
284   for(Int_t i=0; i<n; i++) {
285     const Int_t entry = evl.GetEntry(i);
286     mTreeH->GetEntry(entry);
287     container->SetPoint(i, mH.V.x, mH.V.y, mH.V.z);
288   }
289
290   container->SetTitle(Form("N=%d", container->GetN()));
291   container->SetMarkerColor(2);
292   container->SetMarkerStyle(20);
293   container->SetMarkerSize(0.5);
294   gReve->AddRenderElement(container);
295   gReve->Redraw3D();
296 }
297
298 /**************************************************************************/
299
300 void VSDSelector::SelectClusters()
301 {
302   static const Exc_t eH("VSDSelector::SelectClusters ");
303
304   if(mTreeC == 0) 
305     throw (eH + "clusters not available.");
306
307   const Text_t* selection;
308   if (mClusterSelection)
309     selection = mClusterSelection->GetText();
310   else 
311     selection  ="1";
312
313   TTreeQuery evl;
314   Int_t n = evl.Select(mTreeC, selection);
315   printf(" cluster Selection %d entries for selection %s\n", n, selection);
316   
317   if(n==0)
318     throw(eH + "no clusters matching selection.");
319
320   PointSet* container = new PointSet
321     (Form("Clusters %s", selection), n);
322   for(Int_t i=0; i<n; i++) {
323     const Int_t entry = evl.GetEntry(i);
324     mTreeC->GetEntry(entry);
325     container->SetPoint(i, mC.V.x, mC.V.y, mC.V.z);
326   }
327
328   container->SetTitle(Form("N=%d", container->GetN()));
329   container->SetMarkerColor(9);
330   container->SetMarkerStyle(20);
331   container->SetMarkerSize(0.5);
332   gReve->AddRenderElement(container);
333   gReve->Redraw3D();
334 }
335
336 /**************************************************************************/
337
338 void VSDSelector::SelectRecTracks()
339 {
340   static const Exc_t eH("VSDSelector::SelectRecTracks ");
341
342   if(mTreeR == 0) 
343     throw (eH + "reconstructed tracks not available.");
344
345   const Text_t* selection;
346   if(mRecSelection)
347     selection = mRecSelection->GetText();
348   else 
349     selection = "Pt() > 1";
350   
351   TTreeQuery evl;
352   Int_t n = evl.Select(mTreeR, selection);
353   // printf("%d entries in selection %s \n", n,  selection);
354
355   if (n == 0)
356     throw (eH + "No entries found in ESD data.");
357
358   if(n > 0) {
359     TrackList* cont = new TrackList(Form("RecTracks %s [%d]",selection, n));
360     cont->SetMainColor(6);
361
362     gReve->AddRenderElement(cont);
363
364     for (Int_t i=0; i<n; i++) {
365       Int_t label = evl.GetEntry(i);
366       mTreeR->GetEntry(label);
367       Track* track = new Track(mpR, cont->GetRnrStyle());
368       track->MakeTrack();
369
370       gReve->AddRenderElement(track, cont);
371     }
372     gReve->Redraw3D();
373   }
374 }