////////////////////////////////////////////////////////////////////////// // // 'DATA AND CATEGORIES' RooFit tutorial macro #401 // // Overview of advanced option for importing data from ROOT TTree and THx histograms // Basic import options are demonstrated in rf102_dataimport.C // // // 07/2008 - Wouter Verkerke // ///////////////////////////////////////////////////////////////////////// #ifndef __CINT__ #include "RooGlobalFunc.h" #endif #include "RooRealVar.h" #include "RooDataSet.h" #include "RooDataHist.h" #include "RooCategory.h" #include "RooGaussian.h" #include "RooConstVar.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" #include "TH1.h" #include "TTree.h" #include "TRandom.h" using namespace RooFit ; struct testst{ double px; double py; double pz; // int pi; }; TTree* makeTTree(bool usestruct) ; void rf401_importttreethx(bool usestruct) { TTree* tree = makeTTree(usestruct) ; RooRealVar px("xyz.x","xyz.x",-10,10) ; RooRealVar py("xyz.y","xyz.y",-10,10) ; RooRealVar pz("xyz.z","xyz.z",-10,10) ; RooDataSet ds("ds","ds",RooArgSet(px, py, pz),Import(*tree)) ; ds.Print() ; RooPlot* p1=px.frame(); ds.plotOn(p1); RooPlot* p2=py.frame(); ds.plotOn(p2); RooPlot* p3=pz.frame(); ds.plotOn(p3); new TCanvas(); p1->Draw(); new TCanvas(); p2->Draw(); new TCanvas(); p3->Draw(); } TTree* makeTTree(bool usestruct) { // Create ROOT TTree filled with a Gaussian distribution in x and a uniform distribution in y TTree* tree = new TTree("tree","tree") ; testst pxyz; if (usestruct) tree->Branch("xyz", &pxyz,"x/D:y/D:z/D") ; else { tree->Branch("xyz.x",&pxyz.px,"x/D") ; tree->Branch("xyz.y",&pxyz.py,"y/D") ; tree->Branch("xyz.z",&pxyz.pz,"z/D") ;\ } for (int i=0 ; i<10000 ; i++) { pxyz.px = gRandom->Gaus(0,3) ; pxyz.py = gRandom->Uniform()*30 - 15 ; pxyz.pz = gRandom->Gaus(0,5) ; tree->Fill() ; } return tree ; }