1 /// \class TTreeSelection
4 /// .L $ALICE_ROOT/TPC/macros/TTreeSelection.cxx++
6 /// TFile f("eveTree.root");
9 /// TTreeDraw draw("draw",Tracks);
10 /// draw.AddSelection("TPC clusters","Tr.fTPCncls>0");
11 /// draw.AddSelection("TRD clusters","Tr.fTRDncls>0");
17 #include "TTreeStream.h"
18 #include "TPolyMarker3D.h"
20 #include "TObjString.h"
23 class TTreePoint: public TNamed{
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();
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)
40 class TTreeCutAtom: public TNamed{
42 enum ExprType { kBool=0, kInt=1, kRange=2};
44 TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1=0);
45 TString GetSelection();
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)
55 class TTreeDraw: public TNamed{
57 TTreeDraw(const char *name, TTree * tree);
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();
65 TTree * fTree; ///< tree
66 TObjArray fCutAtoms; ///< array of axpressions
67 TObjArray fDraws; ///< array of draw experssions
74 ClassImp(TTreeCutAtom)
79 TTreePoint::TTreePoint():
85 fMSize(1), //marker size
86 fMType(22), //marker type
91 TTreePoint::TTreePoint(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType)
97 fMColor(mColor), //color
98 fMSize(mSize), //marker size
99 fMType(mType), //marker type
105 TTreeCutAtom::TTreeCutAtom():
116 TTreeCutAtom::TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1):
129 TString TTreeCutAtom::GetSelection(){
135 if (fType==kBool) str = fTitle;
137 sprintf(command,"(%s==%d)",GetTitle(), TMath::Nint(fVal0));
141 sprintf(command,"((%s>%f) &&(%s<%f))",GetTitle(), fVal0,GetTitle(),fVal1);
148 TTreeDraw::TTreeDraw():
156 TTreeDraw::TTreeDraw(const char *name, TTree * tree):
164 void TTreeDraw::AddSelection(const char *alias, const char*expr){
166 // add string selection
168 TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kBool,0,1);
169 fCutAtoms.AddLast(atom);
172 void TTreeDraw::AddSelectionRange(const char *alias, const char*expr, Float_t min, Float_t max){
176 TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kRange,min,max);
177 fCutAtoms.AddLast(atom);
180 TString TTreeDraw::MakeSelection(){
182 // Make selection string
185 for (Int_t i=0; i<fCutAtoms.GetEntries(); i++){
186 TTreeCutAtom * atom = (TTreeCutAtom*)fCutAtoms.At(i);
188 if (res.Length()>0) res+="&&";
189 res+=atom->GetSelection();