3 .L $ALICE_ROOT/TPC/macros/TTreeSelection.cxx++
5 TFile f("eveTree.root");
8 TTreeDraw draw("draw",Tracks);
9 draw.AddSelection("TPC clusters","Tr.fTPCncls>0");
10 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
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)
77 TTreePoint::TTreePoint():
83 fMSize(1), //marker size
84 fMType(22), //marker type
89 TTreePoint::TTreePoint(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType)
95 fMColor(mColor), //color
96 fMSize(mSize), //marker size
97 fMType(mType), //marker type
103 TTreeCutAtom::TTreeCutAtom():
114 TTreeCutAtom::TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1):
127 TString TTreeCutAtom::GetSelection(){
133 if (fType==kBool) str = fTitle;
135 sprintf(command,"(%s==%d)",GetTitle(), TMath::Nint(fVal0));
139 sprintf(command,"((%s>%f) &&(%s<%f))",GetTitle(), fVal0,GetTitle(),fVal1);
146 TTreeDraw::TTreeDraw():
154 TTreeDraw::TTreeDraw(const char *name, TTree * tree):
162 void TTreeDraw::AddSelection(const char *alias, const char*expr){
164 // add string selection
166 TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kBool,0,1);
167 fCutAtoms.AddLast(atom);
170 void TTreeDraw::AddSelectionRange(const char *alias, const char*expr, Float_t min, Float_t max){
174 TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kRange,min,max);
175 fCutAtoms.AddLast(atom);
178 TString TTreeDraw::MakeSelection(){
180 // Make selection string
183 for (Int_t i=0; i<fCutAtoms.GetEntries(); i++){
184 TTreeCutAtom * atom = (TTreeCutAtom*)fCutAtoms.At(i);
186 if (res.Length()>0) res+="&&";
187 res+=atom->GetSelection();