void fitSignalShapeW(int massBin,int id, int channels,int categ, int sample, /* float lumi, bool doSfLepton, */double rangeLow, double rangeHigh, double bwSigma, double fitValues[9], double fitErrors[9], double covQual[1]){ // ------ root settings --------- gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPadGridX(kFALSE); gStyle->SetPadGridY(kFALSE); //gStyle->SetOptStat("kKsSiourRmMen"); gStyle->SetOptStat("iourme"); //gStyle->SetOptStat("rme"); //gStyle->SetOptStat(""); gStyle->SetOptFit(11); gStyle->SetPadLeftMargin(0.14); gStyle->SetPadRightMargin(0.06); // ------------------------------ ROOT::Math::MinimizerOptions::SetDefaultTolerance( 1.E-7); stringstream FileName; //Insert the file here if(sample==1) FileName <<"root://lxcms03//data3/Higgs/150915/ZH125/ZZ4lAnalysis.root" ; else if(sample==2) FileName << "root://lxcms03//data3/Higgs/150915/WplusH125/ZZ4lAnalysis.root"; else if(sample==3) FileName << "root://lxcms03//data3/Higgs/150915/WminusH125/ZZ4lAnalysis.root"; else if(sample==4) FileName << "root://lxcms03//data3/Higgs/150915/ttH125/ZZ4lAnalysis.root"; else { cout << "Wrong sample." << endl; return; } cout << "Using " << FileName.str() << endl; TFile* ggFile = TFile::Open(FileName.str().c_str()); TTree* ggTree = (TTree*) ggFile->Get("ZZTree/candTree"); float m4l; Short_t z1flav, z2flav; float weight; Short_t nExtraLeptons; float ZZPt; Short_t nJets; Short_t nBTaggedJets; std::vector<float> * jetpt = 0; std::vector<float> * jeteta = 0; std::vector<float> * jetphi = 0; std::vector<float> * jetmass = 0; float jet30pt[10]; float jet30eta[10]; float jet30phi[10]; float jet30mass[10]; float Fisher; int nentries = ggTree->GetEntries(); //--- ggTree part ggTree->SetBranchAddress("ZZMass",&m4l); ggTree->SetBranchAddress("Z1Flav",&z1flav); ggTree->SetBranchAddress("Z2Flav",&z2flav); ggTree->SetBranchAddress("genHEPMCweight",&weight); ggTree->SetBranchAddress("nExtraLep",&nExtraLeptons); ggTree->SetBranchAddress("nCleanedJets",&nJets); ggTree->SetBranchAddress("nCleanedJetsPt30BTagged",&nBTaggedJets); ggTree->SetBranchAddress("DiJetFisher",&Fisher); ggTree->SetBranchAddress("JetPt",&jetpt); ggTree->SetBranchAddress("JetEta",&jeteta); ggTree->SetBranchAddress("JetPhi",&jetphi); ggTree->SetBranchAddress("JetMass",&jetmass); ggTree->SetBranchAddress("ZZPt",&ZZPt); //--- rooFit part double xMin,xMax,xInit; xInit = (double) massBin; xMin = rangeLow; xMax = rangeHigh ; cout << "Fit range: [" << xMin << " , " << xMax << "]. Init value = " << xInit << endl; TH1F *hmass = new TH1F("hmass","hmass",200,xMin,xMax); //--------- RooRealVar x("mass","m_{4l}",xInit,xMin,xMax,"GeV"); RooRealVar w("myW","myW",1.0,0.,1000.); RooArgSet ntupleVarSet(x,w); RooDataSet dataset("mass4l","mass4l",ntupleVarSet,WeightVar("myW")); for(int k=0; k<nentries; k++){ ggTree->GetEvent(k); int njet30 = 0; for (unsigned int ijet = 0; ijet < jetpt->size(); ijet++) { if ( (*jetpt)[ijet] > 30. ) { jet30pt[njet30] = (*jetpt)[ijet]; jet30eta[njet30] = (*jeteta)[ijet]; jet30phi[njet30] = (*jetphi)[ijet]; jet30mass[njet30] = (*jetmass)[ijet]; njet30++; } } int Cat = category(nExtraLeptons, ZZPt, m4l, njet30, nBTaggedJets, jet30pt, jet30eta, jet30phi,jet30mass, Fisher); if (categ >= 0 && categ != Cat ) continue; if(channels==0 && z1flav*z2flav != 28561) continue; if(channels==1 && z1flav*z2flav != 14641) continue; if (weight <= 0 ) cout << "Warning! Negative weight events" << endl; if(channels==2 && z1flav*z2flav != 20449) continue; ntupleVarSet.setRealValue("mass",m4l); ntupleVarSet.setRealValue("myW",weight); if(x.getVal()>xMin && x.getVal()<xMax) dataset.add(ntupleVarSet, weight); hmass->Fill(m4l); } //--------- cout << "dataset n entries: " << dataset.sumEntries() << endl; TCanvas *c1 = new TCanvas("c1","c1",725,725); c1->cd(); TPad *pad1 = new TPad("pad1","This is pad1",0.05,0.35,0.95,0.97); pad1->Draw(); TPad *pad2 = new TPad("pad2","This is pad2",0.05,0.02,0.95,0.35); pad2->Draw(); //--- double CrystalBall RooRealVar mean("bias","mean of gaussian",0,-5.,5.) ; RooRealVar sigma("sigma","width of gaussian",1.5,0.,30.); RooRealVar a1("a1","a1",1.46,0.5,5.); RooRealVar n1("n1","n1",1.92,0.,10.); RooRealVar a2("a2","a2",1.46,1.,10.); RooRealVar n2("n2","n2",20,1.,50.); RooDoubleCB DCBall("DCBall","Double Crystal ball",x,mean,sigma,a1,n1,a2,n2); if (channels== 1) mean.setVal(-1.); //--- Breit-Wigner float bwSigmaMax,bwSigmaMin; if(massBin<400) bwSigmaMin=bwSigmaMax=bwSigma; else { bwSigmaMin=bwSigma-20.; bwSigmaMax=bwSigma+20.; } RooRealVar mean3("mean3","mean3",xInit) ; RooRealVar sigma3("sigma3","width3",bwSigma,bwSigmaMin,bwSigmaMax); RooRealVar scale3("scale3","scale3 ",1.); RooRelBWUFParam bw("bw","bw",x,mean3,scale3); //Chebyshev-Polynomial RooRealVar A1("A1","A1",-1,-3,3.); RooRealVar A2("A2","A2",0.5,-3.,3.); RooChebychev BkgPDF("BkgPDF","BkgPDF",x ,RooArgList(A1,A2)); //Fraction RooRealVar frac("frac","Fraction for PDF",0.5,0.,1.); x.setBins(10000,"fft"); RooFFTConvPdf model("model","model",x,bw,DCBall); RooAddPdf totPDF("totPDF","Total PDF ",RooArgList(model,BkgPDF),RooArgList(frac)); RooArgSet* params = totPDF.getParameters(x); if(sample!=1 && categ!=0 && id!=125){ if(channels==0 ){params->readFromFile("Ch0_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev) if(channels==1 ){params->readFromFile("Ch1_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev) if(channels==2 ){params->readFromFile("Ch2_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev) } RooFitResult *fitres = (RooFitResult*)totPDF.fitTo(dataset,SumW2Error(1),Range(xMin,xMax),Strategy(2),NumCPU(8),Save(true)); if (sample==1 && categ==0 && id==125){ mean.setConstant(kTRUE); sigma.setConstant(kTRUE); a1.setConstant(kTRUE); n1.setConstant(kTRUE); a2.setConstant(kTRUE); n2.setConstant(kTRUE); mean3.setConstant(kTRUE); sigma3.setConstant(kTRUE); scale3.setConstant(kTRUE); A1.setConstant(kTRUE); A2.setConstant(kTRUE); frac.setConstant(kTRUE); if(channels==0 ){ params->readFromFile("Ch0_Cat0_para.txt"); // Read the Parameter for the Resonance as ggH sample params->writeToFile("Ch0_Cat0_paraT.txt");} // Writing the Parameter for Full PDF including the Chebyshev-Polynomial if(channels==1 ) {params->readFromFile("Ch1_Cat0_para.txt"); // Read the Parameter for the Resonance as in ggH sample params->writeToFile("Ch1_Cat0_paraT.txt");}// Writing the Parameter for Full PDF including the Chebyshev-Polynomial if(channels==2 ){ params->readFromFile("Ch2_Cat0_para.txt"); // Read the Parameter for the Resonance as ggH sample params->writeToFile("Ch2_Cat0_paraT.txt");}// Writing the Parameter for Full PDF including the Chebyshev-Polynomial } stringstream frameTitle; if(channels==0){frameTitle << "4#mu, m_{H} = "; } if(channels==1){frameTitle << "4e, m_{H} = ";} if(channels==2){frameTitle << "2e2#mu, m_{H} = ";} frameTitle << massBin << " GeV"; stringstream nameFileRoot; nameFileRoot << "fitM" << massBin << ".root"; TFile *fileplot = TFile::Open(nameFileRoot.str().c_str(), "recreate"); RooPlot* xframe = x.frame() ; xframe->SetTitle(""); xframe->SetName("m4lplot"); dataset.plotOn(xframe,DataError(RooAbsData::SumW2), MarkerStyle(kOpenCircle), MarkerSize(1.1) ); int col; if(channels==0) col=kOrange+7; if(channels==1) col=kAzure+2; if(channels==2) col=kGreen+3; totPDF.plotOn(xframe,LineColor(col)); RooHist* hpull = xframe->pullHist(); RooPlot* frame3 = x.frame(Title("Pull Distribution")) ; frame3->addPlotable(hpull,"P"); // cosmetics TLegend *legend = new TLegend(0.20,0.45,0.45,0.60,NULL,"brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetTextAlign(12); legend->SetTextFont (42); legend->SetTextSize (0.03); TH1F *dummyPoints = new TH1F("dummyP","dummyP",1,0,1); TH1F *dummyLine = new TH1F("dummyL","dummyL",1,0,1); dummyPoints->SetMarkerStyle(kOpenCircle); dummyPoints->SetMarkerSize(1.1); dummyLine->SetLineColor(col); legend->AddEntry(dummyPoints, "Simulation", "pe"); legend->AddEntry(dummyLine, "Parametric Model", "l"); TPaveText *text = new TPaveText(0.15,0.90,0.77,0.98,"brNDC"); text->AddText("CMS Simulation"); text->SetBorderSize(0); text->SetFillStyle(0); text->SetTextAlign(12); text->SetTextFont(42); text->SetTextSize(0.03); TPaveText *titlet = new TPaveText(0.15,0.80,0.60,0.85,"brNDC"); titlet->AddText(frameTitle.str().c_str()); titlet->SetBorderSize(0); titlet->SetFillStyle(0); titlet->SetTextAlign(12); titlet->SetTextFont(132); titlet->SetTextSize(0.045); TPaveText *sigmat = new TPaveText(0.15,0.65,0.77,0.78,"brNDC"); stringstream sigmaval0, sigmaval1, sigmaval2; sigmaval0 << fixed; sigmaval0 << setprecision(1); sigmaval0 << "m_{dCB} = " << mean.getVal() + massBin << " GeV"; sigmaval1 << fixed; sigmaval1 << setprecision(1); sigmaval1 << "#sigma_{dCB} = " << sigma.getVal() << " GeV"; sigmaval2 << fixed; sigmaval2 << setprecision(1); sigmaval2 << "RMS_{eff} = " << effSigma(hmass) << " GeV"; sigmat->AddText(sigmaval1.str().c_str()); sigmat->AddText(sigmaval2.str().c_str()); sigmat->SetBorderSize(0); sigmat->SetFillStyle(0); sigmat->SetTextAlign(12); sigmat->SetTextFont(132); sigmat->SetTextSize(0.04); xframe->GetYaxis()->SetTitleOffset(1.5); cout << "EFF RMS = " << effSigma(hmass) << " RMS = " << hmass->GetRMS() << endl; pad1->cd(); stringstream nameFile, nameFileC, nameFilePng; nameFile << "fitM" << massBin << "_channel" << channels<< "_category"<< categ << ".pdf"; nameFileC << "fitM" << massBin << "_channel" << channels << "_category"<< categ << ".C"; nameFilePng << "fitM" << massBin << "_channel" << channels << "_category"<< categ << ".png"; xframe->Draw(); gPad->Update(); legend->Draw(); text->Draw(); sigmat->Draw(); titlet->Draw(); pad2->cd() ; frame3->Draw() ; frame3->SetMinimum(-3); frame3->SetMaximum(3); TLine *line1 = new TLine(105,0,140,0); line1->SetLineColor(kRed); line1->Draw(); c1->Print(nameFile.str().c_str()); c1->SaveAs(nameFileC.str().c_str()); c1->SaveAs(nameFilePng.str().c_str()); fileplot->cd(); xframe->Write(); sigmat->Write(); hmass->Write(); fileplot->Close(); if(fitValues!=0){ fitValues[0] = a1.getVal(); fitValues[1] = a2.getVal(); fitValues[2] = mean.getVal(); fitValues[3] = mean3.getVal(); fitValues[4] = n1.getVal(); fitValues[5] = n2.getVal(); fitValues[6] = sigma.getVal(); fitValues[7] = A1.getVal(); fitValues[8] = A2.getVal(); } if(fitErrors!=0){ fitErrors[0] = a1.getError(); fitErrors[1] = a2.getError(); fitErrors[2] = mean.getError(); fitErrors[3] = mean3.getError(); fitErrors[4] = n1.getError(); fitErrors[5] = n2.getError(); fitErrors[6] = sigma.getError(); fitErrors[7] = A1.getError(); fitErrors[8] = A2.getError(); } covQual[0] = fitres->covQual(); }
RooWorkspace* makeInvertedANFit(TTree* tree, float forceSigma=-1, bool constrainMu=false, float forceMu=-1) { RooWorkspace *ws = new RooWorkspace("ws",""); std::vector< TString (*)(TString, RooRealVar&, RooWorkspace&) > bkgPdfList; bkgPdfList.push_back(makeSingleExp); bkgPdfList.push_back(makeDoubleExp); #if DEBUG==0 //bkgPdfList.push_back(makeTripleExp); bkgPdfList.push_back(makeModExp); bkgPdfList.push_back(makeSinglePow); bkgPdfList.push_back(makeDoublePow); bkgPdfList.push_back(makePoly2); bkgPdfList.push_back(makePoly3); #endif RooRealVar mgg("mgg","m_{#gamma#gamma}",103,160,"GeV"); mgg.setBins(38); mgg.setRange("sideband_low", 103,120); mgg.setRange("sideband_high",131,160); mgg.setRange("signal",120,131); RooRealVar MR("MR","",0,3000,"GeV"); MR.setBins(60); RooRealVar Rsq("t1Rsq","",0,1,"GeV"); Rsq.setBins(20); RooRealVar hem1_M("hem1_M","",-1,2000,"GeV"); hem1_M.setBins(40); RooRealVar hem2_M("hem2_M","",-1,2000,"GeV"); hem2_M.setBins(40); RooRealVar ptgg("ptgg","p_{T}^{#gamma#gamma}",0,500,"GeV"); ptgg.setBins(50); RooDataSet data("data","",tree,RooArgSet(mgg,MR,Rsq,hem1_M,hem2_M,ptgg)); RooDataSet* blind_data = (RooDataSet*)data.reduce("mgg<121 || mgg>130"); std::vector<TString> tags; //fit many different background models for(auto func = bkgPdfList.begin(); func != bkgPdfList.end(); func++) { TString tag = (*func)("bonly",mgg,*ws); tags.push_back(tag); ws->pdf("bonly_"+tag+"_ext")->fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); RooFitResult* bres = ws->pdf("bonly_"+tag+"_ext")->fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); bres->SetName(tag+"_bonly_fitres"); ws->import(*bres); //make blinded fit RooPlot *fmgg_b = mgg.frame(); blind_data->plotOn(fmgg_b,RooFit::Range("sideband_low,sideband_high")); TBox blindBox(121,fmgg_b->GetMinimum()-(fmgg_b->GetMaximum()-fmgg_b->GetMinimum())*0.015,130,fmgg_b->GetMaximum()); blindBox.SetFillColor(kGray); fmgg_b->addObject(&blindBox); ws->pdf("bonly_"+tag+"_ext")->plotOn(fmgg_b,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("sideband_low,sideband_high")); fmgg_b->SetName(tag+"_blinded_frame"); ws->import(*fmgg_b); delete fmgg_b; //set all the parameters constant RooArgSet* vars = ws->pdf("bonly_"+tag)->getVariables(); RooFIter iter = vars->fwdIterator(); RooAbsArg* a; while( (a = iter.next()) ){ if(string(a->GetName()).compare("mgg")==0) continue; static_cast<RooRealVar*>(a)->setConstant(kTRUE); } //make the background portion of the s+b fit (*func)("b",mgg,*ws); RooRealVar sigma(tag+"_s_sigma","",5,0,100); if(forceSigma!=-1) { sigma.setVal(forceSigma); sigma.setConstant(true); } RooRealVar mu(tag+"_s_mu","",126,120,132); if(forceMu!=-1) { mu.setVal(forceMu); mu.setConstant(true); } RooGaussian sig(tag+"_sig_model","",mgg,mu,sigma); RooRealVar Nsig(tag+"_sb_Ns","",5,0,100); RooRealVar Nbkg(tag+"_sb_Nb","",100,0,100000); RooRealVar HiggsMass("HiggsMass","",125.1); RooRealVar HiggsMassError("HiggsMassError","",0.24); RooGaussian HiggsMassConstraint("HiggsMassConstraint","",mu,HiggsMass,HiggsMassError); RooAddPdf fitModel(tag+"_sb_model","",RooArgList( *ws->pdf("b_"+tag), sig ),RooArgList(Nbkg,Nsig)); RooFitResult* sbres; RooAbsReal* nll; if(constrainMu) { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); } else { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE)); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE)); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE)); } sbres->SetName(tag+"_sb_fitres"); ws->import(*sbres); ws->import(fitModel); RooPlot *fmgg = mgg.frame(); data.plotOn(fmgg); fitModel.plotOn(fmgg); ws->pdf("b_"+tag+"_ext")->plotOn(fmgg,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("Full")); fmgg->SetName(tag+"_frame"); ws->import(*fmgg); delete fmgg; RooMinuit(*nll).migrad(); RooPlot *fNs = Nsig.frame(0,25); fNs->SetName(tag+"_Nsig_pll"); RooAbsReal *pll = nll->createProfile(Nsig); //nll->plotOn(fNs,RooFit::ShiftToZero(),RooFit::LineColor(kRed)); pll->plotOn(fNs); ws->import(*fNs); delete fNs; RooPlot *fmu = mu.frame(125,132); fmu->SetName(tag+"_mu_pll"); RooAbsReal *pll_mu = nll->createProfile(mu); pll_mu->plotOn(fmu); ws->import(*fmu); delete fmu; } RooArgSet weights("weights"); RooArgSet pdfs_bonly("pdfs_bonly"); RooArgSet pdfs_b("pdfs_b"); RooRealVar minAIC("minAIC","",1E10); //compute AIC stuff for(auto t = tags.begin(); t!=tags.end(); t++) { RooAbsPdf *p_bonly = ws->pdf("bonly_"+*t); RooAbsPdf *p_b = ws->pdf("b_"+*t); RooFitResult *sb = (RooFitResult*)ws->obj(*t+"_bonly_fitres"); RooRealVar k(*t+"_b_k","",p_bonly->getParameters(RooArgSet(mgg))->getSize()); RooRealVar nll(*t+"_b_minNll","",sb->minNll()); RooRealVar Npts(*t+"_b_N","",blind_data->sumEntries()); RooFormulaVar AIC(*t+"_b_AIC","2*@0+2*@1+2*@1*(@1+1)/(@2-@1-1)",RooArgSet(nll,k,Npts)); ws->import(AIC); if(AIC.getVal() < minAIC.getVal()) { minAIC.setVal(AIC.getVal()); } //aicExpSum+=TMath::Exp(-0.5*AIC.getVal()); //we will need this precomputed for the next step pdfs_bonly.add(*p_bonly); pdfs_b.add(*p_b); } ws->import(minAIC); //compute the AIC weight float aicExpSum=0; for(auto t = tags.begin(); t!=tags.end(); t++) { RooFormulaVar *AIC = (RooFormulaVar*)ws->obj(*t+"_b_AIC"); aicExpSum+=TMath::Exp(-0.5*(AIC->getVal()-minAIC.getVal())); //we will need this precomputed for the next step } std::cout << "aicExpSum: " << aicExpSum << std::endl; for(auto t = tags.begin(); t!=tags.end(); t++) { RooFormulaVar *AIC = (RooFormulaVar*)ws->obj(*t+"_b_AIC"); RooRealVar *AICw = new RooRealVar(*t+"_b_AICWeight","",TMath::Exp(-0.5*(AIC->getVal()-minAIC.getVal()))/aicExpSum); if( TMath::IsNaN(AICw->getVal()) ) {AICw->setVal(0);} ws->import(*AICw); std::cout << *t << ": " << AIC->getVal()-minAIC.getVal() << " " << AICw->getVal() << std::endl; weights.add(*AICw); } RooAddPdf bonly_AIC("bonly_AIC","",pdfs_bonly,weights); RooAddPdf b_AIC("b_AIC","",pdfs_b,weights); //b_AIC.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); //RooFitResult* bres = b_AIC.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); //bres->SetName("AIC_b_fitres"); //ws->import(*bres); //make blinded fit RooPlot *fmgg_b = mgg.frame(RooFit::Range("sideband_low,sideband_high")); blind_data->plotOn(fmgg_b,RooFit::Range("sideband_low,sideband_high")); TBox blindBox(121,fmgg_b->GetMinimum()-(fmgg_b->GetMaximum()-fmgg_b->GetMinimum())*0.015,130,fmgg_b->GetMaximum()); blindBox.SetFillColor(kGray); fmgg_b->addObject(&blindBox); bonly_AIC.plotOn(fmgg_b,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("sideband_low,sideband_high")); fmgg_b->SetName("AIC_blinded_frame"); ws->import(*fmgg_b); delete fmgg_b; #if 1 RooRealVar sigma("AIC_s_sigma","",5,0,100); if(forceSigma!=-1) { sigma.setVal(forceSigma); sigma.setConstant(true); } RooRealVar mu("AIC_s_mu","",126,120,132); if(forceMu!=-1) { mu.setVal(forceMu); mu.setConstant(true); } RooGaussian sig("AIC_sig_model","",mgg,mu,sigma); RooRealVar Nsig("AIC_sb_Ns","",5,0,100); RooRealVar Nbkg("AIC_sb_Nb","",100,0,100000); RooRealVar HiggsMass("HiggsMass","",125.1); RooRealVar HiggsMassError("HiggsMassError","",0.24); RooGaussian HiggsMassConstraint("HiggsMassConstraint","",mu,HiggsMass,HiggsMassError); RooAddPdf fitModel("AIC_sb_model","",RooArgList( b_AIC, sig ),RooArgList(Nbkg,Nsig)); RooFitResult* sbres; RooAbsReal *nll; if(constrainMu) { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); } else { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE)); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE)); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE)); } assert(nll!=0); sbres->SetName("AIC_sb_fitres"); ws->import(*sbres); ws->import(fitModel); RooPlot *fmgg = mgg.frame(); data.plotOn(fmgg); fitModel.plotOn(fmgg); ws->pdf("b_AIC")->plotOn(fmgg,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("Full")); fmgg->SetName("AIC_frame"); ws->import(*fmgg); delete fmgg; RooMinuit(*nll).migrad(); RooPlot *fNs = Nsig.frame(0,25); fNs->SetName("AIC_Nsig_pll"); RooAbsReal *pll = nll->createProfile(Nsig); //nll->plotOn(fNs,RooFit::ShiftToZero(),RooFit::LineColor(kRed)); pll->plotOn(fNs); ws->import(*fNs); delete fNs; RooPlot *fmu = mu.frame(125,132); fmu->SetName("AIC_mu_pll"); RooAbsReal *pll_mu = nll->createProfile(mu); pll_mu->plotOn(fmu); ws->import(*fmu); delete fmu; std::cout << "min AIC: " << minAIC.getVal() << std::endl; for(auto t = tags.begin(); t!=tags.end(); t++) { RooFormulaVar *AIC = (RooFormulaVar*)ws->obj(*t+"_b_AIC"); RooRealVar *AICw = ws->var(*t+"_b_AICWeight"); RooRealVar* k = ws->var(*t+"_b_k"); printf("%s & %0.0f & %0.2f & %0.2f \\\\\n",t->Data(),k->getVal(),AIC->getVal()-minAIC.getVal(),AICw->getVal()); //std::cout << k->getVal() << " " << AIC->getVal()-minAIC.getVal() << " " << AICw->getVal() << std::endl; } #endif return ws; }
double FitInvMassBkg_v3(TH1D* histo, TH1D* histo_bkg, TString signal = "CBxBW",TString _bkg = "Cheb", TString option = ""){ //Set Style setTDRStyle(); if(option.Contains("nentries")){return histo->GetEntries()-histo_bkg->GetEntries();} else{ //Getting info about the histogram to fit int n = histo->GetEntries(); double w = histo->GetXaxis()->GetBinWidth(1); int ndf; double hmin0 = histo->GetXaxis()->GetXmin(); double hmax0 = histo->GetXaxis()->GetXmax(); histo->GetXaxis()->SetRangeUser(hmin0,hmax0); //Declare observable x //Try to rebin using this. Doesn't work for now //RooBinning xbins = Rebin2(histo); RooRealVar x("x","x",hmin0,hmax0) ; RooDataHist dh("dh","dh",x,Import(*histo)) ; //Define the frame RooPlot* frame; frame = x.frame(); dh.plotOn(frame,DataError(RooAbsData::SumW2), MarkerColor(1),MarkerSize(0.9),MarkerStyle(7)); //this will show histogram data points on canvas //x.setRange("R0",0,200) ; x.setRange("R1",55,200) ; x.setRange("D",55,120) ; ///////////////////// //Define fit function ///////////////////// cout<<"Debug4"<<endl; //fsig for adding two funciton i.e. F(x) = fsig*sig(x) + (1-fsig)*bkg(x) //RooRealVar fsig("fsig","sigal fraction",0.5, 0., 1.); RooRealVar nsig("nsig","signal events",histo->GetEntries()/2., 1,histo->GetEntries()); RooRealVar nbkg("nbkg","background events",histo_bkg->GetEntries()/2.,1,histo_bkg->GetEntries()); RooArgList pdfval(nsig,nbkg); //Various parameters //True mean RooRealVar mean("mean","PDG mean of Z",91.186);//, 70.0, 120.0); //For the BW RooRealVar width("width","PDG width of Z",2.4952);//, 0., 5.); //For the Gauss and the CB alone RooRealVar sigma("sigma","sigma",1, 0., 10.); RooRealVar alpha("alpha","alpha",0.7, 0., 7); RooRealVar ncb("ncb","ncb",7, 0, 150); //For the CB used for convolution, i.e. CBxBW RooRealVar cb_bias("cb_bias","bias",0, -3.,3.); RooRealVar cb_sigma("cb_sigma","response",1, 0.,5); RooRealVar cb_alpha("cb_alpha","alpha",1.,0.,7); RooRealVar cb_ncb("cb_ncb","ncb",2, 0, 10); //Gauss used for convolution RooRealVar gau_bias("gau_bias","alpha",0, -3., 3.); RooRealVar gau_sigma("gau_sigma","bias",1, 0., 7.); cout<<"Debug5"<<endl; mean.setRange(88,94); width.setRange(0,20); sigma.setRange(0.5,10); //fsig.setConstant(kTRUE); //alpha.setConstant(kTRUE); RooVoigtian sig_voigtian("sig_voigtian","Voigtian",x,mean,width,sigma); RooBreitWigner sig_bw("sig_bw","BW",x,mean,width); //RooGaussian sig_gau("sig_gau","gauss",x,mean,sigma); RooCBShape sig_cb("sig_cb", "Crystal Ball",x,mean,sigma,alpha,ncb); RooCBShape sig_cb_resp("sig_cb_resp", "Crystal Ball for conv.",x,cb_bias,cb_sigma,cb_alpha,cb_ncb); RooGaussian sig_gau_resp("sig_gau_resp", "Gaussian for conv.",x,gau_bias,gau_sigma); x.setBins(10000,"cache"); RooFFTConvPdf sig_cbbw("sig_cbbw","CBxBW",x,sig_cb_resp,sig_bw); RooFFTConvPdf sig_bwgau("sig_bwgau","BWxGau",x,sig_bw,sig_gau_resp); //NB: The CrystalBall shape is Gaussian that is 'connected' to an exponential taill at 'alpha' sigma of the Gaussian. The sign determines if it happens on the left or right side. The 'n' parameter control the slope of the exponential part. cout<<"Debug6"<<endl; RooAbsPdf* sig; if(signal == "Vo"){sig = &sig_bwgau;} else if(signal == "BW"){sig = &sig_bw;} //else if(signal == "Gau"){sig = &sig_gau;} else if(signal == "CB"){sig = &sig_cb;} else if(signal == "CBxBW"){ sig = &sig_cbbw;} else if(signal == "BWxGau"){ sig = &sig_bwgau;} else{ cout<<"Wrong signal function name"<<endl; return 1; } ///////////////////////////// //Background fitting function ///////////////////////////// //Get the initial parameter of the background // cout<<"Debug7"<<endl; vector<double> vec = FitBkg(histo_bkg,_bkg); //Chebychev RooRealVar a0("a0","a0",vec[0],-5.,0.) ; RooRealVar a1("a1","a1",vec[1],-2.5,1.2) ; RooRealVar a2("a2","a2",vec[2],-1.5,1.) ; RooRealVar a3("a3","a3",vec[3],-3,1.) ; RooRealVar a4("a4","a4",vec[4],-1.5,1.) ; RooRealVar a5("a5","a5",vec[5],-1.,1.) ; RooRealVar a6("a6","a6",vec[6],-1.,1.) ; RooChebychev bkg_cheb("bkg","Background",x,RooArgSet(a0,a1,a2,a3,a4,a5,a6)); //Novo RooRealVar peak_bkg("peak_bkg","peak",vec[0],0,250); RooRealVar width_bkg("width_bkg","width",vec[1],0,1) ; RooRealVar tail_bkg("tail_bkg","tail",vec[2],0,10) ; RooNovosibirsk bkg_nov("bkg","Background",x,peak_bkg,width_bkg,tail_bkg); RooAbsPdf* bkg; if(_bkg == "Cheb"){bkg = &bkg_cheb;} if(_bkg == "Novo"){bkg = &bkg_nov;} ////////////////////////// //Adding the two functions ////////////////////////// //RooAddPdf model("model","Signal+Background", RooArgList(*sig,*bkg),fsig); RooAddPdf model("model","Signal+Background", RooArgList(*sig,*bkg),pdfval); //Perform the fit RooAbsPdf* fit_func; fit_func = &model; RooFitResult* filters = fit_func->fitTo(dh,Range("R1"),"qr"); fit_func->plotOn(frame); fit_func->plotOn(frame,Components(*sig),LineStyle(kDashed),LineColor(kRed)); fit_func->plotOn(frame,Components(*bkg),LineStyle(kDashed),LineColor(kGreen)); frame->SetAxisRange(50,120); frame->Draw(); fit_func->paramOn(frame); dh.statOn(frame); //this will display hist stat on canvas frame->SetTitle(histo->GetTitle()); frame->GetXaxis()->SetTitle("m (in GeV/c^{2})"); frame->GetXaxis()->SetTitleOffset(1.2); float binsize = histo->GetBinWidth(1); //Store result in .root file frame->SetName(histo->GetName()); frame->Write(); /////////////////////// //Plot the efficiency// /////////////////////// //Old stuff //ofstream myfile; //myfile.open("/Users/GLP/Desktop/integrals.txt"); //This one doesn't take the normalisation into account ! //myfile<<"integral 1 "<<histo->GetName()<<endl; ////Integral of sig //RooAbsReal* integral_sig = sig->createIntegral(x,x,"D") ; //myfile<<fsig.getVal()*integral_sig->getVal()<<endl; //Integral of sig+bkg //RooAbsReal* total = fit_func->createIntegral(x, NormSet(x), Range("D")) ; //Integral of sig only //RooAbsReal* background = bkg->createIntegral(x, NormSet(x), Range("D")); //cout<<"The total integral is"<<n*total->getVal(); //cout<<"The bkg integral is"<<n*bkg->getVal(); //cout<<"The bkg with the fsig is"<<fsig.getVal()*n*bkg->getVal(); //cout<<"The returned value is"<<n*(total->getVal()-fsig.getVal()*background->getVal()); //myfile<<"integral 2 "<<endl; //myfile<<n*(total->getVal()-(1-fsig.getVal())*background->getVal())<<endl; //myfile.close(); //return n*(total->getVal()-(1-fsig.getVal())*background->getVal()); return nsig.getVal(); } }
int FitInvMassBkg(TH1D* histo, TH1D* histo_bkg, TString signal,TString _bkg){ //Set Style setTDRStyle(); cout<<"21"<<endl; //Path for input and output file. Written in FitDataPath.txt ifstream file("FitDataPath.txt"); string str; getline(file,str); TString _path = str; //Rebin(histo); //Getting info about the histogram to fit int n = histo->GetEntries(); double w = histo->GetXaxis()->GetBinWidth(1); int ndf; double hmin0 = histo->GetXaxis()->GetXmin(); double hmax0 = histo->GetXaxis()->GetXmax(); histo->GetXaxis()->SetRangeUser(hmin0,hmax0); //Declare observable x //Try to rebin using this. Doesn't work for now //RooBinning xbins = Rebin2(histo); RooRealVar x("x","x",hmin0,hmax0) ; RooDataHist dh("dh","dh",x,Import(*histo)) ; //Define the frame RooPlot* frame; frame = x.frame(); dh.plotOn(frame,DataError(RooAbsData::SumW2), MarkerColor(1),MarkerSize(0.9),MarkerStyle(7)); //this will show histogram data points on canvas //x.setRange("R0",0,200) ; x.setRange("R1",55,200) ; ///////////////////// //Define fit function ///////////////////// //fsig for adding two funciton i.e. F(x) = fsig*sig(x) + (1-fsig)*bkg(x) RooRealVar fsig("fsig","sigal fraction",0.5, 0., 1.);//before 0.9 //Various parameters //True mean RooRealVar mean("mean","PDG mean of Z",91.186);//, 70.0, 120.0); //For the BW RooRealVar width("width","PDG width of Z",2.4952);//, 0., 5.); //For the Gauss and the CB alone RooRealVar sigma("sigma","sigma",1, 0., 10.); RooRealVar alpha("alpha","alpha",0.7, 0., 7); RooRealVar ncb("ncb","ncb",7, 0, 150); //For the CB used for convolution, i.e. CBxBW RooRealVar cb_bias("cb_bias","bias",0, -3.,3.); RooRealVar cb_sigma("cb_sigma","response",1, 0.,5); RooRealVar cb_alpha("cb_alpha","alpha",1.,0.,7); RooRealVar cb_ncb("cb_ncb","ncb",2, 0, 10); mean.setRange(88,94); width.setRange(0,20); sigma.setRange(0.5,10); //fsig.setConstant(kTRUE); //alpha.setConstant(kTRUE); RooVoigtian sig_bwgau("sig_bwgau","BWxgauss",x,mean,width,sigma); RooBreitWigner sig_bw("sig_bw","BW",x,mean,width); RooGaussian sig_gau("sig_gau","gauss",x,mean,sigma); RooCBShape sig_cb("sig_cb", "Crystal Ball",x,mean,sigma,alpha,ncb); RooCBShape sig_cb_resp("sig_cb_resp", "Crystal Ball for conv.",x,cb_bias,cb_sigma,cb_alpha,cb_ncb); x.setBins(10000,"cache"); RooFFTConvPdf sig_cbbw("sig_cbbw","CBxBW",x,sig_cb_resp,sig_bw); //NB: The CrystalBall shape is Gaussian that is 'connected' to an exponential taill at 'alpha' sigma of the Gaussian. The sign determines if it happens on the left or right side. The 'n' parameter control the slope of the exponential part. RooAbsPdf* sig; if(signal == "BWxGau"){sig = &sig_bwgau;} else if(signal == "BW"){sig = &sig_bw;} else if(signal == "Gau"){sig = &sig_gau;} else if(signal == "CB"){sig = &sig_cb;} else if(signal == "CBxBW"){ sig = &sig_cbbw;} else{ cout<<"Wrong signal function name"<<endl; return 1; } ///////////////////////////// //Background fitting function ///////////////////////////// //Get the initial parameter of the background // vector<double> vec = FitBkg(histo_bkg,_bkg); //Chebychev RooRealVar a0("a0","a0",vec[0],-5.,0.) ; RooRealVar a1("a1","a1",vec[1],-2,1.2) ; RooRealVar a2("a2","a2",vec[2],-1.,1.) ; RooRealVar a3("a3","a3",vec[3],-2.5,0.) ; RooRealVar a4("a4","a4",vec[4],-1.,1.) ; RooRealVar a5("a5","a5",vec[5],-1.,1.) ; RooRealVar a6("a6","a6",vec[6],-1.,1.) ; RooChebychev bkg_cheb("bkg","Background",x,RooArgSet(a0,a1,a2,a3,a4,a5,a6)); //Novo RooRealVar peak_bkg("peak_bkg","peak",vec[0],0,250); RooRealVar width_bkg("width_bkg","width",vec[1],0,1) ; RooRealVar tail_bkg("tail_bkg","tail",vec[2],0,10) ; RooNovosibirsk bkg_nov("bkg","Background",x,peak_bkg,width_bkg,tail_bkg); RooAbsPdf* bkg; if(_bkg == "Cheb"){bkg = &bkg_cheb;} if(_bkg == "Novo"){bkg = &bkg_nov;} ////////////////////////// //Adding the two functions ////////////////////////// RooAddPdf model("model","Signal+Background", RooArgList(*sig,*bkg),fsig); //Perform the fit RooAbsPdf* fit_func; fit_func = &model; RooFitResult* filters = fit_func->fitTo(dh,Range("R1"),"qr"); fit_func->plotOn(frame); fit_func->plotOn(frame,Components(*sig),LineStyle(kDashed),LineColor(kRed)); fit_func->plotOn(frame,Components(*bkg),LineStyle(kDashed),LineColor(kGreen)); frame->Draw(); fit_func->paramOn(frame); dh.statOn(frame); //this will display hist stat on canvas frame->SetTitle(histo->GetTitle()); frame->GetXaxis()->SetTitle("m (in GeV/c^{2})"); frame->GetXaxis()->SetTitleOffset(1.2); float binsize = histo->GetBinWidth(1); //Store result in .root file frame->SetName(histo->GetName()); frame->Write(); return 0; }
void StandardHistFactoryPlotsWithCategories(const char* infile = "", const char* workspaceName = "combined", const char* modelConfigName = "ModelConfig", const char* dataName = "obsData"){ double nSigmaToVary=5.; double muVal=0; bool doFit=false; // ------------------------------------------------------- // First part is just to access a user-defined file // or create the standard example file if it doesn't exist const char* filename = ""; if (!strcmp(infile,"")) { filename = "results/example_combined_GaussExample_model.root"; bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code // if file does not exists generate with histfactory if (!fileExist) { #ifdef _WIN32 cout << "HistFactory file cannot be generated on Windows - exit" << endl; return; #endif // Normally this would be run on the command line cout <<"will run standard hist2workspace example"<<endl; gROOT->ProcessLine(".! prepareHistFactory ."); gROOT->ProcessLine(".! hist2workspace config/example.xml"); cout <<"\n\n---------------------"<<endl; cout <<"Done creating example input"<<endl; cout <<"---------------------\n\n"<<endl; } } else filename = infile; // Try to open the file TFile *file = TFile::Open(filename); // if input file was specified byt not found, quit if(!file ){ cout <<"StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl; return; } // ------------------------------------------------------- // Tutorial starts here // ------------------------------------------------------- // get the workspace out of the file RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName); if(!w){ cout <<"workspace not found" << endl; return; } // get the modelConfig out of the file ModelConfig* mc = (ModelConfig*) w->obj(modelConfigName); // get the modelConfig out of the file RooAbsData* data = w->data(dataName); // make sure ingredients are found if(!data || !mc){ w->Print(); cout << "data or ModelConfig was not found" <<endl; return; } // ------------------------------------------------------- // now use the profile inspector RooRealVar* obs = (RooRealVar*)mc->GetObservables()->first(); TList* list = new TList(); RooRealVar * firstPOI = dynamic_cast<RooRealVar*>(mc->GetParametersOfInterest()->first()); firstPOI->setVal(muVal); // firstPOI->setConstant(); if(doFit){ mc->GetPdf()->fitTo(*data); } // ------------------------------------------------------- mc->GetNuisanceParameters()->Print("v"); int nPlotsMax = 1000; cout <<" check expectedData by category"<<endl; RooDataSet* simData=NULL; RooSimultaneous* simPdf = NULL; if(strcmp(mc->GetPdf()->ClassName(),"RooSimultaneous")==0){ cout <<"Is a simultaneous PDF"<<endl; simPdf = (RooSimultaneous *)(mc->GetPdf()); } else { cout <<"Is not a simultaneous PDF"<<endl; } if(doFit) { RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat()); TIterator* iter = channelCat->typeIterator() ; RooCatType* tt = NULL; tt=(RooCatType*) iter->Next(); RooAbsPdf* pdftmp = ((RooSimultaneous*)mc->GetPdf())->getPdf(tt->GetName()) ; RooArgSet* obstmp = pdftmp->getObservables(*mc->GetObservables()) ; obs = ((RooRealVar*)obstmp->first()); RooPlot* frame = obs->frame(); cout <<Form("%s==%s::%s",channelCat->GetName(),channelCat->GetName(),tt->GetName())<<endl; cout << tt->GetName() << " " << channelCat->getLabel() <<endl; data->plotOn(frame,MarkerSize(1),Cut(Form("%s==%s::%s",channelCat->GetName(),channelCat->GetName(),tt->GetName())),DataError(RooAbsData::None)); Double_t normCount = data->sumEntries(Form("%s==%s::%s",channelCat->GetName(),channelCat->GetName(),tt->GetName())) ; pdftmp->plotOn(frame,LineWidth(2.),Normalization(normCount,RooAbsReal::NumEvent)) ; frame->Draw(); cout <<"expected events = " << mc->GetPdf()->expectedEvents(*data->get()) <<endl; return; } int nPlots=0; if(!simPdf){ TIterator* it = mc->GetNuisanceParameters()->createIterator(); RooRealVar* var = NULL; while( (var = (RooRealVar*) it->Next()) != NULL){ RooPlot* frame = obs->frame(); frame->SetYTitle(var->GetName()); data->plotOn(frame,MarkerSize(1)); var->setVal(0); mc->GetPdf()->plotOn(frame,LineWidth(1.)); var->setVal(1); mc->GetPdf()->plotOn(frame,LineColor(kRed),LineStyle(kDashed),LineWidth(1)); var->setVal(-1); mc->GetPdf()->plotOn(frame,LineColor(kGreen),LineStyle(kDashed),LineWidth(1)); list->Add(frame); var->setVal(0); } } else { RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat()); // TIterator* iter = simPdf->indexCat().typeIterator() ; TIterator* iter = channelCat->typeIterator() ; RooCatType* tt = NULL; while(nPlots<nPlotsMax && (tt=(RooCatType*) iter->Next())) { cout << "on type " << tt->GetName() << " " << endl; // Get pdf associated with state from simpdf RooAbsPdf* pdftmp = simPdf->getPdf(tt->GetName()) ; // Generate observables defined by the pdf associated with this state RooArgSet* obstmp = pdftmp->getObservables(*mc->GetObservables()) ; // obstmp->Print(); obs = ((RooRealVar*)obstmp->first()); TIterator* it = mc->GetNuisanceParameters()->createIterator(); RooRealVar* var = NULL; while(nPlots<nPlotsMax && (var = (RooRealVar*) it->Next())){ TCanvas* c2 = new TCanvas("c2"); RooPlot* frame = obs->frame(); frame->SetName(Form("frame%d",nPlots)); frame->SetYTitle(var->GetName()); cout <<Form("%s==%s::%s",channelCat->GetName(),channelCat->GetName(),tt->GetName())<<endl; cout << tt->GetName() << " " << channelCat->getLabel() <<endl; data->plotOn(frame,MarkerSize(1),Cut(Form("%s==%s::%s",channelCat->GetName(),channelCat->GetName(),tt->GetName())),DataError(RooAbsData::None)); Double_t normCount = data->sumEntries(Form("%s==%s::%s",channelCat->GetName(),channelCat->GetName(),tt->GetName())) ; if(strcmp(var->GetName(),"Lumi")==0){ cout <<"working on lumi"<<endl; var->setVal(w->var("nominalLumi")->getVal()); var->Print(); } else{ var->setVal(0); } // w->allVars().Print("v"); // mc->GetNuisanceParameters()->Print("v"); // pdftmp->plotOn(frame,LineWidth(2.)); // mc->GetPdf()->plotOn(frame,LineWidth(2.),Slice(*channelCat,tt->GetName()),ProjWData(*data)); //pdftmp->plotOn(frame,LineWidth(2.),Slice(*channelCat,tt->GetName()),ProjWData(*data)); normCount = pdftmp->expectedEvents(*obs); pdftmp->plotOn(frame,LineWidth(2.),Normalization(normCount,RooAbsReal::NumEvent)) ; if(strcmp(var->GetName(),"Lumi")==0){ cout <<"working on lumi"<<endl; var->setVal(w->var("nominalLumi")->getVal()+0.05); var->Print(); } else{ var->setVal(nSigmaToVary); } // pdftmp->plotOn(frame,LineColor(kRed),LineStyle(kDashed),LineWidth(2)); // mc->GetPdf()->plotOn(frame,LineColor(kRed),LineStyle(kDashed),LineWidth(2.),Slice(*channelCat,tt->GetName()),ProjWData(*data)); //pdftmp->plotOn(frame,LineColor(kRed),LineStyle(kDashed),LineWidth(2.),Slice(*channelCat,tt->GetName()),ProjWData(*data)); normCount = pdftmp->expectedEvents(*obs); pdftmp->plotOn(frame,LineWidth(2.),LineColor(kRed),LineStyle(kDashed),Normalization(normCount,RooAbsReal::NumEvent)) ; if(strcmp(var->GetName(),"Lumi")==0){ cout <<"working on lumi"<<endl; var->setVal(w->var("nominalLumi")->getVal()-0.05); var->Print(); } else{ var->setVal(-nSigmaToVary); } // pdftmp->plotOn(frame,LineColor(kGreen),LineStyle(kDashed),LineWidth(2)); // mc->GetPdf()->plotOn(frame,LineColor(kGreen),LineStyle(kDashed),LineWidth(2),Slice(*channelCat,tt->GetName()),ProjWData(*data)); //pdftmp->plotOn(frame,LineColor(kGreen),LineStyle(kDashed),LineWidth(2),Slice(*channelCat,tt->GetName()),ProjWData(*data)); normCount = pdftmp->expectedEvents(*obs); pdftmp->plotOn(frame,LineWidth(2.),LineColor(kGreen),LineStyle(kDashed),Normalization(normCount,RooAbsReal::NumEvent)) ; // set them back to normal if(strcmp(var->GetName(),"Lumi")==0){ cout <<"working on lumi"<<endl; var->setVal(w->var("nominalLumi")->getVal()); var->Print(); } else{ var->setVal(0); } list->Add(frame); // quit making plots ++nPlots; frame->Draw(); c2->SaveAs(Form("%s_%s_%s.pdf",tt->GetName(),obs->GetName(),var->GetName())); delete c2; } } } // ------------------------------------------------------- // now make plots TCanvas* c1 = new TCanvas("c1","ProfileInspectorDemo",800,200); if(list->GetSize()>4){ double n = list->GetSize(); int nx = (int)sqrt(n) ; int ny = TMath::CeilNint(n/nx); nx = TMath::CeilNint( sqrt(n) ); c1->Divide(ny,nx); } else c1->Divide(list->GetSize()); for(int i=0; i<list->GetSize(); ++i){ c1->cd(i+1); list->At(i)->Draw(); } }