2#ifndef RIVET_RivetHandler_HH
3#define RIVET_RivetHandler_HH
5#include "Rivet/Config/RivetCommon.hh"
6#include "Rivet/Particle.hh"
7#include "Rivet/AnalysisLoader.hh"
8#include "Rivet/Tools/RivetYODA.hh"
15 typedef std::shared_ptr<Analysis> AnaHandle;
51 const double N = _eventCounter.get()->_getPersistent(
defaultWeightIndex())->numEntries();
52 return size_t(N + 0.5 - (N<0));
59 double sumW()
const {
return _eventCounter->sumW(); }
61 double sumW2()
const {
return _eventCounter->sumW2(); }
64 const vector<string>&
weightNames()
const {
return _weightNames; }
70 size_t numWeights()
const {
return _weightNames.size(); }
82 void setWeightCap(
const double maxWeight) { _weightCap = maxWeight; }
109 void setCrossSection(
const vector<pair<double,double>>& xsecs,
bool isUserSupplied =
false);
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";
135 double xs = ps[0].x();
136 _xs.get()->unsetActiveWeight();
189 std::vector<AnaHandle> rtn;
190 rtn.reserve(_analyses.size());
191 for (
const auto& apair : _analyses) rtn.push_back(apair.second);
196 AnaHandle
analysis(
const std::string& analysisname) {
197 if ( _analyses.find(analysisname) == _analyses.end() )
198 throw LookupError(
"No analysis named '" + analysisname +
"' registered in AnalysisHandler");
200 return _analyses[analysisname];
202 throw LookupError(
"No analysis named '" + analysisname +
"' registered in AnalysisHandler");
241 void init(
const GenEvent& event);
268 void readData(std::istream& istr,
const string& fmt,
bool preload =
true);
271 void readData(
const std::string& filename,
bool preload =
true);
274 vector<YODA::AnalysisObjectPtr>
getYodaAOs(
bool includeraw=
false)
const;
278 const YODA::AnalysisObjectPtr
getPreload(
string path)
const {
279 auto it = _preloads.find(path);
280 if ( it == _preloads.end() )
return nullptr;
287 void writeData(std::ostream& ostr,
const string& fmt)
const;
298 dump(dumpfile, period);
306 void dump(
const string& dumpfile,
int period) {
307 _dumpPeriod = period;
308 _dumpFile = dumpfile;
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>(),
344 enum class Stage { OTHER, INIT, FINALIZE };
361 vector<MultiweightAOPtr> getRivetAOs()
const;
364 void stripOptions(YODA::AnalysisObjectPtr ao,
const vector<string>& delopts)
const;
368 void pushToPersistent();
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>(),
379 const bool overwrite_xsec =
false,
380 const double user_xsec = 1.0);
387 void loadAOs(
const map<string, YODA::AnalysisObjectPtr>& allAOs,
const bool unscale =
false);
395 Stage _stage = Stage::OTHER;
398 std::map<std::string, AnaHandle> _analyses;
403 map<string,YODA::AnalysisObjectPtr> _preloads;
406 vector<YODA::AnalysisObjectPtr> _finalizedAOs;
413 std::vector<std::string> _weightNames;
414 std::vector<std::valarray<double> > _subEventWeights;
418 std::vector<size_t> _weightIndices;
421 std::string _runname;
424 CounterPtr _eventCounter;
430 vector<Scatter1D> _xsAvg;
433 double _numEntriesAggregate;
439 std::pair<double,double> _userxs;
454 std::string _matchWeightNames;
457 std::string _unmatchWeightNames;
460 std::string _nominalWeightName;
474 size_t _defaultWeightIdx;
477 size_t _rivetDefaultWeightIdx;
The key class for coordination of Analysis objects and the event loop.
Definition AnalysisHandler.hh:23
AnalysisHandler & addAnalysis(const std::string &analysisname, std::map< string, string > pars)
Add an analysis with a map of analysis options.
void setNLOSmearing(double frac)
Set the relative width of the NLO smearing window.
Definition AnalysisHandler.hh:85
std::vector< std::string > stdAnalysisNames() const
Get a list of the official analysis names for this release.
PdgIdPair beamIds() const
void setAODump(const string &dumpfile, int period)
Configure the AnalysisObject dump rate and destination.
Definition AnalysisHandler.hh:297
size_t defaultWeightIndex() const
Get the index of the nominal weight-stream.
Definition AnalysisHandler.hh:79
void writeData(const string &filename) const
Write all analyses' plots (via getData) to the named file.
AnalysisHandler & setRunBeams(const ParticlePair &beams)
Set the beam particles for this run.
Definition AnalysisHandler.hh:147
void updateCrossSection()
void setCrossSection(double xsec, double xsecerr, bool isUserSupplied=false)
Set the cross-section for the process being generated (alternative signature)
Definition AnalysisHandler.hh:115
void init(const GenEvent &event)
Initialize a run, with the run beams taken from the example event.
AnalysisHandler & addAnalyses(const std::vector< std::string > &analysisnames)
Add analyses to the run list using their names.
AnalysisHandler & removeAnalyses(const std::vector< std::string > &analysisnames)
Remove analyses from the run list using their names.
const ParticlePair & beams() const
Get the beam particles for this run, usually determined from the first event.
Definition AnalysisHandler.hh:154
size_t numWeights() const
Indices of the weights in the original weight matrix.
Definition AnalysisHandler.hh:70
void selectMultiWeights(std::string patterns="")
Setter for _matchWeightNames.
void setNominalWeightName(std::string name="")
Setter for _nominalWeightName.
void setNoAODump()
Configure the AnalysisObject dump rate and destination.
Definition AnalysisHandler.hh:301
void setCrossSection(const pair< double, double > &xsec, bool isUserSupplied=false)
Set all cross-sections for the process being generated, based on nominal weight.
string runName() const
Get the name of this run.
AnalysisHandler(const string &runname="")
Preferred constructor, with optional run name.
void dump(const string &dumpfile, int period)
Definition AnalysisHandler.hh:306
~AnalysisHandler()
The destructor is not virtual, as this class should not be inherited from.
void merge(AnalysisHandler &other)
A method to merge another AnalysisHandler into the current one.
void readData(const std::string &filename, bool preload=true)
Read analysis plots into the histo collection (via addData) from the named file.
void analyze(const GenEvent *event)
Analyze the given event by pointer.
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.
const vector< string > & weightNames() const
Names of event weight categories.
Definition AnalysisHandler.hh:64
void setCrossSection(const vector< pair< double, double > > &xsecs, bool isUserSupplied=false)
Set all cross-sections for the process being generated specifically (preferred)
void readData(std::istream &istr, const string &fmt, bool preload=true)
Read analysis plots into the histo collection from the given stream.
void notifyEndOfFile()
Toggle to signal a change in HepMC input file.
Definition AnalysisHandler.hh:125
Stage stage() const
Return the current processing stage.
Definition AnalysisHandler.hh:347
double sumW2() const
Access to the sum of squared-weights.
Definition AnalysisHandler.hh:61
AnalysisHandler & addAnalysis(Analysis *analysis)
Add an analysis to the run list by object.
void setIgnoreBeams(bool ignore=true)
bool haveNamedWeights() const
Are any of the weights non-numeric?
void setWeightNames(const GenEvent &ge)
Set the weight names from a GenEvent.
size_t numEvents() const
Definition AnalysisHandler.hh:50
std::vector< AnaHandle > analyses() const
Get the collection of currently registered analyses.
Definition AnalysisHandler.hh:188
void deselectMultiWeights(std::string patterns="")
Setter for _unmatchWeightNames.
void setWeightCap(const double maxWeight)
Set the weight cap.
Definition AnalysisHandler.hh:82
AnaHandle analysis(const std::string &analysisname)
Get a registered analysis by name.
Definition AnalysisHandler.hh:196
const YODA::AnalysisObjectPtr getPreload(string path) const
Definition AnalysisHandler.hh:278
void writeData(std::ostream &ostr, const string &fmt) const
Write all analyses' plots (via getData) to the given stream.
const std::map< std::string, AnaHandle > & analysesMap() const
Get the collection of currently registered analyses.
Definition AnalysisHandler.hh:183
AnalysisHandler & addAnalysis(const std::string &analysisname)
Add an analysis to the run list using its name.
Stage
Definition AnalysisHandler.hh:344
vector< YODA::AnalysisObjectPtr > getYodaAOs(bool includeraw=false) const
Get all YODA analysis objects (across all weights, optionally including RAW)
AnalysisHandler & removeAnalysis(const std::string &analysisname)
Remove an analysis from the run list using its name.
AnalysisHandler(const AnalysisHandler &)=delete
The copy constructor is deleted, so it can never be called.
void checkBeams(bool check=true)
Option to disable AH beam-consistency checks.
Definition AnalysisHandler.hh:165
void skipMultiWeights(bool ignore=false)
Setter for _skipWeights.
double nominalCrossSection() const
Get the nominal cross-section.
Definition AnalysisHandler.hh:128
double sumW() const
Access the sum of the event weights seen.
Definition AnalysisHandler.hh:59
Scatter1DPtr crossSection() const
Get the cross-section known to the handler.
Definition AnalysisHandler.hh:106
AnalysisHandler & operator=(const AnalysisHandler &)=delete
The assignment operator is deleted, so it can never be called.
void analyze(const GenEvent &event)
Analyze the given event by reference.
std::vector< std::string > analysisNames() const
Get a list of the currently registered analyses' names.
This is the base class of all analysis classes in Rivet.
Definition Analysis.hh:65
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
Definition MC_Cent_pPb.hh:10
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:42
Generic runtime Rivet error.
Definition Exceptions.hh:12
Error relating to looking up analysis objects in the register.
Definition Exceptions.hh:61