]>
Commit | Line | Data |
---|---|---|
5cdd5f7f | 1 | /* |
2 | ||
3 | .L $ALICE_ROOT/TPC/macros/TTreeSelection.cxx++ | |
4 | ||
5 | TFile f("eveTree.root"); | |
6 | Tracks; | |
7 | ||
8 | TTreeDraw draw("draw",Tracks); | |
9 | draw.AddSelection("TPC clusters","Tr.fTPCncls>0"); | |
10 | draw.AddSelection("TRD clusters","Tr.fTRDncls>0"); | |
11 | ||
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 | ClassImp(TTreeDraw) | |
76 | ||
77 | TTreePoint::TTreePoint(): | |
78 | TNamed(), | |
79 | fPx(), // point X | |
80 | fPy(), // point Y | |
81 | fPz(), // point Z | |
82 | fMColor(1), //color | |
83 | fMSize(1), //marker size | |
84 | fMType(22), //marker type | |
85 | fIsOn(kTRUE) //is On | |
86 | { | |
87 | } | |
88 | ||
89 | TTreePoint::TTreePoint(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType) | |
90 | : | |
91 | TNamed(alias,alias), | |
92 | fPx(px), // point X | |
93 | fPy(py), // point Y | |
94 | fPz(pz), // point Z | |
95 | fMColor(mColor), //color | |
96 | fMSize(mSize), //marker size | |
97 | fMType(mType), //marker type | |
98 | fIsOn(kTRUE) //is On | |
99 | { | |
100 | } | |
101 | ||
102 | ||
103 | TTreeCutAtom::TTreeCutAtom(): | |
104 | TNamed(), | |
105 | fVal0(0), | |
106 | fVal1(0), | |
107 | fType(kBool) | |
108 | { | |
109 | // | |
110 | // | |
111 | // | |
112 | } | |
113 | ||
114 | TTreeCutAtom::TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1): | |
115 | TNamed(alias,expr), | |
116 | fInt0(val0), | |
117 | fInt1(val1), | |
118 | fVal0(val0), | |
119 | fVal1(val1), | |
120 | fType(type) | |
121 | { | |
122 | // | |
123 | // | |
124 | // | |
125 | } | |
126 | ||
127 | TString TTreeCutAtom::GetSelection(){ | |
128 | // | |
129 | // | |
130 | // | |
131 | TString str; | |
132 | char command[1000]; | |
133 | if (fType==kBool) str = fTitle; | |
134 | if (fType==kInt){ | |
135 | sprintf(command,"(%s==%d)",GetTitle(), TMath::Nint(fVal0)); | |
136 | str = command; | |
137 | } | |
138 | if (fType==kRange){ | |
139 | sprintf(command,"((%s>%f) &&(%s<%f))",GetTitle(), fVal0,GetTitle(),fVal1); | |
140 | str = command; | |
141 | } | |
142 | return str; | |
143 | } | |
144 | ||
145 | ||
146 | TTreeDraw::TTreeDraw(): | |
147 | TNamed(), | |
148 | fTree(0), | |
149 | fCutAtoms(0), | |
150 | fDraws(0) | |
151 | { | |
152 | } | |
153 | ||
154 | TTreeDraw::TTreeDraw(const char *name, TTree * tree): | |
155 | TNamed(name,name), | |
156 | fTree(tree), | |
157 | fCutAtoms(100), | |
158 | fDraws(100) | |
159 | { | |
160 | } | |
161 | ||
162 | void TTreeDraw::AddSelection(const char *alias, const char*expr){ | |
163 | // | |
164 | // add string selection | |
165 | // | |
166 | TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kBool,0,1); | |
167 | fCutAtoms.AddLast(atom); | |
168 | } | |
169 | ||
170 | void TTreeDraw::AddSelectionRange(const char *alias, const char*expr, Float_t min, Float_t max){ | |
171 | // | |
172 | // | |
173 | // | |
174 | TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kRange,min,max); | |
175 | fCutAtoms.AddLast(atom); | |
176 | } | |
177 | ||
178 | TString TTreeDraw::MakeSelection(){ | |
179 | // | |
180 | // Make selection string | |
181 | // | |
182 | TString res; | |
183 | for (Int_t i=0; i<fCutAtoms.GetEntries(); i++){ | |
184 | TTreeCutAtom * atom = (TTreeCutAtom*)fCutAtoms.At(i); | |
185 | if (!atom) continue; | |
186 | if (res.Length()>0) res+="&&"; | |
187 | res+=atom->GetSelection(); | |
188 | } | |
189 | return res; | |
190 | } |