Logo ROOT  
Reference Guide
RooLagrangianMorphFunc.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * *
4 * authors: *
5 * Lydia Brenner (lbrenner@cern.ch), Carsten Burgard (cburgard@cern.ch) *
6 * Katharina Ecker (kecker@cern.ch), Adam Kaluza (akaluza@cern.ch) *
7 * Copyright (c) 2000-2007, Regents of the University of California *
8 * and Stanford University. All rights reserved. *
9 * *
10 * Redistribution and use in source and binary forms, *
11 * with or without modification, are permitted according to the terms *
12 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
13 *****************************************************************************/
14
15////////////////////////////////////////////////////////////////////////////////////////////////
16//
17// RooLagrangianMorph
18//
19// The RooLagrangianMorphFunc is a type of RooAbsReal that allows to morph
20// different input EFT samples to some arbitrary output EFT
21// sample, as long as the desired set of output parameters lie
22// within the realm spanned by the input samples. More
23// specifically, it expects as an input a TFile (or TDirectory)
24// with the following layout:
25//
26// TDirectory
27// |-sample1
28// | |-param_card // TH1 EFT parameter values of sample1
29// | | histogram1 // TH1 of some physics distribution
30// | |-subfolder1 // a subfolder (optional)
31// | | |-histogram2 // TH1 of some physics distribution
32// | | |-....
33// |-sample2
34// | |-param_card // TH1 of EFT parameter values of sample2
35// | | histogram1 // TH1 of some physics distribution
36// | |-subfolder1 // same folder structure as before
37// | | |-histogram2 // TH1 of some physics distribution
38// | | |-....
39// |-sampleN
40// The RooLagrangianMorphFunc operates on this structure, extracts data
41// and meta-data and produces a morphing result as a RooRealSumFunc
42// consisting of the input histograms with appropriate prefactors.
43//
44// The histograms to be morphed can be accessed via their paths in
45// the respective sample, e.g. using
46// "histogram"
47// or "subfolder1/histogram1"
48// or "some/deep/path/to/some/subfolder/histname"
49//
50////////////////////////////////////////////////////////////////////////////////////////////////
51
52#ifndef ROO_LAGRANGIAN_MORPH
53#define ROO_LAGRANGIAN_MORPH
54
55#include "Floats.h"
56#include "RooAbsArg.h"
57#include "RooAbsReal.h"
58#include "RooArgList.h"
59#include "RooRatio.h"
60#include "RooRealSumFunc.h"
61#include "RooRealSumPdf.h"
62#include "RooSetProxy.h"
63#include "RooWrapperPdf.h"
64#include "TMatrixD.h"
65
66class RooWorkspace;
68class RooProduct;
69class RooRealVar;
70class TPair;
71class TFolder;
73
74#include <fstream>
75#include <iostream>
76#include <string>
77#include <vector>
78
80
81public:
82 typedef std::map<const std::string, double> ParamSet;
83 typedef std::map<const std::string, int> FlagSet;
84 typedef std::map<const std::string, ParamSet> ParamMap;
85 typedef std::map<const std::string, FlagSet> FlagMap;
86
87 struct Config {
88
89 std::string observableName;
90 std::string fileName;
93 std::vector<std::string> folderNames;
98 std::vector<RooArgList *> vertices;
99 std::vector<RooArgList *> nonInterfering;
101 };
102
104 RooLagrangianMorphFunc(const char *name, const char *title,
105 const Config &config);
107 const char *newName);
108
109 virtual ~RooLagrangianMorphFunc();
110
111 virtual std::list<Double_t> *binBoundaries(RooAbsRealLValue & /*obs*/,
112 Double_t /*xlo*/,
113 Double_t /*xhi*/) const override;
114 virtual std::list<Double_t> *
115 plotSamplingHint(RooAbsRealLValue & /*obs*/, Double_t /*xlo*/,
116 Double_t /*xhi*/) const override;
117 virtual Bool_t isBinnedDistribution(const RooArgSet &obs) const override;
118 virtual Double_t evaluate() const override;
119 virtual TObject *clone(const char *newname) const override;
120 virtual Double_t getValV(const RooArgSet *set = 0) const override;
121
122 virtual Bool_t checkObservables(const RooArgSet *nset) const override;
123 virtual Bool_t forceAnalyticalInt(const RooAbsArg &arg) const override;
124 virtual Int_t
126 const RooArgSet *normSet,
127 const char *rangeName = 0) const override;
128 virtual Double_t
129 analyticalIntegralWN(Int_t code, const RooArgSet *normSet,
130 const char *rangeName = 0) const override;
131 virtual void printMetaArgs(std::ostream &os) const override;
132 virtual RooAbsArg::CacheMode canNodeBeCached() const override;
133 virtual void setCacheAndTrackHints(RooArgSet &) override;
134
135 void insert(RooWorkspace *ws);
136
137 void setParameters(const char *foldername);
138 void setParameters(TH1 *paramhist);
139 void setParameter(const char *name, double value);
140 void setFlag(const char *name, double value);
141 void setParameters(const ParamSet &params);
142 void setParameters(const RooArgList *list);
143 double getParameterValue(const char *name) const;
144 RooRealVar *getParameter(const char *name) const;
145 RooRealVar *getFlag(const char *name) const;
146 bool hasParameter(const char *paramname) const;
147 bool isParameterUsed(const char *paramname) const;
148 bool isParameterConstant(const char *paramname) const;
149 void setParameterConstant(const char *paramname, bool constant) const;
150 void setParameter(const char *name, double value, double min, double max);
151 void setParameter(const char *name, double value, double min, double max,
152 double error);
153 void randomizeParameters(double z);
154 const RooArgSet *getParameterSet() const;
155 ParamSet getMorphParameters(const char *foldername) const;
157
159
160 int nParameters() const;
161 int nPolynomials() const;
162
163 bool isCouplingUsed(const char *couplname);
164 const RooArgList *getCouplingSet() const;
165 ParamSet getCouplings() const;
166
167 // virtual Bool_t IsAllowNegativeYields() const { return
168 // this->_config.IsAllowNegativeYields(); }
169 TMatrixD getMatrix() const;
171 double getCondition() const;
172
173 RooRealVar *getObservable() const;
174 RooRealVar *getBinWidth() const;
175
176 void printEvaluation() const;
177 void printCouplings() const;
178 void printFlags() const;
179 void printPhysics() const;
180
181 RooProduct *getSumElement(const char *name) const;
182
183 std::vector<std::string> getSamples() const;
184
185 double expectedUncertainty() const;
186 TH1 *createTH1(const std::string &name);
187 TH1 *createTH1(const std::string &name, bool correlateErrors);
188
189protected:
190 class CacheElem;
191 void init();
192 void printAuthors() const;
193 void setup(bool ownParams = true);
194 bool _ownParameters = false;
195
196 /* wip
197 void disableInterference(const std::vector<const char*>& nonInterfering) ;
198 void disableInterferences(const std::vector<std::vector<const char*> >&
199 nonInterfering) ;
200 */
201
202 mutable RooObjCacheManager _cacheMgr; //! The cache manager
203
204 void addFolders(const RooArgList &folders);
205
206 bool hasCache() const;
208 void updateSampleWeights();
209
210 RooRealVar *setupObservable(const char *obsname, TClass *mode,
211 TObject *inputExample);
212
213public:
214 /// length of floating point digits precision supported by implementation.
215 static constexpr double implementedPrecision = SuperFloatPrecision::digits10;
216 void importToWorkspace(RooWorkspace *ws, const RooAbsReal *object);
218
219 void writeMatrixToFile(const TMatrixD &matrix, const char *fname);
220 void writeMatrixToStream(const TMatrixD &matrix, std::ostream &stream);
221 TMatrixD readMatrixFromFile(const char *fname);
222 TMatrixD readMatrixFromStream(std::istream &stream);
223
224 // RooDataHist* makeDataHistogram(TH1* hist, RooRealVar* observable, const
225 // char* histname = NULL) ; void setDataHistogram(TH1* hist, RooRealVar*
226 // observable, RooDataHist* dh) ; void printDataHistogram(RooDataHist* hist,
227 // RooRealVar* obs) ;
228
229 int countSamples(std::vector<RooArgList *> &vertices);
230 int countSamples(int nprod, int ndec, int nboth);
231
232 TPair *makeCrosssectionContainer(double xs, double unc);
233 std::map<std::string, std::string>
234 createWeightStrings(const ParamMap &inputs,
235 const std::vector<std::vector<std::string>> &vertices);
236 std::map<std::string, std::string>
237 createWeightStrings(const ParamMap &inputs,
238 const std::vector<RooArgList *> &vertices,
239 RooArgList &couplings);
240 std::map<std::string, std::string> createWeightStrings(
241 const ParamMap &inputs, const std::vector<RooArgList *> &vertices,
242 RooArgList &couplings, const FlagMap &flagValues, const RooArgList &flags,
243 const std::vector<RooArgList *> &nonInterfering);
244 RooArgSet createWeights(const ParamMap &inputs,
245 const std::vector<RooArgList *> &vertices,
246 RooArgList &couplings, const FlagMap &inputFlags,
247 const RooArgList &flags,
248 const std::vector<RooArgList *> &nonInterfering);
249 RooArgSet createWeights(const ParamMap &inputs,
250 const std::vector<RooArgList *> &vertices,
251 RooArgList &couplings);
252
253 bool updateCoefficients();
254 bool useCoefficients(const TMatrixD &inverse);
255 bool useCoefficients(const char *filename);
256 bool writeCoefficients(const char *filename);
257
258 int countContributingFormulas() const;
259 RooAbsReal *getSampleWeight(const char *name);
260 void printParameters(const char *samplename) const;
261 void printParameters() const;
262 void printSamples() const;
263 void printSampleWeights() const;
264 void printWeights() const;
265
266 void setScale(double val);
267 double getScale();
268
269 int nSamples() const {return this->_config.folderNames.size(); }
270
271 RooRealSumFunc *getFunc() const;
272 std::unique_ptr<RooWrapperPdf> createPdf() const;
273
275 Double_t expectedEvents(const RooArgSet *nset) const;
276 Double_t expectedEvents(const RooArgSet &nset) const;
277 Double_t expectedEvents() const;
278 Bool_t selfNormalized() const { return true; }
279
282
283 static std::unique_ptr<RooRatio> makeRatio(const char *name,
284 const char *title, RooArgList &nr,
285 RooArgList &dr);
286
287protected:
288 double _scale = 1;
289 std::map<std::string, int> _sampleMap;
296 std::vector<std::vector<RooListProxy *>> _diagrams;
297 mutable const RooArgSet *_curNormSet; //!
298 std::vector<RooListProxy *> _nonInterfering;
299
301};
302
303#endif
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:45
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:79
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:35
Class RooLagrangianMorphing is a implementation of the method of Effective Lagrangian Morphing,...
static constexpr double implementedPrecision
length of floating point digits precision supported by implementation.
bool isParameterConstant(const char *paramname) const
return true if the parameter with the given name is set constant, false otherwise
TPair * makeCrosssectionContainer(double xs, double unc)
create TPair containers of the type expected by the RooLagrangianMorph
int nPolynomials() const
return the number of samples in this morphing function
void setParameter(const char *name, double value)
set one parameter to a specific value
ParamSet getMorphParameters() const
retrieve the parameter set
RooProduct * getSumElement(const char *name) const
return the RooProduct that is the element of the RooRealSumPdfi corresponding to the given sample nam...
void insert(RooWorkspace *ws)
insert this object into a workspace
RooRealVar * getBinWidth() const
retrieve the histogram observable
void writeMatrixToFile(const TMatrixD &matrix, const char *fname)
write a matrix to a file
RooRealVar * getParameter(const char *name) const
retrieve the RooRealVar object incorporating the parameter with the given name
bool useCoefficients(const TMatrixD &inverse)
setup the morphing function with a predefined inverse matrix call this function before any other afte...
const RooArgSet * getParameterSet() const
get the set of parameters
std::map< const std::string, int > FlagSet
TMatrixD readMatrixFromStream(std::istream &stream)
read a matrix from a stream
std::vector< std::string > getSamples() const
return the vector of sample names, used to build the morph func
int countSamples(std::vector< RooArgList * > &vertices)
calculate the number of samples needed to morph a certain physics process usage: countSamples ( { Roo...
virtual Double_t analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const override
Retrieve the matrix of coefficients.
virtual void setCacheAndTrackHints(RooArgSet &) override
Retrieve the matrix of coefficients.
virtual Double_t getValV(const RooArgSet *set=0) const override
call getVal on the internal function
ParamSet getCouplings() const
retrieve a set of couplings (-?-)
void printSampleWeights() const
print the current sample weights
std::map< const std::string, double > ParamSet
RooArgSet createWeights(const ParamMap &inputs, const std::vector< RooArgList * > &vertices, RooArgList &couplings, const FlagMap &inputFlags, const RooArgList &flags, const std::vector< RooArgList * > &nonInterfering)
create only the weight formulas. static function for external usage.
RooLagrangianMorphFunc * getLinear() const
virtual Double_t evaluate() const override
call getVal on the internal function
void writeMatrixToStream(const TMatrixD &matrix, std::ostream &stream)
write a matrix to a stream
void addFolders(const RooArgList &folders)
The cache manager.
std::map< const std::string, ParamSet > ParamMap
bool updateCoefficients()
retrive the new physics objects and update the weights in the morphing function
RooRealVar * getObservable() const
retrieve the histogram observable
int countContributingFormulas() const
count the number of formulas that correspond to the current parameter set
RooRealVar * getFlag(const char *name) const
retrieve the RooRealVar object incorporating the flag with the given name
void randomizeParameters(double z)
randomize the parameters a bit useful to test and debug fitting
virtual ~RooLagrangianMorphFunc()
default destructor
bool isCouplingUsed(const char *couplname)
check if there is any morphing power provided for the given coupling morphing power is provided as so...
void readParameters(TDirectory *f)
read the parameters from the input file
double getScale()
get energy scale of the EFT expansion
std::vector< RooListProxy * > _nonInterfering
virtual std::list< Double_t > * plotSamplingHint(RooAbsRealLValue &, Double_t, Double_t) const override
retrieve the sample Hint
virtual Bool_t checkObservables(const RooArgSet *nset) const override
check if observable exists in the RooArgSet (-?-)
double getCondition() const
Retrieve the condition of the coefficient matrix.
TMatrixD getMatrix() const
Retrieve the matrix of coefficients.
void printWeights() const
print the current sample weights
void printCouplings() const
print a set of couplings
TMatrixD readMatrixFromFile(const char *fname)
read a matrix from a text file
void printParameters() const
print the parameters and their current values
void printAuthors() const
print the authors information
void printPhysics() const
print the current physics values
virtual std::list< Double_t > * binBoundaries(RooAbsRealLValue &, Double_t, Double_t) const override
retrieve the list of bin boundaries
static std::unique_ptr< RooRatio > makeRatio(const char *name, const char *title, RooArgList &nr, RooArgList &dr)
Return the RooRatio form of products and denominators of morphing functions.
void setFlag(const char *name, double value)
set one flag to a specific value
TH1 * createTH1(const std::string &name)
retrieve a histogram output of the current morphing settings
double expectedUncertainty() const
return the expected uncertainty for the current parameter set
int nParameters() const
return the number of parameters in this morphing function
RooLagrangianMorphFunc::CacheElem * getCache(const RooArgSet *nset) const
retrieve the cache object
bool hasParameter(const char *paramname) const
check if a parameter of the given name is contained in the list of known parameters
virtual Bool_t isBinnedDistribution(const RooArgSet &obs) const override
check if this PDF is a binned distribution in the given observable
bool hasCache() const
return true if a cache object is present, false otherwise
void printFlags() const
print the flags and their current values
void setScale(double val)
set energy scale of the EFT expansion
Double_t expectedEvents() const
return the number of expected events for the current parameter set
TMatrixD getInvertedMatrix() const
Retrieve the matrix of coefficients after inversion.
virtual RooAbsArg::CacheMode canNodeBeCached() const override
Retrieve the matrix of coefficients.
void updateSampleWeights()
update sample weight (-?-)
void setParameters(const char *foldername)
set the morphing parameters to those supplied in the sample with the given name
bool isParameterUsed(const char *paramname) const
check if there is any morphing power provided for the given parameter morphing power is provided as s...
RooAbsPdf::ExtendMode extendMode() const
get a standalone clone of the func that does not depend on this object
std::map< const std::string, FlagSet > FlagMap
void setParameterConstant(const char *paramname, bool constant) const
call setConstant with the boolean argument provided on the parameter with the given name
void printSamples() const
print all the known samples to the console
double getParameterValue(const char *name) const
set one parameter to a specific value
void setup(bool ownParams=true)
setup this instance with the given set of operators and vertices if own=true, the class will own the ...
virtual void printMetaArgs(std::ostream &os) const override
Retrieve the matrix of coefficients.
std::unique_ptr< RooWrapperPdf > createPdf() const
(currently similar to cloning the Pdf
RooAbsReal * getSampleWeight(const char *name)
retrieve the weight (prefactor) of a sample with the given name
std::map< std::string, std::string > createWeightStrings(const ParamMap &inputs, const std::vector< std::vector< std::string > > &vertices)
create only the weight formulas. static function for external usage.
std::vector< std::vector< RooListProxy * > > _diagrams
void importToWorkspace(RooWorkspace *ws, const RooAbsReal *object)
insert an object into a workspace (wrapper for RooWorkspace::import)
std::map< std::string, int > _sampleMap
virtual TObject * clone(const char *newname) const override
cloning method
RooRealVar * setupObservable(const char *obsname, TClass *mode, TObject *inputExample)
setup observable, recycle existing observable if defined
const RooArgList * getCouplingSet() const
get the set of couplings
virtual Bool_t forceAnalyticalInt(const RooAbsArg &arg) const override
Force analytical integration for the given observable.
RooRealSumFunc * getFunc() const
get the func
void printEvaluation() const
print the contributing samples and their respective weights
bool writeCoefficients(const char *filename)
write the inverse matrix to a file
void collectInputs(TDirectory *f)
retrieve the physics inputs
virtual Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=0) const override
Retrieve the mat.
RooListProxy is the concrete proxy for RooArgList objects.
Definition: RooListProxy.h:24
Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement> and specia...
A histogram function that assigns scale parameters to every bin.
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:29
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
RooSetProxy is the concrete proxy for RooArgSet objects.
Definition: RooSetProxy.h:23
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
Describe directory structure in memory.
Definition: TDirectory.h:45
A TFolder object is a collection of objects and folders.
Definition: TFolder.h:30
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
Mother of all ROOT objects.
Definition: TObject.h:37
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:102
std::vector< RooArgList * > nonInterfering
std::vector< std::string > folderNames
std::vector< RooArgList * > vertices
void ws()
Definition: ws.C:66