#include #include #include #include #include #include #include #include "TChain.h" #include "TFile.h" #include "TTree.h" #include "TString.h" #include "TObjString.h" #include "TSystem.h" #include "TROOT.h" #include "TCanvas.h" #include "RooRealVar.h" #include "RooConstVar.h" #include "RooGaussian.h" #include "RooArgusBG.h" #include "RooAddPdf.h" #include "RooDataSet.h" #include "RooPlot.h" using namespace RooFit; void tester() { // Declare observable RooRealVar x("x","x",-10,10) ; // Construction a gaussian pdf RooRealVar mean1("mean1","mean1",-2.0,-2.0,-2.0); RooRealVar mean2("mean2","mean2", 2.0, 2.0, 2.0); RooRealVar sigma1("sigma1","sigma1",1.0,1.0,1.0); RooRealVar sigma2("sigma2","sigma2",1.0,1.0,1.0); RooGaussian gauss1("gauss1","gauss1",x,mean1,sigma1); RooGaussian gauss2("gauss2","gauss2",x,mean2,sigma2); // Sampling events RooDataSet* data1 = gauss1.generate(x,1000); RooDataSet* data2 = gauss2.generate(x,1000); TCanvas* a = new TCanvas("a"); a->cd(); RooPlot* plot = x.frame(); data1->plotOn(plot); data2->plotOn(plot); plot->SetTitle("raw data"); plot->Draw(); RooRealVar scale("scale","scale",0.1,0.0,100.); // Defining the varset RooArgSet varsetWithWeight(x, scale); // Make a master RooDataSet to add the intermediate ones to RooDataSet ds_global_MC("ds_global_MC", "ds_global_MC", varsetWithWeight, WeightVar(scale)); ds_global_MC.Print("V"); // Not a loop, but doing exactly what the loop code would have done // "Loop" 1 std::cout << "\n\nFirst dataset:" << std::endl; scale.setVal(0.); RooDataSet* ds_local_MC1 = new RooDataSet("k", "k", varsetWithWeight, Import(*data1), WeightVar(scale)); RooRealVar* w1 = (RooRealVar*) ds_local_MC1->addColumn(scale); std::cout << "After appending weight column:" << std::endl; ds_local_MC1->Print("V"); ds_global_MC.append(*ds_local_MC1); std::cout <<"\nGlobal DS is:" << std::endl; ds_global_MC.get(0); ds_global_MC.Print("V"); std::cout << "Weight is " << ds_global_MC.weight() << std::endl; // "Loop" 2 std::cout << "\n\nSecond dataset:" << std::endl; scale.setVal(1.); RooDataSet* ds_local_MC2 = new RooDataSet("k", "k", varsetWithWeight, Import(*data2), WeightVar(scale)); RooRealVar* w2 = (RooRealVar*) ds_local_MC2->addColumn(scale); ds_global_MC.append(*ds_local_MC2); std::cout <<"\nGlobal DS is:" << std::endl; ds_global_MC.get(1001); ds_global_MC.Print("V"); std::cout << "Weight is " << ds_global_MC.weight() << std::endl; // Making the final dataset TCanvas* b = new TCanvas("b"); b->cd(); RooPlot* plot2 = x.frame(); ds_global_MC.plotOn(plot2); plot2->SetTitle("attempted scaled data"); plot2->Draw(); }