rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.2
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#ifdef HAVE_H5
16#include "Rivet/Tools/RivetHDF5.hh"
17#endif
18#include "Rivet/Tools/HistoGroup.hh"
19#include "Rivet/Tools/RivetMT2.hh"
20#include "Rivet/Tools/RivetPaths.hh"
21#include "Rivet/Tools/RivetYODA.hh"
22#include "Rivet/Tools/Percentile.hh"
23#include "Rivet/Tools/Cutflow.hh"
24#include "Rivet/Projections/CentralityProjection.hh"
25#include <tuple>
26
27
30#define vetoEvent \
31 do { MSG_DEBUG("Vetoing event on line " << __LINE__ << " of " << __FILE__); return; } while(0)
32
33
34namespace Rivet {
35
36
37 // Convenience for analysis writers
38 using std::cout;
39 using std::cerr;
40 using std::endl;
41 using std::tuple;
42 using std::stringstream;
43 using std::swap;
44 using std::numeric_limits;
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
113 this->_syncDeclQueue();
114 this->markAsOwned();
115 }
116
118
119
120 public:
121
127
129 void loadInfo() { info().parseInfoFile(); }
130
132 const AnalysisInfo& info() const {
133 if (!_info) throw Error("No AnalysisInfo object :-O");
134 return *_info;
135 }
136
144 virtual std::string name() const {
145 return ( (info().name().empty()) ? _defaultname : info().name() ) + _optstring;
146 }
147
152 std::string analysisDataPath(const std::string& extn, const std::string& suffix="") {
153 string filename = name() + (suffix.empty() ? "" : "-") + suffix + "." + extn;
154 return findAnalysisDataFile(filename);
155 }
156
158 virtual std::string inspireID() const {
159 return info().inspireID();
160 }
161
163 virtual std::string spiresID() const {
164 return info().spiresID();
165 }
166
171 virtual std::vector<std::string> authors() const {
172 return info().authors();
173 }
174
180 virtual std::string summary() const {
181 return info().summary();
182 }
183
190 virtual std::string description() const {
191 return info().description();
192 }
193
199 virtual std::string runInfo() const {
200 return info().runInfo();
201 }
202
204 virtual std::string experiment() const {
205 return info().experiment();
206 }
207
209 virtual std::string collider() const {
210 return info().collider();
211 }
212
214 virtual std::string year() const {
215 return info().year();
216 }
217
219 virtual double luminosityfb() const {
220 return info().luminosityfb();
221 }
223 virtual double luminosity() const {
224 return info().luminosity();
225 }
227 double luminositypb() const { return luminosity(); }
228
230 virtual std::vector<std::string> references() const {
231 return info().references();
232 }
233
235 virtual std::string bibKey() const {
236 return info().bibKey();
237 }
238
240 virtual std::string bibTeX() const {
241 return info().bibTeX();
242 }
243
245 virtual std::string status() const {
246 return (info().status().empty()) ? "UNVALIDATED" : info().status();
247 }
248
250 virtual std::string warning() const {
251 return info().warning();
252 }
253
255 virtual std::vector<std::string> todos() const {
256 return info().todos();
257 }
258
260 virtual std::vector<std::string> validation() const {
261 return info().validation();
262 }
263
265 virtual bool reentrant() const {
266 return info().reentrant();
267 }
268
270 virtual const std::vector<std::string>& keywords() const {
271 return info().keywords();
272 }
273
275 virtual std::string refMatch() const {
276 return info().refMatch();
277 }
278
280 virtual std::string refUnmatch() const {
281 return info().refUnmatch();
282 }
283
285 virtual std::string writerDoublePrecision() const {
286 return info().writerDoublePrecision();
287 }
288
290 virtual const std::vector<PdgIdPair>& requiredBeamIDs() const {
291 return info().beamIDs();
292 }
294 virtual Analysis& setRequiredBeamIDs(const std::vector<PdgIdPair>& beamids) {
295 info().setBeamIDs(beamids);
296 return *this;
297 }
298
300 virtual const std::vector<std::pair<double, double> >& requiredBeamEnergies() const {
301 return info().energies();
302 }
304 virtual Analysis& setRequiredBeamEnergies(const std::vector<std::pair<double, double> >& energies) {
305 info().setEnergies(energies);
306 return *this;
307 }
308
309
311 virtual std::string refFile() const {
312 return info().refFile();
313 }
315 virtual std::string refDataName() const {
316 return (info().getRefDataName().empty()) ? _defaultname : info().getRefDataName();
317 }
319 virtual void setRefDataName(const std::string& ref_data="") {
320 info().setRefDataName(!ref_data.empty() ? ref_data : name());
321 }
322
323
328 if (!_info) throw Error("No AnalysisInfo object :-O");
329 return *_info;
330 }
331
333
334
337
339 bool merging() const {
340 return sqrtS() <= 0.0;
341 }
342
344 bool compatibleWithRun() const;
345
347
348
352
354 const ParticlePair& beams() const;
355
357 PdgIdPair beamIDs() const;
358
360 pair<double,double> beamEnergies() const;
361
363 vector<double> allowedEnergies() const;
364
366 double sqrtS() const;
367
369 bool beamsMatch(const ParticlePair& beams) const;
370
372 bool beamsMatch(PdgId beam1, PdgId beam2, double e1, double e2) const;
373
375 bool beamsMatch(const PdgIdPair& beams, const std::pair<double,double>& energies) const;
376
378 bool beamIDsMatch(PdgId beam1, PdgId beam2) const;
379
381 bool beamIDsMatch(const PdgIdPair& beamids) const;
382
384 bool beamEnergiesMatch(double e1, double e2) const;
385
387 bool beamEnergiesMatch(const std::pair<double,double>& energies) const;
388
390 bool beamEnergyMatch(const std::pair<double,double>& energies) const;
391
393 bool beamEnergyMatch(double sqrts) const;
394
396 bool isCompatibleWithSqrtS(double energy, double tolerance=1e-5) const;
397
399
400
402 AnalysisHandler& handler() const { return *_analysishandler; }
403
404
405 protected:
406
408 Log& getLog() const;
409
411 double crossSection() const;
412
415 double crossSectionPerEvent() const;
416
418 double crossSectionError() const;
419
423
427 size_t numEvents() const;
428
432 double sumW() const;
434 double sumOfWeights() const { return sumW(); }
435
439 double sumW2() const;
440
441
442 protected:
443
449
451 const std::string histoDir() const;
452
454 const std::string histoPath(const std::string& hname) const;
455
457 const std::string histoPath(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
458
460 const std::string mkAxisCode(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
461
463
464
465 #ifdef HAVE_H5
468
470 H5::File auxFile() const {
471 return H5::readFile(name()+".h5");
472 }
473
475 template <typename T>
476 bool auxData(const string& dsname, T& rtndata) {
478 return H5::readData(name()+".h5", dsname, rtndata);
479 }
480
481 template <typename T>
482 T auxData(const string& dsname) {
484 return H5::readData<T>(name()+".h5", dsname);
485 }
486
488 #endif
489
490
493
495 const std::map<std::string, YODA::AnalysisObjectPtr>& refData() const {
496 _cacheRefData();
497 return _refdata;
498 }
499
500
503 template <typename T=YODA::Estimate1D>
504 const T& refData(const string& hname) const {
505 _cacheRefData();
506 MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
507 if (!_refdata[hname]) {
508 MSG_ERROR("Can't find reference histogram " << hname);
509 throw Exception("Reference data " + hname + " not found.");
510 }
511 return dynamic_cast<T&>(*_refdata[hname]);
512 }
513
514
517 template <typename T=YODA::Estimate1D>
518 const T& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
519 const string hname = mkAxisCode(datasetId, xAxisId, yAxisId);
520 return refData<T>(hname);
521 }
522
524
525
531
533 CounterPtr& book(CounterPtr&, const std::string& name);
534
538 CounterPtr& book(CounterPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
539
541
542
545
547 Estimate0DPtr& book(Estimate0DPtr&, const std::string& name);
548
552 Estimate0DPtr& book(Estimate0DPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
553
554
556
559
561 template<size_t DbnN, typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
563 const std::string& name, const std::vector<size_t>& nbins,
564 const std::vector<std::pair<double,double>>& loUpPairs) {
565 if (nbins.size() != loUpPairs.size()) {
566 throw RangeError("Vectors should have the same size!");
567 }
568 const string path = histoPath(name);
569
570 YODA::BinnedDbn<DbnN, AxisT...> yao(nbins, loUpPairs, path);
571 _setWriterPrecision(path, yao);
572
573 return ao = registerAO(yao);
574 }
575
576 // Specialiation for 1D
577 Histo1DPtr& book(Histo1DPtr& ao, const std::string& name,
578 const size_t nbins, const double lower, const double upper) {
579 return book(ao, name, vector<size_t>{nbins},
580 vector<pair<double,double>>{{lower,upper}});
581 }
582 //
583 Profile1DPtr& book(Profile1DPtr& ao, const std::string& name,
584 const size_t nbins, const double lower, const double upper) {
585 return book(ao, name, vector<size_t>{nbins},
586 vector<pair<double,double>>{{lower,upper}});
587 }
588
589 // Specialiation for 2D
590 Histo2DPtr& book(Histo2DPtr& 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 Profile2DPtr& book(Profile2DPtr& ao, const std::string& name,
598 const size_t nbinsX, const double lowerX, const double upperX,
599 const size_t nbinsY, const double lowerY, const double upperY) {
600 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
601 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
602 }
603
604 // Specialiation for 3D
605 Histo3DPtr& book(Histo3DPtr& ao, const std::string& name,
606 const size_t nbinsX, const double lowerX, const double upperX,
607 const size_t nbinsY, const double lowerY, const double upperY,
608 const size_t nbinsZ, const double lowerZ, const double upperZ) {
609 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
610 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
611 }
612 //
613 Profile3DPtr& book(Profile3DPtr& ao, const std::string& name,
614 const size_t nbinsX, const double lowerX, const double upperX,
615 const size_t nbinsY, const double lowerY, const double upperY,
616 const size_t nbinsZ, const double lowerZ, const double upperZ) {
617 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
618 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
619 }
620
622 template<size_t DbnN, typename... AxisT>
623 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
624 const std::vector<AxisT>&... binedges) {
625 const string path = histoPath(name);
626 YODA::BinnedDbn<DbnN, AxisT...> yao(binedges..., path);
627 _setWriterPrecision(path, yao);
628
629 return ao = registerAO(yao);
630 }
631
633 template<size_t DbnN, typename... AxisT>
634 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
635 const std::initializer_list<AxisT>&... binedges) {
636 return book(ao, name, vector<AxisT>{binedges} ...);
637 }
638
640 template<size_t DbnN, typename... AxisT>
641 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
642 const YODA::BinnedEstimate<AxisT...>& refest) {
643 const string path = histoPath(name);
644
645 YODA::BinnedDbn<DbnN, AxisT...> yao(refest.binning(), path);
646 for (const string& a : yao.annotations()) {
647 if (a != "Path") yao.rmAnnotation(a);
648 }
649 _setWriterPrecision(path, yao);
650 return ao = registerAO(yao);
651 }
652
654 template<size_t DbnN, typename... AxisT>
655 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name) {
656 return book(ao, name, refData<YODA::BinnedEstimate<AxisT...>>(name));
657 }
658
662 template<size_t DbnN, typename... AxisT>
663 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const unsigned int datasetID,
664 const unsigned int xAxisID, const unsigned int yAxisID) {
665 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
666 return book(ao, name);
667 }
668
670
673
674 template <typename GroupAxisT, typename... AxisT>
675 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
676 const std::vector<GroupAxisT>& edges,
677 const std::vector<std::string>& names) {
678 ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
679 if (ao->numBins() != names.size()) {
680 throw RangeError("Binning and reference-data names don't match!");
681 }
682 for (auto& b : ao->bins()) {
683 const string& refname = names[b.index()-1];
684 book(b, refname, refData<YODA::BinnedEstimate<AxisT...>>(refname));
685 }
686 return ao;
687 }
688
689 template <typename GroupAxisT, typename... AxisT>
690 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
691 const std::vector<GroupAxisT>& edges) {
692 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
693 }
694
695 template <typename GroupAxisT, typename... AxisT>
696 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
697 std::initializer_list<GroupAxisT>&& edges) {
698 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(std::move(edges));
699 }
700
702
705
707 template<typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
709 const std::string& name, const std::vector<size_t>& nbins,
710 const std::vector<std::pair<double,double>>& loUpPairs) {
711 if (nbins.size() != loUpPairs.size()) {
712 throw RangeError("Vectors should have the same size!");
713 }
714 const string path = histoPath(name);
715
716 YODA::BinnedEstimate<AxisT...> yao(nbins, loUpPairs, path);
717 _setWriterPrecision(path, yao);
718
719 return ao = registerAO(yao);
720 }
721
722
723 // Specialiation for 1D
724 Estimate1DPtr& book(Estimate1DPtr& ao, const std::string& name,
725 const size_t nbins, const double lower, const double upper) {
726 return book(ao, name, vector<size_t>{nbins},
727 vector<pair<double,double>>{{lower,upper}});
728 }
729
730 // Specialiation for 2D
731 Estimate2DPtr& book(Estimate2DPtr& ao, const std::string& name,
732 const size_t nbinsX, const double lowerX, const double upperX,
733 const size_t nbinsY, const double lowerY, const double upperY) {
734 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
735 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
736 }
737
738 // Specialiation for 3D
739 Estimate3DPtr& book(Estimate3DPtr& ao, const std::string& name,
740 const size_t nbinsX, const double lowerX, const double upperX,
741 const size_t nbinsY, const double lowerY, const double upperY,
742 const size_t nbinsZ, const double lowerZ, const double upperZ) {
743 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
744 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
745 }
746
748 template<typename... AxisT>
749 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
750 const std::vector<AxisT>&... binedges) {
751 const string path = histoPath(name);
752 YODA::BinnedEstimate<AxisT...> yao(binedges..., path);
753 _setWriterPrecision(path, yao);
754
755 return ao = registerAO(yao);
756 }
757
759 template<typename... AxisT>
760 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
761 const std::initializer_list<AxisT>&... binedges) {
762 return book(ao, name, vector<AxisT>{binedges} ...);
763 }
764
766 template<typename... AxisT>
767 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name) {
768
769 const string path = histoPath(name);
770 YODA::BinnedEstimate<AxisT...> yao;
771 try {
772 yao = YODA::BinnedEstimate<AxisT...>(refData<YODA::BinnedEstimate<AxisT...>>(name).binning());
773 } catch (...) {
774 MSG_DEBUG("Couldn't retrieve reference binning, continue with nullary AO constructor.");
775 }
776 yao.setPath(path);
777 _setWriterPrecision(path, yao);
778 return ao = registerAO(yao);
779 }
780
784 template<typename... AxisT>
785 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const unsigned int datasetID,
786 const unsigned int xAxisID, const unsigned int yAxisID) {
787 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
788 return book(ao, name);
789 }
790
792
793
796
807 template<size_t N>
808 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const bool copy_pts = false) {
809 const string path = histoPath(name);
810 YODA::ScatterND<N> scat(path);
811 if (copy_pts) {
812 const YODA::ScatterND<N> ref = refData<YODA::EstimateND<N-1>>(name).mkScatter();
813 for (YODA::PointND<N> p : ref.points()) {
814 p.setVal(N-1, 0.0);
815 p.setErr(N-1, 0.0);
816 scat.addPoint(std::move(p));
817 }
818 }
819 _setWriterPrecision(path, scat);
820 return snd = registerAO(scat);
821 }
822
833 template<size_t N>
834 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const unsigned int datasetID, const unsigned int xAxisID,
835 const unsigned int yAxisID, const bool copy_pts = false) {
836 const string axisCode = mkAxisCode(datasetID, xAxisID, yAxisID);
837 return book(snd, axisCode, copy_pts);
838 }
839
845 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
846 const size_t npts, const double lower, const double upper) {
847 const string path = histoPath(name);
848
849 Scatter2D scat(path);
850 const double binwidth = (upper-lower)/npts;
851 for (size_t pt = 0; pt < npts; ++pt) {
852 const double bincentre = lower + (pt + 0.5) * binwidth;
853 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
854 }
855 _setWriterPrecision(path, scat);
856
857 return snd = registerAO(scat);
858 }
859 //
860 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
861 const size_t nptsX, const double lowerX, const double upperX,
862 const size_t nptsY, const double lowerY, const double upperY) {
863 const string path = histoPath(name);
864
865 Scatter3D scat(path);
866 const double xbinwidth = (upperX-lowerX)/nptsX;
867 const double ybinwidth = (upperY-lowerY)/nptsY;
868 for (size_t xpt = 0; xpt < nptsX; ++xpt) {
869 const double xbincentre = lowerX + (xpt + 0.5) * xbinwidth;
870 for (size_t ypt = 0; ypt < nptsY; ++ypt) {
871 const double ybincentre = lowerY + (ypt + 0.5) * ybinwidth;
872 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
873 }
874 }
875 _setWriterPrecision(path, scat);
876
877 return snd = registerAO(scat);
878 }
879
885 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
886 const std::vector<double>& binedges) {
887 const string path = histoPath(name);
888
889 Scatter2D scat(path);
890 for (size_t pt = 0; pt < binedges.size()-1; ++pt) {
891 const double bincentre = (binedges[pt] + binedges[pt+1]) / 2.0;
892 const double binwidth = binedges[pt+1] - binedges[pt];
893 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
894 }
895 _setWriterPrecision(path, scat);
896
897 return snd = registerAO(scat);
898 }
899 //
900 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
901 const std::vector<double>& binedgesX,
902 const std::vector<double>& binedgesY) {
903 const string path = histoPath(name);
904
905 Scatter3D scat(path);
906 for (size_t xpt = 0; xpt < binedgesX.size()-1; ++xpt) {
907 const double xbincentre = (binedgesX[xpt] + binedgesX[xpt+1]) / 2.0;
908 const double xbinwidth = binedgesX[xpt+1] - binedgesX[xpt];
909 for (size_t ypt = 0; ypt < binedgesY.size()-1; ++ypt) {
910 const double ybincentre = (binedgesY[ypt] + binedgesY[ypt+1]) / 2.0;
911 const double ybinwidth = binedgesY[ypt+1] - binedgesY[ypt];
912 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
913 }
914 }
915 _setWriterPrecision(path, scat);
916
917 return snd = registerAO(scat);
918 }
919
921 template<size_t N>
922 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const YODA::ScatterND<N>& refscatter) {
923 const string path = histoPath(name);
924
925 YODA::ScatterND<N> scat(refscatter, path);
926 for (const string& a : scat.annotations()) {
927 if (a != "Path") scat.rmAnnotation(a);
928 }
929 _setWriterPrecision(path, scat);
930
931 return snd = registerAO(scat);
932 }
933
935
938
940 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::vector<std::string>& edges) {
941 const string path = histoPath(name);
942 Cutflow yao(edges, path);
943 _setWriterPrecision(path, yao);
944 return ao = registerAO(yao);
945 }
946
948 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::initializer_list<std::string>& edges) {
949 return book(ao, name, vector<std::string>{edges});
950 }
951
953
956
957 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges,
958 const std::vector<std::vector<std::string>>& innerEdges) {
959 ao = make_shared<Cutflows>(edges);
960 if (ao->numBins() !=innerEdges.size()) {
961 throw RangeError("Outer and Inner edges don't match");
962 }
963 for (auto& b : ao->bins()) {
964 book(b, b.xEdge(), innerEdges[b.index()-1]);
965 }
966 return ao;
967 }
968
969 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges) {
970 return ao = make_shared<Cutflows>(edges);
971 }
972
973 CutflowsPtr& book(CutflowsPtr& ao, std::initializer_list<std::string>&& edges) {
974 return ao = make_shared<Cutflows>(std::move(edges));
975 }
976
978
979
983 virtual void rawHookIn(YODA::AnalysisObjectPtr yao) {
984 (void) yao; // suppress unused variable warning
985 }
986
990 virtual void rawHookOut(const vector<MultiplexAOPtr>& raos, size_t iW) {
991 (void) raos; // suppress unused variable warning
992 (void) iW; // suppress unused variable warning
993 }
994
995
996 public:
997
1000
1002 const std::map<std::string,std::string>& options() const {
1003 return _options;
1004 }
1005
1007 std::string getOption(std::string optname, string def="") const {
1008 if ( _options.find(optname) != _options.end() )
1009 return _options.find(optname)->second;
1010 return def;
1011 }
1012
1017 std::string getOption(std::string optname, const char* def) {
1018 return getOption<std::string>(optname, def);
1019 }
1020
1028 template<typename T>
1029 T getOption(std::string optname, T def) const {
1030 if (_options.find(optname) == _options.end()) return def;
1031 std::stringstream ss;
1032 ss.exceptions(std::ios::failbit);
1033 T ret;
1034 ss << _options.find(optname)->second;
1035 try {
1036 ss >> ret;
1037 } catch (...) {
1038 throw ReadError("Could not read user-provided option into requested type");
1039 }
1040 return ret;
1041 }
1042
1053 // template<>
1054 // bool getOption<bool>(std::string optname, bool def) const {
1055 bool getOption(std::string optname, bool def) const {
1056 if (_options.find(optname) == _options.end()) return def;
1057 const std::string val = getOption(optname);
1058 const std::string lval = toLower(val);
1059 if (lval.empty()) return false;
1060 if (lval == "true" || lval == "yes" || lval == "on") return true;
1061 if (lval == "false" || lval == "no" || lval == "off") return false;
1062 return bool(getOption<int>(optname, 0));
1063 }
1064
1066
1067
1070
1089 string calAnaName, string calHistName,
1090 const string projName,
1091 PercentileOrder pctorder=PercentileOrder::DECREASING);
1092
1093
1100 template<typename T>
1101 Percentile<T> book(const string& projName,
1102 const vector<pair<double, double>>& centralityBins,
1103 const vector<tuple<size_t, size_t, size_t>>& ref) {
1104
1105 using RefT = typename ReferenceTraits<T>::RefT;
1106 using WrapT = MultiplexPtr<Multiplexer<T>>;
1107
1108 Percentile<T> pctl(this, projName);
1109
1110 const size_t nCent = centralityBins.size();
1111 for (size_t iCent = 0; iCent < nCent; ++iCent) {
1112 const string axisCode = mkAxisCode(std::get<0>(ref[iCent]),
1113 std::get<1>(ref[iCent]),
1114 std::get<2>(ref[iCent]));
1115 const RefT& refscatter = refData<RefT>(axisCode);
1116
1117 WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1118 wtf = addAnalysisObject(wtf);
1119
1120 CounterPtr cnt(_weightNames(), Counter(histoPath("TMP/COUNTER/" + axisCode)));
1121 cnt = addAnalysisObject(cnt);
1122
1123 pctl.add(wtf, cnt, centralityBins[iCent]);
1124 }
1125 return pctl;
1126 }
1127
1128
1129 // /// @brief Book Percentile Multiplexers around AnalysisObjects.
1130 // ///
1131 // /// Based on a previously registered CentralityProjection named @a
1132 // /// projName book one (or several) AnalysisObject(s) named
1133 // /// according to @a ref where the x-axis will be filled according
1134 // /// to the percentile output(s) of the @projName.
1135 // ///
1136 // /// @todo Convert to just be called book() cf. others
1137 // template <class T>
1138 // PercentileXaxis<T> bookPercentileXaxis(string projName,
1139 // tuple<int, int, int> ref) {
1140
1141 // typedef typename ReferenceTraits<T>::RefT RefT;
1142 // typedef MultiplexPtr<Multiplexer<T>> WrapT;
1143
1144 // PercentileXaxis<T> pctl(this, projName);
1145
1146 // const string axisCode = mkAxisCode(std::get<0>(ref),
1147 // std::get<1>(ref),
1148 // std::get<2>(ref));
1149 // const RefT & refscatter = refData<RefT>(axisCode);
1150
1151 // WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1152 // wtf = addAnalysisObject(wtf);
1153
1154 // CounterPtr cnt(_weightNames(), Counter());
1155 // cnt = addAnalysisObject(cnt);
1156
1157 // pctl.add(wtf, cnt);
1158 // return pctl;
1159 // }
1160
1162
1163
1164 private:
1165
1166 // Functions that have to be defined in the .cc file to avoid circular #includes
1167
1169 vector<string> _weightNames() const;
1170
1172 YODA::AnalysisObjectPtr _getPreload (const string& name) const;
1173
1175 MultiplexAOPtr _getOtherAnalysisObject(const std::string & ananame, const std::string& name);
1176
1178 void _checkBookInit() const;
1179
1181 bool _inInit() const;
1182
1184 bool _inFinalize() const;
1185
1187 template <typename YODAT>
1188 void _setWriterPrecision(const string& path, YODAT& yao) {
1189 const string re = _info->writerDoublePrecision();
1190 if (re != "") {
1191 std::smatch match;
1192 const bool needsDP = std::regex_search(path, match, std::regex(re));
1193 if (needsDP) yao.template setAnnotation("WriterDoublePrecision", "1");
1194 }
1195 }
1196
1197
1198 private:
1199
1201 class CounterAdapter {
1202 public:
1203
1204 CounterAdapter(double x) : x_(x) {}
1205
1206 CounterAdapter(const YODA::Counter& c) : x_(c.val()) {}
1207
1208 CounterAdapter(const YODA::Estimate& e) : x_(e.val()) {}
1209
1210 CounterAdapter(const YODA::Scatter1D& s) : x_(s.points()[0].x()) {
1211 if (s.numPoints() != 1) throw RangeError("Can only scale by a single value.");
1212 }
1213
1214 operator double() const { return x_; }
1215
1216 private:
1217 double x_;
1218
1219 };
1220
1221
1222 public:
1223
1224 double dbl(double x) { return x; }
1225 double dbl(const YODA::Counter& c) { return c.val(); }
1226 double dbl(const YODA::Estimate0D& e) { return e.val(); }
1227 double dbl(const YODA::Scatter1D& s) {
1228 if ( s.numPoints() != 1 ) throw RangeError("Only scatter with single value supported.");
1229 return s.points()[0].x();
1230 }
1231
1232
1233 protected:
1234
1238
1240 template<typename T>
1241 void scale(MultiplexPtr<Multiplexer<T>>& ao, CounterAdapter factor) {
1242 if (!ao) {
1243 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1244 << name() << " (scale=" << double(factor) << ")");
1245 return;
1246 }
1247 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1248 MSG_WARNING("Failed to scale AnalysisObject=" << ao->path() << " in analysis: "
1249 << name() << " (invalid scale factor = " << double(factor) << ")");
1250 factor = 0;
1251 }
1252 MSG_TRACE("Scaling AnalysisObject " << ao->path() << " by factor " << double(factor));
1253 try {
1254 if constexpr( isFillable<T>::value ) {
1255 ao->scaleW(factor);
1256 }
1257 else {
1258 ao->scale(factor);
1259 }
1260 }
1261 catch (YODA::Exception& we) {
1262 MSG_WARNING("Could not scale AnalysisObject " << ao->path());
1263 return;
1264 }
1265 }
1266
1268 template<typename GroupAxisT, typename... AxisT>
1269 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, CounterAdapter factor) {
1270 if (!group) {
1271 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1272 << name() << " (scale=" << double(factor) << ")");
1273 return;
1274 }
1275 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1276 MSG_WARNING("Failed to scale histo group in analysis: "
1277 << name() << " (invalid scale factor = " << double(factor) << ")");
1278 factor = 0;
1279 }
1280 MSG_TRACE("Scaling histo group by factor " << double(factor));
1281 try {
1282 group->scaleW(factor);
1283 }
1284 catch (YODA::Exception& we) {
1285 MSG_WARNING("Could not scale histo group.");
1286 return;
1287 }
1288 }
1289
1291 template<typename GroupAxisT, typename... AxisT>
1292 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, const vector<double>& factors) {
1293 if (!group) {
1294 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis " << name());
1295 return;
1296 }
1297 if (group->numBins(true) != factors.size()) {
1298 throw RangeError(name() + ": Number of scale factors does not match group binning");
1299 return;
1300 }
1301 for (auto& b : group->bins(true)) {
1302 if (!b.get()) continue;
1303 double factor = factors[b.index()];
1304 if (std::isnan(factor) || std::isinf(factor)) {
1305 MSG_WARNING("Failed to scale componment of histo group in analysis: "
1306 << name() << " (invalid scale factor = " << factor << ")");
1307 factor = 0;
1308 }
1309 MSG_TRACE("Scaling histo group element by factor " << factor);
1310 try {
1311 b->scaleW(factor);
1312 }
1313 catch (YODA::Exception& we) {
1314 MSG_WARNING("Could not scale component of histo group.");
1315 }
1316 }
1317 }
1318
1320 void scale(CutflowsPtr& group, CounterAdapter factor) {
1321 if (!group) {
1322 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1323 << name() << " (scale=" << double(factor) << ")");
1324 return;
1325 }
1326 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1327 MSG_WARNING("Failed to scale histo group in analysis: "
1328 << name() << " (invalid scale factor = " << double(factor) << ")");
1329 factor = 0;
1330 }
1331 MSG_TRACE("Scaling histo group by factor " << double(factor));
1332 try {
1333 group->scale(factor);
1334 }
1335 catch (YODA::Exception& we) {
1336 MSG_WARNING("Could not scale histo group.");
1337 return;
1338 }
1339 }
1340
1342 template<typename T, typename U>
1343 void scale(std::map<T, U>& aos, CounterAdapter factor) {
1344 for (auto& item : aos) scale(item.second, factor);
1345 }
1346
1348 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1349 void scale(AORange& aos, CounterAdapter factor) {
1350 for (auto& ao : aos) scale(ao, factor);
1351 }
1352
1354 template <typename T>
1355 void scale(std::initializer_list<T> aos, CounterAdapter factor) {
1356 for (auto& ao : std::vector<T>{aos}) scale(ao, factor);
1357 }
1358
1360 template<typename T, typename U>
1361 void scale(std::map<T, U>& aos, const vector<double>& factors) {
1362 for (auto& item : aos) scale(item.second, factors);
1363 }
1364
1366 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1367 void scale(AORange& aos, const vector<double>& factors) {
1368 for (auto& ao : aos) scale(ao, factors);
1369 }
1370
1372 template <typename T>
1373 void scale(std::initializer_list<T> aos, const vector<double>& factors) {
1374 for (auto& ao : std::vector<T>{aos}) scale(ao, factors);
1375 }
1376
1378 template<typename GroupAxisT, typename... AxisT>
1379 void divByGroupWidth(HistoGroupPtr<GroupAxisT, AxisT...>& group) {
1380 if (!group) {
1381 MSG_WARNING("Failed to scale HistoGroup=NULL in analysis "
1382 << name() << " by group axis width");
1383 return;
1384 }
1385 group->divByGroupWidth();
1386 }
1387
1389 template<typename T, typename U>
1390 void divByGroupWidth(std::map<T, U>& aos) {
1391 for (auto& item : aos) divByGroupWidth(item.second);
1392 }
1393
1395 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1396 void divByGroupWidth(AORange& aos) {
1397 for (auto& ao : aos) divByGroupWidth(ao);
1398 }
1399
1401 template <typename T>
1402 void divByGroupWidth(std::initializer_list<T> aos) {
1403 for (auto& ao : std::vector<T>{aos}) divByGroupWidth(ao);
1404 }
1405
1406
1408 template <size_t DbnN, typename... AxisT>
1409 void normalize(BinnedDbnPtr<DbnN, AxisT...> ao, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1410 if (!ao) {
1411 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1412 return;
1413 }
1414 MSG_TRACE("Normalizing histo " << ao->path() << " to " << double(norm));
1415 try {
1416 const double hint = ao->integral(includeoverflows);
1417 if (hint == 0) MSG_DEBUG("Skipping histo with null area " << ao->path());
1418 else ao->normalize(norm, includeoverflows);
1419 }
1420 catch (YODA::Exception& we) {
1421 MSG_WARNING("Could not normalize histo " << ao->path());
1422 return;
1423 }
1424 }
1425
1427 template <typename GroupAxisT, typename... AxisT>
1428 void normalize(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1429 if (!group) {
1430 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1431 return;
1432 }
1433 MSG_TRACE("Normalizing histo group to " << double(norm));
1434 try {
1435 const double hint = group->integral(includeoverflows);
1436 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1437 else group->normalize(norm, includeoverflows);
1438 }
1439 catch (YODA::Exception& we) {
1440 MSG_WARNING("Could not normalize histo group.");
1441 return;
1442 }
1443 }
1444
1445
1447 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1448 void normalize(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1449 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1450 }
1451
1453 template<typename T>
1454 void normalize(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1455 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1456 }
1457
1459 template<typename T, typename U>
1460 void normalize(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1461 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1462 for (auto& item : aos) normalize(item.second, norm, includeoverflows);
1463 }
1464
1466 template <typename GroupAxisT, typename... AxisT>
1467 void normalizeGroup(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1468 if (!group) {
1469 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1470 return;
1471 }
1472 MSG_TRACE("Normalizing histo group to " << double(norm));
1473 try {
1474 const double hint = group->integral(includeoverflows);
1475 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1476 else group->normalizeGroup(norm, includeoverflows);
1477 }
1478 catch (YODA::Exception& we) {
1479 MSG_WARNING("Could not normalize histo group.");
1480 return;
1481 }
1482 }
1483
1485 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1486 void normalizeGroup(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1487 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1488 }
1489
1491 template<typename T>
1492 void normalizeGroup(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1493 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1494 }
1495
1497 template<typename T, typename U>
1498 void normalizeGroup(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1499 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1500 for (auto& item : aos) normalizeGroup(item.second, norm, includeoverflows);
1501 }
1502
1503
1508 template<size_t DbnN, typename... AxisT>
1510 const string path = est->path();
1511 *est = ao->mkEstimate(path, "stats", false); //< do NOT divide by bin area cf. a differential dsigma/dX histogram
1512 }
1513
1518
1522 void divide(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const;
1523
1528
1532 void divide(const YODA::Estimate0D& e1, const YODA::Estimate0D& e2, Estimate0DPtr est) const;
1533
1534
1538 template<size_t DbnN, typename... AxisT>
1539 void divide(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1540 BinnedEstimatePtr<AxisT...> est) const {
1541 const string path = est->path();
1542 *est = h1 / h2;
1543 est->setPath(path);
1544 }
1545 //
1546 template<size_t DbnN, typename... AxisT>
1548 BinnedEstimatePtr<AxisT...> est) const {
1549 return divide(*h1, *h2, est);
1550 }
1551
1555 template<typename... AxisT>
1556 void divide(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1557 BinnedEstimatePtr<AxisT...> est) const {
1558 const string path = est->path();
1559 *est = e1 / e2;
1560 est->setPath(path);
1561 }
1562 //
1563 template<typename... AxisT>
1565 BinnedEstimatePtr<AxisT...> est) const {
1566 return divide(*e1, *e2, est);
1567 }
1568
1569
1570
1575 efficiency(*c1, *c2, est);
1576 }
1577
1581 void efficiency(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const {
1582 const string path = est->path();
1583 *est = YODA::efficiency(c1, c2);
1584 est->setPath(path);
1585 }
1586
1587
1588
1592 template<size_t DbnN, typename... AxisT>
1593 void efficiency(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1594 BinnedEstimatePtr<AxisT...> est) const {
1595 const string path = est->path();
1596 *est = YODA::efficiency(h1, h2);
1597 est->setPath(path);
1598 }
1599 //
1600 template<size_t DbnN, typename... AxisT>
1602 BinnedEstimatePtr<AxisT...> est) const {
1603 efficiency(*h1, *h2, est);
1604 }
1605
1606
1610 template<typename... AxisT>
1611 void efficiency(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1612 BinnedEstimatePtr<AxisT...> est) const {
1613 const string path = est->path();
1614 *est = YODA::efficiency(e1, e2);
1615 est->setPath(path);
1616 }
1617 //
1618 template<typename... AxisT>
1620 BinnedEstimatePtr<AxisT...> est) const {
1621 efficiency(*e1, *e2, est);
1622 }
1623
1624
1628 template<size_t DbnN, typename... AxisT>
1629 void asymm(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1630 BinnedEstimatePtr<AxisT...> est) const {
1631 const string path = est->path();
1632 *est = YODA::asymm(h1, h2);
1633 est->setPath(path);
1634 }
1635 //
1636 template<size_t DbnN, typename... AxisT>
1638 BinnedEstimatePtr<AxisT...> est) const {
1639 asymm(*h1, *h2, est);
1640 }
1641
1645 template<typename... AxisT>
1646 void asymm(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1647 BinnedEstimatePtr<AxisT...> est) const {
1648 const string path = est->path();
1649 *est = YODA::asymm(e1, e2);
1650 est->setPath(path);
1651 }
1652 //
1653 template<typename... AxisT>
1655 BinnedEstimatePtr<AxisT...> est) const {
1656 asymm(*e1, *e2, est);
1657 }
1658
1662 template<size_t DbnN, typename... AxisT>
1663 void integrate(const YODA::BinnedDbn<DbnN, AxisT...>& h, BinnedEstimatePtr<AxisT...> est) const {
1664 const string path = est->path();
1665 *est = mkIntegral(h);
1666 est->setPath(path);
1667 }
1668 //
1669 template<size_t DbnN, typename... AxisT>
1671 integrate(*h, est);
1672 }
1673
1675
1676
1677 public:
1678
1680 const vector<MultiplexAOPtr>& analysisObjects() const {
1681 return _analysisobjects;
1682 }
1683
1684
1685 protected:
1686
1689
1691 size_t defaultWeightIndex() const;
1692
1694 template <typename YODAT>
1695 shared_ptr<YODAT> getPreload(const string& path) const {
1696 return dynamic_pointer_cast<YODAT>(_getPreload(path));
1697 }
1698
1699
1701 template <typename YODAT>
1703 using MultiplexerT = Multiplexer<YODAT>;
1704 using YODAPtrT = shared_ptr<YODAT>;
1705 using RAOT = MultiplexPtr<MultiplexerT>;
1706
1707 if ( !_inInit() && !_inFinalize() ) {
1708 MSG_ERROR("Can't book objects outside of init() or finalize()");
1709 throw UserError(name() + ": Can't book objects outside of init() or finalize().");
1710 }
1711
1712 // First check that we haven't booked this before.
1713 // This is allowed when booking in finalize: just warn in that case.
1714 // If in init(), throw an exception: it's 99.9% never going to be intentional.
1715 for (auto& waold : analysisObjects()) {
1716 if ( yao.path() == waold.get()->basePath() ) {
1717 const string msg = "Found double-booking of " + yao.path() + " in " + name();
1718 if ( _inInit() ) {
1719 MSG_ERROR(msg);
1720 throw LookupError(msg);
1721 } else {
1722 MSG_WARNING(msg + ". Keeping previous booking");
1723 }
1724 return RAOT(dynamic_pointer_cast<MultiplexerT>(waold.get()));
1725 }
1726 }
1727
1728 shared_ptr<MultiplexerT> wao = make_shared<MultiplexerT>();
1729 wao->_basePath = yao.path();
1730 YODAPtrT yaop = make_shared<YODAT>(yao);
1731
1732 for (const string& weightname : _weightNames()) {
1733 // Create two YODA objects for each weight. Copy from
1734 // preloaded YODAs if present. First the finalized yoda:
1735 string finalpath = yao.path();
1736 if ( weightname != "" ) finalpath += "[" + weightname + "]";
1737 YODAPtrT preload = getPreload<YODAT>(finalpath);
1738 if ( preload ) {
1739 if ( !bookingCompatible(preload, yaop) ) {
1741 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1742 << finalpath << " for " << name());
1743 preload = nullptr;
1744 } else {
1745 MSG_TRACE("Using preloaded " << finalpath << " in " <<name());
1746 wao->_final.push_back(make_shared<YODAT>(*preload));
1747 }
1748 }
1749 else {
1750 wao->_final.push_back(make_shared<YODAT>(yao));
1751 wao->_final.back()->setPath(finalpath);
1752 }
1753
1754 // Then the raw filling yodas.
1755 string rawpath = "/RAW" + finalpath;
1756 preload = getPreload<YODAT>(rawpath);
1757 if ( preload ) {
1758 if ( !bookingCompatible(preload, yaop) ) {
1759 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1760 << rawpath << " for " << name());
1761 preload = nullptr;
1762 } else {
1763 MSG_TRACE("Using preloaded " << rawpath << " in " <<name());
1764 wao->_persistent.push_back(make_shared<YODAT>(*preload));
1765 }
1766 }
1767 else {
1768 wao->_persistent.push_back(make_shared<YODAT>(yao));
1769 wao->_persistent.back()->setPath(rawpath);
1770 }
1771 }
1773
1774 ret.get()->unsetActiveWeight();
1775 if ( _inFinalize() ) {
1776 // If booked in finalize() we assume it is the first time
1777 // finalize is run.
1778 ret.get()->pushToFinal();
1779 ret.get()->setActiveFinalWeightIdx(0);
1780 }
1781 _analysisobjects.push_back(ret);
1782
1783 return ret;
1784 }
1785
1786
1788 template <typename AO=MultiplexAOPtr>
1789 AO addAnalysisObject(const AO& aonew) {
1790 _checkBookInit();
1791
1792 for (const MultiplexAOPtr& ao : analysisObjects()) {
1793
1794 // Check AO base-name first
1795 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1796 aonew.get()->setActiveWeightIdx(defaultWeightIndex());
1797 if (ao->path() != aonew->path()) continue;
1798
1799 // If base-name matches, check compatibility
1800 // NB. This evil is because dynamic_ptr_cast can't work on MultiplexPtr directly
1801 AO aoold = AO(dynamic_pointer_cast<typename AO::value_type>(ao.get())); //< OMG
1802 if ( !aoold || !bookingCompatible(aonew, aoold) ) {
1803 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1804 << aonew->path() << " for " << name());
1805 throw LookupError("Found incompatible pre-existing data object with same base path during AO booking");
1806 }
1807
1808 // Finally, check all weight variations
1809 for (size_t weightIdx = 0; weightIdx < _weightNames().size(); ++weightIdx) {
1810 aoold.get()->setActiveWeightIdx(weightIdx);
1811 aonew.get()->setActiveWeightIdx(weightIdx);
1812 if (aoold->path() != aonew->path()) {
1813 MSG_WARNING("Found incompatible pre-existing data object with different weight-path "
1814 << aonew->path() << " for " << name());
1815 throw LookupError("Found incompatible pre-existing data object with same weight-path during AO booking");
1816 }
1817 }
1818
1819 // They're fully compatible: bind and return
1820 aoold.get()->unsetActiveWeight();
1821 MSG_TRACE("Bound pre-existing data object " << aoold->path() << " for " << name());
1822 return aoold;
1823 }
1824
1825 // No equivalent found
1826 MSG_TRACE("Registered " << aonew->annotation("Type") << " " << aonew->path() << " for " << name());
1827 aonew.get()->unsetActiveWeight();
1828
1829 _analysisobjects.push_back(aonew);
1830 return aonew;
1831 }
1832
1834 void removeAnalysisObject(const std::string& path);
1835
1838
1840 template <typename AO=MultiplexAOPtr>
1841 const AO getAnalysisObject(const std::string& aoname) const {
1842 for (const MultiplexAOPtr& ao : analysisObjects()) {
1843 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1844 if (ao->path() == histoPath(aoname)) {
1845 // return dynamic_pointer_cast<AO>(ao);
1846 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1847 }
1848 }
1849 throw LookupError("Data object " + histoPath(aoname) + " not found");
1850 }
1851
1852
1853 // /// Get a data object from the histogram system
1854 // template <typename AO=YODA::AnalysisObject>
1855 // const std::shared_ptr<AO> getAnalysisObject(const std::string& name) const {
1856 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1857 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1858 // }
1859 // throw LookupError("Data object " + histoPath(name) + " not found");
1860 // }
1861
1862 // /// Get a data object from the histogram system (non-const)
1863 // template <typename AO=YODA::AnalysisObject>
1864 // std::shared_ptr<AO> getAnalysisObject(const std::string& name) {
1865 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1866 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1867 // }
1868 // throw LookupError("Data object " + histoPath(name) + " not found");
1869 // }
1870
1871
1874 template <typename AO=MultiplexAOPtr>
1875 AO getAnalysisObject(const std::string& ananame,
1876 const std::string& aoname) {
1877 MultiplexAOPtr ao = _getOtherAnalysisObject(ananame, aoname);
1878 // return dynamic_pointer_cast<AO>(ao);
1879 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1880 }
1881
1883
1884
1885 private:
1886
1888 string _defaultname;
1889
1891 unique_ptr<AnalysisInfo> _info;
1892
1895 vector<MultiplexAOPtr> _analysisobjects;
1896
1899 double _crossSection;
1900 bool _gotCrossSection;
1902
1904 AnalysisHandler* _analysishandler;
1905
1908 mutable std::map<std::string, YODA::AnalysisObjectPtr> _refdata;
1909
1911 map<string, string> _options;
1912
1914 string _optstring;
1915
1916
1917 private:
1918
1921
1923 void _cacheRefData() const;
1924
1926
1927 };
1928
1929
1930 // // Template specialisation for literal character strings (which don't play well with stringstream)
1931 // template<>
1932 // inline std::string Analysis::getOption(std::string optname, const char* def) {
1933 // return getOption<std::string>(optname, def); //.c_str();
1934 // }
1935
1936
1937}
1938
1939
1940// Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
1941#include "Rivet/AnalysisBuilder.hh"
1942
1943
1946
1949#define RIVET_DECLARE_PLUGIN(clsname) ::Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
1950
1953#define RIVET_DECLARE_ALIASED_PLUGIN(clsname, alias) RIVET_DECLARE_PLUGIN(clsname)( #alias )
1954
1957#define RIVET_DEFAULT_ANALYSIS_CTOR(clsname) clsname() : Analysis(# clsname) {}
1958
1961#define RIVET_REGISTER_TYPE(...) handler().registerType<__VA_ARGS__>()
1962
1965#define RIVET_REGISTER_BINNED_SET(...) { \
1966 RIVET_REGISTER_TYPE(YODA::BinnedHisto<__VA_ARGS__>); \
1967 RIVET_REGISTER_TYPE(YODA::BinnedProfile<__VA_ARGS__>); \
1968 RIVET_REGISTER_TYPE(YODA::BinnedEstimate<__VA_ARGS__>); }
1969
1971
1972
1973#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:69
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:1017
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:655
virtual std::string status() const
Whether this analysis is trusted (in any way!)
Definition Analysis.hh:245
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:265
shared_ptr< YODAT > getPreload(const string &path) const
Get a preloaded YODA object.
Definition Analysis.hh:1695
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:152
void scale(std::initializer_list< T > aos, CounterAdapter factor)
Iteratively scale the AOs in the initialiser list aos, by factor factor.
Definition Analysis.hh:1355
virtual std::string collider() const
Collider on which the experiment ran.
Definition Analysis.hh:209
MultiplexPtr< Multiplexer< YODAT > > registerAO(const YODAT &yao)
Register a new data object, optionally read in preloaded data.
Definition Analysis.hh:1702
virtual double luminosityfb() const
The integrated luminosity in inverse femtobarn.
Definition Analysis.hh:219
void loadInfo()
Get the AnalysisInfo object to parse its info file in which the metadata is stored.
Definition Analysis.hh:129
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:1101
const AnalysisInfo & info() const
Get the actual AnalysisInfo object in which all this metadata is stored.
Definition Analysis.hh:132
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:1448
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:1460
void efficiency(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const
Definition Analysis.hh:1574
virtual const std::vector< std::string > & keywords() const
Get vector of analysis keywords.
Definition Analysis.hh:270
virtual double luminosity() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:223
virtual std::string spiresID() const
Get the SPIRES ID code for this analysis (~deprecated).
Definition Analysis.hh:163
virtual std::string writerDoublePrecision() const
Positive filtering regex for setting double precision in Writer.
Definition Analysis.hh:285
void efficiency(const YODA::Counter &c1, const YODA::Counter &c2, Estimate0DPtr est) const
Definition Analysis.hh:1581
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:641
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:808
virtual Analysis & setRequiredBeamIDs(const std::vector< PdgIdPair > &beamids)
Declare the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:294
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:749
AO getAnalysisObject(const std::string &ananame, const std::string &aoname)
Definition Analysis.hh:1875
void barchart(BinnedDbnPtr< DbnN, AxisT... > ao, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1509
AnalysisInfo & info()
Get the actual AnalysisInfo object in which all this metadata is stored (non-const).
Definition Analysis.hh:327
virtual std::string runInfo() const
Information about the events needed as input for this analysis.
Definition Analysis.hh:199
void syncDeclQueue()
Definition Analysis.hh:112
void scale(AORange &aos, CounterAdapter factor)
Iteratively scale the AOs in the iterable aos, by factor factor.
Definition Analysis.hh:1349
virtual std::string year() const
When the original experimental analysis was published.
Definition Analysis.hh:214
T getOption(std::string optname, T def) const
Get an option for this analysis instance converted to a specific type.
Definition Analysis.hh:1029
virtual void setRefDataName(const std::string &ref_data="")
Set name of reference data file, which could be different from plugin name.
Definition Analysis.hh:319
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:1680
double crossSectionPerEvent() const
virtual std::string summary() const
Get a short description of the analysis.
Definition Analysis.hh:180
void scale(AORange &aos, const vector< double > &factors)
Iteratively scale the AOs in the iterable aos, by factors factors.
Definition Analysis.hh:1367
virtual std::string description() const
Get a full description of the analysis.
Definition Analysis.hh:190
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:1361
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:1007
virtual std::vector< std::string > validation() const
make-style commands for validating this analysis.
Definition Analysis.hh:260
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:1492
virtual std::vector< std::string > authors() const
Names & emails of paper/analysis authors.
Definition Analysis.hh:171
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, const vector< double > &factors)
Multiplicatively scale the given histogram group, group, by factors factors.
Definition Analysis.hh:1292
void asymm(const YODA::BinnedEstimate< AxisT... > &e1, const YODA::BinnedEstimate< AxisT... > &e2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1646
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:304
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:1486
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:1396
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:760
virtual std::string refFile() const
Location of reference data YODA file.
Definition Analysis.hh:311
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:1467
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:1593
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:623
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:845
virtual std::vector< std::string > references() const
Journal, and preprint references.
Definition Analysis.hh:230
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:255
virtual std::string inspireID() const
Get the Inspire ID code for this analysis.
Definition Analysis.hh:158
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, CounterAdapter factor)
Multiplicatively scale the given histogram group, group, by factor factor.
Definition Analysis.hh:1269
bool merging() const
Check if we are running rivet-merge.
Definition Analysis.hh:339
void divByGroupWidth(std::initializer_list< T > aos)
Iteratively scale the HistoGroups in the initialiser list aos, by the group axis width.
Definition Analysis.hh:1402
void divide(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1539
vector< double > allowedEnergies() const
Allowed centre-of-mass energies (in GeV) for this routine.
virtual const std::vector< PdgIdPair > & requiredBeamIDs() const
Return the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:290
virtual std::string refUnmatch() const
Negative filtering regex for ref-data HepData sync.
Definition Analysis.hh:280
const std::map< std::string, std::string > & options() const
Return the map of all options given to this analysis.
Definition Analysis.hh:1002
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:1055
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:1241
void scale(CutflowsPtr &group, CounterAdapter factor)
Multiplicatively scale the cutflow group, group, by factor factor.
Definition Analysis.hh:1320
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:834
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:275
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:1498
double luminositypb() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:227
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:1556
void integrate(const YODA::BinnedDbn< DbnN, AxisT... > &h, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1663
const T & refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Definition Analysis.hh:518
virtual std::string warning() const
A warning message from the info file, if there is one.
Definition Analysis.hh:250
AnalysisHandler & handler() const
Access the controlling AnalysisHandler object.
Definition Analysis.hh:402
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:1379
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:1454
double sumOfWeights() const
Alias.
Definition Analysis.hh:434
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:708
const AO getAnalysisObject(const std::string &aoname) const
Get a Rivet data object from the histogram system.
Definition Analysis.hh:1841
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:922
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:885
const std::map< std::string, YODA::AnalysisObjectPtr > & refData() const
Get all reference data objects for this analysis.
Definition Analysis.hh:495
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:1611
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:663
void asymm(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1629
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:785
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:235
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:240
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:634
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:504
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:562
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:315
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:767
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:1409
virtual std::string name() const
Get the name of the analysis.
Definition Analysis.hh:144
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:1373
void divByGroupWidth(std::map< T, U > &aos)
Iteratively scale the HistoGroups in the map aos, by the group axis width.
Definition Analysis.hh:1390
virtual std::string experiment() const
Experiment which performed and published this analysis.
Definition Analysis.hh:204
void scale(std::map< T, U > &aos, CounterAdapter factor)
Iteratively scale the AOs in the map aos, by factor factor.
Definition Analysis.hh:1343
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:1428
virtual const std::vector< std::pair< double, double > > & requiredBeamEnergies() const
Sets of valid beam energy pairs, in GeV.
Definition Analysis.hh:300
AO addAnalysisObject(const AO &aonew)
Register a data object in the histogram system.
Definition Analysis.hh:1789
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:24
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:948
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:940
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:67
Error for e.g. use of invalid bin ranges.
Definition Exceptions.hh:22
Error for read failures.
Definition Exceptions.hh:78
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:61