rivet is hosted by Hepforge, IPPP Durham
Rivet  2.7.0
Analysis.hh
1 // -*- C++ -*-
2 #ifndef RIVET_Analysis_HH
3 #define RIVET_Analysis_HH
4 
5 #include "Rivet/Config/RivetCommon.hh"
6 #include "Rivet/AnalysisInfo.hh"
7 #include "Rivet/Event.hh"
8 #include "Rivet/Projection.hh"
9 #include "Rivet/ProjectionApplier.hh"
10 #include "Rivet/ProjectionHandler.hh"
11 #include "Rivet/AnalysisLoader.hh"
12 #include "Rivet/Tools/Cuts.hh"
13 #include "Rivet/Tools/Logging.hh"
14 #include "Rivet/Tools/ParticleUtils.hh"
15 #include "Rivet/Tools/BinnedHistogram.hh"
16 #include "Rivet/Tools/RivetMT2.hh"
17 #include "Rivet/Tools/RivetYODA.hh"
18 #include "Rivet/Tools/Percentile.hh"
19 #include "Rivet/Projections/CentralityProjection.hh"
20 
21 
24 #define vetoEvent \
25  do { MSG_DEBUG("Vetoing event on line " << __LINE__ << " of " << __FILE__); return; } while(0)
26 
27 
28 namespace Rivet {
29 
30 
31  // Forward declaration
32  class AnalysisHandler;
33 
52  class Analysis : public ProjectionApplier {
53 
55  friend class AnalysisHandler;
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 && "No AnalysisInfo object :O");
110  return *_info;
111  }
112 
120  virtual std::string name() const {
121  return ( (info().name().empty()) ? _defaultname : info().name() ) + _optstring;
122  }
123  // get name of reference data file, which could be different from plugin name
124  virtual std::string getRefDataName() const {
125  return (info().getRefDataName().empty()) ? _defaultname : info().getRefDataName();
126  }
127 
128  // set name of reference data file, which could be different from plugin name
129  virtual void setRefDataName(const std::string& ref_data="") {
130  info().setRefDataName(!ref_data.empty() ? ref_data : name());
131  }
132 
134  virtual std::string inspireId() const {
135  return info().inspireId();
136  }
137 
139  virtual std::string spiresId() const {
140  return info().spiresId();
141  }
142 
147  virtual std::vector<std::string> authors() const {
148  return info().authors();
149  }
150 
156  virtual std::string summary() const {
157  return info().summary();
158  }
159 
166  virtual std::string description() const {
167  return info().description();
168  }
169 
175  virtual std::string runInfo() const {
176  return info().runInfo();
177  }
178 
180  virtual std::string experiment() const {
181  return info().experiment();
182  }
183 
185  virtual std::string collider() const {
186  return info().collider();
187  }
188 
190  virtual std::string year() const {
191  return info().year();
192  }
193 
195  virtual std::string luminosityfb() const {
196  return info().luminosityfb();
197  }
198 
200  virtual std::vector<std::string> references() const {
201  return info().references();
202  }
203 
205  virtual std::string bibKey() const {
206  return info().bibKey();
207  }
208 
210  virtual std::string bibTeX() const {
211  return info().bibTeX();
212  }
213 
215  virtual std::string status() const {
216  return (info().status().empty()) ? "UNVALIDATED" : info().status();
217  }
218 
220  virtual std::vector<std::string> todos() const {
221  return info().todos();
222  }
223 
224 
226  virtual const std::vector<PdgIdPair>& requiredBeams() const {
227  return info().beams();
228  }
230  virtual Analysis& setRequiredBeams(const std::vector<PdgIdPair>& requiredBeams) {
231  info().setBeams(requiredBeams);
232  return *this;
233  }
234 
235 
237  virtual const std::vector<std::pair<double, double> >& requiredEnergies() const {
238  return info().energies();
239  }
240 
242  virtual const std::vector<std::string> & keywords() const {
243  return info().keywords();
244  }
245 
247  virtual Analysis& setRequiredEnergies(const std::vector<std::pair<double, double> >& requiredEnergies) {
249  return *this;
250  }
251 
252 
255  bool needsCrossSection() const {
256  return info().needsCrossSection();
257  }
260  Analysis& setNeedsCrossSection(bool needed=true) {
261  info().setNeedsCrossSection(needed);
262  return *this;
263  }
264 
266 
267 
269 
270 
273  assert(_info && "No AnalysisInfo object :O");
274  return *_info;
275  }
276 
278 
279 
281 
282 
284  const ParticlePair& beams() const;
285 
287  const PdgIdPair beamIds() const;
288 
290  double sqrtS() const;
291 
293  bool merging() const {
294  return sqrtS() <= 0.0;
295  }
296 
298 
299 
303 
304 
306  bool isCompatible(const ParticlePair& beams) const;
307 
309  bool isCompatible(PdgId beam1, PdgId beam2, double e1, double e2) const;
310 
312  bool isCompatible(const PdgIdPair& beams, const std::pair<double,double>& energies) const;
313 
315 
316 
318  Analysis& setCrossSection(double xs); //, double xserr=0.0);
319 
321  AnalysisHandler& handler() const { return *_analysishandler; }
322 
323 
324 
325  protected:
326 
328  Log& getLog() const;
329 
331  double crossSection() const;
332 
335  double crossSectionPerEvent() const;
336 
340  size_t numEvents() const;
341 
345  double sumW() const;
347  double sumOfWeights() const { return sumW(); }
348 
352  double sumW2() const;
353 
354 
355  protected:
356 
358 
359 
361  const std::string histoDir() const;
362 
364  const std::string histoPath(const std::string& hname) const;
365 
367  const std::string histoPath(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const;
368 
370  const std::string mkAxisCode(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const;
373  const std::string makeAxisCode(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
374  return mkAxisCode(datasetId, xAxisId, yAxisId);
375  }
376 
378 
379 
381 
382 
385  template <typename T=YODA::Scatter2D>
386  const T& refData(const string& hname) const {
387  _cacheRefData();
388  MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
389  if (!_refdata[hname]) {
390  MSG_ERROR("Can't find reference histogram " << hname);
391  throw Exception("Reference data " + hname + " not found.");
392  }
393  return dynamic_cast<T&>(*_refdata[hname]);
394  }
395 
398  template <typename T=YODA::Scatter2D>
399  const T& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
400  const string hname = makeAxisCode(datasetId, xAxisId, yAxisId);
401  return refData(hname);
402  }
403 
405 
406 
408 
409 
411  CounterPtr bookCounter(const std::string& name,
412  const std::string& title="");
413  // const std::string& valtitle=""
414 
418  CounterPtr bookCounter(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
419  const std::string& title="");
420  // const std::string& valtitle=""
421 
423 
424 
426 
427 
429  Histo1DPtr bookHisto1D(const std::string& name,
430  size_t nbins, double lower, double upper,
431  const std::string& title="",
432  const std::string& xtitle="",
433  const std::string& ytitle="");
434 
436  Histo1DPtr bookHisto1D(const std::string& name,
437  const std::vector<double>& binedges,
438  const std::string& title="",
439  const std::string& xtitle="",
440  const std::string& ytitle="");
441 
443  Histo1DPtr bookHisto1D(const std::string& name,
444  const std::initializer_list<double>& binedges,
445  const std::string& title="",
446  const std::string& xtitle="",
447  const std::string& ytitle="");
448 
450  Histo1DPtr bookHisto1D(const std::string& name,
451  const Scatter2D& refscatter,
452  const std::string& title="",
453  const std::string& xtitle="",
454  const std::string& ytitle="");
455 
457  Histo1DPtr bookHisto1D(const std::string& name,
458  const std::string& title="",
459  const std::string& xtitle="",
460  const std::string& ytitle="");
461 
465  Histo1DPtr bookHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
466  const std::string& title="",
467  const std::string& xtitle="",
468  const std::string& ytitle="");
469 
471 
472 
474 
475 
479  Histo2DPtr bookHisto2D(const std::string& name,
480  size_t nxbins, double xlower, double xupper,
481  size_t nybins, double ylower, double yupper,
482  const std::string& title="",
483  const std::string& xtitle="",
484  const std::string& ytitle="",
485  const std::string& ztitle="");
486 
489  Histo2DPtr bookHisto2D(const std::string& name,
490  const std::vector<double>& xbinedges,
491  const std::vector<double>& ybinedges,
492  const std::string& title="",
493  const std::string& xtitle="",
494  const std::string& ytitle="",
495  const std::string& ztitle="");
496 
499  Histo2DPtr bookHisto2D(const std::string& name,
500  const std::initializer_list<double>& xbinedges,
501  const std::initializer_list<double>& ybinedges,
502  const std::string& title="",
503  const std::string& xtitle="",
504  const std::string& ytitle="",
505  const std::string& ztitle="");
506 
508  Histo2DPtr bookHisto2D(const std::string& name,
509  const Scatter3D& refscatter,
510  const std::string& title="",
511  const std::string& xtitle="",
512  const std::string& ytitle="",
513  const std::string& ztitle="");
514 
516  Histo2DPtr bookHisto2D(const std::string& name,
517  const std::string& title="",
518  const std::string& xtitle="",
519  const std::string& ytitle="",
520  const std::string& ztitle="");
521 
525  Histo2DPtr bookHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
526  const std::string& title="",
527  const std::string& xtitle="",
528  const std::string& ytitle="",
529  const std::string& ztitle="");
530 
532 
533 
535 
536 
538  Profile1DPtr bookProfile1D(const std::string& name,
539  size_t nbins, double lower, double upper,
540  const std::string& title="",
541  const std::string& xtitle="",
542  const std::string& ytitle="");
543 
545  Profile1DPtr bookProfile1D(const std::string& name,
546  const std::vector<double>& binedges,
547  const std::string& title="",
548  const std::string& xtitle="",
549  const std::string& ytitle="");
550 
552  Profile1DPtr bookProfile1D(const std::string& name,
553  const std::initializer_list<double>& binedges,
554  const std::string& title="",
555  const std::string& xtitle="",
556  const std::string& ytitle="");
557 
559  Profile1DPtr bookProfile1D(const std::string& name,
560  const Scatter2D& refscatter,
561  const std::string& title="",
562  const std::string& xtitle="",
563  const std::string& ytitle="");
564 
566  Profile1DPtr bookProfile1D(const std::string& name,
567  const std::string& title="",
568  const std::string& xtitle="",
569  const std::string& ytitle="");
570 
574  Profile1DPtr bookProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
575  const std::string& title="",
576  const std::string& xtitle="",
577  const std::string& ytitle="");
578 
580 
581 
583 
584 
588  Profile2DPtr bookProfile2D(const std::string& name,
589  size_t nxbins, double xlower, double xupper,
590  size_t nybins, double ylower, double yupper,
591  const std::string& title="",
592  const std::string& xtitle="",
593  const std::string& ytitle="",
594  const std::string& ztitle="");
595 
598  Profile2DPtr bookProfile2D(const std::string& name,
599  const std::vector<double>& xbinedges,
600  const std::vector<double>& ybinedges,
601  const std::string& title="",
602  const std::string& xtitle="",
603  const std::string& ytitle="",
604  const std::string& ztitle="");
605 
608  Profile2DPtr bookProfile2D(const std::string& name,
609  const std::initializer_list<double>& xbinedges,
610  const std::initializer_list<double>& ybinedges,
611  const std::string& title="",
612  const std::string& xtitle="",
613  const std::string& ytitle="",
614  const std::string& ztitle="");
615 
617  Profile2DPtr bookProfile2D(const std::string& name,
618  const Scatter3D& refscatter,
619  const std::string& title="",
620  const std::string& xtitle="",
621  const std::string& ytitle="",
622  const std::string& ztitle="");
623 
625  Profile2DPtr bookProfile2D(const std::string& name,
626  const std::string& title="",
627  const std::string& xtitle="",
628  const std::string& ytitle="",
629  const std::string& ztitle="");
630 
634  Profile2DPtr bookProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
635  const std::string& title="",
636  const std::string& xtitle="",
637  const std::string& ytitle="",
638  const std::string& ztitle="");
639 
641 
642 
644 
645 
656  Scatter2DPtr bookScatter2D(const std::string& name,
657  bool copy_pts=false,
658  const std::string& title="",
659  const std::string& xtitle="",
660  const std::string& ytitle="");
661 
672  Scatter2DPtr bookScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
673  bool copy_pts=false,
674  const std::string& title="",
675  const std::string& xtitle="",
676  const std::string& ytitle="");
677 
681  Scatter2DPtr bookScatter2D(const std::string& name,
682  size_t npts, double lower, double upper,
683  const std::string& title="",
684  const std::string& xtitle="",
685  const std::string& ytitle="");
686 
690  Scatter2DPtr bookScatter2D(const std::string& hname,
691  const std::vector<double>& binedges,
692  const std::string& title,
693  const std::string& xtitle,
694  const std::string& ytitle);
695 
697  Scatter2DPtr bookScatter2D(const Scatter2DPtr scPtr,
698  const std::string& path, const std::string& title = "",
699  const std::string& xtitle = "", const std::string& ytitle = "" );
700 
702 
703 
704  public:
705 
707 
708 
710  std::string getOption(std::string optname) {
711  if ( _options.find(optname) != _options.end() )
712  return _options.find(optname)->second;
713  return "";
714  }
715 
718  template<typename T>
719  T getOption(std::string optname, T def) {
720  if (_options.find(optname) == _options.end()) return def;
721  std::stringstream ss;
722  ss << _options.find(optname)->second;
723  T ret;
724  ss >> ret;
725  return ret;
726  }
727 
729  const CentralityProjection&
747  string calAnaName, string calHistName,
748  const string projName, bool increasing = false);
749 
756  template <class T>
757  Percentile<T> bookPercentile(string projName,
758  vector<pair<float, float> > centralityBins,
759  vector<tuple<int, int, int> > ref) {
760  typedef typename ReferenceTraits<T>::RefT RefT;
761  Percentile<T> pctl(this, projName);
762 
763  const int nCent = centralityBins.size();
764  for (int iCent = 0; iCent < nCent; ++iCent) {
765  const string axisCode = makeAxisCode(std::get<0>(ref[iCent]),
766  std::get<1>(ref[iCent]),
767  std::get<2>(ref[iCent]));
768  const RefT & refscatter = refData<RefT>(axisCode);
769  shared_ptr<T> ao = addOrGetCompatAO(make_shared<T>(refscatter, histoPath(axisCode)));
770  CounterPtr cnt =
771  addOrGetCompatAO(make_shared<Counter>(histoPath("TMP/COUNTER/" + axisCode)));
772  pctl.add(ao, cnt, centralityBins[iCent]);
773  }
774  return pctl;
775  }
776 
783  template <class T>
785  tuple<int, int, int> ref) {
786  typedef typename ReferenceTraits<T>::RefT RefT;
787  PercentileXaxis<T> pctl(this, projName);
788 
789  const string axisCode = makeAxisCode(std::get<0>(ref),
790  std::get<1>(ref),
791  std::get<2>(ref));
792  const RefT & refscatter = refData<RefT>(axisCode);
793  shared_ptr<T> ao = addOrGetCompatAO(make_shared<T>(refscatter, histoPath(axisCode)));
794  pctl.add(proj, ao, make_shared<Counter>());
795 
796  return pctl;
797  }
798 
799 
800 
803 
804 
806  void scale(CounterPtr cnt, double factor);
807 
811  void scale(const std::vector<CounterPtr>& cnts, double factor) {
812  for (auto& c : cnts) scale(c, factor);
813  }
815  template <std::size_t array_size>
816  void scale(const CounterPtr (&cnts)[array_size], double factor) {
817  // for (size_t i = 0; i < std::extent<decltype(cnts)>::value; ++i) scale(cnts[i], factor);
818  for (auto& c : cnts) scale(c, factor);
819  }
820 
821 
823  void normalize(Histo1DPtr histo, double norm=1.0, bool includeoverflows=true);
824 
828  void normalize(const std::vector<Histo1DPtr>& histos, double norm=1.0, bool includeoverflows=true) {
829  for (auto& h : histos) normalize(h, norm, includeoverflows);
830  }
832  template <std::size_t array_size>
833  void normalize(const Histo1DPtr (&histos)[array_size], double norm=1.0, bool includeoverflows=true) {
834  for (auto& h : histos) normalize(h, norm, includeoverflows);
835  }
836 
838  void scale(Histo1DPtr histo, double factor);
839 
843  void scale(const std::vector<Histo1DPtr>& histos, double factor) {
844  for (auto& h : histos) scale(h, factor);
845  }
847  template <std::size_t array_size>
848  void scale(const Histo1DPtr (&histos)[array_size], double factor) {
849  for (auto& h : histos) scale(h, factor);
850  }
851 
852 
854  void normalize(Histo2DPtr histo, double norm=1.0, bool includeoverflows=true);
855 
859  void normalize(const std::vector<Histo2DPtr>& histos, double norm=1.0, bool includeoverflows=true) {
860  for (auto& h : histos) normalize(h, norm, includeoverflows);
861  }
863  template <std::size_t array_size>
864  void normalize(const Histo2DPtr (&histos)[array_size], double norm=1.0, bool includeoverflows=true) {
865  for (auto& h : histos) normalize(h, norm, includeoverflows);
866  }
867 
869  void scale(Histo2DPtr histo, double factor);
870 
874  void scale(const std::vector<Histo2DPtr>& histos, double factor) {
875  for (auto& h : histos) scale(h, factor);
876  }
878  template <std::size_t array_size>
879  void scale(const Histo2DPtr (&histos)[array_size], double factor) {
880  for (auto& h : histos) scale(h, factor);
881  }
882 
883 
887  void divide(CounterPtr c1, CounterPtr c2, Scatter1DPtr s) const;
888 
892  void divide(const YODA::Counter& c1, const YODA::Counter& c2, Scatter1DPtr s) const;
893 
894 
898  void divide(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const;
899 
903  void divide(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const;
904 
905 
909  void divide(Profile1DPtr p1, Profile1DPtr p2, Scatter2DPtr s) const;
910 
914  void divide(const YODA::Profile1D& p1, const YODA::Profile1D& p2, Scatter2DPtr s) const;
915 
916 
920  void divide(Histo2DPtr h1, Histo2DPtr h2, Scatter3DPtr s) const;
921 
925  void divide(const YODA::Histo2D& h1, const YODA::Histo2D& h2, Scatter3DPtr s) const;
926 
927 
931  void divide(Profile2DPtr p1, Profile2DPtr p2, Scatter3DPtr s) const;
932 
936  void divide(const YODA::Profile2D& p1, const YODA::Profile2D& p2, Scatter3DPtr s) const;
937 
938 
942  void efficiency(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const;
943 
947  void efficiency(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const;
948 
949 
953  void asymm(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const;
954 
958  void asymm(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const;
959 
960 
964  void integrate(Histo1DPtr h, Scatter2DPtr s) const;
965 
969  void integrate(const Histo1D& h, Scatter2DPtr s) const;
970 
972 
973 
974  public:
975 
977  const vector<AnalysisObjectPtr>& analysisObjects() const {
978  return _analysisobjects;
979  }
980 
981 
982  protected:
983 
985 
986 
988  void addAnalysisObject(AnalysisObjectPtr ao);
989 
996  template <typename AO=YODA::AnalysisObject>
997  std::shared_ptr<AO> addOrGetCompatAO(std::shared_ptr<AO> aonew) {
998  foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
999  if ( ao->path() == aonew->path() ) {
1000  std::shared_ptr<AO> aoold = dynamic_pointer_cast<AO>(ao);
1001  if ( aoold && bookingCompatible(aonew, aoold) ) {
1002  MSG_TRACE("Bound pre-existing data object " << aonew->path()
1003  << " for " << name());
1004  return aoold;
1005  } else {
1006  MSG_WARNING("Found incompatible pre-existing data object with same path "
1007  << aonew->path() << " for " << name());
1008  }
1009  }
1010  }
1011  MSG_TRACE("Registered " << aonew->annotation("Type") << " " << aonew->path()
1012  << " for " << name());
1013  addAnalysisObject(aonew);
1014  return aonew;
1015  }
1016 
1018  template <typename AO=YODA::AnalysisObject>
1019  const std::shared_ptr<AO> getAnalysisObject(const std::string& name) const {
1020  foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1021  if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1022  }
1023  throw LookupError("Data object " + histoPath(name) + " not found");
1024  }
1025 
1027  template <typename AO=YODA::AnalysisObject>
1028  std::shared_ptr<AO> getAnalysisObject(const std::string& name) {
1029  foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1030  if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1031  }
1032  throw LookupError("Data object " + histoPath(name) + " not found");
1033  }
1034 
1036  void removeAnalysisObject(const std::string& path);
1037 
1039  void removeAnalysisObject(AnalysisObjectPtr ao);
1040 
1042  vector<AnalysisObjectPtr> getAllData(bool includeorphans) const;
1043 
1047  template <typename AO=YODA::AnalysisObject>
1048  std::shared_ptr<AO> getAnalysisObject(const std::string & ananame,
1049  const std::string& name) {
1050  std::string path = "/" + ananame + "/" + name;
1051  for ( AnalysisObjectPtr ao : getAllData(true) ) {
1052  if ( ao->path() == path )
1053  return dynamic_pointer_cast<AO>(ao);
1054  }
1055  return std::shared_ptr<AO>();
1056  }
1057 
1059  const Histo1DPtr getHisto1D(const std::string& name) const {
1060  return getAnalysisObject<Histo1D>(name);
1061  }
1062 
1064  Histo1DPtr getHisto1D(const std::string& name) {
1065  return getAnalysisObject<Histo1D>(name);
1066  }
1067 
1069  const Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
1070  return getAnalysisObject<Histo1D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1071  }
1072 
1074  Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) {
1075  return getAnalysisObject<Histo1D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1076  }
1077 
1078 
1080  const Histo2DPtr getHisto2D(const std::string& name) const {
1081  return getAnalysisObject<Histo2D>(name);
1082  }
1083 
1085  Histo2DPtr getHisto2D(const std::string& name) {
1086  return getAnalysisObject<Histo2D>(name);
1087  }
1088 
1090  const Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
1091  return getAnalysisObject<Histo2D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1092  }
1093 
1095  Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) {
1096  return getAnalysisObject<Histo2D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1097  }
1098 
1099 
1101  const Profile1DPtr getProfile1D(const std::string& name) const {
1102  return getAnalysisObject<Profile1D>(name);
1103  }
1104 
1106  Profile1DPtr getProfile1D(const std::string& name) {
1107  return getAnalysisObject<Profile1D>(name);
1108  }
1109 
1111  const Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
1112  return getAnalysisObject<Profile1D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1113  }
1114 
1116  Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) {
1117  return getAnalysisObject<Profile1D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1118  }
1119 
1120 
1122  const Profile2DPtr getProfile2D(const std::string& name) const {
1123  return getAnalysisObject<Profile2D>(name);
1124  }
1125 
1127  Profile2DPtr getProfile2D(const std::string& name) {
1128  return getAnalysisObject<Profile2D>(name);
1129  }
1130 
1132  const Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
1133  return getAnalysisObject<Profile2D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1134  }
1135 
1137  Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) {
1138  return getAnalysisObject<Profile2D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1139  }
1140 
1141 
1143  const Scatter2DPtr getScatter2D(const std::string& name) const {
1144  return getAnalysisObject<Scatter2D>(name);
1145  }
1146 
1148  Scatter2DPtr getScatter2D(const std::string& name) {
1149  return getAnalysisObject<Scatter2D>(name);
1150  }
1151 
1153  const Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
1154  return getAnalysisObject<Scatter2D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1155  }
1156 
1158  Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) {
1159  return getAnalysisObject<Scatter2D>(makeAxisCode(datasetId, xAxisId, yAxisId));
1160  }
1161 
1163 
1164 
1165  private:
1166 
1168  string _defaultname;
1169 
1171  unique_ptr<AnalysisInfo> _info;
1172 
1175  vector<AnalysisObjectPtr> _analysisobjects;
1176 
1178 
1179  double _crossSection;
1180  bool _gotCrossSection;
1182 
1184  AnalysisHandler* _analysishandler;
1185 
1188  mutable std::map<std::string, AnalysisObjectPtr> _refdata;
1189 
1191  map<string, string> _options;
1192 
1194  string _optstring;
1195 
1196  private:
1197 
1199 
1200 
1202  void _cacheRefData() const;
1203 
1205 
1206 
1209  Analysis& operator=(const Analysis&);
1210 
1211  };
1212 
1213 
1214 }
1215 
1216 
1217 // Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
1218 #include "Rivet/AnalysisBuilder.hh"
1219 
1222 #define DECLARE_RIVET_PLUGIN(clsname) Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
1223 
1226 // #define DECLARE_ALIASED_RIVET_PLUGIN(clsname, alias) Rivet::AnalysisBuilder<clsname> plugin_ ## clsname ## ( ## #alias ## )
1227 #define DECLARE_ALIASED_RIVET_PLUGIN(clsname, alias) DECLARE_RIVET_PLUGIN(clsname)( #alias )
1228 
1231 #define DEFAULT_RIVET_ANALYSIS_CONSTRUCTOR(clsname) clsname() : Analysis(# clsname) {}
1232 
1235 #define DEFAULT_RIVET_ANALYSIS_CTOR(clsname) DEFAULT_RIVET_ANALYSIS_CONSTRUCTOR(clsname)
1236 
1237 
1238 
1239 #endif
double sumOfWeights() const
Alias.
Definition: Analysis.hh:347
Definition: ALICE_2010_I880049.cc:13
virtual std::string inspireId() const
Get the Inspire ID code for this analysis.
Definition: Analysis.hh:134
const std::string & summary() const
Get a short description of the analysis. Short (one sentence) description used as an index entry...
Definition: AnalysisInfo.hh:89
const std::string histoDir() const
Get the canonical histogram "directory" path for this analysis.
Definition: Analysis.cc:42
void scale(const CounterPtr(&cnts)[array_size], double factor)
Definition: Analysis.hh:816
void normalize(const std::vector< Histo1DPtr > &histos, double norm=1.0, bool includeoverflows=true)
Definition: Analysis.hh:828
std::shared_ptr< AO > addOrGetCompatAO(std::shared_ptr< AO > aonew)
Definition: Analysis.hh:997
virtual std::string summary() const
Get a short description of the analysis.
Definition: Analysis.hh:156
Scatter2DPtr bookScatter2D(const std::string &name, bool copy_pts=false, const std::string &title="", const std::string &xtitle="", const std::string &ytitle="")
Book a 2-dimensional data point set with the given name.
Definition: Analysis.cc:560
void setNeedsCrossSection(bool needXsec)
Return true if this analysis needs to know the process cross-section.
Definition: AnalysisInfo.hh:215
bool needsCrossSection() const
Definition: Analysis.hh:255
CentralityProjection is used together with the percentile-based analysis objects Percentile and Perce...
Definition: CentralityProjection.hh:31
Histo2DPtr bookHisto2D(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:303
Definition: AnalysisInfo.hh:11
Base class for projections returning a single floating point value.
Definition: SingleValueProjection.hh:18
const std::string & status() const
Whether this analysis is trusted (in any way!)
Definition: AnalysisInfo.hh:182
virtual const std::vector< std::pair< double, double > > & requiredEnergies() const
Sets of valid beam energy pairs, in GeV.
Definition: Analysis.hh:237
void scale(const Histo2DPtr(&histos)[array_size], double factor)
Definition: Analysis.hh:879
const std::shared_ptr< AO > getAnalysisObject(const std::string &name) const
Get a data object from the histogram system.
Definition: Analysis.hh:1019
const Profile1DPtr getProfile1D(const std::string &name) const
Get a named Profile1D object from the histogram system.
Definition: Analysis.hh:1101
virtual std::string year() const
When the original experimental analysis was published.
Definition: Analysis.hh:190
const std::string histoPath(const std::string &hname) const
Get the canonical histogram path for the named histogram in this analysis.
Definition: Analysis.cc:56
bool isCompatible(const ParticlePair &beams) const
Check if analysis is compatible with the provided beam particle IDs and energies. ...
Definition: Analysis.cc:107
virtual std::string spiresId() const
Get the SPIRES ID code for this analysis (~deprecated).
Definition: Analysis.hh:139
void setRefDataName(const std::string &name)
Set the reference data name of the analysis (if different from plugin name).
Definition: AnalysisInfo.hh:60
const std::string & bibTeX() const
BibTeX citation entry for this article.
Definition: AnalysisInfo.hh:175
virtual std::vector< std::string > todos() const
Any work to be done on this analysis.
Definition: Analysis.hh:220
void scale(const std::vector< Histo1DPtr > &histos, double factor)
Definition: Analysis.hh:843
virtual void finalize()
Definition: Analysis.hh:95
void add(shared_ptr< T > ao, CounterPtr cnt, pair< float, float > cent={0.0, 100.0})
add a new percentile bin.
Definition: Percentile.hh:119
const CentralityProjection & declareCentrality(const SingleValueProjection &proj, string calAnaName, string calHistName, const string projName, bool increasing=false)
Book a CentralityProjection.
Definition: Analysis.cc:865
bool bookingCompatible(TPtr a, TPtr b)
Definition: RivetYODA.hh:107
Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId)
Get a Histo1D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1074
const Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Get a Profile1D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1111
virtual std::string experiment() const
Experiment which performed and published this analysis.
Definition: Analysis.hh:180
vector< AnalysisObjectPtr > getAllData(bool includeorphans) const
Get all data object from the AnalysisHandler.
Definition: Analysis.cc:215
virtual void analyze(const Event &event)=0
std::shared_ptr< AO > getAnalysisObject(const std::string &name)
Get a data object from the histogram system (non-const)
Definition: Analysis.hh:1028
const std::string & bibKey() const
BibTeX citation key for this article.
Definition: AnalysisInfo.hh:168
AnalysisInfo & info()
Get the actual AnalysisInfo object in which all this metadata is stored (non-const).
Definition: Analysis.hh:272
Definition: RivetYODA.hh:54
virtual std::string status() const
Whether this analysis is trusted (in any way!)
Definition: Analysis.hh:215
virtual void init()
Definition: Analysis.hh:82
The Percentile class for centrality binning.
Definition: Percentile.hh:197
const std::vector< std::string > & todos() const
Any work to be done on this analysis.
Definition: AnalysisInfo.hh:189
double crossSection() const
Get the process cross-section in pb. Throws if this hasn&#39;t been set.
Definition: Analysis.cc:188
Profile1DPtr getProfile1D(const std::string &name)
Get a named Profile1D object from the histogram system (non-const)
Definition: Analysis.hh:1106
Analysis & setCrossSection(double xs)
Set the cross section from the generator.
Definition: Analysis.cc:182
const std::string makeAxisCode(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Definition: Analysis.hh:373
Definition: Logging.hh:9
virtual std::vector< std::string > references() const
Journal, and preprint references.
Definition: Analysis.hh:200
Profile2DPtr bookProfile2D(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:463
const std::vector< std::string > & authors() const
Names & emails of paper/analysis authors. Names and email of authors in &#39;NAME <EMAIL>&#39; format...
Definition: AnalysisInfo.hh:79
const std::vector< PdgIdPair > & beams() const
Beam particle types.
Definition: AnalysisInfo.hh:117
const std::string mkAxisCode(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Get the internal histogram name for given d, x and y (cf. HepData)
Definition: Analysis.cc:67
Percentile< T > bookPercentile(string projName, vector< pair< float, float > > centralityBins, vector< tuple< int, int, int > > ref)
Book a Pecentile wrapper around AnalysisObjects.
Definition: Analysis.hh:757
const std::string & experiment() const
Experiment which performed and published this analysis.
Definition: AnalysisInfo.hh:131
void normalize(const Histo1DPtr(&histos)[array_size], double norm=1.0, bool includeoverflows=true)
Definition: Analysis.hh:833
std::string getOption(std::string optname)
Get an option for this analysis instance as a string.
Definition: Analysis.hh:710
const std::string & spiresId() const
Get the SPIRES ID code for this analysis.
Definition: AnalysisInfo.hh:70
const std::vector< std::string > & keywords() const
Analysis Keywords for grouping etc.
Definition: AnalysisInfo.hh:165
This is the base class of all analysis classes in Rivet.
Definition: Analysis.hh:52
void efficiency(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const
Definition: Analysis.cc:702
Definition: Event.hh:22
const T & refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Definition: Analysis.hh:399
double sumW() const
Get the sum of event weights seen (via the analysis handler).
Definition: Analysis.cc:95
std::shared_ptr< AO > getAnalysisObject(const std::string &ananame, const std::string &name)
Definition: Analysis.hh:1048
Common base class for Projection and Analysis, used for internal polymorphism.
Definition: ProjectionApplier.hh:21
Histo1DPtr getHisto1D(const std::string &name)
Get a named Histo1D object from the histogram system (non-const)
Definition: Analysis.hh:1064
The PercentileXaxis class for centrality binning.
Definition: Percentile.hh:270
virtual std::vector< std::string > authors() const
Names & emails of paper/analysis authors.
Definition: Analysis.hh:147
AnalysisHandler & handler() const
Access the controlling AnalysisHandler object.
Definition: Analysis.hh:321
virtual std::string name() const
Get the name of the analysis.
Definition: Analysis.hh:120
const Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Get a Profile2D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1132
bool merging() const
Check if we are running rivet-merge.
Definition: Analysis.hh:293
void scale(const std::vector< CounterPtr > &cnts, double factor)
Definition: Analysis.hh:811
const Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Get a Histo2D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1090
Error relating to looking up analyis objects in the register.
Definition: Exceptions.hh:60
void asymm(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const
Definition: Analysis.cc:715
virtual const std::vector< std::string > & keywords() const
Get vector of analysis keywords.
Definition: Analysis.hh:242
Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId)
Get a Histo2D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1095
Analysis & setNeedsCrossSection(bool needed=true)
Definition: Analysis.hh:260
Error Exception
Rivet::Exception is a synonym for Rivet::Error.
Definition: Exceptions.hh:18
size_t numEvents() const
Get the number of events seen (via the analysis handler).
Definition: Analysis.cc:91
void removeAnalysisObject(const std::string &path)
Unregister a data object from the histogram system (by name)
Definition: Analysis.cc:845
Profile1DPtr bookProfile1D(const std::string &name, size_t nbins, double lower, double upper, const std::string &title="", const std::string &xtitle="", const std::string &ytitle="")
Book a 1D profile histogram with nbins uniformly distributed across the range lower - upper ...
Definition: Analysis.cc:390
double sqrtS() const
Centre of mass energy for this run.
Definition: Analysis.cc:29
Definition: AnalysisHandler.hh:29
CounterPtr bookCounter(const std::string &name, const std::string &title="")
Book a counter.
Definition: Analysis.cc:219
virtual std::string bibKey() const
BibTeX citation key for this article.
Definition: Analysis.hh:205
Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId)
Get a Profile2D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1137
void normalize(const Histo2DPtr(&histos)[array_size], double norm=1.0, bool includeoverflows=true)
Definition: Analysis.hh:864
virtual std::string luminosityfb() const
The luminosity in inverse femtobarn.
Definition: Analysis.hh:195
virtual Analysis & setRequiredEnergies(const std::vector< std::pair< double, double > > &requiredEnergies)
Declare the list of valid beam energy pairs, in GeV.
Definition: Analysis.hh:247
Histo2DPtr getHisto2D(const std::string &name)
Get a named Histo2D object from the histogram system (non-const)
Definition: Analysis.hh:1085
const ParticlePair & beams() const
Incoming beams for this run.
Definition: Analysis.cc:33
Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId)
Get a Profile1D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1116
Profile2DPtr getProfile2D(const std::string &name)
Get a named Profile2D object from the histogram system (non-const)
Definition: Analysis.hh:1127
double sumW2() const
Get the sum of squared event weights seen (via the analysis handler).
Definition: Analysis.cc:99
const std::string & luminosityfb() const
The integrated data luminosity of the data set.
Definition: AnalysisInfo.hh:153
virtual Analysis & setRequiredBeams(const std::vector< PdgIdPair > &requiredBeams)
Declare the allowed pairs of incoming beams required by this analysis.
Definition: Analysis.hh:230
Histo1DPtr bookHisto1D(const std::string &name, size_t nbins, double lower, double upper, const std::string &title="", const std::string &xtitle="", const std::string &ytitle="")
Book a 1D histogram with nbins uniformly distributed across the range lower - upper ...
Definition: Analysis.cc:231
const std::vector< std::string > & references() const
Journal and preprint references.
Definition: AnalysisInfo.hh:159
const T & refData(const string &hname) const
Definition: Analysis.hh:386
const Profile2DPtr getProfile2D(const std::string &name) const
Get a named Profile2D object from the histogram system.
Definition: Analysis.hh:1122
std::string getRefDataName() const
Get the reference data name of the analysis (if different from plugin name).
Definition: AnalysisInfo.hh:54
void addAnalysisObject(AnalysisObjectPtr ao)
Register a data object in the histogram system.
Definition: Analysis.cc:840
virtual std::string runInfo() const
Information about the events needed as input for this analysis.
Definition: Analysis.hh:175
void scale(const std::vector< Histo2DPtr > &histos, double factor)
Definition: Analysis.hh:874
void scale(CounterPtr cnt, double factor)
Multiplicatively scale the given counter, cnt, by factor factor.
Definition: Analysis.cc:728
virtual std::string description() const
Get a full description of the analysis.
Definition: Analysis.hh:166
bool needsCrossSection() const
Return true if this analysis needs to know the process cross-section.
Definition: AnalysisInfo.hh:212
void integrate(Histo1DPtr h, Scatter2DPtr s) const
Definition: Analysis.cc:819
Analysis(const std::string &name)
Constructor.
Definition: Analysis.cc:15
void normalize(Histo1DPtr histo, double norm=1.0, bool includeoverflows=true)
Normalize the given histogram, histo, to area = norm.
Definition: Analysis.cc:747
const std::string & year() const
When the original experimental analysis was published. When the refereed paper on which this is based...
Definition: AnalysisInfo.hh:147
const Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Get a Histo1D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1069
Log & getLog() const
Get a Log object based on the name() property of the calling analysis object.
Definition: Analysis.cc:82
const Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Get a Scatter2D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1153
virtual std::string bibTeX() const
BibTeX citation entry for this article.
Definition: Analysis.hh:210
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:100
T getOption(std::string optname, T def)
Definition: Analysis.hh:719
void normalize(const std::vector< Histo2DPtr > &histos, double norm=1.0, bool includeoverflows=true)
Definition: Analysis.hh:859
void scale(const Histo1DPtr(&histos)[array_size], double factor)
Definition: Analysis.hh:848
virtual std::string collider() const
Collider on which the experiment ran.
Definition: Analysis.hh:185
double crossSectionPerEvent() const
Definition: Analysis.cc:196
virtual ~Analysis()
The destructor.
Definition: Analysis.hh:69
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:110
const vector< AnalysisObjectPtr > & analysisObjects() const
List of registered analysis data objects.
Definition: Analysis.hh:977
const Histo1DPtr getHisto1D(const std::string &name) const
Get a named Histo1D object from the histogram system.
Definition: Analysis.hh:1059
const Scatter2DPtr getScatter2D(const std::string &name) const
Get a named Scatter2D object from the histogram system.
Definition: Analysis.hh:1143
void setBeams(const std::vector< PdgIdPair > &beams)
Set beam particle types.
Definition: AnalysisInfo.hh:120
const std::string & inspireId() const
Get the Inspire (SPIRES replacement) ID code for this analysis.
Definition: AnalysisInfo.hh:63
Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId)
Get a Scatter2D object from the histogram system by axis ID codes (non-const)
Definition: Analysis.hh:1158
const std::string & collider() const
Collider on which the experiment ran.
Definition: AnalysisInfo.hh:138
void divide(CounterPtr c1, CounterPtr c2, Scatter1DPtr s) const
Definition: Analysis.cc:634
virtual const std::vector< PdgIdPair > & requiredBeams() const
Return the allowed pairs of incoming beams required by this analysis.
Definition: Analysis.hh:226
const PdgIdPair beamIds() const
Incoming beam IDs for this run.
Definition: Analysis.cc:37
const AnalysisInfo & info() const
Get the actual AnalysisInfo object in which all this metadata is stored.
Definition: Analysis.hh:108
const Histo2DPtr getHisto2D(const std::string &name) const
Get a named Histo2D object from the histogram system.
Definition: Analysis.hh:1080
void setEnergies(const std::vector< std::pair< double, double > > &energies)
Set the valid beam energies.
Definition: AnalysisInfo.hh:127
PercentileXaxis< T > bookPercentileXaxis(string projName, tuple< int, int, int > ref)
Book Pecentile wrappers around AnalysisObjects.
Definition: Analysis.hh:784
const std::vector< std::pair< double, double > > & energies() const
Sets of valid beam energies.
Definition: AnalysisInfo.hh:124
Scatter2DPtr getScatter2D(const std::string &name)
Get a named Scatter2D object from the histogram system (non-const)
Definition: Analysis.hh:1148