double TwoBody::GetPoiUpperSimple(std::string channel, Double_t peak){ // // Estimate a good value for the upper boundary of the range of POI // using just data in a window corresponding to the signal region // std::string legend = "[TwoBody::GetPoiUpperSimple]: "; char buf[128]; // special handling needed for single-channel workspaces bool b_single_channel; if (channel.size()==0) b_single_channel = true; else b_single_channel = false; double _range = 1.0; // get data yield under the signal peak ws->var("peak")->setVal(peak); if (b_single_channel) sprintf(buf,"width"); else sprintf(buf,"width_%s",channel.c_str()); double _width = 0;//ws->function(buf)->getVal(); if (b_single_channel) sprintf(buf,"sigma"); else sprintf(buf,"sigma_%s",channel.c_str()); double _sigma = ws->function(buf)->getVal(); double c_min = peak - sqrt(_width*_width + _sigma*_sigma); double c_max = peak + sqrt(_width*_width + _sigma*_sigma); sprintf(buf, "mass>=%f && mass<=%f", c_min, c_max); double n_count = data->sumEntries( buf ); // ad-hoc fix when there are no events in window if (n_count < 0.3) n_count = 0.3; std::cout << legend << "event yield in data in the window: " << n_count << std::endl; // compute the corresponding POI range if (b_single_channel) sprintf(buf,"nsig_scale"); else sprintf(buf,"nsig_scale_%s",channel.c_str()); double _nsig_scale = ws->var(buf)->getVal(); if (b_single_channel) sprintf(buf,"nz"); else sprintf(buf,"nz_%s",channel.c_str()); double _nz = ws->var(buf)->getVal(); if (b_single_channel) sprintf(buf,"eff"); else sprintf(buf,"eff_%s",channel.c_str()); double _eff = ws->function(buf)->getVal(); double n_excess = 3.0 * sqrt(n_count)/0.68; // let signal excess be ~ uncertainty on BG _range = n_excess / _nsig_scale / _nz / _eff; return _range; }
/// /// Make an Asimov toy: set all observables set to truth values. /// The Asimov point needs to be loaded in the combiner before. /// \param c - combiner which should be set to an asimov toy /// void GammaComboEngine::setAsimovObservables(Combiner* c) { if ( !c->isCombined() ) { cout << "GammaComboEngine::setAsimovObservables() : ERROR : Can't set an Asimov toy before " "the combiner is combined. Call combine() first." << endl; exit(1); } // set observables to asimov values in workspace RooWorkspace* w = c->getWorkspace(); TIterator* itObs = c->getObservables()->createIterator(); while(RooRealVar* pObs = (RooRealVar*) itObs->Next()) { // get theory name from the observable name TString pThName = pObs->GetName(); pThName.ReplaceAll("obs","th"); // get the theory relation RooAbsReal* th = w->function(pThName); if ( th==0 ) { cout << "GammaComboEngine::setAsimovObservables() : ERROR : theory relation not found in workspace: " << pThName << endl; exit(1); } // set the observable to what the theory relation predicts pObs->setVal(th->getVal()); } delete itObs; // write back the asimov values to the PDF object so that when // the PDF is printed, the asimov values show up for ( int i=0; i<c->getPdfs().size(); i++ ) { PDF_Abs* pdf = c->getPdfs()[i]; pdf->setObservableSourceString("Asimov"); TIterator* itObs = pdf->getObservables()->createIterator(); while(RooRealVar* pObs = (RooRealVar*) itObs->Next()) { RooAbsReal* obs = w->var(pObs->GetName()); if ( obs==0 ) { cout << "GammaComboEngine::setAsimovObservables() : ERROR : observable not found in workspace: " << pObs->GetName() << endl; exit(1); } pdf->setObservable(pObs->GetName(), obs->getVal()); } delete itObs; } }
// Function that loads LoadedWS LoadWorkspace( TString ws_file, bool dobarrel ){ TFile *ws_rootfp = TFile::Open(ws_file); RooWorkspace *ws; if (dobarrel) ws = (RooWorkspace*)ws_rootfp->Get("wereg_eb"); else ws = (RooWorkspace*)ws_rootfp->Get("wereg_ee"); //####################################### // Load relevant variables from the ws //####################################### // Read variables from workspace RooGBRTargetFlex *meantgt; if (dobarrel) meantgt = static_cast<RooGBRTargetFlex*>( ws->arg("sigmeantEB") ); else meantgt = static_cast<RooGBRTargetFlex*>( ws->arg("sigmeantEE") ); RooRealVar *tgtvar = ws->var("targetvar"); RooAbsPdf *sigpdf; RooAbsReal *sigmeanlim; RooAbsReal *sigwidthlim; RooAbsReal *signlim; RooAbsReal *sign2lim; if (dobarrel){ sigpdf = ws->pdf("sigpdfEB"); sigmeanlim = ws->function("sigmeanlimEB"); sigwidthlim = ws->function("sigwidthlimEB"); signlim = ws->function("signlimEB"); sign2lim = ws->function("sign2limEB"); } else { sigpdf = ws->pdf("sigpdfEE"); sigmeanlim = ws->function("sigmeanlimEE"); sigwidthlim = ws->function("sigwidthlimEE"); signlim = ws->function("signlimEE"); sign2lim = ws->function("sign2limEE"); } //####################################### // Register to-be-returned variables in a specific struct //####################################### LoadedWS LWS; LWS.ws = ws; if (dobarrel) LWS.name = "wereg_eb"; else LWS.name = "wereg_ee"; LWS.meantgt = meantgt; LWS.tgtvar = tgtvar; LWS.sigpdf = sigpdf; LWS.sigmeanlim = sigmeanlim; LWS.sigwidthlim = sigwidthlim; LWS.signlim = signlim; LWS.sign2lim = sign2lim; return LWS; }
void eregtesting_13TeV_Eta(bool dobarrel=true, bool doele=false,int gammaID=0) { //output dir TString EEorEB = "EE"; if(dobarrel) { EEorEB = "EB"; } TString gammaDir = "bothGammas"; if(gammaID==1) { gammaDir = "gamma1"; } else if(gammaID==2) { gammaDir = "gamma2"; } TString dirname = TString::Format("ereg_test_plots_Eta/%s_%s",gammaDir.Data(),EEorEB.Data()); gSystem->mkdir(dirname,true); gSystem->cd(dirname); //read workspace from training TString fname; if (doele && dobarrel) fname = "wereg_ele_eb.root"; else if (doele && !dobarrel) fname = "wereg_ele_ee.root"; else if (!doele && dobarrel) fname = "wereg_ph_eb.root"; else if (!doele && !dobarrel) fname = "wereg_ph_ee.root"; TString infile = TString::Format("../../ereg_ws_Eta/%s/%s",gammaDir.Data(),fname.Data()); TFile *fws = TFile::Open(infile); RooWorkspace *ws = (RooWorkspace*)fws->Get("wereg"); //read variables from workspace RooGBRTargetFlex *meantgt = static_cast<RooGBRTargetFlex*>(ws->arg("sigmeant")); RooRealVar *tgtvar = ws->var("tgtvar"); RooArgList vars; vars.add(meantgt->FuncVars()); vars.add(*tgtvar); //read testing dataset from TTree RooRealVar weightvar("weightvar","",1.); TTree *dtree; if (doele) { //TFile *fdin = TFile::Open("root://eoscms.cern.ch//eos/cms/store/cmst3/user/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TFile *fdin = TFile::Open("/data/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterSingleInvert"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } else { //TFile *fdin = TFile::Open("/eos/cms/store/group/dpg_ecal/alca_ecalcalib/piZero2017/zhicaiz/Gun_MultiPion_FlatPt-1To15/Gun_FlatPt1to15_MultiPion_withPhotonPtFilter_pythia8/photons_0_half2.root"); //TFile *fdin = TFile::Open("/eos/cms/store/group/dpg_ecal/alca_ecalcalib/piZero2017/zhicaiz/Gun_MultiEta_FlatPt-1To15/Gun_FlatPt1to15_MultiEta_withPhotonPtFilter_pythia8/photons_22Aug2017_V3_half2.root"); TFile *fdin = TFile::Open("/eos/cms/store/group/dpg_ecal/alca_ecalcalib/piZero2017/zhicaiz/Gun_MultiEta_FlatPt-1To15/Gun_FlatPt1to15_MultiEtaToGG_withPhotonPtFilter_pythia8/photons_20171008_half2.root"); if(gammaID==0) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma"); } else if(gammaID==1) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma1"); } else if(gammaID==2) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma2"); } } //selection cuts for testing //TCut selcut = "(STr2_enG1_true/cosh(STr2_Eta_1)>1.0) && (STr2_S4S9_1>0.75)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (STr2_enG_true/STr2_enG_rec)<3.0 && STr2_EOverEOther < 10.0 && STr2_EOverEOther > 0.1"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (STr2_mPi0_nocor>0.1)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.1) && (STr2_mPi0_nocor < 0.2)"; TCut selcut = ""; if(dobarrel) selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.2) && (STr2_mPi0_nocor < 1.0) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)<1.479 && (!STr2_fromPi0)"; //if(dobarrel) selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.1) && (STr2_mPi0_nocor < 0.2) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)<1.479"; else selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.2) && (STr2_mPi0_nocor < 1.0) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)>1.479 && (!STr2_fromPi0)"; //else selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.1) && (STr2_mPi0_nocor < 0.2) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)>1.479"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (STr2_iEta_on2520==0 || STr2_iPhi_on20==0) "; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)>60)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03)"; /* TCut selcut; if (dobarrel) selcut = "ph.genpt>25. && ph.isbarrel && ph.ispromptgen"; else selcut = "ph.genpt>25. && !ph.isbarrel && ph.ispromptgen"; */ TCut selweight = "xsecweight(procidx)*puweight(numPU,procidx)"; TCut prescale10 = "(Entry$%10==0)"; TCut prescale10alt = "(Entry$%10==1)"; TCut prescale25 = "(Entry$%25==0)"; TCut prescale100 = "(Entry$%100==0)"; TCut prescale1000 = "(Entry$%1000==0)"; TCut evenevents = "(Entry$%2==0)"; TCut oddevents = "(Entry$%2==1)"; TCut prescale100alt = "(Entry$%100==1)"; TCut prescale1000alt = "(Entry$%1000==1)"; TCut prescale50alt = "(Entry$%50==1)"; TCut Events3_4 = "(Entry$%4==3)"; TCut Events1_4 = "(Entry$%4==1)"; TCut Events2_4 = "(Entry$%4==2)"; TCut Events0_4 = "(Entry$%4==0)"; TCut Events01_4 = "(Entry$%4<2)"; TCut Events23_4 = "(Entry$%4>1)"; TCut EventsTest = "(Entry$%2==1)"; //weightvar.SetTitle(EventsTest*selcut); weightvar.SetTitle(selcut); /* if (doele) weightvar.SetTitle(prescale100alt*selcut); else weightvar.SetTitle(selcut); */ //make testing dataset RooDataSet *hdata = RooTreeConvert::CreateDataSet("hdata",dtree,vars,weightvar); if (doele) weightvar.SetTitle(prescale1000alt*selcut); else weightvar.SetTitle(prescale10alt*selcut); //make reduced testing dataset for integration over conditional variables RooDataSet *hdatasmall = RooTreeConvert::CreateDataSet("hdatasmall",dtree,vars,weightvar); //retrieve full pdf from workspace RooAbsPdf *sigpdf = ws->pdf("sigpdf"); //input variable corresponding to sceta RooRealVar *scEraw = ws->var("var_0"); scEraw->setRange(1.,2.); scEraw->setBins(100); // RooRealVar *scetavar = ws->var("var_1"); // RooRealVar *scphivar = ws->var("var_2"); //regressed output functions RooAbsReal *sigmeanlim = ws->function("sigmeanlim"); RooAbsReal *sigwidthlim = ws->function("sigwidthlim"); RooAbsReal *signlim = ws->function("signlim"); RooAbsReal *sign2lim = ws->function("sign2lim"); // RooAbsReal *sigalphalim = ws->function("sigalphalim"); //RooAbsReal *sigalpha2lim = ws->function("sigalpha2lim"); //formula for corrected energy/true energy ( 1.0/(etrue/eraw) * regression mean) RooFormulaVar ecor("ecor","","1./(@0)*@1",RooArgList(*tgtvar,*sigmeanlim)); RooRealVar *ecorvar = (RooRealVar*)hdata->addColumn(ecor); ecorvar->setRange(0.,2.); ecorvar->setBins(800); //formula for raw energy/true energy (1.0/(etrue/eraw)) RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); RooRealVar *rawvar = (RooRealVar*)hdata->addColumn(raw); rawvar->setRange(0.,2.); rawvar->setBins(800); //clone data and add regression outputs for plotting RooDataSet *hdataclone = new RooDataSet(*hdata,"hdataclone"); RooRealVar *meanvar = (RooRealVar*)hdataclone->addColumn(*sigmeanlim); RooRealVar *widthvar = (RooRealVar*)hdataclone->addColumn(*sigwidthlim); RooRealVar *nvar = (RooRealVar*)hdataclone->addColumn(*signlim); RooRealVar *n2var = (RooRealVar*)hdataclone->addColumn(*sign2lim); // RooRealVar *alphavar = (RooRealVar*)hdataclone->addColumn(*sigalphalim); // RooRealVar *alpha2var = (RooRealVar*)hdataclone->addColumn(*sigalpha2lim); //plot target variable and weighted regression prediction (using numerical integration over reduced testing dataset) TCanvas *craw = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot = tgtvar->frame(0.6,2.0,100); hdata->plotOn(plot); sigpdf->plotOn(plot,ProjWData(*hdatasmall)); plot->Draw(); craw->SaveAs("RawE.pdf"); craw->SaveAs("RawE.png"); craw->SetLogy(); plot->SetMinimum(0.1); craw->SaveAs("RawElog.pdf"); craw->SaveAs("RawElog.png"); //plot distribution of regressed functions over testing dataset TCanvas *cmean = new TCanvas; RooPlot *plotmean = meanvar->frame(0.8,2.0,100); hdataclone->plotOn(plotmean); plotmean->Draw(); cmean->SaveAs("mean.pdf"); cmean->SaveAs("mean.png"); TCanvas *cwidth = new TCanvas; RooPlot *plotwidth = widthvar->frame(0.,0.05,100); hdataclone->plotOn(plotwidth); plotwidth->Draw(); cwidth->SaveAs("width.pdf"); cwidth->SaveAs("width.png"); TCanvas *cn = new TCanvas; RooPlot *plotn = nvar->frame(0.,111.,200); hdataclone->plotOn(plotn); plotn->Draw(); cn->SaveAs("n.pdf"); cn->SaveAs("n.png"); TCanvas *cn2 = new TCanvas; RooPlot *plotn2 = n2var->frame(0.,111.,100); hdataclone->plotOn(plotn2); plotn2->Draw(); cn2->SaveAs("n2.pdf"); cn2->SaveAs("n2.png"); /* TCanvas *calpha = new TCanvas; RooPlot *plotalpha = alphavar->frame(0.,5.,200); hdataclone->plotOn(plotalpha); plotalpha->Draw(); calpha->SaveAs("alpha.pdf"); calpha->SaveAs("alpha.png"); TCanvas *calpha2 = new TCanvas; RooPlot *plotalpha2 = alpha2var->frame(0.,5.,200); hdataclone->plotOn(plotalpha2); plotalpha2->Draw(); calpha2->SaveAs("alpha2.pdf"); calpha2->SaveAs("alpha2.png"); */ /* TCanvas *ceta = new TCanvas; RooPlot *ploteta = scetavar->frame(-2.6,2.6,200); hdataclone->plotOn(ploteta); ploteta->Draw(); ceta->SaveAs("eta.pdf"); ceta->SaveAs("eta.png"); */ //create histograms for eraw/etrue and ecor/etrue to quantify regression performance TH1 *heraw;// = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.)); TH1 *hecor;// = hdata->createHistogram("hecor",*ecorvar); if (EEorEB == "EB") { heraw = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.0)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(800,0.,2.0)); } else { heraw = hdata->createHistogram("hraw",*rawvar,Binning(200,0.,2.)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(200,0.,2.)); } //heold->SetLineColor(kRed); hecor->SetLineColor(kBlue); heraw->SetLineColor(kMagenta); hecor->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); heraw->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); hecor->GetXaxis()->SetRangeUser(0.0,1.5); heraw->GetXaxis()->SetRangeUser(0.0,1.5); /*if(EEorEB == "EE") { heraw->GetYaxis()->SetRangeUser(10.0,200.0); hecor->GetYaxis()->SetRangeUser(10.0,200.0); } */ //heold->GetXaxis()->SetRangeUser(0.6,1.2); double effsigma_cor, effsigma_raw, fwhm_cor, fwhm_raw; if(EEorEB == "EB") { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(800,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(800,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } else { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(200,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(200,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } TCanvas *cresponse = new TCanvas; gStyle->SetOptStat(0); gStyle->SetPalette(107); hecor->SetTitle(""); heraw->SetTitle(""); hecor->Draw("HIST"); //heold->Draw("HISTSAME"); heraw->Draw("HISTSAME"); //show errSigma in the plot TLegend *leg = new TLegend(0.1, 0.75, 0.7, 0.9); leg->AddEntry(hecor,Form("E_{cor}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_cor, fwhm_cor),"l"); leg->AddEntry(heraw,Form("E_{raw}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_raw, fwhm_raw),"l"); leg->SetFillStyle(0); leg->SetBorderSize(0); // leg->SetTextColor(kRed); leg->Draw(); cresponse->SaveAs("response.pdf"); cresponse->SaveAs("response.png"); cresponse->SetLogy(); cresponse->SaveAs("responselog.pdf"); cresponse->SaveAs("responselog.png"); // draw CCs vs eta and phi /* TCanvas *c_eta = new TCanvas; TH1 *h_eta = hdata->createHistogram("h_eta",*scetavar,Binning(100,-3.2,3.2)); h_eta->Draw("HIST"); c_eta->SaveAs("heta.pdf"); c_eta->SaveAs("heta.png"); TCanvas *c_phi = new TCanvas; TH1 *h_phi = hdata->createHistogram("h_phi",*scphivar,Binning(100,-3.2,3.2)); h_phi->Draw("HIST"); c_phi->SaveAs("hphi.pdf"); c_phi->SaveAs("hphi.png"); */ RooRealVar *scetaiXvar = ws->var("var_4"); RooRealVar *scphiiYvar = ws->var("var_5"); if(EEorEB=="EB") { scetaiXvar->setRange(-90,90); scetaiXvar->setBins(180); scphiiYvar->setRange(0,360); scphiiYvar->setBins(360); } else { scetaiXvar->setRange(0,50); scetaiXvar->setBins(50); scphiiYvar->setRange(0,50); scphiiYvar->setBins(50); } ecorvar->setRange(0.5,1.5); ecorvar->setBins(800); rawvar->setRange(0.5,1.5); rawvar->setBins(800); TCanvas *c_cor_eta = new TCanvas; TH3F *h3_CC_eta_phi = (TH3F*) hdata->createHistogram("var_5,var_4,ecor",(EEorEB=="EB") ? 170 : 100, (EEorEB=="EB") ? 360 : 100,25); TProfile2D *h_CC_eta_phi = h3_CC_eta_phi->Project3DProfile(); h_CC_eta_phi->SetTitle("E_{cor}/E_{true}"); if(EEorEB=="EB") { h_CC_eta_phi->GetXaxis()->SetTitle("i#eta"); h_CC_eta_phi->GetYaxis()->SetTitle("i#phi"); h_CC_eta_phi->GetXaxis()->SetRangeUser(-85,85); h_CC_eta_phi->GetYaxis()->SetRangeUser(0,360); } else { h_CC_eta_phi->GetXaxis()->SetTitle("iX"); h_CC_eta_phi->GetYaxis()->SetTitle("iY"); } h_CC_eta_phi->SetMinimum(0.5); h_CC_eta_phi->SetMaximum(1.5); h_CC_eta_phi->Draw("COLZ"); c_cor_eta->SaveAs("cor_vs_eta_phi.pdf"); c_cor_eta->SaveAs("cor_vs_eta_phi.png"); TH2F *h_CC_eta = hdata->createHistogram(*scetaiXvar, *ecorvar, "","cor_vs_eta"); if(EEorEB=="EB") { h_CC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetXaxis()->SetTitle("iX"); } h_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_eta->Draw("COLZ"); c_cor_eta->SaveAs("cor_vs_eta.pdf"); c_cor_eta->SaveAs("cor_vs_eta.png"); TCanvas *c_cor_scEraw = new TCanvas; TH2F *h_CC_scEraw = hdata->createHistogram(*scEraw, *ecorvar, "","cor_vs_scEraw"); h_CC_scEraw->GetXaxis()->SetTitle("E_{raw}"); h_CC_scEraw->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_scEraw->Draw("COLZ"); c_cor_scEraw->SaveAs("cor_vs_scEraw.pdf"); c_cor_scEraw->SaveAs("cor_vs_scEraw.png"); TCanvas *c_raw_scEraw = new TCanvas; TH2F *h_RC_scEraw = hdata->createHistogram(*scEraw, *rawvar, "","raw_vs_scEraw"); h_RC_scEraw->GetXaxis()->SetTitle("E_{raw}"); h_RC_scEraw->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_scEraw->Draw("COLZ"); c_raw_scEraw->SaveAs("raw_vs_scEraw.pdf"); c_raw_scEraw->SaveAs("raw_vs_scEraw.png"); TCanvas *c_cor_phi = new TCanvas; TH2F *h_CC_phi = hdata->createHistogram(*scphiiYvar, *ecorvar, "","cor_vs_phi"); if(EEorEB=="EB") { h_CC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetXaxis()->SetTitle("iY"); } h_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_phi->Draw("COLZ"); c_cor_phi->SaveAs("cor_vs_phi.pdf"); c_cor_phi->SaveAs("cor_vs_phi.png"); TCanvas *c_raw_eta = new TCanvas; TH3F *h3_RC_eta_phi = (TH3F*) hdata->createHistogram("var_5,var_4,raw",(EEorEB=="EB") ? 170 : 100, (EEorEB=="EB") ? 360 : 100,25); TProfile2D *h_RC_eta_phi = h3_RC_eta_phi->Project3DProfile(); h_RC_eta_phi->SetTitle("E_{raw}/E_{true}"); if(EEorEB=="EB") { h_RC_eta_phi->GetXaxis()->SetTitle("i#eta"); h_RC_eta_phi->GetYaxis()->SetTitle("i#phi"); h_RC_eta_phi->GetXaxis()->SetRangeUser(-85,85); h_RC_eta_phi->GetYaxis()->SetRangeUser(0,360); } else { h_RC_eta_phi->GetXaxis()->SetTitle("iX"); h_RC_eta_phi->GetYaxis()->SetTitle("iY"); } h_RC_eta_phi->SetMinimum(0.5); h_RC_eta_phi->SetMaximum(1.5); h_RC_eta_phi->Draw("COLZ"); c_raw_eta->SaveAs("raw_vs_eta_phi.pdf"); c_raw_eta->SaveAs("raw_vs_eta_phi.png"); TH2F *h_RC_eta = hdata->createHistogram(*scetaiXvar, *rawvar, "","raw_vs_eta"); if(EEorEB=="EB") { h_RC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_RC_eta->GetXaxis()->SetTitle("iX"); } h_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_eta->Draw("COLZ"); c_raw_eta->SaveAs("raw_vs_eta.pdf"); c_raw_eta->SaveAs("raw_vs_eta.png"); TCanvas *c_raw_phi = new TCanvas; TH2F *h_RC_phi = hdata->createHistogram(*scphiiYvar, *rawvar, "","raw_vs_phi"); if(EEorEB=="EB") { h_RC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_RC_phi->GetXaxis()->SetTitle("iY"); } h_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_phi->Draw("COLZ"); c_raw_phi->SaveAs("raw_vs_phi.pdf"); c_raw_phi->SaveAs("raw_vs_phi.png"); //on2,5,20, etc if(EEorEB == "EB") { TCanvas *myC_iCrystal_mod = new TCanvas; RooRealVar *SM_distvar = ws->var("var_6"); SM_distvar->setRange(0,10); SM_distvar->setBins(10); TH2F *h_CC_SM_dist = hdata->createHistogram(*SM_distvar, *ecorvar, "","cor_vs_SM_dist"); h_CC_SM_dist->GetXaxis()->SetTitle("SM_dist"); h_CC_SM_dist->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_SM_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_SM_dist.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_SM_dist.png"); TH2F *h_RC_SM_dist = hdata->createHistogram(*SM_distvar, *rawvar, "","raw_vs_SM_dist"); h_RC_SM_dist->GetXaxis()->SetTitle("distance to SM gap"); h_RC_SM_dist->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_SM_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_SM_dist.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_SM_dist.png"); RooRealVar *M_distvar = ws->var("var_7"); M_distvar->setRange(0,13); M_distvar->setBins(10); TH2F *h_CC_M_dist = hdata->createHistogram(*M_distvar, *ecorvar, "","cor_vs_M_dist"); h_CC_M_dist->GetXaxis()->SetTitle("M_dist"); h_CC_M_dist->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_M_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_M_dist.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_M_dist.png"); TH2F *h_RC_M_dist = hdata->createHistogram(*M_distvar, *rawvar, "","raw_vs_M_dist"); h_RC_M_dist->GetXaxis()->SetTitle("distance to module gap"); h_RC_M_dist->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_M_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_M_dist.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_M_dist.png"); /* RooRealVar *DeltaRG1G2var = ws->var("var_8"); DeltaRG1G2var->setRange(0,0.2); DeltaRG1G2var->setBins(100); TH2F *h_CC_DeltaRG1G2 = hdata->createHistogram(*DeltaRG1G2var, *ecorvar, "","cor_vs_DeltaRG1G2"); h_CC_DeltaRG1G2->GetXaxis()->SetTitle("DeltaRG1G2"); h_CC_DeltaRG1G2->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_DeltaRG1G2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_DeltaRG1G2.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_DeltaRG1G2.png"); TH2F *h_RC_DeltaRG1G2 = hdata->createHistogram(*DeltaRG1G2var, *rawvar, "","raw_vs_DeltaRG1G2"); h_RC_DeltaRG1G2->GetXaxis()->SetTitle("distance to module gap"); h_RC_DeltaRG1G2->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_DeltaRG1G2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_DeltaRG1G2.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_DeltaRG1G2.png"); */ } // other variables TCanvas *myC_variables = new TCanvas; RooRealVar *Nxtalvar = ws->var("var_1"); Nxtalvar->setRange(0,10); Nxtalvar->setBins(10); TH2F *h_CC_Nxtal = hdata->createHistogram(*Nxtalvar, *ecorvar, "","cor_vs_Nxtal"); h_CC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_CC_Nxtal->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Nxtal.pdf"); myC_variables->SaveAs("cor_vs_Nxtal.png"); TH2F *h_RC_Nxtal = hdata->createHistogram(*Nxtalvar, *rawvar, "","raw_vs_Nxtal"); h_RC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_RC_Nxtal->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Nxtal.pdf"); myC_variables->SaveAs("raw_vs_Nxtal.png"); RooRealVar *S4S9var = ws->var("var_2"); int Nbins_S4S9 = 100; double Low_S4S9 = 0.6; double High_S4S9 = 1.0; S4S9var->setRange(Low_S4S9,High_S4S9); S4S9var->setBins(Nbins_S4S9); TH2F *h_CC_S4S9 = hdata->createHistogram(*S4S9var, *ecorvar, "","cor_vs_S4S9"); h_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h_CC_S4S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S4S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S4S9.pdf"); myC_variables->SaveAs("cor_vs_S4S9.png"); TH2F *h_RC_S4S9 = hdata->createHistogram(*S4S9var, *rawvar, "","raw_vs_S4S9"); h_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h_RC_S4S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S4S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S4S9.pdf"); myC_variables->SaveAs("raw_vs_S4S9.png"); RooRealVar *S2S9var = ws->var("var_3"); int Nbins_S2S9 = 100; double Low_S2S9 = 0.5; double High_S2S9 = 1.0; S2S9var->setRange(Low_S2S9,High_S2S9); S2S9var->setBins(Nbins_S2S9); TH2F *h_CC_S2S9 = hdata->createHistogram(*S2S9var, *ecorvar, "","cor_vs_S2S9"); h_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h_CC_S2S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S2S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S2S9.pdf"); myC_variables->SaveAs("cor_vs_S2S9.png"); TH2F *h_RC_S2S9 = hdata->createHistogram(*S2S9var, *rawvar, "","raw_vs_S2S9"); h_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h_RC_S2S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S2S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S2S9.pdf"); myC_variables->SaveAs("raw_vs_S2S9.png"); TH2F *h_S2S9_eta = hdata->createHistogram(*scetaiXvar, *S2S9var, "","S2S9_vs_eta"); h_S2S9_eta->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S2S9_eta->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_eta.pdf"); myC_variables->SaveAs("S2S9_vs_eta.png"); TH2F *h_S4S9_eta = hdata->createHistogram(*scetaiXvar, *S4S9var, "","S4S9_vs_eta"); h_S4S9_eta->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S4S9_eta->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_eta.pdf"); myC_variables->SaveAs("S4S9_vs_eta.png"); TH2F *h_S2S9_phi = hdata->createHistogram(*scphiiYvar, *S2S9var, "","S2S9_vs_phi"); h_S2S9_phi->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S2S9_phi->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_phi.pdf"); myC_variables->SaveAs("S2S9_vs_phi.png"); TH2F *h_S4S9_phi = hdata->createHistogram(*scphiiYvar, *S4S9var, "","S4S9_vs_phi"); h_S4S9_phi->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S4S9_phi->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_phi.pdf"); myC_variables->SaveAs("S4S9_vs_phi.png"); if(EEorEB=="EE") { } TProfile *p_CC_eta = h_CC_eta->ProfileX("p_CC_eta");//,1,-1,"s"); p_CC_eta->GetYaxis()->SetRangeUser(0.8,1.05); if(EEorEB == "EB") { // p_CC_eta->GetYaxis()->SetRangeUser(0.85,1.0); // p_CC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_eta->SetTitle(""); p_CC_eta->Draw(); myC_variables->SaveAs("profile_cor_vs_eta.pdf"); myC_variables->SaveAs("profile_cor_vs_eta.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_CC_eta = new TH1F("h1_fit_CC_eta","h1_fit_CC_eta",(EEorEB=="EB") ? 180 : 50,(EEorEB=="EB") ? -90 : 0, (EEorEB=="EB") ? 90 : 50); for(int ix = 1;ix <= h_CC_eta->GetNbinsX(); ix++) { stringstream os_iEta; os_iEta << ((EEorEB=="EB") ? (-90 + ix -1) : (0 + ix -1)); string ss_iEta = os_iEta.str(); TH1D * h_temp = h_CC_eta->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.95,1.07); h_temp->Fit("f_temp","R"); h1_fit_CC_eta->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_CC_eta->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{cor}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/CC_iEta_"+ss_iEta+".pdf").c_str()); myC_variables->SaveAs(("fits/CC_iEta_"+ss_iEta+".png").c_str()); myC_variables->SaveAs(("fits/CC_iEta_"+ss_iEta+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_CC_eta->GetYaxis()->SetRangeUser(0.95,1.05); h1_fit_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h1_fit_CC_eta->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#eta" : "iX"); h1_fit_CC_eta->SetTitle(""); h1_fit_CC_eta->Draw(); myC_variables->SaveAs("profile_fit_cor_vs_eta.pdf"); myC_variables->SaveAs("profile_fit_cor_vs_eta.png"); myC_variables->SaveAs("profile_fit_cor_vs_eta.C"); TProfile *p_RC_eta = h_RC_eta->ProfileX("p_RC_eta");//,1,-1,"s"); p_RC_eta->GetYaxis()->SetRangeUser(0.8,1.05); if(EEorEB=="EB") { // p_RC_eta->GetYaxis()->SetRangeUser(0.80,0.95); // p_RC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_eta->SetTitle(""); p_RC_eta->Draw(); myC_variables->SaveAs("profile_raw_vs_eta.pdf"); myC_variables->SaveAs("profile_raw_vs_eta.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_RC_eta = new TH1F("h1_fit_RC_eta","h1_fit_RC_eta",(EEorEB=="EB") ? 180 : 50,(EEorEB=="EB") ? -90 : 0, (EEorEB=="EB") ? 90 : 50); for(int ix = 1;ix <= h_RC_eta->GetNbinsX(); ix++) { stringstream os_iEta; os_iEta << ((EEorEB=="EB") ? (-90 + ix -1) : (0 + ix -1)); string ss_iEta = os_iEta.str(); TH1D * h_temp = h_RC_eta->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.87,1.05); h_temp->Fit("f_temp","R"); h1_fit_RC_eta->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_RC_eta->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{raw}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/RC_iEta_"+ss_iEta+".pdf").c_str()); myC_variables->SaveAs(("fits/RC_iEta_"+ss_iEta+".png").c_str()); myC_variables->SaveAs(("fits/RC_iEta_"+ss_iEta+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_RC_eta->GetYaxis()->SetRangeUser(0.9,1.0); h1_fit_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h1_fit_RC_eta->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#eta" : "iX"); h1_fit_RC_eta->SetTitle(""); h1_fit_RC_eta->Draw(); myC_variables->SaveAs("profile_fit_raw_vs_eta.pdf"); myC_variables->SaveAs("profile_fit_raw_vs_eta.png"); myC_variables->SaveAs("profile_fit_raw_vs_eta.C"); int Nbins_iEta = EEorEB=="EB" ? 180 : 50; int nLow_iEta = EEorEB=="EB" ? -90 : 0; int nHigh_iEta = EEorEB=="EB" ? 90 : 50; TH1F *h1_RC_eta = new TH1F("h1_RC_eta","h1_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_RC_eta->SetBinContent(i,p_RC_eta->GetBinError(i)); } h1_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_RC_eta->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_eta->SetTitle(""); h1_RC_eta->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.png"); TH1F *h1_CC_eta = new TH1F("h1_CC_eta","h1_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_CC_eta->SetBinContent(i,p_CC_eta->GetBinError(i)); } h1_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_CC_eta->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_eta->SetTitle(""); h1_CC_eta->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.png"); TProfile *p_CC_phi = h_CC_phi->ProfileX("p_CC_phi");//,1,-1,"s"); p_CC_phi->GetYaxis()->SetRangeUser(0.9,1.0); if(EEorEB == "EB") { // p_CC_phi->GetYaxis()->SetRangeUser(0.94,1.00); } p_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_phi->SetTitle(""); p_CC_phi->Draw(); myC_variables->SaveAs("profile_cor_vs_phi.pdf"); myC_variables->SaveAs("profile_cor_vs_phi.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_CC_phi = new TH1F("h1_fit_CC_phi","h1_fit_CC_phi",(EEorEB=="EB") ? 360 : 50,(EEorEB=="EB") ? 0 : 0, (EEorEB=="EB") ? 360 : 50); for(int ix = 1;ix <= h_CC_phi->GetNbinsX(); ix++) { stringstream os_iPhi; os_iPhi << ((EEorEB=="EB") ? (0 + ix -1) : (0 + ix -1)); string ss_iPhi = os_iPhi.str(); TH1D * h_temp = h_CC_phi->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.95,1.07); h_temp->Fit("f_temp","R"); h1_fit_CC_phi->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_CC_phi->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{cor}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/CC_iPhi_"+ss_iPhi+".pdf").c_str()); myC_variables->SaveAs(("fits/CC_iPhi_"+ss_iPhi+".png").c_str()); myC_variables->SaveAs(("fits/CC_iPhi_"+ss_iPhi+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_CC_phi->GetYaxis()->SetRangeUser(0.95,1.05); h1_fit_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h1_fit_CC_phi->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#phi" : "iX"); h1_fit_CC_phi->SetTitle(""); h1_fit_CC_phi->Draw(); myC_variables->SaveAs("profile_fit_cor_vs_phi.pdf"); myC_variables->SaveAs("profile_fit_cor_vs_phi.png"); myC_variables->SaveAs("profile_fit_cor_vs_phi.C"); TProfile *p_RC_phi = h_RC_phi->ProfileX("p_RC_phi");//,1,-1,"s"); p_RC_phi->GetYaxis()->SetRangeUser(0.8,0.9); if(EEorEB=="EB") { // p_RC_phi->GetYaxis()->SetRangeUser(0.89,0.95); } p_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_phi->SetTitle(""); p_RC_phi->Draw(); myC_variables->SaveAs("profile_raw_vs_phi.pdf"); myC_variables->SaveAs("profile_raw_vs_phi.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_RC_phi = new TH1F("h1_fit_RC_phi","h1_fit_RC_phi",(EEorEB=="EB") ? 360 : 50,(EEorEB=="EB") ? 0 : 0, (EEorEB=="EB") ? 360 : 50); for(int ix = 1;ix <= h_RC_phi->GetNbinsX(); ix++) { stringstream os_iPhi; os_iPhi << ((EEorEB=="EB") ? (0 + ix -1) : (0 + ix -1)); string ss_iPhi = os_iPhi.str(); TH1D * h_temp = h_RC_phi->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.87,1.05); h_temp->Fit("f_temp","R"); h1_fit_RC_phi->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_RC_phi->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{raw}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/RC_iPhi_"+ss_iPhi+".pdf").c_str()); myC_variables->SaveAs(("fits/RC_iPhi_"+ss_iPhi+".png").c_str()); myC_variables->SaveAs(("fits/RC_iPhi_"+ss_iPhi+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_RC_phi->GetYaxis()->SetRangeUser(0.9,1.0); h1_fit_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h1_fit_RC_phi->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#phi" : "iX"); h1_fit_RC_phi->SetTitle(""); h1_fit_RC_phi->Draw(); myC_variables->SaveAs("profile_fit_raw_vs_phi.pdf"); myC_variables->SaveAs("profile_fit_raw_vs_phi.png"); myC_variables->SaveAs("profile_fit_raw_vs_phi.C"); int Nbins_iPhi = EEorEB=="EB" ? 360 : 50; int nLow_iPhi = EEorEB=="EB" ? 0 : 0; int nHigh_iPhi = EEorEB=="EB" ? 360 : 50; TH1F *h1_RC_phi = new TH1F("h1_RC_phi","h1_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_RC_phi->SetBinContent(i,p_RC_phi->GetBinError(i)); } h1_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_RC_phi->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_phi->SetTitle(""); h1_RC_phi->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.png"); TH1F *h1_CC_phi = new TH1F("h1_CC_phi","h1_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_CC_phi->SetBinContent(i,p_CC_phi->GetBinError(i)); } h1_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_CC_phi->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_phi->SetTitle(""); h1_CC_phi->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.png"); // FWHM over sigma_eff vs. eta/phi TH1F *h1_FoverS_RC_phi = new TH1F("h1_FoverS_RC_phi","h1_FoverS_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_CC_phi = new TH1F("h1_FoverS_CC_phi","h1_FoverS_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_RC_eta = new TH1F("h1_FoverS_RC_eta","h1_FoverS_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_eta = new TH1F("h1_FoverS_CC_eta","h1_FoverS_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_S2S9 = new TH1F("h1_FoverS_CC_S2S9","h1_FoverS_CC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_RC_S2S9 = new TH1F("h1_FoverS_RC_S2S9","h1_FoverS_RC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_CC_S4S9 = new TH1F("h1_FoverS_CC_S4S9","h1_FoverS_CC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); TH1F *h1_FoverS_RC_S4S9 = new TH1F("h1_FoverS_RC_S4S9","h1_FoverS_RC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); float FWHMoverSigmaEff = 0.0; TH1F *h_tmp_rawvar = new TH1F("tmp_rawvar","tmp_rawvar",800,0.5,1.5); TH1F *h_tmp_corvar = new TH1F("tmp_corvar","tmp_corvar",800,0.5,1.5); for(int i=1;i<=Nbins_iPhi;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_phi->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_phi->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_phi->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_phi->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_CC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_phi->SetTitle(""); h1_FoverS_CC_phi->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.png"); h1_FoverS_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_RC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_phi->SetTitle(""); h1_FoverS_RC_phi->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.png"); for(int i=1;i<=Nbins_iEta;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_eta->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_eta->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_eta->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_eta->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_CC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_eta->SetTitle(""); h1_FoverS_CC_eta->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.png"); h1_FoverS_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_RC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_eta->SetTitle(""); h1_FoverS_RC_eta->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.png"); for(int i=1;i<=Nbins_S2S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S2S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S2S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S2S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S2S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_CC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S2S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S2S9->SetTitle(""); h1_FoverS_CC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.png"); h1_FoverS_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_RC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S2S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S2S9->SetTitle(""); h1_FoverS_RC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.png"); for(int i=1;i<=Nbins_S4S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S4S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S4S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S4S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S4S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_CC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S4S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S4S9->SetTitle(""); h1_FoverS_CC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.png"); h1_FoverS_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_RC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S4S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S4S9->SetTitle(""); h1_FoverS_RC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.png"); printf("calc effsigma\n"); std::cout<<"_"<<EEorEB<<std::endl; printf("corrected curve effSigma= %5f, FWHM=%5f \n",effsigma_cor, fwhm_cor); printf("raw curve effSigma= %5f FWHM=%5f \n",effsigma_raw, fwhm_raw); /* new TCanvas; RooPlot *ploteold = testvar.frame(0.6,1.2,100); hdatasigtest->plotOn(ploteold); ploteold->Draw(); new TCanvas; RooPlot *plotecor = ecorvar->frame(0.6,1.2,100); hdatasig->plotOn(plotecor); plotecor->Draw(); */ }
void plot_pll(TString fname="monoh_withsm_SRCR_bg11.7_bgslop-0.0_nsig0.0.root") { SetAtlasStyle(); TFile* file = TFile::Open(fname); RooWorkspace* wspace = (RooWorkspace*) file->Get("wspace"); cout << "\n\ncheck that eff and reco terms included in BSM component to make fiducial cross-section" <<endl; wspace->function("nsig")->Print(); RooRealVar* reco = wspace->var("reco"); if( wspace->function("nsig")->dependsOn(*reco) ) { cout << "all good." <<endl; } else { cout << "need to rerun fit_withsm using DO_FIDUCIAL_LIMIT true" <<endl; return; } /* // DANGER // TEST WITH EXAGGERATED UNCERTAINTY wspace->var("unc_theory")->setMax(1); wspace->var("unc_theory")->setVal(1); wspace->var("unc_theory")->Print(); */ // this was for making plot about decoupling/recoupling approach TCanvas* tc = new TCanvas("tc","",400,400); RooPlot *frame = wspace->var("xsec_bsm")->frame(); RooAbsPdf* pdfc = wspace->pdf("jointModeld"); RooAbsData* data = wspace->data("data"); RooAbsReal *nllJoint = pdfc->createNLL(*data, RooFit::Constrained()); // slice with fixed xsec_bsm RooAbsReal *profileJoint = nllJoint->createProfile(*wspace->var("xsec_bsm")); wspace->allVars().Print("v"); pdfc->fitTo(*data); wspace->allVars().Print("v"); wspace->var("xsec_bsm")->Print(); double nllmin = 2*nllJoint->getVal(); wspace->var("xsec_bsm")->setVal(0); double nll0 = 2*nllJoint->getVal(); cout << Form("nllmin = %f, nll0 = %f, Z=%f", nllmin, nll0, sqrt(nll0-nllmin)) << endl; nllJoint->plotOn(frame, RooFit::LineColor(kGreen), RooFit::LineStyle(kDotted), RooFit::ShiftToZero(), RooFit::Name("nll_statonly")); // no error profileJoint->plotOn(frame,RooFit::Name("pll") ); wspace->var("xsec_sm")->Print(); wspace->var("theory")->Print(); wspace->var("theory")->setConstant(); profileJoint->plotOn(frame, RooFit::LineColor(kRed), RooFit::LineStyle(kDashed), RooFit::Name("pll_smfixed") ); frame->GetXaxis()->SetTitle("#sigma_{BSM, fid} [fb]"); frame->GetYaxis()->SetTitle("-log #lambda ( #sigma_{BSM, fid} )"); double temp = frame->GetYaxis()->GetTitleOffset(); frame->GetYaxis()->SetTitleOffset( 1.1* temp ); frame->SetMinimum(1e-7); frame->SetMaximum(4); // Legend double x1,y1,x2,y2; GetX1Y1X2Y2(tc,x1,y1,x2,y2); TLegend *legend_sr=FastLegend(x2-0.75,y2-0.3,x2-0.25,y2-0.5,0.045); legend_sr->AddEntry(frame->findObject("pll"),"with #sigma_{SM} uncertainty","L"); legend_sr->AddEntry(frame->findObject("pll_smfixed"),"with #sigma_{SM} constant","L"); legend_sr->AddEntry(frame->findObject("nll_statonly"),"no systematics","L"); frame->Draw(); legend_sr->Draw("SAME"); // descriptive text vector<TString> pavetext11; pavetext11.push_back("#bf{#it{ATLAS Internal}}"); pavetext11.push_back("#sqrt{#it{s}} = 8 TeV #scale[0.6]{#int}Ldt = 20.3 fb^{-1}"); pavetext11.push_back("#it{H}+#it{E}_{T}^{miss} , #it{H #rightarrow #gamma#gamma}, #it{m}_{#it{H}} = 125.4 GeV"); TPaveText* text11=CreatePaveText(x2-0.75,y2-0.25,x2-0.25,y2-0.05,pavetext11,0.045); text11->Draw(); tc->SaveAs("pll.pdf"); /* wspace->var("xsec_bsm")->setConstant(true); wspace->var("eff" )->setConstant(true); wspace->var("mh" )->setConstant(true); wspace->var("sigma_h" )->setConstant(true); wspace->var("lumi" )->setConstant(true); wspace->var("xsec_sm" )->setVal(v_xsec_sm); wspace->var("eff" )->setVal(1.0); wspace->var("lumi" )->setVal(v_lumi); TH1* nllHist = profileJoint->createHistogram("xsec_bsm",100); TFile* out = new TFile("nllHist.root","REPLACE"); nllHist->Write() out->Write(); out->Close(); */ }
void eregtesting_13TeV_Pi0(bool dobarrel=true, bool doele=false,int gammaID=0) { //output dir TString EEorEB = "EE"; if(dobarrel) { EEorEB = "EB"; } TString gammaDir = "bothGammas"; if(gammaID==1) { gammaDir = "gamma1"; } else if(gammaID==2) { gammaDir = "gamma2"; } TString dirname = TString::Format("ereg_test_plots/%s_%s",gammaDir.Data(),EEorEB.Data()); gSystem->mkdir(dirname,true); gSystem->cd(dirname); //read workspace from training TString fname; if (doele && dobarrel) fname = "wereg_ele_eb.root"; else if (doele && !dobarrel) fname = "wereg_ele_ee.root"; else if (!doele && dobarrel) fname = "wereg_ph_eb.root"; else if (!doele && !dobarrel) fname = "wereg_ph_ee.root"; TString infile = TString::Format("../../ereg_ws/%s/%s",gammaDir.Data(),fname.Data()); TFile *fws = TFile::Open(infile); RooWorkspace *ws = (RooWorkspace*)fws->Get("wereg"); //read variables from workspace RooGBRTargetFlex *meantgt = static_cast<RooGBRTargetFlex*>(ws->arg("sigmeant")); RooRealVar *tgtvar = ws->var("tgtvar"); RooArgList vars; vars.add(meantgt->FuncVars()); vars.add(*tgtvar); //read testing dataset from TTree RooRealVar weightvar("weightvar","",1.); TTree *dtree; if (doele) { //TFile *fdin = TFile::Open("root://eoscms.cern.ch//eos/cms/store/cmst3/user/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TFile *fdin = TFile::Open("/data/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterSingleInvert"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } else { if(dobarrel) { TFile *fdin = TFile::Open("/afs/cern.ch/work/z/zhicaiz/public/ECALpro_MC_TreeForRegression/Gun_Pi0_Pt1To15_FlatPU0to50RAW_withHLT_80X_mcRun2_GEN-SIM-RAW_ALL_EcalNtp_ALL_EB_combine_test.root");//("root://eoscms.cern.ch///eos/cms/store/cmst3/user/bendavid/idTreesAug1/hgg-2013Final8TeV_ID_s12-h124gg-gf-v7n_noskim.root"); // TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); if(gammaID==0) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma"); } else if(gammaID==1) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma1"); } else if(gammaID==2) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma2"); } } else { TFile *fdin = TFile::Open("/afs/cern.ch/work/z/zhicaiz/public/ECALpro_MC_TreeForRegression/Gun_Pi0_Pt1To15_FlatPU0to50RAW_withHLT_80X_mcRun2_GEN-SIM-RAW_ALL_EcalNtp_ALL_EE_combine_test.root");//("root://eoscms.cern.ch///eos/cms/store/cmst3/user/bendavid/idTreesAug1/hgg-2013Final8TeV_ID_s12-h124gg-gf-v7n_noskim.root"); // TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); if(gammaID==0) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma"); } else if(gammaID==1) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma1"); } else if(gammaID==2) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma2"); } } } //selection cuts for testing //TCut selcut = "(STr2_enG1_true/cosh(STr2_Eta_1)>1.0) && (STr2_S4S9_1>0.75)"; TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)>60)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03)"; /* TCut selcut; if (dobarrel) selcut = "ph.genpt>25. && ph.isbarrel && ph.ispromptgen"; else selcut = "ph.genpt>25. && !ph.isbarrel && ph.ispromptgen"; */ TCut selweight = "xsecweight(procidx)*puweight(numPU,procidx)"; TCut prescale10 = "(Entry$%10==0)"; TCut prescale10alt = "(Entry$%10==1)"; TCut prescale25 = "(Entry$%25==0)"; TCut prescale100 = "(Entry$%100==0)"; TCut prescale1000 = "(Entry$%1000==0)"; TCut evenevents = "(Entry$%2==0)"; TCut oddevents = "(Entry$%2==1)"; TCut prescale100alt = "(Entry$%100==1)"; TCut prescale1000alt = "(Entry$%1000==1)"; TCut prescale50alt = "(Entry$%50==1)"; TCut Events3_4 = "(Entry$%4==3)"; TCut Events1_4 = "(Entry$%4==1)"; TCut Events2_4 = "(Entry$%4==2)"; TCut Events0_4 = "(Entry$%4==0)"; TCut Events01_4 = "(Entry$%4<2)"; TCut Events23_4 = "(Entry$%4>1)"; if (doele) weightvar.SetTitle(prescale100alt*selcut); else weightvar.SetTitle(selcut); //make testing dataset RooDataSet *hdata = RooTreeConvert::CreateDataSet("hdata",dtree,vars,weightvar); if (doele) weightvar.SetTitle(prescale1000alt*selcut); else weightvar.SetTitle(prescale10alt*selcut); //make reduced testing dataset for integration over conditional variables RooDataSet *hdatasmall = RooTreeConvert::CreateDataSet("hdatasmall",dtree,vars,weightvar); //retrieve full pdf from workspace RooAbsPdf *sigpdf = ws->pdf("sigpdf"); //input variable corresponding to sceta RooRealVar *scetavar = ws->var("var_1"); RooRealVar *scphivar = ws->var("var_2"); //regressed output functions RooAbsReal *sigmeanlim = ws->function("sigmeanlim"); RooAbsReal *sigwidthlim = ws->function("sigwidthlim"); RooAbsReal *signlim = ws->function("signlim"); RooAbsReal *sign2lim = ws->function("sign2lim"); RooAbsReal *sigalphalim = ws->function("sigalphalim"); RooAbsReal *sigalpha2lim = ws->function("sigalpha2lim"); //formula for corrected energy/true energy ( 1.0/(etrue/eraw) * regression mean) RooFormulaVar ecor("ecor","","1./(@0)*@1",RooArgList(*tgtvar,*sigmeanlim)); RooRealVar *ecorvar = (RooRealVar*)hdata->addColumn(ecor); ecorvar->setRange(0.,2.); ecorvar->setBins(800); //formula for raw energy/true energy (1.0/(etrue/eraw)) RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); RooRealVar *rawvar = (RooRealVar*)hdata->addColumn(raw); rawvar->setRange(0.,2.); rawvar->setBins(800); //clone data and add regression outputs for plotting RooDataSet *hdataclone = new RooDataSet(*hdata,"hdataclone"); RooRealVar *meanvar = (RooRealVar*)hdataclone->addColumn(*sigmeanlim); RooRealVar *widthvar = (RooRealVar*)hdataclone->addColumn(*sigwidthlim); RooRealVar *nvar = (RooRealVar*)hdataclone->addColumn(*signlim); RooRealVar *n2var = (RooRealVar*)hdataclone->addColumn(*sign2lim); RooRealVar *alphavar = (RooRealVar*)hdataclone->addColumn(*sigalphalim); RooRealVar *alpha2var = (RooRealVar*)hdataclone->addColumn(*sigalpha2lim); //plot target variable and weighted regression prediction (using numerical integration over reduced testing dataset) TCanvas *craw = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot = tgtvar->frame(0.6,2.0,100); hdata->plotOn(plot); sigpdf->plotOn(plot,ProjWData(*hdatasmall)); plot->Draw(); craw->SaveAs("RawE.pdf"); craw->SaveAs("RawE.png"); craw->SetLogy(); plot->SetMinimum(0.1); craw->SaveAs("RawElog.pdf"); craw->SaveAs("RawElog.png"); //plot distribution of regressed functions over testing dataset TCanvas *cmean = new TCanvas; RooPlot *plotmean = meanvar->frame(0.8,2.0,100); hdataclone->plotOn(plotmean); plotmean->Draw(); cmean->SaveAs("mean.pdf"); cmean->SaveAs("mean.png"); TCanvas *cwidth = new TCanvas; RooPlot *plotwidth = widthvar->frame(0.,0.05,100); hdataclone->plotOn(plotwidth); plotwidth->Draw(); cwidth->SaveAs("width.pdf"); cwidth->SaveAs("width.png"); TCanvas *cn = new TCanvas; RooPlot *plotn = nvar->frame(0.,111.,200); hdataclone->plotOn(plotn); plotn->Draw(); cn->SaveAs("n.pdf"); cn->SaveAs("n.png"); TCanvas *cn2 = new TCanvas; RooPlot *plotn2 = n2var->frame(0.,111.,100); hdataclone->plotOn(plotn2); plotn2->Draw(); cn2->SaveAs("n2.pdf"); cn2->SaveAs("n2.png"); TCanvas *calpha = new TCanvas; RooPlot *plotalpha = alphavar->frame(0.,5.,200); hdataclone->plotOn(plotalpha); plotalpha->Draw(); calpha->SaveAs("alpha.pdf"); calpha->SaveAs("alpha.png"); TCanvas *calpha2 = new TCanvas; RooPlot *plotalpha2 = alpha2var->frame(0.,5.,200); hdataclone->plotOn(plotalpha2); plotalpha2->Draw(); calpha2->SaveAs("alpha2.pdf"); calpha2->SaveAs("alpha2.png"); TCanvas *ceta = new TCanvas; RooPlot *ploteta = scetavar->frame(-2.6,2.6,200); hdataclone->plotOn(ploteta); ploteta->Draw(); ceta->SaveAs("eta.pdf"); ceta->SaveAs("eta.png"); //create histograms for eraw/etrue and ecor/etrue to quantify regression performance TH1 *heraw;// = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.)); TH1 *hecor;// = hdata->createHistogram("hecor",*ecorvar); if (EEorEB == "EB") { heraw = hdata->createHistogram("hraw",*rawvar,Binning(800,0.8,1.1)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(800,0.8,1.1)); } else { heraw = hdata->createHistogram("hraw",*rawvar,Binning(200,0.,2.)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(200,0.,2.)); } //heold->SetLineColor(kRed); hecor->SetLineColor(kBlue); heraw->SetLineColor(kMagenta); hecor->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); heraw->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); hecor->GetXaxis()->SetRangeUser(0.0,1.5); heraw->GetXaxis()->SetRangeUser(0.0,1.5); /*if(EEorEB == "EE") { heraw->GetYaxis()->SetRangeUser(10.0,200.0); hecor->GetYaxis()->SetRangeUser(10.0,200.0); } */ //heold->GetXaxis()->SetRangeUser(0.6,1.2); double effsigma_cor, effsigma_raw, fwhm_cor, fwhm_raw; if(EEorEB == "EB") { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(200,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(200,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } else { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(200,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(200,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } TCanvas *cresponse = new TCanvas; gStyle->SetOptStat(0); gStyle->SetPalette(107); hecor->SetTitle(""); heraw->SetTitle(""); hecor->Draw("HIST"); //heold->Draw("HISTSAME"); heraw->Draw("HISTSAME"); //show errSigma in the plot TLegend *leg = new TLegend(0.1, 0.75, 0.7, 0.9); leg->AddEntry(hecor,Form("E_{cor}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_cor, fwhm_cor),"l"); leg->AddEntry(heraw,Form("E_{raw}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_raw, fwhm_raw),"l"); leg->SetFillStyle(0); leg->SetBorderSize(0); // leg->SetTextColor(kRed); leg->Draw(); cresponse->SaveAs("response.pdf"); cresponse->SaveAs("response.png"); cresponse->SetLogy(); cresponse->SaveAs("responselog.pdf"); cresponse->SaveAs("responselog.png"); // draw CCs vs eta and phi TCanvas *c_eta = new TCanvas; TH1 *h_eta = hdata->createHistogram("h_eta",*scetavar,Binning(100,-3.2,3.2)); h_eta->Draw("HIST"); c_eta->SaveAs("heta.pdf"); c_eta->SaveAs("heta.png"); TCanvas *c_phi = new TCanvas; TH1 *h_phi = hdata->createHistogram("h_phi",*scphivar,Binning(100,-3.2,3.2)); h_phi->Draw("HIST"); c_phi->SaveAs("hphi.pdf"); c_phi->SaveAs("hphi.png"); RooRealVar *scetaiXvar = ws->var("var_6"); RooRealVar *scphiiYvar = ws->var("var_7"); if(EEorEB=="EB") { scetaiXvar->setRange(-90,90); scetaiXvar->setBins(180); scphiiYvar->setRange(0,360); scphiiYvar->setBins(360); } else { scetaiXvar->setRange(0,50); scetaiXvar->setBins(50); scphiiYvar->setRange(0,50); scphiiYvar->setBins(50); } ecorvar->setRange(0.5,1.5); ecorvar->setBins(800); rawvar->setRange(0.5,1.5); rawvar->setBins(800); TCanvas *c_cor_eta = new TCanvas; TH2F *h_CC_eta = hdata->createHistogram(*scetaiXvar, *ecorvar, "","cor_vs_eta"); if(EEorEB=="EB") { h_CC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetXaxis()->SetTitle("iX"); } h_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_eta->Draw("COLZ"); c_cor_eta->SaveAs("cor_vs_eta.pdf"); c_cor_eta->SaveAs("cor_vs_eta.png"); TCanvas *c_cor_phi = new TCanvas; TH2F *h_CC_phi = hdata->createHistogram(*scphiiYvar, *ecorvar, "","cor_vs_phi"); if(EEorEB=="EB") { h_CC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetXaxis()->SetTitle("iY"); } h_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_phi->Draw("COLZ"); c_cor_phi->SaveAs("cor_vs_phi.pdf"); c_cor_phi->SaveAs("cor_vs_phi.png"); TCanvas *c_raw_eta = new TCanvas; TH2F *h_RC_eta = hdata->createHistogram(*scetaiXvar, *rawvar, "","raw_vs_eta"); if(EEorEB=="EB") { h_RC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_RC_eta->GetXaxis()->SetTitle("iX"); } h_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_eta->Draw("COLZ"); c_raw_eta->SaveAs("raw_vs_eta.pdf"); c_raw_eta->SaveAs("raw_vs_eta.png"); TCanvas *c_raw_phi = new TCanvas; TH2F *h_RC_phi = hdata->createHistogram(*scphiiYvar, *rawvar, "","raw_vs_phi"); if(EEorEB=="EB") { h_RC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_RC_phi->GetXaxis()->SetTitle("iY"); } h_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_phi->Draw("COLZ"); c_raw_phi->SaveAs("raw_vs_phi.pdf"); c_raw_phi->SaveAs("raw_vs_phi.png"); //on2,5,20, etc if(EEorEB == "EB") { TCanvas *myC_iCrystal_mod = new TCanvas; RooRealVar *iEtaOn5var = ws->var("var_8"); iEtaOn5var->setRange(0,5); iEtaOn5var->setBins(5); TH2F *h_CC_iEtaOn5 = hdata->createHistogram(*iEtaOn5var, *ecorvar, "","cor_vs_iEtaOn5"); h_CC_iEtaOn5->GetXaxis()->SetTitle("iEtaOn5"); h_CC_iEtaOn5->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iEtaOn5->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn5.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn5.png"); TH2F *h_RC_iEtaOn5 = hdata->createHistogram(*iEtaOn5var, *rawvar, "","raw_vs_iEtaOn5"); h_RC_iEtaOn5->GetXaxis()->SetTitle("iEtaOn5"); h_RC_iEtaOn5->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iEtaOn5->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn5.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn5.png"); RooRealVar *iPhiOn2var = ws->var("var_9"); iPhiOn2var->setRange(0,2); iPhiOn2var->setBins(2); TH2F *h_CC_iPhiOn2 = hdata->createHistogram(*iPhiOn2var, *ecorvar, "","cor_vs_iPhiOn2"); h_CC_iPhiOn2->GetXaxis()->SetTitle("iPhiOn2"); h_CC_iPhiOn2->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iPhiOn2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn2.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn2.png"); TH2F *h_RC_iPhiOn2 = hdata->createHistogram(*iPhiOn2var, *rawvar, "","raw_vs_iPhiOn2"); h_RC_iPhiOn2->GetXaxis()->SetTitle("iPhiOn2"); h_RC_iPhiOn2->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iPhiOn2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn2.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn2.png"); RooRealVar *iPhiOn20var = ws->var("var_10"); iPhiOn20var->setRange(0,20); iPhiOn20var->setBins(20); TH2F *h_CC_iPhiOn20 = hdata->createHistogram(*iPhiOn20var, *ecorvar, "","cor_vs_iPhiOn20"); h_CC_iPhiOn20->GetXaxis()->SetTitle("iPhiOn20"); h_CC_iPhiOn20->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iPhiOn20->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn20.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn20.png"); TH2F *h_RC_iPhiOn20 = hdata->createHistogram(*iPhiOn20var, *rawvar, "","raw_vs_iPhiOn20"); h_RC_iPhiOn20->GetXaxis()->SetTitle("iPhiOn20"); h_RC_iPhiOn20->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iPhiOn20->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn20.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn20.png"); RooRealVar *iEtaOn2520var = ws->var("var_11"); iEtaOn2520var->setRange(-25,25); iEtaOn2520var->setBins(50); TH2F *h_CC_iEtaOn2520 = hdata->createHistogram(*iEtaOn2520var, *ecorvar, "","cor_vs_iEtaOn2520"); h_CC_iEtaOn2520->GetXaxis()->SetTitle("iEtaOn2520"); h_CC_iEtaOn2520->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iEtaOn2520->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn2520.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn2520.png"); TH2F *h_RC_iEtaOn2520 = hdata->createHistogram(*iEtaOn2520var, *rawvar, "","raw_vs_iEtaOn2520"); h_RC_iEtaOn2520->GetXaxis()->SetTitle("iEtaOn2520"); h_RC_iEtaOn2520->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iEtaOn2520->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn2520.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn2520.png"); } // other variables TCanvas *myC_variables = new TCanvas; RooRealVar *Nxtalvar = ws->var("var_3"); Nxtalvar->setRange(0,10); Nxtalvar->setBins(10); TH2F *h_CC_Nxtal = hdata->createHistogram(*Nxtalvar, *ecorvar, "","cor_vs_Nxtal"); h_CC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_CC_Nxtal->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Nxtal.pdf"); myC_variables->SaveAs("cor_vs_Nxtal.png"); TH2F *h_RC_Nxtal = hdata->createHistogram(*Nxtalvar, *rawvar, "","raw_vs_Nxtal"); h_RC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_RC_Nxtal->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Nxtal.pdf"); myC_variables->SaveAs("raw_vs_Nxtal.png"); RooRealVar *S4S9var = ws->var("var_4"); int Nbins_S4S9 = 100; double Low_S4S9 = 0.6; double High_S4S9 = 1.0; S4S9var->setRange(Low_S4S9,High_S4S9); S4S9var->setBins(Nbins_S4S9); TH2F *h_CC_S4S9 = hdata->createHistogram(*S4S9var, *ecorvar, "","cor_vs_S4S9"); h_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h_CC_S4S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S4S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S4S9.pdf"); myC_variables->SaveAs("cor_vs_S4S9.png"); TH2F *h_RC_S4S9 = hdata->createHistogram(*S4S9var, *rawvar, "","raw_vs_S4S9"); h_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h_RC_S4S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S4S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S4S9.pdf"); myC_variables->SaveAs("raw_vs_S4S9.png"); /* RooRealVar *S1S9var = ws->var("var_5"); S1S9var->setRange(0.3,1.0); S1S9var->setBins(100); TH2F *h_CC_S1S9 = hdata->createHistogram(*S1S9var, *ecorvar, "","cor_vs_S1S9"); h_CC_S1S9->GetXaxis()->SetTitle("S1S9"); h_CC_S1S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S1S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S1S9.pdf"); TH2F *h_RC_S1S9 = hdata->createHistogram(*S1S9var, *rawvar, "","raw_vs_S1S9"); h_RC_S1S9->GetXaxis()->SetTitle("S1S9"); h_RC_S1S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S1S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S1S9.pdf"); */ RooRealVar *S2S9var = ws->var("var_5"); int Nbins_S2S9 = 100; double Low_S2S9 = 0.5; double High_S2S9 = 1.0; S2S9var->setRange(Low_S2S9,High_S2S9); S2S9var->setBins(Nbins_S2S9); TH2F *h_CC_S2S9 = hdata->createHistogram(*S2S9var, *ecorvar, "","cor_vs_S2S9"); h_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h_CC_S2S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S2S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S2S9.pdf"); myC_variables->SaveAs("cor_vs_S2S9.png"); TH2F *h_RC_S2S9 = hdata->createHistogram(*S2S9var, *rawvar, "","raw_vs_S2S9"); h_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h_RC_S2S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S2S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S2S9.pdf"); myC_variables->SaveAs("raw_vs_S2S9.png"); TH2F *h_S2S9_eta = hdata->createHistogram(*scetaiXvar, *S2S9var, "","S2S9_vs_eta"); h_S2S9_eta->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S2S9_eta->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_eta.pdf"); myC_variables->SaveAs("S2S9_vs_eta.png"); TH2F *h_S4S9_eta = hdata->createHistogram(*scetaiXvar, *S4S9var, "","S4S9_vs_eta"); h_S4S9_eta->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S4S9_eta->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_eta.pdf"); myC_variables->SaveAs("S4S9_vs_eta.png"); TH2F *h_S2S9_phi = hdata->createHistogram(*scphiiYvar, *S2S9var, "","S2S9_vs_phi"); h_S2S9_phi->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S2S9_phi->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_phi.pdf"); myC_variables->SaveAs("S2S9_vs_phi.png"); TH2F *h_S4S9_phi = hdata->createHistogram(*scphiiYvar, *S4S9var, "","S4S9_vs_phi"); h_S4S9_phi->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S4S9_phi->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_phi.pdf"); myC_variables->SaveAs("S4S9_vs_phi.png"); /* RooRealVar *DeltaRvar = ws->var("var_6"); DeltaRvar->setRange(0.0,0.1); DeltaRvar->setBins(100); TH2F *h_CC_DeltaR = hdata->createHistogram(*DeltaRvar, *ecorvar, "","cor_vs_DeltaR"); h_CC_DeltaR->GetXaxis()->SetTitle("#Delta R"); h_CC_DeltaR->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_DeltaR->Draw("COLZ"); myC_variables->SaveAs("cor_vs_DeltaR.pdf"); myC_variables->SaveAs("cor_vs_DeltaR.png"); TH2F *h_RC_DeltaR = hdata->createHistogram(*DeltaRvar, *rawvar, "","raw_vs_DeltaR"); h_RC_DeltaR->GetXaxis()->SetTitle("#Delta R"); h_RC_DeltaR->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_DeltaR->Draw("COLZ"); myC_variables->SaveAs("raw_vs_DeltaR.pdf"); myC_variables->SaveAs("raw_vs_DeltaR.png"); */ if(EEorEB=="EE") { /* RooRealVar *Es_e1var = ws->var("var_9"); Es_e1var->setRange(0.0,200.0); Es_e1var->setBins(1000); TH2F *h_CC_Es_e1 = hdata->createHistogram(*Es_e1var, *ecorvar, "","cor_vs_Es_e1"); h_CC_Es_e1->GetXaxis()->SetTitle("Es_e1"); h_CC_Es_e1->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Es_e1->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Es_e1.pdf"); myC_variables->SaveAs("cor_vs_Es_e1.png"); TH2F *h_RC_Es_e1 = hdata->createHistogram(*Es_e1var, *rawvar, "","raw_vs_Es_e1"); h_RC_Es_e1->GetXaxis()->SetTitle("Es_e1"); h_RC_Es_e1->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Es_e1->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Es_e1.pdf"); myC_variables->SaveAs("raw_vs_Es_e1.png"); RooRealVar *Es_e2var = ws->var("var_10"); Es_e2var->setRange(0.0,200.0); Es_e2var->setBins(1000); TH2F *h_CC_Es_e2 = hdata->createHistogram(*Es_e2var, *ecorvar, "","cor_vs_Es_e2"); h_CC_Es_e2->GetXaxis()->SetTitle("Es_e2"); h_CC_Es_e2->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Es_e2->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Es_e2.pdf"); myC_variables->SaveAs("cor_vs_Es_e2.png"); TH2F *h_RC_Es_e2 = hdata->createHistogram(*Es_e2var, *rawvar, "","raw_vs_Es_e2"); h_RC_Es_e2->GetXaxis()->SetTitle("Es_e2"); h_RC_Es_e2->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Es_e2->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Es_e2.pdf"); myC_variables->SaveAs("raw_vs_Es_e2.png"); */ } TProfile *p_CC_eta = h_CC_eta->ProfileX("p_CC_eta",1,-1,"s"); p_CC_eta->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB == "EB") { // p_CC_eta->GetYaxis()->SetRangeUser(0.85,1.0); // p_CC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_eta->SetTitle(""); p_CC_eta->Draw(); myC_variables->SaveAs("profile_cor_vs_eta.pdf"); myC_variables->SaveAs("profile_cor_vs_eta.png"); TProfile *p_RC_eta = h_RC_eta->ProfileX("p_RC_eta",1,-1,"s"); p_RC_eta->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB=="EB") { // p_RC_eta->GetYaxis()->SetRangeUser(0.80,0.95); // p_RC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_eta->SetTitle(""); p_RC_eta->Draw(); myC_variables->SaveAs("profile_raw_vs_eta.pdf"); myC_variables->SaveAs("profile_raw_vs_eta.png"); int Nbins_iEta = EEorEB=="EB" ? 180 : 50; int nLow_iEta = EEorEB=="EB" ? -90 : 0; int nHigh_iEta = EEorEB=="EB" ? 90 : 50; TH1F *h1_RC_eta = new TH1F("h1_RC_eta","h1_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_RC_eta->SetBinContent(i,p_RC_eta->GetBinError(i)); } h1_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_RC_eta->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_eta->SetTitle(""); h1_RC_eta->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.png"); TH1F *h1_CC_eta = new TH1F("h1_CC_eta","h1_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_CC_eta->SetBinContent(i,p_CC_eta->GetBinError(i)); } h1_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_CC_eta->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_eta->SetTitle(""); h1_CC_eta->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.png"); TProfile *p_CC_phi = h_CC_phi->ProfileX("p_CC_phi",1,-1,"s"); p_CC_phi->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB == "EB") { // p_CC_phi->GetYaxis()->SetRangeUser(0.94,1.00); } p_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_phi->SetTitle(""); p_CC_phi->Draw(); myC_variables->SaveAs("profile_cor_vs_phi.pdf"); myC_variables->SaveAs("profile_cor_vs_phi.png"); TProfile *p_RC_phi = h_RC_phi->ProfileX("p_RC_phi",1,-1,"s"); p_RC_phi->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB=="EB") { // p_RC_phi->GetYaxis()->SetRangeUser(0.89,0.95); } p_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_phi->SetTitle(""); p_RC_phi->Draw(); myC_variables->SaveAs("profile_raw_vs_phi.pdf"); myC_variables->SaveAs("profile_raw_vs_phi.png"); int Nbins_iPhi = EEorEB=="EB" ? 360 : 50; int nLow_iPhi = EEorEB=="EB" ? 0 : 0; int nHigh_iPhi = EEorEB=="EB" ? 360 : 50; TH1F *h1_RC_phi = new TH1F("h1_RC_phi","h1_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_RC_phi->SetBinContent(i,p_RC_phi->GetBinError(i)); } h1_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_RC_phi->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_phi->SetTitle(""); h1_RC_phi->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.png"); TH1F *h1_CC_phi = new TH1F("h1_CC_phi","h1_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_CC_phi->SetBinContent(i,p_CC_phi->GetBinError(i)); } h1_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_CC_phi->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_phi->SetTitle(""); h1_CC_phi->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.png"); // FWHM over sigma_eff vs. eta/phi TH1F *h1_FoverS_RC_phi = new TH1F("h1_FoverS_RC_phi","h1_FoverS_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_CC_phi = new TH1F("h1_FoverS_CC_phi","h1_FoverS_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_RC_eta = new TH1F("h1_FoverS_RC_eta","h1_FoverS_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_eta = new TH1F("h1_FoverS_CC_eta","h1_FoverS_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_S2S9 = new TH1F("h1_FoverS_CC_S2S9","h1_FoverS_CC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_RC_S2S9 = new TH1F("h1_FoverS_RC_S2S9","h1_FoverS_RC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_CC_S4S9 = new TH1F("h1_FoverS_CC_S4S9","h1_FoverS_CC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); TH1F *h1_FoverS_RC_S4S9 = new TH1F("h1_FoverS_RC_S4S9","h1_FoverS_RC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); float FWHMoverSigmaEff = 0.0; TH1F *h_tmp_rawvar = new TH1F("tmp_rawvar","tmp_rawvar",800,0.5,1.5); TH1F *h_tmp_corvar = new TH1F("tmp_corvar","tmp_corvar",800,0.5,1.5); for(int i=1;i<=Nbins_iPhi;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_phi->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_phi->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_phi->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_phi->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_CC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_phi->SetTitle(""); h1_FoverS_CC_phi->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.png"); h1_FoverS_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_RC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_phi->SetTitle(""); h1_FoverS_RC_phi->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.png"); for(int i=1;i<=Nbins_iEta;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_eta->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_eta->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_eta->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_eta->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_CC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_eta->SetTitle(""); h1_FoverS_CC_eta->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.png"); h1_FoverS_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_RC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_eta->SetTitle(""); h1_FoverS_RC_eta->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.png"); for(int i=1;i<=Nbins_S2S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S2S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S2S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S2S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S2S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_CC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S2S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S2S9->SetTitle(""); h1_FoverS_CC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.png"); h1_FoverS_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_RC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S2S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S2S9->SetTitle(""); h1_FoverS_RC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.png"); for(int i=1;i<=Nbins_S4S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S4S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S4S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S4S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S4S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_CC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S4S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S4S9->SetTitle(""); h1_FoverS_CC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.png"); h1_FoverS_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_RC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S4S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S4S9->SetTitle(""); h1_FoverS_RC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.png"); printf("calc effsigma\n"); std::cout<<"_"<<EEorEB<<std::endl; printf("corrected curve effSigma= %5f, FWHM=%5f \n",effsigma_cor, fwhm_cor); printf("raw curve effSigma= %5f FWHM=%5f \n",effsigma_raw, fwhm_raw); /* new TCanvas; RooPlot *ploteold = testvar.frame(0.6,1.2,100); hdatasigtest->plotOn(ploteold); ploteold->Draw(); new TCanvas; RooPlot *plotecor = ecorvar->frame(0.6,1.2,100); hdatasig->plotOn(plotecor); plotecor->Draw(); */ }
void constrained_scan( const char* wsfile = "outputfiles/ws.root", const char* new_poi_name="mu_bg_4b_msig_met1", double constraintWidth=1.5, int npoiPoints = 20, double poiMinVal = 0., double poiMaxVal = 10.0, double ymax = 9., int verbLevel=1 ) { TString outputdir("outputfiles") ; gStyle->SetOptStat(0) ; TFile* wstf = new TFile( wsfile ) ; RooWorkspace* ws = dynamic_cast<RooWorkspace*>( wstf->Get("ws") ); ws->Print() ; RooDataSet* rds = (RooDataSet*) ws->obj( "hbb_observed_rds" ) ; cout << "\n\n\n ===== RooDataSet ====================\n\n" << endl ; rds->Print() ; rds->printMultiline(cout, 1, kTRUE, "") ; RooRealVar* rv_sig_strength = ws->var("sig_strength") ; if ( rv_sig_strength == 0x0 ) { printf("\n\n *** can't find sig_strength in workspace.\n\n" ) ; return ; } RooAbsPdf* likelihood = ws->pdf("likelihood") ; if ( likelihood == 0x0 ) { printf("\n\n *** can't find likelihood in workspace.\n\n" ) ; return ; } printf("\n\n Likelihood:\n") ; likelihood -> Print() ; /////rv_sig_strength -> setConstant( kFALSE ) ; rv_sig_strength -> setVal(0.) ; rv_sig_strength -> setConstant( kTRUE ) ; likelihood->fitTo( *rds, Save(false), PrintLevel(0), Hesse(true), Strategy(1) ) ; //RooFitResult* fitResult = likelihood->fitTo( *rds, Save(true), PrintLevel(0), Hesse(true), Strategy(1) ) ; //double minNllSusyFloat = fitResult->minNll() ; //double susy_ss_atMinNll = rv_sig_strength -> getVal() ; RooMsgService::instance().getStream(1).removeTopic(Minimization) ; RooMsgService::instance().getStream(1).removeTopic(Fitting) ; //-- Construct the new POI parameter. RooAbsReal* new_poi_rar(0x0) ; new_poi_rar = ws->var( new_poi_name ) ; if ( new_poi_rar == 0x0 ) { printf("\n\n New POI %s is not a variable. Trying function.\n\n", new_poi_name ) ; new_poi_rar = ws->function( new_poi_name ) ; if ( new_poi_rar == 0x0 ) { printf("\n\n New POI %s is not a function. I quit.\n\n", new_poi_name ) ; return ; } else { printf("\n Found it.\n\n") ; } } else { printf("\n\n New POI %s is a variable with current value %.1f.\n\n", new_poi_name, new_poi_rar->getVal() ) ; } double startPoiVal = new_poi_rar->getVal() ; RooAbsReal* nll = likelihood -> createNLL( *rds, Verbose(true) ) ; RooRealVar* rrv_poiValue = new RooRealVar( "poiValue", "poiValue", 0., -10000., 10000. ) ; RooRealVar* rrv_constraintWidth = new RooRealVar("constraintWidth","constraintWidth", 0.1, 0.1, 1000. ) ; rrv_constraintWidth -> setVal( constraintWidth ) ; rrv_constraintWidth -> setConstant(kTRUE) ; RooMinuit* rminuit( 0x0 ) ; RooMinuit* rminuit_uc = new RooMinuit( *nll ) ; rminuit_uc->setPrintLevel(verbLevel-1) ; rminuit_uc->setNoWarn() ; rminuit_uc->migrad() ; rminuit_uc->hesse() ; RooFitResult* rfr_uc = rminuit_uc->fit("mr") ; double floatParInitVal[10000] ; char floatParName[10000][100] ; int nFloatParInitVal(0) ; RooArgList ral_floats = rfr_uc->floatParsFinal() ; TIterator* floatParIter = ral_floats.createIterator() ; { RooRealVar* par ; while ( (par = (RooRealVar*) floatParIter->Next()) ) { sprintf( floatParName[nFloatParInitVal], "%s", par->GetName() ) ; floatParInitVal[nFloatParInitVal] = par->getVal() ; nFloatParInitVal++ ; } } printf("\n\n Unbiased best value for new POI %s is : %7.1f\n\n", new_poi_rar->GetName(), new_poi_rar->getVal() ) ; double best_poi_val = new_poi_rar->getVal() ; char minuit_formula[10000] ; sprintf( minuit_formula, "%s+%s*(%s-%s)*(%s-%s)", nll->GetName(), rrv_constraintWidth->GetName(), new_poi_rar->GetName(), rrv_poiValue->GetName(), new_poi_rar->GetName(), rrv_poiValue->GetName() ) ; printf("\n\n Creating new minuit variable with formula: %s\n\n", minuit_formula ) ; RooFormulaVar* new_minuit_var = new RooFormulaVar("new_minuit_var", minuit_formula, RooArgList( *nll, *rrv_constraintWidth, *new_poi_rar, *rrv_poiValue, *new_poi_rar, *rrv_poiValue ) ) ; printf("\n\n Current value is %.2f\n\n", new_minuit_var->getVal() ) ; rminuit = new RooMinuit( *new_minuit_var ) ; RooAbsReal* plot_var = nll ; printf("\n\n Current value is %.2f\n\n", plot_var->getVal() ) ; rminuit->setPrintLevel(verbLevel-1) ; if ( verbLevel <=0 ) { rminuit->setNoWarn() ; } if ( poiMinVal < 0. && poiMaxVal < 0. ) { printf("\n\n Automatic determination of scan range.\n\n") ; if ( startPoiVal <= 0. ) { printf("\n\n *** POI starting value zero or negative %g. Quit.\n\n\n", startPoiVal ) ; return ; } poiMinVal = startPoiVal - 3.5 * sqrt(startPoiVal) ; poiMaxVal = startPoiVal + 6.0 * sqrt(startPoiVal) ; if ( poiMinVal < 0. ) { poiMinVal = 0. ; } printf(" Start val = %g. Scan range: %g to %g\n\n", startPoiVal, poiMinVal, poiMaxVal ) ; } //---------------------------------------------------------------------------------------------- double poiVals_scanDown[1000] ; double nllVals_scanDown[1000] ; //-- Do scan down from best value. printf("\n\n +++++ Starting scan down from best value.\n\n") ; double minNllVal(1.e9) ; for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) { ////double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*(npoiPoints-1)) ; double poiValue = best_poi_val - poivi*(best_poi_val-poiMinVal)/(1.*(npoiPoints/2-1)) ; rrv_poiValue -> setVal( poiValue ) ; rrv_poiValue -> setConstant( kTRUE ) ; //+++++++++++++++++++++++++++++++++++ rminuit->migrad() ; rminuit->hesse() ; RooFitResult* rfr = rminuit->save() ; //+++++++++++++++++++++++++++++++++++ if ( verbLevel > 0 ) { rfr->Print("v") ; } float fit_minuit_var_val = rfr->minNll() ; printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI : %.5f %.5f %.5f %.5f\n", poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ; cout << flush ; poiVals_scanDown[poivi] = new_poi_rar->getVal() ; nllVals_scanDown[poivi] = plot_var->getVal() ; if ( nllVals_scanDown[poivi] < minNllVal ) { minNllVal = nllVals_scanDown[poivi] ; } delete rfr ; } // poivi printf("\n\n +++++ Resetting floats to best fit values.\n\n") ; for ( int pi=0; pi<nFloatParInitVal; pi++ ) { RooRealVar* par = ws->var( floatParName[pi] ) ; par->setVal( floatParInitVal[pi] ) ; } // pi. printf("\n\n +++++ Starting scan up from best value.\n\n") ; //-- Now do scan up. double poiVals_scanUp[1000] ; double nllVals_scanUp[1000] ; for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) { double poiValue = best_poi_val + poivi*(poiMaxVal-best_poi_val)/(1.*(npoiPoints/2-1)) ; rrv_poiValue -> setVal( poiValue ) ; rrv_poiValue -> setConstant( kTRUE ) ; //+++++++++++++++++++++++++++++++++++ rminuit->migrad() ; rminuit->hesse() ; RooFitResult* rfr = rminuit->save() ; //+++++++++++++++++++++++++++++++++++ if ( verbLevel > 0 ) { rfr->Print("v") ; } float fit_minuit_var_val = rfr->minNll() ; printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI : %.5f %.5f %.5f %.5f\n", poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ; cout << flush ; poiVals_scanUp[poivi] = new_poi_rar->getVal() ; nllVals_scanUp[poivi] = plot_var->getVal() ; if ( nllVals_scanUp[poivi] < minNllVal ) { minNllVal = nllVals_scanUp[poivi] ; } delete rfr ; } // poivi double poiVals[1000] ; double nllVals[1000] ; int pointCount(0) ; for ( int pi=0; pi<npoiPoints/2; pi++ ) { poiVals[pi] = poiVals_scanDown[(npoiPoints/2-1)-pi] ; nllVals[pi] = nllVals_scanDown[(npoiPoints/2-1)-pi] ; pointCount++ ; } for ( int pi=1; pi<npoiPoints/2; pi++ ) { poiVals[pointCount] = poiVals_scanUp[pi] ; nllVals[pointCount] = nllVals_scanUp[pi] ; pointCount++ ; } npoiPoints = pointCount ; printf("\n\n --- TGraph arrays:\n") ; for ( int i=0; i<npoiPoints; i++ ) { printf(" %2d : poi = %6.1f, nll = %g\n", i, poiVals[i], nllVals[i] ) ; } printf("\n\n") ; double nllDiffVals[1000] ; double poiAtMinlnL(-1.) ; double poiAtMinusDelta2(-1.) ; double poiAtPlusDelta2(-1.) ; for ( int poivi=0; poivi < npoiPoints ; poivi++ ) { nllDiffVals[poivi] = 2.*(nllVals[poivi] - minNllVal) ; double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*npoiPoints) ; if ( nllDiffVals[poivi] < 0.01 ) { poiAtMinlnL = poiValue ; } if ( poiAtMinusDelta2 < 0. && nllDiffVals[poivi] < 2.5 ) { poiAtMinusDelta2 = poiValue ; } if ( poiAtMinlnL > 0. && poiAtPlusDelta2 < 0. && nllDiffVals[poivi] > 2.0 ) { poiAtPlusDelta2 = poiValue ; } } // poivi printf("\n\n Estimates for poi at delta ln L = -2, 0, +2: %g , %g , %g\n\n", poiAtMinusDelta2, poiAtMinlnL, poiAtPlusDelta2 ) ; //--- Main canvas TCanvas* cscan = (TCanvas*) gDirectory->FindObject("cscan") ; if ( cscan == 0x0 ) { printf("\n Creating canvas.\n\n") ; cscan = new TCanvas("cscan","Delta nll") ; } char gname[1000] ; TGraph* graph = new TGraph( npoiPoints, poiVals, nllDiffVals ) ; sprintf( gname, "scan_%s", new_poi_name ) ; graph->SetName( gname ) ; double poiBest(-1.) ; double poiMinus1stdv(-1.) ; double poiPlus1stdv(-1.) ; double poiMinus2stdv(-1.) ; double poiPlus2stdv(-1.) ; double twoDeltalnLMin(1e9) ; int nscan(1000) ; for ( int xi=0; xi<nscan; xi++ ) { double x = poiVals[0] + xi*(poiVals[npoiPoints-1]-poiVals[0])/(nscan-1) ; double twoDeltalnL = graph -> Eval( x, 0, "S" ) ; if ( poiMinus1stdv < 0. && twoDeltalnL < 1.0 ) { poiMinus1stdv = x ; printf(" set m1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( poiMinus2stdv < 0. && twoDeltalnL < 4.0 ) { poiMinus2stdv = x ; printf(" set m2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( twoDeltalnL < twoDeltalnLMin ) { poiBest = x ; twoDeltalnLMin = twoDeltalnL ; } if ( twoDeltalnLMin < 0.3 && poiPlus1stdv < 0. && twoDeltalnL > 1.0 ) { poiPlus1stdv = x ; printf(" set p1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( twoDeltalnLMin < 0.3 && poiPlus2stdv < 0. && twoDeltalnL > 4.0 ) { poiPlus2stdv = x ; printf(" set p2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( xi%100 == 0 ) { printf( " %4d : poi=%6.2f, 2DeltalnL = %6.2f\n", xi, x, twoDeltalnL ) ; } } printf("\n\n POI estimate : %g +%g -%g [%g,%g], two sigma errors: +%g -%g [%g,%g]\n\n", poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), poiMinus1stdv, poiPlus1stdv, (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv), poiMinus2stdv, poiPlus2stdv ) ; printf(" %s val,pm1sig,pm2sig: %7.2f %7.2f %7.2f %7.2f %7.2f\n", new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv) ) ; char htitle[1000] ; sprintf(htitle, "%s profile likelihood scan: -2ln(L/Lm)", new_poi_name ) ; TH1F* hscan = new TH1F("hscan", htitle, 10, poiMinVal, poiMaxVal ) ; hscan->SetMinimum(0.) ; hscan->SetMaximum(ymax) ; hscan->DrawCopy() ; graph->SetLineColor(4) ; graph->SetLineWidth(3) ; graph->Draw("CP") ; gPad->SetGridx(1) ; gPad->SetGridy(1) ; cscan->Update() ; TLine* line = new TLine() ; line->SetLineColor(2) ; line->DrawLine(poiMinVal, 1., poiPlus1stdv, 1.) ; line->DrawLine(poiMinus1stdv,0., poiMinus1stdv, 1.) ; line->DrawLine(poiPlus1stdv ,0., poiPlus1stdv , 1.) ; TText* text = new TText() ; text->SetTextSize(0.04) ; char tstring[1000] ; sprintf( tstring, "%s = %.1f +%.1f -%.1f", new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv) ) ; text -> DrawTextNDC( 0.15, 0.85, tstring ) ; sprintf( tstring, "68%% interval [%.1f, %.1f]", poiMinus1stdv, poiPlus1stdv ) ; text -> DrawTextNDC( 0.15, 0.78, tstring ) ; char hname[1000] ; sprintf( hname, "hscanout_%s", new_poi_name ) ; TH1F* hsout = new TH1F( hname,"scan results",4,0.,4.) ; double obsVal(-1.) ; hsout->SetBinContent(1, obsVal ) ; hsout->SetBinContent(2, poiPlus1stdv ) ; hsout->SetBinContent(3, poiBest ) ; hsout->SetBinContent(4, poiMinus1stdv ) ; TAxis* xaxis = hsout->GetXaxis() ; xaxis->SetBinLabel(1,"Observed val.") ; xaxis->SetBinLabel(2,"Model+1sd") ; xaxis->SetBinLabel(3,"Model") ; xaxis->SetBinLabel(4,"Model-1sd") ; char outrootfile[10000] ; sprintf( outrootfile, "%s/scan-ff-%s.root", outputdir.Data(), new_poi_name ) ; char outpdffile[10000] ; sprintf( outpdffile, "%s/scan-ff-%s.pdf", outputdir.Data(), new_poi_name ) ; cscan->Update() ; cscan->Draw() ; printf("\n Saving %s\n", outpdffile ) ; cscan->SaveAs( outpdffile ) ; //--- save in root file printf("\n Saving %s\n", outrootfile ) ; TFile fout(outrootfile,"recreate") ; graph->Write() ; hsout->Write() ; fout.Close() ; delete ws ; wstf->Close() ; } // constrained_scan.
void ws_cls_hybrid1_ag( const char* wsfile = "output-files/expected-ws-lm9-2BL.root", bool isBgonlyStudy=false, double poiVal = 150.0, int nToys=100, bool makeTtree=true, int verbLevel=0 ) { TTree* toytt(0x0) ; TFile* ttfile(0x0) ; int tt_gen_Nsig ; int tt_gen_Nsb ; int tt_gen_Nsig_sl ; int tt_gen_Nsb_sl ; int tt_gen_Nsig_ldp ; int tt_gen_Nsb_ldp ; int tt_gen_Nsig_ee ; int tt_gen_Nsb_ee ; int tt_gen_Nsig_mm ; int tt_gen_Nsb_mm ; double tt_testStat ; double tt_dataTestStat ; double tt_hypo_mu_susy_sig ; char ttname[1000] ; char tttitle[1000] ; if ( makeTtree ) { ttfile = gDirectory->GetFile() ; if ( ttfile == 0x0 ) { printf("\n\n\n *** asked for a ttree but no open file???\n\n") ; return ; } if ( isBgonlyStudy ) { sprintf( ttname, "toytt_%.0f_bgo", poiVal ) ; sprintf( tttitle, "Toy study for background only, mu_susy_sig = %.0f", poiVal ) ; } else { sprintf( ttname, "toytt_%.0f_spb", poiVal ) ; sprintf( tttitle, "Toy study for signal+background, mu_susy_sig = %.0f", poiVal ) ; } printf("\n\n Creating TTree : %s : %s\n\n", ttname, tttitle ) ; gDirectory->pwd() ; gDirectory->ls() ; toytt = new TTree( ttname, tttitle ) ; gDirectory->ls() ; toytt -> Branch( "gen_Nsig" , &tt_gen_Nsig , "gen_Nsig/I" ) ; toytt -> Branch( "gen_Nsb" , &tt_gen_Nsb , "gen_Nsb/I" ) ; toytt -> Branch( "gen_Nsig_sl" , &tt_gen_Nsig_sl , "gen_Nsig_sl/I" ) ; toytt -> Branch( "gen_Nsb_sl" , &tt_gen_Nsb_sl , "gen_Nsb_sl/I" ) ; toytt -> Branch( "gen_Nsig_ldp" , &tt_gen_Nsig_ldp , "gen_Nsig_ldp/I" ) ; toytt -> Branch( "gen_Nsb_ldp" , &tt_gen_Nsb_ldp , "gen_Nsb_ldp/I" ) ; toytt -> Branch( "gen_Nsig_ee" , &tt_gen_Nsig_ee , "gen_Nsig_ee/I" ) ; toytt -> Branch( "gen_Nsb_ee" , &tt_gen_Nsb_ee , "gen_Nsb_ee/I" ) ; toytt -> Branch( "gen_Nsig_mm" , &tt_gen_Nsig_mm , "gen_Nsig_mm/I" ) ; toytt -> Branch( "gen_Nsb_mm" , &tt_gen_Nsb_mm , "gen_Nsb_mm/I" ) ; toytt -> Branch( "testStat" , &tt_testStat , "testStat/D" ) ; toytt -> Branch( "dataTestStat" , &tt_dataTestStat , "dataTestStat/D" ) ; toytt -> Branch( "hypo_mu_susy_sig" , &tt_hypo_mu_susy_sig , "hypo_mu_susy_sig/D" ) ; } //--- Tell RooFit to shut up about anything less important than an ERROR. RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR) ; random_ng = new TRandom2(12345) ; /// char sel[100] ; /// if ( strstr( wsfile, "1BL" ) != 0 ) { /// sprintf( sel, "1BL" ) ; /// } else if ( strstr( wsfile, "2BL" ) != 0 ) { /// sprintf( sel, "2BL" ) ; /// } else if ( strstr( wsfile, "3B" ) != 0 ) { /// sprintf( sel, "3B" ) ; /// } else if ( strstr( wsfile, "1BT" ) != 0 ) { /// sprintf( sel, "1BT" ) ; /// } else if ( strstr( wsfile, "2BT" ) != 0 ) { /// sprintf( sel, "2BT" ) ; /// } else { /// printf("\n\n\n *** can't figure out which selection this is. I quit.\n\n" ) ; /// return ; /// } /// printf("\n\n selection is %s\n\n", sel ) ; TFile* wstf = new TFile( wsfile ) ; RooWorkspace* ws = dynamic_cast<RooWorkspace*>( wstf->Get("ws") ); ws->Print() ; RooDataSet* rds = (RooDataSet*) ws->obj( "ra2b_observed_rds" ) ; printf("\n\n\n ===== RooDataSet ====================\n\n") ; rds->Print() ; rds->printMultiline(cout, 1, kTRUE, "") ; ModelConfig* modelConfig = (ModelConfig*) ws->obj( "SbModel" ) ; RooAbsPdf* likelihood = modelConfig->GetPdf() ; const RooArgSet* nuisanceParameters = modelConfig->GetNuisanceParameters() ; RooRealVar* rrv_mu_susy_sig = ws->var("mu_susy_sig") ; if ( rrv_mu_susy_sig == 0x0 ) { printf("\n\n\n *** can't find mu_susy_sig in workspace. Quitting.\n\n\n") ; return ; } //// printf("\n\n\n ===== Doing a fit ====================\n\n") ; //// RooFitResult* preFitResult = likelihood->fitTo( *rds, Save(true) ) ; //// const RooArgList preFitFloatVals = preFitResult->floatParsFinal() ; //// { //// TIterator* parIter = preFitFloatVals.createIterator() ; //// while ( RooRealVar* par = (RooRealVar*) parIter->Next() ) { //// printf(" %20s : %8.2f\n", par->GetName(), par->getVal() ) ; //// } //// } //--- Get pointers to the model predictions of the observables. rfv_n_sig = ws->function("n_sig") ; rfv_n_sb = ws->function("n_sb") ; rfv_n_sig_sl = ws->function("n_sig_sl") ; rfv_n_sb_sl = ws->function("n_sb_sl") ; rfv_n_sig_ldp = ws->function("n_sig_ldp") ; rfv_n_sb_ldp = ws->function("n_sb_ldp") ; rfv_n_sig_ee = ws->function("n_sig_ee") ; rfv_n_sb_ee = ws->function("n_sb_ee") ; rfv_n_sig_mm = ws->function("n_sig_mm") ; rfv_n_sb_mm = ws->function("n_sb_mm") ; if ( rfv_n_sig == 0x0 ) { printf("\n\n\n *** can't find n_sig in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sb == 0x0 ) { printf("\n\n\n *** can't find n_sb in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sig_sl == 0x0 ) { printf("\n\n\n *** can't find n_sig_sl in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sb_sl == 0x0 ) { printf("\n\n\n *** can't find n_sb_sl in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sig_ldp == 0x0 ) { printf("\n\n\n *** can't find n_sig_ldp in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sb_ldp == 0x0 ) { printf("\n\n\n *** can't find n_sb_ldp in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sig_ee == 0x0 ) { printf("\n\n\n *** can't find n_sig_ee in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sb_ee == 0x0 ) { printf("\n\n\n *** can't find n_sb_ee in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sig_mm == 0x0 ) { printf("\n\n\n *** can't find n_sig_mm in workspace. Quitting.\n\n\n") ; return ; } if ( rfv_n_sb_mm == 0x0 ) { printf("\n\n\n *** can't find n_sb_mm in workspace. Quitting.\n\n\n") ; return ; } //--- Get pointers to the observables. const RooArgSet* dsras = rds->get() ; TIterator* obsIter = dsras->createIterator() ; while ( RooRealVar* obs = (RooRealVar*) obsIter->Next() ) { if ( strcmp( obs->GetName(), "Nsig" ) == 0 ) { rrv_Nsig = obs ; } if ( strcmp( obs->GetName(), "Nsb" ) == 0 ) { rrv_Nsb = obs ; } if ( strcmp( obs->GetName(), "Nsig_sl" ) == 0 ) { rrv_Nsig_sl = obs ; } if ( strcmp( obs->GetName(), "Nsb_sl" ) == 0 ) { rrv_Nsb_sl = obs ; } if ( strcmp( obs->GetName(), "Nsig_ldp" ) == 0 ) { rrv_Nsig_ldp = obs ; } if ( strcmp( obs->GetName(), "Nsb_ldp" ) == 0 ) { rrv_Nsb_ldp = obs ; } if ( strcmp( obs->GetName(), "Nsig_ee" ) == 0 ) { rrv_Nsig_ee = obs ; } if ( strcmp( obs->GetName(), "Nsb_ee" ) == 0 ) { rrv_Nsb_ee = obs ; } if ( strcmp( obs->GetName(), "Nsig_mm" ) == 0 ) { rrv_Nsig_mm = obs ; } if ( strcmp( obs->GetName(), "Nsb_mm" ) == 0 ) { rrv_Nsb_mm = obs ; } } if ( rrv_Nsig == 0x0 ) { printf("\n\n\n *** can't find Nsig in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsb == 0x0 ) { printf("\n\n\n *** can't find Nsb in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsig_sl == 0x0 ) { printf("\n\n\n *** can't find Nsig_sl in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsb_sl == 0x0 ) { printf("\n\n\n *** can't find Nsb_sl in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsig_ldp == 0x0 ) { printf("\n\n\n *** can't find Nsig_ldp in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsb_ldp == 0x0 ) { printf("\n\n\n *** can't find Nsb_ldp in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsig_ee == 0x0 ) { printf("\n\n\n *** can't find Nsig_ee in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsb_ee == 0x0 ) { printf("\n\n\n *** can't find Nsb_ee in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsig_mm == 0x0 ) { printf("\n\n\n *** can't find Nsig_mm in dataset. Quitting.\n\n\n") ; return ; } if ( rrv_Nsb_mm == 0x0 ) { printf("\n\n\n *** can't find Nsb_mm in dataset. Quitting.\n\n\n") ; return ; } printf("\n\n\n === Model values for observables\n\n") ; printObservables() ; //--- save the actual values of the observables. saveObservables() ; //--- evaluate the test stat on the data: fit with susy floating. rrv_mu_susy_sig->setVal( poiVal ) ; rrv_mu_susy_sig->setConstant( kTRUE ) ; printf("\n\n\n ====== Fitting the data with susy fixed.\n\n") ; RooFitResult* dataFitResultSusyFixed = likelihood->fitTo(*rds, Save(true)); int dataSusyFixedFitCovQual = dataFitResultSusyFixed->covQual() ; if ( dataSusyFixedFitCovQual != 3 ) { printf("\n\n\n *** Failed fit! Cov qual %d. Quitting.\n\n", dataSusyFixedFitCovQual ) ; return ; } double dataFitSusyFixedNll = dataFitResultSusyFixed->minNll() ; rrv_mu_susy_sig->setVal( 0.0 ) ; rrv_mu_susy_sig->setConstant( kFALSE ) ; printf("\n\n\n ====== Fitting the data with susy floating.\n\n") ; RooFitResult* dataFitResultSusyFloat = likelihood->fitTo(*rds, Save(true)); int dataSusyFloatFitCovQual = dataFitResultSusyFloat->covQual() ; if ( dataSusyFloatFitCovQual != 3 ) { printf("\n\n\n *** Failed fit! Cov qual %d. Quitting.\n\n", dataSusyFloatFitCovQual ) ; return ; } double dataFitSusyFloatNll = dataFitResultSusyFloat->minNll() ; double dataTestStat = 2.*( dataFitSusyFixedNll - dataFitSusyFloatNll) ; printf("\n\n\n Data value of test stat : %8.2f\n", dataTestStat ) ; printf("\n\n\n === Nuisance parameters\n\n") ; { int npi(0) ; TIterator* npIter = nuisanceParameters->createIterator() ; while ( RooRealVar* np_rrv = (RooRealVar*) npIter->Next() ) { np_initial_val[npi] = np_rrv->getVal() ; //--- I am assuming that the order of the NPs in the iterator does not change. TString npname( np_rrv->GetName() ) ; npname.ReplaceAll("_prim","") ; RooAbsReal* np_rfv = ws->function( npname ) ; TString pdfname( np_rrv->GetName() ) ; pdfname.ReplaceAll("_prim","") ; pdfname.Prepend("pdf_") ; RooAbsPdf* np_pdf = ws->pdf( pdfname ) ; if ( np_pdf == 0x0 ) { printf("\n\n *** Can't find nuisance parameter pdf with name %s.\n\n", pdfname.Data() ) ; } if ( np_rfv != 0x0 ) { printf(" %20s : %8.2f , %20s, %8.2f\n", np_rrv->GetName(), np_rrv->getVal(), np_rfv->GetName(), np_rfv->getVal() ) ; } else { printf(" %20s : %8.2f\n", np_rrv->GetName(), np_rrv->getVal() ) ; } npi++ ; } // np_rrv iterator. np_count = npi ; } tt_dataTestStat = dataTestStat ; tt_hypo_mu_susy_sig = poiVal ; printf("\n\n\n === Doing the toys\n\n") ; int nToyOK(0) ; int nToyWorseThanData(0) ; for ( int ti=0; ti<nToys; ti++ ) { printf("\n\n\n ======= Toy %4d\n\n\n", ti ) ; //--- 1) pick values for the nuisance parameters from the PDFs and fix them. { TIterator* npIter = nuisanceParameters->createIterator() ; while ( RooRealVar* np_rrv = (RooRealVar*) npIter->Next() ) { TString pdfname( np_rrv->GetName() ) ; pdfname.ReplaceAll("_prim","") ; pdfname.Prepend("pdf_") ; RooAbsPdf* np_pdf = ws->pdf( pdfname ) ; if ( np_pdf == 0x0 ) { printf("\n\n *** Can't find nuisance parameter pdf with name %s.\n\n", pdfname.Data() ) ; return ; } RooDataSet* nprds = np_pdf->generate( RooArgSet(*np_rrv) ,1) ; const RooArgSet* npdsras = nprds->get() ; TIterator* valIter = npdsras->createIterator() ; RooRealVar* val = (RooRealVar*) valIter->Next() ; //--- reset the value of the nuisance parameter and fix it for the toy model definition fit. np_rrv->setVal( val->getVal() ) ; np_rrv->setConstant( kTRUE ) ; TString npname( np_rrv->GetName() ) ; npname.ReplaceAll("_prim","") ; RooAbsReal* np_rfv = ws->function( npname ) ; if ( verbLevel > 0 ) { if ( np_rfv != 0x0 ) { printf(" %20s : %8.2f , %15s, %8.3f\n", val->GetName(), val->getVal(), np_rfv->GetName(), np_rfv->getVal() ) ; } else if ( strstr( npname.Data(), "eff_sf" ) != 0 ) { np_rfv = ws->function( "eff_sf_sig" ) ; RooAbsReal* np_rfv2 = ws->function( "eff_sf_sb" ) ; printf(" %20s : %8.2f , %15s, %8.3f , %15s, %8.3f\n", val->GetName(), val->getVal(), np_rfv->GetName(), np_rfv->getVal(), np_rfv2->GetName(), np_rfv2->getVal() ) ; } else if ( strstr( npname.Data(), "sf_ll" ) != 0 ) { np_rfv = ws->function( "sf_ee" ) ; RooAbsReal* np_rfv2 = ws->function( "sf_mm" ) ; printf(" %20s : %8.2f , %15s, %8.3f , %15s, %8.3f\n", val->GetName(), val->getVal(), np_rfv->GetName(), np_rfv->getVal(), np_rfv2->GetName(), np_rfv2->getVal() ) ; } else { printf(" %20s : %8.2f\n", val->GetName(), val->getVal() ) ; } } delete nprds ; } // np_rrv iterator } //--- 2) Fit the dataset with these values for the nuisance parameters. if ( isBgonlyStudy ) { //-- fit with susy yield fixed to zero. rrv_mu_susy_sig -> setVal( 0. ) ; if ( verbLevel > 0 ) { printf("\n Setting mu_susy_sig to zero.\n\n") ; } } else { //-- fit with susy yield fixed to predicted value. rrv_mu_susy_sig -> setVal( poiVal ) ; if ( verbLevel > 0 ) { printf("\n Setting mu_susy_sig to %8.1f.\n\n", poiVal) ; } } rrv_mu_susy_sig->setConstant( kTRUE ) ; if ( verbLevel > 0 ) { printf("\n\n") ; printf(" Fitting with these values for the observables to define the model for toy generation.\n") ; rds->printMultiline(cout, 1, kTRUE, "") ; printf("\n\n") ; } RooFitResult* toyModelDefinitionFitResult(0x0) ; if ( verbLevel < 2 ) { toyModelDefinitionFitResult = likelihood->fitTo(*rds, Save(true), PrintLevel(-1)); } else { toyModelDefinitionFitResult = likelihood->fitTo(*rds, Save(true)); } int toyModelDefFitCovQual = toyModelDefinitionFitResult->covQual() ; if ( verbLevel > 0 ) { printf("\n fit covariance matrix quality: %d\n\n", toyModelDefFitCovQual ) ; } if ( toyModelDefFitCovQual != 3 ) { printf("\n\n\n *** Bad toy model definition fit. Cov qual %d. Aborting this toy.\n\n\n", toyModelDefFitCovQual ) ; continue ; } delete toyModelDefinitionFitResult ; if ( verbLevel > 0 ) { printf("\n\n\n === Model values for observables. These will be used to generate the toy dataset.\n\n") ; printObservables() ; } //--- 3) Generate a new set of observables based on this model. generateObservables() ; printf("\n\n\n Generated dataset\n") ; rds->Print() ; rds->printMultiline(cout, 1, kTRUE, "") ; //--- Apparently, I need to make a new RooDataSet... Resetting the // values in the old one doesn't stick. If you do likelihood->fitTo(*rds), it // uses the original values, not the reset ones, in the fit. RooArgSet toyFitobservedParametersList ; toyFitobservedParametersList.add( *rrv_Nsig ) ; toyFitobservedParametersList.add( *rrv_Nsb ) ; toyFitobservedParametersList.add( *rrv_Nsig_sl ) ; toyFitobservedParametersList.add( *rrv_Nsb_sl ) ; toyFitobservedParametersList.add( *rrv_Nsig_ldp ) ; toyFitobservedParametersList.add( *rrv_Nsb_ldp ) ; toyFitobservedParametersList.add( *rrv_Nsig_ee ) ; toyFitobservedParametersList.add( *rrv_Nsb_ee ) ; toyFitobservedParametersList.add( *rrv_Nsig_mm ) ; toyFitobservedParametersList.add( *rrv_Nsb_mm ) ; RooDataSet* toyFitdsObserved = new RooDataSet("toyfit_ra2b_observed_rds", "RA2b toy observed data values", toyFitobservedParametersList ) ; toyFitdsObserved->add( toyFitobservedParametersList ) ; //--- 4) Reset and free the nuisance parameters. { if ( verbLevel > 0 ) { printf("\n\n") ; } int npi(0) ; TIterator* npIter = nuisanceParameters->createIterator() ; while ( RooRealVar* np_rrv = (RooRealVar*) npIter->Next() ) { np_rrv -> setVal( np_initial_val[npi] ) ; // assuming that the order in the iterator does not change. np_rrv -> setConstant( kFALSE ) ; npi++ ; if ( verbLevel > 0 ) { printf(" reset %20s to %8.2f and freed it.\n", np_rrv->GetName() , np_rrv->getVal() ) ; } } // np_rrv iterator. if ( verbLevel > 0 ) { printf("\n\n") ; } } //--- 5a) Evaluate the test statistic: Fit with susy yield floating to get the absolute maximum log likelihood. if ( verbLevel > 0 ) { printf("\n\n Evaluating the test statistic for this toy. Fitting with susy floating.\n\n") ; } rrv_mu_susy_sig->setVal( 0.0 ) ; rrv_mu_susy_sig->setConstant( kFALSE ) ; if ( verbLevel > 0 ) { printf("\n toy dataset\n\n") ; toyFitdsObserved->printMultiline(cout, 1, kTRUE, "") ; } /////---- nfg. Need to create a new dataset ---------- /////RooFitResult* maxLikelihoodFitResult = likelihood->fitTo(*rds, Save(true), PrintLevel(-1)); /////RooFitResult* maxLikelihoodFitResult = likelihood->fitTo(*rds, Save(true)); /////-------------- RooFitResult* maxLikelihoodFitResult(0x0) ; if ( verbLevel < 2 ) { maxLikelihoodFitResult = likelihood->fitTo(*toyFitdsObserved, Save(true), PrintLevel(-1)); } else { maxLikelihoodFitResult = likelihood->fitTo(*toyFitdsObserved, Save(true)); } if ( verbLevel > 0 ) { printObservables() ; } int mlFitCovQual = maxLikelihoodFitResult->covQual() ; if ( verbLevel > 0 ) { printf("\n fit covariance matrix quality: %d , -log likelihood %f\n\n", mlFitCovQual, maxLikelihoodFitResult->minNll() ) ; } if ( mlFitCovQual != 3 ) { printf("\n\n\n *** Bad maximum likelihood fit (susy floating). Cov qual %d. Aborting this toy.\n\n\n", mlFitCovQual ) ; continue ; } double maxL_susyFloat = maxLikelihoodFitResult->minNll() ; double maxL_mu_susy_sig = rrv_mu_susy_sig->getVal() ; delete maxLikelihoodFitResult ; //--- 5b) Evaluate the test statistic: Fit with susy yield fixed to hypothesis value. // This is only necessary if the maximum likelihood fit value of the susy yield // is less than the hypothesis value (to get a one-sided limit). double testStat(0.0) ; double maxL_susyFixed(0.0) ; if ( maxL_mu_susy_sig < poiVal ) { if ( verbLevel > 0 ) { printf("\n\n Evaluating the test statistic for this toy. Fitting with susy fixed to %8.2f.\n\n", poiVal ) ; } rrv_mu_susy_sig->setVal( poiVal ) ; rrv_mu_susy_sig->setConstant( kTRUE ) ; if ( verbLevel > 0 ) { printf("\n toy dataset\n\n") ; rds->printMultiline(cout, 1, kTRUE, "") ; } ////--------- nfg. need to make a new dataset --------------- ////RooFitResult* susyFixedFitResult = likelihood->fitTo(*rds, Save(true), PrintLevel(-1)); ////RooFitResult* susyFixedFitResult = likelihood->fitTo(*rds, Save(true)); ////----------------------------- RooFitResult* susyFixedFitResult(0x0) ; if ( verbLevel < 2 ) { susyFixedFitResult = likelihood->fitTo(*toyFitdsObserved, Save(true), PrintLevel(-1)); } else { susyFixedFitResult = likelihood->fitTo(*toyFitdsObserved, Save(true)); } if ( verbLevel > 0 ) { printObservables() ; } int susyFixedFitCovQual = susyFixedFitResult->covQual() ; if ( verbLevel > 0 ) { printf("\n fit covariance matrix quality: %d , -log likelihood %f\n\n", susyFixedFitCovQual, susyFixedFitResult->minNll() ) ; } if ( susyFixedFitCovQual != 3 ) { printf("\n\n\n *** Bad maximum likelihood fit (susy fixed). Cov qual %d. Aborting this toy.\n\n\n", susyFixedFitCovQual ) ; continue ; } maxL_susyFixed = susyFixedFitResult->minNll() ; testStat = 2. * (maxL_susyFixed - maxL_susyFloat) ; delete susyFixedFitResult ; } else { if ( verbLevel > 0 ) { printf("\n\n Floating value of susy yield greater than hypo value (%8.2f > %8.2f). Setting test stat to zero.\n\n", maxL_mu_susy_sig, poiVal ) ; } testStat = 0.0 ; } printf(" --- test stat for toy %4d : %8.2f\n", ti, testStat ) ; nToyOK++ ; if ( testStat > dataTestStat ) { nToyWorseThanData++ ; } if ( makeTtree ) { tt_testStat = testStat ; tt_gen_Nsig = rrv_Nsig->getVal() ; tt_gen_Nsb = rrv_Nsb->getVal() ; tt_gen_Nsig_sl = rrv_Nsig_sl->getVal() ; tt_gen_Nsb_sl = rrv_Nsb_sl->getVal() ; tt_gen_Nsig_ldp = rrv_Nsig_ldp->getVal() ; tt_gen_Nsb_ldp = rrv_Nsb_ldp->getVal() ; tt_gen_Nsig_ee = rrv_Nsig_ee->getVal() ; tt_gen_Nsb_ee = rrv_Nsb_ee->getVal() ; tt_gen_Nsig_mm = rrv_Nsig_mm->getVal() ; tt_gen_Nsb_mm = rrv_Nsb_mm->getVal() ; toytt->Fill() ; } //--- *) reset things for the next toy. resetObservables() ; delete toyFitdsObserved ; } // ti. wstf->Close() ; printf("\n\n\n") ; if ( nToyOK == 0 ) { printf("\n\n\n *** All toys bad !?!?!\n\n\n") ; return ; } double pValue = (1.0*nToyWorseThanData) / (1.0*nToyOK) ; if ( isBgonlyStudy ) { printf("\n\n\n p-value result, BG-only , poi=%3.0f : %4d / %4d = %6.3f\n\n\n\n", poiVal, nToyWorseThanData, nToyOK, pValue ) ; } else { printf("\n\n\n p-value result, S-plus-B, poi=%3.0f : %4d / %4d = %6.3f\n\n\n\n", poiVal, nToyWorseThanData, nToyOK, pValue ) ; } if ( makeTtree ) { printf("\n\n Writing TTree : %s : %s\n\n", ttname, tttitle ) ; ttfile->cd() ; toytt->Write() ; } } // ws_cls_hybrid1
void check_fit_bias_sim(const int N=1, string infname="20140409_SimFits_M1850_DblMu0_AllCent/fracLogCBG_PbPbpol3_HI020_pol2_HI2040_pol2_HI40100_pppol2_rap16-24_pT3-30_centMult_Workspace.root") { RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING); TFile *inf = new TFile(infname.c_str(),"READ"); RooWorkspace *ws = (RooWorkspace*) inf->Get("workspace"); // ws->var("doubleRatio_HI020")->setConstant(true); // ws->var("doubleRatio_HI2040")->setConstant(true); // ws->var("doubleRatio_HI40100")->setConstant(true); RooRealVar *Jpsi_Mass = ws->var("Jpsi_Mass"); RooCategory *sample = ws->cat("sample"); // TIter types(ws->cat("sample")->typeIterator()); // RooCatType * type; // types.Reset(); RooDataSet * protoData = (RooDataSet*) ws->data("redDataSim"); RooDataSet * protoData_pp = (RooDataSet*) ws->data("data4"); RooDataSet * protoData_HI020 = (RooDataSet*) ws->data("data1"); RooDataSet * protoData_HI2040 = (RooDataSet*) ws->data("data2"); RooDataSet * protoData_HI40100 = (RooDataSet*) ws->data("data3"); // RooSimultaneous *model = (RooSimultaneous*) ws->pdf("sigMassPDFSim"); RooAbsPdf *model_pp = (RooAbsPdf*) ws->pdf("sigMassPDF_pp"); RooAbsPdf *model_HI020 = (RooAbsPdf*) ws->pdf("pdf_HI020"); RooAbsPdf *model_HI2040 = (RooAbsPdf*) ws->pdf("pdf_HI2040"); RooAbsPdf *model_HI40100 = (RooAbsPdf*) ws->pdf("pdf_HI40100"); // ws->var("sigma_pol")->setVal(0.0); // ws->var("sigma_b")->setVal(0.0); // ws->var("sigma_pol")->setConstant(true); // ws->var("sigma_b")->setConstant(true); // ws->var("sigma_fit_HI020")->setVal(0.0); // ws->var("sigma_eff_HI020")->setVal(0.0); // ws->var("sigma_fit_HI020")->setConstant(true); // ws->var("sigma_eff_HI020")->setConstant(true); // ws->var("sigma_fit_HI2040")->setVal(0.0); // ws->var("sigma_eff_HI2040")->setVal(0.0); // ws->var("sigma_fit_HI2040")->setConstant(true); // ws->var("sigma_eff_HI2040")->setConstant(true); // ws->var("sigma_fit_HI40100")->setVal(0.0); // ws->var("sigma_eff_HI40100")->setVal(0.0); // ws->var("sigma_fit_HI40100")->setConstant(true); // ws->var("sigma_eff_HI40100")->setConstant(true); RooPlot *frame = Jpsi_Mass->frame(Range("M2242")); protoData->plotOn(frame, Cut("sample==sample::pp")); protoData->plotOn(frame, Cut("sample==sample::HI020"), MarkerColor(kRed)); protoData->plotOn(frame, Cut("sample==sample::HI2040"), MarkerStyle(25), MarkerColor(kBlue)); protoData->plotOn(frame, Cut("sample==sample::HI40100"), MarkerStyle(24), MarkerColor(kGreen+2)); // model->plotOn(frame, Slice(*sample,"pp"), ProjWData(*sample,*protoData)); TCanvas *c0 = new TCanvas("c0","c0"); c0->cd(); frame->Draw(); // return; // ws->pdf("sigMassPDF_M2242")->plotOn(frame,Range("M2242")); // redData->plotOn(frame,MarkerStyle(24),MarkerColor(kRed),Range("M2242")); // while ((type=(RooCatType*)types.Next())) { // protoData = // (RooDataSet*)ws->data(TString::Format("data_%s", type->GetName())); // bkg = ws.pdf(TString::Format("expFunct_%s", type->GetName())); // if ((*type) == "HI") // N = Nhi; // else // N = Npp; // RooDataSet * tmpData = bkg->generate(RooArgSet(*Jpsi_mass), N, // RooFit::ProtoData(*protoData)); // osBkgData->append(*tmpData); // delete tmpData; // } // double Nevents = ws->var("NJpsi_pp")->getVal()+ws->function("NPsiP_pp")->getVal()+ws->var("NBkg_pp")->getVal(); TH1F *h0_pp = new TH1F("h0_pp","h0_pp;R_{#psi}^{pp};Events",1200,-0.3,0.3); TH1F *h1_pp = new TH1F("h1_pp","h1_pp;R_{#psi}^{pp};Events",1200,-0.3,0.3); TH2F *h2_pp = new TH2F("h2_pp","h2_pp;R_{#psi}^{pp} (M1850);R_{#psi}^{pp} (M2242)",600,-0.3,0.3,600,-0.3,0.3); h0_pp->Sumw2(); h1_pp->Sumw2(); h2_pp->Sumw2(); h1_pp->SetMarkerColor(2); h1_pp->SetLineColor(2); h0_pp->GetXaxis()->CenterTitle(true); h1_pp->GetXaxis()->CenterTitle(true); h2_pp->GetXaxis()->CenterTitle(true); TH1F *h0_HI020 = new TH1F("h0_HI020","h0_HI020;#chi_{#psi}^{HI020};Events",5000,-1.0,4.0); TH1F *h1_HI020 = new TH1F("h1_HI020","h1_HI020;#chi_{#psi}^{HI020};Events",5000,-1.0,4.0); TH2F *h2_HI020 = new TH2F("h2_HI020","h2_HI020;#chi_{#psi}^{HI020} (M1850);#chi_{#psi}^{HI020} (M2242)",500,-1,4,500,-1,4); h0_HI020->Sumw2(); h1_HI020->Sumw2(); h2_HI020->Sumw2(); h1_HI020->SetMarkerColor(2); h1_HI020->SetLineColor(2); h0_HI020->GetXaxis()->CenterTitle(true); h1_HI020->GetXaxis()->CenterTitle(true); h2_HI020->GetXaxis()->CenterTitle(true); TH1F *h0_HI2040 = new TH1F("h0_HI2040","h0_HI2040;#chi_{#psi}^{HI2040};Events",5000,-1.0,4.0); TH1F *h1_HI2040 = new TH1F("h1_HI2040","h1_HI2040;#chi_{#psi}^{HI2040};Events",5000,-1.0,4.0); TH2F *h2_HI2040 = new TH2F("h2_HI2040","h2_HI2040;#chi_{#psi}^{HI2040} (M1850);#chi_{#psi}^{HI2040} (M2242)",500,-1,4,500,-1,4); h0_HI2040->Sumw2(); h1_HI2040->Sumw2(); h2_HI2040->Sumw2(); h1_HI2040->SetMarkerColor(2); h1_HI2040->SetLineColor(2); h0_HI2040->GetXaxis()->CenterTitle(true); h1_HI2040->GetXaxis()->CenterTitle(true); h2_HI2040->GetXaxis()->CenterTitle(true); TH1F *h0_HI40100 = new TH1F("h0_HI40100","h0_HI40100;#chi_{#psi}^{HI40100};Events",5000,-1.0,4.0); TH1F *h1_HI40100 = new TH1F("h1_HI40100","h1_HI40100;#chi_{#psi}^{HI40100};Events",5000,-1.0,4.0); TH2F *h2_HI40100 = new TH2F("h2_HI40100","h2_HI40100;#chi_{#psi}^{HI40100} (M1850);#chi_{#psi}^{HI40100} (M2242)",500,-1,4,500,-1,4); h0_HI40100->Sumw2(); h1_HI40100->Sumw2(); h2_HI40100->Sumw2(); h1_HI40100->SetMarkerColor(2); h1_HI40100->SetLineColor(2); h0_HI40100->GetXaxis()->CenterTitle(true); h1_HI40100->GetXaxis()->CenterTitle(true); h2_HI40100->GetXaxis()->CenterTitle(true); TH1F *h0_HI0100 = new TH1F("h0_HI0100","h0_HI0100;#chi_{#psi}^{HI0100};Events",5000,-1.0,4.0); TH1F *h1_HI0100 = new TH1F("h1_HI0100","h1_HI0100;#chi_{#psi}^{HI0100};Events",5000,-1.0,4.0); TH2F *h2_HI0100 = new TH2F("h2_HI0100","h2_HI0100;#chi_{#psi}^{HI0100} (M1850);#chi_{#psi}^{HI0100} (M2242)",500,-1,4,500,-1,4); h0_HI0100->Sumw2(); h1_HI0100->Sumw2(); h2_HI0100->Sumw2(); h1_HI0100->SetMarkerColor(2); h1_HI0100->SetLineColor(2); h0_HI0100->GetXaxis()->CenterTitle(true); h1_HI0100->GetXaxis()->CenterTitle(true); h2_HI0100->GetXaxis()->CenterTitle(true); Jpsi_Mass->setRange("signal",3.6,3.76); Jpsi_Mass->setRange("M2045",2.0,4.5); Jpsi_Mass->setRange("M2242",2.2,4.2); RooFitResult *fitMall; RooFitResult *fitM; // RooFit cannot normalize Chebychev polynomials to a subrange (no analytic integral?) // using normal polynomials instead RooRealVar a("a","a",0.0);a.setConstant(false); RooRealVar b("b","b",0.01);b.setConstant(false); RooRealVar c("c","c",-0.005);c.setConstant(false); // mid // RooPolynomial bkg_pp("bkg_pp","bkg_pp",*Jpsi_Mass,RooArgSet(a,b,c)); // fwd RooPolynomial bkg_pp("bkg_pp","bkg_pp",*Jpsi_Mass,RooArgSet(a));//,b,c)); RooRealVar a_HI020("a_HI020","a_HI020",0.0);a_HI020.setConstant(false); RooRealVar b_HI020("b_HI020","b_HI020",0.01);b_HI020.setConstant(false); RooRealVar c_HI020("c_HI020","c_HI020",-0.005);c_HI020.setConstant(false); // mid // RooPolynomial bkg_HI020("bkg_HI020","bkg_HI020",*Jpsi_Mass,RooArgSet(a_HI020));//,b_HI020,c_HI020)); // fwd RooPolynomial bkg_HI020("bkg_HI020","bkg_HI020",*Jpsi_Mass,RooArgSet(a_HI020,b_HI020,c_HI020)); RooRealVar a_HI2040("a_HI2040","a_HI2040",0.0);a_HI2040.setConstant(false); RooRealVar b_HI2040("b_HI2040","b_HI2040",0.01);b_HI2040.setConstant(false); RooRealVar c_HI2040("c_HI2040","c_HI2040",-0.005);c_HI2040.setConstant(false); // mid // RooPolynomial bkg_HI2040("bkg_HI2040","bkg_HI2040",*Jpsi_Mass,RooArgSet(a_HI2040));//,b_HI2040,c_HI2040)); // fwd RooPolynomial bkg_HI2040("bkg_HI2040","bkg_HI2040",*Jpsi_Mass,RooArgSet(a_HI2040,b_HI2040));//,c_HI2040)); RooRealVar a_HI40100("a_HI40100","a_HI40100",0.0);a_HI40100.setConstant(false); RooRealVar b_HI40100("b_HI40100","b_HI40100",0.01);b_HI40100.setConstant(false); RooRealVar c_HI40100("c_HI40100","c_HI40100",-0.005);c_HI40100.setConstant(false); // mid // a_HI40100.setConstant(true); // RooPolynomial bkg_HI40100("bkg_HI40100","bkg_HI40100",*Jpsi_Mass,RooArgSet(a_HI40100));//,b_HI40100,c_HI40100)); // fwd RooPolynomial bkg_HI40100("bkg_HI40100","bkg_HI40100",*Jpsi_Mass,RooArgSet(a_HI40100));//,b_HI40100,c_HI40100)); ws->import(bkg_pp); ws->import(bkg_HI020); ws->import(bkg_HI2040); ws->import(bkg_HI40100); ws->factory("SUM::sigMassPDF_pp_M2242(NJpsi_pp*sigCB1G2_HI,NPsiP_pp*sigCB1G2P_HI,NBkg_pp*bkg_pp)"); ws->factory("SUM::sigMassPDF_HI020_M2242(NJpsi_HI020*sigCB1G2_HI,NPsiP_HI020*sigCB1G2P_HI,NBkg_HI020*bkg_HI020)"); ws->factory("SUM::sigMassPDF_HI2040_M2242(NJpsi_HI2040*sigCB1G2_HI,NPsiP_HI2040*sigCB1G2P_HI,NBkg_HI2040*bkg_HI2040)"); ws->factory("SUM::sigMassPDF_HI40100_M2242(NJpsi_HI40100*sigCB1G2_HI,NPsiP_HI40100*sigCB1G2P_HI,NBkg_HI40100*bkg_HI40100)"); ws->factory("SIMUL::sigMassPDFSim_M2242(sample,HI020=sigMassPDF_HI020_M2242,HI2040=sigMassPDF_HI2040_M2242,HI40100=sigMassPDF_HI40100_M2242,pp=sigMassPDF_pp_M2242)"); RooDataSet *data[N]; RooDataSet *data_pp[N]; RooDataSet *data_HI020[N]; RooDataSet *data_HI2040[N]; RooDataSet *data_HI40100[N]; RooDataSet *redData; for (int i=0;i<N;++i) { cout << "Generating event " << i << "/" << N << endl; // cout << "Generate N = " << Nevents << " events with R_{psi} = " << ws->var("fracP_pp")->getVal() << endl; // data[i] = model->generateSimGlobal(*Jpsi_Mass,ProtoData(*protoData), Verbose(1)); data_pp[i] = model_pp->generate(*Jpsi_Mass, ProtoData(*protoData_pp),Verbose(0)); data_HI020[i] = model_HI020->generate(*Jpsi_Mass, ProtoData(*protoData_HI020),Verbose(0)); data_HI2040[i] = model_HI2040->generate(*Jpsi_Mass, ProtoData(*protoData_HI2040),Verbose(0)); data_HI40100[i] = model_HI40100->generate(*Jpsi_Mass, ProtoData(*protoData_HI40100),Verbose(0)); data[i] = new RooDataSet("data","data",RooArgSet(*Jpsi_Mass),Index(*sample),Import("HI020",*data_HI020[i]),Import("HI2040",*data_HI2040[i]),Import("HI40100",*data_HI40100[i]),Import("pp",*data_pp[i])); } RooPlot *frame2 = Jpsi_Mass->frame(); data_pp[0]->plotOn(frame2); data[N-1]->plotOn(frame2, Cut("sample==sample::pp"),MarkerColor(kRed), MarkerStyle(24)); data[N-1]->plotOn(frame2, Cut("sample==sample::HI020"), MarkerColor(kRed)); data[N-1]->plotOn(frame2, Cut("sample==sample::HI2040"), MarkerStyle(25), MarkerColor(kBlue)); data[N-1]->plotOn(frame2, Cut("sample==sample::HI40100"), MarkerStyle(24), MarkerColor(kGreen+2)); // data[N-1]->plotOn(frame2, Cut("sample!=sample::pp"), MarkerColor(kRed)); // model->plotOn(frame, Slice(*sample,"pp"), ProjWData(*sample,*protoData)); TCanvas *c0a = new TCanvas("c0a","c0a"); c0a->cd(); frame2->Draw(); // return; // cout << data->sumEntries() << endl; for (int i=0;i<N;++i) { cout << "Fitting event " << i << "/" << N << endl; fitMall = ws->pdf("sigMassPDFSim")->fitTo(*data[i],Extended(1),Hesse(1),Save(1),NumCPU(8),PrintEvalErrors(-1),Verbose(0),PrintLevel(-1)); if (fitMall->statusCodeHistory(fitMall->numStatusHistory()-1) != 0) {i--; continue;} // fitMall->Print("v"); // cout << "Fitted R_{psi} = " << ws->var("fracP_pp")->getVal() << " +/- " << ws->var("fracP_pp")->getPropagatedError(*fitMall) << endl; double R1850_pp = ws->var("fracP_pp")->getVal(); double R1850_HI020 = ws->var("doubleRatio_HI020")->getVal(); double R1850_HI2040 = ws->var("doubleRatio_HI2040")->getVal(); double R1850_HI40100 = ws->var("doubleRatio_HI40100")->getVal(); double R1850_HI0100 = ws->function("doubleRatio_HI0100")->getVal(); h0_pp->Fill(R1850_pp); h0_HI020->Fill(R1850_HI020); h0_HI2040->Fill(R1850_HI2040); h0_HI40100->Fill(R1850_HI40100); h0_HI0100->Fill(R1850_HI0100); redData = (RooDataSet*)data[i]->reduce("Jpsi_Mass>2.2&&Jpsi_Mass<4.2"); // cout << redData->sumEntries() << endl; fitM = ws->pdf("sigMassPDFSim_M2242")->fitTo(*redData,Extended(1),Hesse(1),Save(1),NumCPU(8),PrintEvalErrors(-1),Verbose(0),PrintLevel(-1),Range("M2242")); if (fitM->statusCodeHistory(fitM->numStatusHistory()-1) != 0) {i--; continue;} // fitM->Print("v"); // cout << "Fit over M2242: R_{psi} = " << ws->var("fracP_pp")->getVal() << " +/- " << ws->var("fracP_pp")->getPropagatedError(*fitM) << endl; // RooPlot *frame = Jpsi_Mass->frame(Range("M2242")); // redData->plotOn(frame); // ws->pdf("sigMassPDF_M2242")->plotOn(frame,Range("M2242")); // redData->plotOn(frame,MarkerStyle(24),MarkerColor(kRed),Range("M2242")); double R2242_pp = ws->var("fracP_pp")->getVal(); double R2242_HI020 = ws->var("doubleRatio_HI020")->getVal(); double R2242_HI2040 = ws->var("doubleRatio_HI2040")->getVal(); double R2242_HI40100 = ws->var("doubleRatio_HI40100")->getVal(); double R2242_HI0100 = ws->function("doubleRatio_HI0100")->getVal(); h1_pp->Fill(R2242_pp); h1_HI020->Fill(R2242_HI020); h1_HI2040->Fill(R2242_HI2040); h1_HI40100->Fill(R2242_HI40100); h1_HI0100->Fill(R2242_HI0100); h2_pp->Fill(R1850_pp,R2242_pp); h2_HI020->Fill(R1850_HI020,R2242_HI020); h2_HI2040->Fill(R1850_HI2040,R2242_HI2040); h2_HI40100->Fill(R1850_HI40100,R2242_HI40100); h2_HI0100->Fill(R1850_HI0100,R2242_HI0100); } TCanvas *c1 = new TCanvas("c1","c1"); c1->Divide(2,2); c1->cd(1); h0_pp->Draw(); h1_pp->Draw("same"); c1->cd(2); h0_HI020->Draw(); h1_HI020->Draw("same"); c1->cd(3); h0_HI2040->Draw(); h1_HI2040->Draw("same"); c1->cd(4); h0_HI40100->Draw(); h1_HI40100->Draw("same"); // frame->Draw(); cout << "pp" << endl; cout << h0_pp->GetMean() << "\t" << h0_pp->GetRMS() << endl; cout << h1_pp->GetMean() << "\t" << h1_pp->GetRMS() << endl; cout << 1-(h0_pp->GetMean()/h1_pp->GetMean()) << endl; cout << "HI020" << endl; cout << h0_HI020->GetMean() << "\t" << h0_HI020->GetRMS() << endl; cout << h1_HI020->GetMean() << "\t" << h1_HI020->GetRMS() << endl; cout << 1-(h0_HI020->GetMean()/h1_HI020->GetMean()) << endl; cout << "HI2040" << endl; cout << h0_HI2040->GetMean() << "\t" << h0_HI2040->GetRMS() << endl; cout << h1_HI2040->GetMean() << "\t" << h1_HI2040->GetRMS() << endl; cout << 1-(h0_HI2040->GetMean()/h1_HI2040->GetMean()) << endl; cout << "HI40100" << endl; cout << h0_HI40100->GetMean() << "\t" << h0_HI40100->GetRMS() << endl; cout << h1_HI40100->GetMean() << "\t" << h1_HI40100->GetRMS() << endl; cout << 1-(h0_HI40100->GetMean()/h1_HI40100->GetMean()) << endl; cout << "HI0100" << endl; cout << h0_HI0100->GetMean() << "\t" << h0_HI0100->GetRMS() << endl; cout << h1_HI0100->GetMean() << "\t" << h1_HI0100->GetRMS() << endl; cout << 1-(h0_HI0100->GetMean()/h1_HI0100->GetMean()) << endl; c1->SaveAs(Form("toy_fits_dblRatio_fwd_M1850_N%i.pdf",N)); TF1 *f3 = new TF1("f3","x",-0.5,3.0); f3->SetLineWidth(1); TCanvas *c2 = new TCanvas("c2","c2"); c2->Divide(2,2); c2->cd(1); h2_pp->Draw("colz"); f3->Draw("same"); c2->cd(2); h2_HI020->Draw("colz"); f3->Draw("same"); c2->cd(3); h2_HI2040->Draw("colz"); f3->Draw("same"); c2->cd(4); h2_HI40100->Draw("colz"); f3->Draw("same"); TCanvas *c3 = new TCanvas("c3","c3"); c3->Divide(2,1); c3->cd(1); h0_HI0100->Draw(); h1_HI0100->Draw("same"); c3->cd(2); h2_HI0100->Draw("colz"); f3->Draw("same"); TFile *outf = new TFile(Form("toy_fits_dblRatio_fwd_M1850_N%i.root",N),"RECREATE"); h0_pp->Write(); h1_pp->Write(); h2_pp->Write(); h0_HI020->Write(); h1_HI020->Write(); h2_HI020->Write(); h0_HI2040->Write(); h1_HI2040->Write(); h2_HI2040->Write(); h0_HI40100->Write(); h1_HI40100->Write(); h2_HI40100->Write(); h0_HI0100->Write(); h1_HI0100->Write(); h2_HI0100->Write(); outf->Close(); return; }
void fitqual_plots( const char* wsfile = "outputfiles/ws.root", const char* plottitle="" ) { TText* tt_title = new TText() ; tt_title -> SetTextAlign(33) ; gStyle -> SetOptStat(0) ; gStyle -> SetLabelSize( 0.06, "y" ) ; gStyle -> SetLabelSize( 0.08, "x" ) ; gStyle -> SetLabelOffset( 0.010, "y" ) ; gStyle -> SetLabelOffset( 0.010, "x" ) ; gStyle -> SetTitleSize( 0.07, "y" ) ; gStyle -> SetTitleSize( 0.05, "x" ) ; gStyle -> SetTitleOffset( 1.50, "x" ) ; gStyle -> SetTitleH( 0.07 ) ; gStyle -> SetPadLeftMargin( 0.15 ) ; gStyle -> SetPadBottomMargin( 0.15 ) ; gStyle -> SetTitleX( 0.10 ) ; gDirectory->Delete("h*") ; TFile* wstf = new TFile( wsfile ) ; RooWorkspace* ws = dynamic_cast<RooWorkspace*>( wstf->Get("ws") ); ws->Print() ; int bins_of_met = TMath::Nint( ws->var("bins_of_met")->getVal() ) ; printf("\n\n Bins of MET : %d\n\n", bins_of_met ) ; int bins_of_nb = TMath::Nint( ws->var("bins_of_nb")->getVal() ) ; printf("\n\n Bins of nb : %d\n\n", bins_of_nb ) ; int nb_lookup[10] ; if ( bins_of_nb == 2 ) { nb_lookup[0] = 2 ; nb_lookup[1] = 4 ; } else if ( bins_of_nb == 3 ) { nb_lookup[0] = 2 ; nb_lookup[1] = 3 ; nb_lookup[2] = 4 ; } TCanvas* cfq1 = (TCanvas*) gDirectory->FindObject("cfq1") ; if ( cfq1 == 0x0 ) { if ( bins_of_nb == 3 ) { cfq1 = new TCanvas("cfq1","hbb fit", 700, 1000 ) ; } else if ( bins_of_nb == 2 ) { cfq1 = new TCanvas("cfq1","hbb fit", 700, 750 ) ; } else { return ; } } RooRealVar* rv_sig_strength = ws->var("sig_strength") ; if ( rv_sig_strength == 0x0 ) { printf("\n\n *** can't find sig_strength in workspace.\n\n" ) ; return ; } ModelConfig* modelConfig = (ModelConfig*) ws->obj( "SbModel" ) ; RooDataSet* rds = (RooDataSet*) ws->obj( "hbb_observed_rds" ) ; rds->Print() ; rds->printMultiline(cout, 1, kTRUE, "") ; RooAbsPdf* likelihood = modelConfig->GetPdf() ; ///RooFitResult* fitResult = likelihood->fitTo( *rds, Save(true), PrintLevel(0) ) ; RooFitResult* fitResult = likelihood->fitTo( *rds, Save(true), PrintLevel(3) ) ; fitResult->Print() ; char hname[1000] ; char htitle[1000] ; char pname[1000] ; //-- unpack observables. int obs_N_msig[10][50] ; // first index is n btags, second is met bin. int obs_N_msb[10][50] ; // first index is n btags, second is met bin. const RooArgSet* dsras = rds->get() ; TIterator* obsIter = dsras->createIterator() ; while ( RooRealVar* obs = (RooRealVar*) obsIter->Next() ) { for ( int nbi=0; nbi<bins_of_nb; nbi++ ) { for ( int mbi=0; mbi<bins_of_met; mbi++ ) { sprintf( pname, "N_%db_msig_met%d", nb_lookup[nbi], mbi+1 ) ; if ( strcmp( obs->GetName(), pname ) == 0 ) { obs_N_msig[nbi][mbi] = TMath::Nint( obs -> getVal() ) ; } sprintf( pname, "N_%db_msb_met%d", nb_lookup[nbi], mbi+1 ) ; if ( strcmp( obs->GetName(), pname ) == 0 ) { obs_N_msb[nbi][mbi] = TMath::Nint( obs -> getVal() ) ; } } // mbi. } // nbi. } // obs iterator. printf("\n\n") ; for ( int nbi=0; nbi<bins_of_nb; nbi++ ) { printf(" nb=%d : ", nb_lookup[nbi] ) ; for ( int mbi=0; mbi<bins_of_met; mbi++ ) { printf(" sig=%3d, sb=%3d |", obs_N_msig[nbi][mbi], obs_N_msb[nbi][mbi] ) ; } // mbi. printf("\n") ; } // nbi. printf("\n\n") ; int pad(1) ; cfq1->Clear() ; cfq1->Divide( 2, bins_of_nb+1 ) ; for ( int nbi=0; nbi<bins_of_nb; nbi++ ) { sprintf( hname, "h_bg_%db_msig_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sig, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_bg_msig = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; hist_bg_msig -> SetFillColor( kBlue-9 ) ; labelBins( hist_bg_msig ) ; sprintf( hname, "h_bg_%db_msb_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sb, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_bg_msb = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; hist_bg_msb -> SetFillColor( kBlue-9 ) ; labelBins( hist_bg_msb ) ; sprintf( hname, "h_sig_%db_msig_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sig, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_sig_msig = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; hist_sig_msig -> SetFillColor( kMagenta+2 ) ; labelBins( hist_sig_msig ) ; sprintf( hname, "h_sig_%db_msb_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sb, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_sig_msb = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; hist_sig_msb -> SetFillColor( kMagenta+2 ) ; labelBins( hist_sig_msb ) ; sprintf( hname, "h_all_%db_msig_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sig, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_all_msig = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; sprintf( hname, "h_all_%db_msb_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sb, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_all_msb = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; sprintf( hname, "h_data_%db_msig_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sig, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_data_msig = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; hist_data_msig -> SetLineWidth(2) ; hist_data_msig -> SetMarkerStyle(20) ; labelBins( hist_data_msig ) ; sprintf( hname, "h_data_%db_msb_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sb, %db, MET", nb_lookup[nbi] ) ; TH1F* hist_data_msb = new TH1F( hname, htitle, bins_of_met, 0.5, bins_of_met+0.5 ) ; hist_data_msb -> SetLineWidth(2) ; hist_data_msb -> SetMarkerStyle(20) ; labelBins( hist_data_msb ) ; for ( int mbi=0; mbi<bins_of_met; mbi++ ) { sprintf( pname, "mu_bg_%db_msig_met%d", nb_lookup[nbi], mbi+1 ) ; RooAbsReal* mu_bg_msig = ws->function( pname ) ; if ( mu_bg_msig == 0x0 ) { printf("\n\n *** ws missing %s\n\n", pname ) ; return ; } hist_bg_msig -> SetBinContent( mbi+1, mu_bg_msig->getVal() ) ; sprintf( pname, "mu_sig_%db_msig_met%d", nb_lookup[nbi], mbi+1 ) ; RooAbsReal* mu_sig_msig = ws->function( pname ) ; if ( mu_sig_msig == 0x0 ) { printf("\n\n *** ws missing %s\n\n", pname ) ; return ; } hist_sig_msig -> SetBinContent( mbi+1, mu_sig_msig->getVal() ) ; hist_all_msig -> SetBinContent( mbi+1, mu_bg_msig->getVal() + mu_sig_msig->getVal() ) ; hist_data_msig -> SetBinContent( mbi+1, obs_N_msig[nbi][mbi] ) ; sprintf( pname, "mu_bg_%db_msb_met%d", nb_lookup[nbi], mbi+1 ) ; RooAbsReal* mu_bg_msb = ws->function( pname ) ; if ( mu_bg_msb == 0x0 ) { printf("\n\n *** ws missing %s\n\n", pname ) ; return ; } hist_bg_msb -> SetBinContent( mbi+1, mu_bg_msb->getVal() ) ; sprintf( pname, "mu_sig_%db_msb_met%d", nb_lookup[nbi], mbi+1 ) ; RooAbsReal* mu_sig_msb = ws->function( pname ) ; if ( mu_sig_msb == 0x0 ) { printf("\n\n *** ws missing %s\n\n", pname ) ; return ; } hist_sig_msb -> SetBinContent( mbi+1, mu_sig_msb->getVal() ) ; hist_all_msb -> SetBinContent( mbi+1, mu_bg_msb->getVal() + mu_sig_msb->getVal() ) ; hist_data_msb -> SetBinContent( mbi+1, obs_N_msb[nbi][mbi] ) ; } // mbi. cfq1->cd( pad ) ; sprintf( hname, "h_stack_%db_msig_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sig, %db, MET", nb_lookup[nbi] ) ; THStack* hstack_msig = new THStack( hname, htitle ) ; hstack_msig -> Add( hist_bg_msig ) ; hstack_msig -> Add( hist_sig_msig ) ; hist_data_msig -> Draw("e") ; hstack_msig -> Draw("same") ; hist_data_msig -> Draw("same e") ; hist_data_msig -> Draw("same axis") ; tt_title -> DrawTextNDC( 0.85, 0.85, plottitle ) ; pad++ ; cfq1->cd( pad ) ; sprintf( hname, "h_stack_%db_msb_met", nb_lookup[nbi] ) ; sprintf( htitle, "mass sig, %db, MET", nb_lookup[nbi] ) ; THStack* hstack_msb = new THStack( hname, htitle ) ; hstack_msb -> Add( hist_bg_msb ) ; hstack_msb -> Add( hist_sig_msb ) ; hist_data_msb -> Draw("e") ; hstack_msb -> Draw("same") ; hist_data_msb -> Draw("same e") ; hist_data_msb -> Draw("same axis") ; tt_title -> DrawTextNDC( 0.85, 0.85, plottitle ) ; pad++ ; } // nbi. TH1F* hist_R_msigmsb = new TH1F( "h_R_msigmsb", "R msig/msb vs met bin", bins_of_met, 0.5, 0.5+bins_of_met ) ; hist_R_msigmsb -> SetLineWidth(2) ; hist_R_msigmsb -> SetMarkerStyle(20) ; hist_R_msigmsb -> SetYTitle("R msig/msb") ; labelBins( hist_R_msigmsb ) ; for ( int mbi=0; mbi<bins_of_met; mbi++ ) { sprintf( pname, "R_msigmsb_met%d", mbi+1 ) ; RooRealVar* rrv_R = ws->var( pname ) ; if ( rrv_R == 0x0 ) { printf("\n\n *** Can't find %s in ws.\n\n", pname ) ; return ; } hist_R_msigmsb -> SetBinContent( mbi+1, rrv_R -> getVal() ) ; hist_R_msigmsb -> SetBinError( mbi+1, rrv_R -> getError() ) ; } // mbi. cfq1->cd( pad ) ; gPad->SetGridy(1) ; hist_R_msigmsb -> SetMaximum(0.35) ; hist_R_msigmsb -> Draw("e") ; tt_title -> DrawTextNDC( 0.85, 0.85, plottitle ) ; pad++ ; cfq1->cd( pad ) ; scan_sigstrength( wsfile ) ; tt_title -> DrawTextNDC( 0.85, 0.25, plottitle ) ; TString pdffile( wsfile ) ; pdffile.ReplaceAll("ws-","fitqual-") ; pdffile.ReplaceAll("root","pdf") ; cfq1->SaveAs( pdffile ) ; TString histfile( wsfile ) ; histfile.ReplaceAll("ws-","fitqual-") ; saveHist( histfile, "h*" ) ; } // fitqual_plots
void buildModel(int sel_i, TFile *fin, TDirectory *fout){ // Define outputs RooWorkspace *wout = new RooWorkspace(); wout->SetName(Form("normalization_cat%d",sel_i)); fout->cd(); // Input to this is TTrees // Setup the "x" variable and weights RooRealVar mvamet("metRaw","metRaw",200,1200); //RooRealVar mvamet("jet1mprune","jet1mprune",0,200); //RooRealVar mvamet("jet1tau2o1","jet1tau2o1",0,1); wout->import(mvamet); // TH1F Base Style std::string lName = "basehist"; //const int numberofBins = 18; //double myBins[numberofBins+1] = {200,210,220,230,240,250,260,270,280,290,300,310,320,330,350,380,430,500,1200}; //TH1F *lMet = new TH1F(lName.c_str(),lName.c_str(),numberofBins,myBins); TH1F *lMet = new TH1F(lName.c_str(),lName.c_str(),20,200,1200); //TH1F *lMet = new TH1F(lName.c_str(),lName.c_str(),20,0,1); // Make Datasets makeAndImportDataSets(fin,wout,mvamet); // ========================================================================================================== const int nProcs = 27; std::string procnames[nProcs]; procnames[0] = "DY"; procnames[1] = "RDY"; procnames[2] = "W"; procnames[3] = "WHT"; procnames[4] = "TT"; procnames[5] = "T"; procnames[6] = "ZZ"; procnames[7] = "WW"; procnames[8] = "WZ"; procnames[9] = "WH0"; procnames[10] = "ZH0"; procnames[11] = "GGH0"; procnames[12] = "VBFH0"; //procnames[12] = "DY_control_bkg_mc"; procnames[13] = "Zvv_control_mc"; procnames[14] = "T_control_bkg_mc"; procnames[15] = "TT_control_bkg_mc"; procnames[16] = "WW_control_bkg_mc"; procnames[17] = "WZ_control_bkg_mc"; procnames[18] = "ZZ_control_bkg_mc"; procnames[19] = "Wlv_control_mc_1"; procnames[20] = "Wlv_control_mc_2"; procnames[21] = "T_sl_control_bkg_mc"; procnames[22] = "TT_sl_control_bkg_mc"; procnames[23] = "WW_sl_control_bkg_mc"; procnames[24] = "WZ_sl_control_bkg_mc"; procnames[25] = "ZZ_sl_control_bkg_mc"; procnames[26] = "DY_sl_control_bkg_mc"; // Fill TF1s which do not need corrections for (int p0=0;p0<nProcs;p0++){ std::cout << "Filling hist for " << procnames[p0] << std::endl;; TH1F *hist_ = (TH1F*)generateTemplate(lMet, (TTree*)fin->Get(procnames[p0].c_str()), mvamet.GetName(), "weight",cutstring); // standard processes are TTrees hist_->Write(); } std::cout << "Filling hist for " << "data_obs" << std::endl;; TH1F *hist_ = (TH1F*)generateTemplate(lMet, (TTree*)fin->Get("data_obs"), mvamet.GetName(), "",cutstring); // standard processes are TTrees hist_->Write(); std::cout << "Filling hist for " << "Zvv_control" << std::endl;; hist_ = (TH1F*)generateTemplate(lMet, (TTree*)fin->Get("Zvv_control"), mvamet.GetName(), "",cutstring); // standard processes are TTrees hist_->Write(); std::cout << "Filling hist for " << "Wlv_control" << std::endl;; hist_ = (TH1F*)generateTemplate(lMet, (TTree*)fin->Get("Wlv_control"), mvamet.GetName(), "",cutstring); // standard processes are TTrees hist_->Write(); // ========================================================================================================== // Fit backgrounds to produce fit model #ifdef RUN_CORRECTION buildAndFitModels(fout,wout,mvamet,"Zvv"); buildAndFitModels(fout,wout,mvamet,"Wlv"); double mcyield = wout->data("DY")->sumEntries(); double datayield = wout->var("num_Zvv")->getVal(); // post fit number of data Z->mumu in control std::cout << "sfactor" << brscaleFactorZvv*datayield/mcyield << std::endl; TH1F *hist_zvv = (TH1F*)generateTemplate(lMet, (RooFormulaVar*)wout->function("ratio_Zvv") , *(wout->var(mvamet.GetName())), (RooDataSet*) wout->data("DY") //TH1F *hist_zvv = (TH1F*)generateTemplate(lMet, (RooFormulaVar*)wout->function("") , *(wout->var(mvamet.GetName())), (RooDataSet*) wout->data("DY") , 1 /*run correction*/ , 1 /*brscaleFactorZvv*datayield/mcyield*/ /*additional weight*/); hist_zvv->Write(); std::cout << " DataCardInfo ---------------- " << std::endl; std::cout << Form(" Zvv_norm gmN %d %g ",(int)datayield,hist_zvv->Integral()/datayield) << std::endl; std::cout << " ----------------------------- " << std::endl; // Also correct normalization data why not? hist_zvv = (TH1F*)generateTemplate(lMet, (RooFormulaVar*)wout->function("ratio_Zvv") , *(wout->var(mvamet.GetName())), (RooDataSet*) wout->data("Zvv_control_mc") , 1 /*run correction*/ , 1. /*additional weight*/); hist_zvv->Write(); // Single muon mcyield = wout->data("W")->sumEntries(); datayield = wout->var("num_Wlv")->getVal(); // post fit number of data W->munu in control std::cout << "sfactor" << brscaleFactorWlv*datayield/mcyield << std::endl; TH1F *hist_wlv = (TH1F*)generateTemplate(lMet, (RooFormulaVar*)wout->function("ratio_Wlv") , *(wout->var(mvamet.GetName())), (RooDataSet*) wout->data("W") , 1 /*run correction*/ , 1./*brscaleFactorWlv*datayield/mcyield*/ /*additional weight*/); hist_wlv->Write(); std::cout << " DataCardInfo ---------------- " << std::endl; std::cout << Form(" Wlv_norm gmN %d %g ",(int)datayield,hist_wlv->Integral()/datayield) << std::endl; std::cout << " ----------------------------- " << std::endl; // Also correct normalization data why not? hist_wlv = (TH1F*)generateTemplate(lMet, (RooFormulaVar*)wout->function("ratio_Wlv") , *(wout->var(mvamet.GetName())), (RooDataSet*) wout->data("Wlv_control_mc") , 1 /*run correction*/ , 1. /*additional weight*/); hist_wlv->Write(); //buildAndFitModels(fout,wout,mvamet,"Wlv"); //TH1F *hist_wlv = (TH1F*)generateTemplate(lMet, (RooFormulaVar*)wout->function("ratio_Wlv"), &mvamet, (RooDataSet*) wout->data("")); //hist_wlv->Write(); #endif // Since the W came in 2 parts, we can make the histogram based on the dataset (called uncorrected) TH1F *hist_wlv_uc = (TH1F*)generateTemplate(lMet, (RooFormulaVar*)wout->function("") , *(wout->var(mvamet.GetName())), (RooDataSet*) wout->data("W") , 1 /*run correction forwards*/ , 1./*brscaleFactorWlv*datayield/mcyield*/ /*additional weight*/); hist_wlv_uc->Write(); #ifdef RUN_BKGSYS // Load and run systematics from fit model std::vector<TH1F> v_th1f_Z; generateVariations(lMet,(RooFitResult*)fout->Get("fitResult_Zvv_control"),(RooFormulaVar*)wout->function("ratio_Zvv"),wout->var(mvamet.GetName()),v_th1f_Z,wout,"DY"); std::vector<TH1F> v_th1f_W; generateVariations(lMet,(RooFitResult*)fout->Get("fitResult_Wlv_control"),(RooFormulaVar*)wout->function("ratio_Wlv"),wout->var(mvamet.GetName()),v_th1f_W,wout,"W"); // Nice plots hist_zvv = (TH1F*)fout->Get("th1f_corrected_DY"); hist_wlv = (TH1F*)fout->Get("th1f_corrected_W"); double norm = hist_zvv->Integral(); int colit=2, styleit=1; TCanvas *can_zvv_systs = new TCanvas("can_zvv_systs","can_zvv_systs",800,600); TLegend *leg = new TLegend(0.6,0.4,0.89,0.89); leg->SetFillColor(0); leg->SetTextFont(42); hist_zvv->SetLineColor(1);hist_zvv->SetLineWidth(3); hist_zvv->Draw(); for (std::vector<TH1F>::iterator hit=v_th1f_Z.begin();hit!=v_th1f_Z.end();hit++){ hit->SetLineColor(colit); hit->SetLineWidth(3); hit->SetLineStyle(styleit%2+1); leg->AddEntry(&(*hit),hit->GetName(),"L"); hit->Scale(norm/hit->Integral()); hit->Draw("same"); hit->Write(); styleit++; if (styleit%2==1) colit++; } leg->Draw(); can_zvv_systs->Write(); norm = hist_wlv->Integral(); styleit=1; colit=2; TCanvas *can_wlv_systs = new TCanvas("can_wlv_systs","can_wlv_systs",800,600); TLegend *leg_2 = new TLegend(0.6,0.4,0.89,0.89); leg_2->SetFillColor(0); leg_2->SetTextFont(42); hist_wlv->SetLineColor(1);hist_wlv->SetLineWidth(3); hist_wlv->Draw(); for (std::vector<TH1F>::iterator hit=v_th1f_W.begin();hit!=v_th1f_W.end();hit++){ hit->SetLineColor(colit); hit->SetLineWidth(3); hit->SetLineStyle(styleit%2+1); leg_2->AddEntry(&(*hit),hit->GetName(),"L"); hit->Scale(norm/hit->Integral()); hit->Draw("same"); hit->Write(); styleit++; if (styleit%2==1) colit++; } leg_2->Draw(); can_wlv_systs->Write(); #endif // Save the work fout->cd(); wout->Write(); // Done! }
void eregtestingExample(bool dobarrel=true, bool doele=true) { //output dir TString dirname = "/data/bendavid/eregexampletest/eregexampletest_test/"; gSystem->mkdir(dirname,true); gSystem->cd(dirname); //read workspace from training TString fname; if (doele && dobarrel) fname = "wereg_ele_eb.root"; else if (doele && !dobarrel) fname = "wereg_ele_ee.root"; else if (!doele && dobarrel) fname = "wereg_ph_eb.root"; else if (!doele && !dobarrel) fname = "wereg_ph_ee.root"; TString infile = TString::Format("/data/bendavid/eregexampletest/%s",fname.Data()); TFile *fws = TFile::Open(infile); RooWorkspace *ws = (RooWorkspace*)fws->Get("wereg"); //read variables from workspace RooGBRTargetFlex *meantgt = static_cast<RooGBRTargetFlex*>(ws->arg("sigmeant")); RooRealVar *tgtvar = ws->var("tgtvar"); RooArgList vars; vars.add(meantgt->FuncVars()); vars.add(*tgtvar); //read testing dataset from TTree RooRealVar weightvar("weightvar","",1.); TTree *dtree; if (doele) { //TFile *fdin = TFile::Open("root://eoscms.cern.ch//eos/cms/store/cmst3/user/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TFile *fdin = TFile::Open("/data/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterSingleInvert"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } else { TFile *fdin = TFile::Open("root://eoscms.cern.ch///eos/cms/store/cmst3/user/bendavid/idTreesAug1/hgg-2013Final8TeV_ID_s12-h124gg-gf-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } //selection cuts for testing TCut selcut; if (dobarrel) selcut = "ph.genpt>25. && ph.isbarrel && ph.ispromptgen"; else selcut = "ph.genpt>25. && !ph.isbarrel && ph.ispromptgen"; TCut selweight = "xsecweight(procidx)*puweight(numPU,procidx)"; TCut prescale10 = "(evt%10==0)"; TCut prescale10alt = "(evt%10==1)"; TCut prescale25 = "(evt%25==0)"; TCut prescale100 = "(evt%100==0)"; TCut prescale1000 = "(evt%1000==0)"; TCut evenevents = "(evt%2==0)"; TCut oddevents = "(evt%2==1)"; TCut prescale100alt = "(evt%100==1)"; TCut prescale1000alt = "(evt%1000==1)"; TCut prescale50alt = "(evt%50==1)"; if (doele) weightvar.SetTitle(prescale100alt*selcut); else weightvar.SetTitle(selcut); //make testing dataset RooDataSet *hdata = RooTreeConvert::CreateDataSet("hdata",dtree,vars,weightvar); if (doele) weightvar.SetTitle(prescale1000alt*selcut); else weightvar.SetTitle(prescale10alt*selcut); //make reduced testing dataset for integration over conditional variables RooDataSet *hdatasmall = RooTreeConvert::CreateDataSet("hdatasmall",dtree,vars,weightvar); //retrieve full pdf from workspace RooAbsPdf *sigpdf = ws->pdf("sigpdf"); //input variable corresponding to sceta RooRealVar *scetavar = ws->var("var_1"); //regressed output functions RooAbsReal *sigmeanlim = ws->function("sigmeanlim"); RooAbsReal *sigwidthlim = ws->function("sigwidthlim"); RooAbsReal *signlim = ws->function("signlim"); RooAbsReal *sign2lim = ws->function("sign2lim"); //formula for corrected energy/true energy ( 1.0/(etrue/eraw) * regression mean) RooFormulaVar ecor("ecor","","1./(@0)*@1",RooArgList(*tgtvar,*sigmeanlim)); RooRealVar *ecorvar = (RooRealVar*)hdata->addColumn(ecor); ecorvar->setRange(0.,2.); ecorvar->setBins(800); //formula for raw energy/true energy (1.0/(etrue/eraw)) RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); RooRealVar *rawvar = (RooRealVar*)hdata->addColumn(raw); rawvar->setRange(0.,2.); rawvar->setBins(800); //clone data and add regression outputs for plotting RooDataSet *hdataclone = new RooDataSet(*hdata,"hdataclone"); RooRealVar *meanvar = (RooRealVar*)hdataclone->addColumn(*sigmeanlim); RooRealVar *widthvar = (RooRealVar*)hdataclone->addColumn(*sigwidthlim); RooRealVar *nvar = (RooRealVar*)hdataclone->addColumn(*signlim); RooRealVar *n2var = (RooRealVar*)hdataclone->addColumn(*sign2lim); //plot target variable and weighted regression prediction (using numerical integration over reduced testing dataset) TCanvas *craw = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot = tgtvar->frame(0.6,2.0,100); hdata->plotOn(plot); sigpdf->plotOn(plot,ProjWData(*hdatasmall)); plot->Draw(); craw->SaveAs("RawE.eps"); craw->SetLogy(); plot->SetMinimum(0.1); craw->SaveAs("RawElog.eps"); //plot distribution of regressed functions over testing dataset TCanvas *cmean = new TCanvas; RooPlot *plotmean = meanvar->frame(0.8,2.0,100); hdataclone->plotOn(plotmean); plotmean->Draw(); cmean->SaveAs("mean.eps"); TCanvas *cwidth = new TCanvas; RooPlot *plotwidth = widthvar->frame(0.,0.05,100); hdataclone->plotOn(plotwidth); plotwidth->Draw(); cwidth->SaveAs("width.eps"); TCanvas *cn = new TCanvas; RooPlot *plotn = nvar->frame(0.,111.,200); hdataclone->plotOn(plotn); plotn->Draw(); cn->SaveAs("n.eps"); TCanvas *cn2 = new TCanvas; RooPlot *plotn2 = n2var->frame(0.,111.,100); hdataclone->plotOn(plotn2); plotn2->Draw(); cn2->SaveAs("n2.eps"); TCanvas *ceta = new TCanvas; RooPlot *ploteta = scetavar->frame(-2.6,2.6,200); hdataclone->plotOn(ploteta); ploteta->Draw(); ceta->SaveAs("eta.eps"); //create histograms for eraw/etrue and ecor/etrue to quantify regression performance TH1 *heraw = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.)); TH1 *hecor = hdata->createHistogram("hecor",*ecorvar); //heold->SetLineColor(kRed); hecor->SetLineColor(kBlue); heraw->SetLineColor(kMagenta); hecor->GetXaxis()->SetRangeUser(0.6,1.2); //heold->GetXaxis()->SetRangeUser(0.6,1.2); TCanvas *cresponse = new TCanvas; hecor->Draw("HIST"); //heold->Draw("HISTSAME"); heraw->Draw("HISTSAME"); cresponse->SaveAs("response.eps"); cresponse->SetLogy(); cresponse->SaveAs("responselog.eps"); printf("make fine histogram\n"); TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(20e3,0.,2.)); printf("calc effsigma\n"); double effsigma = effSigma(hecorfine); printf("effsigma = %5f\n",effsigma); /* new TCanvas; RooPlot *ploteold = testvar.frame(0.6,1.2,100); hdatasigtest->plotOn(ploteold); ploteold->Draw(); new TCanvas; RooPlot *plotecor = ecorvar->frame(0.6,1.2,100); hdatasig->plotOn(plotecor); plotecor->Draw(); */ }
void Raa3S_Workspace(const char* filename="fitresult_combo_nofixed.root"){ TFile File(filename); RooWorkspace * ws; File.GetObject("wcombo", ws); // ws->Print(); RooAbsData * data = ws->data("data"); // RooDataSet * US_data = (RooDataSet*) data->reduce( "QQsign == QQsign::PlusMinus"); // US_data->SetName("US_data"); // ws->import(* US_data); // RooDataSet * hi_data = (RooDataSet*) US_data->reduce("dataCat == dataCat::hi"); // hi_data->SetName("hi_data"); // ws->import(* hi_data); // hi_data->Print(); RooRealVar* raa3 = new RooRealVar("raa3","R_{AA}(#Upsilon (3S))",0.5,0,1); RooRealVar* leftEdge = new RooRealVar("leftEdge","leftEdge",0); RooRealVar* rightEdge = new RooRealVar("rightEdge","rightEdge",1); RooGenericPdf step("step", "step", "(@0 >= @1) && (@0 < @2)", RooArgList(*raa3, *leftEdge, *rightEdge)); ws->import(step); ws->factory( "Uniform::flat(raa3)" ); //pp Luminosities, Taa and efficiency ratios Systematics ws->factory( "Taa_hi[5.662e-9]" ); ws->factory( "Taa_kappa[1.057]" ); ws->factory( "expr::alpha_Taa('pow(Taa_kappa,beta_Taa)',Taa_kappa,beta_Taa[0,-5,5])" ); ws->factory( "prod::Taa_nom(Taa_hi,alpha_Taa)" ); ws->factory( "Gaussian::constr_Taa(beta_Taa,glob_Taa[0,-5,5],1)" ); ws->factory( "lumipp_hi[5.4]" ); ws->factory( "lumipp_kappa[1.06]" ); ws->factory( "expr::alpha_lumipp('pow(lumipp_kappa,beta_lumipp)',lumipp_kappa,beta_lumipp[0,-5,5])" ); ws->factory( "prod::lumipp_nom(lumipp_hi,alpha_lumipp)" ); ws->factory( "Gaussian::constr_lumipp(beta_lumipp,glob_lumipp[0,-5,5],1)" ); // ws->factory( "effRat1[1]" ); // ws->factory( "effRat2[1]" ); ws->factory( "effRat3_hi[0.95]" ); ws->factory( "effRat_kappa[1.054]" ); ws->factory( "expr::alpha_effRat('pow(effRat_kappa,beta_effRat)',effRat_kappa,beta_effRat[0,-5,5])" ); // ws->factory( "prod::effRat1_nom(effRat1_hi,alpha_effRat)" ); ws->factory( "Gaussian::constr_effRat(beta_effRat,glob_effRat[0,-5,5],1)" ); // ws->factory( "prod::effRat2_nom(effRat2_hi,alpha_effRat)" ); ws->factory( "prod::effRat3_nom(effRat3_hi,alpha_effRat)" ); // ws->factory("Nmb_hi[1.161e9]"); ws->factory("prod::denominator(Taa_nom,Nmb_hi)"); ws->factory( "expr::lumiOverTaaNmbmodified('lumipp_nom/denominator',lumipp_nom,denominator)"); RooFormulaVar *lumiOverTaaNmbmodified = ws->function("lumiOverTaaNmbmodified"); // // RooRealVar *raa1 = ws->var("raa1"); // RooRealVar* nsig1_pp = ws->var("nsig1_pp"); // RooRealVar* effRat1 = ws->function("effRat1_nom"); // RooRealVar *raa2 = ws->var("raa2"); // RooRealVar* nsig2_pp = ws->var("nsig2_pp"); // RooRealVar* effRat2 = ws->function("effRat2_nom"); RooRealVar* nsig3_pp = ws->var("N_{#Upsilon(3S)}_pp"); cout << nsig3_pp << endl; RooRealVar* effRat3 = ws->function("effRat3_nom"); // // RooFormulaVar nsig1_hi_modified("nsig1_hi_modified", "@0*@1*@3/@2", RooArgList(*raa1, *nsig1_pp, *lumiOverTaaNmbmodified, *effRat1)); // ws->import(nsig1_hi_modified); // RooFormulaVar nsig2_hi_modified("nsig2_hi_modified", "@0*@1*@3/@2", RooArgList(*raa2, *nsig2_pp, *lumiOverTaaNmbmodified, *effRat2)); // ws->import(nsig2_hi_modified); RooFormulaVar nsig3_hi_modified("nsig3_hi_modified", "@0*@1*@3/@2", RooArgList(*raa3, *nsig3_pp, *lumiOverTaaNmbmodified, *effRat3)); ws->import(nsig3_hi_modified); // // background yield with systematics ws->factory( "nbkg_hi_kappa[1.10]" ); ws->factory( "expr::alpha_nbkg_hi('pow(nbkg_hi_kappa,beta_nbkg_hi)',nbkg_hi_kappa,beta_nbkg_hi[0,-5,5])" ); ws->factory( "SUM::nbkg_hi_nom(alpha_nbkg_hi*bkgPdf_hi)" ); ws->factory( "Gaussian::constr_nbkg_hi(beta_nbkg_hi,glob_nbkg_hi[0,-5,5],1)" ); RooAbsPdf* sig1S_hi = ws->pdf("cbcb_hi"); RooAbsPdf* sig2S_hi = ws->pdf("sig2S_hi"); RooAbsPdf* sig3S_hi = ws->pdf("sig3S_hi"); RooAbsPdf* LSBackground_hi = ws->pdf("nbkg_hi_nom"); RooRealVar* nsig1_hi = ws->var("N_{#Upsilon(1S)}_hi"); RooRealVar* nsig2_hi = ws->var("N_{#Upsilon(2S)}_hi"); cout << nsig1_hi << " " << nsig2_hi << " " << nsig3_pp << endl; RooFormulaVar* nsig3_hi = ws->function("nsig3_hi_modified"); RooRealVar* norm_nbkg_hi = ws->var("n_{Bkgd}_hi"); RooArgList pdfs_hi( *sig1S_hi,*sig2S_hi,*sig3S_hi, *LSBackground_hi); RooArgList norms_hi(*nsig1_hi,*nsig2_hi,*nsig3_hi, *norm_nbkg_hi); //////////////////////////////////////////////////////////////////////////////// ws->factory( "nbkg_pp_kappa[1.03]" ); ws->factory( "expr::alpha_nbkg_pp('pow(nbkg_pp_kappa,beta_nbkg_pp)',nbkg_pp_kappa,beta_nbkg_pp[0,-5,5])" ); ws->factory( "SUM::nbkg_pp_nom(alpha_nbkg_pp*bkgPdf_pp)" ); ws->factory( "Gaussian::constr_nbkg_pp(beta_nbkg_pp,glob_nbkg_pp[0,-5,5],1)" ); RooAbsPdf* sig1S_pp = ws->pdf("cbcb_pp"); RooAbsPdf* sig2S_pp = ws->pdf("sig2S_pp"); RooAbsPdf* sig3S_pp = ws->pdf("sig3S_pp"); RooAbsPdf* LSBackground_pp = ws->pdf("nbkg_pp_nom"); RooRealVar* nsig1_pp = ws->var("N_{#Upsilon(1S)}_pp"); RooRealVar* nsig2_pp = ws->var("N_{#Upsilon(2S)}_pp"); RooRealVar* nsig3_pp = ws->var("N_{#Upsilon(3S)}_pp"); RooRealVar* norm_nbkg_pp = ws->var("n_{Bkgd}_pp"); RooArgList pdfs_pp( *sig1S_pp,*sig2S_pp,*sig3S_pp, *LSBackground_pp); RooArgList norms_pp( *nsig1_pp,*nsig2_pp,*nsig3_pp,*norm_nbkg_pp); RooAddPdf model_num("model_num", "model_num", pdfs_hi,norms_hi); ws->import(model_num); ws->factory("PROD::model_hi(model_num, constr_nbkg_hi,constr_lumipp,constr_Taa,constr_effRat)"); RooAddPdf model_den("model_den", "model_den", pdfs_pp,norms_pp); ws->import(model_den); ws->factory("PROD::model_pp(model_den, constr_nbkg_pp)"); ws->factory("SIMUL::joint(dataCat,hi=model_hi,pp=model_pp)"); ///////////////////////////////////////////////////////////////////// RooRealVar * pObs = ws->var("invariantMass"); // get the pointer to the observable RooArgSet obs("observables"); obs.add(*pObs); obs.add( *ws->cat("dataCat")); // ///////////////////////////////////////////////////////////////////// ws->var("glob_lumipp")->setConstant(true); ws->var("glob_Taa")->setConstant(true); ws->var("glob_effRat")->setConstant(true); ws->var("glob_nbkg_pp")->setConstant(true); ws->var("glob_nbkg_hi")->setConstant(true); RooArgSet globalObs("global_obs"); globalObs.add( *ws->var("glob_lumipp") ); globalObs.add( *ws->var("glob_Taa") ); globalObs.add( *ws->var("glob_effRat") ); globalObs.add( *ws->var("glob_nbkg_hi") ); globalObs.add( *ws->var("glob_nbkg_pp") ); // ws->Print(); RooArgSet poi("poi"); poi.add( *ws->var("raa3") ); // create set of nuisance parameters RooArgSet nuis("nuis"); nuis.add( *ws->var("beta_lumipp") ); nuis.add( *ws->var("beta_nbkg_hi") ); nuis.add( *ws->var("beta_nbkg_pp") ); nuis.add( *ws->var("beta_Taa") ); nuis.add( *ws->var("beta_effRat") ); ws->var("#alpha_{CB}_hi")->setConstant(true); ws->var("#alpha_{CB}_pp")->setConstant(true); ws->var("#sigma_{CB1}_hi")->setConstant(true); ws->var("#sigma_{CB1}_pp")->setConstant(true); ws->var("#sigma_{CB2}/#sigma_{CB1}_hi")->setConstant(true); ws->var("#sigma_{CB2}/#sigma_{CB1}_pp")->setConstant(true); ws->var("Centrality")->setConstant(true); ws->var("N_{#Upsilon(1S)}_hi")->setConstant(true); ws->var("N_{#Upsilon(1S)}_pp")->setConstant(true); ws->var("N_{#Upsilon(2S)}_hi")->setConstant(true); ws->var("N_{#Upsilon(2S)}_pp")->setConstant(true); ws->var("N_{#Upsilon(3S)}_pp")->setConstant(true); ws->var("Nmb_hi")->setConstant(true); // ws->var("QQsign")->setConstant(true); ws->var("Taa_hi")->setConstant(true); ws->var("Taa_kappa")->setConstant(true); // ws->var("beta_Taa")->setConstant(true); // ws->var("beta_effRat")->setConstant(true); // ws->var("beta_lumipp")->setConstant(true); // ws->var("beta_nbkg_hi")->setConstant(true); // ws->var("beta_nbkg_pp")->setConstant(true); // ws->var("dataCat")->setConstant(true); ws->var("decay_hi")->setConstant(true); ws->var("decay_pp")->setConstant(true); ws->var("effRat3_hi")->setConstant(true); ws->var("effRat_kappa")->setConstant(true); // ws->var("glob_Taa")->setConstant(true); // ws->var("glob_effRat")->setConstant(true); // ws->var("glob_lumipp")->setConstant(true); // ws->var("glob_nbkg_hi")->setConstant(true); // ws->var("glob_nbkg_pp")->setConstant(true); // ws->var("invariantMass")->setConstant(true); ws->var("leftEdge")->setConstant(true); ws->var("lumipp_hi")->setConstant(true); ws->var("lumipp_kappa")->setConstant(true); ws->var("mass1S_hi")->setConstant(true); ws->var("mass1S_pp")->setConstant(true); ws->var("muMinusPt")->setConstant(true); ws->var("muPlusPt")->setConstant(true); ws->var("n_{Bkgd}_hi")->setConstant(true); ws->var("n_{Bkgd}_pp")->setConstant(true); ws->var("nbkg_hi_kappa")->setConstant(true); ws->var("nbkg_pp_kappa")->setConstant(true); ws->var("npow")->setConstant(true); ws->var("N_{#Upsilon(3S)}_pp")->setConstant(true); // ws->var("raa3")->setConstant(true); ws->var("rightEdge")->setConstant(true); ws->var("sigmaFraction_hi")->setConstant(true); ws->var("sigmaFraction_pp")->setConstant(true); ws->var("turnOn_hi")->setConstant(true); ws->var("turnOn_pp")->setConstant(true); ws->var("upsPt")->setConstant(true); ws->var("upsRapidity")->setConstant(true); ws->var("vProb")->setConstant(true); ws->var("width_hi")->setConstant(true); ws->var("width_pp")->setConstant(true); ws->var("x3raw")->setConstant(true); // RooArgSet fixed_again("fixed_again"); // fixed_again.add( *ws->var("leftEdge") ); // fixed_again.add( *ws->var("rightEdge") ); // fixed_again.add( *ws->var("Taa_hi") ); // fixed_again.add( *ws->var("Nmb_hi") ); // fixed_again.add( *ws->var("lumipp_hi") ); // fixed_again.add( *ws->var("effRat1_hi") ); // fixed_again.add( *ws->var("effRat2_hi") ); // fixed_again.add( *ws->var("effRat3_hi") ); // fixed_again.add( *ws->var("nsig3_pp") ); // fixed_again.add( *ws->var("nsig1_pp") ); // fixed_again.add( *ws->var("nbkg_hi") ); // fixed_again.add( *ws->var("alpha") ); // fixed_again.add( *ws->var("nbkg_kappa") ); // fixed_again.add( *ws->var("Taa_kappa") ); // fixed_again.add( *ws->var("lumipp_kappa") ); // fixed_again.add( *ws->var("mean_hi") ); // fixed_again.add( *ws->var("mean_pp") ); // fixed_again.add( *ws->var("width_hi") ); // fixed_again.add( *ws->var("turnOn_hi") ); // fixed_again.add( *ws->var("bkg_a1_pp") ); // fixed_again.add( *ws->var("bkg_a2_pp") ); // fixed_again.add( *ws->var("decay_hi") ); // fixed_again.add( *ws->var("raa1") ); // fixed_again.add( *ws->var("raa2") ); // fixed_again.add( *ws->var("nsig2_pp") ); // fixed_again.add( *ws->var("sigma1") ); // fixed_again.add( *ws->var("nbkg_pp") ); // fixed_again.add( *ws->var("npow") ); // fixed_again.add( *ws->var("muPlusPt") ); // fixed_again.add( *ws->var("muMinusPt") ); // fixed_again.add( *ws->var("mscale_hi") ); // fixed_again.add( *ws->var("mscale_pp") ); // // ws->Print(); // create signal+background Model Config RooStats::ModelConfig sbHypo("SbHypo"); sbHypo.SetWorkspace( *ws ); sbHypo.SetPdf( *ws->pdf("joint") ); sbHypo.SetObservables( obs ); sbHypo.SetGlobalObservables( globalObs ); sbHypo.SetParametersOfInterest( poi ); sbHypo.SetNuisanceParameters( nuis ); sbHypo.SetPriorPdf( *ws->pdf("step") ); // this is optional // ws->Print(); ///////////////////////////////////////////////////////////////////// RooAbsReal * pNll = sbHypo.GetPdf()->createNLL( *data,NumCPU(2) ); RooMinuit(*pNll).migrad(); // minimize likelihood wrt all parameters before making plots RooPlot *framepoi = ((RooRealVar *)poi.first())->frame(Bins(10),Range(0.,0.2),Title("LL and profileLL in raa3")); pNll->plotOn(framepoi,ShiftToZero()); RooAbsReal * pProfile = pNll->createProfile( globalObs ); // do not profile global observables pProfile->getVal(); // this will do fit and set POI and nuisance parameters to fitted values pProfile->plotOn(framepoi,LineColor(kRed)); framepoi->SetMinimum(0); framepoi->SetMaximum(3); TCanvas *cpoi = new TCanvas(); cpoi->cd(); framepoi->Draw(); cpoi->SaveAs("cpoi.pdf"); RooArgSet * pPoiAndNuisance = new RooArgSet("poiAndNuisance"); // pPoiAndNuisance->add(*sbHypo.GetNuisanceParameters()); // pPoiAndNuisance->add(*sbHypo.GetParametersOfInterest()); pPoiAndNuisance->add( nuis ); pPoiAndNuisance->add( poi ); sbHypo.SetSnapshot(*pPoiAndNuisance); RooPlot* xframeSB = pObs->frame(Title("SBhypo")); data->plotOn(xframeSB,Cut("dataCat==dataCat::hi")); RooAbsPdf *pdfSB = sbHypo.GetPdf(); RooCategory *dataCat = ws->cat("dataCat"); pdfSB->plotOn(xframeSB,Slice(*dataCat,"hi"),ProjWData(*dataCat,*data)); TCanvas *c1 = new TCanvas(); c1->cd(); xframeSB->Draw(); c1->SaveAs("c1.pdf"); delete pProfile; delete pNll; delete pPoiAndNuisance; ws->import( sbHypo ); ///////////////////////////////////////////////////////////////////// RooStats::ModelConfig bHypo = sbHypo; bHypo.SetName("BHypo"); bHypo.SetWorkspace(*ws); pNll = bHypo.GetPdf()->createNLL( *data,NumCPU(2) ); RooArgSet poiAndGlobalObs("poiAndGlobalObs"); poiAndGlobalObs.add( poi ); poiAndGlobalObs.add( globalObs ); pProfile = pNll->createProfile( poiAndGlobalObs ); // do not profile POI and global observables double oldval = ((RooRealVar *)poi.first())->getVal( ); ((RooRealVar *)poi.first())->setVal( 0 ); // set raa3=0 here pProfile->getVal(); // this will do fit and set nuisance parameters to profiled values pPoiAndNuisance = new RooArgSet( "poiAndNuisance" ); pPoiAndNuisance->add( nuis ); pPoiAndNuisance->add( poi ); bHypo.SetSnapshot(*pPoiAndNuisance); RooPlot* xframeB = pObs->frame(Title("Bhypo")); data->plotOn(xframeB,Cut("dataCat==dataCat::hi")); RooAbsPdf *pdfB = bHypo.GetPdf(); pdfB->plotOn(xframeB,Slice(*dataCat,"hi"),ProjWData(*dataCat,*data)); TCanvas *c2 = new TCanvas(); c2->cd(); xframeB->Draw(); c2->SaveAs("c2.pdf"); delete pProfile; delete pNll; delete pPoiAndNuisance; // import model config into workspace bHypo.SetWorkspace(*ws); ws->import( bHypo ); ///////////////////////////////////////////////////////////////////// ws->Print(); bHypo.Print(); sbHypo.Print(); ((RooRealVar *)poi.first())->setVal( oldval ); // set raa3=oldval here // save workspace to file ws -> SaveAs("TRIAL.root"); return; }
//------------------------------------------------------------- //Main macro for generating data and fitting //============================================================= void FitMassTwoD(const string workspaceFile = "/afs/cern.ch/work/d/daan/public/releases/CMSSW_5_3_9_patch3/src/CMSAna/HHToBBGG/data/FitWorkspace_asdf.root", const string outputTree = "/afs/cern.ch/work/d/daan/public/releases/CMSSW_5_3_9_patch3/src/CMSAna/HHToBBGG/data/MassFitResults/MassFitTwoD_asdf.root", Int_t plotOption = 0, Int_t storeOption = 1, Int_t constBkg = 1, Int_t NToys = 5000) { TRandom3 *randomnumber = new TRandom3(1200); TFile *wsFile = new TFile (workspaceFile.c_str(), "READ"); RooWorkspace *ws = (RooWorkspace*)wsFile->Get("MassFitWorkspace"); //Import variables from workspace RooAbsPdf *model2Dpdf = ws->pdf("model2Dpdf"); RooRealVar *massBjet = ws->var("massBjet"); RooRealVar *massPho = ws->var("massPho"); RooRealVar *HHHCoupling = ws->var("HHHCoupling"); RooRealVar constHHHCoupling(*HHHCoupling); RooRealVar *nres = ws->var("N (ResBkg)"); RooRealVar constNres(*nres); RooRealVar *nnonres = ws->var("N (NonResBkg)"); RooRealVar constNnonres(*nnonres); RooRealVar *expRateBjet = ws->var("expRateBjet"); RooRealVar constexpBjet(*expRateBjet); RooRealVar *expRatePho = ws->var("expRatePho"); RooRealVar constexpPho(*expRatePho); RooFormulaVar *nsig = (RooFormulaVar*)ws->function("nsig"); if (constBkg == 0) { expRateBjet->setConstant(false); expRatePho->setConstant(false); } else { expRateBjet->setConstant(true); expRatePho->setConstant(true); } //Variables to set constant RooRealVar *sigMeanBjet = ws->var("sigMeanBjet"); sigMeanBjet->setConstant(); RooRealVar *sigSigmaBjet = ws->var("sigSigmaBjet"); sigSigmaBjet->setConstant(); RooRealVar *sigAlpha = ws->var("sigAlpha"); sigAlpha->setConstant(); RooRealVar *sigPower = ws->var("sigPower"); sigPower->setConstant(); RooRealVar *resMeanBjet = ws->var("resMeanBjet"); resMeanBjet->setConstant(); RooRealVar *resSigmaBjet = ws->var("resSigmaBjet"); resSigmaBjet->setConstant(); RooRealVar *resAlpha = ws->var("resAlpha"); resAlpha->setConstant(); RooRealVar *resPower = ws->var("resPower"); resPower->setConstant(); RooRealVar *resExpo = ws->var("resExpo"); resExpo->setConstant(); RooRealVar *nbbH = ws->var("nbbH"); nbbH->setConstant(); RooRealVar *nOthers = ws->var("nOthers"); nOthers->setConstant(); //Create TTree to store the resulting yield data TFile *f = new TFile(outputTree.c_str(), "RECREATE"); TTree *resultTree = new TTree("resultTree", "Parameter results from fitting"); Float_t nsigOut, nresOut, nnonresOut; Float_t nsigStd, nresStd, nnonresStd; Float_t HHHCouplingOut, HHHCouplingStd; resultTree->Branch("nsigOut",&nsigOut, "nsigOut/F"); resultTree->Branch("nresOut",&nresOut, "nresOut/F"); resultTree->Branch("nnonresOut",&nnonresOut, "nnonresOut/F"); resultTree->Branch("nsigStd",&nsigStd, "nsigStd/F"); resultTree->Branch("nresStd",&nresStd, "nresStd/F"); resultTree->Branch("nnonresStd",&nnonresStd, "nnonresStd/F"); resultTree->Branch("HHHCouplingOut",&HHHCouplingOut, "HHHCouplingOut/F"); resultTree->Branch("HHHCouplingStd",&HHHCouplingStd, "HHHCouplingStd/F"); //Generate Toy MC experiment data and fits for(UInt_t t=0; t < NToys; ++t) { cout << "Toy #" << t << endl; HHHCoupling->setVal(constHHHCoupling.getVal()); nres->setVal(constNres.getVal()); nnonres->setVal(constNnonres.getVal()); expRateBjet->setVal(constexpBjet.getVal()); expRatePho->setVal(constexpPho.getVal()); Float_t ran = randomnumber->Poisson(325.); RooDataSet *pseudoData2D = model2Dpdf->generate(RooArgList(*massBjet,*massPho), ran); RooFitResult *fitResult2D = model2Dpdf->fitTo(*pseudoData2D, RooFit::Save(), RooFit::Extended(kTRUE), RooFit::Strategy(2)); // if (t == 1763) { // ws->import(*pseudoData2D, kTRUE); // ws->import(*pseudoData2D, Rename("pseudoData2D")); // } // if (plotOption == 1) MakePlots(ws, fitResult2D); // cout << "DEBUG: " << constexpBjet.getVal() << " , " << constexpPho.getVal() << " | " << expRateBjet->getVal() << " " << expRatePho->getVal() << "\n"; cout << "DEBUG: " << HHHCoupling->getVal() << " " << HHHCoupling->getPropagatedError(*fitResult2D) << "\n"; //Store fit parameters into ROOT file if (storeOption == 1) { //Save variables into separate branches of root tree nsigOut = nsig->getVal(); nresOut = nres->getVal(); nnonresOut = nnonres->getVal(); nsigStd = nsig->getPropagatedError(*fitResult2D); nresStd = nres->getPropagatedError(*fitResult2D); nnonresStd = nnonres->getPropagatedError(*fitResult2D); HHHCouplingOut = HHHCoupling->getVal(); HHHCouplingStd = HHHCoupling->getPropagatedError(*fitResult2D); //cout << "\n\n\n\n\n\n" << nsigOut << " | " << nresOut << " | " << nnonresOut << " | " << ran << "\n\n\n\n\n" << endl; resultTree->Fill(); } } //Write to the TTree and close it resultTree->Write(); f->Close(); }
void mvaPUPPETEvaluation() { //output dir TString dirname = "."; gSystem->mkdir(dirname,true); gSystem->cd(dirname); //read workspace from training TString fname; fname = "mvaPUPPET.root"; TString infile = fname.Data(); TFile *fws = TFile::Open(infile); RooWorkspace *ws = (RooWorkspace*)fws->Get("wereg"); //read variables from workspace RooGBRTargetFlex *perpwidth = static_cast<RooGBRTargetFlex*>(ws->arg("perpwidth")); RooGBRTargetFlex *perpmean = static_cast<RooGBRTargetFlex*>(ws->arg("perpmean")); RooGBRTargetFlex *parpwidth = static_cast<RooGBRTargetFlex*>(ws->arg("parwidth")); RooGBRTargetFlex *parmean = static_cast<RooGBRTargetFlex*>(ws->arg("parmean")); RooRealVar *tgtvarX = ws->var("tgtX"); RooRealVar *tgtvarY = ws->var("tgtY"); RooArgList vars; vars.add(perpwidth->FuncVars()); vars.add(perpmean->FuncVars()); vars.add(perpwidth->FuncVars()); vars.add(parmean->FuncVars()); vars.add(*tgtvarX); vars.add(*tgtvarY); //read testing dataset from TTree RooRealVar weightvar("weightvar","",1.); TChain *dtree = new TChain("tree"); dtree->Add("root://eoscms.cern.ch//store//group/dpg_ecal/alca_ecalcalib/ecalMIBI/rgerosa/PUPPETAnalysis/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_Asympt50ns_MCRUN2_74_V9A_forMVATraining/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/crab_20150724_111858/150724_091912/0000/output_mc_1.root/PUPPET/t"); //TFile *fdin = TFile::Open("/data/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); // TDirectory *ddir = (TDirectory*)fdin->FindObjectAny(""); // dtree = (TTree*)ddir->Get("t"); //selection cuts for testing TCut selcut; selcut = "Boson_daughter==13"; TCut selweight = "1"; TCut prescale100alt = "(evt%100==1)"; weightvar.SetTitle(selcut); //make testing dataset RooDataSet *hdata = RooTreeConvert::CreateDataSet("hdata",dtree,vars,weightvar); weightvar.SetTitle(selcut); //make reduced testing dataset for integration over conditional variables RooDataSet *hdatasmall = RooTreeConvert::CreateDataSet("hdatasmall",dtree,vars,weightvar); //retrieve full pdf from workspace RooAbsPdf *sigpdfX = ws->pdf("sigpdfX"); RooAbsPdf *sigpdfY = ws->pdf("sigpdfY"); //input variable corresponding to sceta RooRealVar *scetavar = ws->var("var_1"); //regressed output functions RooAbsReal *perpwidthlim = ws->function("perpwidthlim"); RooAbsReal *perpmeanlim = ws->function("perpmeanlim"); RooAbsReal *parwidthlim = ws->function("parwidthlim"); RooAbsReal *parmeanlim = ws->function("parmeanlim"); ////////////////////////////////////////////////////////////////////////////////////// // // formula for corrected recoil? // /* //formula for corrected energy/true energy ( 1.0/(etrue/eraw) * regression mean) RooFormulaVar ecor("ecor","","1./(@0)*@1",RooArgList(*tgtvar,*sigmeanlim)); RooRealVar *ecorvar = (RooRealVar*)hdata->addColumn(ecor); ecorvar->setRange(0.,2.); ecorvar->setBins(800); //formula for raw energy/true energy (1.0/(etrue/eraw)) RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); RooRealVar *rawvar = (RooRealVar*)hdata->addColumn(raw); rawvar->setRange(0.,2.); rawvar->setBins(800); */ ////////////////////////////////////////////////////////////////////////////////////// //clone data and add regression outputs for plotting RooDataSet *hdataclone = new RooDataSet(*hdata,"hdataclone"); RooRealVar *perpwidthvar = (RooRealVar*)hdataclone->addColumn(*perpwidthlim); RooRealVar *perpmeanvar = (RooRealVar*)hdataclone->addColumn(*perpmeanlim); RooRealVar *parwidthvar = (RooRealVar*)hdataclone->addColumn(*parwidthlim); RooRealVar *parmeanvar = (RooRealVar*)hdataclone->addColumn(*parmeanlim); //plot target variable and weighted regression prediction (using numerical integration over reduced testing dataset) TCanvas *crawX = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot = tgtvarX->frame(-2.0,2.0,100); hdata->plotOn(plot); sigpdfX->plotOn(plot,ProjWData(*hdatasmall)); plot->Draw(); crawX->SaveAs("RawX.png"); //plot target variable and weighted regression prediction (using numerical integration over reduced testing dataset) TCanvas *crawY = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot2 = tgtvarY->frame(-2.0,2.0,100); hdata->plotOn(plot2); sigpdfY->plotOn(plot2,ProjWData(*hdatasmall)); plot2->Draw(); crawY->SaveAs("RawY.png"); ////////////////////////////////////////////////////////////////////////////////////// /* //plot distribution of regressed functions over testing dataset TCanvas *cmean = new TCanvas; RooPlot *plotmean = meanvar->frame(0.8,2.0,100); hdataclone->plotOn(plotmean); plotmean->Draw(); cmean->SaveAs("mean.eps"); TCanvas *cwidth = new TCanvas; RooPlot *plotwidth = widthvar->frame(0.,0.05,100); hdataclone->plotOn(plotwidth); plotwidth->Draw(); cwidth->SaveAs("width.eps"); TCanvas *cn = new TCanvas; RooPlot *plotn = nvar->frame(0.,111.,200); hdataclone->plotOn(plotn); plotn->Draw(); cn->SaveAs("n.eps"); TCanvas *cn2 = new TCanvas; RooPlot *plotn2 = n2var->frame(0.,111.,100); hdataclone->plotOn(plotn2); plotn2->Draw(); cn2->SaveAs("n2.eps"); TCanvas *ceta = new TCanvas; RooPlot *ploteta = scetavar->frame(-2.6,2.6,200); hdataclone->plotOn(ploteta); ploteta->Draw(); ceta->SaveAs("eta.eps"); //create histograms for eraw/etrue and ecor/etrue to quantify regression performance TH1 *heraw = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.)); TH1 *hecor = hdata->createHistogram("hecor",*ecorvar); //heold->SetLineColor(kRed); hecor->SetLineColor(kBlue); heraw->SetLineColor(kMagenta); hecor->GetXaxis()->SetRangeUser(0.6,1.2); //heold->GetXaxis()->SetRangeUser(0.6,1.2); TCanvas *cresponse = new TCanvas; hecor->Draw("HIST"); //heold->Draw("HISTSAME"); heraw->Draw("HISTSAME"); cresponse->SaveAs("response.eps"); cresponse->SetLogy(); cresponse->SaveAs("responselog.eps"); printf("make fine histogram\n"); TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(20e3,0.,2.)); printf("calc effsigma\n"); double effsigma = effSigma(hecorfine); printf("effsigma = %5f\n",effsigma); */ }
void ws_constrained_profile3D( const char* wsfile = "rootfiles/ws-data-unblind.root", const char* new_poi_name = "n_M234_H4_3b", int npoiPoints = 20, double poiMinVal = 0., double poiMaxVal = 20., double constraintWidth = 1.5, double ymax = 10., int verbLevel=0 ) { gStyle->SetOptStat(0) ; //--- make output directory. char command[10000] ; sprintf( command, "basename %s", wsfile ) ; TString wsfilenopath = gSystem->GetFromPipe( command ) ; wsfilenopath.ReplaceAll(".root","") ; char outputdirstr[1000] ; sprintf( outputdirstr, "outputfiles/scans-%s", wsfilenopath.Data() ) ; TString outputdir( outputdirstr ) ; printf("\n\n Creating output directory: %s\n\n", outputdir.Data() ) ; sprintf(command, "mkdir -p %s", outputdir.Data() ) ; gSystem->Exec( command ) ; //--- Tell RooFit to shut up about anything less important than an ERROR. RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR) ; if ( verbLevel > 0 ) { printf("\n\n Verbose level : %d\n\n", verbLevel) ; } TFile* wstf = new TFile( wsfile ) ; RooWorkspace* ws = dynamic_cast<RooWorkspace*>( wstf->Get("ws") ); if ( verbLevel > 0 ) { ws->Print() ; } RooDataSet* rds = (RooDataSet*) ws->obj( "ra2b_observed_rds" ) ; if ( verbLevel > 0 ) { printf("\n\n\n ===== RooDataSet ====================\n\n") ; rds->Print() ; rds->printMultiline(cout, 1, kTRUE, "") ; } ModelConfig* modelConfig = (ModelConfig*) ws->obj( "SbModel" ) ; RooAbsPdf* likelihood = modelConfig->GetPdf() ; RooRealVar* rrv_mu_susy_all0lep = ws->var("mu_susy_all0lep") ; if ( rrv_mu_susy_all0lep == 0x0 ) { printf("\n\n\n *** can't find mu_susy_all0lep in workspace. Quitting.\n\n\n") ; return ; } //-- do BG only. rrv_mu_susy_all0lep->setVal(0.) ; rrv_mu_susy_all0lep->setConstant( kTRUE ) ; //-- do a prefit. printf("\n\n\n ====== Pre fit with unmodified nll var.\n\n") ; RooFitResult* dataFitResultSusyFixed = likelihood->fitTo(*rds, Save(true),Hesse(false),Minos(false),Strategy(1),PrintLevel(verbLevel)); int dataSusyFixedFitCovQual = dataFitResultSusyFixed->covQual() ; if ( dataSusyFixedFitCovQual < 2 ) { printf("\n\n\n *** Failed fit! Cov qual %d. Quitting.\n\n", dataSusyFixedFitCovQual ) ; return ; } double dataFitSusyFixedNll = dataFitResultSusyFixed->minNll() ; if ( verbLevel > 0 ) { dataFitResultSusyFixed->Print("v") ; } printf("\n\n Nll value, from fit result : %.3f\n\n", dataFitSusyFixedNll ) ; delete dataFitResultSusyFixed ; //-- Construct the new POI parameter. RooAbsReal* new_poi_rar(0x0) ; new_poi_rar = ws->var( new_poi_name ) ; if ( new_poi_rar == 0x0 ) { printf("\n\n New POI %s is not a variable. Trying function.\n\n", new_poi_name ) ; new_poi_rar = ws->function( new_poi_name ) ; if ( new_poi_rar == 0x0 ) { printf("\n\n New POI %s is not a function. I quit.\n\n", new_poi_name ) ; return ; } } else { printf("\n\n New POI %s is a variable with current value %.1f.\n\n", new_poi_name, new_poi_rar->getVal() ) ; } if ( npoiPoints <=0 ) { printf("\n\n Quitting now.\n\n" ) ; return ; } double startPoiVal = new_poi_rar->getVal() ; //--- The RooNLLVar is NOT equivalent to what minuit uses. // RooNLLVar* nll = new RooNLLVar("nll","nll", *likelihood, *rds ) ; // printf("\n\n Nll value, from construction : %.3f\n\n", nll->getVal() ) ; //--- output of createNLL IS what minuit uses, so use that. RooAbsReal* nll = likelihood -> createNLL( *rds, Verbose(true) ) ; RooRealVar* rrv_poiValue = new RooRealVar( "poiValue", "poiValue", 0., -10000., 10000. ) ; /// rrv_poiValue->setVal( poiMinVal ) ; /// rrv_poiValue->setConstant(kTRUE) ; RooRealVar* rrv_constraintWidth = new RooRealVar("constraintWidth","constraintWidth", 0.1, 0.1, 1000. ) ; rrv_constraintWidth -> setVal( constraintWidth ) ; rrv_constraintWidth -> setConstant(kTRUE) ; if ( verbLevel > 0 ) { printf("\n\n ======= debug likelihood print\n\n") ; likelihood->Print("v") ; printf("\n\n ======= debug nll print\n\n") ; nll->Print("v") ; } //---------------------------------------------------------------------------------------------- RooMinuit* rminuit( 0x0 ) ; RooMinuit* rminuit_uc = new RooMinuit( *nll ) ; rminuit_uc->setPrintLevel(verbLevel-1) ; rminuit_uc->setNoWarn() ; rminuit_uc->migrad() ; rminuit_uc->hesse() ; RooFitResult* rfr_uc = rminuit_uc->fit("mr") ; double floatParInitVal[10000] ; char floatParName[10000][100] ; int nFloatParInitVal(0) ; RooArgList ral_floats = rfr_uc->floatParsFinal() ; TIterator* floatParIter = ral_floats.createIterator() ; { RooRealVar* par ; while ( (par = (RooRealVar*) floatParIter->Next()) ) { sprintf( floatParName[nFloatParInitVal], "%s", par->GetName() ) ; floatParInitVal[nFloatParInitVal] = par->getVal() ; nFloatParInitVal++ ; } } //------- printf("\n\n Unbiased best value for new POI %s is : %7.1f\n\n", new_poi_rar->GetName(), new_poi_rar->getVal() ) ; double best_poi_val = new_poi_rar->getVal() ; char minuit_formula[10000] ; sprintf( minuit_formula, "%s+%s*(%s-%s)*(%s-%s)", nll->GetName(), rrv_constraintWidth->GetName(), new_poi_rar->GetName(), rrv_poiValue->GetName(), new_poi_rar->GetName(), rrv_poiValue->GetName() ) ; printf("\n\n Creating new minuit variable with formula: %s\n\n", minuit_formula ) ; RooFormulaVar* new_minuit_var = new RooFormulaVar("new_minuit_var", minuit_formula, RooArgList( *nll, *rrv_constraintWidth, *new_poi_rar, *rrv_poiValue, *new_poi_rar, *rrv_poiValue ) ) ; printf("\n\n Current value is %.2f\n\n", new_minuit_var->getVal() ) ; rminuit = new RooMinuit( *new_minuit_var ) ; RooAbsReal* plot_var = nll ; printf("\n\n Current value is %.2f\n\n", plot_var->getVal() ) ; rminuit->setPrintLevel(verbLevel-1) ; if ( verbLevel <=0 ) { rminuit->setNoWarn() ; } //---------------------------------------------------------------------------------------------- //-- If POI range is -1 to -1, automatically determine the range using the set value. if ( poiMinVal < 0. && poiMaxVal < 0. ) { printf("\n\n Automatic determination of scan range.\n\n") ; if ( startPoiVal <= 0. ) { printf("\n\n *** POI starting value zero or negative %g. Quit.\n\n\n", startPoiVal ) ; return ; } poiMinVal = startPoiVal - 3.5 * sqrt(startPoiVal) ; poiMaxVal = startPoiVal + 6.0 * sqrt(startPoiVal) ; if ( poiMinVal < 0. ) { poiMinVal = 0. ; } printf(" Start val = %g. Scan range: %g to %g\n\n", startPoiVal, poiMinVal, poiMaxVal ) ; } //---------------------------------------------------------------------------------------------- double poiVals_scanDown[1000] ; double nllVals_scanDown[1000] ; //-- Do scan down from best value. printf("\n\n +++++ Starting scan down from best value.\n\n") ; double minNllVal(1.e9) ; for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) { ////double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*(npoiPoints-1)) ; double poiValue = best_poi_val - poivi*(best_poi_val-poiMinVal)/(1.*(npoiPoints/2-1)) ; rrv_poiValue -> setVal( poiValue ) ; rrv_poiValue -> setConstant( kTRUE ) ; //+++++++++++++++++++++++++++++++++++ rminuit->migrad() ; rminuit->hesse() ; RooFitResult* rfr = rminuit->save() ; //+++++++++++++++++++++++++++++++++++ if ( verbLevel > 0 ) { rfr->Print("v") ; } float fit_minuit_var_val = rfr->minNll() ; printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI : %.5f %.5f %.5f %.5f\n", poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ; cout << flush ; poiVals_scanDown[poivi] = new_poi_rar->getVal() ; nllVals_scanDown[poivi] = plot_var->getVal() ; if ( nllVals_scanDown[poivi] < minNllVal ) { minNllVal = nllVals_scanDown[poivi] ; } delete rfr ; } // poivi printf("\n\n +++++ Resetting floats to best fit values.\n\n") ; for ( int pi=0; pi<nFloatParInitVal; pi++ ) { RooRealVar* par = ws->var( floatParName[pi] ) ; par->setVal( floatParInitVal[pi] ) ; } // pi. printf("\n\n +++++ Starting scan up from best value.\n\n") ; //-- Now do scan up. double poiVals_scanUp[1000] ; double nllVals_scanUp[1000] ; for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) { double poiValue = best_poi_val + poivi*(poiMaxVal-best_poi_val)/(1.*(npoiPoints/2-1)) ; rrv_poiValue -> setVal( poiValue ) ; rrv_poiValue -> setConstant( kTRUE ) ; //+++++++++++++++++++++++++++++++++++ rminuit->migrad() ; rminuit->hesse() ; RooFitResult* rfr = rminuit->save() ; //+++++++++++++++++++++++++++++++++++ if ( verbLevel > 0 ) { rfr->Print("v") ; } float fit_minuit_var_val = rfr->minNll() ; printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI : %.5f %.5f %.5f %.5f\n", poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ; cout << flush ; poiVals_scanUp[poivi] = new_poi_rar->getVal() ; nllVals_scanUp[poivi] = plot_var->getVal() ; if ( nllVals_scanUp[poivi] < minNllVal ) { minNllVal = nllVals_scanUp[poivi] ; } delete rfr ; } // poivi double poiVals[1000] ; double nllVals[1000] ; int pointCount(0) ; for ( int pi=0; pi<npoiPoints/2; pi++ ) { poiVals[pi] = poiVals_scanDown[(npoiPoints/2-1)-pi] ; nllVals[pi] = nllVals_scanDown[(npoiPoints/2-1)-pi] ; pointCount++ ; } for ( int pi=1; pi<npoiPoints/2; pi++ ) { poiVals[pointCount] = poiVals_scanUp[pi] ; nllVals[pointCount] = nllVals_scanUp[pi] ; pointCount++ ; } npoiPoints = pointCount ; printf("\n\n --- TGraph arrays:\n") ; for ( int i=0; i<npoiPoints; i++ ) { printf(" %2d : poi = %6.1f, nll = %g\n", i, poiVals[i], nllVals[i] ) ; } printf("\n\n") ; double nllDiffVals[1000] ; double poiAtMinlnL(-1.) ; double poiAtMinusDelta2(-1.) ; double poiAtPlusDelta2(-1.) ; for ( int poivi=0; poivi < npoiPoints ; poivi++ ) { nllDiffVals[poivi] = 2.*(nllVals[poivi] - minNllVal) ; double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*npoiPoints) ; if ( nllDiffVals[poivi] < 0.01 ) { poiAtMinlnL = poiValue ; } if ( poiAtMinusDelta2 < 0. && nllDiffVals[poivi] < 2.5 ) { poiAtMinusDelta2 = poiValue ; } if ( poiAtMinlnL > 0. && poiAtPlusDelta2 < 0. && nllDiffVals[poivi] > 2.0 ) { poiAtPlusDelta2 = poiValue ; } } // poivi printf("\n\n Estimates for poi at delta ln L = -2, 0, +2: %g , %g , %g\n\n", poiAtMinusDelta2, poiAtMinlnL, poiAtPlusDelta2 ) ; //--- Main canvas TCanvas* cscan = (TCanvas*) gDirectory->FindObject("cscan") ; if ( cscan == 0x0 ) { printf("\n Creating canvas.\n\n") ; cscan = new TCanvas("cscan","Delta nll") ; } char gname[1000] ; TGraph* graph = new TGraph( npoiPoints, poiVals, nllDiffVals ) ; sprintf( gname, "scan_%s", new_poi_name ) ; graph->SetName( gname ) ; double poiBest(-1.) ; double poiMinus1stdv(-1.) ; double poiPlus1stdv(-1.) ; double poiMinus2stdv(-1.) ; double poiPlus2stdv(-1.) ; double twoDeltalnLMin(1e9) ; int nscan(1000) ; for ( int xi=0; xi<nscan; xi++ ) { double x = poiVals[0] + xi*(poiVals[npoiPoints-1]-poiVals[0])/(nscan-1) ; double twoDeltalnL = graph -> Eval( x, 0, "S" ) ; if ( poiMinus1stdv < 0. && twoDeltalnL < 1.0 ) { poiMinus1stdv = x ; printf(" set m1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( poiMinus2stdv < 0. && twoDeltalnL < 4.0 ) { poiMinus2stdv = x ; printf(" set m2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( twoDeltalnL < twoDeltalnLMin ) { poiBest = x ; twoDeltalnLMin = twoDeltalnL ; } if ( twoDeltalnLMin < 0.3 && poiPlus1stdv < 0. && twoDeltalnL > 1.0 ) { poiPlus1stdv = x ; printf(" set p1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( twoDeltalnLMin < 0.3 && poiPlus2stdv < 0. && twoDeltalnL > 4.0 ) { poiPlus2stdv = x ; printf(" set p2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;} if ( xi%100 == 0 ) { printf( " %4d : poi=%6.2f, 2DeltalnL = %6.2f\n", xi, x, twoDeltalnL ) ; } } printf("\n\n POI estimate : %g +%g -%g [%g,%g], two sigma errors: +%g -%g [%g,%g]\n\n", poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), poiMinus1stdv, poiPlus1stdv, (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv), poiMinus2stdv, poiPlus2stdv ) ; printf(" %s val,pm1sig,pm2sig: %7.2f %7.2f %7.2f %7.2f %7.2f\n", new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv) ) ; char htitle[1000] ; sprintf(htitle, "%s profile likelihood scan: -2ln(L/Lm)", new_poi_name ) ; TH1F* hscan = new TH1F("hscan", htitle, 10, poiMinVal, poiMaxVal ) ; hscan->SetMinimum(0.) ; hscan->SetMaximum(ymax) ; hscan->DrawCopy() ; graph->SetLineColor(4) ; graph->SetLineWidth(3) ; graph->Draw("CP") ; gPad->SetGridx(1) ; gPad->SetGridy(1) ; cscan->Update() ; TLine* line = new TLine() ; line->SetLineColor(2) ; line->DrawLine(poiMinVal, 1., poiPlus1stdv, 1.) ; line->DrawLine(poiMinus1stdv,0., poiMinus1stdv, 1.) ; line->DrawLine(poiPlus1stdv ,0., poiPlus1stdv , 1.) ; TText* text = new TText() ; text->SetTextSize(0.04) ; char tstring[1000] ; sprintf( tstring, "%s = %.1f +%.1f -%.1f", new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv) ) ; text -> DrawTextNDC( 0.15, 0.85, tstring ) ; sprintf( tstring, "68%% interval [%.1f, %.1f]", poiMinus1stdv, poiPlus1stdv ) ; text -> DrawTextNDC( 0.15, 0.78, tstring ) ; char hname[1000] ; sprintf( hname, "hscanout_%s", new_poi_name ) ; TH1F* hsout = new TH1F( hname,"scan results",4,0.,4.) ; double obsVal(-1.) ; hsout->SetBinContent(1, obsVal ) ; hsout->SetBinContent(2, poiPlus1stdv ) ; hsout->SetBinContent(3, poiBest ) ; hsout->SetBinContent(4, poiMinus1stdv ) ; TAxis* xaxis = hsout->GetXaxis() ; xaxis->SetBinLabel(1,"Observed val.") ; xaxis->SetBinLabel(2,"Model+1sd") ; xaxis->SetBinLabel(3,"Model") ; xaxis->SetBinLabel(4,"Model-1sd") ; char outrootfile[10000] ; sprintf( outrootfile, "%s/scan-ff-%s.root", outputdir.Data(), new_poi_name ) ; char outpdffile[10000] ; sprintf( outpdffile, "%s/scan-ff-%s.pdf", outputdir.Data(), new_poi_name ) ; cscan->Update() ; cscan->Draw() ; printf("\n Saving %s\n", outpdffile ) ; cscan->SaveAs( outpdffile ) ; //--- save in root file printf("\n Saving %s\n", outrootfile ) ; TFile fout(outrootfile,"recreate") ; graph->Write() ; hsout->Write() ; fout.Close() ; delete ws ; wstf->Close() ; }
/* * Prepares the workspace to be used by the hypothesis test calculator */ void workspace_preparer(char *signal_file_name, char *signal_hist_name_in_file, char *background_file_name, char *background_hist_name_in_file, char *data_file_name, char *data_hist_name_in_file, char *config_file) { // Include the config_reader class. TString path = gSystem->GetIncludePath(); path.Append(" -I/home/max/cern/cls/mario"); gSystem->SetIncludePath(path); gROOT->LoadMacro("config_reader.cxx"); // RooWorkspace used to store values. RooWorkspace * pWs = new RooWorkspace("ws"); // Create a config_reader (see source for details) to read the config // file. config_reader reader(config_file, pWs); // Read MR and RR bounds from the config file. double MR_lower = reader.find_double("MR_lower"); double MR_upper = reader.find_double("MR_upper"); double RR_lower = reader.find_double("RR_lower"); double RR_upper = reader.find_double("RR_upper"); double MR_initial = (MR_lower + MR_upper)/2; double RR_initial = (RR_lower + RR_upper)/2; // Define the Razor Variables RooRealVar MR = RooRealVar("MR", "MR", MR_initial, MR_lower, MR_upper); RooRealVar RR = RooRealVar("RSQ", "RSQ", RR_initial, RR_lower, RR_upper); // Argument lists RooArgList pdf_arg_list(MR, RR, "input_args_list"); RooArgSet pdf_arg_set(MR, RR, "input_pdf_args_set"); /***********************************************************************/ /* PART 1: IMPORTING SIGNAL AND BACKGROUND HISTOGRAMS */ /***********************************************************************/ /* * Get the signal's unextended pdf by converting the TH2D in the file * into a RooHistPdf */ TFile *signal_file = new TFile(signal_file_name); TH2D *signal_hist = (TH2D *)signal_file->Get(signal_hist_name_in_file); RooDataHist *signal_RooDataHist = new RooDataHist("signal_roodatahist", "signal_roodatahist", pdf_arg_list, signal_hist); RooHistPdf *unextended_sig_pdf = new RooHistPdf("unextended_sig_pdf", "unextended_sig_pdf", pdf_arg_set, *signal_RooDataHist); /* * Repeat this process for the background. */ TFile *background_file = new TFile(background_file_name); TH2D *background_hist = (TH2D *)background_file->Get(background_hist_name_in_file); RooDataHist *background_RooDataHist = new RooDataHist("background_roodatahist", "background_roodatahist", pdf_arg_list, background_hist); RooHistPdf *unextended_bkg_pdf = new RooHistPdf("unextended_bkg_pdf", "unextended_bkg_pdf", pdf_arg_set, *background_RooDataHist); /* * Now, we want to create the bprime variable, which represents the * integral over the background-only sample. We will perform the * integral automatically (that's why this is the only nuisance * parameter declared in this file - its value can be determined from * the input histograms). */ ostringstream bprime_string; ostringstream bprime_pdf_string; bprime_string << "bprime[" << background_hist->Integral() << ", 0, 999999999]"; bprime_pdf_string << "Poisson::bprime_pdf(bprime, " << background_hist->Integral() << ")"; pWs->factory(bprime_string.str().c_str()); pWs->factory(bprime_pdf_string.str().c_str()); /* * This simple command will create all values from the config file * with 'make:' at the beginning and a delimiter at the end (see config * _reader if you don't know what a delimiter is). In other * words, the luminosity, efficiency, transfer factors, and their pdfs * are created from this command. The declarations are contained in the * config file to be changed easily without having to modify this code. */ reader.factory_all(); /* * Now, we want to create the extended pdfs from the unextended pdfs, as * well as from the S and B values we manufactured in the config file. * S and B are the values by which the signal and background pdfs, * respectively, are extended. Recall that they were put in the * workspace in the reader.facotry_all() command. */ RooAbsReal *S = pWs->function("S"); RooAbsReal *B = pWs->function("B"); RooExtendPdf *signalpart = new RooExtendPdf("signalpart", "signalpart", *unextended_sig_pdf, *S); RooExtendPdf *backgroundpart = new RooExtendPdf("backgroundpart", "backgroundpart", *unextended_bkg_pdf, *B); RooArgList *pdf_list = new RooArgList(*signalpart, *backgroundpart, "list"); // Add the signal and background pdfs to make a TotalPdf RooAddPdf *TotalPdf = new RooAddPdf("TotalPdf", "TotalPdf", *pdf_list); RooArgList *pdf_prod_list = new RooArgList(*TotalPdf, *pWs->pdf("lumi_pdf"), *pWs->pdf("eff_pdf"), *pWs->pdf("rho_pdf"), *pWs->pdf("bprime_pdf")); // This creates the final model pdf. RooProdPdf *model = new RooProdPdf("model", "model", *pdf_prod_list); /* * Up until now, we have been using the workspace pWs to contain all of * our values. Now, all of our values that we require are in use in the * RooProdPdf called "model". So, we need to import "model" into a * RooWorkspace. To avoid recopying values into the rooworkspace, when * the values may already be present (which can cause problems), we will * simply create a new RooWorkspace to avoid confusion and problems. The * new RooWorkspace is created here. */ RooWorkspace *newworkspace = new RooWorkspace("newws"); newworkspace->import(*model); // Immediately delete pWs, so we don't accidentally use it again. delete pWs; // Show off the newworkspace newworkspace->Print(); // observables RooArgSet obs(*newworkspace->var("MR"), *newworkspace->var("RSQ"), "obs"); // global observables RooArgSet globalObs(*newworkspace->var("nom_lumi"), *newworkspace->var("nom_eff"), *newworkspace->var("nom_rho")); //fix global observables to their nominal values newworkspace->var("nom_lumi")->setConstant(); newworkspace->var("nom_eff")->setConstant(); newworkspace->var("nom_rho")->setConstant(); //Set Parameters of interest RooArgSet poi(*newworkspace->var("sigma"), "poi"); //Set Nuisnaces RooArgSet nuis(*newworkspace->var("prime_lumi"), *newworkspace->var("prime_eff"), *newworkspace->var("prime_rho"), *newworkspace->var("bprime")); // priors (for Bayesian calculation) newworkspace->factory("Uniform::prior_signal(sigma)"); // for parameter of interest newworkspace->factory("Uniform::prior_bg_b(bprime)"); // for data driven nuisance parameter newworkspace->factory("PROD::prior(prior_signal,prior_bg_b)"); // total prior //Observed data is pulled from histogram. //TFile *data_file = new TFile(data_file_name); TFile *data_file = new TFile(data_file_name); TH2D *data_hist = (TH2D *)data_file->Get(data_hist_name_in_file); RooDataHist *pData = new RooDataHist("data", "data", obs, data_hist); newworkspace->import(*pData); // Now, we will draw our data from a RooDataHist. /*TFile *data_file = new TFile(data_file_name); TTree *data_tree = (TTree *) data_file->Get(data_hist_name_in_file); RooDataSet *pData = new RooDataSet("data", "data", data_tree, obs); newworkspace->import(*pData);*/ // Craft the signal+background model ModelConfig * pSbModel = new ModelConfig("SbModel"); pSbModel->SetWorkspace(*newworkspace); pSbModel->SetPdf(*newworkspace->pdf("model")); pSbModel->SetPriorPdf(*newworkspace->pdf("prior")); pSbModel->SetParametersOfInterest(poi); pSbModel->SetNuisanceParameters(nuis); pSbModel->SetObservables(obs); pSbModel->SetGlobalObservables(globalObs); // set all but obs, poi and nuisance to const SetConstants(newworkspace, pSbModel); newworkspace->import(*pSbModel); // background-only model // use the same PDF as s+b, with sig=0 // POI value under the background hypothesis // (We will set the value to 0 later) Double_t poiValueForBModel = 0.0; ModelConfig* pBModel = new ModelConfig(*(RooStats::ModelConfig *)newworkspace->obj("SbModel")); pBModel->SetName("BModel"); pBModel->SetWorkspace(*newworkspace); newworkspace->import(*pBModel); // find global maximum with the signal+background model // with conditional MLEs for nuisance parameters // and save the parameter point snapshot in the Workspace // - safer to keep a default name because some RooStats calculators // will anticipate it RooAbsReal * pNll = pSbModel->GetPdf()->createNLL(*pData); RooAbsReal * pProfile = pNll->createProfile(RooArgSet()); pProfile->getVal(); // this will do fit and set POI and nuisance parameters to fitted values RooArgSet * pPoiAndNuisance = new RooArgSet(); if(pSbModel->GetNuisanceParameters()) pPoiAndNuisance->add(*pSbModel->GetNuisanceParameters()); pPoiAndNuisance->add(*pSbModel->GetParametersOfInterest()); cout << "\nWill save these parameter points that correspond to the fit to data" << endl; pPoiAndNuisance->Print("v"); pSbModel->SetSnapshot(*pPoiAndNuisance); delete pProfile; delete pNll; delete pPoiAndNuisance; // Find a parameter point for generating pseudo-data // with the background-only data. // Save the parameter point snapshot in the Workspace pNll = pBModel->GetPdf()->createNLL(*pData); pProfile = pNll->createProfile(poi); ((RooRealVar *)poi.first())->setVal(poiValueForBModel); pProfile->getVal(); // this will do fit and set nuisance parameters to profiled values pPoiAndNuisance = new RooArgSet(); if(pBModel->GetNuisanceParameters()) pPoiAndNuisance->add(*pBModel->GetNuisanceParameters()); pPoiAndNuisance->add(*pBModel->GetParametersOfInterest()); cout << "\nShould use these parameter points to generate pseudo data for bkg only" << endl; pPoiAndNuisance->Print("v"); pBModel->SetSnapshot(*pPoiAndNuisance); delete pProfile; delete pNll; delete pPoiAndNuisance; // save workspace to file newworkspace->writeToFile("ws_twobin.root"); // clean up delete newworkspace; delete pData; delete pSbModel; delete pBModel; } // ----- end of tutorial ----------------------------------------
void eregtest_flextest(bool dobarrel, bool doele) { TString dirname = "/afs/cern.ch/work/b/bendavid/bare/eregtestoutalphafix2_float/"; gSystem->mkdir(dirname,true); gSystem->cd(dirname); TString fname; if (doele && dobarrel) fname = "wereg_ele_eb.root"; else if (doele && !dobarrel) fname = "wereg_ele_ee.root"; else if (!doele && dobarrel) fname = "wereg_ph_eb.root"; else if (!doele && !dobarrel) fname = "wereg_ph_ee.root"; //TString infile = TString::Format("/afs/cern.ch/work/b/bendavid/bare/eregAug10RCalphafixphiblind//%s",fname.Data()); TString infile = TString::Format("/data/bendavid/regflextesting/%s",fname.Data()); TFile *fws = TFile::Open(infile); RooWorkspace *ws = (RooWorkspace*)fws->Get("wereg"); //RooGBRFunction *func = static_cast<RooGBRFunction*>(ws->arg("func")); RooGBRTargetFlex *sigmeant = (RooGBRTargetFlex*)ws->function("sigmeant"); RooRealVar *tgtvar = ws->var("tgtvar"); //tgtvar->removeRange(); //tgtvar->setRange(0.98,1.02); RooRealVar *rawptvar = new RooRealVar("rawptvar","ph.scrawe/cosh(ph.eta)",1.); if (!dobarrel) rawptvar->SetTitle("(ph.scrawe+ph.scpse)/cosh(ph.eta)"); RooRealVar *rawevar = new RooRealVar("rawevar","ph.scrawe",1.); if (!dobarrel) rawevar->SetTitle("(ph.scrawe+ph.scpse)"); RooRealVar *nomevar = new RooRealVar("nomevar","ph.e",1.); RooArgList vars; vars.add(sigmeant->FuncVars()); vars.add(*tgtvar); vars.add(*rawptvar); vars.add(*rawevar); vars.add(*nomevar); RooArgList condvars; condvars.add(sigmeant->FuncVars()); RooRealVar weightvar("weightvar","",1.); TTree *dtree; if (doele) { TFile *fdin = TFile::Open("/data/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterSingleInvert"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } else { TFile *fdin = TFile::Open("/data/bendavid/idTreesAug1/hgg-2013Final8TeV_ID_s12-h124gg-gf-v7n_noskim.root"); //TFile *fdin = TFile::Open("/data/bendavid/idTrees_7TeV_Sept17/hgg-2013Final7TeV_ID_s11-h125gg-gf-lv3_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } // if (0) // { // // TFile *fdin = TFile::Open("/data/bendavid/8TeVFinalTreesSept17/hgg-2013Final8TeV_s12-diphoj-v7n_noskim.root"); // TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPresel"); // dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); // // } if (0) { TFile *fdin = TFile::Open("/data/bendavid/diphoTrees8TeVOct6/hgg-2013Final8TeV_s12-h123gg-gf-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } // //TFile *fdin = TFile::Open("/home/mingyang/cms/hist/hgg-2013Moriond/merged/hgg-2013Moriond_s12-diphoj-3-v7a_noskim.root"); // //TFile *fdin = TFile::Open("root://eoscms.cern.ch//eos/cms/store/cmst3/user/bendavid/trainingtreesJul1/hgg-2013Final8TeV_s12-zllm50-v7n_noskim.root"); // TFile *fdin = TFile::Open("root://eoscms.cern.ch///eos/cms/store/cmst3/user/bendavid/idTreesAug1/hgg-2013Final8TeV_ID_s12-h124gg-gf-v7n_noskim.root"); // //TFile *fdin = TFile::Open("root://eoscms.cern.ch//eos/cms/store/cmst3/user/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); // //TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterSingleInvert"); // TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); // TTree *dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); /* TFile *fdinsig = TFile::Open("/home/mingyang/cms/hist/hgg-2013Moriond/merged/hgg-2013Moriond_s12-h125gg-gf-v7a_noskim.root"); TDirectory *ddirsig = (TDirectory*)fdinsig->FindObjectAny("PhotonTreeWriterPreselNoSmear"); TTree *dtreesig = (TTree*)ddirsig->Get("hPhotonTreeSingle"); */ TCut selcut; if (dobarrel) { selcut = "ph.pt>25. && ph.isbarrel && ph.ispromptgen && abs(ph.sceta)>(-1.0)"; //selcut = "ph.pt>25. && ph.isbarrel && ph.ispromptgen && abs(ph.sceta)>(-1.0) && run==194533 && lumi==5 && evt==1400"; } else { selcut = "ph.pt>25 && !ph.isbarrel && ph.ispromptgen"; //selcut = "ph.pt>25 && !ph.isbarrel && ph.ispromptgen && run==194533 && lumi==5 && evt==1400"; } // TCut selcut = "ph.pt>25. && ph.isbarrel && ph.ispromptgen && abs(ph.sceta)<1.0"; //TCut selcut = "ph.pt>25. && ph.isbarrel && (ph.scrawe/ph.gene)>0. && (ph.scrawe/ph.gene)<2. && ph.ispromptgen"; //TCut selcut = "ph.pt>25. && ph.isbarrel && (ph.gene/ph.scrawe)>0. && (ph.gene/ph.scrawe)<2."; TCut selweight = "xsecweight(procidx)*puweight(numPU,procidx)"; TCut prescale10 = "(evt%10==0)"; TCut prescale10alt = "(evt%10==1)"; TCut prescale25 = "(evt%25==0)"; TCut prescale100 = "(evt%100==0)"; TCut prescale1000 = "(evt%1000==0)"; TCut evenevents = "(evt%2==0)"; TCut oddevents = "(evt%2==1)"; TCut prescale100alt = "(evt%100==1)"; TCut prescale1000alt = "(evt%1000==1)"; TCut prescale50alt = "(evt%50==1)"; //TCut oddevents = prescale100; if (doele) weightvar.SetTitle(prescale100alt*selcut); else weightvar.SetTitle(selcut); RooDataSet *hdata = RooTreeConvert::CreateDataSet("hdata",dtree,vars,weightvar); // for (int iev=0; iev<hdata->numEntries(); ++iev) { // const RooArgSet *dset = hdata->get(iev); // // condvars = *dset; // condvars.Print("V"); // // } //return; // if (doele) // weightvar.SetTitle(prescale100alt*selcut); // else // weightvar.SetTitle(selcut); //RooDataSet *hdatasmall = RooTreeConvert::CreateDataSet("hdatasmall",dtree,vars,weightvar); // const HybridGBRForestD *forest = func->Forest(); // for (unsigned int itgt=0; itgt<forest->Trees().size(); ++itgt) { // int ntrees = 0; // for (unsigned int itree = 0; itree<forest->Trees().at(itgt).size(); ++itree) { // if (forest->Trees()[itgt][itree].Responses().size()>1) ++ntrees; // } // printf("itgt = %i, ntrees = %i\n", int(itgt),ntrees); // } RooAbsPdf *sigpdf = ws->pdf("sigpdf"); RooRealVar *scetavar = ws->var("var_1"); RooAbsReal *sigmeanlim = ws->function("sigmeanlim"); RooAbsReal *sigwidthlim = ws->function("sigwidthlim"); RooAbsReal *signlim = ws->function("signlim"); RooAbsReal *sign2lim = ws->function("sign2lim"); RooAbsReal *alphalim = ws->function("sigalphalim"); RooAbsReal *alpha2lim = ws->function("sigalpha2lim"); //RooFormulaVar ecor("ecor","","1./(@0*@1)",RooArgList(*tgtvar,*sigmeanlim)); RooFormulaVar ecor("ecor","","@1/@0",RooArgList(*tgtvar,*sigmeanlim)); //RooFormulaVar ecor("ecor","","@0/@1",RooArgList(*tgtvar,*sigmeanlim)); //RooFormulaVar ecor("ecor","","exp(@1-@0)",RooArgList(*tgtvar,*sigmeanlim)); RooAbsReal *condnll = sigpdf->createNLL(*hdata,ConditionalObservables(sigmeant->FuncVars())); double condnllval = condnll->getVal(); //RooFormulaVar ecor("ecor","","@1/@0",RooArgList(*tgtvar,*sigmeanlim)); //RooFormulaVar ecor("ecor","","@0/@1",RooArgList(*tgtvar,*sigmeanlim)); //RooFormulaVar ecor("ecor","","@0",RooArgList(*tgtvar)); //RooRealVar *ecorvar = (RooRealVar*)hdata->addColumn(ecor); // ecorvar->setRange(0.,2.); // ecorvar->setBins(800); // RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); // //RooRealVar *rawvar = (RooRealVar*)hdata->addColumn(raw); // rawvar->setRange(0.,2.); // rawvar->setBins(800); /* RooFormulaVar eraw("eraw","","@0",RooArgList(*tgtvar)); RooRealVar *erawvar = (RooRealVar*)hdatasig->addColumn(eraw); erawvar->setRange(0.,2.); erawvar->setBins(400); */ //RooFormulaVar ecor("ptcor","","@0/(@1)",RooArgList(*tgtvar,*sigmeanlim)); RooDataSet *hdataclone = new RooDataSet(*hdata,"hdataclone"); RooRealVar *ecorvar = (RooRealVar*)hdataclone->addColumn(ecor); RooRealVar *meanvar = (RooRealVar*)hdataclone->addColumn(*sigmeanlim); RooRealVar *widthvar = (RooRealVar*)hdataclone->addColumn(*sigwidthlim); RooRealVar *nvar = 0; if (signlim) nvar = (RooRealVar*)hdataclone->addColumn(*signlim); RooRealVar *n2var = 0; if (sign2lim) n2var = (RooRealVar*)hdataclone->addColumn(*sign2lim); RooRealVar *alphavar = 0;; if (alphalim) alphavar = (RooRealVar*)hdataclone->addColumn(*alphalim); RooRealVar *alpha2var = 0; if (alpha2lim) alpha2var = (RooRealVar*)hdataclone->addColumn(*alpha2lim); RooFormulaVar ecorfull("ecorfull","","@0*@1",RooArgList(*sigmeanlim,*rawevar)); RooRealVar *ecorfullvar = (RooRealVar*)hdataclone->addColumn(ecorfull); RooFormulaVar ediff("ediff","","(@0 - @1)/@1",RooArgList(*nomevar,ecorfull)); RooRealVar *ediffvar = (RooRealVar*)hdataclone->addColumn(ediff); RooFormulaVar fullerr("fullerr","","@0*@1",RooArgList(*ecorvar,*sigwidthlim)); RooRealVar *fullerrvar = (RooRealVar*)hdataclone->addColumn(fullerr); RooFormulaVar relerr("relerr","","@0/@1",RooArgList(*sigwidthlim,*sigmeanlim)); RooRealVar *relerrvar = (RooRealVar*)hdataclone->addColumn(relerr); ecorvar->setRange(0.,2.); ecorvar->setBins(800); RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); //RooFormulaVar raw("raw","","exp(-@0)",RooArgList(*tgtvar)); RooRealVar *rawvar = (RooRealVar*)hdataclone->addColumn(raw); rawvar->setRange(0.,2.); rawvar->setBins(800); RooNormPdf sigpdfpeaknorm("sigpdfpeaknorm","",*sigpdf,*tgtvar); RooRealVar *sigpdfpeaknormvar = (RooRealVar*)hdataclone->addColumn(sigpdfpeaknorm); RooFormulaVar equivsigma("equivsigma","","@0/sqrt(2.0*TMath::Pi())/@1",RooArgList(sigpdfpeaknorm,*sigmeanlim)); RooRealVar *equivsigmavar = (RooRealVar*)hdataclone->addColumn(equivsigma); // for (int iev=0; iev<hdataclone->numEntries(); ++iev) { // const RooArgSet *dset = hdataclone->get(iev); // // //condvars = *dset; // //condvars.Print("V"); // dset->Print("V"); // } // // return; //hdataclone = (RooDataSet*)hdataclone->reduce("(rawptvar/sigmeanlim)>45."); //hdataclone = (RooDataSet*)hdataclone->reduce("relerr>0.1"); // hdataclone = (RooDataSet*)hdataclone->reduce("sigwidthlim>0.017"); // RooLinearVar *tgtscaled = (RooLinearVar*)ws->function("tgtscaled"); // // TCanvas *ccor = new TCanvas; // //RooPlot *plot = tgtvar->frame(0.6,1.2,100); // RooPlot *plotcor = tgtscaled->frame(0.6,2.0,100); // hdataclone->plotOn(plotcor); // sigpdf->plotOn(plotcor,ProjWData(*hdataclone)); // plotcor->Draw(); // ccor->SaveAs("CorE.eps"); // ccor->SetLogy(); // plotcor->SetMinimum(0.1); // ccor->SaveAs("CorElog.eps"); TCanvas *craw = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot = tgtvar->frame(0.8,1.4,400); //RooPlot *plot = tgtvar->frame(0.0,5.,400); //RooPlot *plot = tgtvar->frame(0.,5.,400); //RooPlot *plot = tgtvar->frame(-2.0,2.0,200); hdataclone->plotOn(plot); sigpdf->plotOn(plot,ProjWData(*hdataclone)); plot->Draw(); craw->SaveAs("RawE.eps"); craw->SetLogy(); plot->SetMinimum(0.1); craw->SaveAs("RawElog.eps"); /* new TCanvas; RooPlot *plotsig = tgtvar->frame(0.6,1.2,100); hdatasig->plotOn(plotsig); sigpdf.plotOn(plotsig,ProjWData(*hdatasig)); plotsig->Draw(); */ TCanvas *cmean = new TCanvas; RooPlot *plotmean = meanvar->frame(0.0,5.0,200); //RooPlot *plotmean = meanvar->frame(0.5,1.5,200); //RooPlot *plotmean = meanvar->frame(-1.0,1.0,200); hdataclone->plotOn(plotmean); plotmean->Draw(); cmean->SaveAs("mean.eps"); cmean->SetLogy(); plotmean->SetMinimum(0.1); TCanvas *cwidth = new TCanvas; RooPlot *plotwidth = widthvar->frame(0.,1.0,200); hdataclone->plotOn(plotwidth); plotwidth->Draw(); cwidth->SaveAs("width.eps"); cwidth->SetLogy(); plotwidth->SetMinimum(0.1); if (signlim) { TCanvas *cn = new TCanvas; RooPlot *plotn = nvar->frame(0.,20.,200); hdataclone->plotOn(plotn); plotn->Draw(); cn->SaveAs("n.eps"); TCanvas *cnwide = new TCanvas; RooPlot *plotnwide = nvar->frame(0.,2100.,200); hdataclone->plotOn(plotnwide); plotnwide->Draw(); cnwide->SaveAs("nwide.eps"); } if (sign2lim) { TCanvas *cn2 = new TCanvas; RooPlot *plotn2 = n2var->frame(0.,20.,200); hdataclone->plotOn(plotn2); plotn2->Draw(); cn2->SaveAs("n2.eps"); TCanvas *cn2wide = new TCanvas; RooPlot *plotn2wide = n2var->frame(0.,2100.,200); hdataclone->plotOn(plotn2wide); plotn2wide->Draw(); cn2wide->SaveAs("n2wide.eps"); } if (alphalim) { TCanvas *calpha = new TCanvas; RooPlot *plotalpha = alphavar->frame(0.,6.,200); hdataclone->plotOn(plotalpha); plotalpha->Draw(); calpha->SaveAs("alpha.eps"); calpha->SetLogy(); plotalpha->SetMinimum(0.1); } if (alpha2lim) { TCanvas *calpha2 = new TCanvas; RooPlot *plotalpha2 = alpha2var->frame(0.,6.,200); hdataclone->plotOn(plotalpha2); plotalpha2->Draw(); calpha2->SaveAs("alpha2.eps"); } TCanvas *ceta = new TCanvas; RooPlot *ploteta = scetavar->frame(-2.6,2.6,200); hdataclone->plotOn(ploteta); ploteta->Draw(); ceta->SaveAs("eta.eps"); //TH1 *heold = hdatasigtest->createHistogram("heold",testvar); //TH1 *heraw = hdata->createHistogram("heraw",*tgtvar,Binning(800,0.,2.)); TH1 *heraw = hdataclone->createHistogram("hraw",*rawvar,Binning(800,0.,2.)); TH1 *hecor = hdataclone->createHistogram("hecor",*ecorvar); //heold->SetLineColor(kRed); hecor->SetLineColor(kBlue); heraw->SetLineColor(kMagenta); hecor->GetXaxis()->SetRangeUser(0.6,1.2); //heold->GetXaxis()->SetRangeUser(0.6,1.2); TCanvas *cresponse = new TCanvas; hecor->Draw("HIST"); //heold->Draw("HISTSAME"); heraw->Draw("HISTSAME"); cresponse->SaveAs("response.eps"); cresponse->SetLogy(); cresponse->SaveAs("responselog.eps"); TCanvas *cpeakval = new TCanvas; RooPlot *plotpeak = sigpdfpeaknormvar->frame(0.,10.,100); hdataclone->plotOn(plotpeak); plotpeak->Draw(); TCanvas *cequivsigmaval = new TCanvas; RooPlot *plotequivsigma = equivsigmavar->frame(0.,0.04,100); hdataclone->plotOn(plotequivsigma); plotequivsigma->Draw(); TCanvas *cediff = new TCanvas; RooPlot *plotediff = ediffvar->frame(-0.01,0.01,100); hdataclone->plotOn(plotediff); plotediff->Draw(); printf("make fine histogram\n"); TH1 *hecorfine = hdataclone->createHistogram("hecorfine",*ecorvar,Binning(20e3,0.,2.)); printf("calc effsigma\n"); double effsigma = effSigma(hecorfine); printf("effsigma = %5f\n",effsigma); printf("condnll = %5f\n",condnllval); TFile *fhist = new TFile("hist.root","RECREATE"); fhist->WriteTObject(hecor); fhist->Close(); return; /* new TCanvas; RooPlot *ploteold = testvar.frame(0.6,1.2,100); hdatasigtest->plotOn(ploteold); ploteold->Draw(); new TCanvas; RooPlot *plotecor = ecorvar->frame(0.6,1.2,100); hdatasig->plotOn(plotecor); plotecor->Draw(); */ TH2 *profhist = (TH2*)hdataclone->createHistogram("relerrvsE",*ecorfullvar,Binning(50,0.,200.), YVar(*relerrvar,Binning(100,0.,0.05))); new TCanvas; profhist->Draw("COLZ"); new TCanvas; profhist->ProfileX()->Draw(); new TCanvas; profhist->ProfileY()->Draw(); TH2 *profhistequiv = (TH2*)hdataclone->createHistogram("equiverrvsE",*ecorfullvar,Binning(50,0.,200.), YVar(*equivsigmavar,Binning(100,0.,0.05))); new TCanvas; profhistequiv->Draw("COLZ"); new TCanvas; profhistequiv->ProfileX()->Draw(); new TCanvas; profhistequiv->ProfileY()->Draw(); }