Logo ROOT  
Reference Guide
No Matches
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Morphing effective field theory distributions with RooLagrangianMorphFunc
5/// A morphing function as a function of one coefficient is setup and can be used
6/// to obtain the distribution for any value of the coefficient.
8/// \macro_image
9/// \macro_code
10/// \macro_output
12/// \date January 2022
13/// \author Rahul Balasubramanian
15#include <RooAbsCollection.h>
16#include <RooDataHist.h>
17#include <RooDataSet.h>
19#include <RooPlot.h>
20#include <RooRealVar.h>
22#include <TCanvas.h>
23#include <TColor.h>
24#include <TFile.h>
25#include <TFolder.h>
26#include <TH1.h>
27#include <TLegend.h>
28#include <TStyle.h>
30using namespace RooFit;
34 // C r e a t e v a r i a b l e s f o r
35 // m o r p h i n g f u n c t i o n
36 // ---------------------------------------------
38 std::string observablename = "pTV";
40 // Setup observable that is morphed
41 RooRealVar obsvar(observablename.c_str(), "p_{T}^{V}", 10, 600);
43 // Setup two couplings that enters the morphing function
44 // kSM -> SM coupling set to constant (1)
45 // cHq3 -> EFT parameter with NewPhysics attribute set to true
46 RooRealVar kSM("kSM", "sm modifier", 1.0);
47 RooRealVar cHq3("cHq3", "EFT modifier", 0.0, 1.0);
48 cHq3.setAttribute("NewPhysics", true);
50 // I n p u t s n e e d e d f o r c o n f i g
51 // ---------------------------------------------
52 std::string infilename = std::string(gROOT->GetTutorialDir()) + "/roofit/input_histos_rf_lagrangianmorph.root";
53 std::vector<std::string> samplelist = {"SM_NPsq0", "cHq3_NPsq1", "cHq3_NPsq2"};
55 // S e t u p C o n f i g
56 // ---------------------------------------------
58 config.fileName = infilename;
59 config.observableName = observablename;
60 config.folderNames = samplelist;
61 config.couplings.add(cHq3);
62 config.couplings.add(kSM);
64 // C r e a t e m o r p h i n g f u n c t i o n
65 // ---------------------------------------------
66 RooLagrangianMorphFunc morphfunc("morphfunc", "morphed dist. of pTV", config);
68 // G e t m o r p h e d d i s t r i b u t i o n f o r
69 // d i f f e r e n t c H q 3
70 // ---------------------------------------------
71 morphfunc.setParameter("cHq3", 0.01);
72 auto morph_hist_0p01 = morphfunc.createTH1("morph_cHq3=0.01");
73 morphfunc.setParameter("cHq3", 0.25);
74 auto morph_hist_0p25 = morphfunc.createTH1("morph_cHq3=0.25");
75 morphfunc.setParameter("cHq3", 0.5);
76 auto morph_hist_0p5 = morphfunc.createTH1("morph_cHq3=0.5");
77 RooDataHist morph_datahist_0p01("morph_dh_cHq3=0.01", "", {obsvar}, morph_hist_0p01);
78 RooDataHist morph_datahist_0p25("morph_dh_cHq3=0.25", "", {obsvar}, morph_hist_0p25);
79 RooDataHist morph_datahist_0p5("morph_dh_cHq3=0.5", "", {obsvar}, morph_hist_0p5);
81 // E x t r a c t i n p u t t e m p l a t e s
82 // f o r p l o t t i n g
83 // ---------------------------------------------
84 TFile *file = new TFile(infilename.c_str(), "READ");
85 TFolder *folder = 0;
86 file->GetObject(samplelist[0].c_str(), folder);
87 TH1 *input_hist0 = dynamic_cast<TH1 *>(folder->FindObject(observablename.c_str()));
88 input_hist0->SetDirectory(NULL);
89 file->GetObject(samplelist[1].c_str(), folder);
90 TH1 *input_hist1 = dynamic_cast<TH1 *>(folder->FindObject(observablename.c_str()));
91 input_hist1->SetDirectory(NULL);
92 file->GetObject(samplelist[2].c_str(), folder);
93 TH1 *input_hist2 = dynamic_cast<TH1 *>(folder->FindObject(observablename.c_str()));
94 input_hist2->SetDirectory(NULL);
95 file->Close();
97 RooDataHist input_dh0(samplelist[0], "", {obsvar}, input_hist0);
98 RooDataHist input_dh1(samplelist[1], "", {obsvar}, input_hist1);
99 RooDataHist input_dh2(samplelist[2], "", {obsvar}, input_hist2);
101 auto frame0 = obsvar.frame(Title("Input templates for p_{T}^{V}"));
102 input_dh0.plotOn(frame0, Name(samplelist[0].c_str()), LineColor(kBlack), MarkerColor(kBlack), MarkerSize(1));
103 input_dh1.plotOn(frame0, Name(samplelist[1].c_str()), LineColor(kRed), MarkerColor(kRed), MarkerSize(1));
104 input_dh2.plotOn(frame0, Name(samplelist[2].c_str()), LineColor(kBlue), MarkerColor(kBlue), MarkerSize(1));
106 // P l o t m o r p h e d d i s t r i b u t i o n f o r
107 // d i f f e r e n t c H q 3
108 // ---------------------------------------------
109 auto frame1 = obsvar.frame(Title("Morphed templates for selected values"));
110 morph_datahist_0p01.plotOn(frame1, Name("morph_dh_cHq3=0.01"), DrawOption("C"), LineColor(kGreen),
112 morph_datahist_0p25.plotOn(frame1, Name("morph_dh_cHq3=0.25"), DrawOption("C"), LineColor(kGreen + 1),
114 morph_datahist_0p5.plotOn(frame1, Name("morph_dh_cHq3=0.5"), DrawOption("C"), LineColor(kGreen + 2),
117 // C r e a t e w r a p p e d p d f t o g e n e r a t e
118 // 2D d a t a s e t o f c H q 3 a s a f u n c t i o n o f
119 // o b s e r v a b l e
120 // ---------------------------------------------
122 RooWrapperPdf model("wrap_pdf", "wrap_pdf", morphfunc);
123 std::unique_ptr<RooDataSet> data{model.generate({cHq3, obsvar}, 1000000)};
124 TH1 *hh_data = data->createHistogram("pTV vs cHq3", obsvar, Binning(20), YVar(cHq3, Binning(50)));
125 hh_data->SetTitle("Morphing prediction");
127 // D r a w p l o t s o n c a n v a s
128 // ---------------------------------------------
129 TCanvas *c1 = new TCanvas("fig3", "fig3", 1200, 400);
130 c1->Divide(3, 1);
132 c1->cd(1);
133 gPad->SetLeftMargin(0.15);
134 gPad->SetRightMargin(0.05);
136 frame0->Draw();
137 TLegend *leg1 = new TLegend(0.55, 0.65, 0.94, 0.87);
138 leg1->SetTextSize(0.04);
139 leg1->SetFillColor(kWhite);
140 leg1->SetLineColor(kWhite);
141 leg1->AddEntry("SM_NPsq0", "SM", "LP");
142 leg1->AddEntry((TObject *)0, "", "");
143 leg1->AddEntry("cHq3_NPsq1", "c_{Hq^(3)}=1.0 at #Lambda^{-2}", "LP");
144 leg1->AddEntry((TObject *)0, "", "");
145 leg1->AddEntry("cHq3_NPsq2", "c_{Hq^(3)}=1.0 at #Lambda^{-4}", "LP");
146 leg1->Draw();
148 c1->cd(2);
149 gPad->SetLeftMargin(0.15);
150 gPad->SetRightMargin(0.05);
152 frame1->Draw();
154 TLegend *leg2 = new TLegend(0.60, 0.65, 0.94, 0.87);
155 leg2->SetTextSize(0.04);
156 leg2->SetFillColor(kWhite);
157 leg2->SetLineColor(kWhite);
158 leg2->AddEntry("morph_dh_cHq3=0.01", "c_{Hq^{(3)}}=0.01", "L");
159 leg2->AddEntry((TObject *)0, "", "");
160 leg2->AddEntry("morph_dh_cHq3=0.25", "c_{Hq^{(3)}}=0.25", "L");
161 leg2->AddEntry((TObject *)0, "", "");
162 leg2->AddEntry("morph_dh_cHq3=0.5", "c_{Hq^{(3)}}=0.5", "L");
163 leg2->AddEntry((TObject *)0, "", "");
164 leg2->Draw();
166 c1->cd(3);
167 gPad->SetLeftMargin(0.12);
168 gPad->SetRightMargin(0.18);
171 gStyle->SetOptStat(0);
173 gPad->SetLogz();
174 hh_data->GetYaxis()->SetTitle("c_{Hq^{(3)}}");
175 hh_data->GetYaxis()->SetRangeUser(0, 0.5);
176 hh_data->GetZaxis()->SetTitleOffset(1.8);
177 hh_data->Draw("COLZ");
178 c1->SaveAs("rf711_lagrangianmorph.png");
@ kRed
Definition Rtypes.h:66
@ kBlack
Definition Rtypes.h:65
@ kGreen
Definition Rtypes.h:66
@ kWhite
Definition Rtypes.h:65
@ kBlue
Definition Rtypes.h:66
@ kGreyScale
Definition TColor.h:112
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
#define gPad
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:39
RooPlot * plotOn(RooPlot *frame, PlotOpt o) const override
Back end function to plotting functionality.
Class RooLagrangianMorphing is a implementation of the method of Effective Lagrangian Morphing,...
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:237
Variable that can be changed from the outside.
Definition RooRealVar.h:37
The RooWrapperPdf is a class that can be used to convert a function into a PDF.
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition TAxis.cxx:1077
The Canvas class.
Definition TCanvas.h:23
static void InvertPalette()
Invert the current color palette.
Definition TColor.cxx:3455
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
Definition TFile.h:53
<div class="legacybox"><h2>Legacy Code</h2> TFolder is a legacy interface: there will be no bug fixes...
Definition TFolder.h:30
TObject * FindObject(const char *name) const override
Search object identified by name in the tree of folders inside this folder.
Definition TFolder.cxx:306
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8764
TAxis * GetZaxis()
Definition TH1.h:325
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6667
TAxis * GetYaxis()
Definition TH1.h:324
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3047
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition TLegend.cxx:317
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
Definition TLegend.cxx:422
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
Mother of all ROOT objects.
Definition TObject.h:41
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition TStyle.cxx:1636
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1884
void SetNumberContours(Int_t number=20)
Set the default number of contour levels when drawing 2-d plots.
Definition TStyle.cxx:1496
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg={})
RooCmdArg DataError(Int_t)
RooCmdArg MarkerColor(Color_t color)
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg DrawOption(const char *opt)
RooCmdArg XErrorSize(double width)
RooCmdArg MarkerSize(Size_t size)
RooCmdArg LineColor(Color_t color)
return c1
Definition legend1.C:41
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
Definition file.py:1
const char * Name
Definition TXMLSetup.cxx:67
const char * Title
Definition TXMLSetup.cxx:68
std::vector< std::string > folderNames