void plot2(RooRealVar *mass, RooAbsPdf *pdf, RooAbsPdf *pdf1, RooAbsPdf *pdf2, float frac, RooDataSet *data, string name, int bins, int mhLow, int mhHigh){ RooPlot *plot = mass->frame(); mass->setRange("unblindReg_1",85,95); mass->setRange("unblindReg_2",110,120); if (BLIND) { data->plotOn(plot,Binning(bins),CutRange("unblindReg_1")); data->plotOn(plot,Binning(bins),CutRange("unblindReg_2")); data->plotOn(plot,Binning(bins),Invisible()); } else data->plotOn(plot,Binning(bins)); TCanvas *canv = new TCanvas(); pdf->plotOn(plot); pdf->plotOn(plot,Components(*pdf1),LineColor(kRed),LineStyle(2)) ; pdf->plotOn(plot,Components(*pdf2),LineColor(kGreen),LineStyle(2)) ; //,RooFit::NormRange("fitdata_1,fitdata_2")); //pdf->paramOn(plot,RooFit::Layout(0.35,0.89,0.89),RooFit::Format("NEA",AutoPrecision(1))); //plot->getAttText()->SetTextSize(0.01); //plot->SetMaximum(plot->GetMaximum()*2); if (BLIND) plot->SetMinimum(0.0001); plot->SetTitle(""); plot->SetYTitle(Form("Events / %.2fGeV",float(mhHigh-mhLow)/float(bins))); //plot->GetYaxis()->SetLabelSize(0.05); plot->SetTitleSize(0.045, "Y"); plot->SetTitleOffset(1.,"Y"); //plot->GetXaxis()->SetLabelSize(0.15); //plot->GetYaxis()->SetLabelSize(0.15); plot->SetXTitle("m_{#gamma#gamma}(GeV)"); plot->SetTitleSize(0.15, "X"); plot->Draw(); TLatex *lat = new TLatex(); lat->SetNDC(); lat->SetTextFont(42); lat->DrawLatex(0.68,0.93,"19.7fb^{-1}(8TeV)"); lat->DrawLatex(0.12,0.85,"CMS Preliminary"); lat->DrawLatex(0.7,0.7,Form("Frac = %.3f",frac)); string nameTemp = name; int catNum = nameTemp.find("cat"); string catNameOLD = nameTemp.replace(0, catNum, ""); string catName = catNameOLD.replace(catNameOLD.length()-4, 4, ""); lat->DrawLatex(0.1,0.92, Form("%s", catName.c_str())); TLegend *leg = new TLegend(0.12,0.7,0.32,0.8); leg->SetFillColor(0); leg->SetLineColor(1); leg->AddEntry(data,"Data","lep"); leg->Draw("same"); canv->SaveAs(Form("%s.png",name.c_str())); canv->SaveAs(Form("%s.pdf",name.c_str())); delete canv; delete lat; }
void MakeSpinPlots::DrawSpinBackground(TString tag, TString mcName,bool signal){ bool drawSM = (smName!="" && smName!=mcName); TCanvas cv; double thisN = ws->data(mcName+"_Combined")->reduce(TString("evtcat==evtcat::")+tag)->sumEntries(); float norm = thisN; //607*lumi/12.*thisN/(totEB+totEE); cout << norm <<endl; if(signal) norm = ws->data(Form("Data_%s_%s_sigWeight",tag.Data(),mcName.Data()))->sumEntries(); RooPlot *frame = ws->var("cosT")->frame(0,1,5); RooDataSet* bkgWeight = (RooDataSet*)ws->data(Form("Data_%s_%s_bkgWeight",tag.Data(),mcName.Data())); RooDataSet* tmp = (RooDataSet*)ws->data("Data_Combined")->reduce(TString("((mass>115 && mass<120) || (mass>130 && mass<135)) && evtcat==evtcat::")+tag); tmp->plotOn(frame,RooFit::Rescale(norm/tmp->sumEntries())); cout << "b" <<endl; ws->pdf(Form("%s_FIT_%s_cosTpdf",mcName.Data(),tag.Data()))->plotOn(frame,RooFit::LineColor(kGreen),RooFit::Normalization(norm/tmp->sumEntries())); if(drawSM) ws->pdf(Form("%s_FIT_%s_cosTpdf",smName.Data(),tag.Data()))->plotOn(frame,RooFit::LineColor(kRed),RooFit::Normalization(norm/tmp->sumEntries())); cout << "c " <<bkgWeight <<endl; bkgWeight->plotOn(frame,RooFit::Rescale(norm/bkgWeight->sumEntries()),RooFit::MarkerColor(kBlue) ); if(signal){ cout << "d" <<endl; ws->data(Form("Data_%s_%s_sigWeight",tag.Data(),mcName.Data()))->plotOn(frame,RooFit::MarkerStyle(4)); } cout << "d" <<endl; frame->SetMaximum(frame->GetMaximum()*(signal?0.8:0.4)*norm/tmp->sumEntries()); frame->SetMinimum(-1*frame->GetMaximum()); TLegend l(0.6,0.2,0.95,0.45); l.SetFillColor(0); l.SetBorderSize(0); l.SetHeader(tag); l.AddEntry(frame->getObject(0),"Data m#in [115,120]#cup[130,135]","p"); l.AddEntry(frame->getObject(1),mcName,"l"); if(drawSM) l.AddEntry(frame->getObject(2),"SM Higgs","l"); l.AddEntry(frame->getObject(2+drawSM),"background weighted Data","p"); if(signal) l.AddEntry(frame->getObject(3+drawSM),"signal weighted Data","p"); cout << "e" <<endl; frame->Draw(); l.Draw("SAME"); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_%s%s_%s_%s.png",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data(),tag.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/C/CosThetaDist_%s%s_%s_%s.C",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data(),tag.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_%s%s_%s_%s.pdf",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data(),tag.Data()) ); }
void MakeSpinPlots::DrawSpinSubTotBackground(TString mcName,bool signal){ bool drawSM = (smName!="" && smName!=mcName); TCanvas cv; double thisN = ws->data(mcName+"_Combined")->sumEntries(); float norm = thisN; if(signal) norm = ws->var(Form("Data_%s_FULLFIT_Nsig",mcName.Data()))->getVal(); RooPlot *frame = ws->var("cosT")->frame(0,1,10); RooDataSet* tmp = (RooDataSet*)ws->data(Form("Data_Combined"))->reduce("(mass>115 && mass<120) || (mass>130 && mass<135)"); tmp->plotOn(frame,RooFit::Rescale(norm/tmp->sumEntries())); ws->pdf(Form("%s_FIT_cosTpdf",mcName.Data()))->plotOn(frame,RooFit::LineColor(kGreen),RooFit::Normalization(norm/tmp->sumEntries())); if(drawSM) ws->pdf(Form("%s_FIT_cosTpdf",smName.Data()))->plotOn(frame,RooFit::LineColor(kRed),RooFit::Normalization(norm/tmp->sumEntries())); if(signal){ RooDataHist *h = (RooDataHist*)ws->data( Form("Data_%s_Combined_bkgSub_cosT",mcName.Data()) ); h->plotOn(frame,RooFit::MarkerStyle(4)); std::cout << "Nsig: " << h->sumEntries() << std::endl; } frame->SetMaximum(frame->GetMaximum()*(signal?2.:1.2)*norm/tmp->sumEntries()); frame->SetMinimum(-1*frame->GetMaximum()); TLegend l(0.6,0.2,0.95,0.45); l.SetFillColor(0); l.SetBorderSize(0); l.SetHeader("Combined"); l.AddEntry(frame->getObject(0),"Data m#in [115,120]#cup[130,135]","p"); l.AddEntry(frame->getObject(1),mcName,"l"); if(drawSM) l.AddEntry(frame->getObject(2),"SM Higgs","l"); if(signal) l.AddEntry(frame->getObject(2+drawSM),"bkg-subtracted Data","p"); frame->Draw(); l.Draw("SAME"); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_SimpleSub_%s%s_%s.png",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/C/CosThetaDist_SimpleSub_%s%s_%s.C",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_SimpleSub_%s%s_%s.pdf",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data()) ); }
void Raa3S_Workspace(const char* name_pbpb="chad_ws_fits/centFits/ws_PbPbData_262548_263757_0cent10_0.0pt50.0_0.0y2.4.root", const char* name_pp="chad_ws_fits/centFits/ws_PPData_262157_262328_-1cent1_0.0pt50.0_0.0y2.4.root", const char* name_out="fitresult_combo.root"){ //TFile File(filename); //RooWorkspace * ws = test_combine(name_pbpb, name_pp); TFile *f = new TFile("fitresult_combo_333.root") ; RooWorkspace * ws1 = (RooWorkspace*) f->Get("wcombo"); //File.GetObject("wcombo", ws); ws1->Print(); RooAbsData * data = ws1->data("data"); //dataOS, dataSS // 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,-1,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)); ws1->import(step); ws1->factory( "Uniform::flat(raa3)" ); //pp Luminosities, Taa and efficiency ratios Systematics ws1->factory( "Taa_hi[5.662e-9]" ); ws1->factory( "Taa_kappa[1.062]" ); // was 1.057 ws1->factory( "expr::alpha_Taa('pow(Taa_kappa,beta_Taa)',Taa_kappa,beta_Taa[0,-5,5])" ); ws1->factory( "prod::Taa_nom(Taa_hi,alpha_Taa)" ); ws1->factory( "Gaussian::constr_Taa(beta_Taa,glob_Taa[0,-5,5],1)" ); ws1->factory( "lumipp_hi[5.4]" ); ws1->factory( "lumipp_kappa[1.037]" ); // was 1.06 ws1->factory( "expr::alpha_lumipp('pow(lumipp_kappa,beta_lumipp)',lumipp_kappa,beta_lumipp[0,-5,5])" ); ws1->factory( "prod::lumipp_nom(lumipp_hi,alpha_lumipp)" ); ws1->factory( "Gaussian::constr_lumipp(beta_lumipp,glob_lumipp[0,-5,5],1)" ); // ws->factory( "effRat1[1]" ); // ws->factory( "effRat2[1]" ); ws1->factory( "effRat3_hi[0.95]" ); ws1->factory( "effRat_kappa[1.054]" ); ws1->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)" ); ws1->factory( "Gaussian::constr_effRat(beta_effRat,glob_effRat[0,-5,5],1)" ); // ws->factory( "prod::effRat2_nom(effRat2_hi,alpha_effRat)" ); ws1->factory( "prod::effRat3_nom(effRat3_hi,alpha_effRat)" ); // ws1->factory("Nmb_hi[1.161e9]"); ws1->factory("prod::denominator(Taa_nom,Nmb_hi)"); ws1->factory( "expr::lumiOverTaaNmbmodified('lumipp_nom/denominator',lumipp_nom,denominator)"); RooAbsReal *lumiOverTaaNmbmodified = ws1->function("lumiOverTaaNmbmodified"); //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 = ws1->var("R_{#frac{3S}{1S}}_pp"); //RooRealVar* nsig3_pp = ws->var("N_{#Upsilon(3S)}_pp"); cout << nsig3_pp << endl; RooAbsReal* effRat3 = ws1->function("effRat3_nom"); //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)); ws1->import(nsig3_hi_modified); // // background yield with systematics ws1->factory( "nbkg_hi_kappa[1.10]" ); ws1->factory( "expr::alpha_nbkg_hi('pow(nbkg_hi_kappa,beta_nbkg_hi)',nbkg_hi_kappa,beta_nbkg_hi[0,-5,5])" ); ws1->factory( "SUM::nbkg_hi_nom(alpha_nbkg_hi*bkgPdf_hi)" ); ws1->factory( "Gaussian::constr_nbkg_hi(beta_nbkg_hi,glob_nbkg_hi[0,-5,5],1)" ); RooAbsPdf* sig1S_hi = ws1->pdf("sig1S_hi"); //RooAbsPdf* sig1S_hi = ws->pdf("cbcb_hi"); RooAbsPdf* sig2S_hi = ws1->pdf("sig2S_hi"); RooAbsPdf* sig3S_hi = ws1->pdf("sig3S_hi"); RooAbsPdf* LSBackground_hi = ws1->pdf("nbkg_hi_nom"); RooRealVar* nsig1_hi = ws1->var("N_{#Upsilon(1S)}_hi"); RooRealVar* nsig2_hi = ws1->var("R_{#frac{2S}{1S}}_hi"); RooAbsReal* nsig3_hi = ws1->function("nsig3_hi_modified"); //RooFormulaVar* nsig3_hi = ws->function("nsig3_hi_modified"); cout << nsig1_hi << " " << nsig2_hi << " " << nsig3_pp << endl; RooRealVar* norm_nbkg_hi = ws1->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); //////////////////////////////////////////////////////////////////////////////// ws1->factory( "nbkg_pp_kappa[1.03]" ); ws1->factory( "expr::alpha_nbkg_pp('pow(nbkg_pp_kappa,beta_nbkg_pp)',nbkg_pp_kappa,beta_nbkg_pp[0,-5,5])" ); ws1->factory( "SUM::nbkg_pp_nom(alpha_nbkg_pp*bkgPdf_pp)" ); ws1->factory( "Gaussian::constr_nbkg_pp(beta_nbkg_pp,glob_nbkg_pp[0,-5,5],1)" ); RooAbsPdf* sig1S_pp = ws1->pdf("sig1S_pp"); //RooAbsPdf* sig1S_pp = ws1->pdf("cbcb_pp"); RooAbsPdf* sig2S_pp = ws1->pdf("sig2S_pp"); RooAbsPdf* sig3S_pp = ws1->pdf("sig3S_pp"); RooAbsPdf* LSBackground_pp = ws1->pdf("nbkg_pp_nom"); RooRealVar* nsig1_pp = ws1->var("N_{#Upsilon(1S)}_pp"); RooRealVar* nsig2_pp = ws1->var("R_{#frac{2S}{1S}}_pp"); //RooRealVar* nsig2_pp = ws1->var("N_{#Upsilon(2S)}_pp"); // RooRealVar* nsig3_pp = ws1->var("N_{#Upsilon(3S)}_pp"); RooRealVar* norm_nbkg_pp = ws1->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); ws1->import(model_num); ws1->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); ws1->import(model_den); ws1->factory("PROD::model_pp(model_den, constr_nbkg_pp)"); ws1->factory("SIMUL::joint(dataCat,hi=model_hi,pp=model_pp)"); ///////////////////////////////////////////////////////////////////// RooRealVar * pObs = ws1->var("invariantMass"); // get the pointer to the observable RooArgSet obs("observables"); obs.add(*pObs); obs.add( *ws1->cat("dataCat")); // ///////////////////////////////////////////////////////////////////// ws1->var("glob_lumipp")->setConstant(true); ws1->var("glob_Taa")->setConstant(true); ws1->var("glob_effRat")->setConstant(true); ws1->var("glob_nbkg_pp")->setConstant(true); ws1->var("glob_nbkg_hi")->setConstant(true); RooArgSet globalObs("global_obs"); globalObs.add( *ws1->var("glob_lumipp") ); globalObs.add( *ws1->var("glob_Taa") ); globalObs.add( *ws1->var("glob_effRat") ); globalObs.add( *ws1->var("glob_nbkg_hi") ); globalObs.add( *ws1->var("glob_nbkg_pp") ); cout << "66666" << endl; // ws1->Print(); RooArgSet poi("poi"); poi.add( *ws1->var("raa3") ); cout << "77777" << endl; // create set of nuisance parameters RooArgSet nuis("nuis"); nuis.add( *ws1->var("beta_lumipp") ); nuis.add( *ws1->var("beta_nbkg_hi") ); nuis.add( *ws1->var("beta_nbkg_pp") ); nuis.add( *ws1->var("beta_Taa") ); nuis.add( *ws1->var("beta_effRat") ); cout << "88888" << endl; ws1->var("#alpha_{CB}_hi")->setConstant(true); ws1->var("#alpha_{CB}_pp")->setConstant(true); ws1->var("#sigma_{CB1}_hi")->setConstant(true); ws1->var("#sigma_{CB1}_pp")->setConstant(true); ws1->var("#sigma_{CB2}/#sigma_{CB1}_hi")->setConstant(true); ws1->var("#sigma_{CB2}/#sigma_{CB1}_pp")->setConstant(true); //ws1->var("Centrality")->setConstant(true); //delete ws1->var("N_{#varUpsilon(1S)}_hi")->setConstant(true); ws1->var("N_{#varUpsilon(1S)}_pp")->setConstant(true); //ws1->var("N_{#Upsilon(2S)}_hi")->setConstant(true); //ws1->var("N_{#Upsilon(2S)}_pp")->setConstant(true); //ws1->var("N_{#Upsilon(3S)}_pp")->setConstant(true); ws1->var("R_{#frac{2S}{1S}}_hi")->setConstant(true); //new ws1->var("R_{#frac{2S}{1S}}_pp")->setConstant(true); //new ws1->var("R_{#frac{3S}{1S}}_hi")->setConstant(true); //new ws1->var("R_{#frac{3S}{1S}}_pp")->setConstant(true); //new ws1->var("Nmb_hi")->setConstant(true); // ws1->var("QQsign")->setConstant(true); ws1->var("Taa_hi")->setConstant(true); ws1->var("Taa_kappa")->setConstant(true); // ws1->var("beta_Taa")->setConstant(true); // ws1->var("beta_effRat")->setConstant(true); // ws1->var("beta_lumipp")->setConstant(true); // ws1->var("beta_nbkg_hi")->setConstant(true); // ws1->var("beta_nbkg_pp")->setConstant(true); // ws1->var("dataCat")->setConstant(true); ws1->var("decay_hi")->setConstant(true); ws1->var("decay_pp")->setConstant(true); ws1->var("effRat3_hi")->setConstant(true); ws1->var("effRat_kappa")->setConstant(true); // ws1->var("glob_Taa")->setConstant(true); // ws1->var("glob_effRat")->setConstant(true); // ws1->var("glob_lumipp")->setConstant(true); // ws1->var("glob_nbkg_hi")->setConstant(true); // ws1->var("glob_nbkg_pp")->setConstant(true); // ws1->var("invariantMass")->setConstant(true); ws1->var("leftEdge")->setConstant(true); ws1->var("lumipp_hi")->setConstant(true); ws1->var("lumipp_kappa")->setConstant(true); ws1->var("m_{ #varUpsilon(1S)}_hi")->setConstant(true); //ws1->var("mass1S_hi")->setConstant(true); ws1->var("m_{ #varUpsilon(1S)}_pp")->setConstant(true); //ws1->var("mass1S_pp")->setConstant(true); ws1->var("muMinusPt")->setConstant(true); ws1->var("muPlusPt")->setConstant(true); ws1->var("n_{Bkgd}_hi")->setConstant(true); ws1->var("n_{Bkgd}_pp")->setConstant(true); ws1->var("nbkg_hi_kappa")->setConstant(true); ws1->var("nbkg_pp_kappa")->setConstant(true); //ws1->var("n_{CB}")->setConstant(true); //ws1->var("n_{CB}")->setConstant(true); //ws1->var("npow")->setConstant(true); ws1->var("n_{CB}_hi")->setConstant(true); //ws1->var("n_{CB}")->setConstant(true); //ws1->var("npow")->setConstant(true); ws1->var("n_{CB}_pp")->setConstant(true); //ws1->var("n_{CB}")->setConstant(true); //ws1->var("npow")->setConstant(true); // ws1->var("raa3")->setConstant(true); ws1->var("rightEdge")->setConstant(true); ws1->var("sigmaFraction_hi")->setConstant(true); ws1->var("sigmaFraction_pp")->setConstant(true); ws1->var("turnOn_hi")->setConstant(true); ws1->var("turnOn_pp")->setConstant(true); ws1->var("dimuPt")->setConstant(true); //ws1->var("upsPt")->setConstant(true); ws1->var("dimuRapidity")->setConstant(true); //ws1->var("upsRapidity")->setConstant(true); ws1->var("vProb")->setConstant(true); ws1->var("width_hi")->setConstant(true); ws1->var("width_pp")->setConstant(true); // ws1->var("x3raw")->setConstant(true); // RooArgSet fixed_again("fixed_again"); // fixed_again.add( *ws1->var("leftEdge") ); // fixed_again.add( *ws1->var("rightEdge") ); // fixed_again.add( *ws1->var("Taa_hi") ); // fixed_again.add( *ws1->var("Nmb_hi") ); // fixed_again.add( *ws1->var("lumipp_hi") ); // fixed_again.add( *ws1->var("effRat1_hi") ); // fixed_again.add( *ws1->var("effRat2_hi") ); // fixed_again.add( *ws1->var("effRat3_hi") ); // fixed_again.add( *ws1->var("nsig3_pp") ); // fixed_again.add( *ws1->var("nsig1_pp") ); // fixed_again.add( *ws1->var("nbkg_hi") ); // fixed_again.add( *ws1->var("alpha") ); // fixed_again.add( *ws1->var("nbkg_kappa") ); // fixed_again.add( *ws1->var("Taa_kappa") ); // fixed_again.add( *ws1->var("lumipp_kappa") ); // fixed_again.add( *ws1->var("mean_hi") ); // fixed_again.add( *ws1->var("mean_pp") ); // fixed_again.add( *ws1->var("width_hi") ); // fixed_again.add( *ws1->var("turnOn_hi") ); // fixed_again.add( *ws1->var("bkg_a1_pp") ); // fixed_again.add( *ws1->var("bkg_a2_pp") ); // fixed_again.add( *ws1->var("decay_hi") ); // fixed_again.add( *ws1->var("raa1") ); // fixed_again.add( *ws1->var("raa2") ); // fixed_again.add( *ws1->var("nsig2_pp") ); // fixed_again.add( *ws1->var("sigma1") ); // fixed_again.add( *ws1->var("nbkg_pp") ); // fixed_again.add( *ws1->var("npow") ); // fixed_again.add( *ws1->var("muPlusPt") ); // fixed_again.add( *ws1->var("muMinusPt") ); // fixed_again.add( *ws1->var("mscale_hi") ); // fixed_again.add( *ws1->var("mscale_pp") ); // // ws1->Print(); cout << "99999" << endl; // create signal+background Model Config RooStats::ModelConfig sbHypo("SbHypo"); sbHypo.SetWorkspace( *ws1 ); sbHypo.SetPdf( *ws1->pdf("joint") ); sbHypo.SetObservables( obs ); sbHypo.SetGlobalObservables( globalObs ); sbHypo.SetParametersOfInterest( poi ); sbHypo.SetNuisanceParameters( nuis ); sbHypo.SetPriorPdf( *ws1->pdf("step") ); // this is optional // ws1->Print(); ///////////////////////////////////////////////////////////////////// RooAbsReal * pNll = sbHypo.GetPdf()->createNLL( *data,NumCPU(10) ); cout << "111111" << endl; RooMinuit(*pNll).migrad(); // minimize likelihood wrt all parameters before making plots cout << "444444" << endl; RooPlot *framepoi = ((RooRealVar *)poi.first())->frame(Bins(10),Range(0.,0.2),Title("LL and profileLL in raa3")); cout << "222222" << endl; pNll->plotOn(framepoi,ShiftToZero()); cout << "333333" << endl; 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"); ((RooRealVar *)poi.first())->setMin(0.); 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 = ws1->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; ws1->import( sbHypo ); ///////////////////////////////////////////////////////////////////// RooStats::ModelConfig bHypo = sbHypo; bHypo.SetName("BHypo"); bHypo.SetWorkspace(*ws1); 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 ((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(*ws1); ws1->import( bHypo ); ///////////////////////////////////////////////////////////////////// ws1->Print(); bHypo.Print(); sbHypo.Print(); // save workspace to file ws1 -> SaveAs(name_out); return; }
void fit_mass(TString fileN="") {//suffix added before file extension, e.g., '.pdf' TString placeholder;//to add strings before using them, e.g., for saving text files gROOT->SetBatch(kTRUE); gROOT->ProcessLine(".x /afs/cern.ch/user/m/mwilkins/cmtuser/src/lhcbStyle.C"); // gStyle->SetPadTickX(1); // gStyle->SetPadTickY(1); // gStyle->SetPadLeftMargin(0.15); // gStyle->SetTextSize(0.3); // //open file and get histogram // TFile *inHistos = new TFile("/afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/histos_data.root", "READ"); // TH1F * h100 = (TH1F*)inHistos->Get("h70"); // cout<<"data histogram gotten"<<endl; //unbinned TFile *hastree = new TFile("/afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/cutfile_Optimized.root", "READ"); TTree * h100 = (TTree*)hastree->Get("mytree"); cout<<"tree gotten"<<endl; TFile *SMChistos= new TFile("/afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/MC/withKScut/histos_SMCfile_fullMC.root", "READ"); cout<<"SMC file opened"<<endl; TH1F *SMCh = (TH1F*)SMChistos->Get("h00"); cout<<"SMC hist gotten"<<endl; RooRealVar *mass = new RooRealVar("Bs_LOKI_MASS_JpsiConstr","m(J/#psi #Lambda)",4100,6100,"MeV"); mass->setRange("bkg1",4300,4800); mass->setRange("bkg2",5700,5950); mass->setRange("bkg3",4300,5500); mass->setRange("bkg4",5100,5500); mass->setRange("L",5350,5950); mass->setRange("tot",4300,5950); cout<<"mass declared"<<endl; // RooDataHist *data = new RooDataHist("data","1D",RooArgList(*mass),h100); //unbinned RooDataSet *data = new RooDataSet("data","1D",h100,*mass); cout<<"data declared"<<endl; RooDataHist *SMC = new RooDataHist("SMC","1D",RooArgList(*mass),SMCh); cout<<"SMC hist assigned to RooDataHist"<<endl; // Construct Pdf Model // /\0 //gaussian RooRealVar mean1L("mean1L","/\\ gaus 1: mean",5621.103095,5525,5700); RooRealVar sig1L("sig1L","/\\ gaus 1: sigma",6.898126,0,100); RooGaussian gau1L("gau1L","#Lambda signal: gaussian 1",*mass,mean1L,sig1L); RooFormulaVar mean2L("mean2L","@0",mean1L); RooRealVar sig2L("sig2L","/\\ gaus 2: sigma",14.693117,0,100); RooGaussian gau2L("gau2L","#Lambda signal: gaussian 2",*mass,mean2L,sig2L); RooRealVar f1L("f1L","/\\ signal: fraction gaussian 1",0.748776,0,1); RooAddPdf sigL("sigL","#Lambda signal",RooArgList(gau1L,gau2L),RooArgList(f1L)); // //CB // RooRealVar mean3L("mean3L","/\\ CB: mean",5621.001,5525,5700); // RooRealVar sig3L("sig3L","/\\ CB: sigma",5.161,0,100); // RooRealVar alphaL3("alphaL3","/\\ CB: alpha",2.077,0,1000); // RooRealVar nL3("nL1","/\\ CB: n",0.286,0,1000); // RooCBShape CBL("CBL","#Lambda signal: CB",*mass,mean3L,sig3L,alphaL3,nL3); // RooRealVar mean4L("mean4L","/\\ gaus: mean",5621.804,5525,5700); // RooRealVar sig4L("sig4L","/\\ gaus: sigma",10.819,0,100); // RooGaussian gauL("gauL","#Lambda signal: gaussian",*mass,mean4L,sig4L); // RooRealVar f1L("f1L","/\\ signal: fraction CB",0.578,0,1); // RooAddPdf sigL("sigL","#Lambda signal",RooArgList(CBL,gauL),RooArgList(f1L)); // sigma0 //using RooHistPdf from MC--no need to build pdf here RooHistPdf sigS = makeroohistpdf(SMC,mass,"sigS","#Sigma^{0} signal (RooHistPdf)"); // /\* cout<<"Lst stuff"<<endl; RooRealVar meanLst1("meanLst1","/\\*(misc.): mean1",5011.031237,4900,5100); RooRealVar sigLst1("sigLst1","/\\*(misc.): sigma1",70.522092,0,100); RooRealVar meanLst2("mean5Lst2","/\\*(1405): mean2",5245.261703,5100,5350); RooRealVar sigLst2("sigLst2","/\\*(1405): sigma2",64.564763,0,100); RooRealVar alphaLst2("alphaLst2","/\\*(1405): alpha2",29.150301); RooRealVar nLst2("nLst2","/\\*(1405): n2",4.615817,0,50); RooGaussian gauLst1("gauLst1","#Lambda*(misc.), gaus",*mass,meanLst1,sigLst1); RooCBShape gauLst2("gauLst2","#Lambda*(1405), CB",*mass,meanLst2,sigLst2,alphaLst2,nLst2); // RooRealVar fLst1("fLst1","/\\* bkg: fraction gaus 1",0.743,0,1); // RooAddPdf bkgLst("bkgLst","#Lambda* signal",RooArgList(gauLst1,gauLst2),RooArgList(fLst1)); //Poly func BKG mass // RooRealVar b0("b0","Background: Chebychev b0",-1.071,-10000,10000); RooRealVar b1("b1","Background: Chebychev b1",-1.323004,-10,-0.00000000000000000000001); RooRealVar b2("b2","Background: Chebychev b2",0.145494,0,10); RooRealVar b3("b3","Background: Chebychev b3",-0.316,-10000,10000); RooRealVar b4("b4","Background: Chebychev b4",0.102,-10000,10000); RooRealVar b5("b5","Background: Chebychev b5",0.014,-10000,10000); RooRealVar b6("b6","Background: Chebychev b6",-0.015,-10000,10000); RooRealVar b7("b7","Background: Chebychev b7",0.012,-10000,10000); RooArgList bList(b1,b2); RooChebychev bkg("bkg","Background", *mass, bList); // TF1 *ep = new TF1("ep","[2]*exp([0]*x+[1]*x*x)",4300,5950); // ep->SetParameter(0,1); // ep->SetParameter(1,-1); // ep->SetParameter(2,2000); // ep->SetParName(0,"a"); // ep->SetParName(1,"b"); // ep->SetParName(2,"c"); // RooRealVar a("a","Background: Coefficent of x",1,-10000,10000); // RooRealVar b("b","Background: Coefficent of x*x",-1,-10000,10000); // RooRealVar c("c","Background: Coefficent of exp()",2000,-10000,10000); // RooTFnPdfBinding bkg("ep","ep",ep,RooArgList(*mass,a,b)); //number of each shape RooRealVar nbkg("nbkg","N bkg",2165.490249,0,100000000); RooRealVar nsigL("nsigL","N /\\",1689.637290,0,1000000000); RooRealVar nsigS("nsigS","N sigma",0.000002,0,10000000000); RooRealVar ngauLst1("ngauLst1","N /\\*(misc.)",439.812103,0,10000000000); RooRealVar ngauLst2("ngauLst2","N /\\*(1405)",152.061617,0,10000000000); RooRealVar nbkgLst("nbkgLst","N /\\*",591.828,0,1000000000); //add shapes and their number to a totalPdf RooArgList shapes; RooArgList yields; shapes.add(sigL); yields.add(nsigL); shapes.add(sigS); yields.add(nsigS); // shapes.add(bkgLst); yields.add(nbkgLst); shapes.add(gauLst1); yields.add(ngauLst1); shapes.add(gauLst2); yields.add(ngauLst2); shapes.add(bkg); yields.add(nbkg); RooAddPdf totalPdf("totalPdf","totalPdf",shapes,yields); //fit the totalPdf RooAbsReal * nll = totalPdf.createNLL(*data,Extended(kTRUE),Range("tot")); RooMinuit m(*nll); m.setVerbose(kFALSE); m.migrad(); m.minos(); m.minos(); //display and save information ofstream textfile;//create text file to hold data placeholder = "plots/fit"+fileN+".txt"; textfile.open(placeholder); TString outputtext;//for useful text //plot things RooPlot *framex = mass->frame(); framex->GetYaxis()->SetTitle("Events/(5 MeV)"); data->plotOn(framex,Name("Hist"),MarkerColor(kBlack),LineColor(kBlack),DataError(RooAbsData::SumW2)); totalPdf.plotOn(framex,Name("curvetot"),LineColor(kBlue)); RooArgSet* totalPdfComponents = totalPdf.getComponents(); TIterator* itertPC = totalPdfComponents->createIterator(); RooAddPdf* vartPC = (RooAddPdf*) itertPC->Next(); vartPC = (RooAddPdf*) itertPC->Next();//skip totalPdf int i=0;//color index TLegend *leg = new TLegend(0.2, 0.02, .4, .42); leg->SetTextSize(0.06); leg->AddEntry(framex->findObject("curvetot"),"Total PDF","l"); while(vartPC){//loop over compotents of totalPdf TString vartPCtitle = vartPC->GetTitle(); TIterator* itercompPars;//forward declare so it persists outside the if statement RooRealVar* varcompPars; if(!(vartPCtitle.Contains(":")||vartPCtitle.Contains("@"))){//only for non-sub-shapes while(i==0||i==10||i==4||i==1||i==5||(i>=10&&i<=27))i++;//avoid white and blue and black and yellow and horribleness RooArgSet* compPars = vartPC->getParameters(data);//set of the parameters of the component the loop is on itercompPars = compPars->createIterator(); varcompPars = (RooRealVar*) itercompPars->Next(); while(varcompPars){//write and print mean, sig, etc. of sub-shapes TString vartitle = varcompPars->GetTitle(); double varval = varcompPars->getVal(); TString varvalstring = Form("%f",varval); double hi = varcompPars->getErrorHi(); TString varerrorstring = "[exact]"; if(hi!=-1){ double lo = varcompPars->getErrorLo(); double varerror = TMath::Max(fabs(lo),hi); varerrorstring = Form("%E",varerror); } outputtext = vartitle+" = "+varvalstring+" +/- "+varerrorstring; textfile<<outputtext<<endl; cout<<outputtext<<endl; varcompPars = (RooRealVar*) itercompPars->Next(); } totalPdf.plotOn(framex,Name(vartPC->GetName()),LineStyle(kDashed),LineColor(i),Components(vartPC->GetName())); leg->AddEntry(framex->findObject(vartPC->GetName()),vartPCtitle,"l"); i++; } vartPC = (RooAddPdf*) itertPC->Next(); itercompPars->Reset();//make sure it's ready for the next vartPC } // Calculate chi2/ndf RooArgSet *floatpar = totalPdf.getParameters(data); int floatpars = (floatpar->selectByAttrib("Constant",kFALSE))->getSize(); Double_t chi2 = framex->chiSquare("curvetot","Hist",floatpars); TString chi2string = Form("%f",chi2); //create text box to list important parameters on the plot // TPaveText* txt = new TPaveText(0.1,0.5,0.7,0.9,"NBNDC"); // txt->SetTextSize(0.06); // txt->SetTextColor(kBlack); // txt->SetBorderSize(0); // txt->SetFillColor(0); // txt->SetFillStyle(0); outputtext = "#chi^{2}/N_{DoF} = "+chi2string; cout<<outputtext<<endl; textfile<<outputtext<<endl; // txt->AddText(outputtext); // Print stuff TIterator* iteryields = yields.createIterator(); RooRealVar* varyields = (RooRealVar*) iteryields->Next();//only inherits things from TObject unless class specified vector<double> Y, E;//holds yields and associated errors vector<TString> YS, ES;//holds strings of the corresponding yields int j=0;//count vector position int jS=0, jL=0;//these hold the position of the S and L results;initialized in case there is no nsigS or nsigL while(varyields){//loop over yields TString varname = varyields->GetName(); TString vartitle = varyields->GetTitle(); double varval = varyields->getVal(); Y.push_back(varval); double lo = varyields->getErrorLo(); double hi = varyields->getErrorHi(); E.push_back(TMath::Max(fabs(lo),hi)); YS.push_back(Form("%f",Y[j])); ES.push_back(Form("%f",E[j])); if(varname=="nsigS") jS=j; if(varname=="nsigL") jL=j; outputtext = vartitle+" = "+YS[j]+" +/- "+ES[j]; cout<<outputtext<<endl; textfile<<outputtext<<endl; //txt->AddText(outputtext); varyields = (RooRealVar*) iteryields->Next(); j++; } //S/L double result = Y[jS]/Y[jL]; cout<<"result declared"<<endl; double E_result = TMath::Abs(result)*sqrt(pow(E[jS]/Y[jS],2)+pow(E[jL]/Y[jL],2)); cout<<"E_result declared"<<endl; TString resultstring = Form("%E",result); TString E_resultstring = Form("%E",E_result); outputtext = "Y_{#Sigma^{0}}/Y_{#Lambda} = "+resultstring+" +/- "+E_resultstring; cout<<outputtext<<endl; textfile<<outputtext<<endl; //txt->AddText(outputtext); double resultlimit = (Y[jS]+E[jS])/(Y[jL]-E[jL]); outputtext = Form("%E",resultlimit); outputtext = "limit = "+outputtext; cout<<outputtext<<endl; textfile<<outputtext<<endl; //txt->AddText(outputtext); // Create canvas and pads, set style TCanvas *c1 = new TCanvas("c1","data fits",1200,800); TPad *pad1 = new TPad("pad1","pad1",0.0,0.3,1.0,1.0); TPad *pad2 = new TPad("pad2","pad2",0.0,0.0,1.0,0.3); pad1->SetBottomMargin(0); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.5); pad2->SetBorderMode(0); pad1->SetBorderMode(0); c1->SetBorderMode(0); pad2->Draw(); pad1->Draw(); pad1->cd(); framex->SetMinimum(1); framex->SetMaximum(3000); framex->addObject(leg);//add legend to frame //framex->addObject(txt);//add text to frame gPad->SetTopMargin(0.06); pad1->SetLogy(); // pad1->Range(4100,0,6100,0.0005); pad1->Update(); framex->Draw(); // Pull distribution RooPlot *framex2 = mass->frame(); RooHist* hpull = framex->pullHist("Hist","curvetot"); framex2->addPlotable(hpull,"P"); hpull->SetLineColor(kBlack); hpull->SetMarkerColor(kBlack); framex2->SetTitle(0); framex2->GetYaxis()->SetTitle("Pull"); framex2->GetYaxis()->SetTitleSize(0.15); framex2->GetYaxis()->SetLabelSize(0.15); framex2->GetXaxis()->SetTitleSize(0.2); framex2->GetXaxis()->SetLabelSize(0.15); framex2->GetYaxis()->CenterTitle(); framex2->GetYaxis()->SetTitleOffset(0.45); framex2->GetXaxis()->SetTitleOffset(1.1); framex2->GetYaxis()->SetNdivisions(505); framex2->GetYaxis()->SetRangeUser(-8.8,8.8); pad2->cd(); framex2->Draw(); c1->cd(); placeholder = "plots/fit"+fileN+".eps"; c1->Print(placeholder); placeholder = "plots/fit"+fileN+".C"; c1->SaveAs(placeholder); textfile.close(); }
void rf610_visualerror() { // S e t u p e x a m p l e f i t // --------------------------------------- // Create sum of two Gaussians p.d.f. with factory RooRealVar x("x","x",-10,10) ; RooRealVar m("m","m",0,-10,10) ; RooRealVar s("s","s",2,1,50) ; RooGaussian sig("sig","sig",x,m,s) ; RooRealVar m2("m2","m2",-1,-10,10) ; RooRealVar s2("s2","s2",6,1,50) ; RooGaussian bkg("bkg","bkg",x,m2,s2) ; RooRealVar fsig("fsig","fsig",0.33,0,1) ; RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ; // Create binned dataset x.setBins(25) ; RooAbsData* d = model.generateBinned(x,1000) ; // Perform fit and save fit result RooFitResult* r = model.fitTo(*d,Save()) ; // V i s u a l i z e f i t e r r o r // ------------------------------------- // Make plot frame RooPlot* frame = x.frame(Bins(40),Title("P.d.f with visualized 1-sigma error band")) ; d->plotOn(frame) ; // Visualize 1-sigma error encoded in fit result 'r' as orange band using linear error propagation // This results in an error band that is by construction symmetric // // The linear error is calculated as // error(x) = Z* F_a(x) * Corr(a,a') F_a'(x) // // where F_a(x) = [ f(x,a+da) - f(x,a-da) ] / 2, // // with f(x) = the plotted curve // 'da' = error taken from the fit result // Corr(a,a') = the correlation matrix from the fit result // Z = requested significance 'Z sigma band' // // The linear method is fast (required 2*N evaluations of the curve, where N is the number of parameters), // but may not be accurate in the presence of strong correlations (~>0.9) and at Z>2 due to linear and // Gaussian approximations made // model.plotOn(frame,VisualizeError(*r,1),FillColor(kOrange)) ; // Calculate error using sampling method and visualize as dashed red line. // // In this method a number of curves is calculated with variations of the parameter values, as sampled // from a multi-variate Gaussian p.d.f. that is constructed from the fit results covariance matrix. // The error(x) is determined by calculating a central interval that capture N% of the variations // for each valye of x, where N% is controlled by Z (i.e. Z=1 gives N=68%). The number of sampling curves // is chosen to be such that at least 100 curves are expected to be outside the N% interval, and is minimally // 100 (e.g. Z=1->Ncurve=356, Z=2->Ncurve=2156)) Intervals from the sampling method can be asymmetric, // and may perform better in the presence of strong correlations, but may take (much) longer to calculate model.plotOn(frame,VisualizeError(*r,1,kFALSE),DrawOption("L"),LineWidth(2),LineColor(kRed)) ; // Perform the same type of error visualization on the background component only. // The VisualizeError() option can generally applied to _any_ kind of plot (components, asymmetries, efficiencies etc..) model.plotOn(frame,VisualizeError(*r,1),FillColor(kOrange),Components("bkg")) ; model.plotOn(frame,VisualizeError(*r,1,kFALSE),DrawOption("L"),LineWidth(2),LineColor(kRed),Components("bkg"),LineStyle(kDashed)) ; // Overlay central value model.plotOn(frame) ; model.plotOn(frame,Components("bkg"),LineStyle(kDashed)) ; d->plotOn(frame) ; frame->SetMinimum(0) ; // V i s u a l i z e p a r t i a l f i t e r r o r // ------------------------------------------------------ // Make plot frame RooPlot* frame2 = x.frame(Bins(40),Title("Visualization of 2-sigma partial error from (m,m2)")) ; // Visualize partial error. For partial error visualization the covariance matrix is first reduced as follows // ___ -1 // Vred = V22 = V11 - V12 * V22 * V21 // // Where V11,V12,V21,V22 represent a block decomposition of the covariance matrix into observables that // are propagated (labeled by index '1') and that are not propagated (labeled by index '2'), and V22bar // is the Shur complement of V22, calculated as shown above // // (Note that Vred is _not_ a simple sub-matrix of V) // Propagate partial error due to shape parameters (m,m2) using linear and sampling method model.plotOn(frame2,VisualizeError(*r,RooArgSet(m,m2),2),FillColor(kCyan)) ; model.plotOn(frame2,Components("bkg"),VisualizeError(*r,RooArgSet(m,m2),2),FillColor(kCyan)) ; model.plotOn(frame2) ; model.plotOn(frame2,Components("bkg"),LineStyle(kDashed)) ; frame2->SetMinimum(0) ; // Make plot frame RooPlot* frame3 = x.frame(Bins(40),Title("Visualization of 2-sigma partial error from (s,s2)")) ; // Propagate partial error due to yield parameter using linear and sampling method model.plotOn(frame3,VisualizeError(*r,RooArgSet(s,s2),2),FillColor(kGreen)) ; model.plotOn(frame3,Components("bkg"),VisualizeError(*r,RooArgSet(s,s2),2),FillColor(kGreen)) ; model.plotOn(frame3) ; model.plotOn(frame3,Components("bkg"),LineStyle(kDashed)) ; frame3->SetMinimum(0) ; // Make plot frame RooPlot* frame4 = x.frame(Bins(40),Title("Visualization of 2-sigma partial error from fsig")) ; // Propagate partial error due to yield parameter using linear and sampling method model.plotOn(frame4,VisualizeError(*r,RooArgSet(fsig),2),FillColor(kMagenta)) ; model.plotOn(frame4,Components("bkg"),VisualizeError(*r,RooArgSet(fsig),2),FillColor(kMagenta)) ; model.plotOn(frame4) ; model.plotOn(frame4,Components("bkg"),LineStyle(kDashed)) ; frame4->SetMinimum(0) ; TCanvas* c = new TCanvas("rf610_visualerror","rf610_visualerror",800,800) ; c->Divide(2,2) ; c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ; c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ; c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ; c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.6) ; frame4->Draw() ; }
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 combinedWorkspace_4WS(const char* name_pbpb_pass="******", const char* name_pbpb_fail="fitresult_pbpb_fail.root", const char* name_pp_pass="******", const char* name_pp_fail="fitresult_pp_fail.root", const char* name_out="fitresult_combo.root", const float systval = 0., const char* subDirName ="wsTest", int nCPU=2){ // subdir: Directory to save workspaces under currentPATH/CombinedWorkspaces/subDir/ // set things silent gErrorIgnoreLevel=kError; RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR); bool dosyst = (systval > 0.); TString nameOut(name_out); RooWorkspace * ws = test_combine_4WS(name_pbpb_pass, name_pp_pass, name_pbpb_fail, name_pp_fail, false, nCPU); RooAbsData * data = ws->data("dOS_DATA"); RooRealVar* RFrac2Svs1S_PbPbvsPP_P = ws->var("RFrac2Svs1S_PbPbvsPP_P"); RooRealVar* leftEdge = new RooRealVar("leftEdge","leftEdge",-10); RooRealVar* rightEdge = new RooRealVar("rightEdge","rightEdge",10); RooGenericPdf step("step", "step", "(@0 >= @1) && (@0 < @2)", RooArgList(*RFrac2Svs1S_PbPbvsPP_P, *leftEdge, *rightEdge)); ws->import(step); ws->factory( "Uniform::flat(RFrac2Svs1S_PbPbvsPP_P)" ); // systematics if (dosyst) { ws->factory( Form("kappa_syst[%f]",systval) ); ws->factory( "expr::alpha_syst('kappa_syst*beta_syst',kappa_syst,beta_syst[0,-5,5])" ); ws->factory( "Gaussian::constr_syst(beta_syst,glob_syst[0,-5,5],1)" ); // add systematics into the double ratio ws->factory( "expr::RFrac2Svs1S_PbPbvsPP_P_syst('@0+@1',RFrac2Svs1S_PbPbvsPP_P,alpha_syst)" ); // build the pbpb pdf RooRealVar* effjpsi_pp_P = (RooRealVar*)ws->var("effjpsi_pp_P"); RooRealVar* effpsip_pp_P = (RooRealVar*)ws->var("effpsip_pp_P"); RooRealVar* effjpsi_pp_NP = (RooRealVar*)ws->var("effjpsi_pp_NP"); Double_t Npsi2SPbPbPass = npsip_pbpb_pass_from_doubleratio_prompt(ws, RooArgList(*effjpsi_pp_P,*effpsip_pp_P,*effjpsi_pp_NP),true); // Create and import N_Psi2S_PbPb_pass_syst ws->factory( "SUM::pdfMASS_Tot_PbPb_pass_syst(N_Jpsi_PbPb_pass * pdfMASS_Jpsi_PbPb_pass, N_Psi2S_PbPb_pass_syst * pdfMASS_Psi2S_PbPb_pass, N_Bkg_PbPb_pass * pdfMASS_Bkg_PbPb_pass)" ); ws->factory( "PROD::pdfMASS_Tot_PbPb_pass_constr(pdfMASS_Tot_PbPb_pass_syst,constr_syst)" ); // build the combined pdf ws->factory("SIMUL::simPdf_syst_noconstr(sample,PbPb_pass=pdfMASS_Tot_PbPb_pass_syst,PbPb_fail=pdfMASS_Tot_PbPb_fail,PP_pass=pdfMASS_Tot_PP_pass,PP_fail=pdfMASS_Tot_PP_fail)"); RooSimultaneous *simPdf = (RooSimultaneous*) ws->pdf("simPdf_syst_noconstr"); RooGaussian *constr_syst = (RooGaussian*) ws->pdf("constr_syst"); RooProdPdf *simPdf_constr = new RooProdPdf("simPdf_syst","simPdf_syst",RooArgSet(*simPdf,*constr_syst)); ws->import(*simPdf_constr); } else { ws->factory("SIMUL::simPdf_syst(sample,PbPb_pass=pdfMASS_Tot_PbPb_pass,PbPb_fail=pdfMASS_Tot_PbPb_fail,PP_pass=pdfMASS_Tot_PP_pass,PP_fail=pdfMASS_Tot_PP_fail)"); } ws->Print(); if (dosyst) ws->var("beta_syst")->setConstant(kFALSE); ///////////////////////////////////////////////////////////////////// RooRealVar * pObs = ws->var("invMass"); // get the pointer to the observable RooArgSet obs("observables"); obs.add(*pObs); obs.add( *ws->cat("sample")); // ///////////////////////////////////////////////////////////////////// if (dosyst) ws->var("glob_syst")->setConstant(true); RooArgSet globalObs("global_obs"); if (dosyst) globalObs.add( *ws->var("glob_syst") ); // ws->Print(); RooArgSet poi("poi"); poi.add( *ws->var("RFrac2Svs1S_PbPbvsPP_P") ); // create set of nuisance parameters RooArgSet nuis("nuis"); if (dosyst) nuis.add( *ws->var("beta_syst") ); // set parameters constant RooArgSet allVars = ws->allVars(); TIterator* it = allVars.createIterator(); RooRealVar *theVar = (RooRealVar*) it->Next(); while (theVar) { TString varname(theVar->GetName()); // if (varname != "RFrac2Svs1S_PbPbvsPP" // && varname != "invMass" // && varname != "sample" // ) // theVar->setConstant(); if ( varname.Contains("f_Jpsi_PP") || varname.Contains("f_Jpsi_PbPb") || varname.Contains("rSigma21_Jpsi_PP") || varname.Contains("m_Jpsi_PP") || varname.Contains("m_Jpsi_PbPb") || varname.Contains("sigma1_Jpsi_PP") || varname.Contains("sigma1_Jpsi_PbPb") || (varname.Contains("lambda")) || (varname.Contains("_fail") && !varname.Contains("RFrac2Svs1S"))) { theVar->setConstant(); } if (varname=="glob_syst" || varname=="beta_syst" ) { cout << varname << endl; theVar->setConstant(!dosyst); } theVar = (RooRealVar*) it->Next(); } // create signal+background Model Config RooStats::ModelConfig sbHypo("SbHypo"); sbHypo.SetWorkspace( *ws ); sbHypo.SetPdf( *ws->pdf("simPdf_syst") ); sbHypo.SetObservables( obs ); sbHypo.SetGlobalObservables( globalObs ); sbHypo.SetParametersOfInterest( poi ); sbHypo.SetNuisanceParameters( nuis ); sbHypo.SetPriorPdf( *ws->pdf("step") ); // this is optional ///////////////////////////////////////////////////////////////////// RooAbsReal * pNll = sbHypo.GetPdf()->createNLL( *data,NumCPU(nCPU) ); RooMinuit(*pNll).migrad(); // minimize likelihood wrt all parameters before making plots if (controlPlots) { RooPlot *framepoi = ((RooRealVar *)poi.first())->frame(Bins(10),Range(0.,1),Title("LL and profileLL in RFrac2Svs1S_PbPbvsPP_P")); pNll->plotOn(framepoi,ShiftToZero()); framepoi->SetMinimum(0); framepoi->SetMaximum(10); TCanvas *cpoi = new TCanvas(); cpoi->cd(); framepoi->Draw(); cpoi->SaveAs("cpoi.pdf"); } ((RooRealVar *)poi.first())->setMin(0.); RooArgSet * pPoiAndNuisance = new RooArgSet("poiAndNuisance"); pPoiAndNuisance->add( nuis ); pPoiAndNuisance->add( poi ); sbHypo.SetSnapshot(*pPoiAndNuisance); if (controlPlots) { RooPlot* xframeSB_PP_pass = pObs->frame(Title("SBhypo_PP_pass")); data->plotOn(xframeSB_PP_pass,Cut("sample==sample::PP_pass")); RooAbsPdf *pdfSB_PP_pass = sbHypo.GetPdf(); RooCategory *sample = ws->cat("sample"); pdfSB_PP_pass->plotOn(xframeSB_PP_pass,Slice(*sample,"PP_pass"),ProjWData(*sample,*data)); TCanvas *c1 = new TCanvas(); c1->cd(); xframeSB_PP_pass->Draw(); c1->SaveAs("c1.pdf"); RooPlot* xframeSB_PP_fail = pObs->frame(Title("SBhypo_PP_fail")); data->plotOn(xframeSB_PP_fail,Cut("sample==sample::PP_fail")); RooAbsPdf *pdfSB_PP_fail = sbHypo.GetPdf(); pdfSB_PP_fail->plotOn(xframeSB_PP_fail,Slice(*sample,"PP_fail"),ProjWData(*sample,*data)); TCanvas *c2 = new TCanvas(); c2->cd(); xframeSB_PP_fail->Draw(); c2->SaveAs("c1.pdf"); RooPlot* xframeB_PbPb_pass = pObs->frame(Title("SBhypo_PbPb_pass")); data->plotOn(xframeB_PbPb_pass,Cut("sample==sample::PbPb_pass")); RooAbsPdf *pdfB_PbPb_pass = sbHypo.GetPdf(); pdfB_PbPb_pass->plotOn(xframeB_PbPb_pass,Slice(*sample,"PbPb_pass"),ProjWData(*sample,*data)); TCanvas *c3 = new TCanvas(); c3->cd(); xframeB_PbPb_pass->Draw(); c3->SetLogy(); c3->SaveAs("c2.pdf"); RooPlot* xframeB_PbPb_fail = pObs->frame(Title("SBhypo_PbPb_fail")); data->plotOn(xframeB_PbPb_fail,Cut("sample==sample::PbPb_fail")); RooAbsPdf *pdfB_PbPb_fail = sbHypo.GetPdf(); pdfB_PbPb_fail->plotOn(xframeB_PbPb_fail,Slice(*sample,"PbPb_fail"),ProjWData(*sample,*data)); TCanvas *c4 = new TCanvas(); c4->cd(); xframeB_PbPb_fail->Draw(); c4->SetLogy(); c4->SaveAs("c2.pdf"); } delete pNll; delete pPoiAndNuisance; ws->import( sbHypo ); ///////////////////////////////////////////////////////////////////// RooStats::ModelConfig bHypo = sbHypo; bHypo.SetName("BHypo"); bHypo.SetWorkspace(*ws); pNll = bHypo.GetPdf()->createNLL( *data,NumCPU(nCPU) ); // RooMinuit(*pNll).migrad(); // minimize likelihood wrt all parameters before making plots RooArgSet poiAndGlobalObs("poiAndGlobalObs"); poiAndGlobalObs.add( poi ); poiAndGlobalObs.add( globalObs ); RooAbsReal * pProfile = pNll->createProfile( poiAndGlobalObs ); // do not profile POI and global observables ((RooRealVar *)poi.first())->setVal( 0 ); // set RFrac2Svs1S_PbPbvsPP=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); delete pNll; delete pPoiAndNuisance; // import model config into workspace bHypo.SetWorkspace(*ws); ws->import( bHypo ); ///////////////////////////////////////////////////////////////////// ws->Print(); bHypo.Print(); sbHypo.Print(); // save workspace to file string mainDIR = gSystem->ExpandPathName(gSystem->pwd()); string wsDIR = mainDIR + "/CombinedWorkspaces/"; string ssubDirName=""; if (subDirName) ssubDirName.append(subDirName); string subDIR = wsDIR + ssubDirName; void * dirp = gSystem->OpenDirectory(wsDIR.c_str()); if (dirp) gSystem->FreeDirectory(dirp); else gSystem->mkdir(wsDIR.c_str(), kTRUE); void * dirq = gSystem->OpenDirectory(subDIR.c_str()); if (dirq) gSystem->FreeDirectory(dirq); else gSystem->mkdir(subDIR.c_str(), kTRUE); const char* saveName = Form("%s/%s",subDIR.c_str(),nameOut.Data()); ws->writeToFile(saveName); }
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 paper_fit_plot() { SetAtlasStyle(); // get the stuff from the file char fname_postfit[200] = "monoh_withsm_SRCR_bg11.7_bgslop-0.0_nsig0.0.root"; TFile *tf = new TFile(fname_postfit); RooWorkspace *ws_post = (RooWorkspace*)tf->Get("wspace"); // data and pdf RooAbsData *data = ws_post->data("data"); RooAbsPdf *pdfc = ws_post->pdf("jointModeld"); // variables to be constrained RooRealVar *mh = ws_post->var("mh"); RooRealVar *sigma_h = ws_post->var("sigma_h"); RooRealVar *eff = ws_post->var("eff"); RooRealVar *theory = ws_post->var("theory"); RooRealVar *lumi = ws_post->var("lumi"); RooRealVar *x_mgg = ws_post->var("mgg"); RooArgSet cas(*mh,*sigma_h,*eff,*theory,*lumi); // redo the fit RooFitResult *r = pdfc->fitTo(*data,RooFit::Constrain(cas),RooFit::Save(true)); // make the frame RooPlot *frame = x_mgg->frame(); TCanvas *tc = new TCanvas("tc","",700,500); frame->GetXaxis()->SetTitle("m_{#gamma#gamma} [GeV]"); frame->GetYaxis()->SetTitle("Events / 1 GeV"); // add the data data->plotOn(frame,RooFit::Binning(55),RooFit::Name("xdata"),RooFit::DataError(RooAbsData::Poisson)); //data->plotOn(frame,RooFit::Binning(11),RooFit::Name("xdata"),RooFit::DataError(RooAbsData::Poisson)); /// PDFs pdfc->plotOn(frame, RooFit::Components("E"), RooFit::LineColor(kRed), RooFit::Name("xbackground")); pdfc->plotOn(frame, RooFit::Components("S"), RooFit::LineColor(kBlue),RooFit::LineStyle(kDotted), RooFit::Name("xsm")); pdfc->plotOn(frame, RooFit::Components("G"), RooFit::LineColor(kGreen),RooFit::LineStyle(kDotted), RooFit::Name("xbsm")); pdfc->plotOn(frame, RooFit::LineColor(kRed), RooFit::LineStyle(kDashed),RooFit::Name("xtotal")); frame->SetMinimum(1e-7); frame->SetMaximum(9); // Legend double x1,y1,x2,y2; GetX1Y1X2Y2(tc,x1,y1,x2,y2); TLegend *legend_sr=FastLegend(x1+0.02,y2-0.3,x1+0.35,y2-0.02,0.045); legend_sr->AddEntry(frame->findObject("xdata"),"Data","LEP"); legend_sr->AddEntry(frame->findObject("xbackground"),"Background fit","L"); legend_sr->AddEntry(frame->findObject("xsm"),"SM H","L"); legend_sr->AddEntry(frame->findObject("xbsm"),"Best-fit BSM H","L"); legend_sr->AddEntry(frame->findObject("xtotal"),"Total","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}#it{L} dt = 20.3 fb^{-1}"); pavetext11.push_back("#it{H + E}_{T}^{miss} , #it{H #rightarrow #gamma#gamma}, #it{m}_{#it{H}} = 125.4 GeV"); TPaveText* text11=CreatePaveText(x2-0.47,y2-0.25,x2-0.05,y2-0.05,pavetext11,0.045); text11->Draw(); tc->Print("paper_fit_plot.pdf"); }
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 rf405_realtocatfuncs() { // D e f i n e p d f i n x , s a m p l e d a t a s e t i n x // ------------------------------------------------------------------------ // Define a dummy PDF in x RooRealVar x("x","x",0,10) ; RooArgusBG a("a","argus(x)",x,RooConst(10),RooConst(-1)) ; // Generate a dummy dataset RooDataSet *data = a.generate(x,10000) ; // C r e a t e a t h r e s h o l d r e a l - > c a t f u n c t i o n // -------------------------------------------------------------------------- // A RooThresholdCategory is a category function that maps regions in a real-valued // input observable observables to state names. At construction time a 'default' // state name must be specified to which all values of x are mapped that are not // otherwise assigned RooThresholdCategory xRegion("xRegion","region of x",x,"Background") ; // Specify thresholds and state assignments one-by-one. // Each statement specifies that all values _below_ the given value // (and above any lower specified threshold) are mapped to the // category state with the given name // // Background | SideBand | Signal | SideBand | Background // 4.23 5.23 8.23 9.23 xRegion.addThreshold(4.23,"Background") ; xRegion.addThreshold(5.23,"SideBand") ; xRegion.addThreshold(8.23,"Signal") ; xRegion.addThreshold(9.23,"SideBand") ; // U s e t h r e s h o l d f u n c t i o n t o p l o t d a t a r e g i o n s // ------------------------------------------------------------------------------------- // Add values of threshold function to dataset so that it can be used as observable data->addColumn(xRegion) ; // Make plot of data in x RooPlot* xframe = x.frame(Title("Demo of threshold and binning mapping functions")) ; data->plotOn(xframe) ; // Use calculated category to select sideband data data->plotOn(xframe,Cut("xRegion==xRegion::SideBand"),MarkerColor(kRed),LineColor(kRed)) ; // C r e a t e a b i n n i n g r e a l - > c a t f u n c t i o n // ---------------------------------------------------------------------- // A RooBinningCategory is a category function that maps bins of a (named) binning definition // in a real-valued input observable observables to state names. The state names are automatically // constructed from the variable name, the binning name and the bin number. If no binning name // is specified the default binning is mapped x.setBins(10,"coarse") ; RooBinningCategory xBins("xBins","coarse bins in x",x,"coarse") ; // U s e b i n n i n g f u n c t i o n f o r t a b u l a t i o n a n d p l o t t i n g // ----------------------------------------------------------------------------------------------- // Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data // it can be a function of observables in data as well Roo1DTable* xbtable = data->table(xBins) ; xbtable->Print("v") ; // Add values of xBins function to dataset so that it can be used as observable RooCategory* xb = (RooCategory*) data->addColumn(xBins) ; // Define range "alt" as including bins 1,3,5,7,9 xb->setRange("alt","x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9") ; // Construct subset of data matching range "alt" but only for the first 5000 events and plot it on the frame RooDataSet* dataSel = (RooDataSet*) data->reduce(CutRange("alt"),EventRange(0,5000)) ; dataSel->plotOn(xframe,MarkerColor(kGreen),LineColor(kGreen)) ; new TCanvas("rf405_realtocatfuncs","rf405_realtocatfuncs",600,600) ; xframe->SetMinimum(0.01) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ; }
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 fitPtOverMCJLST(int mass = 125, int LHCsqrts = 7, int whichtype = 1, bool correctErrors = false, /* string changeParName = "", */ bool showErrorPDFs = false, string systString = "Default") // whichtype // 0 - gg Signal // 1 - VBF Signal // 2 - ZZ // 3 - ZX // 4 - ggZZ // 5 - WH // 6 - ZH // 7 - ttH { string changeParName = ""; if (systString == "Default") changeParName = "up"; string nameSample[8] = {"gg","vbf","zz","zx","ggzz","wh","zh","tth"}; float maxType[8] = {2.4,3.2,1.6,1.6,1.6,3.2,3.2,3.2}; float rebinType[8] = {1,2,1,1,4,10,10,40}; for (int t = 0; t < 8; t++) { if (mass > 150) maxType[t] = int(117.90*maxType[t]/sqrt(mass-10.91))/10.; } char fileToOpen[200]; sprintf(fileToOpen,"selRootFiles/PToverM_%s%d_SEL_%dTeV.root",nameSample[whichtype].c_str(),mass,LHCsqrts); // if (whichtype == 3) sprintf(fileToOpen,"PTOVERM_%s_SEL_allTeV.root",nameSample[whichtype].c_str()); RooRealVar* ptoverm = new RooRealVar("ptoverm","p_{T}/M^{4l}",0.,maxType[whichtype],"GeV/c"); TFile input(fileToOpen); // if (systString == "Mass" || systString == "Mela") { // sprintf(fileToOpen,"ptovermH_%sUp",systString.c_str()); // } else { sprintf(fileToOpen,"ptovermH_%s",systString.c_str()); //} TH1F* ptovermH = (TH1F*)input.Get(fileToOpen); if (rebinType[whichtype] > 1) ptovermH->Rebin(rebinType[whichtype]); if (maxType[whichtype] < ptovermH->GetBinLowEdge(ptovermH->GetNbinsX() + 1) - ptovermH->GetBinWidth(1)) { int theBin = ptovermH->FindBin(maxType[whichtype]); ptovermH->GetXaxis()->SetRange(1,theBin-1); } gROOT->ProcessLine(".L mytdrstyle.C"); gROOT->ProcessLine("setTDRStyle()"); // cout << endl << "Signal " << endl; ptoverm->setBins(ptovermH->GetNbinsX()); RooDataHist* rdh = new RooDataHist("rdh","Some dataset",RooArgList(*ptoverm),Import(*ptovermH,kFALSE)); // fit definitions // RooWorkspace *ws = new RooWorkspace("ws"); RooRealVar m("m","emme", 1.,0.01, 40.); RooRealVar n("n","enne", 0.93, 0.05, 15.); RooRealVar n2("n2","enne2", 0.75, 0.5, 15.); RooRealVar bb("bb","bibi",0.02, 0.000005, 20.0); RooRealVar T("T","tti",0.2,0.00000005,1.); RooRealVar bb2("bb2","bibi2",0.02, 0.0005, 10.0); RooRealVar fexp("fexp","f_exp",0.02, 0.0, 1.0); if (whichtype == 0) { if (LHCsqrts == 8) { m.setVal(3.319); // m.setConstant(kTRUE); n.setVal(0.7606); if (systString != "Default" || mass != 125) n.setConstant(kTRUE); n2.setVal(0.8061); n2.setConstant(kTRUE); bb.setVal(3.728); // bb.setConstant(kTRUE); T.setVal(0.00333); // T.setConstant(kTRUE); bb2.setVal(1.7172); // bb2.setConstant(kTRUE); fexp.setVal(0.002144); if (systString != "Default" || mass != 125) fexp.setConstant(kTRUE); } else { m.setVal(0.061); // m.setConstant(kTRUE); n.setVal(1.6141); if (systString == "Resummation" || systString == "TopMass") n.setConstant(kTRUE); n2.setVal(1.3294); n2.setConstant(kTRUE); bb.setVal(4.2761); // bb.setConstant(kTRUE); T.setVal(0.0361); // T.setConstant(kTRUE); bb2.setVal(1.6643); bb2.setConstant(kTRUE); fexp.setVal(0.0004); // fexp.setConstant(kTRUE); } } else if (whichtype == 1) { m.setVal(1.006); // m.setConstant(kTRUE); n.setVal(10.939); n.setConstant(kTRUE); n2.setVal(1.1448); n2.setConstant(kTRUE); bb.setVal(0.02048); bb.setConstant(kTRUE); T.setVal(0.16115); if (systString.find("Mela") != string::npos) T.setConstant(kTRUE); // T.setConstant(kTRUE); bb2.setVal(1.0024); bb2.setConstant(kTRUE); fexp.setVal(0.005); fexp.setConstant(kTRUE); if (mass > 300) { fexp.setVal(0.0); fexp.setConstant(kFALSE); } if (mass > 500) { bb2.setVal(5.0); // bb2.setConstant(kFALSE); } if (mass > 500) { bb.setVal(15.0); // bb.setConstant(kFALSE); } } else if (whichtype == 2) { if (LHCsqrts == 8) { m.setVal(1.0476); // m.setConstant(kTRUE); bb.setVal(3.3088); // if (mass != 140) bb.setConstant(kTRUE); n2.setVal(0.7146); n2.setConstant(kTRUE); n.setVal(0.9518); n.setConstant(kTRUE); bb2.setVal(100000.); bb2.setConstant(kTRUE); T.setVal(0.0021889); if (systString.find("Mela") != string::npos || mass != 140) T.setConstant(kTRUE); fexp.setVal(0.0); fexp.setConstant(kTRUE); } else { m.setVal(1.028); // m.setConstant(kTRUE); bb.setVal(2.91); // bb.setConstant(kTRUE); n2.setVal(0.7146); n2.setConstant(kTRUE); n.setVal(0.9518); n.setConstant(kTRUE); bb2.setVal(100000.); bb2.setConstant(kTRUE); T.setVal(0.002248); if (systString.find("Mela") != string::npos) T.setConstant(kTRUE); fexp.setVal(0.0); fexp.setConstant(kTRUE); } } else if (whichtype == 3) { m.setVal(1.411); // m.setConstant(kTRUE); n.setVal(3.4523); n.setConstant(kTRUE); n2.setVal(0.6910); n2.setConstant(kTRUE); bb.setVal(0.00039); // bb.setConstant(kTRUE); T.setVal(0.118); // T.setConstant(kTRUE); bb2.setVal(0.0224); bb2.setConstant(kTRUE); fexp.setVal(0.0); fexp.setConstant(kTRUE); } else if (whichtype == 4) { m.setVal(1.411); // m.setConstant(kTRUE); n.setVal(5.756); // n.setConstant(kTRUE); n2.setVal(0.8738); // n2.setConstant(kTRUE); bb.setVal(0.00039); // bb.setConstant(kTRUE); T.setVal(0.118); // T.setConstant(kTRUE); bb2.setVal(0.0224); bb2.setConstant(kTRUE); fexp.setVal(0.0); fexp.setConstant(kTRUE); } else if (whichtype == 5 && LHCsqrts == 8) { m.setVal(1.006); // m.setConstant(kTRUE); n.setVal(10.939); n.setConstant(kTRUE); n2.setVal(1.1448); n2.setConstant(kTRUE); bb.setVal(3.897); bb.setConstant(kTRUE); T.setVal(0.1009); // T.setConstant(kTRUE); bb2.setVal(1.0224); bb2.setConstant(kTRUE); fexp.setVal(0.01); fexp.setConstant(kTRUE); } else { // cout << "Entro qui" << endl; m.setVal(1.006); // m.setConstant(kTRUE); n.setVal(10.939); n.setConstant(kTRUE); n2.setVal(1.1448); n2.setConstant(kTRUE); bb.setVal(0.0129); bb.setConstant(kTRUE); T.setVal(0.1009); // T.setConstant(kTRUE); bb2.setVal(1.0224); bb2.setConstant(kTRUE); fexp.setVal(0.01); fexp.setConstant(kTRUE); } RooModifTsallis* rt3 = new RooModifTsallis("rt3","rt3",*ptoverm,m,n,n2,bb,bb2,T,fexp); // ws->import(*rt3); // fit RooFitResult* fit = rt3->fitTo(*rdh,Minos(0),Save(1),SumW2Error(kTRUE),NumCPU(1)); float mVal = m.getVal(); float nVal = n.getVal(); float n2Val = n2.getVal(); float bbVal = bb.getVal(); float bb2Val = bb2.getVal(); float fexpVal = fexp.getVal(); float TVal = T.getVal(); if (correctErrors) { // Tsallis errors not reliable, use toy MC TH1F* mHist = new TH1F("mHist","m",21,-0.5*mVal,0.5*mVal); TH1F* nHist = new TH1F("nHist","n",21,-0.2*nVal,0.2*nVal); TH1F* n2Hist = new TH1F("n2Hist","n2",21,-0.2*n2Val,0.2*n2Val); TH1F* bbHist = new TH1F("bbHist","bb",21,-0.2*bbVal,0.2*bbVal); TH1F* bb2Hist = new TH1F("bb2Hist","bb2",21,-0.2*bb2Val,0.2*bb2Val); TH1F* fexpHist = new TH1F("fexpHist","fexp",21,-0.2*fexpVal-0.000001,0.2*fexpVal+0.000001); TH1F* THist = new TH1F("THist","T",21,-0.5*TVal,0.5*TVal); mHist->GetXaxis()->SetTitle("m-m_{gen}"); nHist->GetXaxis()->SetTitle("n-n_{gen}"); n2Hist->GetXaxis()->SetTitle("n2-n2_{gen}"); bbHist->GetXaxis()->SetTitle("bb-bb_{gen}"); bb2Hist->GetXaxis()->SetTitle("bb2-bb2_{gen}"); THist->GetXaxis()->SetTitle("T-T_{gen}"); fexpHist->GetXaxis()->SetTitle("fexp-fexp_{gen}"); for (unsigned int iToy = 0; iToy < 200; iToy++) { cout << endl << "####" << endl; cout << "Generating toy experiment n. " << iToy+1 << endl; m.setVal(mVal); n.setVal(nVal); n2.setVal(n2Val); bb.setVal(bbVal); bb2.setVal(bb2Val); fexp.setVal(fexpVal); T.setVal(TVal); TDatime *now = new TDatime(); Int_t seed = now->GetDate() + now->GetTime(); cout << "RooFit Generation Seed = " << seed+iToy << endl; RooRandom::randomGenerator()->SetSeed(seed+iToy); cout << "####" << endl << endl; RooDataSet *dataToy = rt3->generate(RooArgSet(*ptoverm),ptovermH->GetEntries()); RooDataHist *dataToyH = new RooDataHist("dataToyH","toy",RooArgSet(*ptoverm),*dataToy); rt3->fitTo(*dataToyH,Minos(0),SumW2Error(kTRUE),NumCPU(1)); if (fit->floatParsFinal().find("m")) mHist->Fill(m.getVal()-mVal); if (fit->floatParsFinal().find("n")) nHist->Fill(n.getVal()-nVal); if (fit->floatParsFinal().find("n2")) n2Hist->Fill(n2.getVal()-n2Val); if (fit->floatParsFinal().find("bb")) bbHist->Fill(bb.getVal()-bbVal); if (fit->floatParsFinal().find("bb2")) bb2Hist->Fill(bb2.getVal()-bb2Val); if (fit->floatParsFinal().find("fexp")) fexpHist->Fill(fexp.getVal()-fexpVal); if (fit->floatParsFinal().find("T")) THist->Fill(T.getVal()-TVal); } TCanvas cant("cant","Test canvas",5.,5.,900.,500.); cant.Divide(4,2); cant.cd(1); mHist->Draw(); cant.cd(2); nHist->Draw(); cant.cd(3); n2Hist->Draw(); cant.cd(4); bbHist->Draw(); cant.cd(5); bb2Hist->Draw(); cant.cd(6); fexpHist->Draw(); cant.cd(7); THist->Draw(); // cant.SaveAs("figs/testToys.pdf"); cant.SaveAs("newfigs/testToys.pdf"); if (fit->floatParsFinal().find("m")) m.setError(mHist->GetRMS()); if (fit->floatParsFinal().find("n")) n.setError(nHist->GetRMS()); if (fit->floatParsFinal().find("n2")) n2.setError(n2Hist->GetRMS()); if (fit->floatParsFinal().find("bb")) bb.setError(bbHist->GetRMS()); if (fit->floatParsFinal().find("bb2")) bb2.setError(bb2Hist->GetRMS()); if (fit->floatParsFinal().find("fexp")) fexp.setError(fexpHist->GetRMS()); if (fit->floatParsFinal().find("T")) T.setError(THist->GetRMS()); } m.setVal(mVal); n.setVal(nVal); n2.setVal(n2Val); bb.setVal(bbVal); bb2.setVal(bb2Val); fexp.setVal(fexpVal); T.setVal(TVal); char fileToSave[200]; // if (changeParName != "") // sprintf(fileToSave,"text/paramsPTOverMCJLST_%s_%dTeV_%s_%s.txt",nameSample[whichtype].c_str(),LHCsqrts,systString.c_str(),changeParName.c_str()); // else sprintf(fileToSave,"text/paramsPTOverMCJLST_%s%d_%dTeV_%s.txt",nameSample[whichtype].c_str(),mass,LHCsqrts,systString.c_str()); ofstream os1(fileToSave); if (changeParName != "") { sprintf(fileToSave,"m%s",changeParName.c_str()); m.SetName(fileToSave); sprintf(fileToSave,"n%s",changeParName.c_str()); n.SetName(fileToSave); sprintf(fileToSave,"n2%s",changeParName.c_str()); n2.SetName(fileToSave); sprintf(fileToSave,"bb%s",changeParName.c_str()); bb.SetName(fileToSave); sprintf(fileToSave,"bb2%s",changeParName.c_str()); bb2.SetName(fileToSave); sprintf(fileToSave,"fexp%s",changeParName.c_str()); fexp.SetName(fileToSave); sprintf(fileToSave,"T%s",changeParName.c_str()); T.SetName(fileToSave); } (RooArgSet(m,n,n2,bb,bb2,fexp,T)).writeToStream(os1,false); os1.close(); RooRealVar mup("mup","emme", 1.,0.01, 30.); RooRealVar nup("nup","enne", 0.93, 0.5, 15.); RooRealVar n2up("n2up","enne2", 0.75, 0.5, 15.); RooRealVar bbup("bbup","bibi",0.02, 0.00005, 20.0); RooRealVar Tup("Tup","tti",0.2,0.00000005,1.); RooRealVar bb2up("bb2up","bibi2",0.02, 0.0005, 10.0); RooRealVar fexpup("fexpup","f_exp",0.02, 0.0, 1.0); RooModifTsallis* rt3up = new RooModifTsallis("rt3up","rt3up",*ptoverm,mup,nup,n2up,bbup,bb2up,Tup,fexpup); // ws->import(*rt3up); RooRealVar mdown("mdown","emme", 1.,0.01, 30.); RooRealVar ndown("ndown","enne", 0.93, 0.5, 15.); RooRealVar n2down("n2down","enne2", 0.75, 0.5, 15.); RooRealVar bbdown("bbdown","bibi",0.02, 0.00005, 20.0); RooRealVar Tdown("Tdown","tti",0.2,0.00000005,1.); RooRealVar bb2down("bb2down","bibi2",0.02, 0.0005, 10.0); RooRealVar fexpdown("fexpdown","f_exp",0.02, 0.0, 1.0); RooModifTsallis* rt3down = new RooModifTsallis("rt3down","rt3down",*ptoverm,mdown,ndown,n2down,bbdown,bb2down,Tdown,fexpdown); // ws->import(*rt3down); RooPlot *frame = ptoverm->frame(); char reducestr[300]; sprintf(reducestr,"ptoverm > %f && ptoverm < %f",ptoverm->getMin(),ptoverm->getMax()); rdh->plotOn(frame,DataError(RooAbsData::SumW2),Cut(reducestr)); static RooHist *hpull; float chi2 = 0.; if (changeParName == "") { sprintf(fileToSave,"text/paramsPTOverMCJLST_%s%d_%dTeV_Default.txt",nameSample[whichtype].c_str(),mass,LHCsqrts); ifstream is1(fileToSave); (RooArgSet(mup,nup,n2up,bbup,bb2up,fexpup,Tup)).readFromStream(is1,false); mdown.setVal(fabs(3*mup.getVal() - 2*m.getVal())); ndown.setVal(fabs(3*nup.getVal() - 2*n.getVal())); n2down.setVal(fabs(3*n2up.getVal() - 2*n2.getVal())); bbdown.setVal(fabs(3*bbup.getVal() - 2*bb.getVal())); Tdown.setVal(fabs(3*Tup.getVal() - 2*T.getVal())); bb2down.setVal(fabs(3*bb2up.getVal() - 2*bb2.getVal())); fexpdown.setVal(fabs(3*fexpup.getVal() - 2*fexp.getVal())); if (showErrorPDFs) { rt3->plotOn(frame,LineColor(kRed),LineStyle(kDashed),Normalization(rdh->sumEntries(),RooAbsReal::NumEvent)); hpull = frame->pullHist(); rt3up->plotOn(frame,LineColor(kBlue),Normalization(rdh->sumEntries(),RooAbsReal::NumEvent)); if (systString.find("Mela") == string::npos) rt3down->plotOn(frame,LineColor(kRed),LineStyle(kDashed),Normalization(rdh->sumEntries(),RooAbsReal::NumEvent)); } else { rt3->plotOn(frame,LineColor(kBlue),Normalization(rdh->sumEntries(),RooAbsReal::NumEvent)); hpull = frame->pullHist(); } } else { mup.setVal(m.getVal() + m.getError()); cout << "mup = " << mup.getVal() << endl; nup.setVal(n.getVal() + n.getError()); n2up.setVal(n2.getVal() + n2.getError()); bbup.setVal(bb.getVal() + bb.getError()); Tup.setVal(T.getVal() + T.getError()); bb2up.setVal(bb2.getVal() + bb2.getError()); fexpup.setVal(fexp.getVal() + fexp.getError()); mdown.setVal(m.getVal() - m.getError()); cout << "mdown = " << mdown.getVal() << endl; ndown.setVal(n.getVal() - n.getError()); n2down.setVal(n2.getVal() - n2.getError()); bbdown.setVal(bb.getVal() - bb.getError()); Tdown.setVal(T.getVal() - T.getError()); bb2down.setVal(bb2.getVal() - bb2.getError()); fexpdown.setVal(fexp.getVal() - fexp.getError()); rt3->plotOn(frame,LineColor(kBlue),Normalization(rdh->sumEntries(),RooAbsReal::NumEvent)); hpull = frame->pullHist(); if (showErrorPDFs) { rt3up->plotOn(frame,LineColor(kRed),LineStyle(kDashed),Normalization(rdh->sumEntries(),RooAbsReal::NumEvent)); rt3down->plotOn(frame,LineColor(kRed),LineStyle(kDashed),Normalization(rdh->sumEntries(),RooAbsReal::NumEvent)); } } double *ypulls = hpull->GetY(); unsigned int nBins = rdh->numEntries(); unsigned int nFullBins = 0; for (unsigned int i = 0; i < nBins; i++) { cout << "Pull of bin " << i << " = " << ypulls[i] << endl; if (fabs(ypulls[i]) < 5.0) chi2 += ypulls[i]*ypulls[i]; cout << "Partial chi2 = " << chi2 << endl; if (fabs(ypulls[i]) > 0.0001 && fabs(ypulls[i]) < 5.0) nFullBins++; } for (unsigned int i = 0; i < nBins; i++) { if (fabs(ypulls[i]) < 0.0001) ypulls[i] = 999.; hpull->SetPointError(i,0.,0.,0.,0.); } int nFitPar = fit->floatParsFinal().getSize() - 1; TCanvas can("can","The canvas",5.,5.,500.,900.); can.Divide(1,3); TLatex *t = new TLatex(); t->SetNDC(); t->SetTextAlign(22); t->SetTextSize(0.06); can.cd(1); gPad->SetBottomMargin(0.0); frame->Draw(); // gPad->SetLogy(); // Htest->Draw(); sprintf(fileToSave,"%s %d GeV at %d TeV",nameSample[whichtype].c_str(),mass,LHCsqrts); t->DrawLatex(0.6,0.8,fileToSave); can.cd(2); gPad->SetLogy(); gPad->SetTopMargin(0.0); frame->Draw(); RooPlot* pull = ptoverm->frame(Title("Pull Distribution")) ; pull->GetYaxis()->SetTitle("Pull"); /* pull->SetLabelSize(0.08,"XYZ"); pull->SetTitleSize(0.08,"XYZ"); pull->SetTitleOffset(0.6,"Y"); pull->SetTitleOffset(1.0,"X"); */ pull->addPlotable(hpull,"P") ; pull->SetMinimum(-6.); pull->SetMaximum(6.); can.cd(3); gPad->SetGridy(); pull->Draw(); sprintf(fileToSave,"#chi^{2}/n_{DoF} = %4.1f/%d",chi2,nFullBins - nFitPar); if (chi2 < 1000.) t->DrawLatex(0.80,0.86,fileToSave); // sprintf(fileToSave,"figs/fitPTOverMCJLST_%s%d_%dTeV_%s.pdf",nameSample[whichtype].c_str(),mass,LHCsqrts,systString.c_str()); sprintf(fileToSave,"newfigs/fitPTOverMCJLST_%s%d_%dTeV_%s.pdf",nameSample[whichtype].c_str(),mass,LHCsqrts,systString.c_str()); can.SaveAs(fileToSave); }
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(); }
void mKKfit(string filename, string branchname, string cuts, string weight, string xtitle, string unit, string plotname, double xlow, double xup, double yup, int nbins, bool convolve, bool phsp, bool fitnonres, bool fitfzero, bool fitftwop) { /*Physics parameters**********************************************************/ // Define in MeV double mBs = 5366.77; // TODO: turn this into a map (or one map per dimension: energy, inverse energy and unitless) and do the MeV to GeV conversion at the top double mfzero = 990;//939.9; double gpipi = 199; double gKK = gpipi*3; double mftwop = 1522.2; double Gftwop = 84; double mphi = 1019.461; double Gphi = 4.266; double mpi = 139.57018; double mK = 493.677; double BWBFradius = 0.0031; double mKKresolution_lo = 0.2; double mKKresolution_hi = 0.6; double mKKresolution_MC = 0.4; /*Input***********************************************************************/ TFile* file = TFile::Open(filename.c_str()); TTree* tree = GetTree(file,cuts); /*Fit the resolution**********************************************************/ using namespace RooFit; /*Do convolved fit************************************************************/ RooRealVar* m = new RooRealVar(branchname.c_str(),xtitle.c_str(),xlow,xup); cout << "Importing tree" << endl; RooDataSet* data; MassFitter* massfitter = new MassFitter(m); if(weight == "") data = new RooDataSet("data","",RooArgSet(*m),Import(*tree)); else { RooRealVar* w = new RooRealVar(weight.c_str(),"weighting variable",-100,100); data = new RooDataSet("data","",RooArgSet(*m,*w),Import(*tree),WeightVar(*w)); massfitter->SetWeighted(); } RooRealVar* Nnonres = new RooRealVar("N","Number of non-resonant candidates",200,0,1e6); RooRealVar* Nfzero = new RooRealVar("N","Number of f0(980) candidates",150,0,1e6); RooRealVar* Nphi = new RooRealVar("N","Number of phi candidates",3000,0,1e6); RooRealVar* Nftwop = new RooRealVar("N","Number of f2'(1525) candidates",200,0,1e6); /*Phase space function********************************************************/ if(phsp) { Component* phasespace = massfitter->SetWeightFunction("Three Body Phase Space"); if(unit.find("GeV")!=string::npos) { phasespace->SetRange("M",mBs*1e-3,mBs*1e-3); phasespace->FixValue("M",mBs*1e-3); phasespace->SetRange("m1",mK*1e-3,mK*1e-3); phasespace->FixValue("m1",mK*1e-3); phasespace->SetRange("m2",mK*1e-3,mK*1e-3); phasespace->FixValue("m2",mK*1e-3); phasespace->SetRange("m3",mphi*1e-3,mphi*1e-3); phasespace->FixValue("m3",mphi*1e-3); } else { phasespace->SetRange("M",mBs,mBs); phasespace->FixValue("M",mBs); phasespace->SetRange("m1",mK,mK); phasespace->FixValue("m1",mK); phasespace->SetRange("m2",mK,mK); phasespace->FixValue("m2",mK); phasespace->SetRange("m3",mphi,mphi); phasespace->FixValue("m3",mphi); } } /*Non-resonant kaon pairs*****************************************************/ Component* nonres; if(fitnonres) { if(!phsp) { nonres = massfitter->AddComponent("nonres","Three Body Phase Space",Nnonres); if(unit.find("GeV")!=string::npos) { nonres->SetRange("M",mBs*1e-3,mBs*1e-3); nonres->FixValue("M",mBs*1e-3); nonres->SetRange("m1",mK*1e-3,mK*1e-3); nonres->FixValue("m1",mK*1e-3); nonres->SetRange("m2",mK*1e-3,mK*1e-3); nonres->FixValue("m2",mK*1e-3); nonres->SetRange("m3",mphi*1e-3,mphi*1e-3); nonres->FixValue("m3",mphi*1e-3); } else { nonres->SetRange("M",mBs,mBs); nonres->FixValue("M",mBs); nonres->SetRange("m1",mK,mK); nonres->FixValue("m1",mK); nonres->SetRange("m2",mK,mK); nonres->FixValue("m2",mK); nonres->SetRange("m3",mphi,mphi); nonres->FixValue("m3",mphi); } } else { nonres = massfitter->AddComponent("nonres","Flat",Nnonres); } nonres->SetColour(kCyan+1); nonres->SetStyle(kDotted); } /*f0(980)*********************************************************************/ Component* fzero; if(fitfzero) { fzero = massfitter->AddComponent("fzero","Flatte",Nfzero); fzero->SetColour(kGreen+1); fzero->SetStyle(9); // fzero->FixValue("spin",0); if(unit.find("GeV")!=string::npos) { fzero->SetRange("mean",mfzero*1e-3,mfzero*1e-3); fzero->FixValue("mean",mfzero*1e-3); fzero->SetRange("gpipi",gpipi*1e-3,gpipi*1e-3); fzero->FixValue("gpipi",gpipi*1e-3); fzero->SetRange("mpi",mpi*1e-3,mpi*1e-3); fzero->FixValue("mpi",mpi*1e-3); fzero->SetRange("gKK",gKK*1e-3,gKK*1e-3); fzero->FixValue("gKK",gKK*1e-3); fzero->SetRange("mK",mK*1e-3,mK*1e-3); fzero->FixValue("mK",mK*1e-3); } else { fzero->SetRange("mean",mfzero,mfzero); fzero->FixValue("mean",mfzero); fzero->SetRange("gpipi",gpipi,gpipi); fzero->FixValue("gpipi",gpipi); fzero->SetRange("mpi",mpi,mpi); fzero->FixValue("mpi",mpi); fzero->SetRange("gKK",gKK,gKK); fzero->FixValue("gKK",gKK); fzero->SetRange("mK",mK,mK); fzero->FixValue("mK",mK); } } /*phi(1020)*******************************************************************/ Component* phi; if(convolve) { phi = massfitter->AddComponent("phi","RBW(X)Gauss",Nphi); } else { phi = massfitter->AddComponent("phi","Rel Breit-Wigner",Nphi); } phi->SetColour(kMagenta+1); phi->SetStyle(9); phi->FixValue("spin",1); if(unit.find("GeV")!=string::npos) { phi->SetRange("mean",mphi*1e-3,mphi*1e-3); phi->FixValue("mean",mphi*1e-3); phi->SetRange("width",Gphi*1e-3,Gphi*1e-3); phi->FixValue("width",Gphi*1e-3); phi->SetRange("radius",BWBFradius*1e3,BWBFradius*1e3); phi->FixValue("radius",BWBFradius*1e3); phi->SetRange("mK",mK*1e-3,mK*1e-3); phi->FixValue("mK",mK*1e-3); if(convolve) { phi->SetRange("sigma1",mKKresolution_lo*1e-3,mKKresolution_hi*1e-3); phi->FixValue("sigma1",mKKresolution_MC*1e-3); } } else { phi->SetRange("mean",mphi,mphi); phi->FixValue("mean",mphi); phi->SetRange("width",Gphi,Gphi); phi->FixValue("width",Gphi); phi->SetRange("radius",BWBFradius,BWBFradius); phi->FixValue("radius",BWBFradius); phi->SetRange("mK",mK,mK); phi->FixValue("mK",mK); if(convolve) { phi->SetRange("sigma1",mKKresolution_lo,mKKresolution_hi); phi->FixValue("sigma1",mKKresolution_MC); } } /*f2'(1525)*******************************************************************/ Component* ftwop; if(fitftwop) { ftwop = massfitter->AddComponent("ftwop","Rel Breit-Wigner",Nftwop); ftwop->FixValue("spin",2); ftwop->SetColour(kOrange+2); ftwop->SetStyle(9); if(unit.find("GeV")!=string::npos) { ftwop->SetRange("mean",mftwop*1e-3,mftwop*1e-3); ftwop->FixValue("mean",mftwop*1e-3); ftwop->SetRange("width",Gftwop*1e-3,Gftwop*1e-3); ftwop->FixValue("width",Gftwop*1e-3); ftwop->SetRange("radius",BWBFradius*1e3,BWBFradius*1e3); ftwop->FixValue("radius",BWBFradius*1e3); ftwop->SetRange("mK",mK*1e-3,mK*1e-3); ftwop->FixValue("mK",mK*1e-3); } else { ftwop->SetRange("mean",mftwop,mftwop); ftwop->FixValue("mean",mftwop); ftwop->SetRange("width",Gftwop,Gftwop); ftwop->FixValue("width",Gftwop); ftwop->SetRange("radius",BWBFradius,BWBFradius); ftwop->FixValue("radius",BWBFradius); ftwop->SetRange("mK",mK,mK); ftwop->FixValue("mK",mK); } } /*Do the fit******************************************************************/ massfitter->Fit(data); RooPlot* frame = m->frame(); cout << "Plotting" << endl; data->plotOn(frame,(Binning(nbins))); massfitter->Plot(frame); plotmaker fullplot(frame); RooHist* pullhist = frame->pullHist(); RooPlot* pullframe = m->frame(Title("Pull")); pullframe->addPlotable(pullhist,"B"); fullplot.SetPullPlot(pullframe); fullplot.SetTitle(xtitle, unit); if(yup>0) frame->SetMaximum(yup); frame->SetMinimum(0); TCanvas* can = fullplot.Draw(); stringstream ytitle; ytitle << "#font[132]{}Candidates / (" << (xup-xlow)/nbins << " " << unit << ")"; frame->GetYaxis()->SetTitle(ytitle.str().c_str()); can->SaveAs((plotname+".pdf").c_str()); double xsplit = 1060; double lowbinwidth = 1; if(unit.find("GeV")!=string::npos) { xsplit*=1e-3; lowbinwidth*=1e-3; } if((xup-xlow) > 2*(xsplit-xlow)) { // Make low range bins a certain width int nbins_lo = (xsplit-xlow)/lowbinwidth; // Get the same bin width for the high range int nbins_hi = nbins * (xup-xsplit)/(xup-xlow); // Make the frames RooPlot* frame_lo = m->frame(Range(xlow,xsplit),Bins(nbins_lo)); RooPlot* frame_hi = m->frame(Range(xsplit,xup),Bins(nbins_hi)); // Plot the data data->plotOn(frame_lo); data->plotOn(frame_hi); // Plot the PDFs massfitter->Plot(frame_lo); massfitter->Plot(frame_hi); // Set the y-axis ranges frame_lo->SetMaximum(yup); frame_lo->SetMinimum(0); frame_hi->SetMinimum(0); // Make the pull plots RooHist* pullhist_lo = frame_lo->pullHist(); RooHist* pullhist_hi = frame_hi->pullHist(); RooPlot* pullframe_lo = m->frame(Title("Pull"),Range(xlow,xsplit)); RooPlot* pullframe_hi = m->frame(Title("Pull"),Range(xsplit,xup)); pullframe_lo->addPlotable(pullhist_lo,"B"); pullframe_hi->addPlotable(pullhist_hi,"B"); // Draw the low-mass plot plotmaker lowplot(frame_lo); lowplot.SetPullPlot(pullframe_lo); lowplot.SetTitle(xtitle, unit); can = lowplot.Draw(); stringstream ytitle_lo; ytitle_lo << "#font[132]{}Candidates / (" << lowbinwidth << " " << unit << ")"; frame_lo->GetYaxis()->SetTitle(ytitle_lo.str().c_str()); can->SaveAs((plotname+"_low_range.pdf").c_str()); // Draw the high-mass plot plotmaker highplot(frame_hi); highplot.SetPullPlot(pullframe_hi); highplot.SetTitle(xtitle, unit); can = highplot.Draw(); frame_hi->GetYaxis()->SetTitle(ytitle.str().c_str()); can->SaveAs((plotname+"_high_range.pdf").c_str()); } }