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);
121 _xs.get()->setActiveWeightIdx(_rivetDefaultWeightIdx);
122 const YODA::Scatter1D::Points& ps = _xs->points();
123 if (ps.size() != 1) {
124 string errMsg =
"value missing when requesting nominal cross-section";
127 double xs = ps[0].x();
128 _xs.get()->unsetActiveWeight();
181 std::vector<AnaHandle> rtn;
182 rtn.reserve(_analyses.size());
183 for (
const auto& apair : _analyses) rtn.push_back(apair.second);
188 AnaHandle
analysis(
const std::string& analysisname) {
189 if ( _analyses.find(analysisname) == _analyses.end() )
190 throw LookupError(
"No analysis named '" + analysisname +
"' registered in AnalysisHandler");
192 return _analyses[analysisname];
194 throw LookupError(
"No analysis named '" + analysisname +
"' registered in AnalysisHandler");
233 void init(
const GenEvent& event);
260 void readData(std::istream& istr,
const string& fmt,
bool preload =
true);
263 void readData(
const std::string& filename,
bool preload =
true);
266 vector<YODA::AnalysisObjectPtr>
getYodaAOs(
bool includeraw=
false)
const;
270 const YODA::AnalysisObjectPtr
getPreload(
string path)
const {
271 auto it = _preloads.find(path);
272 if ( it == _preloads.end() )
return nullptr;
279 void writeData(std::ostream& ostr,
const string& fmt)
const;
290 dump(dumpfile, period);
298 void dump(
const string& dumpfile,
int period) {
299 _dumpPeriod = period;
300 _dumpFile = dumpfile;
319 const vector<string>& delopts=vector<string>(),
320 const vector<string>& addopts=vector<string>(),
321 const vector<string>& matches=vector<string>(),
322 const vector<string>& unmatches=vector<string>(),
336 enum class Stage { OTHER, INIT, FINALIZE };
353 vector<MultiweightAOPtr> getRivetAOs()
const;
356 void stripOptions(YODA::AnalysisObjectPtr ao,
const vector<string>& delopts)
const;
360 void pushToPersistent();
363 void mergeAOS(map<string, YODA::AnalysisObjectPtr> &allaos,
364 map<string, YODA::AnalysisObject*> &newaos,
365 map<
string, pair<double, double>> &allxsecs,
366 const vector<string>& delopts=vector<string>(),
367 const vector<string>& optAnas=vector<string>(),
368 const vector<string>& optKeys=vector<string>(),
369 const vector<string>& optVals=vector<string>(),
371 const bool overwrite_xsec =
false,
372 const double user_xsec = 1.0);
379 void loadAOs(
const map<string, YODA::AnalysisObjectPtr>& allAOs,
const bool unscale =
false);
387 Stage _stage = Stage::OTHER;
390 std::map<std::string, AnaHandle> _analyses;
395 map<string,YODA::AnalysisObjectPtr> _preloads;
398 vector<YODA::AnalysisObjectPtr> _finalizedAOs;
405 std::vector<std::string> _weightNames;
406 std::vector<std::valarray<double> > _subEventWeights;
410 std::vector<size_t> _weightIndices;
413 std::string _runname;
416 CounterPtr _eventCounter;
422 std::pair<double,double> _userxs;
437 std::string _matchWeightNames;
440 std::string _unmatchWeightNames;
443 std::string _nominalWeightName;
457 size_t _defaultWeightIdx;
460 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:289
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:139
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:146
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:293
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:298
~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.
Stage stage() const
Return the current processing stage.
Definition: AnalysisHandler.hh:339
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:180
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:188
const YODA::AnalysisObjectPtr getPreload(string path) const
Definition: AnalysisHandler.hh:270
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:175
AnalysisHandler & addAnalysis(const std::string &analysisname)
Add an analysis to the run list using its name.
Stage
Definition: AnalysisHandler.hh:336
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:157
void skipMultiWeights(bool ignore=false)
Setter for _skipWeights.
double nominalCrossSection() const
Get the nominal cross-section.
Definition: AnalysisHandler.hh:120
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:64
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