void buildPdf() { Double_t lorange = 100.; Double_t hirange = 140.; // Import data TFile *file = new TFile("/atlas/data18a/yupan/HZZ4l2012/MiniTree/data12.root"); TTree *tree = (TTree*)file->Get("tree_incl_4mu"); // should include all channels, for now just testing... // Define variables Float_t m4l = 0; Float_t m4lerr = 0; // Float_t wgt = 0; // Get number of entries and setbranchaddress Int_t nevents = tree->GetEntries(); tree->SetBranchStatus("*",0); tree->SetBranchStatus("m4l_unconstrained",1); tree->SetBranchStatus("m4lerr_unconstrained",1); //tree->SetBranchStatus("weight",1); tree->SetBranchAddress("m4l_unconstrained",&m4l); tree->SetBranchAddress("m4lerr_unconstrained",&m4lerr); //tree->SetBranchAddress("weight",&wgt); /////////////// // Build pdfs ////////////// RooRealVar* mass = new RooRealVar("m4l","mass",lorange,hirange,"GeV"); RooRealVar merr("m4lerr","mass err",0.1,4.0,"GeV"); //RooRealVar weight("weight","weight",0,10); RooRealVar scale("scale","per-event error scale factor",1.0,0.2,4.0); RooProduct sigmaErr("sigmaErr","sigmaErr",RooArgSet(scale,merr)); /* float totalwgt(0); for (Int_t i=0; i<nevents; i++) { tree->GetEntry(i); totalwgt+=wgt; } std::cout<<"total weight = "<<totalwgt<<std::endl; */ /// Make DataSet RooDataSet signal("signal","signal",RooArgSet(*mass,merr)); std::cout<<"Reading in events from signal minitree"<<std::endl; for (Int_t i=0; i<nevents; i++) { tree->GetEntry(i); mass->setVal(m4l); merr.setVal(m4lerr); //weight.setVal(wgt/totalwgt); signal.add(RooArgSet(*mass,merr)); } // Create 1D kernel estimation for signal mass std::cout<<"Building mass keys"<<std::endl; RooKeysPdf kestsig("kestsig","kestsig",*mass,signal); TH1F* hm = (TH1F*)kestsig.createHistogram("hm",*mass); kestsig.fillHistogram(hm,RooArgList(*mass)); std::cout<<"Building mass pdf"<<std::endl; RooDataHist* dmass = new RooDataHist("dmass","binned dataset",*mass,hm); RooHistPdf* masspdf = new RooHistPdf("masspdf","pdf(dm)",*mass,*dmass,2); // Create 1D kernel estimation for mass err std::cout<<"Building error keys"<<std::endl; RooKeysPdf kestsigerr("kestsigerr","kestsigerr",merr,signal,RooKeysPdf::MirrorBoth,2); TH1F* herr = (TH1F*)kestsigerr.createHistogram("herr",merr); kestsigerr.fillHistogram(herr,RooArgList(merr)); std::cout<<"Integral "<<herr->Integral()<<std::endl; std::cout<<"Building error pdf"<<std::endl; RooDataHist* derr = new RooDataHist("derr","binned dataset",merr,herr); RooHistPdf* errpdf = new RooHistPdf("errpdf","pdf(de)",merr,*derr,2); //Make the crystal ball resolution model with CB sigma = mass error RooRealVar meanCB ("meanCB", "mean CB", hmass, hmass-10., hmass+5.); RooRealVar alphaCB ("alphaCB", "alpha CB", 7, 0., 10.); RooRealVar nnCB ("nnCB", "nn CB", 1.5, 0., 15.); RooCBShape* shapeCB = new RooCBShape("shapeCB", "crystal ball pdf", *mass, meanCB, sigmaErr, alphaCB, nnCB); // Make conditional pdf RooProdPdf* sigmodel = new RooProdPdf("sigmodel","sigmodel", *errpdf, Conditional(*shapeCB, *mass)); // Make a workspace to store the fit model RooWorkspace* pdfWsp = new RooWorkspace("pdfWspCB"); pdfWsp->import(*sigmodel,RecycleConflictNodes()); pdfWsp->import(*masspdf); pdfWsp->import(*errpdf,RecycleConflictNodes()); pdfWsp->import(signal); pdfWsp->Print(); pdfWsp->writeToFile("pdfWspCB.root"); // Make some plots TCanvas *c = new TCanvas("c","c",500,500); c->Divide(2); RooPlot* frame = merr.frame(Title("keys signal error")); signal.plotOn(frame); kestsigerr.plotOn(frame,LineColor(kRed)); errpdf->plotOn(frame); RooPlot* frame2 = mass->frame(Title("keys signal")); signal.plotOn(frame2); kestsig.plotOn(frame2,LineColor(kRed)); masspdf->plotOn(frame2); c->cd(2); frame->Draw(); c->cd(1); grame2->Draw(); c->Print("testPdf.png"); }
void runUPWW() { int higgsMass=125; double intLumi=5.1; int nToys = 10; bool draw=true; using namespace RooFit; gROOT->ProcessLine(".L ~/tdrstyle.C"); setTDRStyle(); gStyle->SetPadLeftMargin(0.16); gROOT->ForceStyle(); gROOT->ProcessLine(".L statsFactory.cc+"); // // set up test kind // double sigRate; double bkgRate; if(higgsMass==125){ sigRate = 7.; bkgRate = 66.; }else{ cout << "HMMMM.... I don't know that mass point...BYE!" << endl; return; } RooRealVar* mll = new RooRealVar("mll","dilepton mass [GeV]", 12, 80.); mll->setBins(17); RooArgSet* obs = new RooArgSet(*mll) ; // read signal hypothesis 1 TChain *tsigHyp1 = new TChain("angles"); tsigHyp1->Add(Form("datafiles/bdtpresel/%i/SMHiggsWW_%i_JHU.root",higgsMass, higgsMass)); RooDataSet *sigHyp1Data = new RooDataSet("sigHyp1Data","sigHyp1Data",tsigHyp1,*obs); RooDataHist *sigHyp1Hist = sigHyp1Data->binnedClone(0); RooHistPdf* sigHyp1Pdf = new RooHistPdf("sigHyp1Pdf", "sigHyp1Pdf", *obs, *sigHyp1Hist); // read background TChain *bkgTree = new TChain("angles"); bkgTree->Add(Form("datafiles/bdtpresel/%i/WW_madgraph_8TeV.root",higgsMass)); RooDataSet *bkgData = new RooDataSet("bkgData","bkgData",bkgTree,*obs); RooDataHist *bkgHist = bkgData->binnedClone(0); RooHistPdf* bkgPdf = new RooHistPdf("bkgPdf", "bkgPdf", *obs, *bkgHist); char statResults[25]; statsFactory *hwwuls; sprintf(statResults,"uls_hww125_%.0ffb.root", intLumi); hwwuls = new statsFactory(obs, sigHyp1Pdf, sigHyp1Pdf, statResults); hwwuls->runUpperLimitWithBackground(sigRate*intLumi, bkgRate*intLumi, bkgPdf, nToys); delete hwwuls; // draw plots if(draw) { RooPlot* plot1 = mll->frame(); TString plot1Name = "mll"; TCanvas* c1 = new TCanvas("c1","c1",400,400); bkgData->plotOn(plot1,MarkerColor(kBlack)); bkgPdf->plotOn(plot1, LineColor(kBlack), LineStyle(kDashed)); sigHyp1Data->plotOn(plot1,MarkerColor(kRed)); sigHyp1Pdf->plotOn(plot1,LineColor(kRed), LineStyle(kDashed)); // draw... plot1->Draw(); c1->SaveAs(Form("plots/ul/epsfiles/%s.eps", plot1Name.Data())); c1->SaveAs(Form("plots/ul/pngfiles/%s.png", plot1Name.Data())); delete c1; } }
void runSigSepWWSingle(int higgsMass, double intLumi, int nToys, const TestType test, int var, int toy, bool draw, const unsigned int seed) { // location of data // for ucsd batch submission const char *dataLocation = "root://xrootd.unl.edu//store/user/yygao/HWWAngular/datafiles/"; // for local tests // const char *dataLocation = "datafiles/"; // // set up test kind // TString testName = getTestName(test); TString varName = getVarName(var); TString toyName = getToyName(toy); std::cout << "Doing " << toyName << " studies on " << testName << " separation based on " << varName << "\n"; double lowMt(0.); double highMt = higgsMass; double sigRate; double bkgRate; if(higgsMass==125){ sigRate = 13.0; bkgRate = 155.; }else{ cout << "HMMMM.... I don't know that mass point...BYE!" << endl; return; } RooRealVar* dphill = new RooRealVar("dphill","#Delta#phi(leptons) [radian]", 0, TMath::Pi()); dphill->setBins(20); RooRealVar* mt = new RooRealVar("mt","transverse higgs mass", 60, 130); mt->setBins(10); RooRealVar* mll = new RooRealVar("mll","dilepton mass [GeV]", 10, 90.); mll->setBins(10); RooArgSet* obs; if ( var == DPHI ) obs = new RooArgSet(*dphill) ; if ( var == MLL ) obs = new RooArgSet(*mll) ; if ( var == MLLMT ) obs = new RooArgSet(*mll, *mt) ; if ( var == DPHIMT ) obs = new RooArgSet(*dphill, *mt) ; // // read signal hypothesis 1 always SMHiggs // TChain *tsigHyp1 = new TChain("angles"); tsigHyp1->Add(Form("%s/%i/SMHiggsWW_%i_JHU.root", dataLocation, higgsMass, higgsMass)); RooDataSet *sigHyp1Data = new RooDataSet("sigHyp1Data","sigHyp1Data",tsigHyp1,*obs); RooDataHist *sigHyp1Hist = sigHyp1Data->binnedClone(0); RooHistPdf* sigHyp1Pdf = new RooHistPdf("sigHyp1Pdf", "sigHyp1Pdf", *obs, *sigHyp1Hist); // read signal hypothesis 2 TChain *tsigHyp2 = new TChain("angles"); TString secondhypName = getSecondHypInputName(test, float(higgsMass)); tsigHyp2->Add(Form("%s/%i/%s",dataLocation, higgsMass, secondhypName.Data())); std::cout << secondhypName << "\n"; RooDataSet *sigHyp2Data = new RooDataSet("sigHyp2Data","sigHyp2Data",tsigHyp2,*obs); RooDataHist *sigHyp2Hist = sigHyp2Data->binnedClone(0); RooHistPdf* sigHyp2Pdf = new RooHistPdf("sigHyp2Pdf", "sigHyp2Pdf", *obs, *sigHyp2Hist); // read background TChain *bkgTree = new TChain("angles"); bkgTree->Add(Form("%s/%i/WW_madgraph_8TeV_0j.root",dataLocation,higgsMass)); RooDataSet *bkgData = new RooDataSet("bkgData","bkgData",bkgTree,*obs); RooDataHist *bkgHist = bkgData->binnedClone(0); RooHistPdf* bkgPdf = new RooHistPdf("bkgPdf", "bkgPdf", *obs, *bkgHist); char statResults[50]; statsFactory *myHypothesisSeparation; sprintf(statResults,"stat_%s_%s_%s_%.0ffb_%u.root",testName.Data(), toyName.Data(), varName.Data(), intLumi, seed); printf(statResults); myHypothesisSeparation = new statsFactory(obs, sigHyp1Pdf, sigHyp2Pdf, seed, statResults); // running pure toys myHypothesisSeparation->hypothesisSeparationWithBackground(sigRate*intLumi,sigRate*intLumi,nToys,bkgPdf,bkgRate*intLumi); delete myHypothesisSeparation; std::cout << "deleted myHypothesisSeparation" << std::endl; // draw plots if(draw) { RooPlot* plot1; TString plot1Name; TCanvas* c1 = new TCanvas("c1","c1",400,400); if ( var == DPHIMT || var == DPHI) { plot1 = dphill->frame(); plot1Name = Form("MELAproj_%s_%s_%s_dphi", testName.Data(), toyName.Data(), varName.Data()); } if ( var == MLL || var == MLLMT) { plot1 = mll->frame(); plot1Name = Form("MELAproj_%s_%s_%s_mll", testName.Data(), toyName.Data(), varName.Data()); } bkgData->plotOn(plot1,MarkerColor(kBlack)); bkgPdf->plotOn(plot1, LineColor(kBlack), LineStyle(kDashed)); sigHyp1Data->plotOn(plot1,MarkerColor(kRed)); sigHyp1Pdf->plotOn(plot1,LineColor(kRed), LineStyle(kDashed)); sigHyp2Data->plotOn(plot1,MarkerColor(kBlue)); sigHyp2Pdf->plotOn(plot1,LineColor(kBlue), LineStyle(kDashed)); // draw... plot1->Draw(); c1->SaveAs(Form("plots/epsfiles/%s.eps", plot1Name.Data())); c1->SaveAs(Form("plots/pngfiles/%s.png", plot1Name.Data())); if ( var == DPHIMT || var == MLLMT ) { RooPlot* plot2 = mt->frame(); TString plot2Name; plot2Name = Form("MELAproj_%s_%s_%s_mt", testName.Data(), toyName.Data(), varName.Data()); bkgData->plotOn(plot2,MarkerColor(kBlack)); bkgPdf->plotOn(plot2, LineColor(kBlack), LineStyle(kDashed)); sigHyp1Data->plotOn(plot2,MarkerColor(kRed)); sigHyp1Pdf->plotOn(plot2,LineColor(kRed), LineStyle(kDashed)); sigHyp2Data->plotOn(plot2,MarkerColor(kBlue)); sigHyp2Pdf->plotOn(plot2,LineColor(kBlue), LineStyle(kDashed)); c1->Clear(); plot2->Draw(); c1->SaveAs(Form("plots/epsfiles/%s.eps", plot2Name.Data())); c1->SaveAs(Form("plots/pngfiles/%s.png", plot2Name.Data())); } delete c1; delete plot1; delete plot2; } // tidy up delete dphill; delete mt; delete mll; delete obs; delete tsigHyp1; delete sigHyp1Data; delete sigHyp1Pdf; delete tsigHyp2; delete sigHyp2Data; delete sigHyp2Pdf; delete bkgTree; delete bkgData; delete bkgPdf; delete myHypothesisSeparation; }