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