]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/macros/TTreeSelection.cxx
doxy: TPC/macros root converted
[u/mrichter/AliRoot.git] / TPC / macros / TTreeSelection.cxx
1 /// \class TTreeSelection
2 ///
3 /// ~~~{.cpp}
4 /// .L $ALICE_ROOT/TPC/macros/TTreeSelection.cxx++
5 ///
6 /// TFile f("eveTree.root");
7 /// Tracks;
8 ///
9 /// TTreeDraw draw("draw",Tracks);
10 /// draw.AddSelection("TPC clusters","Tr.fTPCncls>0");
11 /// draw.AddSelection("TRD clusters","Tr.fTRDncls>0");
12 /// ~~~
13
14 #include "TMath.h"
15 #include "TFile.h"
16 #include "TTree.h"
17 #include "TTreeStream.h"
18 #include "TPolyMarker3D.h"
19 #include "TVectorD.h"
20 #include "TObjString.h"
21
22
23 class TTreePoint: public TNamed{
24 public:
25   TTreePoint();
26   TTreePoint(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType);
27   //  TString GetSelection();
28 public:
29   TString fPx;   ///< point X
30   TString fPy;   ///< point Y
31   TString fPz;   ///< point Z
32   Int_t   fMColor; ///< color
33   Int_t   fMSize;  ///< marker size
34   Int_t   fMType;  ///< marker type
35   Bool_t  fIsOn;   ///< is On
36   ClassDef(TTreePoint,1)
37 };
38
39
40 class TTreeCutAtom: public TNamed{
41 public:
42   enum ExprType { kBool=0, kInt=1, kRange=2};
43   TTreeCutAtom();
44   TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1=0);
45   TString GetSelection();
46 public:
47   Double_t   fInt0;    ///< interval  value 0
48   Double_t   fInt1;    ///< interval  value 1
49   Double_t   fVal0;    ///< selection value 0
50   Double_t   fVal1;    ///< selection value 1
51   ExprType   fType;    ///< selection type
52   ClassDef(TTreeCutAtom,1)
53 };
54
55 class TTreeDraw: public TNamed{
56 public:
57   TTreeDraw(const char *name, TTree * tree);
58   ~TTreeDraw(){;}
59   TString  MakeSelection();
60   void    AddSelectionRange(const char *alias, const char*expr, Float_t min, Float_t max);
61   void    AddSelection(const char *alias, const char*expr);
62   void    AddDraw(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType);
63   //  TGCompositeFrame * MakeFrame();
64 public:
65   TTree     * fTree;          ///< tree
66   TObjArray   fCutAtoms;      ///< array of axpressions
67   TObjArray   fDraws;         ///< array of draw experssions
68 private:
69   TTreeDraw();
70   ClassDef(TTreeDraw,1)
71 };
72
73 ClassImp(TTreePoint)
74 ClassImp(TTreeCutAtom)
75 /// \cond CLASSIMP
76 ClassImp(TTreeDraw)
77 /// \endcond
78
79 TTreePoint::TTreePoint():
80   TNamed(),
81   fPx(),   // point X
82   fPy(),   // point Y
83   fPz(),   // point Z
84   fMColor(1), //color
85   fMSize(1),  //marker size
86   fMType(22),  //marker type
87   fIsOn(kTRUE)   //is On
88 {
89 }
90
91 TTreePoint::TTreePoint(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType)
92 :
93   TNamed(alias,alias),
94   fPx(px),   // point X
95   fPy(py),   // point Y
96   fPz(pz),   // point Z
97   fMColor(mColor), //color
98   fMSize(mSize),  //marker size
99   fMType(mType),  //marker type
100   fIsOn(kTRUE)   //is On
101 {
102 }
103
104
105 TTreeCutAtom::TTreeCutAtom():
106     TNamed(),
107     fVal0(0),
108     fVal1(0),
109     fType(kBool)
110 {
111   //
112   //
113   //
114 }
115
116 TTreeCutAtom::TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1):
117   TNamed(alias,expr),
118   fInt0(val0),
119   fInt1(val1),
120   fVal0(val0),
121   fVal1(val1),
122   fType(type)
123 {
124   //
125   //
126   //
127 }
128
129 TString TTreeCutAtom::GetSelection(){
130   //
131   //
132   //
133   TString str;
134   char  command[1000];
135   if (fType==kBool) str = fTitle;
136   if (fType==kInt){
137     sprintf(command,"(%s==%d)",GetTitle(), TMath::Nint(fVal0));
138     str = command;
139   }
140   if (fType==kRange){
141     sprintf(command,"((%s>%f) &&(%s<%f))",GetTitle(), fVal0,GetTitle(),fVal1);
142     str = command;
143   }
144   return str;
145 }
146
147
148 TTreeDraw::TTreeDraw():
149     TNamed(),
150     fTree(0),
151     fCutAtoms(0),
152     fDraws(0)
153 {
154 }
155
156 TTreeDraw::TTreeDraw(const char *name, TTree * tree):
157   TNamed(name,name),
158   fTree(tree),
159   fCutAtoms(100),
160   fDraws(100)
161 {
162 }
163
164 void    TTreeDraw::AddSelection(const char *alias, const char*expr){
165   //
166   // add string selection
167   //
168   TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kBool,0,1);
169   fCutAtoms.AddLast(atom);
170 }
171
172 void    TTreeDraw::AddSelectionRange(const char *alias, const char*expr, Float_t min, Float_t max){
173   //
174   //
175   //
176   TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kRange,min,max);
177   fCutAtoms.AddLast(atom);
178 }
179
180 TString  TTreeDraw::MakeSelection(){
181   //
182   // Make selection string
183   //
184   TString res;
185   for (Int_t i=0; i<fCutAtoms.GetEntries(); i++){
186     TTreeCutAtom * atom = (TTreeCutAtom*)fCutAtoms.At(i);
187     if (!atom) continue;
188     if (res.Length()>0) res+="&&";
189     res+=atom->GetSelection();
190   }
191   return res;
192 }