Adding new classes for numerical debugging
authormarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 15 Jun 2008 15:20:27 +0000 (15:20 +0000)
committermarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 15 Jun 2008 15:20:27 +0000 (15:20 +0000)
(TTreeSelection and AliEveTree)

AliMagFDraw - class for magnetic filed visualization + fitting

(Marian Ivanov)

TPC/macros/AliEveTree.C [new file with mode: 0644]
TPC/macros/AliMagFDraw.cxx [new file with mode: 0644]
TPC/macros/TTreeSelection.cxx [new file with mode: 0644]

diff --git a/TPC/macros/AliEveTree.C b/TPC/macros/AliEveTree.C
new file mode 100644 (file)
index 0000000..33cf5b5
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+
+  .L $ALICE_ROOT/TPC/macros/AliEveTree.C+
+  MakeEveTree();
+  
+  TFile fesd("AliESDs.root");
+  TTree * treeESD = (TTree*)fesd.Get("esdTree");
+
+
+
+  TFile ftpc("TPCdebug.root");
+  TFile fits("ITSdebug.root");
+  TTree * treeTPC = (TTree*)ftpc.Get("Transform");
+  TTree * treeITS = (TTree*)fits.Get("Clusters");
+    
+  treeTPC->Draw("gx2/sqrt(gx0^2+gx1^2):sqrt(gx0^2+gx1^2)>>his(100,0,200,100,-1,1)","event==4","")
+  treeITS->Draw("gz/sqrt(gx^2+gy^2):sqrt(gx^2+gy^2)>>his(100,0,200,100,-1,1)","event==4","same")
+  
+  treeTPC->Draw("atan2(gx1,gx0):sqrt(gx0^2+gx1^2)>>his(100,0,200,100,-1,1)","event==4","*")
+  treeITS->Draw("atan2(gy,gx):sqrt(gx^2+gy^2)>>his(100,0,200,100,-1,1)","event==4","same*");
+
+*/
+#include "TFile.h"
+#include "TTree.h"
+#include "TTreeStream.h"
+#include "TPolyMarker3D.h"
+#include "TVectorD.h"
+
+#include "AliESDEvent.h"
+#include "AliESDtrack.h"
+#include "AliESDfriendTrack.h"
+#include "AliTrackPointArray.h"
+
+
+AliTrackPointArray* MakeArray(TPolyMarker3D *pol);
+void MakeESDTree(AliESDEvent*esd, TTreeSRedirector &cstream);
+
+void MakeEveTree(){
+  TFile fesd("AliESDs.root");
+  TTree * esdTree = (TTree*)fesd.Get("esdTree");
+  AliESDEvent cesd; 
+  esdTree->SetBranchStatus("*",kTRUE);
+  cesd.ReadFromTree(esdTree);
+  TTreeSRedirector cstream("eveTree.root");
+  for (Int_t ievent=0; ievent<esdTree->GetEntries();ievent++) {
+    //cout<<endl<<endl<<"********* Processing event number: "<<event<<"*******\n";
+    esdTree->GetEvent(ievent);
+    AliESDfriend *fESDfriend =  (AliESDfriend*)cesd.FindListObject("AliESDfriend");
+    cesd.SetESDfriend(fESDfriend);
+    MakeESDTree(&cesd,cstream);
+  }
+}
+
+
+void MakeESDTree(AliESDEvent*esd, TTreeSRedirector &cstream){
+  //
+  //
+  //
+  Float_t bz = esd->GetMagneticField();
+  //AliTPCseed dummyTPC;
+  //AliTPCseed dummyTRD;
+  for (Int_t i=0;i<esd->GetNumberOfTracks(); i++){
+    AliESDtrack * track = esd->GetTrack(i);
+    if (!track) continue;
+    TPolyMarker3D polA;
+    TPolyMarker3D polV;
+    TPolyMarker3D polI;
+    TPolyMarker3D polO;
+    //
+    AliTrackPointArray * arrayA=0;
+    AliTrackPointArray * arrayV=0;
+    AliTrackPointArray * arrayI=0;
+    AliTrackPointArray * arrayO=0;
+    //
+    if (track->GetInnerParam()) {
+      ((AliExternalTrackParam*)track->GetInnerParam())->FillPolymarker(&polA,bz,0,350,1);}
+    else{
+      track->FillPolymarker(&polA,bz,0,300,5);
+    }
+    arrayA=MakeArray(&polA);
+    track->FillPolymarker(&polV,bz,0,60,1);
+    arrayV=MakeArray(&polV);
+    if (track->GetInnerParam()) {
+      ((AliExternalTrackParam*)track->GetInnerParam())->FillPolymarker(&polI,bz,60,170,1);
+      arrayI = MakeArray(&polI);
+    }
+    if (track->GetOuterParam()) {
+      ((AliExternalTrackParam*)track->GetOuterParam())->FillPolymarker(&polO,bz,170,350,1);    
+      arrayO=MakeArray(&polO);
+    }
+    static  AliTrackPointArray cldummy(5);
+    AliTrackPointArray *clarray= &cldummy;
+    const AliESDfriendTrack *ftrack = track->GetFriendTrack();
+    if (ftrack && ftrack->GetTrackPointArray()) {
+      clarray=(AliTrackPointArray *)ftrack->GetTrackPointArray();
+    }
+    Int_t event = esd->GetEventNumberInFile();
+    Int_t id = track->GetID();
+    cstream<<"Tracks"<<
+      "eventNr="<<event<<
+      "trackNr="<<id<<
+      "Tr.="<<track<<
+      "Cl.="<<clarray<<
+      //
+      "pA.="<<&polA<<
+      "pV.="<<&polV<<
+      "pI.="<<&polI<<
+      "pO.="<<&polO<<
+      //
+      "aA.="<<arrayA<<
+      "aV.="<<arrayV<<
+      "aI.="<<arrayI<<
+      "aO.="<<arrayO<<
+      "\n";
+  }
+}
+
+
+
+AliTrackPointArray *MakeArray(TPolyMarker3D *pol){
+  //
+  // Make a aray of  points with errors
+  //
+  Int_t entries = pol->GetN();
+  AliTrackPointArray * array = new AliTrackPointArray(entries);
+  for (Int_t i=0;i<entries;i++){
+    Double_t xyz[3]={0,0,0};
+    pol->GetPoint(i,xyz[0],xyz[1],xyz[2]);
+    ((Float_t*)array->GetX())[i]=xyz[0];
+    ((Float_t*)array->GetY())[i]=xyz[1];
+    ((Float_t*)array->GetZ())[i]=xyz[2];
+  }
+  return array;
+}
+
diff --git a/TPC/macros/AliMagFDraw.cxx b/TPC/macros/AliMagFDraw.cxx
new file mode 100644 (file)
index 0000000..ef921b5
--- /dev/null
@@ -0,0 +1,283 @@
+/*
+
+  .L $ALICE_ROOT/TPC/macros/AliMagFDraw.cxx+
+  AliMagFDraw draw;
+  draw.RegisterField(0,new AliMagWrapCheb("Maps","Maps", 2, 1., 10., AliMagWrapCheb::k5kG));
+  draw.RegisterField(1,new AliMagFMaps("Maps","Maps", 2, 1., 10., 2));
+
+  TF2 fbz_rz_0pi("fbz_rz_0pi","AliMagFDraw::GetBz(x,0*pi,y)",0,250,-250,250);
+  fbz_rz_0pi->Draw("surf2");
+  
+  TF1 fbz_z_90_00pi("fbz_z_90_00pi","AliMagFDraw::GetBz(90,0*pi,x)",-250,250);
+  TF1 fbz_z_90_05pi("fbz_z_90_05pi","AliMagFDraw::GetBz(90,0.5*pi,x)",-250,250);
+  TF1 fbz_z_90_10pi("fbz_z_90_10pi","AliMagFDraw::GetBz(90,1.0*pi,x)",-250,250);
+  TF1 fbz_z_90_15pi("fbz_z_90_15pi","AliMagFDraw::GetBz(90,1.5*pi,x)",-250,250);
+  fbz_z_90_00pi->SetLineColor(2);
+  fbz_z_90_05pi->SetLineColor(3);
+  fbz_z_90_10pi->SetLineColor(4);
+  fbz_z_90_15pi->SetLineColor(5);
+  fbz_z_90_00pi->Draw()
+  fbz_z_90_05pi->Draw("same")
+  fbz_z_90_15pi->Draw("same")
+  fbz_z_90_10pi->Draw("same")
+  
+
+  TF1 fbr_z_90_00pi("fbz_z_90_00pi","AliMagFDraw::GetBr(90,0*pi,x)",-250,250);
+  TF1 fbr_z_90_05pi("fbz_z_90_05pi","AliMagFDraw::GetBr(90,0.5*pi,x)",-250,250);
+  TF1 fbr_z_90_10pi("fbz_z_90_10pi","AliMagFDraw::GetBr(90,1.0*pi,x)",-250,250);
+  TF1 fbr_z_90_15pi("fbz_z_90_15pi","AliMagFDraw::GetBr(90,1.5*pi,x)",-250,250);
+  fbr_z_90_00pi->SetLineColor(2);
+  fbr_z_90_05pi->SetLineColor(3);
+  fbr_z_90_10pi->SetLineColor(4);
+  fbr_z_90_15pi->SetLineColor(5);
+  fbr_z_90_00pi->Draw()
+  fbr_z_90_05pi->Draw("same")
+  fbr_z_90_15pi->Draw("same")
+  fbr_z_90_10pi->Draw("same")
+
+  //
+  TF2 fbz_xy_0z("fbz_xy_0z","AliMagFDraw::GetBz(sqrt(x^2+y^2),atan2(y,x),0)",-250,250,-250,250);
+  fbz_xy_0z.SetNpy(100);
+  fbz_xy_0z.SetNpx(100);
+  fbz_xy_0z->Draw("colz");
+  //
+  TF2 fbz_xy_250z("fbz_xy_250z","AliMagFDraw::GetBz(sqrt(x^2+y^2),atan2(y,x),250)",-250,250,-250,250);
+  fbz_xy_250z.SetNpy(100);
+  fbz_xy_250z.SetNpx(100)
+  fbz_xy_250z->Draw("colz");
+  //
+   TF2 fbz_xy_m250z("fbz_xy_m250z","AliMagFDraw::GetBz(sqrt(x^2+y^2),atan2(y,x),-250)",-250,250,-250,250);
+  fbz_xy_m250z.SetNpy(100);
+  fbz_xy_m250z.SetNpx(100)
+  fbz_xy_m250z->Draw("colz");
+  //
+
+
+*/
+#include "TObjArray.h"
+#include "TMath.h"
+#include "AliMagF.h"
+#include "TLinearFitter.h"
+#include "TString.h"
+
+class AliMagFDraw  : public AliMagF
+{
+public:
+  AliMagFDraw():AliMagF(){}
+  static  void RegisterField(Int_t index, AliMagF * magf);
+  static  Double_t GetBx(Double_t r, Double_t phi, Double_t z,Int_t index=0);
+  static  Double_t GetBy(Double_t r, Double_t phi, Double_t z,Int_t index=0);
+  static  Double_t GetBz(Double_t r, Double_t phi, Double_t z,Int_t index=0);
+  static  Double_t GetBr(Double_t r, Double_t phi, Double_t z,Int_t index=0);
+  static  Double_t GetBrfi(Double_t r, Double_t phi, Double_t z,Int_t index=0);
+  //static  Double_t GetBr2(Double_t r, Double_t phi, Double_t z,Int_t index=0);
+  //static  Double_t GetBrfi2(Double_t r, Double_t phi, Double_t z,Int_t index=0);
+  static  TObjArray *Fit(const char *formula, Int_t index=0);
+public:
+  static TObjArray   fgArray;
+  ClassDef(AliMagFDraw,2) 
+};
+
+
+ClassImp(AliMagFDraw)
+
+
+TObjArray   AliMagFDraw::fgArray;
+
+void AliMagFDraw::RegisterField(Int_t index, AliMagF * magf){
+  //
+  // add the filed to the list
+  //
+  fgArray.AddAt(magf,index);
+}
+
+Double_t AliMagFDraw::GetBz(Double_t r, Double_t phi, Double_t z,Int_t index){
+  //
+  // 
+  //
+  AliMagF *mag = (AliMagF*)fgArray.At(index);
+  if (!mag) return 0;
+  Float_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
+  //  xyz[1]+=30;
+  Float_t bxyz[3];
+  mag->Field(xyz,bxyz);
+  return bxyz[2];
+}  
+
+Double_t AliMagFDraw::GetBy(Double_t r, Double_t phi, Double_t z,Int_t index){
+  //
+  // 
+  //
+  AliMagF *mag = (AliMagF*)fgArray.At(index);
+  if (!mag) return 0;
+  Float_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
+  //  xyz[1]+=30;
+  Float_t bxyz[3];
+  mag->Field(xyz,bxyz);
+  return bxyz[1];
+}  
+
+
+Double_t AliMagFDraw::GetBx(Double_t r, Double_t phi, Double_t z,Int_t index){
+  //
+  // 
+  //
+  AliMagF *mag = (AliMagF*)fgArray.At(index);
+  if (!mag) return 0;
+  Float_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
+  //  xyz[1]+=30;
+  Float_t bxyz[3];
+  mag->Field(xyz,bxyz);
+  return bxyz[0];
+}  
+
+
+
+
+Double_t AliMagFDraw::GetBr(Double_t r, Double_t phi, Double_t z,Int_t index){
+  //
+  // 
+  //
+  AliMagF *mag = (AliMagF*)fgArray.At(index);
+  if (!mag) return 0;
+  Float_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
+  //xyz[1]+=30;
+  Float_t bxyz[3];
+  mag->Field(xyz,bxyz);
+  if (r==0) return 0;
+  Float_t br = bxyz[0]*xyz[0]/r+bxyz[1]*xyz[1]/r;
+  return br;
+}  
+
+Double_t AliMagFDraw::GetBrfi(Double_t r, Double_t phi, Double_t z,Int_t index){
+  //
+  // 
+  //
+  AliMagF *mag = (AliMagF*)fgArray.At(index);
+  if (!mag) return 0;
+  Float_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
+  //xyz[1]+=30;
+  Float_t bxyz[3];
+  mag->Field(xyz,bxyz);
+  if (r==0) return 0;
+  Float_t br = -bxyz[0]*xyz[1]/r+bxyz[1]*xyz[0]/r;
+  return br;
+}  
+
+
+TObjArray * AliMagFDraw::Fit(const char *formula, Int_t index){
+  //
+  /*
+    formula="1++x+x^2++cos(y)++cos(y)^2++z++z^2"
+    index=0
+  */
+  //
+  TObjArray *fstrings = TString(formula).Tokenize("++");
+  Int_t ndim = fstrings->GetEntries();
+  TObjArray *formulas = new TObjArray(ndim);
+  for (Int_t i=0;i<ndim;i++){
+    formulas->AddAt(new TFormula(Form("fff_%d",i),fstrings->At(i)->GetName()),i);                  
+  }  
+  TLinearFitter * fitR   = new TLinearFitter(ndim+1,Form("hyp%d",ndim));
+  TLinearFitter * fitRFI = new TLinearFitter(ndim+1,Form("hyp%d",ndim));
+  TLinearFitter * fitZ   = new TLinearFitter(ndim+1,Form("hyp%d",ndim));
+  Double_t x[ndim];    
+  for (Float_t r=20; r<250;r+=20){
+    for (Float_t fi=0; fi<TMath::Pi()*2;fi+=0.2){
+      for (Float_t z=-250; z<250;z+=20){
+       for (Int_t ifor=0;ifor<ndim;ifor++){
+         x[ifor]= ((TFormula*)formulas->At(ifor))->Eval(r/250.,fi,z/250.);
+       }
+       fitR->AddPoint(x,AliMagFDraw::GetBr(r,fi,z,index));
+       fitRFI->AddPoint(x,AliMagFDraw::GetBrfi(r,fi,z,index));
+       fitZ->AddPoint(x,AliMagFDraw::GetBz(r,fi,z,index));     
+      }
+    }
+  }
+  fitR->Eval();  
+  fitRFI->Eval();  
+  fitZ->Eval();  
+  TObjArray *res = new TObjArray; 
+  res->AddAt(fitR,0);
+  res->AddAt(fitRFI,1);
+  res->AddAt(fitZ,2);
+  printf("\tchi2\tn\tRMS\n");
+  printf("\t%f\t%d\t%f\n",fitR->GetChisquare(),fitR->GetNpoints(),TMath::Sqrt(fitR->GetChisquare()/fitR->GetNpoints()));
+  printf("\t%f\t%d\t%f\n",fitRFI->GetChisquare(),fitRFI->GetNpoints(),TMath::Sqrt(fitRFI->GetChisquare()/fitRFI->GetNpoints()));
+  printf("\t%f\t%d\t%f\n",fitZ->GetChisquare(),fitZ->GetNpoints(),TMath::Sqrt(fitZ->GetChisquare()/fitZ->GetNpoints()));
+
+  TFormula * funBZ = new TFormula("funBZ",formula);
+  TFormula * funBR = new TFormula("funBR",formula);
+  TFormula * funBRFI = new TFormula("funBRFI",formula);
+  TVectorD vec;
+  fitR->GetParameters(vec);
+  funBR->SetParameters(vec.GetMatrixArray());
+  fitRFI->GetParameters(vec);
+  funBRFI->SetParameters(vec.GetMatrixArray());
+  fitZ->GetParameters(vec);
+  funBZ->SetParameters(vec.GetMatrixArray());
+
+  return res;
+}
+
+
+TString MakeString(){
+  TString str="";
+  {
+    Int_t counter=0;
+    for (Int_t ix=0;ix<3;ix++)
+      for (Int_t iz=0;iz<3;iz++){
+       if (ix+iz>0) {
+         str+=Form("x^%d*z^%d++",ix,iz);
+         printf("x^%d*z^%d++\n",ix,iz);
+       }
+       for (Int_t iy=1;iy<4;iy++){
+         if (ix+iz+iy==0) continue;
+         str+=Form("x^%d*z^%d*sin(y*%d)++",ix,iz,iy);
+         str+=Form("x^%d*z^%d*cos(y*%d)++",ix,iz,iy);
+         printf(   "x^%d*z^%d*sin(y*%d)++\n",ix,iz,iy);
+         printf(   "x^%d*z^%d*cos(y*%d)++\n",ix,iz,iy);
+         counter++;
+       }
+      }
+    str[str.Length()-2]=0;
+  }
+  return str;
+}
+
+
+
+/*
+
+TObjArray * array = AliMagFDraw::Fit("x",0)
+//
+chi2    n       RMS
+15.534116       9600    0.040226
+4.422160        9600    0.021463
+8.378622        9600    0.029543
+
+TObjArray * array = AliMagFDraw::Fit("x++z++z^2++x*sin(y)++x*cos(y)++z*x*sin(y)++z*x*cos(y)++z^2*x*sin(y)++z^2*x*cos(y)++z^2*x*sin(y)^2++z^2*x*cos(y)^2++z^3*x*sin(y)^2++z^3*x*cos(y)^2",0);
+chi2    n       RMS
+1.842443        9600    0.013854
+0.957056        9600    0.009985
+0.097799        9600    0.003192
+
+TObjArray * array = AliMagFDraw::Fit("x++z++z^2++x*sin(y)++x*cos(y)++z*x*sin(y)++z*x*cos(y)++z^2*x*sin(y)++z^2*x*cos(y)++z^2*x*sin(y)^2++z^2*x*cos(y)^2++z^3*x*sin(y)^2++z^3*x*cos(y)++z^3*sin(y)++z^3*cos(y)++z^3*x*cos(y)++z^2*sin(y)++z^2*cos(y)++z*sin(y)++z*cos(y)++sin(y)++cos(y)",0);
+
+chi2    n       RMS
+1.564687        9600    0.012767
+0.002291        9600    0.000489
+0.097063        9600    0.003180
+
+
+TObjArray * array = AliMagFDraw::Fit(MakeString(),0);
+
+chi2    n       RMS
+0.000303        9600    0.000178
+0.000066        9600    0.000083
+0.003110        9600    0.000569
+
+
+}
+*/
+
diff --git a/TPC/macros/TTreeSelection.cxx b/TPC/macros/TTreeSelection.cxx
new file mode 100644 (file)
index 0000000..c3dbe1a
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+
+.L $ALICE_ROOT/TPC/macros/TTreeSelection.cxx++
+
+TFile f("eveTree.root");
+Tracks;
+
+TTreeDraw draw("draw",Tracks);
+draw.AddSelection("TPC clusters","Tr.fTPCncls>0");
+draw.AddSelection("TRD clusters","Tr.fTRDncls>0");
+
+*/
+
+#include "TMath.h"
+#include "TFile.h"
+#include "TTree.h"
+#include "TTreeStream.h"
+#include "TPolyMarker3D.h"
+#include "TVectorD.h"
+#include "TObjString.h"
+
+
+class TTreePoint: public TNamed{
+public: 
+  TTreePoint();
+  TTreePoint(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType);
+  //  TString GetSelection();
+public:
+  TString fPx;   // point X
+  TString fPy;   // point Y
+  TString fPz;   // point Z
+  Int_t   fMColor; //color
+  Int_t   fMSize;  //marker size
+  Int_t   fMType;  //marker type 
+  Bool_t  fIsOn;   //is On 
+  ClassDef(TTreePoint,1)
+};
+
+
+class TTreeCutAtom: public TNamed{
+public: 
+  enum ExprType { kBool=0, kInt=1, kRange=2};
+  TTreeCutAtom();
+  TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1=0);
+  TString GetSelection();
+public:
+  Double_t   fInt0;    // interval  value 0
+  Double_t   fInt1;    // interval  value 1
+  Double_t   fVal0;    // selection value 0
+  Double_t   fVal1;    // selection value 1
+  ExprType   fType;    // selection type
+  ClassDef(TTreeCutAtom,1)
+};
+
+class TTreeDraw: public TNamed{
+public:
+  TTreeDraw(const char *name, TTree * tree);
+  ~TTreeDraw(){;}
+  TString  MakeSelection();
+  void    AddSelectionRange(const char *alias, const char*expr, Float_t min, Float_t max);
+  void    AddSelection(const char *alias, const char*expr);
+  void    AddDraw(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType);
+  //  TGCompositeFrame * MakeFrame();
+public:
+  TTree     * fTree;          // tree
+  TObjArray   fCutAtoms;      // array of axpressions
+  TObjArray   fDraws;         // array of draw experssions
+private:  
+  TTreeDraw();
+  ClassDef(TTreeDraw,1)
+};
+
+ClassImp(TTreePoint)
+ClassImp(TTreeCutAtom)
+ClassImp(TTreeDraw)
+
+TTreePoint::TTreePoint(): 
+  TNamed(),
+  fPx(),   // point X
+  fPy(),   // point Y
+  fPz(),   // point Z
+  fMColor(1), //color
+  fMSize(1),  //marker size
+  fMType(22),  //marker type 
+  fIsOn(kTRUE)   //is On 
+{
+}
+
+TTreePoint::TTreePoint(const char *alias, const char * px, const char * py, const char *pz, Int_t mColor, Int_t mSize, Int_t mType)
+: 
+  TNamed(alias,alias),
+  fPx(px),   // point X
+  fPy(py),   // point Y
+  fPz(pz),   // point Z
+  fMColor(mColor), //color
+  fMSize(mSize),  //marker size
+  fMType(mType),  //marker type 
+  fIsOn(kTRUE)   //is On 
+{
+}
+
+
+TTreeCutAtom::TTreeCutAtom():
+    TNamed(),
+    fVal0(0),
+    fVal1(0),
+    fType(kBool)
+{
+  //
+  //
+  //  
+}
+
+TTreeCutAtom::TTreeCutAtom(const char *alias, const char *expr, ExprType type, Double_t val0, Double_t val1):
+  TNamed(alias,expr),
+  fInt0(val0),
+  fInt1(val1),
+  fVal0(val0),
+  fVal1(val1),
+  fType(type)
+{
+  //
+  //
+  //  
+}
+
+TString TTreeCutAtom::GetSelection(){
+  //
+  // 
+  //
+  TString str;
+  char  command[1000];
+  if (fType==kBool) str = fTitle;
+  if (fType==kInt){
+    sprintf(command,"(%s==%d)",GetTitle(), TMath::Nint(fVal0)); 
+    str = command;
+  }
+  if (fType==kRange){
+    sprintf(command,"((%s>%f) &&(%s<%f))",GetTitle(), fVal0,GetTitle(),fVal1); 
+    str = command;
+  }
+  return str;
+}
+      
+
+TTreeDraw::TTreeDraw():
+    TNamed(),
+    fTree(0),
+    fCutAtoms(0),
+    fDraws(0)
+{
+}
+
+TTreeDraw::TTreeDraw(const char *name, TTree * tree):
+  TNamed(name,name),
+  fTree(tree),
+  fCutAtoms(100),
+  fDraws(100)
+{
+}
+
+void    TTreeDraw::AddSelection(const char *alias, const char*expr){
+  //
+  // add string selection
+  //
+  TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kBool,0,1);
+  fCutAtoms.AddLast(atom);
+}
+
+void    TTreeDraw::AddSelectionRange(const char *alias, const char*expr, Float_t min, Float_t max){
+  //
+  //
+  //  
+  TTreeCutAtom * atom = new TTreeCutAtom(alias,expr,TTreeCutAtom::kRange,min,max);
+  fCutAtoms.AddLast(atom);
+}
+
+TString  TTreeDraw::MakeSelection(){
+  //
+  // Make selection string
+  //
+  TString res;
+  for (Int_t i=0; i<fCutAtoms.GetEntries(); i++){
+    TTreeCutAtom * atom = (TTreeCutAtom*)fCutAtoms.At(i);
+    if (!atom) continue;
+    if (res.Length()>0) res+="&&";
+    res+=atom->GetSelection();
+  }
+  return res;
+}