Rivet  1.8.3
Analysis.hh
1 // -*- C++ -*-
2 #ifndef RIVET_Analysis_HH
3 #define RIVET_Analysis_HH
4 
5 #include "Rivet/Rivet.hh"
6 #include "Rivet/Analysis.fhh"
7 #include "Rivet/AnalysisInfo.hh"
8 #include "Rivet/Event.hh"
9 #include "Rivet/Projection.hh"
10 #include "Rivet/ProjectionApplier.hh"
11 #include "Rivet/ProjectionHandler.hh"
12 #include "Rivet/Constraints.hh"
13 #include "Rivet/AnalysisHandler.fhh"
14 #include "Rivet/AnalysisLoader.hh"
15 #include "Rivet/Tools/Logging.fhh"
16 #include "Rivet/RivetAIDA.fhh"
17 
18 
21 #define vetoEvent \
22  do { MSG_DEBUG("Vetoing event on line " << __LINE__ << " of " << __FILE__); return; } while(0)
23 
26 #define DECLARE_RIVET_PLUGIN(clsname) Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
27 
28 
29 
30 namespace Rivet {
31 
32 
51  class Analysis : public ProjectionApplier {
52 
54  friend class AnalysisHandler;
55 
56 
57  public:
58 
60 
61 
62  // /// The default constructor.
63  // Analysis();
64 
66  Analysis(const std::string& name);
67 
69  virtual ~Analysis() {}
70 
72 
73 
74  public:
75 
77 
78 
82  virtual void init() { }
83 
88  virtual void analyze(const Event& event) = 0;
89 
95  virtual void finalize() { }
96 
98 
99 
100  public:
101 
105 
106 
108  const AnalysisInfo& info() const {
109  assert(_info.get() != 0 && "No AnalysisInfo object :O");
110  return *_info;
111  }
112 
118  virtual std::string name() const {
119  return (info().name().empty()) ? _defaultname : info().name();
120  }
121 
123  virtual std::string inspireId() const {
124  return info().inspireId();
125  }
126 
128  virtual std::string spiresId() const {
129  return info().spiresId();
130  }
131 
136  virtual std::vector<std::string> authors() const {
137  return info().authors();
138  }
139 
145  virtual std::string summary() const {
146  return info().summary();
147  }
148 
155  virtual std::string description() const {
156  return info().description();
157  }
158 
164  virtual std::string runInfo() const {
165  return info().runInfo();
166  }
167 
169  virtual std::string experiment() const {
170  return info().experiment();
171  }
172 
174  virtual std::string collider() const {
175  return info().collider();
176  }
177 
179  virtual std::string year() const {
180  return info().year();
181  }
182 
184  virtual std::vector<std::string> references() const {
185  return info().references();
186  }
187 
189  virtual std::string bibKey() const {
190  return info().bibKey();
191  }
192 
194  virtual std::string bibTeX() const {
195  return info().bibTeX();
196  }
197 
199  virtual std::string status() const {
200  return (info().status().empty()) ? "UNVALIDATED" : info().status();
201  }
202 
204  virtual std::vector<std::string> todos() const {
205  return info().todos();
206  }
207 
208 
210  virtual const std::vector<PdgIdPair>& requiredBeams() const {
211  return info().beams();
212  }
214  virtual Analysis& setRequiredBeams(const std::vector<PdgIdPair>& requiredBeams) {
215  info().setBeams(requiredBeams);
216  return *this;
217  }
218 
219 
221  virtual const std::vector<std::pair<double, double> >& requiredEnergies() const {
222  return info().energies();
223  }
225  virtual Analysis& setRequiredEnergies(const std::vector<std::pair<double, double> >& requiredEnergies) {
227  return *this;
228  }
229 
230 
232  bool needsCrossSection() const {
233  return info().needsCrossSection();
234  }
236  Analysis& setNeedsCrossSection(bool needed=true) {
237  info().setNeedsCrossSection(needed);
238  return *this;
239  }
240 
242 
243 
245 
246 
249  assert(_info.get() != 0 && "No AnalysisInfo object :O");
250  return *_info;
251  }
252 
255  virtual Analysis& setBeams(PdgId beam1, PdgId beam2) {
257  return setRequiredBeams(std::vector<PdgIdPair>(1, make_pair(beam1, beam2)));
258  }
259 
261 
262 
264 
265 
267  const ParticlePair& beams() const;
268 
270  const PdgIdPair beamIds() const;
271 
273  double sqrtS() const;
274 
276 
277 
279 
280 
282  bool isCompatible(const ParticlePair& beams) const;
283 
285  bool isCompatible(PdgId beam1, PdgId beam2, double e1, double e2) const;
286 
288  bool isCompatible(const PdgIdPair& beams, const std::pair<double,double>& energies) const;
289 
291 
292 
293  public:
294 
296  AnalysisHandler& handler() const { return *_analysishandler; }
297 
305  void normalize(AIDA::IHistogram1D*& histo, double norm=1.0, bool includeoverflows=true);
306 
312  void scale(AIDA::IHistogram1D*& histo, double scale);
313 
321  void normalize(AIDA::IHistogram2D*& histo, double norm=1.0);
322 
328  void scale(AIDA::IHistogram2D*& histo, double scale);
329 
331  Analysis& setCrossSection(double xs);
332 
333 
334  protected:
335 
337  Log& getLog() const;
338 
340  double crossSection() const;
341 
344  double crossSectionPerEvent() const;
345 
348  size_t numEvents() const;
349 
352  double sumOfWeights() const;
353 
354 
355  protected:
356 
358 
359  AIDA::IAnalysisFactory& analysisFactory();
361 
363  AIDA::ITree& tree();
364 
366  AIDA::IHistogramFactory& histogramFactory();
367 
369  AIDA::IDataPointSetFactory& datapointsetFactory();
370 
372  const std::string histoDir() const;
373 
375  const std::string histoPath(const std::string& hname) const;
376 
378  const std::string histoPath(size_t datasetId, size_t xAxisId, size_t yAxisId) const;
379 
381  const std::string makeAxisCode(size_t datasetId, size_t xAxisId, size_t yAxisId) const;
382 
384 
385 
387 
388 
390  const BinEdges& binEdges(const std::string& hname) const;
391 
393  const BinEdges& binEdges(size_t datasetId, size_t xAxisId, size_t yAxisId) const;
394 
398  BinEdges logBinEdges(size_t nbins, double lower, double upper);
399 
404  AIDA::IHistogram1D* bookHistogram1D(const std::string& name,
405  size_t nbins, double lower, double upper,
406  const std::string& title="",
407  const std::string& xtitle="", const std::string& ytitle="");
408 
413  AIDA::IHistogram1D* bookHistogram1D(const std::string& name,
414  const std::vector<double>& binedges, const std::string& title="",
415  const std::string& xtitle="", const std::string& ytitle="");
416 
424  AIDA::IHistogram2D*
425  bookHistogram2D(const std::string& name,
426  size_t nxbins, double xlower, double xupper,
427  size_t nybins, double ylower, double yupper,
428  const std::string& title="", const std::string& xtitle="",
429  const std::string& ytitle="", const std::string& ztitle="");
430 
437  AIDA::IHistogram2D*
438  bookHistogram2D(const std::string& name,
439  const std::vector<double>& xbinedges,
440  const std::vector<double>& ybinedges,
441  const std::string& title="", const std::string& xtitle="",
442  const std::string& ytitle="", const std::string& ztitle="");
443 
447  AIDA::IHistogram1D* bookHistogram1D(const std::string& name, const std::string& title="",
448  const std::string& xtitle="", const std::string& ytitle="");
449 
453  AIDA::IHistogram1D* bookHistogram1D(size_t datasetId, size_t xAxisId, size_t yAxisId,
454  const std::string& title="",
455  const std::string& xtitle="", const std::string& ytitle="");
456 
458 
459 
461 
462 
467  AIDA::IProfile1D* bookProfile1D(const std::string& name,
468  size_t nbins, double lower, double upper,
469  const std::string& title="",
470  const std::string& xtitle="", const std::string& ytitle="");
471 
476  AIDA::IProfile1D* bookProfile1D(const std::string& name,
477  const std::vector<double>& binedges,
478  const std::string& title="",
479  const std::string& xtitle="", const std::string& ytitle="");
480 
484  AIDA::IProfile1D* bookProfile1D(const std::string& name, const std::string& title="",
485  const std::string& xtitle="", const std::string& ytitle="");
486 
490  AIDA::IProfile1D* bookProfile1D(size_t datasetId, size_t xAxisId, size_t yAxisId,
491  const std::string& title="",
492  const std::string& xtitle="", const std::string& ytitle="");
494 
495 
497 
498 
503  AIDA::IDataPointSet* bookDataPointSet(const std::string& name, const std::string& title="",
504  const std::string& xtitle="", const std::string& ytitle="");
505 
506 
511  AIDA::IDataPointSet* bookDataPointSet(const std::string& name,
512  size_t npts, double lower, double upper,
513  const std::string& title="",
514  const std::string& xtitle="", const std::string& ytitle="");
515 
520  //AIDA::IDataPointSet* bookDataPointSet(const std::string& name, const std::string& title);
521 
525  AIDA::IDataPointSet* bookDataPointSet(size_t datasetId, size_t xAxisId, size_t yAxisId,
526  const std::string& title="",
527  const std::string& xtitle="", const std::string& ytitle="");
528 
530 
531 
532  private:
533 
535 
536 
538  void _makeHistoDir();
539 
541  void _cacheBinEdges() const;
542 
544  void _cacheXAxisData() const;
545 
547 
548 
549  protected:
550 
552  string _defaultname;
553 
555  shared_ptr<AnalysisInfo> _info;
556 
557 
558  private:
559 
561 
562  double _crossSection;
563  bool _gotCrossSection;
565 
567  AnalysisHandler* _analysishandler;
568 
570  mutable bool _madeHistoDir;
571 
575  mutable map<string, vector<DPSXPoint> > _dpsData;
576 
580  mutable map<string, BinEdges> _histBinEdges;
581 
582 
583  private:
584 
587  Analysis& operator=(const Analysis&);
588 
589  };
590 
591 
592 }
593 
594 
595 // Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
596 #include "Rivet/AnalysisBuilder.hh"
597 
598 
599 #endif
int PdgId
Typedef for a PDG ID code.
Definition: Particle.fhh:29
double sumOfWeights() const
Definition: Analysis.cc:113
virtual std::string summary() const
Get a short description of the analysis.
Definition: Analysis.hh:145
const std::string histoDir() const
Get the canonical histogram &quot;directory&quot; path for this analysis.
Definition: Analysis.cc:63
void setNeedsCrossSection(bool needXsec)
Return true if this analysis needs to know the process cross-section.
Definition: AnalysisInfo.hh:184
Definition: AnalysisInfo.hh:11
virtual std::vector< std::string > todos() const
Any work to be done on this analysis.
Definition: Analysis.hh:204
virtual std::string experiment() const
Experiment which performed and published this analysis.
Definition: Analysis.hh:169
BinEdges logBinEdges(size_t nbins, double lower, double upper)
Get bin edges with logarithmic widths.
Definition: Analysis.cc:229
virtual const std::vector< PdgIdPair > & requiredBeams() const
Return the allowed pairs of incoming beams required by this analysis.
Definition: Analysis.hh:210
virtual std::string bibTeX() const
BibTeX citation entry for this article.
Definition: Analysis.hh:194
AIDA::IAnalysisFactory & analysisFactory()
Access the AIDA analysis factory of the controlling AnalysisHandler object.
Definition: Analysis.cc:30
const ParticlePair & beams() const
Incoming beams for this run.
Definition: Analysis.cc:54
AIDA::IHistogram2D * bookHistogram2D(const std::string &name, size_t nxbins, double xlower, double xupper, size_t nybins, double ylower, double yupper, const std::string &title="", const std::string &xtitle="", const std::string &ytitle="", const std::string &ztitle="")
Definition: Analysis.cc:295
const std::string & collider() const
Collider on which the experiment ran.
Definition: AnalysisInfo.hh:130
const std::string & year() const
When the original experimental analysis was published. When the refereed paper on which this is based...
Definition: AnalysisInfo.hh:139
virtual void finalize()
Definition: Analysis.hh:95
const std::string & bibKey() const
BibTeX citation key for this article.
Definition: AnalysisInfo.hh:153
const std::string & spiresId() const
Get the SPIRES ID code for this analysis.
Definition: AnalysisInfo.hh:62
virtual std::string status() const
Whether this analysis is trusted (in any way!)
Definition: Analysis.hh:199
const std::vector< std::string > & authors() const
Names &amp; emails of paper/analysis authors. Names and email of authors in &#39;NAME &lt;EMAIL&gt;&#39; format...
Definition: AnalysisInfo.hh:71
void scale(AIDA::IHistogram1D *&histo, double scale)
Definition: Analysis.cc:511
virtual std::string runInfo() const
Information about the events needed as input for this analysis.
Definition: Analysis.hh:164
virtual void analyze(const Event &event)=0
AnalysisInfo & info()
Get the actual AnalysisInfo object in which all this metadata is stored (non-const).
Definition: Analysis.hh:248
virtual void init()
Definition: Analysis.hh:82
Analysis & setCrossSection(double xs)
Set the cross section from the generator.
Definition: Analysis.cc:165
Definition: Logging.hh:9
bool needsCrossSection() const
Return true if this analysis needs to know the process cross-section.
Definition: AnalysisInfo.hh:181
virtual std::string description() const
Get a full description of the analysis.
Definition: Analysis.hh:155
double sqrtS() const
Centre of mass energy for this run.
Definition: Analysis.cc:50
const std::vector< std::pair< double, double > > & energies() const
Sets of valid beam energies.
Definition: AnalysisInfo.hh:116
AIDA::IDataPointSet * bookDataPointSet(const std::string &name, const std::string &title="", const std::string &xtitle="", const std::string &ytitle="")
Definition: Analysis.cc:404
size_t numEvents() const
Definition: Analysis.cc:108
This is the base class of all analysis classes in Rivet.
Definition: Analysis.hh:51
const std::string & runInfo() const
Information about the events needed as input for this analysis. Event types, energies, kinematic cuts, particles to be considered stable, etc. etc. Should be treated as a restructuredText bullet list (http://docutils.sourceforge.net/rst.html)
Definition: AnalysisInfo.hh:102
Definition: Event.hh:22
virtual std::string bibKey() const
BibTeX citation key for this article.
Definition: Analysis.hh:189
const PdgIdPair beamIds() const
Incoming beam IDs for this run.
Definition: Analysis.cc:58
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition: Particle.fhh:20
Common base class for Projection and Analysis, used for internal polymorphism.
Definition: ProjectionApplier.hh:18
const std::string histoPath(const std::string &hname) const
Get the canonical histogram path for the named histogram in this analysis.
Definition: Analysis.cc:76
Log & getLog() const
Get a Log object based on the name() property of the calling analysis object.
Definition: Analysis.cc:102
double crossSectionPerEvent() const
Definition: Analysis.cc:179
const std::string & description() const
Get a full description of the analysis. Full textual description of this analysis, what it is useful for, what experimental techniques are applied, etc. Should be treated as a chunk of restructuredText (http://docutils.sourceforge.net/rst.html), with equations to be rendered as LaTeX with amsmath operators.
Definition: AnalysisInfo.hh:92
const std::string & status() const
Whether this analysis is trusted (in any way!)
Definition: AnalysisInfo.hh:167
virtual std::vector< std::string > authors() const
Names &amp; emails of paper/analysis authors.
Definition: Analysis.hh:136
const std::vector< std::string > & todos() const
Any work to be done on this analysis.
Definition: AnalysisInfo.hh:174
Analysis & setNeedsCrossSection(bool needed=true)
Declare whether this analysis needs to know the process cross-section from the generator.
Definition: Analysis.hh:236
AnalysisHandler & handler() const
Access the controlling AnalysisHandler object.
Definition: Analysis.hh:296
std::pair< PdgId, PdgId > PdgIdPair
Typedef for a pair of particle names.
Definition: Particle.fhh:32
AIDA::IHistogramFactory & histogramFactory()
Access the AIDA histogram factory of the controlling AnalysisHandler object.
Definition: Analysis.cc:40
bool isCompatible(const ParticlePair &beams) const
Check if analysis is compatible with the provided beam particle IDs and energies. ...
Definition: Analysis.cc:121
std::string name() const
Definition: AnalysisInfo.hh:38
Definition: AnalysisHandler.hh:29
const std::string & summary() const
Get a short description of the analysis. Short (one sentence) description used as an index entry...
Definition: AnalysisInfo.hh:81
virtual std::vector< std::string > references() const
Journal, and preprint references.
Definition: Analysis.hh:184
AIDA::ITree & tree()
Access the AIDA tree of the controlling AnalysisHandler object.
Definition: Analysis.cc:35
const std::string & experiment() const
Experiment which performed and published this analysis.
Definition: AnalysisInfo.hh:123
const std::vector< PdgIdPair > & beams() const
Beam particle types.
Definition: AnalysisInfo.hh:109
virtual Analysis & setRequiredEnergies(const std::vector< std::pair< double, double > > &requiredEnergies)
Declare the list of valid beam energy pairs, in GeV.
Definition: Analysis.hh:225
const BinEdges & binEdges(const std::string &hname) const
Get bin edges for a named histo (using ref AIDA caching)
Definition: Analysis.cc:208
const std::string & inspireId() const
Get the Inspire (SPIRES replacement) ID code for this analysis.
Definition: AnalysisInfo.hh:55
std::vector< double > BinEdges
Typedef for a collection of bin edges.
Definition: RivetAIDA.fhh:28
AIDA::IDataPointSetFactory & datapointsetFactory()
Access the AIDA histogram factory of the controlling AnalysisHandler object.
Definition: Analysis.cc:45
virtual Analysis & setBeams(PdgId beam1, PdgId beam2)
Definition: Analysis.hh:255
virtual Analysis & setRequiredBeams(const std::vector< PdgIdPair > &requiredBeams)
Declare the allowed pairs of incoming beams required by this analysis.
Definition: Analysis.hh:214
const AnalysisInfo & info() const
Get the actual AnalysisInfo object in which all this metadata is stored.
Definition: Analysis.hh:108
bool needsCrossSection() const
Return true if this analysis needs to know the process cross-section.
Definition: Analysis.hh:232
virtual std::string collider() const
Collider on which the experiment ran.
Definition: Analysis.hh:174
double crossSection() const
Get the process cross-section in pb. Throws if this hasn&#39;t been set.
Definition: Analysis.cc:171
virtual std::string name() const
Get the name of the analysis.
Definition: Analysis.hh:118
Analysis(const std::string &name)
Constructor.
Definition: Analysis.cc:14
const std::string makeAxisCode(size_t datasetId, size_t xAxisId, size_t yAxisId) const
Get the internal histogram name for given d, x and y (cf. HepData)
Definition: Analysis.cc:87
AIDA::IHistogram1D * bookHistogram1D(const std::string &name, size_t nbins, double lower, double upper, const std::string &title="", const std::string &xtitle="", const std::string &ytitle="")
Definition: Analysis.cc:261
virtual std::string year() const
When the original experimental analysis was published.
Definition: Analysis.hh:179
virtual std::string spiresId() const
Get the SPIRES ID code for this analysis (~deprecated).
Definition: Analysis.hh:128
const std::vector< std::string > & references() const
Journal and preprint references.
Definition: AnalysisInfo.hh:146
virtual ~Analysis()
The destructor.
Definition: Analysis.hh:69
const std::string & bibTeX() const
BibTeX citation entry for this article.
Definition: AnalysisInfo.hh:160
void normalize(AIDA::IHistogram1D *&histo, double norm=1.0, bool includeoverflows=true)
Definition: Analysis.cc:479
void setBeams(const std::vector< PdgIdPair > &beams)
Set beam particle types.
Definition: AnalysisInfo.hh:112
virtual const std::vector< std::pair< double, double > > & requiredEnergies() const
Sets of valid beam energy pairs, in GeV.
Definition: Analysis.hh:221
virtual std::string inspireId() const
Get the Inspire ID code for this analysis.
Definition: Analysis.hh:123
AIDA::IProfile1D * bookProfile1D(const std::string &name, size_t nbins, double lower, double upper, const std::string &title="", const std::string &xtitle="", const std::string &ytitle="")
Definition: Analysis.cc:366
void setEnergies(const std::vector< std::pair< double, double > > &energies)
Set the valid beam energies.
Definition: AnalysisInfo.hh:119