Rivet: /Users/chrisg/software/rivet/include/Rivet/AnalysisHandler.hh Source File

| Rivet 3.1.9

AnalysisHandler.hh
1// -*- C++ -*-
2#ifndef RIVET_RivetHandler_HH
3#define RIVET_RivetHandler_HH
4
5#include "Rivet/Config/RivetCommon.hh"
6#include "Rivet/Particle.hh"
7#include "Rivet/AnalysisLoader.hh"
8#include "Rivet/Tools/RivetYODA.hh"
9
10namespace Rivet {
11
12
13 // Forward declaration and smart pointer for Analysis
14 class Analysis;
15 typedef std::shared_ptr<Analysis> AnaHandle;
16
17
23 class AnalysisHandler {
24 public:
25
27 AnalysisHandler(const string& runname="");
28
30 AnalysisHandler(const AnalysisHandler&) = delete;
31
33 AnalysisHandler& operator=(const AnalysisHandler&) = delete;
34
36 ~AnalysisHandler();
37
38
41
43 string runName() const;
44
50 size_t numEvents() const {
51 const double N = _eventCounter.get()->_getPersistent(defaultWeightIndex())->numEntries();
52 return size_t(N + 0.5 - (N<0)); // round to nearest integer
53 }
54
59 double sumW() const { return _eventCounter->sumW(); }
61 double sumW2() const { return _eventCounter->sumW2(); }
62
64 const vector<string>& weightNames() const { return _weightNames; }
65
67 //const vector<size_t> weightIndices() const { return _weightIndices; }
68
70 size_t numWeights() const { return _weightNames.size(); }
71
73 bool haveNamedWeights() const;
74
76 void setWeightNames(const GenEvent& ge);
77
79 size_t defaultWeightIndex() const { return _rivetDefaultWeightIdx; }
80
82 void setWeightCap(const double maxWeight) { _weightCap = maxWeight; }
83
85 void setNLOSmearing(double frac) { _NLOSmearing = frac; }
86
88 void skipMultiWeights(bool ignore=false);
89
91 void selectMultiWeights(std::string patterns="");
92
94 void deselectMultiWeights(std::string patterns="");
95
97 void setNominalWeightName(std::string name="");
98
100
101
104
106 Scatter1DPtr crossSection() const { return _xs; }
107
109 void setCrossSection(const vector<pair<double,double>>& xsecs, bool isUserSupplied = false);
110
112 void setCrossSection(const pair<double, double>& xsec, bool isUserSupplied=false);
113
115 void setCrossSection(double xsec, double xsecerr, bool isUserSupplied=false) {
116 setCrossSection({xsec, xsecerr}, isUserSupplied);
117 }
118
122 void updateCrossSection();
123
125 void notifyEndOfFile() { _isEndOfFile = true; }
126
128 double nominalCrossSection() const {
129 _xs.get()->setActiveWeightIdx(_rivetDefaultWeightIdx);
130 const YODA::Scatter1D::Points& ps = _xs->points();
131 if (ps.size() != 1) {
132 string errMsg = "value missing when requesting nominal cross-section";
133 throw Error(errMsg);
134 }
135 double xs = ps[0].x();
136 _xs.get()->unsetActiveWeight();
137 return xs;
138 }
139
141
142
145
147 AnalysisHandler& setRunBeams(const ParticlePair& beams) {
148 _beams = beams;
149 MSG_DEBUG("Setting run beams = " << beams << " @ " << sqrtS()/GeV << " GeV");
150 return *this;
151 }
152
154 const ParticlePair& beams() const { return _beams; }
155
158 PdgIdPair beamIds() const;
159
162 double sqrtS() const;
163
165 void checkBeams(bool check=true) { setIgnoreBeams(!check); }
168 void setIgnoreBeams(bool ignore=true);
169
171
172
175
177 std::vector<std::string> analysisNames() const;
178
180 std::vector<std::string> stdAnalysisNames() const;
181
183 const std::map<std::string, AnaHandle>& analysesMap() const {
184 return _analyses;
185 }
186
188 std::vector<AnaHandle> analyses() const {
189 std::vector<AnaHandle> rtn;
190 rtn.reserve(_analyses.size());
191 for (const auto& apair : _analyses) rtn.push_back(apair.second);
192 return rtn;
193 }
194
196 AnaHandle analysis(const std::string& analysisname) {
197 if ( _analyses.find(analysisname) == _analyses.end() )
198 throw LookupError("No analysis named '" + analysisname + "' registered in AnalysisHandler");
199 try {
200 return _analyses[analysisname];
201 } catch (...) {
202 throw LookupError("No analysis named '" + analysisname + "' registered in AnalysisHandler");
203 }
204 }
205
207 AnalysisHandler& addAnalysis(Analysis* analysis);
208
214 AnalysisHandler& addAnalysis(const std::string& analysisname);
215
217 AnalysisHandler& addAnalysis(const std::string& analysisname, std::map<string, string> pars);
218
225 AnalysisHandler& addAnalyses(const std::vector<std::string>& analysisnames);
226
227
229 AnalysisHandler& removeAnalysis(const std::string& analysisname);
230
232 AnalysisHandler& removeAnalyses(const std::vector<std::string>& analysisnames);
233
235
236
239
241 void init(const GenEvent& event);
242
247 void analyze(const GenEvent& event);
248
253 void analyze(const GenEvent* event);
254
257 void finalize();
258
260
261
264
268 void readData(std::istream& istr, const string& fmt, bool preload = true);
269
271 void readData(const std::string& filename, bool preload = true);
272
274 vector<YODA::AnalysisObjectPtr> getYodaAOs(bool includeraw=false) const;
275
278 const YODA::AnalysisObjectPtr getPreload(string path) const {
279 auto it = _preloads.find(path);
280 if ( it == _preloads.end() ) return nullptr;
281 return it->second;
282 }
283
287 void writeData(std::ostream& ostr, const string& fmt) const;
288
290 void writeData(const string& filename) const;
291
297 void setAODump(const string& dumpfile, int period) {
298 dump(dumpfile, period);
299 }
301 void setNoAODump() {
302 setAODump("DUMMY", -1);
303 }
306 void dump(const string& dumpfile, int period) {
307 _dumpPeriod = period;
308 _dumpFile = dumpfile;
309 }
310
325
326 void mergeYodas(const vector<string>& aofiles,
327 const vector<string>& delopts=vector<string>(),
328 const vector<string>& addopts=vector<string>(),
329 const vector<string>& matches=vector<string>(),
330 const vector<string>& unmatches=vector<string>(),
331 bool equiv=false);
332
334 void merge(AnalysisHandler &other);
335
337
338
341
344 enum class Stage { OTHER, INIT, FINALIZE };
345
347 Stage stage() const { return _stage; }
348
350
351
352 private:
353
356
358 Log& getLog() const;
359
361 vector<MultiweightAOPtr> getRivetAOs() const;
362
364 void stripOptions(YODA::AnalysisObjectPtr ao, const vector<string>& delopts) const;
365
368 void pushToPersistent();
369
371 void mergeAOS(map<string, YODA::AnalysisObjectPtr> &allaos,
372 map<string, YODA::AnalysisObjectPtr> &newaos,
373 map<string, pair<double, double>> &allxsecs,
374 const vector<string>& delopts=vector<string>(),
375 const vector<string>& optAnas=vector<string>(),
376 const vector<string>& optKeys=vector<string>(),
377 const vector<string>& optVals=vector<string>(),
378 bool equiv=false,
379 const bool overwrite_xsec = false,
380 const double user_xsec = 1.0);
381
382
387 void loadAOs(const map<string, YODA::AnalysisObjectPtr>& allAOs, const bool unscale = false);
388
390
391
392 private:
393
395 Stage _stage = Stage::OTHER;
396
398 std::map<std::string, AnaHandle> _analyses;
399
403 map<string,YODA::AnalysisObjectPtr> _preloads;
404
406 vector<YODA::AnalysisObjectPtr> _finalizedAOs;
407
408
411
413 std::vector<std::string> _weightNames;
414 std::vector<std::valarray<double> > _subEventWeights;
415 //size_t _numWeightTypes; // always == WeightVector.size()
416
418 std::vector<size_t> _weightIndices;
419
421 std::string _runname;
422
424 CounterPtr _eventCounter;
425
427 Scatter1DPtr _xs;
428
430 vector<Scatter1D> _xsAvg;
431
433 double _numEntriesAggregate;
434
436 bool _isEndOfFile;
437
439 std::pair<double,double> _userxs;
440
442 ParticlePair _beams;
443
445 bool _initialised;
446
448 bool _ignoreBeams;
449
451 bool _skipWeights;
452
454 std::string _matchWeightNames;
455
457 std::string _unmatchWeightNames;
458
460 std::string _nominalWeightName;
461
463 double _weightCap;
464
468 double _NLOSmearing;
469
471 int _eventNumber;
472
474 size_t _defaultWeightIdx;
475
477 size_t _rivetDefaultWeightIdx;
478
480 int _dumpPeriod;
481
483 string _dumpFile;
484
486 bool _dumping;
487
489
490 };
491
492
493}
494
495#endif
Rivet::AnalysisHandler
The key class for coordination of Analysis objects and the event loop.
Definition AnalysisHandler.hh:23
Rivet::AnalysisHandler::addAnalysis
AnalysisHandler & addAnalysis(const std::string &analysisname, std::map< string, string > pars)
Add an analysis with a map of analysis options.
Rivet::AnalysisHandler::setNLOSmearing
void setNLOSmearing(double frac)
Set the relative width of the NLO smearing window.
Definition AnalysisHandler.hh:85
Rivet::AnalysisHandler::stdAnalysisNames
std::vector< std::string > stdAnalysisNames() const
Get a list of the official analysis names for this release.
Rivet::AnalysisHandler::beamIds
PdgIdPair beamIds() const
Rivet::AnalysisHandler::setAODump
void setAODump(const string &dumpfile, int period)
Configure the AnalysisObject dump rate and destination.
Definition AnalysisHandler.hh:297
Rivet::AnalysisHandler::defaultWeightIndex
size_t defaultWeightIndex() const
Get the index of the nominal weight-stream.
Definition AnalysisHandler.hh:79
Rivet::AnalysisHandler::writeData
void writeData(const string &filename) const
Write all analyses' plots (via getData) to the named file.
Rivet::AnalysisHandler::finalize
void finalize()
Rivet::AnalysisHandler::setRunBeams
AnalysisHandler & setRunBeams(const ParticlePair &beams)
Set the beam particles for this run.
Definition AnalysisHandler.hh:147
Rivet::AnalysisHandler::updateCrossSection
void updateCrossSection()
Rivet::AnalysisHandler::setCrossSection
void setCrossSection(double xsec, double xsecerr, bool isUserSupplied=false)
Set the cross-section for the process being generated (alternative signature)
Definition AnalysisHandler.hh:115
Rivet::AnalysisHandler::init
void init(const GenEvent &event)
Initialize a run, with the run beams taken from the example event.
Rivet::AnalysisHandler::addAnalyses
AnalysisHandler & addAnalyses(const std::vector< std::string > &analysisnames)
Add analyses to the run list using their names.
Rivet::AnalysisHandler::removeAnalyses
AnalysisHandler & removeAnalyses(const std::vector< std::string > &analysisnames)
Remove analyses from the run list using their names.
Rivet::AnalysisHandler::beams
const ParticlePair & beams() const
Get the beam particles for this run, usually determined from the first event.
Definition AnalysisHandler.hh:154
Rivet::AnalysisHandler::numWeights
size_t numWeights() const
Indices of the weights in the original weight matrix.
Definition AnalysisHandler.hh:70
Rivet::AnalysisHandler::selectMultiWeights
void selectMultiWeights(std::string patterns="")
Setter for _matchWeightNames.
Rivet::AnalysisHandler::setNominalWeightName
void setNominalWeightName(std::string name="")
Setter for _nominalWeightName.
Rivet::AnalysisHandler::setNoAODump
void setNoAODump()
Configure the AnalysisObject dump rate and destination.
Definition AnalysisHandler.hh:301
Rivet::AnalysisHandler::setCrossSection
void setCrossSection(const pair< double, double > &xsec, bool isUserSupplied=false)
Set all cross-sections for the process being generated, based on nominal weight.
Rivet::AnalysisHandler::runName
string runName() const
Get the name of this run.
Rivet::AnalysisHandler::AnalysisHandler
AnalysisHandler(const string &runname="")
Preferred constructor, with optional run name.
Rivet::AnalysisHandler::dump
void dump(const string &dumpfile, int period)
Definition AnalysisHandler.hh:306
Rivet::AnalysisHandler::~AnalysisHandler
~AnalysisHandler()
The destructor is not virtual, as this class should not be inherited from.
Rivet::AnalysisHandler::merge
void merge(AnalysisHandler &other)
A method to merge another AnalysisHandler into the current one.
Rivet::AnalysisHandler::readData
void readData(const std::string &filename, bool preload=true)
Read analysis plots into the histo collection (via addData) from the named file.
Rivet::AnalysisHandler::analyze
void analyze(const GenEvent *event)
Analyze the given event by pointer.
Rivet::AnalysisHandler::sqrtS
double sqrtS() const
Rivet::AnalysisHandler::mergeYodas
void mergeYodas(const vector< string > &aofiles, const vector< string > &delopts=vector< string >(), const vector< string > &addopts=vector< string >(), const vector< string > &matches=vector< string >(), const vector< string > &unmatches=vector< string >(), bool equiv=false)
Merge the vector of YODA files, using the cross-section and weight information provided in each.
Rivet::AnalysisHandler::weightNames
const vector< string > & weightNames() const
Names of event weight categories.
Definition AnalysisHandler.hh:64
Rivet::AnalysisHandler::setCrossSection
void setCrossSection(const vector< pair< double, double > > &xsecs, bool isUserSupplied=false)
Set all cross-sections for the process being generated specifically (preferred)
Rivet::AnalysisHandler::readData
void readData(std::istream &istr, const string &fmt, bool preload=true)
Read analysis plots into the histo collection from the given stream.
Rivet::AnalysisHandler::notifyEndOfFile
void notifyEndOfFile()
Toggle to signal a change in HepMC input file.
Definition AnalysisHandler.hh:125
Rivet::AnalysisHandler::stage
Stage stage() const
Return the current processing stage.
Definition AnalysisHandler.hh:347
Rivet::AnalysisHandler::sumW2
double sumW2() const
Access to the sum of squared-weights.
Definition AnalysisHandler.hh:61
Rivet::AnalysisHandler::addAnalysis
AnalysisHandler & addAnalysis(Analysis *analysis)
Add an analysis to the run list by object.
Rivet::AnalysisHandler::setIgnoreBeams
void setIgnoreBeams(bool ignore=true)
Rivet::AnalysisHandler::haveNamedWeights
bool haveNamedWeights() const
Are any of the weights non-numeric?
Rivet::AnalysisHandler::setWeightNames
void setWeightNames(const GenEvent &ge)
Set the weight names from a GenEvent.
Rivet::AnalysisHandler::numEvents
size_t numEvents() const
Definition AnalysisHandler.hh:50
Rivet::AnalysisHandler::analyses
std::vector< AnaHandle > analyses() const
Get the collection of currently registered analyses.
Definition AnalysisHandler.hh:188
Rivet::AnalysisHandler::deselectMultiWeights
void deselectMultiWeights(std::string patterns="")
Setter for _unmatchWeightNames.
Rivet::AnalysisHandler::setWeightCap
void setWeightCap(const double maxWeight)
Set the weight cap.
Definition AnalysisHandler.hh:82
Rivet::AnalysisHandler::analysis
AnaHandle analysis(const std::string &analysisname)
Get a registered analysis by name.
Definition AnalysisHandler.hh:196
Rivet::AnalysisHandler::getPreload
const YODA::AnalysisObjectPtr getPreload(string path) const
Definition AnalysisHandler.hh:278
Rivet::AnalysisHandler::writeData
void writeData(std::ostream &ostr, const string &fmt) const
Write all analyses' plots (via getData) to the given stream.
Rivet::AnalysisHandler::analysesMap
const std::map< std::string, AnaHandle > & analysesMap() const
Get the collection of currently registered analyses.
Definition AnalysisHandler.hh:183
Rivet::AnalysisHandler::addAnalysis
AnalysisHandler & addAnalysis(const std::string &analysisname)
Add an analysis to the run list using its name.
Rivet::AnalysisHandler::Stage
Stage
Definition AnalysisHandler.hh:344
Rivet::AnalysisHandler::getYodaAOs
vector< YODA::AnalysisObjectPtr > getYodaAOs(bool includeraw=false) const
Get all YODA analysis objects (across all weights, optionally including RAW)
Rivet::AnalysisHandler::removeAnalysis
AnalysisHandler & removeAnalysis(const std::string &analysisname)
Remove an analysis from the run list using its name.
Rivet::AnalysisHandler::AnalysisHandler
AnalysisHandler(const AnalysisHandler &)=delete
The copy constructor is deleted, so it can never be called.
Rivet::AnalysisHandler::checkBeams
void checkBeams(bool check=true)
Option to disable AH beam-consistency checks.
Definition AnalysisHandler.hh:165
Rivet::AnalysisHandler::skipMultiWeights
void skipMultiWeights(bool ignore=false)
Setter for _skipWeights.
Rivet::AnalysisHandler::nominalCrossSection
double nominalCrossSection() const
Get the nominal cross-section.
Definition AnalysisHandler.hh:128
Rivet::AnalysisHandler::sumW
double sumW() const
Access the sum of the event weights seen.
Definition AnalysisHandler.hh:59
Rivet::AnalysisHandler::crossSection
Scatter1DPtr crossSection() const
Get the cross-section known to the handler.
Definition AnalysisHandler.hh:106
Rivet::AnalysisHandler::operator=
AnalysisHandler & operator=(const AnalysisHandler &)=delete
The assignment operator is deleted, so it can never be called.
Rivet::AnalysisHandler::analyze
void analyze(const GenEvent &event)
Analyze the given event by reference.
Rivet::AnalysisHandler::analysisNames
std::vector< std::string > analysisNames() const
Get a list of the currently registered analyses' names.
Rivet::Analysis
This is the base class of all analysis classes in Rivet.
Definition Analysis.hh:65
Rivet::Log
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
MSG_DEBUG
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
Rivet
Definition MC_Cent_pPb.hh:10
Rivet::ParticlePair
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:42
Rivet::Error
Generic runtime Rivet error.
Definition Exceptions.hh:12
Rivet::LookupError
Error relating to looking up analysis objects in the register.
Definition Exceptions.hh:61