-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
RooLagrangianMorphFunc.h
303 lines (257 loc) · 11.4 KB
/
RooLagrangianMorphFunc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*****************************************************************************
* Project: RooFit *
* *
* authors: *
* Lydia Brenner (lbrenner@cern.ch), Carsten Burgard (cburgard@cern.ch) *
* Katharina Ecker (kecker@cern.ch), Adam Kaluza (akaluza@cern.ch) *
* Copyright (c) 2000-2007, Regents of the University of California *
* and Stanford University. All rights reserved. *
* *
* Redistribution and use in source and binary forms, *
* with or without modification, are permitted according to the terms *
* listed in LICENSE (http://roofit.sourceforge.net/license.txt)
*****************************************************************************/
////////////////////////////////////////////////////////////////////////////////////////////////
//
// RooLagrangianMorph
//
// The RooLagrangianMorphFunc is a type of RooAbsReal that allows to morph
// different input EFT samples to some arbitrary output EFT
// sample, as long as the desired set of output parameters lie
// within the realm spanned by the input samples. More
// specifically, it expects as an input a TFile (or TDirectory)
// with the following layout:
//
// TDirectory
// |-sample1
// | |-param_card // TH1 EFT parameter values of sample1
// | | histogram1 // TH1 of some physics distribution
// | |-subfolder1 // a subfolder (optional)
// | | |-histogram2 // TH1 of some physics distribution
// | | |-....
// |-sample2
// | |-param_card // TH1 of EFT parameter values of sample2
// | | histogram1 // TH1 of some physics distribution
// | |-subfolder1 // same folder structure as before
// | | |-histogram2 // TH1 of some physics distribution
// | | |-....
// |-sampleN
// The RooLagrangianMorphFunc operates on this structure, extracts data
// and meta-data and produces a morphing result as a RooRealSumFunc
// consisting of the input histograms with appropriate prefactors.
//
// The histograms to be morphed can be accessed via their paths in
// the respective sample, e.g. using
// "histogram"
// or "subfolder1/histogram1"
// or "some/deep/path/to/some/subfolder/histname"
//
////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef ROO_LAGRANGIAN_MORPH
#define ROO_LAGRANGIAN_MORPH
#include "RooFit/Floats.h"
#include "RooAbsArg.h"
#include "RooAbsReal.h"
#include "RooArgList.h"
#include "RooRatio.h"
#include "RooRealSumFunc.h"
#include "RooRealSumPdf.h"
#include "RooSetProxy.h"
#include "RooWrapperPdf.h"
#include "TMatrixD.h"
class RooWorkspace;
class RooParamHistFunc;
class RooProduct;
class RooRealVar;
class TPair;
class TFolder;
class RooLagrangianMorphFunc;
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
class RooLagrangianMorphFunc : public RooAbsReal {
public:
typedef std::map<const std::string, double> ParamSet;
typedef std::map<const std::string, int> FlagSet;
typedef std::map<const std::string, ParamSet> ParamMap;
typedef std::map<const std::string, FlagSet> FlagMap;
struct Config {
std::string observableName;
std::string fileName;
ParamMap paramCards;
FlagMap flagValues;
std::vector<std::string> folderNames;
RooArgList couplings;
RooArgList decCouplings;
RooArgList prodCouplings;
RooArgList folders;
std::vector<RooArgList *> vertices;
std::vector<RooArgList *> nonInterfering;
bool allowNegativeYields=true;
};
RooLagrangianMorphFunc();
RooLagrangianMorphFunc(const char *name, const char *title,
const Config &config);
RooLagrangianMorphFunc(const RooLagrangianMorphFunc &other,
const char *newName);
virtual ~RooLagrangianMorphFunc();
virtual std::list<Double_t> *binBoundaries(RooAbsRealLValue & /*obs*/,
Double_t /*xlo*/,
Double_t /*xhi*/) const override;
virtual std::list<Double_t> *
plotSamplingHint(RooAbsRealLValue & /*obs*/, Double_t /*xlo*/,
Double_t /*xhi*/) const override;
virtual Bool_t isBinnedDistribution(const RooArgSet &obs) const override;
virtual Double_t evaluate() const override;
virtual TObject *clone(const char *newname) const override;
virtual Double_t getValV(const RooArgSet *set = 0) const override;
virtual Bool_t checkObservables(const RooArgSet *nset) const override;
virtual Bool_t forceAnalyticalInt(const RooAbsArg &arg) const override;
virtual Int_t
getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars,
const RooArgSet *normSet,
const char *rangeName = 0) const override;
virtual Double_t
analyticalIntegralWN(Int_t code, const RooArgSet *normSet,
const char *rangeName = 0) const override;
virtual void printMetaArgs(std::ostream &os) const override;
virtual RooAbsArg::CacheMode canNodeBeCached() const override;
virtual void setCacheAndTrackHints(RooArgSet &) override;
void insert(RooWorkspace *ws);
void setParameters(const char *foldername);
void setParameters(TH1 *paramhist);
void setParameter(const char *name, double value);
void setFlag(const char *name, double value);
void setParameters(const ParamSet ¶ms);
void setParameters(const RooArgList *list);
double getParameterValue(const char *name) const;
RooRealVar *getParameter(const char *name) const;
RooRealVar *getFlag(const char *name) const;
bool hasParameter(const char *paramname) const;
bool isParameterUsed(const char *paramname) const;
bool isParameterConstant(const char *paramname) const;
void setParameterConstant(const char *paramname, bool constant) const;
void setParameter(const char *name, double value, double min, double max);
void setParameter(const char *name, double value, double min, double max,
double error);
void randomizeParameters(double z);
const RooArgSet *getParameterSet() const;
ParamSet getMorphParameters(const char *foldername) const;
ParamSet getMorphParameters() const;
RooLagrangianMorphFunc *getLinear() const;
int nParameters() const;
int nPolynomials() const;
bool isCouplingUsed(const char *couplname);
const RooArgList *getCouplingSet() const;
ParamSet getCouplings() const;
// virtual Bool_t IsAllowNegativeYields() const { return
// this->_config.IsAllowNegativeYields(); }
TMatrixD getMatrix() const;
TMatrixD getInvertedMatrix() const;
double getCondition() const;
RooRealVar *getObservable() const;
RooRealVar *getBinWidth() const;
void printEvaluation() const;
void printCouplings() const;
void printFlags() const;
void printPhysics() const;
RooProduct *getSumElement(const char *name) const;
std::vector<std::string> getSamples() const;
double expectedUncertainty() const;
TH1 *createTH1(const std::string &name);
TH1 *createTH1(const std::string &name, bool correlateErrors);
protected:
class CacheElem;
void init();
void printAuthors() const;
void setup(bool ownParams = true);
bool _ownParameters = false;
/* wip
void disableInterference(const std::vector<const char*>& nonInterfering) ;
void disableInterferences(const std::vector<std::vector<const char*> >&
nonInterfering) ;
*/
mutable RooObjCacheManager _cacheMgr; //! The cache manager
void addFolders(const RooArgList &folders);
bool hasCache() const;
RooLagrangianMorphFunc::CacheElem *getCache(const RooArgSet *nset) const;
void updateSampleWeights();
RooRealVar *setupObservable(const char *obsname, TClass *mode,
TObject *inputExample);
public:
/// length of floating point digits precision supported by implementation.
static constexpr double implementedPrecision = RooFit::SuperFloatPrecision::digits10;
void importToWorkspace(RooWorkspace *ws, const RooAbsReal *object);
void importToWorkspace(RooWorkspace *ws, RooAbsData *object);
void writeMatrixToFile(const TMatrixD &matrix, const char *fname);
void writeMatrixToStream(const TMatrixD &matrix, std::ostream &stream);
TMatrixD readMatrixFromFile(const char *fname);
TMatrixD readMatrixFromStream(std::istream &stream);
// RooDataHist* makeDataHistogram(TH1* hist, RooRealVar* observable, const
// char* histname = NULL) ; void setDataHistogram(TH1* hist, RooRealVar*
// observable, RooDataHist* dh) ; void printDataHistogram(RooDataHist* hist,
// RooRealVar* obs) ;
int countSamples(std::vector<RooArgList *> &vertices);
int countSamples(int nprod, int ndec, int nboth);
TPair *makeCrosssectionContainer(double xs, double unc);
std::map<std::string, std::string>
createWeightStrings(const ParamMap &inputs,
const std::vector<std::vector<std::string>> &vertices);
std::map<std::string, std::string>
createWeightStrings(const ParamMap &inputs,
const std::vector<RooArgList *> &vertices,
RooArgList &couplings);
std::map<std::string, std::string> createWeightStrings(
const ParamMap &inputs, const std::vector<RooArgList *> &vertices,
RooArgList &couplings, const FlagMap &flagValues, const RooArgList &flags,
const std::vector<RooArgList *> &nonInterfering);
RooArgSet createWeights(const ParamMap &inputs,
const std::vector<RooArgList *> &vertices,
RooArgList &couplings, const FlagMap &inputFlags,
const RooArgList &flags,
const std::vector<RooArgList *> &nonInterfering);
RooArgSet createWeights(const ParamMap &inputs,
const std::vector<RooArgList *> &vertices,
RooArgList &couplings);
bool updateCoefficients();
bool useCoefficients(const TMatrixD &inverse);
bool useCoefficients(const char *filename);
bool writeCoefficients(const char *filename);
int countContributingFormulas() const;
RooAbsReal *getSampleWeight(const char *name);
void printParameters(const char *samplename) const;
void printParameters() const;
void printSamples() const;
void printSampleWeights() const;
void printWeights() const;
void setScale(double val);
double getScale();
int nSamples() const {return this->_config.folderNames.size(); }
RooRealSumFunc *getFunc() const;
std::unique_ptr<RooWrapperPdf> createPdf() const;
RooAbsPdf::ExtendMode extendMode() const;
Double_t expectedEvents(const RooArgSet *nset) const;
Double_t expectedEvents(const RooArgSet &nset) const;
Double_t expectedEvents() const;
Bool_t selfNormalized() const { return true; }
void readParameters(TDirectory *f);
void collectInputs(TDirectory *f);
static std::unique_ptr<RooRatio> makeRatio(const char *name,
const char *title, RooArgList &nr,
RooArgList &dr);
protected:
double _scale = 1;
std::map<std::string, int> _sampleMap;
RooListProxy _physics;
RooSetProxy _operators;
RooListProxy _observables;
RooListProxy _binWidths;
RooListProxy _flags;
Config _config;
std::vector<std::vector<RooListProxy *>> _diagrams;
mutable const RooArgSet *_curNormSet; //!
std::vector<RooListProxy *> _nonInterfering;
ClassDefOverride(RooLagrangianMorphFunc, 1)
};
#endif