rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.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/RivetHDF5.hh"
16#include "Rivet/Tools/HistoGroup.hh"
17#include "Rivet/Tools/RivetMT2.hh"
18#include "Rivet/Tools/RivetPaths.hh"
19#include "Rivet/Tools/RivetYODA.hh"
20#include "Rivet/Tools/Percentile.hh"
21#include "Rivet/Tools/Cutflow.hh"
22#include "Rivet/Projections/CentralityProjection.hh"
23#include <tuple>
24
25
28#define vetoEvent \
29 do { MSG_DEBUG("Vetoing event on line " << __LINE__ << " of " << __FILE__); return; } while(0)
30
31
32namespace Rivet {
33
34
35 // Convenience for analysis writers
36 using std::cout;
37 using std::cerr;
38 using std::endl;
39 using std::tuple;
40 using std::stringstream;
41 using std::swap;
42 using std::numeric_limits;
43
44
45 // Forward declaration
46 class AnalysisHandler;
47
48
67 class Analysis : public ProjectionApplier {
68 public:
69
71 friend class AnalysisHandler;
72
73
75 Analysis(const std::string& name);
76
78 virtual ~Analysis() {}
79
81 Analysis& operator = (const Analysis&) = delete;
82
83
84 public:
85
88
92 virtual void init() { }
93
98 virtual void analyze(const Event& event) = 0;
99
105 virtual void finalize() { }
106
111 this->_syncDeclQueue();
112 this->markAsOwned();
113 }
114
116
117
118 public:
119
125
127 void loadInfo() { info().parseInfoFile(); }
128
130 const AnalysisInfo& info() const {
131 if (!_info) throw Error("No AnalysisInfo object :-O");
132 return *_info;
133 }
134
142 virtual std::string name() const {
143 return ( (info().name().empty()) ? _defaultname : info().name() ) + _optstring;
144 }
145
150 std::string analysisDataPath(const std::string& extn, const std::string& suffix="") {
151 string filename = name() + (suffix.empty() ? "" : "-") + suffix + "." + extn;
152 return findAnalysisDataFile(filename);
153 }
154
156 virtual std::string inspireID() const {
157 return info().inspireID();
158 }
159
161 virtual std::string spiresID() const {
162 return info().spiresID();
163 }
164
169 virtual std::vector<std::string> authors() const {
170 return info().authors();
171 }
172
178 virtual std::string summary() const {
179 return info().summary();
180 }
181
188 virtual std::string description() const {
189 return info().description();
190 }
191
197 virtual std::string runInfo() const {
198 return info().runInfo();
199 }
200
202 virtual std::string experiment() const {
203 return info().experiment();
204 }
205
207 virtual std::string collider() const {
208 return info().collider();
209 }
210
212 virtual std::string year() const {
213 return info().year();
214 }
215
217 virtual double luminosityfb() const {
218 return info().luminosityfb();
219 }
221 virtual double luminosity() const {
222 return info().luminosity();
223 }
225 double luminositypb() const { return luminosity(); }
226
228 virtual std::vector<std::string> references() const {
229 return info().references();
230 }
231
233 virtual std::string bibKey() const {
234 return info().bibKey();
235 }
236
238 virtual std::string bibTeX() const {
239 return info().bibTeX();
240 }
241
243 virtual std::string status() const {
244 return (info().status().empty()) ? "UNVALIDATED" : info().status();
245 }
246
248 virtual std::string warning() const {
249 return info().warning();
250 }
251
253 virtual std::vector<std::string> todos() const {
254 return info().todos();
255 }
256
258 virtual std::vector<std::string> validation() const {
259 return info().validation();
260 }
261
263 virtual bool reentrant() const {
264 return info().reentrant();
265 }
266
268 virtual const std::vector<std::string>& keywords() const {
269 return info().keywords();
270 }
271
273 virtual std::string refMatch() const {
274 return info().refMatch();
275 }
276
278 virtual std::string refUnmatch() const {
279 return info().refUnmatch();
280 }
281
283 virtual std::string writerDoublePrecision() const {
284 return info().writerDoublePrecision();
285 }
286
288 virtual const std::vector<PdgIdPair>& requiredBeamIDs() const {
289 return info().beamIDs();
290 }
292 virtual Analysis& setRequiredBeamIDs(const std::vector<PdgIdPair>& beamids) {
293 info().setBeamIDs(beamids);
294 return *this;
295 }
296
298 virtual const std::vector<std::pair<double, double> >& requiredBeamEnergies() const {
299 return info().energies();
300 }
302 virtual Analysis& setRequiredBeamEnergies(const std::vector<std::pair<double, double> >& energies) {
303 info().setEnergies(energies);
304 return *this;
305 }
306
307
309 virtual std::string refFile() const {
310 return info().refFile();
311 }
313 virtual std::string refDataName() const {
314 return (info().getRefDataName().empty()) ? _defaultname : info().getRefDataName();
315 }
317 virtual void setRefDataName(const std::string& ref_data="") {
318 info().setRefDataName(!ref_data.empty() ? ref_data : name());
319 }
320
321
326 if (!_info) throw Error("No AnalysisInfo object :-O");
327 return *_info;
328 }
329
331
332
335
337 bool merging() const {
338 return sqrtS() <= 0.0;
339 }
340
342 bool compatibleWithRun() const;
343
345
346
350
352 const ParticlePair& beams() const;
353
355 PdgIdPair beamIDs() const;
356
358 pair<double,double> beamEnergies() const;
359
361 double sqrtS() const;
362
364 bool beamsMatch(const ParticlePair& beams) const;
365
367 bool beamsMatch(PdgId beam1, PdgId beam2, double e1, double e2) const;
368
370 bool beamsMatch(const PdgIdPair& beams, const std::pair<double,double>& energies) const;
371
373 bool beamIDsMatch(PdgId beam1, PdgId beam2) const;
374
376 bool beamIDsMatch(const PdgIdPair& beamids) const;
377
379 bool beamEnergiesMatch(double e1, double e2) const;
380
382 bool beamEnergiesMatch(const std::pair<double,double>& energies) const;
383
385 bool beamEnergyMatch(const std::pair<double,double>& energies) const;
386
388 bool beamEnergyMatch(double sqrts) const;
389
391 bool isCompatibleWithSqrtS(double energy, double tolerance=1e-5) const;
392
394
395
397 AnalysisHandler& handler() const { return *_analysishandler; }
398
399
400 protected:
401
403 Log& getLog() const;
404
406 double crossSection() const;
407
410 double crossSectionPerEvent() const;
411
413 double crossSectionError() const;
414
418
422 size_t numEvents() const;
423
427 double sumW() const;
429 double sumOfWeights() const { return sumW(); }
430
434 double sumW2() const;
435
436
437 protected:
438
444
446 const std::string histoDir() const;
447
449 const std::string histoPath(const std::string& hname) const;
450
452 const std::string histoPath(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
453
455 const std::string mkAxisCode(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
456
458
459
462
464 H5::File auxFile() const {
465 return H5::readFile(name()+".h5");
466 }
467
469 template <typename T>
470 bool auxData(const string& dsname, T& rtndata) {
472 return H5::readData(name()+".h5", dsname, rtndata);
473 }
474
475 template <typename T>
476 T auxData(const string& dsname) {
478 return H5::readData<T>(name()+".h5", dsname);
479 }
480
482
483
486
488 const std::map<std::string, YODA::AnalysisObjectPtr>& refData() const {
489 _cacheRefData();
490 return _refdata;
491 }
492
493
496 template <typename T=YODA::Estimate1D>
497 const T& refData(const string& hname) const {
498 _cacheRefData();
499 MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
500 if (!_refdata[hname]) {
501 MSG_ERROR("Can't find reference histogram " << hname);
502 throw Exception("Reference data " + hname + " not found.");
503 }
504 return dynamic_cast<T&>(*_refdata[hname]);
505 }
506
507
510 template <typename T=YODA::Estimate1D>
511 const T& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
512 const string hname = mkAxisCode(datasetId, xAxisId, yAxisId);
513 return refData<T>(hname);
514 }
515
517
518
524
526 CounterPtr& book(CounterPtr&, const std::string& name);
527
531 CounterPtr& book(CounterPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
532
534
535
538
540 Estimate0DPtr& book(Estimate0DPtr&, const std::string& name);
541
545 Estimate0DPtr& book(Estimate0DPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
546
547
549
552
554 template<size_t DbnN, typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
556 const std::string& name, const std::vector<size_t>& nbins,
557 const std::vector<std::pair<double,double>>& loUpPairs) {
558 if (nbins.size() != loUpPairs.size()) {
559 throw RangeError("Vectors should have the same size!");
560 }
561 const string path = histoPath(name);
562
563 YODA::BinnedDbn<DbnN, AxisT...> yao(nbins, loUpPairs, path);
564 _setWriterPrecision(path, yao);
565
566 return ao = registerAO(yao);
567 }
568
569 // Specialiation for 1D
570 Histo1DPtr& book(Histo1DPtr& ao, const std::string& name,
571 const size_t nbins, const double lower, const double upper) {
572 return book(ao, name, vector<size_t>{nbins},
573 vector<pair<double,double>>{{lower,upper}});
574 }
575 //
576 Profile1DPtr& book(Profile1DPtr& ao, const std::string& name,
577 const size_t nbins, const double lower, const double upper) {
578 return book(ao, name, vector<size_t>{nbins},
579 vector<pair<double,double>>{{lower,upper}});
580 }
581
582 // Specialiation for 2D
583 Histo2DPtr& book(Histo2DPtr& ao, const std::string& name,
584 const size_t nbinsX, const double lowerX, const double upperX,
585 const size_t nbinsY, const double lowerY, const double upperY) {
586 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
587 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
588 }
589 //
590 Profile2DPtr& book(Profile2DPtr& ao, const std::string& name,
591 const size_t nbinsX, const double lowerX, const double upperX,
592 const size_t nbinsY, const double lowerY, const double upperY) {
593 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
594 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
595 }
596
597 // Specialiation for 3D
598 Histo3DPtr& book(Histo3DPtr& ao, const std::string& name,
599 const size_t nbinsX, const double lowerX, const double upperX,
600 const size_t nbinsY, const double lowerY, const double upperY,
601 const size_t nbinsZ, const double lowerZ, const double upperZ) {
602 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
603 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
604 }
605 //
606 Profile3DPtr& book(Profile3DPtr& ao, const std::string& name,
607 const size_t nbinsX, const double lowerX, const double upperX,
608 const size_t nbinsY, const double lowerY, const double upperY,
609 const size_t nbinsZ, const double lowerZ, const double upperZ) {
610 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
611 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
612 }
613
615 template<size_t DbnN, typename... AxisT>
616 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
617 const std::vector<AxisT>&... binedges) {
618 const string path = histoPath(name);
619 YODA::BinnedDbn<DbnN, AxisT...> yao(binedges..., path);
620 _setWriterPrecision(path, yao);
621
622 return ao = registerAO(yao);
623 }
624
626 template<size_t DbnN, typename... AxisT>
627 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
628 const std::initializer_list<AxisT>&... binedges) {
629 return book(ao, name, vector<AxisT>{binedges} ...);
630 }
631
633 template<size_t DbnN, typename... AxisT>
634 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
635 const YODA::BinnedEstimate<AxisT...>& refest) {
636 const string path = histoPath(name);
637
638 YODA::BinnedDbn<DbnN, AxisT...> yao(refest.binning(), path);
639 for (const string& a : yao.annotations()) {
640 if (a != "Path") yao.rmAnnotation(a);
641 }
642 _setWriterPrecision(path, yao);
643 return ao = registerAO(yao);
644 }
645
647 template<size_t DbnN, typename... AxisT>
648 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name) {
649 return book(ao, name, refData<YODA::BinnedEstimate<AxisT...>>(name));
650 }
651
655 template<size_t DbnN, typename... AxisT>
656 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const unsigned int datasetID,
657 const unsigned int xAxisID, const unsigned int yAxisID) {
658 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
659 return book(ao, name);
660 }
661
663
666
667 template <typename GroupAxisT, typename... AxisT>
668 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
669 const std::vector<GroupAxisT>& edges,
670 const std::vector<std::string>& names) {
671 ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
672 if (ao->numBins() != names.size()) {
673 throw RangeError("Binning and reference-data names don't match!");
674 }
675 for (auto& b : ao->bins()) {
676 const string& refname = names[b.index()-1];
677 book(b, refname, refData<YODA::BinnedEstimate<AxisT...>>(refname));
678 }
679 return ao;
680 }
681
682 template <typename GroupAxisT, typename... AxisT>
683 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
684 const std::vector<GroupAxisT>& edges) {
685 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
686 }
687
688 template <typename GroupAxisT, typename... AxisT>
689 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
690 std::initializer_list<GroupAxisT>&& edges) {
691 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(std::move(edges));
692 }
693
695
698
700 template<typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
702 const std::string& name, const std::vector<size_t>& nbins,
703 const std::vector<std::pair<double,double>>& loUpPairs) {
704 if (nbins.size() != loUpPairs.size()) {
705 throw RangeError("Vectors should have the same size!");
706 }
707 const string path = histoPath(name);
708
709 YODA::BinnedEstimate<AxisT...> yao(nbins, loUpPairs, path);
710 _setWriterPrecision(path, yao);
711
712 return ao = registerAO(yao);
713 }
714
715
716 // Specialiation for 1D
717 Estimate1DPtr& book(Estimate1DPtr& ao, const std::string& name,
718 const size_t nbins, const double lower, const double upper) {
719 return book(ao, name, vector<size_t>{nbins},
720 vector<pair<double,double>>{{lower,upper}});
721 }
722
723 // Specialiation for 2D
724 Estimate2DPtr& book(Estimate2DPtr& ao, const std::string& name,
725 const size_t nbinsX, const double lowerX, const double upperX,
726 const size_t nbinsY, const double lowerY, const double upperY) {
727 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
728 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
729 }
730
731 // Specialiation for 3D
732 Estimate3DPtr& book(Estimate3DPtr& ao, const std::string& name,
733 const size_t nbinsX, const double lowerX, const double upperX,
734 const size_t nbinsY, const double lowerY, const double upperY,
735 const size_t nbinsZ, const double lowerZ, const double upperZ) {
736 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
737 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
738 }
739
741 template<typename... AxisT>
742 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
743 const std::vector<AxisT>&... binedges) {
744 const string path = histoPath(name);
745 YODA::BinnedEstimate<AxisT...> yao(binedges..., path);
746 _setWriterPrecision(path, yao);
747
748 return ao = registerAO(yao);
749 }
750
752 template<typename... AxisT>
753 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
754 const std::initializer_list<AxisT>&... binedges) {
755 return book(ao, name, vector<AxisT>{binedges} ...);
756 }
757
759 template<typename... AxisT>
760 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name) {
761
762 const string path = histoPath(name);
763 YODA::BinnedEstimate<AxisT...> yao;
764 try {
765 yao = YODA::BinnedEstimate<AxisT...>(refData<YODA::BinnedEstimate<AxisT...>>(name).binning());
766 } catch (...) {
767 MSG_DEBUG("Couldn't retrieve reference binning, continue with nullary AO constructor.");
768 }
769 yao.setPath(path);
770 _setWriterPrecision(path, yao);
771 return ao = registerAO(yao);
772 }
773
777 template<typename... AxisT>
778 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const unsigned int datasetID,
779 const unsigned int xAxisID, const unsigned int yAxisID) {
780 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
781 return book(ao, name);
782 }
783
785
786
789
800 template<size_t N>
801 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const bool copy_pts = false) {
802 const string path = histoPath(name);
803 YODA::ScatterND<N> scat(path);
804 if (copy_pts) {
805 const YODA::ScatterND<N> ref = refData<YODA::EstimateND<N-1>>(name).mkScatter();
806 for (YODA::PointND<N> p : ref.points()) {
807 p.setVal(N-1, 0.0);
808 p.setErr(N-1, 0.0);
809 scat.addPoint(std::move(p));
810 }
811 }
812 _setWriterPrecision(path, scat);
813 return snd = registerAO(scat);
814 }
815
826 template<size_t N>
827 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const unsigned int datasetID, const unsigned int xAxisID,
828 const unsigned int yAxisID, const bool copy_pts = false) {
829 const string axisCode = mkAxisCode(datasetID, xAxisID, yAxisID);
830 return book(snd, axisCode, copy_pts);
831 }
832
838 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
839 const size_t npts, const double lower, const double upper) {
840 const string path = histoPath(name);
841
842 Scatter2D scat(path);
843 const double binwidth = (upper-lower)/npts;
844 for (size_t pt = 0; pt < npts; ++pt) {
845 const double bincentre = lower + (pt + 0.5) * binwidth;
846 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
847 }
848 _setWriterPrecision(path, scat);
849
850 return snd = registerAO(scat);
851 }
852 //
853 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
854 const size_t nptsX, const double lowerX, const double upperX,
855 const size_t nptsY, const double lowerY, const double upperY) {
856 const string path = histoPath(name);
857
858 Scatter3D scat(path);
859 const double xbinwidth = (upperX-lowerX)/nptsX;
860 const double ybinwidth = (upperY-lowerY)/nptsY;
861 for (size_t xpt = 0; xpt < nptsX; ++xpt) {
862 const double xbincentre = lowerX + (xpt + 0.5) * xbinwidth;
863 for (size_t ypt = 0; ypt < nptsY; ++ypt) {
864 const double ybincentre = lowerY + (ypt + 0.5) * ybinwidth;
865 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
866 }
867 }
868 _setWriterPrecision(path, scat);
869
870 return snd = registerAO(scat);
871 }
872
878 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
879 const std::vector<double>& binedges) {
880 const string path = histoPath(name);
881
882 Scatter2D scat(path);
883 for (size_t pt = 0; pt < binedges.size()-1; ++pt) {
884 const double bincentre = (binedges[pt] + binedges[pt+1]) / 2.0;
885 const double binwidth = binedges[pt+1] - binedges[pt];
886 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
887 }
888 _setWriterPrecision(path, scat);
889
890 return snd = registerAO(scat);
891 }
892 //
893 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
894 const std::vector<double>& binedgesX,
895 const std::vector<double>& binedgesY) {
896 const string path = histoPath(name);
897
898 Scatter3D scat(path);
899 for (size_t xpt = 0; xpt < binedgesX.size()-1; ++xpt) {
900 const double xbincentre = (binedgesX[xpt] + binedgesX[xpt+1]) / 2.0;
901 const double xbinwidth = binedgesX[xpt+1] - binedgesX[xpt];
902 for (size_t ypt = 0; ypt < binedgesY.size()-1; ++ypt) {
903 const double ybincentre = (binedgesY[ypt] + binedgesY[ypt+1]) / 2.0;
904 const double ybinwidth = binedgesY[ypt+1] - binedgesY[ypt];
905 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
906 }
907 }
908 _setWriterPrecision(path, scat);
909
910 return snd = registerAO(scat);
911 }
912
914 template<size_t N>
915 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const YODA::ScatterND<N>& refscatter) {
916 const string path = histoPath(name);
917
918 YODA::ScatterND<N> scat(refscatter, path);
919 for (const string& a : scat.annotations()) {
920 if (a != "Path") scat.rmAnnotation(a);
921 }
922 _setWriterPrecision(path, scat);
923
924 return snd = registerAO(scat);
925 }
926
928
931
933 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::vector<std::string>& edges) {
934 const string path = histoPath(name);
935 Cutflow yao(edges, path);
936 _setWriterPrecision(path, yao);
937 return ao = registerAO(yao);
938 }
939
941 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::initializer_list<std::string>& edges) {
942 return book(ao, name, vector<std::string>{edges});
943 }
944
946
949
950 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges,
951 const std::vector<std::vector<std::string>>& innerEdges) {
952 ao = make_shared<Cutflows>(edges);
953 if (ao->numBins() !=innerEdges.size()) {
954 throw RangeError("Outer and Inner edges don't match");
955 }
956 for (auto& b : ao->bins()) {
957 book(b, b.xEdge(), innerEdges[b.index()-1]);
958 }
959 return ao;
960 }
961
962 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges) {
963 return ao = make_shared<Cutflows>(edges);
964 }
965
966 CutflowsPtr& book(CutflowsPtr& ao, std::initializer_list<std::string>&& edges) {
967 return ao = make_shared<Cutflows>(std::move(edges));
968 }
969
971
972
976 virtual void rawHookIn(YODA::AnalysisObjectPtr yao) {
977 (void) yao; // suppress unused variable warning
978 }
979
983 virtual void rawHookOut(const vector<MultiplexAOPtr>& raos, size_t iW) {
984 (void) raos; // suppress unused variable warning
985 (void) iW; // suppress unused variable warning
986 }
987
988
989 public:
990
993
995 const std::map<std::string,std::string>& options() const {
996 return _options;
997 }
998
1000 std::string getOption(std::string optname, string def="") const {
1001 if ( _options.find(optname) != _options.end() )
1002 return _options.find(optname)->second;
1003 return def;
1004 }
1005
1010 std::string getOption(std::string optname, const char* def) {
1011 return getOption<std::string>(optname, def);
1012 }
1013
1021 template<typename T>
1022 T getOption(std::string optname, T def) const {
1023 if (_options.find(optname) == _options.end()) return def;
1024 std::stringstream ss;
1025 ss.exceptions(std::ios::failbit);
1026 T ret;
1027 ss << _options.find(optname)->second;
1028 try {
1029 ss >> ret;
1030 } catch (...) {
1031 throw ReadError("Could not read user-provided option into requested type");
1032 }
1033 return ret;
1034 }
1035
1046 // template<>
1047 // bool getOption<bool>(std::string optname, bool def) const {
1048 bool getOption(std::string optname, bool def) const {
1049 if (_options.find(optname) == _options.end()) return def;
1050 const std::string val = getOption(optname);
1051 const std::string lval = toLower(val);
1052 if (lval.empty()) return false;
1053 if (lval == "true" || lval == "yes" || lval == "on") return true;
1054 if (lval == "false" || lval == "no" || lval == "off") return false;
1055 return bool(getOption<int>(optname, 0));
1056 }
1057
1059
1060
1063
1082 string calAnaName, string calHistName,
1083 const string projName,
1084 PercentileOrder pctorder=PercentileOrder::DECREASING);
1085
1086
1093 template<typename T>
1094 Percentile<T> book(const string& projName,
1095 const vector<pair<double, double>>& centralityBins,
1096 const vector<tuple<size_t, size_t, size_t>>& ref) {
1097
1098 using RefT = typename ReferenceTraits<T>::RefT;
1099 using WrapT = MultiplexPtr<Multiplexer<T>>;
1100
1101 Percentile<T> pctl(this, projName);
1102
1103 const size_t nCent = centralityBins.size();
1104 for (size_t iCent = 0; iCent < nCent; ++iCent) {
1105 const string axisCode = mkAxisCode(std::get<0>(ref[iCent]),
1106 std::get<1>(ref[iCent]),
1107 std::get<2>(ref[iCent]));
1108 const RefT& refscatter = refData<RefT>(axisCode);
1109
1110 WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1111 wtf = addAnalysisObject(wtf);
1112
1113 CounterPtr cnt(_weightNames(), Counter(histoPath("TMP/COUNTER/" + axisCode)));
1114 cnt = addAnalysisObject(cnt);
1115
1116 pctl.add(wtf, cnt, centralityBins[iCent]);
1117 }
1118 return pctl;
1119 }
1120
1121
1122 // /// @brief Book Percentile Multiplexers around AnalysisObjects.
1123 // ///
1124 // /// Based on a previously registered CentralityProjection named @a
1125 // /// projName book one (or several) AnalysisObject(s) named
1126 // /// according to @a ref where the x-axis will be filled according
1127 // /// to the percentile output(s) of the @projName.
1128 // ///
1129 // /// @todo Convert to just be called book() cf. others
1130 // template <class T>
1131 // PercentileXaxis<T> bookPercentileXaxis(string projName,
1132 // tuple<int, int, int> ref) {
1133
1134 // typedef typename ReferenceTraits<T>::RefT RefT;
1135 // typedef MultiplexPtr<Multiplexer<T>> WrapT;
1136
1137 // PercentileXaxis<T> pctl(this, projName);
1138
1139 // const string axisCode = mkAxisCode(std::get<0>(ref),
1140 // std::get<1>(ref),
1141 // std::get<2>(ref));
1142 // const RefT & refscatter = refData<RefT>(axisCode);
1143
1144 // WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1145 // wtf = addAnalysisObject(wtf);
1146
1147 // CounterPtr cnt(_weightNames(), Counter());
1148 // cnt = addAnalysisObject(cnt);
1149
1150 // pctl.add(wtf, cnt);
1151 // return pctl;
1152 // }
1153
1155
1156
1157 private:
1158
1159 // Functions that have to be defined in the .cc file to avoid circular #includes
1160
1162 vector<string> _weightNames() const;
1163
1165 YODA::AnalysisObjectPtr _getPreload (const string& name) const;
1166
1168 MultiplexAOPtr _getOtherAnalysisObject(const std::string & ananame, const std::string& name);
1169
1171 void _checkBookInit() const;
1172
1174 bool _inInit() const;
1175
1177 bool _inFinalize() const;
1178
1180 template <typename YODAT>
1181 void _setWriterPrecision(const string& path, YODAT& yao) {
1182 const string re = _info->writerDoublePrecision();
1183 if (re != "") {
1184 std::smatch match;
1185 const bool needsDP = std::regex_search(path, match, std::regex(re));
1186 if (needsDP) yao.template setAnnotation("WriterDoublePrecision", "1");
1187 }
1188 }
1189
1190
1191 private:
1192
1194 class CounterAdapter {
1195 public:
1196
1197 CounterAdapter(double x) : x_(x) {}
1198
1199 CounterAdapter(const YODA::Counter& c) : x_(c.val()) {}
1200
1201 CounterAdapter(const YODA::Estimate& e) : x_(e.val()) {}
1202
1203 CounterAdapter(const YODA::Scatter1D& s) : x_(s.points()[0].x()) {
1204 if (s.numPoints() != 1) throw RangeError("Can only scale by a single value.");
1205 }
1206
1207 operator double() const { return x_; }
1208
1209 private:
1210 double x_;
1211
1212 };
1213
1214
1215 public:
1216
1217 double dbl(double x) { return x; }
1218 double dbl(const YODA::Counter& c) { return c.val(); }
1219 double dbl(const YODA::Estimate0D& e) { return e.val(); }
1220 double dbl(const YODA::Scatter1D& s) {
1221 if ( s.numPoints() != 1 ) throw RangeError("Only scatter with single value supported.");
1222 return s.points()[0].x();
1223 }
1224
1225
1226 protected:
1227
1231
1233 template<typename T>
1234 void scale(MultiplexPtr<Multiplexer<T>>& ao, CounterAdapter factor) {
1235 if (!ao) {
1236 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1237 << name() << " (scale=" << double(factor) << ")");
1238 return;
1239 }
1240 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1241 MSG_WARNING("Failed to scale AnalysisObject=" << ao->path() << " in analysis: "
1242 << name() << " (invalid scale factor = " << double(factor) << ")");
1243 factor = 0;
1244 }
1245 MSG_TRACE("Scaling AnalysisObject " << ao->path() << " by factor " << double(factor));
1246 try {
1247 if constexpr( isFillable<T>::value ) {
1248 ao->scaleW(factor);
1249 }
1250 else {
1251 ao->scale(factor);
1252 }
1253 }
1254 catch (YODA::Exception& we) {
1255 MSG_WARNING("Could not scale AnalysisObject " << ao->path());
1256 return;
1257 }
1258 }
1259
1261 template<typename GroupAxisT, typename... AxisT>
1262 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, CounterAdapter factor) {
1263 if (!group) {
1264 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1265 << name() << " (scale=" << double(factor) << ")");
1266 return;
1267 }
1268 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1269 MSG_WARNING("Failed to scale histo group in analysis: "
1270 << name() << " (invalid scale factor = " << double(factor) << ")");
1271 factor = 0;
1272 }
1273 MSG_TRACE("Scaling histo group by factor " << double(factor));
1274 try {
1275 group->scaleW(factor);
1276 }
1277 catch (YODA::Exception& we) {
1278 MSG_WARNING("Could not scale histo group.");
1279 return;
1280 }
1281 }
1282
1284 void scale(CutflowsPtr& group, CounterAdapter factor) {
1285 if (!group) {
1286 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1287 << name() << " (scale=" << double(factor) << ")");
1288 return;
1289 }
1290 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1291 MSG_WARNING("Failed to scale histo group in analysis: "
1292 << name() << " (invalid scale factor = " << double(factor) << ")");
1293 factor = 0;
1294 }
1295 MSG_TRACE("Scaling histo group by factor " << double(factor));
1296 try {
1297 group->scale(factor);
1298 }
1299 catch (YODA::Exception& we) {
1300 MSG_WARNING("Could not scale histo group.");
1301 return;
1302 }
1303 }
1304
1306 template<typename T, typename U>
1307 void scale(std::map<T, U>& aos, CounterAdapter factor) {
1308 for (auto& item : aos) scale(item.second, factor);
1309 }
1310
1312 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1313 void scale(AORange& aos, CounterAdapter factor) {
1314 for (auto& ao : aos) scale(ao, factor);
1315 }
1316
1318 template <typename T>
1319 void scale(std::initializer_list<T> aos, CounterAdapter factor) {
1320 for (auto& ao : std::vector<T>{aos}) scale(ao, factor);
1321 }
1322
1323
1325 template<typename GroupAxisT, typename... AxisT>
1326 void divByGroupWidth(HistoGroupPtr<GroupAxisT, AxisT...>& group) {
1327 if (!group) {
1328 MSG_WARNING("Failed to scale HistoGroup=NULL in analysis "
1329 << name() << " by group axis width");
1330 return;
1331 }
1332 group->divByGroupWidth();
1333 }
1334
1336 template<typename T, typename U>
1337 void divByGroupWidth(std::map<T, U>& aos) {
1338 for (auto& item : aos) divByGroupWidth(item.second);
1339 }
1340
1342 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1343 void divByGroupWidth(AORange& aos) {
1344 for (auto& ao : aos) divByGroupWidth(ao);
1345 }
1346
1348 template <typename T>
1349 void divByGroupWidth(std::initializer_list<T> aos) {
1350 for (auto& ao : std::vector<T>{aos}) divByGroupWidth(ao);
1351 }
1352
1353
1355 template <size_t DbnN, typename... AxisT>
1356 void normalize(BinnedDbnPtr<DbnN, AxisT...> ao, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1357 if (!ao) {
1358 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1359 return;
1360 }
1361 MSG_TRACE("Normalizing histo " << ao->path() << " to " << double(norm));
1362 try {
1363 const double hint = ao->integral(includeoverflows);
1364 if (hint == 0) MSG_DEBUG("Skipping histo with null area " << ao->path());
1365 else ao->normalize(norm, includeoverflows);
1366 }
1367 catch (YODA::Exception& we) {
1368 MSG_WARNING("Could not normalize histo " << ao->path());
1369 return;
1370 }
1371 }
1372
1374 template <typename GroupAxisT, typename... AxisT>
1375 void normalize(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1376 if (!group) {
1377 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1378 return;
1379 }
1380 MSG_TRACE("Normalizing histo group to " << double(norm));
1381 try {
1382 const double hint = group->integral(includeoverflows);
1383 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1384 else group->normalize(norm, includeoverflows);
1385 }
1386 catch (YODA::Exception& we) {
1387 MSG_WARNING("Could not normalize histo group.");
1388 return;
1389 }
1390 }
1391
1392
1394 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1395 void normalize(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1396 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1397 }
1398
1400 template<typename T>
1401 void normalize(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1402 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1403 }
1404
1406 template<typename T, typename U>
1407 void normalize(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1408 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1409 for (auto& item : aos) normalize(item.second, norm, includeoverflows);
1410 }
1411
1413 template <typename GroupAxisT, typename... AxisT>
1414 void normalizeGroup(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1415 if (!group) {
1416 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1417 return;
1418 }
1419 MSG_TRACE("Normalizing histo group to " << double(norm));
1420 try {
1421 const double hint = group->integral(includeoverflows);
1422 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1423 else group->normalizeGroup(norm, includeoverflows);
1424 }
1425 catch (YODA::Exception& we) {
1426 MSG_WARNING("Could not normalize histo group.");
1427 return;
1428 }
1429 }
1430
1432 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1433 void normalizeGroup(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1434 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1435 }
1436
1438 template<typename T>
1439 void normalizeGroup(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1440 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1441 }
1442
1444 template<typename T, typename U>
1445 void normalizeGroup(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1446 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1447 for (auto& item : aos) normalizeGroup(item.second, norm, includeoverflows);
1448 }
1449
1450
1455 template<size_t DbnN, typename... AxisT>
1457 const string path = est->path();
1458 *est = ao->mkEstimate(path, "stats", false); //< do NOT divide by bin area cf. a differential dsigma/dX histogram
1459 }
1460
1465
1469 void divide(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const;
1470
1475
1479 void divide(const YODA::Estimate0D& e1, const YODA::Estimate0D& e2, Estimate0DPtr est) const;
1480
1481
1485 template<size_t DbnN, typename... AxisT>
1486 void divide(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1487 BinnedEstimatePtr<AxisT...> est) const {
1488 const string path = est->path();
1489 *est = h1 / h2;
1490 est->setPath(path);
1491 }
1492 //
1493 template<size_t DbnN, typename... AxisT>
1495 BinnedEstimatePtr<AxisT...> est) const {
1496 return divide(*h1, *h2, est);
1497 }
1498
1502 template<typename... AxisT>
1503 void divide(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1504 BinnedEstimatePtr<AxisT...> est) const {
1505 const string path = est->path();
1506 *est = e1 / e2;
1507 est->setPath(path);
1508 }
1509 //
1510 template<typename... AxisT>
1512 BinnedEstimatePtr<AxisT...> est) const {
1513 return divide(*e1, *e2, est);
1514 }
1515
1516
1517
1522 efficiency(*c1, *c2, est);
1523 }
1524
1528 void efficiency(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const {
1529 const string path = est->path();
1530 *est = YODA::efficiency(c1, c2);
1531 est->setPath(path);
1532 }
1533
1534
1535
1539 template<size_t DbnN, typename... AxisT>
1540 void efficiency(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1541 BinnedEstimatePtr<AxisT...> est) const {
1542 const string path = est->path();
1543 *est = YODA::efficiency(h1, h2);
1544 est->setPath(path);
1545 }
1546 //
1547 template<size_t DbnN, typename... AxisT>
1549 BinnedEstimatePtr<AxisT...> est) const {
1550 efficiency(*h1, *h2, est);
1551 }
1552
1553
1557 template<typename... AxisT>
1558 void efficiency(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1559 BinnedEstimatePtr<AxisT...> est) const {
1560 const string path = est->path();
1561 *est = YODA::efficiency(e1, e2);
1562 est->setPath(path);
1563 }
1564 //
1565 template<typename... AxisT>
1567 BinnedEstimatePtr<AxisT...> est) const {
1568 efficiency(*e1, *e2, est);
1569 }
1570
1571
1575 template<size_t DbnN, typename... AxisT>
1576 void asymm(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1577 BinnedEstimatePtr<AxisT...> est) const {
1578 const string path = est->path();
1579 *est = YODA::asymm(h1, h2);
1580 est->setPath(path);
1581 }
1582 //
1583 template<size_t DbnN, typename... AxisT>
1585 BinnedEstimatePtr<AxisT...> est) const {
1586 asymm(*h1, *h2, est);
1587 }
1588
1592 template<typename... AxisT>
1593 void asymm(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1594 BinnedEstimatePtr<AxisT...> est) const {
1595 const string path = est->path();
1596 *est = YODA::asymm(e1, e2);
1597 est->setPath(path);
1598 }
1599 //
1600 template<typename... AxisT>
1602 BinnedEstimatePtr<AxisT...> est) const {
1603 asymm(*e1, *e2, est);
1604 }
1605
1609 template<size_t DbnN, typename... AxisT>
1610 void integrate(const YODA::BinnedDbn<DbnN, AxisT...>& h, BinnedEstimatePtr<AxisT...> est) const {
1611 const string path = est->path();
1612 *est = mkIntegral(h);
1613 est->setPath(path);
1614 }
1615 //
1616 template<size_t DbnN, typename... AxisT>
1618 integrate(*h, est);
1619 }
1620
1622
1623
1624 public:
1625
1627 const vector<MultiplexAOPtr>& analysisObjects() const {
1628 return _analysisobjects;
1629 }
1630
1631
1632 protected:
1633
1636
1638 size_t defaultWeightIndex() const;
1639
1641 template <typename YODAT>
1642 shared_ptr<YODAT> getPreload(const string& path) const {
1643 return dynamic_pointer_cast<YODAT>(_getPreload(path));
1644 }
1645
1646
1648 template <typename YODAT>
1650 using MultiplexerT = Multiplexer<YODAT>;
1651 using YODAPtrT = shared_ptr<YODAT>;
1652 using RAOT = MultiplexPtr<MultiplexerT>;
1653
1654 if ( !_inInit() && !_inFinalize() ) {
1655 MSG_ERROR("Can't book objects outside of init() or finalize()");
1656 throw UserError(name() + ": Can't book objects outside of init() or finalize().");
1657 }
1658
1659 // First check that we haven't booked this before.
1660 // This is allowed when booking in finalize: just warn in that case.
1661 // If in init(), throw an exception: it's 99.9% never going to be intentional.
1662 for (auto& waold : analysisObjects()) {
1663 if ( yao.path() == waold.get()->basePath() ) {
1664 const string msg = "Found double-booking of " + yao.path() + " in " + name();
1665 if ( _inInit() ) {
1666 MSG_ERROR(msg);
1667 throw LookupError(msg);
1668 } else {
1669 MSG_WARNING(msg + ". Keeping previous booking");
1670 }
1671 return RAOT(dynamic_pointer_cast<MultiplexerT>(waold.get()));
1672 }
1673 }
1674
1675 shared_ptr<MultiplexerT> wao = make_shared<MultiplexerT>();
1676 wao->_basePath = yao.path();
1677 YODAPtrT yaop = make_shared<YODAT>(yao);
1678
1679 for (const string& weightname : _weightNames()) {
1680 // Create two YODA objects for each weight. Copy from
1681 // preloaded YODAs if present. First the finalized yoda:
1682 string finalpath = yao.path();
1683 if ( weightname != "" ) finalpath += "[" + weightname + "]";
1684 YODAPtrT preload = getPreload<YODAT>(finalpath);
1685 if ( preload ) {
1686 if ( !bookingCompatible(preload, yaop) ) {
1688 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1689 << finalpath << " for " << name());
1690 preload = nullptr;
1691 } else {
1692 MSG_TRACE("Using preloaded " << finalpath << " in " <<name());
1693 wao->_final.push_back(make_shared<YODAT>(*preload));
1694 }
1695 }
1696 else {
1697 wao->_final.push_back(make_shared<YODAT>(yao));
1698 wao->_final.back()->setPath(finalpath);
1699 }
1700
1701 // Then the raw filling yodas.
1702 string rawpath = "/RAW" + finalpath;
1703 preload = getPreload<YODAT>(rawpath);
1704 if ( preload ) {
1705 if ( !bookingCompatible(preload, yaop) ) {
1706 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1707 << rawpath << " for " << name());
1708 preload = nullptr;
1709 } else {
1710 MSG_TRACE("Using preloaded " << rawpath << " in " <<name());
1711 wao->_persistent.push_back(make_shared<YODAT>(*preload));
1712 }
1713 }
1714 else {
1715 wao->_persistent.push_back(make_shared<YODAT>(yao));
1716 wao->_persistent.back()->setPath(rawpath);
1717 }
1718 }
1720
1721 ret.get()->unsetActiveWeight();
1722 if ( _inFinalize() ) {
1723 // If booked in finalize() we assume it is the first time
1724 // finalize is run.
1725 ret.get()->pushToFinal();
1726 ret.get()->setActiveFinalWeightIdx(0);
1727 }
1728 _analysisobjects.push_back(ret);
1729
1730 return ret;
1731 }
1732
1733
1735 template <typename AO=MultiplexAOPtr>
1736 AO addAnalysisObject(const AO& aonew) {
1737 _checkBookInit();
1738
1739 for (const MultiplexAOPtr& ao : analysisObjects()) {
1740
1741 // Check AO base-name first
1742 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1743 aonew.get()->setActiveWeightIdx(defaultWeightIndex());
1744 if (ao->path() != aonew->path()) continue;
1745
1746 // If base-name matches, check compatibility
1747 // NB. This evil is because dynamic_ptr_cast can't work on MultiplexPtr directly
1748 AO aoold = AO(dynamic_pointer_cast<typename AO::value_type>(ao.get())); //< OMG
1749 if ( !aoold || !bookingCompatible(aonew, aoold) ) {
1750 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1751 << aonew->path() << " for " << name());
1752 throw LookupError("Found incompatible pre-existing data object with same base path during AO booking");
1753 }
1754
1755 // Finally, check all weight variations
1756 for (size_t weightIdx = 0; weightIdx < _weightNames().size(); ++weightIdx) {
1757 aoold.get()->setActiveWeightIdx(weightIdx);
1758 aonew.get()->setActiveWeightIdx(weightIdx);
1759 if (aoold->path() != aonew->path()) {
1760 MSG_WARNING("Found incompatible pre-existing data object with different weight-path "
1761 << aonew->path() << " for " << name());
1762 throw LookupError("Found incompatible pre-existing data object with same weight-path during AO booking");
1763 }
1764 }
1765
1766 // They're fully compatible: bind and return
1767 aoold.get()->unsetActiveWeight();
1768 MSG_TRACE("Bound pre-existing data object " << aoold->path() << " for " << name());
1769 return aoold;
1770 }
1771
1772 // No equivalent found
1773 MSG_TRACE("Registered " << aonew->annotation("Type") << " " << aonew->path() << " for " << name());
1774 aonew.get()->unsetActiveWeight();
1775
1776 _analysisobjects.push_back(aonew);
1777 return aonew;
1778 }
1779
1781 void removeAnalysisObject(const std::string& path);
1782
1785
1787 template <typename AO=MultiplexAOPtr>
1788 const AO getAnalysisObject(const std::string& aoname) const {
1789 for (const MultiplexAOPtr& ao : analysisObjects()) {
1790 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1791 if (ao->path() == histoPath(aoname)) {
1792 // return dynamic_pointer_cast<AO>(ao);
1793 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1794 }
1795 }
1796 throw LookupError("Data object " + histoPath(aoname) + " not found");
1797 }
1798
1799
1800 // /// Get a data object from the histogram system
1801 // template <typename AO=YODA::AnalysisObject>
1802 // const std::shared_ptr<AO> getAnalysisObject(const std::string& name) const {
1803 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1804 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1805 // }
1806 // throw LookupError("Data object " + histoPath(name) + " not found");
1807 // }
1808
1809 // /// Get a data object from the histogram system (non-const)
1810 // template <typename AO=YODA::AnalysisObject>
1811 // std::shared_ptr<AO> getAnalysisObject(const std::string& name) {
1812 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1813 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1814 // }
1815 // throw LookupError("Data object " + histoPath(name) + " not found");
1816 // }
1817
1818
1821 template <typename AO=MultiplexAOPtr>
1822 AO getAnalysisObject(const std::string& ananame,
1823 const std::string& aoname) {
1824 MultiplexAOPtr ao = _getOtherAnalysisObject(ananame, aoname);
1825 // return dynamic_pointer_cast<AO>(ao);
1826 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1827 }
1828
1830
1831
1832 private:
1833
1835 string _defaultname;
1836
1838 unique_ptr<AnalysisInfo> _info;
1839
1842 vector<MultiplexAOPtr> _analysisobjects;
1843
1846 double _crossSection;
1847 bool _gotCrossSection;
1849
1851 AnalysisHandler* _analysishandler;
1852
1855 mutable std::map<std::string, YODA::AnalysisObjectPtr> _refdata;
1856
1858 map<string, string> _options;
1859
1861 string _optstring;
1862
1863
1864 private:
1865
1868
1870 void _cacheRefData() const;
1871
1873
1874 };
1875
1876
1877 // // Template specialisation for literal character strings (which don't play well with stringstream)
1878 // template<>
1879 // inline std::string Analysis::getOption(std::string optname, const char* def) {
1880 // return getOption<std::string>(optname, def); //.c_str();
1881 // }
1882
1883
1884}
1885
1886
1887// Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
1888#include "Rivet/AnalysisBuilder.hh"
1889
1890
1893
1896#define RIVET_DECLARE_PLUGIN(clsname) ::Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
1897
1900#define RIVET_DECLARE_ALIASED_PLUGIN(clsname, alias) RIVET_DECLARE_PLUGIN(clsname)( #alias )
1901
1904#define RIVET_DEFAULT_ANALYSIS_CTOR(clsname) clsname() : Analysis(# clsname) {}
1905
1908#define RIVET_REGISTER_TYPE(...) handler().registerType<__VA_ARGS__>()
1909
1912#define RIVET_REGISTER_BINNED_SET(...) { \
1913 RIVET_REGISTER_TYPE(YODA::BinnedHisto<__VA_ARGS__>); \
1914 RIVET_REGISTER_TYPE(YODA::BinnedProfile<__VA_ARGS__>); \
1915 RIVET_REGISTER_TYPE(YODA::BinnedEstimate<__VA_ARGS__>); }
1916
1918
1919
1920#endif
The key class for coordination of Analysis objects and the event loop.
Definition AnalysisHandler.hh:29
Holder of analysis metadata.
Definition AnalysisInfo.hh:12
std::string refFile() const
Find the path to the reference-data file for this analysis.
const std::vector< std::string > & validation() const
List a series of command lines to be used for valdation.
Definition AnalysisInfo.hh:275
This is the base class of all analysis classes in Rivet.
Definition Analysis.hh:67
std::string getOption(std::string optname, const char *def)
Sane overload for literal character strings (which don't play well with stringstream)
Definition Analysis.hh:1010
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const std::string &name)
Book a ND histogram, using the binnings in the reference data histogram.
Definition Analysis.hh:648
virtual std::string status() const
Whether this analysis is trusted (in any way!)
Definition Analysis.hh:243
bool beamEnergyMatch(const std::pair< double, double > &energies) const
Check if analysis is compatible with the provided CoM energy.
virtual ~Analysis()
The destructor.
Definition Analysis.hh:78
virtual bool reentrant() const
Does this analysis have a reentrant finalize()?
Definition Analysis.hh:263
shared_ptr< YODAT > getPreload(const string &path) const
Get a preloaded YODA object.
Definition Analysis.hh:1642
std::string analysisDataPath(const std::string &extn, const std::string &suffix="")
Get the path to a data file associated with this analysis.
Definition Analysis.hh:150
void scale(std::initializer_list< T > aos, CounterAdapter factor)
Iteratively scale the AOs in the initialiser list aos, by factor factor.
Definition Analysis.hh:1319
virtual std::string collider() const
Collider on which the experiment ran.
Definition Analysis.hh:207
MultiplexPtr< Multiplexer< YODAT > > registerAO(const YODAT &yao)
Register a new data object, optionally read in preloaded data.
Definition Analysis.hh:1649
virtual double luminosityfb() const
The integrated luminosity in inverse femtobarn.
Definition Analysis.hh:217
void loadInfo()
Get the AnalysisInfo object to parse its info file in which the metadata is stored.
Definition Analysis.hh:127
bool beamIDsMatch(PdgId beam1, PdgId beam2) const
Check if analysis is compatible with the provided beam particle IDs.
Percentile< T > book(const string &projName, const vector< pair< double, double > > &centralityBins, const vector< tuple< size_t, size_t, size_t > > &ref)
Book a Percentile Multiplexer around AnalysisObjects.
Definition Analysis.hh:1094
const AnalysisInfo & info() const
Get the actual AnalysisInfo object in which all this metadata is stored.
Definition Analysis.hh:130
void normalize(AORange &aos, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Iteratively normalise the AOs in the iterable iter, by factor factor.
Definition Analysis.hh:1395
void removeAnalysisObject(const std::string &path)
Unregister a data object from the histogram system (by name)
void normalize(std::map< T, U > &aos, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Iteratively normalise the AOs in the map aos to a target norm.
Definition Analysis.hh:1407
void efficiency(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const
Definition Analysis.hh:1521
virtual const std::vector< std::string > & keywords() const
Get vector of analysis keywords.
Definition Analysis.hh:268
virtual double luminosity() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:221
virtual std::string spiresID() const
Get the SPIRES ID code for this analysis (~deprecated).
Definition Analysis.hh:161
virtual std::string writerDoublePrecision() const
Positive filtering regex for setting double precision in Writer.
Definition Analysis.hh:283
void efficiency(const YODA::Counter &c1, const YODA::Counter &c2, Estimate0DPtr est) const
Definition Analysis.hh:1528
T auxData(const string &dsname)
Definition Analysis.hh:476
pair< double, double > beamEnergies() const
Incoming beam energies for this run.
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const std::string &name, const YODA::BinnedEstimate< AxisT... > &refest)
Book a ND histogram with binning from a reference scatter.
Definition Analysis.hh:634
ScatterNDPtr< N > & book(ScatterNDPtr< N > &snd, const string &name, const bool copy_pts=false)
Book a N-dimensional data point set with the given name.
Definition Analysis.hh:801
virtual Analysis & setRequiredBeamIDs(const std::vector< PdgIdPair > &beamids)
Declare the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:292
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const std::string &name, const std::vector< AxisT > &... binedges)
Book a ND estimate with non-uniform bins defined by the vector of bin edges binedges .
Definition Analysis.hh:742
AO getAnalysisObject(const std::string &ananame, const std::string &aoname)
Definition Analysis.hh:1822
void barchart(BinnedDbnPtr< DbnN, AxisT... > ao, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1456
AnalysisInfo & info()
Get the actual AnalysisInfo object in which all this metadata is stored (non-const).
Definition Analysis.hh:325
virtual std::string runInfo() const
Information about the events needed as input for this analysis.
Definition Analysis.hh:197
void syncDeclQueue()
Definition Analysis.hh:110
void scale(AORange &aos, CounterAdapter factor)
Iteratively scale the AOs in the iterable aos, by factor factor.
Definition Analysis.hh:1313
virtual std::string year() const
When the original experimental analysis was published.
Definition Analysis.hh:212
T getOption(std::string optname, T def) const
Get an option for this analysis instance converted to a specific type.
Definition Analysis.hh:1022
virtual void setRefDataName(const std::string &ref_data="")
Set name of reference data file, which could be different from plugin name.
Definition Analysis.hh:317
void divide(const YODA::Counter &c1, const YODA::Counter &c2, Estimate0DPtr est) const
double crossSection() const
Get the process cross-section in pb. Throws if this hasn't been set.
const vector< MultiplexAOPtr > & analysisObjects() const
List of registered analysis data objects.
Definition Analysis.hh:1627
double crossSectionPerEvent() const
virtual std::string summary() const
Get a short description of the analysis.
Definition Analysis.hh:178
virtual std::string description() const
Get a full description of the analysis.
Definition Analysis.hh:188
double crossSectionErrorPerEvent() const
void removeAnalysisObject(const MultiplexAOPtr &ao)
Unregister a data object from the histogram system (by pointer)
bool beamEnergyMatch(double sqrts) const
Check if analysis is compatible with the provided CoM energy.
std::string getOption(std::string optname, string def="") const
Get an option for this analysis instance as a string.
Definition Analysis.hh:1000
virtual std::vector< std::string > validation() const
make-style commands for validating this analysis.
Definition Analysis.hh:258
void normalizeGroup(std::initializer_list< T > &&aos, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Iteratively normalise the HistoGroups in the initialiser list iter to a target norm.
Definition Analysis.hh:1439
virtual std::vector< std::string > authors() const
Names & emails of paper/analysis authors.
Definition Analysis.hh:169
void asymm(const YODA::BinnedEstimate< AxisT... > &e1, const YODA::BinnedEstimate< AxisT... > &e2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1593
size_t defaultWeightIndex() const
Get the default/nominal weight index.
const CentralityProjection & declareCentrality(const SingleValueProjection &proj, string calAnaName, string calHistName, const string projName, PercentileOrder pctorder=PercentileOrder::DECREASING)
Book a CentralityProjection.
virtual Analysis & setRequiredBeamEnergies(const std::vector< std::pair< double, double > > &energies)
Declare the list of valid beam energy pairs, in GeV.
Definition Analysis.hh:302
void divide(Estimate0DPtr e1, Estimate0DPtr e2, Estimate0DPtr est) const
void normalizeGroup(AORange &aos, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Iteratively normalise the HistoGroups in the iterable iter, by factor factor.
Definition Analysis.hh:1433
Estimate0DPtr & book(Estimate0DPtr &, const std::string &name)
Book an estimate.
bool beamsMatch(PdgId beam1, PdgId beam2, double e1, double e2) const
Check if analysis is compatible with the provided beam particle IDs and energies.
void divByGroupWidth(AORange &aos)
Iteratively scale the HistoGroups in the iterable aos, by the group axis width.
Definition Analysis.hh:1343
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const std::string &name, const std::initializer_list< AxisT > &... binedges)
Book a ND estimate with non-uniform bins defined by the vector of bin edges binedges .
Definition Analysis.hh:753
virtual std::string refFile() const
Location of reference data YODA file.
Definition Analysis.hh:309
void normalizeGroup(HistoGroupPtr< GroupAxisT, AxisT... > group, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Normalize the given histogram group, group to a target norm.
Definition Analysis.hh:1414
virtual void finalize()
Definition Analysis.hh:105
void efficiency(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1540
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const std::string &name, const std::vector< AxisT > &... binedges)
Book a ND histogram with non-uniform bins defined by the vector of bin edges binedges .
Definition Analysis.hh:616
Scatter2DPtr & book(Scatter2DPtr &snd, const string &name, const size_t npts, const double lower, const double upper)
Book a N-dimensional data point set with equally spaced x-points in a range.
Definition Analysis.hh:838
virtual std::vector< std::string > references() const
Journal, and preprint references.
Definition Analysis.hh:228
double sumW2() const
Get the sum of squared event weights seen (via the analysis handler).
virtual std::vector< std::string > todos() const
Any work to be done on this analysis.
Definition Analysis.hh:253
bool auxData(const string &dsname, T &rtndata)
Read HDF5 file filename.
Definition Analysis.hh:470
virtual std::string inspireID() const
Get the Inspire ID code for this analysis.
Definition Analysis.hh:156
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, CounterAdapter factor)
Multiplicatively scale the given histogram group, group, by factor factor.
Definition Analysis.hh:1262
bool merging() const
Check if we are running rivet-merge.
Definition Analysis.hh:337
void divByGroupWidth(std::initializer_list< T > aos)
Iteratively scale the HistoGroups in the initialiser list aos, by the group axis width.
Definition Analysis.hh:1349
void divide(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1486
virtual const std::vector< PdgIdPair > & requiredBeamIDs() const
Return the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:288
virtual std::string refUnmatch() const
Negative filtering regex for ref-data HepData sync.
Definition Analysis.hh:278
const std::map< std::string, std::string > & options() const
Return the map of all options given to this analysis.
Definition Analysis.hh:995
double sqrtS() const
Centre of mass energy for this run.
bool getOption(std::string optname, bool def) const
Get an option for this analysis instance converted to a bool.
Definition Analysis.hh:1048
bool beamsMatch(const PdgIdPair &beams, const std::pair< double, double > &energies) const
Check if analysis is compatible with the provided beam particle IDs and energies in GeV.
void scale(MultiplexPtr< Multiplexer< T > > &ao, CounterAdapter factor)
Multiplicatively scale the given AnalysisObject, ao, by factor factor.
Definition Analysis.hh:1234
void scale(CutflowsPtr &group, CounterAdapter factor)
Multiplicatively scale the cutflow group, group, by factor factor.
Definition Analysis.hh:1284
ScatterNDPtr< N > & book(ScatterNDPtr< N > &snd, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID, const bool copy_pts=false)
Book a N-dimensional data point set, using the binnings in the reference data histogram.
Definition Analysis.hh:827
double sumW() const
Get the sum of event weights seen (via the analysis handler).
virtual std::string refMatch() const
Positive filtering regex for ref-data HepData sync.
Definition Analysis.hh:273
void normalizeGroup(std::map< T, U > &aos, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Iteratively normalise the HistoGroups in the map aos to a target norm.
Definition Analysis.hh:1445
double luminositypb() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:225
bool beamEnergiesMatch(double e1, double e2) const
Check if analysis is compatible with the provided beam energies.
bool isCompatibleWithSqrtS(double energy, double tolerance=1e-5) const
Check if sqrtS is compatible with provided value.
void divide(const YODA::BinnedEstimate< AxisT... > &e1, const YODA::BinnedEstimate< AxisT... > &e2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1503
void integrate(const YODA::BinnedDbn< DbnN, AxisT... > &h, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1610
const T & refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Definition Analysis.hh:511
virtual std::string warning() const
A warning message from the info file, if there is one.
Definition Analysis.hh:248
AnalysisHandler & handler() const
Access the controlling AnalysisHandler object.
Definition Analysis.hh:397
void divide(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const
void divByGroupWidth(HistoGroupPtr< GroupAxisT, AxisT... > &group)
Scale the given histogram group, group, by the group axis width.
Definition Analysis.hh:1326
void normalize(std::initializer_list< T > &&aos, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Iteratively normalise the AOs in the initialiser list iter to a target norm.
Definition Analysis.hh:1401
double sumOfWeights() const
Alias.
Definition Analysis.hh:429
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const std::string &name, const std::vector< size_t > &nbins, const std::vector< std::pair< double, double > > &loUpPairs)
Book a ND estimate with nbins uniformly distributed across the range lower - upper .
Definition Analysis.hh:701
const AO getAnalysisObject(const std::string &aoname) const
Get a Rivet data object from the histogram system.
Definition Analysis.hh:1788
ScatterNDPtr< N > & book(ScatterNDPtr< N > &snd, const string &name, const YODA::ScatterND< N > &refscatter)
Book a 2-dimensional data point set with x-points from an existing scatter and a new path.
Definition Analysis.hh:915
bool beamEnergiesMatch(const std::pair< double, double > &energies) const
Check if analysis is compatible with the provided beam energies.
Scatter2DPtr & book(Scatter2DPtr &snd, const string &name, const std::vector< double > &binedges)
Book a 2-dimensional data point set based on provided contiguous "bin edges".
Definition Analysis.hh:878
const std::map< std::string, YODA::AnalysisObjectPtr > & refData() const
Get all reference data objects for this analysis.
Definition Analysis.hh:488
size_t numEvents() const
Get the number of events seen (via the analysis handler).
void efficiency(const YODA::BinnedEstimate< AxisT... > &e1, const YODA::BinnedEstimate< AxisT... > &e2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1558
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:656
void asymm(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1576
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:778
PdgIdPair beamIDs() const
Incoming beam IDs for this run.
bool beamIDsMatch(const PdgIdPair &beamids) const
Check if analysis is compatible with the provided beam particle IDs.
virtual void analyze(const Event &event)=0
Analysis(const std::string &name)
Constructor.
virtual std::string bibKey() const
BibTeX citation key for this article.
Definition Analysis.hh:233
Analysis & operator=(const Analysis &)=delete
The assignment operator is private and must be deleted, so it can never be called.
virtual std::string bibTeX() const
BibTeX citation entry for this article.
Definition Analysis.hh:238
bool compatibleWithRun() const
Check if the given conditions are compatible with this analysis' declared constraints.
virtual void init()
Definition Analysis.hh:92
void divide(const YODA::Estimate0D &e1, const YODA::Estimate0D &e2, Estimate0DPtr est) const
Estimate0DPtr & book(Estimate0DPtr &, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID)
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const std::string &name, const std::initializer_list< AxisT > &... binedges)
Book a ND histogram with non-uniform bins defined by the vector of bin edges binedges .
Definition Analysis.hh:627
H5::File auxFile() const
Read in an aux data HDF5 file.
Definition Analysis.hh:464
Log & getLog() const
Get a Log object based on the name() property of the calling analysis object.
const T & refData(const string &hname) const
Definition Analysis.hh:497
bool beamsMatch(const ParticlePair &beams) const
Check if analysis is compatible with the provided beam particle IDs and energies.
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const std::string &name, const std::vector< size_t > &nbins, const std::vector< std::pair< double, double > > &loUpPairs)
Book a ND histogram with nbins uniformly distributed across the range lower - upper .
Definition Analysis.hh:555
const ParticlePair & beams() const
Incoming beams for this run.
virtual std::string refDataName() const
Get name of reference data file, which could be different from plugin name.
Definition Analysis.hh:313
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const std::string &name)
Book a ND estimate, using the binnings in the reference data histogram.
Definition Analysis.hh:760
void normalize(BinnedDbnPtr< DbnN, AxisT... > ao, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Normalize the given analysis object, ao to a target norm.
Definition Analysis.hh:1356
virtual std::string name() const
Get the name of the analysis.
Definition Analysis.hh:142
double crossSectionError() const
Get the process cross-section error in pb. Throws if this hasn't been set.
void divByGroupWidth(std::map< T, U > &aos)
Iteratively scale the HistoGroups in the map aos, by the group axis width.
Definition Analysis.hh:1337
virtual std::string experiment() const
Experiment which performed and published this analysis.
Definition Analysis.hh:202
void scale(std::map< T, U > &aos, CounterAdapter factor)
Iteratively scale the AOs in the map aos, by factor factor.
Definition Analysis.hh:1307
void normalize(HistoGroupPtr< GroupAxisT, AxisT... > group, const CounterAdapter norm=1.0, const bool includeoverflows=true)
Normalize each AO in the given histogram group, group to a target norm.
Definition Analysis.hh:1375
virtual const std::vector< std::pair< double, double > > & requiredBeamEnergies() const
Sets of valid beam energy pairs, in GeV.
Definition Analysis.hh:298
AO addAnalysisObject(const AO &aonew)
Register a data object in the histogram system.
Definition Analysis.hh:1736
Used together with the percentile-based analysis objects Percentile and PercentileXaxis.
Definition CentralityProjection.hh:27
A tracker of numbers & fractions of events passing sequential cuts.
Definition Cutflow.hh:24
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
Definition HistoGroup.hh:23
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
Definition RivetYODA.hh:1330
shared_ptr< T > get() const
Get the internal shared ptr.
Definition RivetYODA.hh:1418
Type-specific multiplexed YODA analysis object.
Definition RivetYODA.hh:1011
void add(TPtr ao, CounterPtr cnt, pair< float, float > cent={0.0, 100.0})
Add a new percentile bin.
Definition Percentile.hh:122
The Percentile class for centrality binning.
Definition Percentile.hh:203
Common base class for Projection and Analysis, used for internal polymorphism.
Definition ProjectionApplier.hh:22
void markAsOwned() const
Mark this object as owned by a proj-handler.
Definition ProjectionApplier.hh:131
Base class for projections returning a single floating point value.
Definition SingleValueProjection.hh:17
CutflowPtr & book(CutflowPtr &ao, const string &name, const std::initializer_list< std::string > &edges)
Book a Cutflow object defined by the vector of edges.
Definition Analysis.hh:941
CutflowPtr & book(CutflowPtr &ao, const string &name, const std::vector< std::string > &edges)
Book a Cutflow object defined by the vector of edges.
Definition Analysis.hh:933
const std::string & refUnmatch() const
Negative filtering regex for ref-data HepData sync.
Definition AnalysisInfo.hh:159
void setBeamIDs(const std::vector< PdgIdPair > &beamids)
Set beam particle types.
Definition AnalysisInfo.hh:108
const std::string & description() const
Get a full description of the analysis.
Definition AnalysisInfo.hh:91
const std::string & warning() const
Any warning message.
Definition AnalysisInfo.hh:151
const std::string & bibKey() const
BibTeX citation key for this article.
Definition AnalysisInfo.hh:167
void setRefDataName(const std::string &name)
Set the reference data name of the analysis (if different from plugin name).
Definition AnalysisInfo.hh:54
const std::vector< std::string > & todos() const
Any work to be done on this analysis.
Definition AnalysisInfo.hh:177
const std::string & collider() const
Collider on which the experiment ran.
Definition AnalysisInfo.hh:121
const std::string & inspireID() const
Get the Inspire (SPIRES replacement) ID code for this analysis.
Definition AnalysisInfo.hh:57
const std::string & bibTeX() const
BibTeX citation entry for this article.
Definition AnalysisInfo.hh:172
const std::vector< PdgIdPair > & beamIDs() const
Beam particle types.
Definition AnalysisInfo.hh:105
const std::vector< std::string > & references() const
Journal and preprint references.
Definition AnalysisInfo.hh:142
const std::string & summary() const
Get a short description of the analysis.
Definition AnalysisInfo.hh:81
const std::vector< std::pair< double, double > > & energies() const
Sets of valid beam energies.
Definition AnalysisInfo.hh:111
const std::string & refMatch() const
Positive filtering regex for ref-data HepData sync.
Definition AnalysisInfo.hh:155
void setEnergies(const std::vector< std::pair< double, double > > &energies)
Set the valid beam energies.
Definition AnalysisInfo.hh:113
const std::string & spiresID() const
Get the SPIRES ID code for this analysis.
Definition AnalysisInfo.hh:63
double luminosity() const
The integrated data luminosity of the data set in 1/pb.
Definition AnalysisInfo.hh:136
const std::vector< std::string > & keywords() const
Analysis keywords, for grouping etc.
Definition AnalysisInfo.hh:147
const std::string & runInfo() const
Information about the events needed as input for this analysis.
Definition AnalysisInfo.hh:100
const std::vector< std::string > & authors() const
Names & emails of paper/analysis authors.
Definition AnalysisInfo.hh:72
std::string name() const
Definition AnalysisInfo.hh:34
std::string getRefDataName() const
Get the reference data name of the analysis (if different from plugin name).
Definition AnalysisInfo.hh:49
const std::string & year() const
When the original experimental analysis was published.
Definition AnalysisInfo.hh:128
const std::string & writerDoublePrecision() const
Positive filtering regex for setting double precision in Writer.
Definition AnalysisInfo.hh:163
double luminosityfb() const
The integrated data luminosity of the data set in 1/fb.
Definition AnalysisInfo.hh:134
const std::string & experiment() const
Experiment which performed and published this analysis.
Definition AnalysisInfo.hh:116
const std::string & status() const
Whether this analysis is trusted (in any way!)
Definition AnalysisInfo.hh:209
bool reentrant() const
Return true if finalize() can be run multiple times for this analysis.
Definition AnalysisInfo.hh:214
CounterPtr & book(CounterPtr &, const std::string &name)
Book a counter.
CounterPtr & book(CounterPtr &, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID)
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)
const std::string histoDir() const
Get the canonical histogram "directory" path for this analysis.
const std::string histoPath(const std::string &hname) const
Get the canonical histogram path for the named histogram in this analysis.
const std::string histoPath(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const
Get the canonical histogram path for the numbered histogram in this analysis.
bool bookingCompatible(TPtr a, TPtr b)
Definition RivetYODA.hh:1541
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:180
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:182
#define MSG_WARNING(x)
Warning messages for non-fatal bad things, using MSG_LVL.
Definition Logging.hh:187
#define MSG_ERROR(x)
Highest level messaging for serious problems, using MSG_LVL.
Definition Logging.hh:189
std::string findAnalysisDataFile(const std::string &filename, const std::vector< std::string > &pathprepend=std::vector< std::string >(), const std::vector< std::string > &pathappend=std::vector< std::string >())
Find the first file of the given name in the general data file search dirs.
string toLower(const string &s)
Convert a string to lower-case.
Definition Utils.hh:129
Definition MC_CENT_PPB_Projections.hh:10
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:38
Error Exception
Rivet::Exception is a synonym for Rivet::Error.
Definition Exceptions.hh:18
std::shared_ptr< Cutflows > CutflowsPtr
Convenience alias.
Definition Cutflow.hh:498
Generic runtime Rivet error.
Definition Exceptions.hh:12
Error relating to looking up analysis objects in the register.
Definition Exceptions.hh:61
Error for e.g. use of invalid bin ranges.
Definition Exceptions.hh:22
Error for read failures.
Definition Exceptions.hh:72
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:55