Rivet API documentation

Rivet 4.1.3
Analysis.hh
1// -*- C++ -*-
2#ifndef RIVET_Analysis_HH
3#define RIVET_Analysis_HH
4
5#include "Rivet/AnalysisInfo.hh"
6#include "Rivet/AnalysisLoader.hh"
7#include "Rivet/Event.hh"
8#include "Rivet/Projection.hh"
9#include "Rivet/ProjectionApplier.hh"
10#include "Rivet/ProjectionHandler.hh"
11#include "Rivet/Config/RivetCommon.hh"
12#include "Rivet/Tools/Cuts.hh"
13#include "Rivet/Tools/Logging.hh"
14#include "Rivet/Tools/ParticleUtils.hh"
15#ifdef HAVE_H5
16 #include "Rivet/Tools/RivetHDF5.hh"
17#endif
18#include "Rivet/Projections/CentralityProjection.hh"
19#include "Rivet/Projections/FastJets.hh"
20#include "Rivet/Tools/Cutflow.hh"
21#include "Rivet/Tools/HistoGroup.hh"
22#include "Rivet/Tools/Percentile.hh"
23#include "Rivet/Tools/RivetMT2.hh"
24#include "Rivet/Tools/RivetPaths.hh"
25#include "Rivet/Tools/RivetYODA.hh"
26#include <tuple>
27
28
31#define vetoEvent \
32 do { MSG_DEBUG("Vetoing event on line " << __LINE__ << " of " << __FILE__); return; } while(0)
33
34namespace Rivet {
35
36
37 // Convenience for analysis writers
38 using std::cerr;
39 using std::cout;
40 using std::endl;
41 using std::numeric_limits;
42 using std::stringstream;
43 using std::swap;
44 using std::tuple;
45
46
47 // Forward declaration
48 class AnalysisHandler;
49
50
69 class Analysis : public ProjectionApplier {
70 public:
71
73 friend class AnalysisHandler;
74
75
77 Analysis(const std::string& name);
78
80 virtual ~Analysis() { }
81
83 Analysis& operator=(const Analysis&) = delete;
84
85
86 public:
87
90
94 virtual void init() { }
95
100 virtual void analyze(const Event& event) = 0;
101
107 virtual void finalize() { }
108
110
111
114
116 virtual void preInit() { }
118 virtual void postInit() { }
120 virtual void preAnalyze(const Event&) { }
122 virtual void postAnalyze(const Event&) { }
124 virtual void preFinalize() { }
126 virtual void postFinalize() { }
127
132 this->_syncDeclQueue();
133 this->markAsOwned();
134 }
135
137
138
139 public:
140
146
148 void loadInfo() {
149 info().parseInfoFile();
150 }
151
153 const AnalysisInfo& info() const {
154 if (!_info) throw Error("No AnalysisInfo object :-O");
155 return *_info;
156 }
157
165 virtual std::string name() const {
166 return ((info().name().empty()) ? _defaultname : info().name()) + _optstring;
167 }
168
173 std::string analysisDataPath(const std::string& extn, const std::string& suffix = "") {
174 string filename = name() + (suffix.empty() ? "" : "-") + suffix + "." + extn;
175 return findAnalysisDataFile(filename);
176 }
177
179 virtual std::string inspireID() const {
180 return info().inspireID();
181 }
182
184 virtual std::string spiresID() const {
185 return info().spiresID();
186 }
187
192 virtual std::vector<std::string> authors() const {
193 return info().authors();
194 }
195
201 virtual std::string summary() const {
202 return info().summary();
203 }
204
211 virtual std::string description() const {
212 return info().description();
213 }
214
220 virtual std::string runInfo() const {
221 return info().runInfo();
222 }
223
225 virtual std::string experiment() const {
226 return info().experiment();
227 }
228
230 virtual std::string collider() const {
231 return info().collider();
232 }
233
235 virtual std::string year() const {
236 return info().year();
237 }
238
240 virtual double luminosityfb() const {
241 return info().luminosityfb();
242 }
243
244 virtual double luminosity() const {
245 return info().luminosity();
246 }
247
248 double luminositypb() const {
249 return luminosity();
250 }
251
253 virtual std::vector<std::string> references() const {
254 return info().references();
255 }
256
258 virtual std::string bibKey() const {
259 return info().bibKey();
260 }
261
263 virtual std::string bibTeX() const {
264 return info().bibTeX();
265 }
266
268 virtual std::string status() const {
269 return (info().status().empty()) ? "UNVALIDATED" : info().status();
270 }
271
273 virtual std::string warning() const {
274 return info().warning();
275 }
276
278 virtual std::vector<std::string> todos() const {
279 return info().todos();
280 }
281
283 virtual std::vector<std::string> validation() const {
284 return info().validation();
285 }
286
288 virtual bool reentrant() const {
289 return info().reentrant();
290 }
291
293 virtual const std::vector<std::string>& keywords() const {
294 return info().keywords();
295 }
296
298 virtual std::string refMatch() const {
299 return info().refMatch();
300 }
301
303 virtual std::string refUnmatch() const {
304 return info().refUnmatch();
305 }
306
308 virtual std::string writerDoublePrecision() const {
309 return info().writerDoublePrecision();
310 }
311
313 virtual const std::vector<PdgIdPair>& requiredBeamIDs() const {
314 return info().beamIDs();
315 }
316
317 virtual Analysis& setRequiredBeamIDs(const std::vector<PdgIdPair>& beamids) {
318 info().setBeamIDs(beamids);
319 return *this;
320 }
321
323 virtual const std::vector<std::pair<double, double>>& requiredBeamEnergies() const {
324 return info().energies();
325 }
326
327 virtual Analysis& setRequiredBeamEnergies(const std::vector<std::pair<double, double>>& energies) {
328 info().setEnergies(energies);
329 return *this;
330 }
331
332
334 virtual std::string refFile() const {
335 return info().refFile();
336 }
337
338 virtual std::string refDataName() const {
339 return (info().getRefDataName().empty()) ? _defaultname : info().getRefDataName();
340 }
341
342 virtual void setRefDataName(const std::string& ref_data = "") {
343 info().setRefDataName(!ref_data.empty() ? ref_data : name());
344 }
345
346
351 if (!_info) throw Error("No AnalysisInfo object :-O");
352 return *_info;
353 }
354
356
357
360
362 bool merging() const {
363 return sqrtS() <= 0.0;
364 }
365
367 bool compatibleWithRun() const;
368
370 void raiseBeamErrorIf(const bool condition) const;
371
373
374
378
380 const ParticlePair& beams() const;
381
383 PdgIdPair beamIDs() const;
384
386 pair<double, double> beamEnergies() const;
387
389 vector<double> allowedEnergies() const;
390
392 double sqrtS() const;
393
395 bool beamsMatch(const ParticlePair& beams) const;
396
398 bool beamsMatch(PdgId beam1, PdgId beam2, double e1, double e2) const;
399
401 bool beamsMatch(const PdgIdPair& beams, const std::pair<double, double>& energies) const;
402
404 bool beamIDsMatch(PdgId beam1, PdgId beam2) const;
405
407 bool beamIDsMatch(const PdgIdPair& beamids) const;
408
410 bool beamEnergiesMatch(double e1, double e2) const;
411
413 bool beamEnergiesMatch(const std::pair<double, double>& energies) const;
414
416 bool beamEnergyMatch(const std::pair<double, double>& energies) const;
417
419 bool beamEnergyMatch(double sqrts) const;
420
422 bool isCompatibleWithSqrtS(double energy, double tolerance = 1e-5) const;
423
425
426
429 return *_analysishandler;
430 }
431
433 const Event& currentEvent() const {
434 if (!_currentevent) {
435 throw Error("No current event set: did you try to access it in init() or finalize()?");
436 }
437 return *_currentevent;
438 }
439
440
441 protected:
442
444 Log& getLog() const;
445
447 double crossSection() const;
448
451 double crossSectionPerEvent() const;
452
454 double crossSectionError() const;
455
459
463 size_t numEvents() const;
464
468 double effNumEvents() const;
469
473 double sumW() const;
475 double sumOfWeights() const {
476 return sumW();
477 }
478
482 double sumW2() const;
483
484
485 protected:
486
492
494 const std::string histoDir() const;
495
497 const std::string histoPath(const std::string& hname) const;
498
500 const std::string histoPath(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
501
503 const std::string mkAxisCode(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
504
506
507
508#ifdef HAVE_H5
511
513 H5::File auxFile() const {
514 return H5::readFile(name() + ".h5");
515 }
516
518 template <typename T>
519 bool auxData(const string& dsname, T& rtndata) {
521 return H5::readData(name() + ".h5", dsname, rtndata);
522 }
523
524 template <typename T>
525 T auxData(const string& dsname) {
527 return H5::readData<T>(name() + ".h5", dsname);
528 }
529
531
532#endif
533
534
537
539 const std::map<std::string, YODA::AnalysisObjectPtr>& refData() const {
540 _cacheRefData();
541 return _refdata;
542 }
543
545 bool hasRefData(const string& hname) const {
546 _cacheRefData();
547 return _refdata.count(hname);
548 }
549
551 bool hasRefData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
552 return hasRefData(mkAxisCode(datasetId, xAxisId, yAxisId));
553 }
554
555
559 template <typename T = YODA::Estimate1D>
560 const T& refData(const string& hname) const {
561 _cacheRefData();
562 MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
563 if (!_refdata[hname]) {
564 MSG_ERROR("Can't find reference histogram " << hname);
565 throw Exception("Reference data " + hname + " not found.");
566 }
567 try {
568 return dynamic_cast<T&>(*_refdata[hname]);
569 }
570 catch (...) {
571 throw Exception("Expected type " + _refdata[hname]->type() + " for reference data \"" + hname
572 + "\".\n");
573 }
574 }
575
576
580 template <typename T = YODA::Estimate1D>
581 const T& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
582 const string hname = mkAxisCode(datasetId, xAxisId, yAxisId);
583 return refData<T>(hname);
584 }
585
587
588
594
596 CounterPtr& book(CounterPtr&, const std::string& name);
597
601 CounterPtr& book(CounterPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
602
604
605
608
610 Estimate0DPtr& book(Estimate0DPtr&, const std::string& name);
611
615 Estimate0DPtr& book(Estimate0DPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
616
617
619
622
624 template <size_t DbnN, typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
625 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao,
626 const std::string& name,
627 const std::vector<size_t>& nbins,
628 const std::vector<std::pair<double, double>>& loUpPairs) {
629 if (nbins.size() != loUpPairs.size()) {
630 throw RangeError("Vectors should have the same size!");
631 }
632 const string path = histoPath(name);
633
634 YODA::BinnedDbn<DbnN, AxisT...> yao(nbins, loUpPairs, path);
635 _setWriterPrecision(path, yao);
636
637 return ao = registerAO(yao);
638 }
639
640 // Specialiation for 1D
641 Histo1DPtr& book(Histo1DPtr& ao,
642 const std::string& name,
643 const size_t nbins,
644 const double lower,
645 const double upper) {
646 return book(ao, name, vector<size_t>{nbins}, vector<pair<double, double>>{{lower, upper}});
647 }
648 //
649 Profile1DPtr& book(Profile1DPtr& ao,
650 const std::string& name,
651 const size_t nbins,
652 const double lower,
653 const double upper) {
654 return book(ao, name, vector<size_t>{nbins}, vector<pair<double, double>>{{lower, upper}});
655 }
656
657 // Specialiation for 2D
658 Histo2DPtr& book(Histo2DPtr& ao,
659 const std::string& name,
660 const size_t nbinsX,
661 const double lowerX,
662 const double upperX,
663 const size_t nbinsY,
664 const double lowerY,
665 const double upperY) {
666 return book(ao, name, vector<size_t>{nbinsX, nbinsY},
667 vector<pair<double, double>>{{lowerX, upperX}, {lowerY, upperY}});
668 }
669 //
670 Profile2DPtr& book(Profile2DPtr& ao,
671 const std::string& name,
672 const size_t nbinsX,
673 const double lowerX,
674 const double upperX,
675 const size_t nbinsY,
676 const double lowerY,
677 const double upperY) {
678 return book(ao, name, vector<size_t>{nbinsX, nbinsY},
679 vector<pair<double, double>>{{lowerX, upperX}, {lowerY, upperY}});
680 }
681
682 // Specialiation for 3D
683 Histo3DPtr& book(Histo3DPtr& ao,
684 const std::string& name,
685 const size_t nbinsX,
686 const double lowerX,
687 const double upperX,
688 const size_t nbinsY,
689 const double lowerY,
690 const double upperY,
691 const size_t nbinsZ,
692 const double lowerZ,
693 const double upperZ) {
694 return book(ao, name, vector<size_t>{nbinsX, nbinsY, nbinsZ},
695 vector<pair<double, double>>{{lowerX, upperX}, {lowerY, upperY}, {lowerZ, upperZ}});
696 }
697 //
698 Profile3DPtr& book(Profile3DPtr& ao,
699 const std::string& name,
700 const size_t nbinsX,
701 const double lowerX,
702 const double upperX,
703 const size_t nbinsY,
704 const double lowerY,
705 const double upperY,
706 const size_t nbinsZ,
707 const double lowerZ,
708 const double upperZ) {
709 return book(ao, name, vector<size_t>{nbinsX, nbinsY, nbinsZ},
710 vector<pair<double, double>>{{lowerX, upperX}, {lowerY, upperY}, {lowerZ, upperZ}});
711 }
712
714 template <size_t DbnN, typename... AxisT>
715 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao,
716 const std::string& name,
717 const std::vector<AxisT>&... binedges) {
718 const string path = histoPath(name);
719 YODA::BinnedDbn<DbnN, AxisT...> yao(binedges..., path);
720 _setWriterPrecision(path, yao);
721
722 return ao = registerAO(yao);
723 }
724
726 template <size_t DbnN, typename... AxisT>
727 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao,
728 const std::string& name,
729 const std::initializer_list<AxisT>&... binedges) {
730 return book(ao, name, vector<AxisT>{binedges}...);
731 }
732
734 template <size_t DbnN, typename... AxisT>
735 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao,
736 const std::string& name,
737 const YODA::BinnedEstimate<AxisT...>& refest) {
738 const string path = histoPath(name);
739
740 YODA::BinnedDbn<DbnN, AxisT...> yao(refest.binning(), path);
741 for (const string& a : yao.annotations()) {
742 if (a != "Path") yao.rmAnnotation(a);
743 }
744 _setWriterPrecision(path, yao);
745 return ao = registerAO(yao);
746 }
747
749 template <size_t DbnN, typename... AxisT>
750 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name) {
751 return book(ao, name, refData<YODA::BinnedEstimate<AxisT...>>(name));
752 }
753
757 template <size_t DbnN, typename... AxisT>
758 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao,
759 const unsigned int datasetID,
760 const unsigned int xAxisID,
761 const unsigned int yAxisID) {
762 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
763 return book(ao, name);
764 }
765
767
770
771 template <typename GroupAxisT, typename... AxisT>
772 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
773 const std::vector<GroupAxisT>& edges,
774 const std::vector<std::string>& names) {
775 ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
776 if (ao->numBins() != names.size()) {
777 throw RangeError("Binning and reference-data names don't match!");
778 }
779 for (auto& b : ao->bins()) {
780 const string& refname = names[b.index() - 1];
781 book(b, refname, refData<YODA::BinnedEstimate<AxisT...>>(refname));
782 }
783 return ao;
784 }
785
786 template <typename GroupAxisT, typename... AxisT>
787 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
788 const std::vector<GroupAxisT>& edges) {
789 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
790 }
791
792 template <typename GroupAxisT, typename... AxisT>
793 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
794 std::initializer_list<GroupAxisT>&& edges) {
795 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(std::move(edges));
796 }
797
799
802
804 template <typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
805 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao,
806 const std::string& name,
807 const std::vector<size_t>& nbins,
808 const std::vector<std::pair<double, double>>& loUpPairs) {
809 if (nbins.size() != loUpPairs.size()) {
810 throw RangeError("Vectors should have the same size!");
811 }
812 const string path = histoPath(name);
813
814 YODA::BinnedEstimate<AxisT...> yao(nbins, loUpPairs, path);
815 _setWriterPrecision(path, yao);
816
817 return ao = registerAO(yao);
818 }
819
820
821 // Specialiation for 1D
822 Estimate1DPtr& book(Estimate1DPtr& ao,
823 const std::string& name,
824 const size_t nbins,
825 const double lower,
826 const double upper) {
827 return book(ao, name, vector<size_t>{nbins}, vector<pair<double, double>>{{lower, upper}});
828 }
829
830 // Specialiation for 2D
831 Estimate2DPtr& book(Estimate2DPtr& ao,
832 const std::string& name,
833 const size_t nbinsX,
834 const double lowerX,
835 const double upperX,
836 const size_t nbinsY,
837 const double lowerY,
838 const double upperY) {
839 return book(ao, name, vector<size_t>{nbinsX, nbinsY},
840 vector<pair<double, double>>{{lowerX, upperX}, {lowerY, upperY}});
841 }
842
843 // Specialiation for 3D
844 Estimate3DPtr& book(Estimate3DPtr& ao,
845 const std::string& name,
846 const size_t nbinsX,
847 const double lowerX,
848 const double upperX,
849 const size_t nbinsY,
850 const double lowerY,
851 const double upperY,
852 const size_t nbinsZ,
853 const double lowerZ,
854 const double upperZ) {
855 return book(ao, name, vector<size_t>{nbinsX, nbinsY, nbinsZ},
856 vector<pair<double, double>>{{lowerX, upperX}, {lowerY, upperY}, {lowerZ, upperZ}});
857 }
858
860 template <typename... AxisT>
861 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao,
862 const std::string& name,
863 const std::vector<AxisT>&... binedges) {
864 const string path = histoPath(name);
865 YODA::BinnedEstimate<AxisT...> yao(binedges..., path);
866 _setWriterPrecision(path, yao);
867
868 return ao = registerAO(yao);
869 }
870
872 template <typename... AxisT>
873 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao,
874 const std::string& name,
875 const std::initializer_list<AxisT>&... binedges) {
876 return book(ao, name, vector<AxisT>{binedges}...);
877 }
878
880 template <typename... AxisT>
881 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name) {
882
883 const string path = histoPath(name);
884 YODA::BinnedEstimate<AxisT...> yao;
885 try {
886 yao = YODA::BinnedEstimate<AxisT...>(refData<YODA::BinnedEstimate<AxisT...>>(name).binning());
887 }
888 catch (...) {
889 MSG_DEBUG("Couldn't retrieve reference binning, continue with nullary AO constructor.");
890 }
891 yao.setPath(path);
892 _setWriterPrecision(path, yao);
893 return ao = registerAO(yao);
894 }
895
899 template <typename... AxisT>
900 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao,
901 const unsigned int datasetID,
902 const unsigned int xAxisID,
903 const unsigned int yAxisID) {
904 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
905 return book(ao, name);
906 }
907
909
910
913
924 template <size_t N>
925 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const bool copy_pts = false) {
926 const string path = histoPath(name);
927 YODA::ScatterND<N> scat(path);
928 if (copy_pts) {
929 const YODA::ScatterND<N> ref = refData<YODA::EstimateND<N - 1>>(name).mkScatter();
930 for (YODA::PointND<N> p : ref.points()) {
931 p.setVal(N - 1, 0.0);
932 p.setErr(N - 1, 0.0);
933 scat.addPoint(std::move(p));
934 }
935 }
936 _setWriterPrecision(path, scat);
937 return snd = registerAO(scat);
938 }
939
950 template <size_t N>
951 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd,
952 const unsigned int datasetID,
953 const unsigned int xAxisID,
954 const unsigned int yAxisID,
955 const bool copy_pts = false) {
956 const string axisCode = mkAxisCode(datasetID, xAxisID, yAxisID);
957 return book(snd, axisCode, copy_pts);
958 }
959
965 Scatter2DPtr& book(Scatter2DPtr& snd,
966 const string& name,
967 const size_t npts,
968 const double lower,
969 const double upper) {
970 const string path = histoPath(name);
971
972 Scatter2D scat(path);
973 const double binwidth = (upper - lower) / npts;
974 for (size_t pt = 0; pt < npts; ++pt) {
975 const double bincentre = lower + (pt + 0.5) * binwidth;
976 scat.addPoint(bincentre, 0, binwidth / 2.0, 0);
977 }
978 _setWriterPrecision(path, scat);
979
980 return snd = registerAO(scat);
981 }
982 //
983 Scatter3DPtr& book(Scatter3DPtr& snd,
984 const string& name,
985 const size_t nptsX,
986 const double lowerX,
987 const double upperX,
988 const size_t nptsY,
989 const double lowerY,
990 const double upperY) {
991 const string path = histoPath(name);
992
993 Scatter3D scat(path);
994 const double xbinwidth = (upperX - lowerX) / nptsX;
995 const double ybinwidth = (upperY - lowerY) / nptsY;
996 for (size_t xpt = 0; xpt < nptsX; ++xpt) {
997 const double xbincentre = lowerX + (xpt + 0.5) * xbinwidth;
998 for (size_t ypt = 0; ypt < nptsY; ++ypt) {
999 const double ybincentre = lowerY + (ypt + 0.5) * ybinwidth;
1000 scat.addPoint(xbincentre, ybincentre, 0, 0.5 * xbinwidth, 0.5 * ybinwidth, 0);
1001 }
1002 }
1003 _setWriterPrecision(path, scat);
1004
1005 return snd = registerAO(scat);
1006 }
1007
1013 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name, const std::vector<double>& binedges) {
1014 const string path = histoPath(name);
1015
1016 Scatter2D scat(path);
1017 for (size_t pt = 0; pt < binedges.size() - 1; ++pt) {
1018 const double bincentre = (binedges[pt] + binedges[pt + 1]) / 2.0;
1019 const double binwidth = binedges[pt + 1] - binedges[pt];
1020 scat.addPoint(bincentre, 0, binwidth / 2.0, 0);
1021 }
1022 _setWriterPrecision(path, scat);
1023
1024 return snd = registerAO(scat);
1025 }
1026 //
1027 Scatter3DPtr& book(Scatter3DPtr& snd,
1028 const string& name,
1029 const std::vector<double>& binedgesX,
1030 const std::vector<double>& binedgesY) {
1031 const string path = histoPath(name);
1032
1033 Scatter3D scat(path);
1034 for (size_t xpt = 0; xpt < binedgesX.size() - 1; ++xpt) {
1035 const double xbincentre = (binedgesX[xpt] + binedgesX[xpt + 1]) / 2.0;
1036 const double xbinwidth = binedgesX[xpt + 1] - binedgesX[xpt];
1037 for (size_t ypt = 0; ypt < binedgesY.size() - 1; ++ypt) {
1038 const double ybincentre = (binedgesY[ypt] + binedgesY[ypt + 1]) / 2.0;
1039 const double ybinwidth = binedgesY[ypt + 1] - binedgesY[ypt];
1040 scat.addPoint(xbincentre, ybincentre, 0, 0.5 * xbinwidth, 0.5 * ybinwidth, 0);
1041 }
1042 }
1043 _setWriterPrecision(path, scat);
1044
1045 return snd = registerAO(scat);
1046 }
1047
1049 template <size_t N>
1050 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const YODA::ScatterND<N>& refscatter) {
1051 const string path = histoPath(name);
1052
1053 YODA::ScatterND<N> scat(refscatter, path);
1054 for (const string& a : scat.annotations()) {
1055 if (a != "Path") scat.rmAnnotation(a);
1056 }
1057 _setWriterPrecision(path, scat);
1058
1059 return snd = registerAO(scat);
1060 }
1061
1063
1066
1068 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::vector<std::string>& edges) {
1069 const string path = histoPath(name);
1070 Cutflow yao(edges, path);
1071 _setWriterPrecision(path, yao);
1072 return ao = registerAO(yao);
1073 }
1074
1076 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::initializer_list<std::string>& edges) {
1077 return book(ao, name, vector<std::string>{edges});
1078 }
1079
1081
1084
1086 const std::vector<std::string>& edges,
1087 const std::vector<std::vector<std::string>>& innerEdges) {
1088 ao = make_shared<Cutflows>(edges);
1089 if (ao->numBins() != innerEdges.size()) {
1090 throw RangeError("Outer and Inner edges don't match");
1091 }
1092 for (auto& b : ao->bins()) {
1093 book(b, b.xEdge(), innerEdges[b.index() - 1]);
1094 }
1095 return ao;
1096 }
1097
1098 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges) {
1099 return ao = make_shared<Cutflows>(edges);
1100 }
1101
1102 CutflowsPtr& book(CutflowsPtr& ao, std::initializer_list<std::string>&& edges) {
1103 return ao = make_shared<Cutflows>(std::move(edges));
1104 }
1105
1107
1108
1112 virtual void rawHookIn(YODA::AnalysisObjectPtr yao) {
1113 (void)yao; // suppress unused variable warning
1114 }
1115
1119 virtual void rawHookOut(const vector<MultiplexAOPtr>& raos, size_t iW) {
1120 (void)raos; // suppress unused variable warning
1121 (void)iW; // suppress unused variable warning
1122 }
1123
1124
1125 public:
1126
1129
1131 const std::map<std::string, std::string>& options() const {
1132 return _options;
1133 }
1134
1136 std::string getOption(std::string optname, string def = "") const {
1137 if (_options.find(optname) != _options.end()) return _options.find(optname)->second;
1138 return def;
1139 }
1140
1145 std::string getOption(std::string optname, const char* def) {
1146 return getOption<std::string>(optname, def);
1147 }
1148
1156 template <typename T>
1157 T getOption(std::string optname, T def) const {
1158 if (_options.find(optname) == _options.end()) return def;
1159 std::stringstream ss;
1160 ss.exceptions(std::ios::failbit);
1161 T ret;
1162 ss << _options.find(optname)->second;
1163 try {
1164 ss >> ret;
1165 }
1166 catch (...) {
1167 throw ReadError("Could not read user-provided option into requested type");
1168 }
1169 return ret;
1170 }
1171
1182 // template<>
1183 // bool getOption<bool>(std::string optname, bool def) const {
1184 bool getOption(std::string optname, bool def) const {
1185 if (_options.find(optname) == _options.end()) return def;
1186 const std::string val = getOption(optname);
1187 const std::string lval = toLower(val);
1188 if (lval.empty()) return false;
1189 if (lval == "true" || lval == "yes" || lval == "on") return true;
1190 if (lval == "false" || lval == "no" || lval == "off") return false;
1191 return bool(getOption<int>(optname, 0));
1192 }
1193
1195
1196
1199
1217 string calAnaName,
1218 string calHistName,
1219 const string projName,
1220 PercentileOrder pctorder = PercentileOrder::DECREASING);
1221
1222
1229 template <typename T>
1230 Percentile<T> book(const string& projName,
1231 const vector<pair<double, double>>& centralityBins,
1232 const vector<tuple<size_t, size_t, size_t>>& ref) {
1233
1234 using RefT = typename ReferenceTraits<T>::RefT;
1235 using WrapT = MultiplexPtr<Multiplexer<T>>;
1236
1237 Percentile<T> pctl(this, projName);
1238
1239 const size_t nCent = centralityBins.size();
1240 for (size_t iCent = 0; iCent < nCent; ++iCent) {
1241 const string axisCode = mkAxisCode(std::get<0>(ref[iCent]), std::get<1>(ref[iCent]),
1242 std::get<2>(ref[iCent]));
1243 const RefT& refscatter = refData<RefT>(axisCode);
1244
1245 WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1246 wtf = addAnalysisObject(wtf);
1247
1248 CounterPtr cnt(_weightNames(), Counter(histoPath("TMP/COUNTER/" + axisCode)));
1249 cnt = addAnalysisObject(cnt);
1250
1251 pctl.add(wtf, cnt, centralityBins[iCent]);
1252 }
1253 return pctl;
1254 }
1255
1256
1257 // /// @brief Book Percentile Multiplexers around AnalysisObjects.
1258 // ///
1259 // /// Based on a previously registered CentralityProjection named @a
1260 // /// projName book one (or several) AnalysisObject(s) named
1261 // /// according to @a ref where the x-axis will be filled according
1262 // /// to the percentile output(s) of the @projName.
1263 // ///
1264 // /// @todo Convert to just be called book() cf. others
1265 // template <class T>
1266 // PercentileXaxis<T> bookPercentileXaxis(string projName,
1267 // tuple<int, int, int> ref) {
1268
1269 // typedef typename ReferenceTraits<T>::RefT RefT;
1270 // typedef MultiplexPtr<Multiplexer<T>> WrapT;
1271
1272 // PercentileXaxis<T> pctl(this, projName);
1273
1274 // const string axisCode = mkAxisCode(std::get<0>(ref),
1275 // std::get<1>(ref),
1276 // std::get<2>(ref));
1277 // const RefT & refscatter = refData<RefT>(axisCode);
1278
1279 // WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1280 // wtf = addAnalysisObject(wtf);
1281
1282 // CounterPtr cnt(_weightNames(), Counter());
1283 // cnt = addAnalysisObject(cnt);
1284
1285 // pctl.add(wtf, cnt);
1286 // return pctl;
1287 // }
1288
1290
1291
1292 private:
1293
1294 // Functions that have to be defined in the .cc file to avoid circular #includes
1295
1297 vector<string> _weightNames() const;
1298
1300 YODA::AnalysisObjectPtr _getPreload(const string& name) const;
1301
1303 MultiplexAOPtr _getOtherAnalysisObject(const std::string& ananame, const std::string& name);
1304
1306 void _checkBookInit() const;
1307
1309 bool _inInit() const;
1310
1312 bool _inFinalize() const;
1313
1315 template <typename YODAT>
1316 void _setWriterPrecision(const string& path, YODAT& yao) {
1317 const string re = _info->writerDoublePrecision();
1318 if (re != "") {
1319 std::smatch match;
1320 const bool needsDP = std::regex_search(path, match, std::regex(re));
1321 if (needsDP) yao.setAnnotation("WriterDoublePrecision", "1");
1322 }
1323 }
1324
1325
1326 private:
1327
1329 class CounterAdapter {
1330 public:
1331
1332 CounterAdapter(double x)
1333 : x_(x) { }
1334
1335 CounterAdapter(const YODA::Counter& c)
1336 : x_(c.val()) { }
1337
1338 CounterAdapter(const YODA::Estimate& e)
1339 : x_(e.val()) { }
1340
1341 CounterAdapter(const YODA::Scatter1D& s)
1342 : x_(s.points()[0].x()) {
1343 if (s.numPoints() != 1) throw RangeError("Can only scale by a single value.");
1344 }
1345
1346 operator double() const {
1347 return x_;
1348 }
1349
1350 private:
1351
1352 double x_;
1353 };
1354
1355
1356 public:
1357
1358 double dbl(double x) {
1359 return x;
1360 }
1361 double dbl(const YODA::Counter& c) {
1362 return c.val();
1363 }
1364 double dbl(const YODA::Estimate0D& e) {
1365 return e.val();
1366 }
1367 double dbl(const YODA::Scatter1D& s) {
1368 if (s.numPoints() != 1) throw RangeError("Only scatter with single value supported.");
1369 return s.points()[0].x();
1370 }
1371
1372
1373 protected:
1374
1378
1380 template <typename T>
1381 void scale(MultiplexPtr<Multiplexer<T>>& ao, CounterAdapter factor) {
1382 if (!ao) {
1383 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1384 << name() << " (scale=" << double(factor) << ")");
1385 return;
1386 }
1387 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1388 MSG_WARNING("Failed to scale AnalysisObject=" << ao->path() << " in analysis: " << name()
1389 << " (invalid scale factor = " << double(factor)
1390 << ")");
1391 factor = 0;
1392 }
1393 MSG_TRACE("Scaling AnalysisObject " << ao->path() << " by factor " << double(factor));
1394 try {
1395 if constexpr (isFillable<T>::value) {
1396 ao->scaleW(factor);
1397 }
1398 else {
1399 ao->scale(factor);
1400 }
1401 }
1402 catch (YODA::Exception& we) {
1403 MSG_WARNING("Could not scale AnalysisObject " << ao->path());
1404 return;
1405 }
1406 }
1407
1409 template <typename GroupAxisT, typename... AxisT>
1410 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, CounterAdapter factor) {
1411 if (!group) {
1412 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1413 << name() << " (scale=" << double(factor) << ")");
1414 return;
1415 }
1416 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1417 MSG_WARNING("Failed to scale histo group in analysis: " << name() << " (invalid scale factor = "
1418 << double(factor) << ")");
1419 factor = 0;
1420 }
1421 MSG_TRACE("Scaling histo group by factor " << double(factor));
1422 try {
1423 group->scaleW(factor);
1424 }
1425 catch (YODA::Exception& we) {
1426 MSG_WARNING("Could not scale histo group.");
1427 return;
1428 }
1429 }
1430
1432 template <typename GroupAxisT, typename... AxisT>
1433 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, const vector<double>& factors) {
1434 if (!group) {
1435 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis " << name());
1436 return;
1437 }
1438 if (group->numBins(true) != factors.size()) {
1439 throw RangeError(name() + ": Number of scale factors does not match group binning");
1440 return;
1441 }
1442 for (auto& b : group->bins(true)) {
1443 if (!b.get()) continue;
1444 double factor = factors[b.index()];
1445 if (std::isnan(factor) || std::isinf(factor)) {
1446 MSG_WARNING("Failed to scale componment of histo group in analysis: "
1447 << name() << " (invalid scale factor = " << factor << ")");
1448 factor = 0;
1449 }
1450 MSG_TRACE("Scaling histo group element by factor " << factor);
1451 try {
1452 b->scaleW(factor);
1453 }
1454 catch (YODA::Exception& we) {
1455 MSG_WARNING("Could not scale component of histo group.");
1456 }
1457 }
1458 }
1459
1461 void scale(CutflowsPtr& group, CounterAdapter factor) {
1462 if (!group) {
1463 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1464 << name() << " (scale=" << double(factor) << ")");
1465 return;
1466 }
1467 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1468 MSG_WARNING("Failed to scale histo group in analysis: " << name() << " (invalid scale factor = "
1469 << double(factor) << ")");
1470 factor = 0;
1471 }
1472 MSG_TRACE("Scaling histo group by factor " << double(factor));
1473 try {
1474 group->scale(factor);
1475 }
1476 catch (YODA::Exception& we) {
1477 MSG_WARNING("Could not scale histo group.");
1478 return;
1479 }
1480 }
1481
1483 template <typename T, typename U>
1484 void scale(std::map<T, U>& aos, CounterAdapter factor) {
1485 for (auto& item : aos) scale(item.second, factor);
1486 }
1487
1489 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1490 void scale(AORange& aos, CounterAdapter factor) {
1491 for (auto& ao : aos) scale(ao, factor);
1492 }
1493
1495 template <typename T>
1496 void scale(std::initializer_list<T> aos, CounterAdapter factor) {
1497 for (auto& ao : std::vector<T>{aos}) scale(ao, factor);
1498 }
1499
1501 template <typename T, typename U>
1502 void scale(std::map<T, U>& aos, const vector<double>& factors) {
1503 for (auto& item : aos) scale(item.second, factors);
1504 }
1505
1507 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1508 void scale(AORange& aos, const vector<double>& factors) {
1509 for (auto& ao : aos) scale(ao, factors);
1510 }
1511
1513 template <typename T>
1514 void scale(std::initializer_list<T> aos, const vector<double>& factors) {
1515 for (auto& ao : std::vector<T>{aos}) scale(ao, factors);
1516 }
1517
1519 template <typename GroupAxisT, typename... AxisT>
1520 void divByGroupWidth(HistoGroupPtr<GroupAxisT, AxisT...>& group) {
1521 if (!group) {
1522 MSG_WARNING("Failed to scale HistoGroup=NULL in analysis " << name() << " by group axis width");
1523 return;
1524 }
1525 group->divByGroupWidth();
1526 }
1527
1529 template <typename T, typename U>
1530 void divByGroupWidth(std::map<T, U>& aos) {
1531 for (auto& item : aos) divByGroupWidth(item.second);
1532 }
1533
1535 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1536 void divByGroupWidth(AORange& aos) {
1537 for (auto& ao : aos) divByGroupWidth(ao);
1538 }
1539
1541 template <typename T>
1542 void divByGroupWidth(std::initializer_list<T> aos) {
1543 for (auto& ao : std::vector<T>{aos}) divByGroupWidth(ao);
1544 }
1545
1546
1548 template <size_t DbnN, typename... AxisT>
1549 void normalize(BinnedDbnPtr<DbnN, AxisT...> ao,
1550 const CounterAdapter norm = 1.0,
1551 const bool includeoverflows = true) {
1552 if (!ao) {
1553 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm)
1554 << ")");
1555 return;
1556 }
1557 MSG_TRACE("Normalizing histo " << ao->path() << " to " << double(norm));
1558 try {
1559 const double hint = ao->integral(includeoverflows);
1560 if (hint == 0) {
1561 MSG_DEBUG("Skipping histo with null area " << ao->path());
1562 }
1563 else {
1564 ao->normalize(norm, includeoverflows);
1565 }
1566 }
1567 catch (YODA::Exception& we) {
1568 MSG_WARNING("Could not normalize histo " << ao->path());
1569 return;
1570 }
1571 }
1572
1574 template <typename GroupAxisT, typename... AxisT>
1575 void normalize(HistoGroupPtr<GroupAxisT, AxisT...> group,
1576 const CounterAdapter norm = 1.0,
1577 const bool includeoverflows = true) {
1578 if (!group) {
1579 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm)
1580 << ")");
1581 return;
1582 }
1583 MSG_TRACE("Normalizing histo group to " << double(norm));
1584 try {
1585 const double hint = group->integral(includeoverflows);
1586 if (hint == 0) {
1587 MSG_DEBUG("Skipping histo group with null area.");
1588 }
1589 else {
1590 group->normalize(norm, includeoverflows);
1591 }
1592 }
1593 catch (YODA::Exception& we) {
1594 MSG_WARNING("Could not normalize histo group.");
1595 return;
1596 }
1597 }
1598
1599
1601 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1602 void normalize(AORange& aos, const CounterAdapter norm = 1.0, const bool includeoverflows = true) {
1603 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1604 }
1605
1607 template <typename T>
1608 void normalize(std::initializer_list<T>&& aos,
1609 const CounterAdapter norm = 1.0,
1610 const bool includeoverflows = true) {
1611 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1612 }
1613
1615 template <typename T, typename U>
1616 void normalize(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1617 const CounterAdapter norm = 1.0,
1618 const bool includeoverflows = true) {
1619 for (auto& item : aos) normalize(item.second, norm, includeoverflows);
1620 }
1621
1623 template <typename GroupAxisT, typename... AxisT>
1624 void normalizeGroup(HistoGroupPtr<GroupAxisT, AxisT...> group,
1625 const CounterAdapter norm = 1.0,
1626 const bool includeoverflows = true) {
1627 if (!group) {
1628 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm)
1629 << ")");
1630 return;
1631 }
1632 MSG_TRACE("Normalizing histo group to " << double(norm));
1633 try {
1634 const double hint = group->integral(includeoverflows);
1635 if (hint == 0) {
1636 MSG_DEBUG("Skipping histo group with null area.");
1637 }
1638 else {
1639 group->normalizeGroup(norm, includeoverflows);
1640 }
1641 }
1642 catch (YODA::Exception& we) {
1643 MSG_WARNING("Could not normalize histo group.");
1644 return;
1645 }
1646 }
1647
1649 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1650 void normalizeGroup(AORange& aos, const CounterAdapter norm = 1.0, const bool includeoverflows = true) {
1651 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1652 }
1653
1655 template <typename T>
1656 void normalizeGroup(std::initializer_list<T>&& aos,
1657 const CounterAdapter norm = 1.0,
1658 const bool includeoverflows = true) {
1659 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1660 }
1661
1663 template <typename T, typename U>
1664 void normalizeGroup(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1665 const CounterAdapter norm = 1.0,
1666 const bool includeoverflows = true) {
1667 for (auto& item : aos) normalizeGroup(item.second, norm, includeoverflows);
1668 }
1669
1670
1675 template <size_t DbnN, typename... AxisT>
1676 void barchart(BinnedDbnPtr<DbnN, AxisT...> ao, BinnedEstimatePtr<AxisT...> est) const {
1677 const string path = est->path();
1678 *est = ao->mkEstimate(path, "stats",
1679 false); //< do NOT divide by bin area cf. a differential dsigma/dX histogram
1680 }
1681
1685 void divide(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const;
1686
1690 void divide(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const;
1691
1695 void divide(Estimate0DPtr e1, Estimate0DPtr e2, Estimate0DPtr est) const;
1696
1700 void divide(const YODA::Estimate0D& e1, const YODA::Estimate0D& e2, Estimate0DPtr est) const;
1701
1702
1706 template <size_t DbnN, typename... AxisT>
1707 void divide(const YODA::BinnedDbn<DbnN, AxisT...>& h1,
1708 const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1709 BinnedEstimatePtr<AxisT...> est) const {
1710 const string path = est->path();
1711 *est = h1 / h2;
1712 est->setPath(path);
1713 }
1714 //
1715 template <size_t DbnN, typename... AxisT>
1716 void divide(BinnedDbnPtr<DbnN, AxisT...> h1,
1717 BinnedDbnPtr<DbnN, AxisT...> h2,
1718 BinnedEstimatePtr<AxisT...> est) const {
1719 return divide(*h1, *h2, est);
1720 }
1721
1725 template <typename... AxisT>
1726 void divide(const YODA::BinnedEstimate<AxisT...>& e1,
1727 const YODA::BinnedEstimate<AxisT...>& e2,
1728 BinnedEstimatePtr<AxisT...> est) const {
1729 const string path = est->path();
1730 *est = e1 / e2;
1731 est->setPath(path);
1732 }
1733 //
1734 template <typename... AxisT>
1735 void divide(BinnedEstimatePtr<AxisT...> e1,
1736 BinnedEstimatePtr<AxisT...> e2,
1737 BinnedEstimatePtr<AxisT...> est) const {
1738 return divide(*e1, *e2, est);
1739 }
1740
1741
1745 void efficiency(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const {
1746 efficiency(*c1, *c2, est);
1747 }
1748
1752 void efficiency(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const {
1753 const string path = est->path();
1754 *est = YODA::efficiency(c1, c2);
1755 est->setPath(path);
1756 }
1757
1758
1762 template <size_t DbnN, typename... AxisT>
1763 void efficiency(const YODA::BinnedDbn<DbnN, AxisT...>& h1,
1764 const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1765 BinnedEstimatePtr<AxisT...> est) const {
1766 const string path = est->path();
1767 *est = YODA::efficiency(h1, h2);
1768 est->setPath(path);
1769 }
1770 //
1771 template <size_t DbnN, typename... AxisT>
1772 void efficiency(BinnedDbnPtr<DbnN, AxisT...> h1,
1773 BinnedDbnPtr<DbnN, AxisT...> h2,
1774 BinnedEstimatePtr<AxisT...> est) const {
1775 efficiency(*h1, *h2, est);
1776 }
1777
1778
1782 template <typename... AxisT>
1783 void efficiency(const YODA::BinnedEstimate<AxisT...>& e1,
1784 const YODA::BinnedEstimate<AxisT...>& e2,
1785 BinnedEstimatePtr<AxisT...> est) const {
1786 const string path = est->path();
1787 *est = YODA::efficiency(e1, e2);
1788 est->setPath(path);
1789 }
1790 //
1791 template <typename... AxisT>
1792 void efficiency(BinnedEstimatePtr<AxisT...> e1,
1793 BinnedEstimatePtr<AxisT...> e2,
1794 BinnedEstimatePtr<AxisT...> est) const {
1795 efficiency(*e1, *e2, est);
1796 }
1797
1798
1802 template <size_t DbnN, typename... AxisT>
1803 void asymm(const YODA::BinnedDbn<DbnN, AxisT...>& h1,
1804 const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1805 BinnedEstimatePtr<AxisT...> est) const {
1806 const string path = est->path();
1807 *est = YODA::asymm(h1, h2);
1808 est->setPath(path);
1809 }
1810 //
1811 template <size_t DbnN, typename... AxisT>
1812 void asymm(BinnedDbnPtr<DbnN, AxisT...> h1,
1813 BinnedDbnPtr<DbnN, AxisT...> h2,
1814 BinnedEstimatePtr<AxisT...> est) const {
1815 asymm(*h1, *h2, est);
1816 }
1817
1821 template <typename... AxisT>
1822 void asymm(const YODA::BinnedEstimate<AxisT...>& e1,
1823 const YODA::BinnedEstimate<AxisT...>& e2,
1824 BinnedEstimatePtr<AxisT...> est) const {
1825 const string path = est->path();
1826 *est = YODA::asymm(e1, e2);
1827 est->setPath(path);
1828 }
1829 //
1830 template <typename... AxisT>
1831 void asymm(BinnedEstimatePtr<AxisT...> e1,
1832 BinnedEstimatePtr<AxisT...> e2,
1833 BinnedEstimatePtr<AxisT...> est) const {
1834 asymm(*e1, *e2, est);
1835 }
1836
1840 template <size_t DbnN, typename... AxisT>
1841 void integrate(const YODA::BinnedDbn<DbnN, AxisT...>& h, BinnedEstimatePtr<AxisT...> est) const {
1842 const string path = est->path();
1843 *est = mkIntegral(h);
1844 est->setPath(path);
1845 }
1846 //
1847 template <size_t DbnN, typename... AxisT>
1848 void integrate(BinnedDbnPtr<DbnN, AxisT...>& h, BinnedEstimatePtr<AxisT...> est) const {
1849 integrate(*h, est);
1850 }
1851
1853
1854
1855 public:
1856
1858 const vector<MultiplexAOPtr>& analysisObjects() const {
1859 return _analysisobjects;
1860 }
1861
1862
1863 protected:
1864
1867
1869 size_t defaultWeightIndex() const;
1870
1872 template <typename YODAT>
1873 shared_ptr<YODAT> getPreload(const string& path) const {
1874 return dynamic_pointer_cast<YODAT>(_getPreload(path));
1875 }
1876
1877
1879 template <typename YODAT>
1881 using MultiplexerT = Multiplexer<YODAT>;
1882 using YODAPtrT = shared_ptr<YODAT>;
1883 using RAOT = MultiplexPtr<MultiplexerT>;
1884
1885 if (!_inInit() && !_inFinalize()) {
1886 MSG_ERROR("Can't book objects outside of init() or finalize()");
1887 throw UserError(name() + ": Can't book objects outside of init() or finalize().");
1888 }
1889
1890 // First check that we haven't booked this before.
1891 // This is allowed when booking in finalize: just warn in that case.
1892 // If in init(), throw an exception: it's 99.9% never going to be intentional.
1893 for (auto& waold : analysisObjects()) {
1894 if (yao.path() == waold.get()->basePath()) {
1895 const string msg = "Found double-booking of " + yao.path() + " in " + name();
1896 if (_inInit()) {
1897 MSG_ERROR(msg);
1898 throw LookupError(msg);
1899 }
1900 else {
1901 MSG_WARNING(msg + ". Keeping previous booking");
1902 }
1903 return RAOT(dynamic_pointer_cast<MultiplexerT>(waold.get()));
1904 }
1905 }
1906
1907 shared_ptr<MultiplexerT> wao = make_shared<MultiplexerT>();
1908 wao->_basePath = yao.path();
1909 YODAPtrT yaop = make_shared<YODAT>(yao);
1910
1911 for (const string& weightname : _weightNames()) {
1912 // Create two YODA objects for each weight. Copy from
1913 // preloaded YODAs if present. First the finalized yoda:
1914 string finalpath = yao.path();
1915 if (weightname != "") finalpath += "[" + weightname + "]";
1916 YODAPtrT preload = getPreload<YODAT>(finalpath);
1917 if (preload) {
1918 if (!bookingCompatible(preload, yaop)) {
1920 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1921 << finalpath << " for " << name());
1922 preload = nullptr;
1923 }
1924 else {
1925 MSG_TRACE("Using preloaded " << finalpath << " in " << name());
1926 wao->_final.push_back(make_shared<YODAT>(*preload));
1927 }
1928 }
1929 else {
1930 wao->_final.push_back(make_shared<YODAT>(yao));
1931 wao->_final.back()->setPath(finalpath);
1932 }
1933
1934 // Then the raw filling yodas.
1935 string rawpath = "/RAW" + finalpath;
1936 preload = getPreload<YODAT>(rawpath);
1937 if (preload) {
1938 if (!bookingCompatible(preload, yaop)) {
1939 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1940 << rawpath << " for " << name());
1941 preload = nullptr;
1942 }
1943 else {
1944 MSG_TRACE("Using preloaded " << rawpath << " in " << name());
1945 wao->_persistent.push_back(make_shared<YODAT>(*preload));
1946 }
1947 }
1948 else {
1949 wao->_persistent.push_back(make_shared<YODAT>(yao));
1950 wao->_persistent.back()->setPath(rawpath);
1951 }
1952 }
1954
1955 ret.get()->unsetActiveWeight();
1956 if (_inFinalize()) {
1957 // If booked in finalize() we assume it is the first time
1958 // finalize is run.
1959 ret.get()->pushToFinal();
1960 ret.get()->setActiveFinalWeightIdx(0);
1961 }
1962 _analysisobjects.push_back(ret);
1963
1964 return ret;
1965 }
1966
1967
1969 template <typename AO = MultiplexAOPtr>
1970 AO addAnalysisObject(const AO& aonew) {
1971 _checkBookInit();
1972
1973 for (const MultiplexAOPtr& ao : analysisObjects()) {
1974
1975 // Check AO base-name first
1976 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1977 aonew.get()->setActiveWeightIdx(defaultWeightIndex());
1978 if (ao->path() != aonew->path()) continue;
1979
1980 // If base-name matches, check compatibility
1981 // NB. This evil is because dynamic_ptr_cast can't work on MultiplexPtr directly
1982 AO aoold = AO(dynamic_pointer_cast<typename AO::value_type>(ao.get())); //< OMG
1983 if (!aoold || !bookingCompatible(aonew, aoold)) {
1984 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1985 << aonew->path() << " for " << name());
1986 throw LookupError(
1987 "Found incompatible pre-existing data object with same base path during AO booking");
1988 }
1989
1990 // Finally, check all weight variations
1991 for (size_t weightIdx = 0; weightIdx < _weightNames().size(); ++weightIdx) {
1992 aoold.get()->setActiveWeightIdx(weightIdx);
1993 aonew.get()->setActiveWeightIdx(weightIdx);
1994 if (aoold->path() != aonew->path()) {
1995 MSG_WARNING("Found incompatible pre-existing data object with different weight-path "
1996 << aonew->path() << " for " << name());
1997 throw LookupError(
1998 "Found incompatible pre-existing data object with same weight-path during AO booking");
1999 }
2000 }
2001
2002 // They're fully compatible: bind and return
2003 aoold.get()->unsetActiveWeight();
2004 MSG_TRACE("Bound pre-existing data object " << aoold->path() << " for " << name());
2005 return aoold;
2006 }
2007
2008 // No equivalent found
2009 MSG_TRACE("Registered " << aonew->annotation("Type") << " " << aonew->path() << " for " << name());
2010 aonew.get()->unsetActiveWeight();
2011
2012 _analysisobjects.push_back(aonew);
2013 return aonew;
2014 }
2015
2017 void removeAnalysisObject(const std::string& path);
2018
2020 void removeAnalysisObject(const MultiplexAOPtr& ao);
2021
2023 template <typename AO = MultiplexAOPtr>
2024 const AO getAnalysisObject(const std::string& aoname) const {
2025 for (const MultiplexAOPtr& ao : analysisObjects()) {
2026 ao.get()->setActiveWeightIdx(defaultWeightIndex());
2027 if (ao->path() == histoPath(aoname)) {
2028 // return dynamic_pointer_cast<AO>(ao);
2029 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
2030 }
2031 }
2032 throw LookupError("Data object " + histoPath(aoname) + " not found");
2033 }
2034
2035
2036 // /// Get a data object from the histogram system
2037 // template <typename AO=YODA::AnalysisObject>
2038 // const std::shared_ptr<AO> getAnalysisObject(const std::string& name) const {
2039 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
2040 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
2041 // }
2042 // throw LookupError("Data object " + histoPath(name) + " not found");
2043 // }
2044
2045 // /// Get a data object from the histogram system (non-const)
2046 // template <typename AO=YODA::AnalysisObject>
2047 // std::shared_ptr<AO> getAnalysisObject(const std::string& name) {
2048 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
2049 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
2050 // }
2051 // throw LookupError("Data object " + histoPath(name) + " not found");
2052 // }
2053
2054
2057 template <typename AO = MultiplexAOPtr>
2058 AO getAnalysisObject(const std::string& ananame, const std::string& aoname) {
2059 MultiplexAOPtr ao = _getOtherAnalysisObject(ananame, aoname);
2060 // return dynamic_pointer_cast<AO>(ao);
2061 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
2062 }
2063
2065
2068
2070 template <typename... Args,
2071 typename CONTAINER,
2072 typename = std::enable_if_t<is_citerable_v<CONTAINER>, Jet>>
2073 static CONTAINER reclusterJets(const CONTAINER& jetsIn, Args&&... args) {
2074 return FastJets::reclusterJets(jetsIn, std::forward<Args>(args)...);
2075 }
2076
2077 template <typename T, typename U, typename... Args>
2078 static std::map<T, U> reclusterJets(const std::map<T, U>& jetsMap, Args&&... args) {
2079 return FastJets::reclusterJets(jetsMap, std::forward<Args>(args)...);
2080 }
2081
2082 template <JetAlg JETALG,
2083 typename... Args,
2084 typename CONTAINER,
2085 typename = std::enable_if_t<is_citerable_v<CONTAINER>, Jet>>
2086 static CONTAINER reclusterJets(const CONTAINER& jetsIn, Args&&... args) {
2087 return FastJets::reclusterJets<JETALG>(jetsIn, std::forward<Args>(args)...);
2088 }
2089
2090 template <JetAlg JETALG, typename T, typename U, typename... Args>
2091 static std::map<T, U> reclusterJets(const std::map<T, U>& jetsMap, Args&&... args) {
2092 return FastJets::reclusterJets<JETALG>(jetsMap, std::forward<Args>(args)...);
2093 }
2094
2096
2097
2098 private:
2099
2101 string _defaultname;
2102
2104 unique_ptr<AnalysisInfo> _info;
2105
2108 vector<MultiplexAOPtr> _analysisobjects;
2109
2112 double _crossSection;
2113 bool _gotCrossSection;
2115
2117 AnalysisHandler* _analysishandler;
2118
2120 const Event* _currentevent = nullptr;
2121
2124 mutable std::map<std::string, YODA::AnalysisObjectPtr> _refdata;
2125
2127 map<string, string> _options;
2128
2130 string _optstring;
2131
2132
2133 private:
2134
2137
2139 void _cacheRefData() const;
2140
2142 };
2143
2144
2145 // // Template specialisation for literal character strings (which don't play well with stringstream)
2146 // template<>
2147 // inline std::string Analysis::getOption(std::string optname, const char* def) {
2148 // return getOption<std::string>(optname, def); //.c_str();
2149 // }
2150
2151
2152}
2153
2154
2155// Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
2156#include "Rivet/AnalysisBuilder.hh"
2157
2158
2161
2164#define RIVET_DECLARE_PLUGIN(clsname) ::Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
2165
2168#define RIVET_DECLARE_ALIASED_PLUGIN(clsname, alias) RIVET_DECLARE_PLUGIN(clsname)( #alias )
2169
2172#define RIVET_DEFAULT_ANALYSIS_CTOR(clsname) clsname() : Analysis(# clsname) {}
2173
2176#define RIVET_REGISTER_TYPE(...) handler().registerType<__VA_ARGS__>()
2177
2180#define RIVET_REGISTER_BINNED_SET(...) { \
2181 RIVET_REGISTER_TYPE(YODA::BinnedHisto<__VA_ARGS__>); \
2182 RIVET_REGISTER_TYPE(YODA::BinnedProfile<__VA_ARGS__>); \
2183 RIVET_REGISTER_TYPE(YODA::BinnedEstimate<__VA_ARGS__>); }
2184
2186
2187
2188#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:377
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:1145
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:750
virtual std::string status() const
Whether this analysis is trusted (in any way!).
Definition Analysis.hh:268
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:80
virtual bool reentrant() const
Does this analysis have a reentrant finalize()?
Definition Analysis.hh:288
shared_ptr< YODAT > getPreload(const string &path) const
Get a preloaded YODA object.
Definition Analysis.hh:1873
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:173
void scale(std::initializer_list< T > aos, CounterAdapter factor)
Iteratively scale the AOs in the initialiser list aos, by factor factor.
Definition Analysis.hh:1496
virtual std::string collider() const
Collider on which the experiment ran.
Definition Analysis.hh:230
MultiplexPtr< Multiplexer< YODAT > > registerAO(const YODAT &yao)
Register a new data object, optionally read in preloaded data.
Definition Analysis.hh:1880
virtual double luminosityfb() const
The integrated luminosity in inverse femtobarn.
Definition Analysis.hh:240
void loadInfo()
Get the AnalysisInfo object to parse its info file in which the metadata is stored.
Definition Analysis.hh:148
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:1230
const AnalysisInfo & info() const
Get the actual AnalysisInfo object in which all this metadata is stored.
Definition Analysis.hh:153
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:1602
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:1616
void efficiency(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const
Definition Analysis.hh:1745
virtual const std::vector< std::string > & keywords() const
Get vector of analysis keywords.
Definition Analysis.hh:293
virtual double luminosity() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:244
virtual std::string spiresID() const
Get the SPIRES ID code for this analysis (~deprecated).
Definition Analysis.hh:184
virtual std::string writerDoublePrecision() const
Positive filtering regex for setting double precision in Writer.
Definition Analysis.hh:308
virtual void preInit()
A method called before init(), for cleaner subclassing.
Definition Analysis.hh:116
void efficiency(const YODA::Counter &c1, const YODA::Counter &c2, Estimate0DPtr est) const
Definition Analysis.hh:1752
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:735
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:925
virtual Analysis & setRequiredBeamIDs(const std::vector< PdgIdPair > &beamids)
Declare the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:317
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:861
AO getAnalysisObject(const std::string &ananame, const std::string &aoname)
Definition Analysis.hh:2058
void barchart(BinnedDbnPtr< DbnN, AxisT... > ao, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1676
AnalysisInfo & info()
Get the actual AnalysisInfo object in which all this metadata is stored (non-const).
Definition Analysis.hh:350
virtual std::string runInfo() const
Information about the events needed as input for this analysis.
Definition Analysis.hh:220
void syncDeclQueue()
Definition Analysis.hh:131
void scale(AORange &aos, CounterAdapter factor)
Iteratively scale the AOs in the iterable aos, by factor factor.
Definition Analysis.hh:1490
virtual std::string year() const
When the original experimental analysis was published.
Definition Analysis.hh:235
virtual void preAnalyze(const Event &)
A method called before analyze(), for cleaner subclassing.
Definition Analysis.hh:120
T getOption(std::string optname, T def) const
Get an option for this analysis instance converted to a specific type.
Definition Analysis.hh:1157
virtual void setRefDataName(const std::string &ref_data="")
Set name of reference data file, which could be different from plugin name.
Definition Analysis.hh:342
double effNumEvents() const
Get the effective number of events seen (via the analysis handler).
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:1858
double crossSectionPerEvent() const
virtual std::string summary() const
Get a short description of the analysis.
Definition Analysis.hh:201
void scale(AORange &aos, const vector< double > &factors)
Iteratively scale the AOs in the iterable aos, by factors factors.
Definition Analysis.hh:1508
virtual std::string description() const
Get a full description of the analysis.
Definition Analysis.hh:211
double crossSectionErrorPerEvent() const
void removeAnalysisObject(const MultiplexAOPtr &ao)
Unregister a data object from the histogram system (by pointer).
void scale(std::map< T, U > &aos, const vector< double > &factors)
Iteratively scale the AOs in the map aos, by factors factors.
Definition Analysis.hh:1502
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:1136
virtual std::vector< std::string > validation() const
make-style commands for validating this analysis.
Definition Analysis.hh:283
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:1656
virtual std::vector< std::string > authors() const
Names & emails of paper/analysis authors.
Definition Analysis.hh:192
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, const vector< double > &factors)
Multiplicatively scale the given histogram group, group, by factors factors.
Definition Analysis.hh:1433
void asymm(const YODA::BinnedEstimate< AxisT... > &e1, const YODA::BinnedEstimate< AxisT... > &e2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1822
virtual void postAnalyze(const Event &)
A method called after analyze(), for cleaner subclassing.
Definition Analysis.hh:122
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:327
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:1650
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:1536
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:873
virtual std::string refFile() const
Location of reference data YODA file.
Definition Analysis.hh:334
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:1624
virtual void finalize()
Definition Analysis.hh:107
void efficiency(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1763
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:715
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:965
virtual std::vector< std::string > references() const
Journal, and preprint references.
Definition Analysis.hh:253
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:278
virtual std::string inspireID() const
Get the Inspire ID code for this analysis.
Definition Analysis.hh:179
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, CounterAdapter factor)
Multiplicatively scale the given histogram group, group, by factor factor.
Definition Analysis.hh:1410
bool merging() const
Check if we are running rivet-merge.
Definition Analysis.hh:362
void divByGroupWidth(std::initializer_list< T > aos)
Iteratively scale the HistoGroups in the initialiser list aos, by the group axis width.
Definition Analysis.hh:1542
void divide(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1707
vector< double > allowedEnergies() const
Allowed centre-of-mass energies (in GeV) for this routine.
const Event & currentEvent() const
Access the current event.
Definition Analysis.hh:433
virtual const std::vector< PdgIdPair > & requiredBeamIDs() const
Return the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:313
virtual std::string refUnmatch() const
Negative filtering regex for ref-data HepData sync.
Definition Analysis.hh:303
const std::map< std::string, std::string > & options() const
Return the map of all options given to this analysis.
Definition Analysis.hh:1131
virtual void postInit()
A method called after init(), for cleaner subclassing.
Definition Analysis.hh:118
double sqrtS() const
Centre of mass energy for this run.
void raiseBeamErrorIf(const bool condition) const
Raise BeamError if condition not met and not in merging mode.
bool getOption(std::string optname, bool def) const
Get an option for this analysis instance converted to a bool.
Definition Analysis.hh:1184
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:1381
void scale(CutflowsPtr &group, CounterAdapter factor)
Multiplicatively scale the cutflow group, group, by factor factor.
Definition Analysis.hh:1461
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:951
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:298
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:1664
double luminositypb() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:248
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:1726
void integrate(const YODA::BinnedDbn< DbnN, AxisT... > &h, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1841
const T & refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Definition Analysis.hh:581
virtual std::string warning() const
A warning message from the info file, if there is one.
Definition Analysis.hh:273
AnalysisHandler & handler() const
Access the controlling AnalysisHandler object.
Definition Analysis.hh:428
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:1520
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:1608
bool hasRefData(const string &hname) const
Check if reference data object exists for a specific histo name.
Definition Analysis.hh:545
double sumOfWeights() const
Alias.
Definition Analysis.hh:475
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:805
const AO getAnalysisObject(const std::string &aoname) const
Get a Rivet data object from the histogram system.
Definition Analysis.hh:2024
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:1050
virtual void postFinalize()
A method called after finalize(), for cleaner subclassing.
Definition Analysis.hh:126
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:1013
friend class AnalysisHandler
The AnalysisHandler is a friend.
Definition Analysis.hh:73
const std::map< std::string, YODA::AnalysisObjectPtr > & refData() const
Get all reference data objects for this analysis.
Definition Analysis.hh:539
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:1783
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:758
void asymm(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1803
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:900
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:258
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:263
bool compatibleWithRun() const
Check if the given conditions are compatible with this analysis' declared constraints.
virtual void init()
Definition Analysis.hh:94
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:727
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:560
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:625
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:338
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:881
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:1549
virtual std::string name() const
Get the name of the analysis.
Definition Analysis.hh:165
double crossSectionError() const
Get the process cross-section error in pb. Throws if this hasn't been set.
void scale(std::initializer_list< T > aos, const vector< double > &factors)
Iteratively scale the AOs in the initialiser list aos, by factors factors.
Definition Analysis.hh:1514
void divByGroupWidth(std::map< T, U > &aos)
Iteratively scale the HistoGroups in the map aos, by the group axis width.
Definition Analysis.hh:1530
virtual void preFinalize()
A method called before finalize(), for cleaner subclassing.
Definition Analysis.hh:124
virtual std::string experiment() const
Experiment which performed and published this analysis.
Definition Analysis.hh:225
void scale(std::map< T, U > &aos, CounterAdapter factor)
Iteratively scale the AOs in the map aos, by factor factor.
Definition Analysis.hh:1484
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:1575
virtual const std::vector< std::pair< double, double > > & requiredBeamEnergies() const
Sets of valid beam energy pairs, in GeV.
Definition Analysis.hh:323
AO addAnalysisObject(const AO &aonew)
Register a data object in the histogram system.
Definition Analysis.hh:1970
bool hasRefData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Check if a reference data object exists for a numbered histo.
Definition Analysis.hh:551
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:26
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
Definition HistoGroup.hh:25
Representation of a clustered jet of particles.
Definition Jet.hh:47
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
Definition RivetYODA.hh:1376
shared_ptr< T > get() const
Get the internal shared ptr.
Definition RivetYODA.hh:1476
Type-specific multiplexed YODA analysis object.
Definition RivetYODA.hh:1038
void add(TPtr ao, CounterPtr cnt, pair< float, float > cent={0.0, 100.0})
Add a new percentile bin.
Definition Percentile.hh:118
The Percentile class for centrality binning.
Definition Percentile.hh:194
void markAsOwned() const
Mark this object as owned by a proj-handler.
Definition ProjectionApplier.hh:158
ProjectionApplier()
Constructor.
Base class for projections returning a single floating point value.
Definition SingleValueProjection.hh:17
STL class.
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:1076
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:1068
static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args &&... args)
Avoid FastJet:: scoping prefix.
Definition Analysis.hh:2073
const std::string & refUnmatch() const
Negative filtering regex for ref-data HepData sync.
Definition AnalysisInfo.hh:232
void setBeamIDs(const std::vector< PdgIdPair > &beamids)
Set beam particle types.
Definition AnalysisInfo.hh:141
const std::string & description() const
Get a full description of the analysis.
Definition AnalysisInfo.hh:114
const std::string & warning() const
Any warning message.
Definition AnalysisInfo.hh:216
const std::string & bibKey() const
BibTeX citation key for this article.
Definition AnalysisInfo.hh:248
void setRefDataName(const std::string &name)
Set the reference data name of the analysis (if different from plugin name).
Definition AnalysisInfo.hh:59
const std::vector< std::string > & todos() const
Any work to be done on this analysis.
Definition AnalysisInfo.hh:266
const std::string & collider() const
Collider on which the experiment ran.
Definition AnalysisInfo.hh:164
const std::string & inspireID() const
Get the Inspire (SPIRES replacement) ID code for this analysis.
Definition AnalysisInfo.hh:64
const std::string & bibTeX() const
BibTeX citation entry for this article.
Definition AnalysisInfo.hh:257
const std::vector< PdgIdPair > & beamIDs() const
Beam particle types.
Definition AnalysisInfo.hh:136
const std::vector< std::string > & references() const
Journal and preprint references.
Definition AnalysisInfo.hh:199
const std::string & summary() const
Get a short description of the analysis.
Definition AnalysisInfo.hh:100
const std::vector< std::pair< double, double > > & energies() const
Sets of valid beam energies.
Definition AnalysisInfo.hh:146
const std::string & refMatch() const
Positive filtering regex for ref-data HepData sync.
Definition AnalysisInfo.hh:224
void setEnergies(const std::vector< std::pair< double, double > > &energies)
Set the valid beam energies.
Definition AnalysisInfo.hh:150
const std::string & spiresID() const
Get the SPIRES ID code for this analysis.
Definition AnalysisInfo.hh:74
double luminosity() const
The integrated data luminosity of the data set in 1/pb.
Definition AnalysisInfo.hh:189
const std::vector< std::string > & keywords() const
Analysis keywords, for grouping etc.
Definition AnalysisInfo.hh:208
const std::string & runInfo() const
Information about the events needed as input for this analysis.
Definition AnalysisInfo.hh:127
const std::vector< std::string > & authors() const
Names & emails of paper/analysis authors.
Definition AnalysisInfo.hh:87
std::string getRefDataName() const
Get the reference data name of the analysis (if different from plugin name).
Definition AnalysisInfo.hh:54
const std::string & year() const
When the original experimental analysis was published.
Definition AnalysisInfo.hh:175
const std::string & writerDoublePrecision() const
Positive filtering regex for setting double precision in Writer.
Definition AnalysisInfo.hh:240
double luminosityfb() const
The integrated data luminosity of the data set in 1/fb.
Definition AnalysisInfo.hh:185
const std::string & experiment() const
Experiment which performed and published this analysis.
Definition AnalysisInfo.hh:155
const std::string & status() const
Whether this analysis is trusted (in any way!).
Definition AnalysisInfo.hh:304
bool reentrant() const
Return true if finalize() can be run multiple times for this analysis.
Definition AnalysisInfo.hh:313
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:1600
static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::JetDefinition &jDef)
Recluster Rivet::Jets.
Definition FastJets.hh:278
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:193
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
#define MSG_WARNING(x)
Warning messages for non-fatal bad things, using MSG_LVL.
Definition Logging.hh:200
#define MSG_ERROR(x)
Highest level messaging for serious problems, using MSG_LVL.
Definition Logging.hh:202
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
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:163
Definition LHCbCommon.hh:9
std::shared_ptr< Cutflows > CutflowsPtr
Convenience alias.
Definition Cutflow.hh:531
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:43
Error Exception
Rivet::Exception is a synonym for Rivet::Error.
Definition Exceptions.hh:19
MultiplexPtr< Multiplexer< Cutflow > > CutflowPtr
Convenience alias.
Definition Cutflow.hh:278
Generic runtime Rivet error.
Definition Exceptions.hh:12
Error relating to looking up analysis objects in the register.
Definition Exceptions.hh:82
Error for e.g. use of invalid bin ranges.
Definition Exceptions.hh:23
Error for read failures.
Definition Exceptions.hh:102
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:75