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/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 "Rivet/Projections/FastJets.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::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
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() { info().parseInfoFile(); }
149
151 const AnalysisInfo& info() const {
152 if (!_info) throw Error("No AnalysisInfo object :-O");
153 return *_info;
154 }
155
163 virtual std::string name() const {
164 return ( (info().name().empty()) ? _defaultname : info().name() ) + _optstring;
165 }
166
171 std::string analysisDataPath(const std::string& extn, const std::string& suffix="") {
172 string filename = name() + (suffix.empty() ? "" : "-") + suffix + "." + extn;
173 return findAnalysisDataFile(filename);
174 }
175
177 virtual std::string inspireID() const {
178 return info().inspireID();
179 }
180
182 virtual std::string spiresID() const {
183 return info().spiresID();
184 }
185
190 virtual std::vector<std::string> authors() const {
191 return info().authors();
192 }
193
199 virtual std::string summary() const {
200 return info().summary();
201 }
202
209 virtual std::string description() const {
210 return info().description();
211 }
212
218 virtual std::string runInfo() const {
219 return info().runInfo();
220 }
221
223 virtual std::string experiment() const {
224 return info().experiment();
225 }
226
228 virtual std::string collider() const {
229 return info().collider();
230 }
231
233 virtual std::string year() const {
234 return info().year();
235 }
236
238 virtual double luminosityfb() const {
239 return info().luminosityfb();
240 }
241
242 virtual double luminosity() const {
243 return info().luminosity();
244 }
245
246 double luminositypb() const { return luminosity(); }
247
249 virtual std::vector<std::string> references() const {
250 return info().references();
251 }
252
254 virtual std::string bibKey() const {
255 return info().bibKey();
256 }
257
259 virtual std::string bibTeX() const {
260 return info().bibTeX();
261 }
262
264 virtual std::string status() const {
265 return (info().status().empty()) ? "UNVALIDATED" : info().status();
266 }
267
269 virtual std::string warning() const {
270 return info().warning();
271 }
272
274 virtual std::vector<std::string> todos() const {
275 return info().todos();
276 }
277
279 virtual std::vector<std::string> validation() const {
280 return info().validation();
281 }
282
284 virtual bool reentrant() const {
285 return info().reentrant();
286 }
287
289 virtual const std::vector<std::string>& keywords() const {
290 return info().keywords();
291 }
292
294 virtual std::string refMatch() const {
295 return info().refMatch();
296 }
297
299 virtual std::string refUnmatch() const {
300 return info().refUnmatch();
301 }
302
304 virtual std::string writerDoublePrecision() const {
305 return info().writerDoublePrecision();
306 }
307
309 virtual const std::vector<PdgIdPair>& requiredBeamIDs() const {
310 return info().beamIDs();
311 }
312
313 virtual Analysis& setRequiredBeamIDs(const std::vector<PdgIdPair>& beamids) {
314 info().setBeamIDs(beamids);
315 return *this;
316 }
317
319 virtual const std::vector<std::pair<double, double> >& requiredBeamEnergies() const {
320 return info().energies();
321 }
322
323 virtual Analysis& setRequiredBeamEnergies(const std::vector<std::pair<double, double> >& energies) {
324 info().setEnergies(energies);
325 return *this;
326 }
327
328
330 virtual std::string refFile() const {
331 return info().refFile();
332 }
333
334 virtual std::string refDataName() const {
335 return (info().getRefDataName().empty()) ? _defaultname : info().getRefDataName();
336 }
337
338 virtual void setRefDataName(const std::string& ref_data="") {
339 info().setRefDataName(!ref_data.empty() ? ref_data : name());
340 }
341
342
347 if (!_info) throw Error("No AnalysisInfo object :-O");
348 return *_info;
349 }
350
352
353
356
358 bool merging() const {
359 return sqrtS() <= 0.0;
360 }
361
363 bool compatibleWithRun() const;
364
366 void raiseBeamErrorIf(const bool condition) const;
367
369
370
374
376 const ParticlePair& beams() const;
377
379 PdgIdPair beamIDs() const;
380
382 pair<double,double> beamEnergies() const;
383
385 vector<double> allowedEnergies() const;
386
388 double sqrtS() const;
389
391 bool beamsMatch(const ParticlePair& beams) const;
392
394 bool beamsMatch(PdgId beam1, PdgId beam2, double e1, double e2) const;
395
397 bool beamsMatch(const PdgIdPair& beams, const std::pair<double,double>& energies) const;
398
400 bool beamIDsMatch(PdgId beam1, PdgId beam2) const;
401
403 bool beamIDsMatch(const PdgIdPair& beamids) const;
404
406 bool beamEnergiesMatch(double e1, double e2) const;
407
409 bool beamEnergiesMatch(const std::pair<double,double>& energies) const;
410
412 bool beamEnergyMatch(const std::pair<double,double>& energies) const;
413
415 bool beamEnergyMatch(double sqrts) const;
416
418 bool isCompatibleWithSqrtS(double energy, double tolerance=1e-5) const;
419
421
422
424 AnalysisHandler& handler() const { return *_analysishandler; }
425
427 const Event& currentEvent() const {
428 if (!_currentevent) throw Error("No current event set: did you try to access it in init() or finalize()?");
429 return *_currentevent;
430 }
431
432
433 protected:
434
436 Log& getLog() const;
437
439 double crossSection() const;
440
443 double crossSectionPerEvent() const;
444
446 double crossSectionError() const;
447
451
455 size_t numEvents() const;
456
460 double effNumEvents() const;
461
465 double sumW() const;
467 double sumOfWeights() const { return sumW(); }
468
472 double sumW2() const;
473
474
475 protected:
476
482
484 const std::string histoDir() const;
485
487 const std::string histoPath(const std::string& hname) const;
488
490 const std::string histoPath(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
491
493 const std::string mkAxisCode(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
494
496
497
498 #ifdef HAVE_H5
501
503 H5::File auxFile() const {
504 return H5::readFile(name()+".h5");
505 }
506
508 template <typename T>
509 bool auxData(const string& dsname, T& rtndata) {
511 return H5::readData(name()+".h5", dsname, rtndata);
512 }
513
514 template <typename T>
515 T auxData(const string& dsname) {
517 return H5::readData<T>(name()+".h5", dsname);
518 }
519
521 #endif
522
523
526
528 const std::map<std::string, YODA::AnalysisObjectPtr>& refData() const {
529 _cacheRefData();
530 return _refdata;
531 }
532
534 bool hasRefData(const string& hname) const {
535 _cacheRefData();
536 return _refdata.count(hname);
537 }
538
540 bool hasRefData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
541 return hasRefData(mkAxisCode(datasetId, xAxisId, yAxisId));
542 }
543
544
548 template <typename T=YODA::Estimate1D>
549 const T& refData(const string& hname) const {
550 _cacheRefData();
551 MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
552 if (!_refdata[hname]) {
553 MSG_ERROR("Can't find reference histogram " << hname);
554 throw Exception("Reference data " + hname + " not found.");
555 }
556 try {
557 return dynamic_cast<T&>(*_refdata[hname]);
558 } catch (...) {
559 throw Exception("Expected type " + _refdata[hname]->type()+" for reference data \"" + hname + "\".\n");
560 }
561 }
562
563
567 template <typename T=YODA::Estimate1D>
568 const T& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
569 const string hname = mkAxisCode(datasetId, xAxisId, yAxisId);
570 return refData<T>(hname);
571 }
572
574
575
581
583 CounterPtr& book(CounterPtr&, const std::string& name);
584
588 CounterPtr& book(CounterPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
589
591
592
595
597 Estimate0DPtr& book(Estimate0DPtr&, const std::string& name);
598
602 Estimate0DPtr& book(Estimate0DPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
603
604
606
609
611 template<size_t DbnN, typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
612 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao,
613 const std::string& name, const std::vector<size_t>& nbins,
614 const std::vector<std::pair<double,double>>& loUpPairs) {
615 if (nbins.size() != loUpPairs.size()) {
616 throw RangeError("Vectors should have the same size!");
617 }
618 const string path = histoPath(name);
619
620 YODA::BinnedDbn<DbnN, AxisT...> yao(nbins, loUpPairs, path);
621 _setWriterPrecision(path, yao);
622
623 return ao = registerAO(yao);
624 }
625
626 // Specialiation for 1D
627 Histo1DPtr& book(Histo1DPtr& ao, const std::string& name,
628 const size_t nbins, const double lower, const double upper) {
629 return book(ao, name, vector<size_t>{nbins},
630 vector<pair<double,double>>{{lower,upper}});
631 }
632 //
633 Profile1DPtr& book(Profile1DPtr& ao, const std::string& name,
634 const size_t nbins, const double lower, const double upper) {
635 return book(ao, name, vector<size_t>{nbins},
636 vector<pair<double,double>>{{lower,upper}});
637 }
638
639 // Specialiation for 2D
640 Histo2DPtr& book(Histo2DPtr& ao, const std::string& name,
641 const size_t nbinsX, const double lowerX, const double upperX,
642 const size_t nbinsY, const double lowerY, const double upperY) {
643 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
644 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
645 }
646 //
647 Profile2DPtr& book(Profile2DPtr& ao, const std::string& name,
648 const size_t nbinsX, const double lowerX, const double upperX,
649 const size_t nbinsY, const double lowerY, const double upperY) {
650 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
651 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
652 }
653
654 // Specialiation for 3D
655 Histo3DPtr& book(Histo3DPtr& ao, const std::string& name,
656 const size_t nbinsX, const double lowerX, const double upperX,
657 const size_t nbinsY, const double lowerY, const double upperY,
658 const size_t nbinsZ, const double lowerZ, const double upperZ) {
659 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
660 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
661 }
662 //
663 Profile3DPtr& book(Profile3DPtr& ao, const std::string& name,
664 const size_t nbinsX, const double lowerX, const double upperX,
665 const size_t nbinsY, const double lowerY, const double upperY,
666 const size_t nbinsZ, const double lowerZ, const double upperZ) {
667 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
668 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
669 }
670
672 template<size_t DbnN, typename... AxisT>
673 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
674 const std::vector<AxisT>&... binedges) {
675 const string path = histoPath(name);
676 YODA::BinnedDbn<DbnN, AxisT...> yao(binedges..., path);
677 _setWriterPrecision(path, yao);
678
679 return ao = registerAO(yao);
680 }
681
683 template<size_t DbnN, typename... AxisT>
684 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
685 const std::initializer_list<AxisT>&... binedges) {
686 return book(ao, name, vector<AxisT>{binedges} ...);
687 }
688
690 template<size_t DbnN, typename... AxisT>
691 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
692 const YODA::BinnedEstimate<AxisT...>& refest) {
693 const string path = histoPath(name);
694
695 YODA::BinnedDbn<DbnN, AxisT...> yao(refest.binning(), path);
696 for (const string& a : yao.annotations()) {
697 if (a != "Path") yao.rmAnnotation(a);
698 }
699 _setWriterPrecision(path, yao);
700 return ao = registerAO(yao);
701 }
702
704 template<size_t DbnN, typename... AxisT>
705 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name) {
706 return book(ao, name, refData<YODA::BinnedEstimate<AxisT...>>(name));
707 }
708
712 template<size_t DbnN, typename... AxisT>
713 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const unsigned int datasetID,
714 const unsigned int xAxisID, const unsigned int yAxisID) {
715 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
716 return book(ao, name);
717 }
718
720
723
724 template <typename GroupAxisT, typename... AxisT>
725 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
726 const std::vector<GroupAxisT>& edges,
727 const std::vector<std::string>& names) {
728 ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
729 if (ao->numBins() != names.size()) {
730 throw RangeError("Binning and reference-data names don't match!");
731 }
732 for (auto& b : ao->bins()) {
733 const string& refname = names[b.index()-1];
734 book(b, refname, refData<YODA::BinnedEstimate<AxisT...>>(refname));
735 }
736 return ao;
737 }
738
739 template <typename GroupAxisT, typename... AxisT>
740 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
741 const std::vector<GroupAxisT>& edges) {
742 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
743 }
744
745 template <typename GroupAxisT, typename... AxisT>
746 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
747 std::initializer_list<GroupAxisT>&& edges) {
748 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(std::move(edges));
749 }
750
752
755
757 template<typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
758 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao,
759 const std::string& name, const std::vector<size_t>& nbins,
760 const std::vector<std::pair<double,double>>& loUpPairs) {
761 if (nbins.size() != loUpPairs.size()) {
762 throw RangeError("Vectors should have the same size!");
763 }
764 const string path = histoPath(name);
765
766 YODA::BinnedEstimate<AxisT...> yao(nbins, loUpPairs, path);
767 _setWriterPrecision(path, yao);
768
769 return ao = registerAO(yao);
770 }
771
772
773 // Specialiation for 1D
774 Estimate1DPtr& book(Estimate1DPtr& ao, const std::string& name,
775 const size_t nbins, const double lower, const double upper) {
776 return book(ao, name, vector<size_t>{nbins},
777 vector<pair<double,double>>{{lower,upper}});
778 }
779
780 // Specialiation for 2D
781 Estimate2DPtr& book(Estimate2DPtr& ao, const std::string& name,
782 const size_t nbinsX, const double lowerX, const double upperX,
783 const size_t nbinsY, const double lowerY, const double upperY) {
784 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
785 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
786 }
787
788 // Specialiation for 3D
789 Estimate3DPtr& book(Estimate3DPtr& ao, const std::string& name,
790 const size_t nbinsX, const double lowerX, const double upperX,
791 const size_t nbinsY, const double lowerY, const double upperY,
792 const size_t nbinsZ, const double lowerZ, const double upperZ) {
793 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
794 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
795 }
796
798 template<typename... AxisT>
799 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
800 const std::vector<AxisT>&... binedges) {
801 const string path = histoPath(name);
802 YODA::BinnedEstimate<AxisT...> yao(binedges..., path);
803 _setWriterPrecision(path, yao);
804
805 return ao = registerAO(yao);
806 }
807
809 template<typename... AxisT>
810 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
811 const std::initializer_list<AxisT>&... binedges) {
812 return book(ao, name, vector<AxisT>{binedges} ...);
813 }
814
816 template<typename... AxisT>
817 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name) {
818
819 const string path = histoPath(name);
820 YODA::BinnedEstimate<AxisT...> yao;
821 try {
822 yao = YODA::BinnedEstimate<AxisT...>(refData<YODA::BinnedEstimate<AxisT...>>(name).binning());
823 } catch (...) {
824 MSG_DEBUG("Couldn't retrieve reference binning, continue with nullary AO constructor.");
825 }
826 yao.setPath(path);
827 _setWriterPrecision(path, yao);
828 return ao = registerAO(yao);
829 }
830
834 template<typename... AxisT>
835 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const unsigned int datasetID,
836 const unsigned int xAxisID, const unsigned int yAxisID) {
837 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
838 return book(ao, name);
839 }
840
842
843
846
857 template<size_t N>
858 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const bool copy_pts = false) {
859 const string path = histoPath(name);
860 YODA::ScatterND<N> scat(path);
861 if (copy_pts) {
862 const YODA::ScatterND<N> ref = refData<YODA::EstimateND<N-1>>(name).mkScatter();
863 for (YODA::PointND<N> p : ref.points()) {
864 p.setVal(N-1, 0.0);
865 p.setErr(N-1, 0.0);
866 scat.addPoint(std::move(p));
867 }
868 }
869 _setWriterPrecision(path, scat);
870 return snd = registerAO(scat);
871 }
872
883 template<size_t N>
884 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const unsigned int datasetID, const unsigned int xAxisID,
885 const unsigned int yAxisID, const bool copy_pts = false) {
886 const string axisCode = mkAxisCode(datasetID, xAxisID, yAxisID);
887 return book(snd, axisCode, copy_pts);
888 }
889
895 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
896 const size_t npts, const double lower, const double upper) {
897 const string path = histoPath(name);
898
899 Scatter2D scat(path);
900 const double binwidth = (upper-lower)/npts;
901 for (size_t pt = 0; pt < npts; ++pt) {
902 const double bincentre = lower + (pt + 0.5) * binwidth;
903 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
904 }
905 _setWriterPrecision(path, scat);
906
907 return snd = registerAO(scat);
908 }
909 //
910 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
911 const size_t nptsX, const double lowerX, const double upperX,
912 const size_t nptsY, const double lowerY, const double upperY) {
913 const string path = histoPath(name);
914
915 Scatter3D scat(path);
916 const double xbinwidth = (upperX-lowerX)/nptsX;
917 const double ybinwidth = (upperY-lowerY)/nptsY;
918 for (size_t xpt = 0; xpt < nptsX; ++xpt) {
919 const double xbincentre = lowerX + (xpt + 0.5) * xbinwidth;
920 for (size_t ypt = 0; ypt < nptsY; ++ypt) {
921 const double ybincentre = lowerY + (ypt + 0.5) * ybinwidth;
922 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
923 }
924 }
925 _setWriterPrecision(path, scat);
926
927 return snd = registerAO(scat);
928 }
929
935 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
936 const std::vector<double>& binedges) {
937 const string path = histoPath(name);
938
939 Scatter2D scat(path);
940 for (size_t pt = 0; pt < binedges.size()-1; ++pt) {
941 const double bincentre = (binedges[pt] + binedges[pt+1]) / 2.0;
942 const double binwidth = binedges[pt+1] - binedges[pt];
943 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
944 }
945 _setWriterPrecision(path, scat);
946
947 return snd = registerAO(scat);
948 }
949 //
950 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
951 const std::vector<double>& binedgesX,
952 const std::vector<double>& binedgesY) {
953 const string path = histoPath(name);
954
955 Scatter3D scat(path);
956 for (size_t xpt = 0; xpt < binedgesX.size()-1; ++xpt) {
957 const double xbincentre = (binedgesX[xpt] + binedgesX[xpt+1]) / 2.0;
958 const double xbinwidth = binedgesX[xpt+1] - binedgesX[xpt];
959 for (size_t ypt = 0; ypt < binedgesY.size()-1; ++ypt) {
960 const double ybincentre = (binedgesY[ypt] + binedgesY[ypt+1]) / 2.0;
961 const double ybinwidth = binedgesY[ypt+1] - binedgesY[ypt];
962 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
963 }
964 }
965 _setWriterPrecision(path, scat);
966
967 return snd = registerAO(scat);
968 }
969
971 template<size_t N>
972 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const YODA::ScatterND<N>& refscatter) {
973 const string path = histoPath(name);
974
975 YODA::ScatterND<N> scat(refscatter, path);
976 for (const string& a : scat.annotations()) {
977 if (a != "Path") scat.rmAnnotation(a);
978 }
979 _setWriterPrecision(path, scat);
980
981 return snd = registerAO(scat);
982 }
983
985
988
990 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::vector<std::string>& edges) {
991 const string path = histoPath(name);
992 Cutflow yao(edges, path);
993 _setWriterPrecision(path, yao);
994 return ao = registerAO(yao);
995 }
996
998 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::initializer_list<std::string>& edges) {
999 return book(ao, name, vector<std::string>{edges});
1000 }
1001
1003
1006
1007 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges,
1008 const std::vector<std::vector<std::string>>& innerEdges) {
1009 ao = make_shared<Cutflows>(edges);
1010 if (ao->numBins() !=innerEdges.size()) {
1011 throw RangeError("Outer and Inner edges don't match");
1012 }
1013 for (auto& b : ao->bins()) {
1014 book(b, b.xEdge(), innerEdges[b.index()-1]);
1015 }
1016 return ao;
1017 }
1018
1019 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges) {
1020 return ao = make_shared<Cutflows>(edges);
1021 }
1022
1023 CutflowsPtr& book(CutflowsPtr& ao, std::initializer_list<std::string>&& edges) {
1024 return ao = make_shared<Cutflows>(std::move(edges));
1025 }
1026
1028
1029
1033 virtual void rawHookIn(YODA::AnalysisObjectPtr yao) {
1034 (void) yao; // suppress unused variable warning
1035 }
1036
1040 virtual void rawHookOut(const vector<MultiplexAOPtr>& raos, size_t iW) {
1041 (void) raos; // suppress unused variable warning
1042 (void) iW; // suppress unused variable warning
1043 }
1044
1045
1046 public:
1047
1050
1052 const std::map<std::string,std::string>& options() const {
1053 return _options;
1054 }
1055
1057 std::string getOption(std::string optname, string def="") const {
1058 if ( _options.find(optname) != _options.end() )
1059 return _options.find(optname)->second;
1060 return def;
1061 }
1062
1067 std::string getOption(std::string optname, const char* def) {
1068 return getOption<std::string>(optname, def);
1069 }
1070
1078 template<typename T>
1079 T getOption(std::string optname, T def) const {
1080 if (_options.find(optname) == _options.end()) return def;
1081 std::stringstream ss;
1082 ss.exceptions(std::ios::failbit);
1083 T ret;
1084 ss << _options.find(optname)->second;
1085 try {
1086 ss >> ret;
1087 } catch (...) {
1088 throw ReadError("Could not read user-provided option into requested type");
1089 }
1090 return ret;
1091 }
1092
1103 // template<>
1104 // bool getOption<bool>(std::string optname, bool def) const {
1105 bool getOption(std::string optname, bool def) const {
1106 if (_options.find(optname) == _options.end()) return def;
1107 const std::string val = getOption(optname);
1108 const std::string lval = toLower(val);
1109 if (lval.empty()) return false;
1110 if (lval == "true" || lval == "yes" || lval == "on") return true;
1111 if (lval == "false" || lval == "no" || lval == "off") return false;
1112 return bool(getOption<int>(optname, 0));
1113 }
1114
1116
1117
1120
1139 string calAnaName, string calHistName,
1140 const string projName,
1141 PercentileOrder pctorder=PercentileOrder::DECREASING);
1142
1143
1150 template<typename T>
1151 Percentile<T> book(const string& projName,
1152 const vector<pair<double, double>>& centralityBins,
1153 const vector<tuple<size_t, size_t, size_t>>& ref) {
1154
1155 using RefT = typename ReferenceTraits<T>::RefT;
1156 using WrapT = MultiplexPtr<Multiplexer<T>>;
1157
1158 Percentile<T> pctl(this, projName);
1159
1160 const size_t nCent = centralityBins.size();
1161 for (size_t iCent = 0; iCent < nCent; ++iCent) {
1162 const string axisCode = mkAxisCode(std::get<0>(ref[iCent]),
1163 std::get<1>(ref[iCent]),
1164 std::get<2>(ref[iCent]));
1165 const RefT& refscatter = refData<RefT>(axisCode);
1166
1167 WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1168 wtf = addAnalysisObject(wtf);
1169
1170 CounterPtr cnt(_weightNames(), Counter(histoPath("TMP/COUNTER/" + axisCode)));
1171 cnt = addAnalysisObject(cnt);
1172
1173 pctl.add(wtf, cnt, centralityBins[iCent]);
1174 }
1175 return pctl;
1176 }
1177
1178
1179 // /// @brief Book Percentile Multiplexers around AnalysisObjects.
1180 // ///
1181 // /// Based on a previously registered CentralityProjection named @a
1182 // /// projName book one (or several) AnalysisObject(s) named
1183 // /// according to @a ref where the x-axis will be filled according
1184 // /// to the percentile output(s) of the @projName.
1185 // ///
1186 // /// @todo Convert to just be called book() cf. others
1187 // template <class T>
1188 // PercentileXaxis<T> bookPercentileXaxis(string projName,
1189 // tuple<int, int, int> ref) {
1190
1191 // typedef typename ReferenceTraits<T>::RefT RefT;
1192 // typedef MultiplexPtr<Multiplexer<T>> WrapT;
1193
1194 // PercentileXaxis<T> pctl(this, projName);
1195
1196 // const string axisCode = mkAxisCode(std::get<0>(ref),
1197 // std::get<1>(ref),
1198 // std::get<2>(ref));
1199 // const RefT & refscatter = refData<RefT>(axisCode);
1200
1201 // WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1202 // wtf = addAnalysisObject(wtf);
1203
1204 // CounterPtr cnt(_weightNames(), Counter());
1205 // cnt = addAnalysisObject(cnt);
1206
1207 // pctl.add(wtf, cnt);
1208 // return pctl;
1209 // }
1210
1212
1213
1214 private:
1215
1216 // Functions that have to be defined in the .cc file to avoid circular #includes
1217
1219 vector<string> _weightNames() const;
1220
1222 YODA::AnalysisObjectPtr _getPreload (const string& name) const;
1223
1225 MultiplexAOPtr _getOtherAnalysisObject(const std::string & ananame, const std::string& name);
1226
1228 void _checkBookInit() const;
1229
1231 bool _inInit() const;
1232
1234 bool _inFinalize() const;
1235
1237 template <typename YODAT>
1238 void _setWriterPrecision(const string& path, YODAT& yao) {
1239 const string re = _info->writerDoublePrecision();
1240 if (re != "") {
1241 std::smatch match;
1242 const bool needsDP = std::regex_search(path, match, std::regex(re));
1243 if (needsDP) yao.setAnnotation("WriterDoublePrecision", "1");
1244 }
1245 }
1246
1247
1248 private:
1249
1251 class CounterAdapter {
1252 public:
1253
1254 CounterAdapter(double x) : x_(x) {}
1255
1256 CounterAdapter(const YODA::Counter& c) : x_(c.val()) {}
1257
1258 CounterAdapter(const YODA::Estimate& e) : x_(e.val()) {}
1259
1260 CounterAdapter(const YODA::Scatter1D& s) : x_(s.points()[0].x()) {
1261 if (s.numPoints() != 1) throw RangeError("Can only scale by a single value.");
1262 }
1263
1264 operator double() const { return x_; }
1265
1266 private:
1267 double x_;
1268
1269 };
1270
1271
1272 public:
1273
1274 double dbl(double x) { return x; }
1275 double dbl(const YODA::Counter& c) { return c.val(); }
1276 double dbl(const YODA::Estimate0D& e) { return e.val(); }
1277 double dbl(const YODA::Scatter1D& s) {
1278 if ( s.numPoints() != 1 ) throw RangeError("Only scatter with single value supported.");
1279 return s.points()[0].x();
1280 }
1281
1282
1283 protected:
1284
1288
1290 template<typename T>
1291 void scale(MultiplexPtr<Multiplexer<T>>& ao, CounterAdapter factor) {
1292 if (!ao) {
1293 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1294 << name() << " (scale=" << double(factor) << ")");
1295 return;
1296 }
1297 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1298 MSG_WARNING("Failed to scale AnalysisObject=" << ao->path() << " in analysis: "
1299 << name() << " (invalid scale factor = " << double(factor) << ")");
1300 factor = 0;
1301 }
1302 MSG_TRACE("Scaling AnalysisObject " << ao->path() << " by factor " << double(factor));
1303 try {
1304 if constexpr( isFillable<T>::value ) {
1305 ao->scaleW(factor);
1306 }
1307 else {
1308 ao->scale(factor);
1309 }
1310 }
1311 catch (YODA::Exception& we) {
1312 MSG_WARNING("Could not scale AnalysisObject " << ao->path());
1313 return;
1314 }
1315 }
1316
1318 template<typename GroupAxisT, typename... AxisT>
1319 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, CounterAdapter factor) {
1320 if (!group) {
1321 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1322 << name() << " (scale=" << double(factor) << ")");
1323 return;
1324 }
1325 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1326 MSG_WARNING("Failed to scale histo group in analysis: "
1327 << name() << " (invalid scale factor = " << double(factor) << ")");
1328 factor = 0;
1329 }
1330 MSG_TRACE("Scaling histo group by factor " << double(factor));
1331 try {
1332 group->scaleW(factor);
1333 }
1334 catch (YODA::Exception& we) {
1335 MSG_WARNING("Could not scale histo group.");
1336 return;
1337 }
1338 }
1339
1341 template<typename GroupAxisT, typename... AxisT>
1342 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, const vector<double>& factors) {
1343 if (!group) {
1344 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis " << name());
1345 return;
1346 }
1347 if (group->numBins(true) != factors.size()) {
1348 throw RangeError(name() + ": Number of scale factors does not match group binning");
1349 return;
1350 }
1351 for (auto& b : group->bins(true)) {
1352 if (!b.get()) continue;
1353 double factor = factors[b.index()];
1354 if (std::isnan(factor) || std::isinf(factor)) {
1355 MSG_WARNING("Failed to scale componment of histo group in analysis: "
1356 << name() << " (invalid scale factor = " << factor << ")");
1357 factor = 0;
1358 }
1359 MSG_TRACE("Scaling histo group element by factor " << factor);
1360 try {
1361 b->scaleW(factor);
1362 }
1363 catch (YODA::Exception& we) {
1364 MSG_WARNING("Could not scale component of histo group.");
1365 }
1366 }
1367 }
1368
1370 void scale(CutflowsPtr& group, CounterAdapter factor) {
1371 if (!group) {
1372 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1373 << name() << " (scale=" << double(factor) << ")");
1374 return;
1375 }
1376 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1377 MSG_WARNING("Failed to scale histo group in analysis: "
1378 << name() << " (invalid scale factor = " << double(factor) << ")");
1379 factor = 0;
1380 }
1381 MSG_TRACE("Scaling histo group by factor " << double(factor));
1382 try {
1383 group->scale(factor);
1384 }
1385 catch (YODA::Exception& we) {
1386 MSG_WARNING("Could not scale histo group.");
1387 return;
1388 }
1389 }
1390
1392 template<typename T, typename U>
1393 void scale(std::map<T, U>& aos, CounterAdapter factor) {
1394 for (auto& item : aos) scale(item.second, factor);
1395 }
1396
1398 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1399 void scale(AORange& aos, CounterAdapter factor) {
1400 for (auto& ao : aos) scale(ao, factor);
1401 }
1402
1404 template <typename T>
1405 void scale(std::initializer_list<T> aos, CounterAdapter factor) {
1406 for (auto& ao : std::vector<T>{aos}) scale(ao, factor);
1407 }
1408
1410 template<typename T, typename U>
1411 void scale(std::map<T, U>& aos, const vector<double>& factors) {
1412 for (auto& item : aos) scale(item.second, factors);
1413 }
1414
1416 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1417 void scale(AORange& aos, const vector<double>& factors) {
1418 for (auto& ao : aos) scale(ao, factors);
1419 }
1420
1422 template <typename T>
1423 void scale(std::initializer_list<T> aos, const vector<double>& factors) {
1424 for (auto& ao : std::vector<T>{aos}) scale(ao, factors);
1425 }
1426
1428 template<typename GroupAxisT, typename... AxisT>
1429 void divByGroupWidth(HistoGroupPtr<GroupAxisT, AxisT...>& group) {
1430 if (!group) {
1431 MSG_WARNING("Failed to scale HistoGroup=NULL in analysis "
1432 << name() << " by group axis width");
1433 return;
1434 }
1435 group->divByGroupWidth();
1436 }
1437
1439 template<typename T, typename U>
1440 void divByGroupWidth(std::map<T, U>& aos) {
1441 for (auto& item : aos) divByGroupWidth(item.second);
1442 }
1443
1445 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1446 void divByGroupWidth(AORange& aos) {
1447 for (auto& ao : aos) divByGroupWidth(ao);
1448 }
1449
1451 template <typename T>
1452 void divByGroupWidth(std::initializer_list<T> aos) {
1453 for (auto& ao : std::vector<T>{aos}) divByGroupWidth(ao);
1454 }
1455
1456
1458 template <size_t DbnN, typename... AxisT>
1459 void normalize(BinnedDbnPtr<DbnN, AxisT...> ao, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1460 if (!ao) {
1461 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1462 return;
1463 }
1464 MSG_TRACE("Normalizing histo " << ao->path() << " to " << double(norm));
1465 try {
1466 const double hint = ao->integral(includeoverflows);
1467 if (hint == 0) MSG_DEBUG("Skipping histo with null area " << ao->path());
1468 else ao->normalize(norm, includeoverflows);
1469 }
1470 catch (YODA::Exception& we) {
1471 MSG_WARNING("Could not normalize histo " << ao->path());
1472 return;
1473 }
1474 }
1475
1477 template <typename GroupAxisT, typename... AxisT>
1478 void normalize(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1479 if (!group) {
1480 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1481 return;
1482 }
1483 MSG_TRACE("Normalizing histo group to " << double(norm));
1484 try {
1485 const double hint = group->integral(includeoverflows);
1486 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1487 else group->normalize(norm, includeoverflows);
1488 }
1489 catch (YODA::Exception& we) {
1490 MSG_WARNING("Could not normalize histo group.");
1491 return;
1492 }
1493 }
1494
1495
1497 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1498 void normalize(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1499 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1500 }
1501
1503 template<typename T>
1504 void normalize(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1505 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1506 }
1507
1509 template<typename T, typename U>
1510 void normalize(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1511 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1512 for (auto& item : aos) normalize(item.second, norm, includeoverflows);
1513 }
1514
1516 template <typename GroupAxisT, typename... AxisT>
1517 void normalizeGroup(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1518 if (!group) {
1519 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1520 return;
1521 }
1522 MSG_TRACE("Normalizing histo group to " << double(norm));
1523 try {
1524 const double hint = group->integral(includeoverflows);
1525 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1526 else group->normalizeGroup(norm, includeoverflows);
1527 }
1528 catch (YODA::Exception& we) {
1529 MSG_WARNING("Could not normalize histo group.");
1530 return;
1531 }
1532 }
1533
1535 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1536 void normalizeGroup(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1537 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1538 }
1539
1541 template<typename T>
1542 void normalizeGroup(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1543 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1544 }
1545
1547 template<typename T, typename U>
1548 void normalizeGroup(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1549 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1550 for (auto& item : aos) normalizeGroup(item.second, norm, includeoverflows);
1551 }
1552
1553
1558 template<size_t DbnN, typename... AxisT>
1559 void barchart(BinnedDbnPtr<DbnN, AxisT...> ao, BinnedEstimatePtr<AxisT...> est) const {
1560 const string path = est->path();
1561 *est = ao->mkEstimate(path, "stats", false); //< do NOT divide by bin area cf. a differential dsigma/dX histogram
1562 }
1563
1567 void divide(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const;
1568
1572 void divide(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const;
1573
1577 void divide(Estimate0DPtr e1, Estimate0DPtr e2, Estimate0DPtr est) const;
1578
1582 void divide(const YODA::Estimate0D& e1, const YODA::Estimate0D& e2, Estimate0DPtr est) const;
1583
1584
1588 template<size_t DbnN, typename... AxisT>
1589 void divide(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1590 BinnedEstimatePtr<AxisT...> est) const {
1591 const string path = est->path();
1592 *est = h1 / h2;
1593 est->setPath(path);
1594 }
1595 //
1596 template<size_t DbnN, typename... AxisT>
1597 void divide(BinnedDbnPtr<DbnN, AxisT...> h1, BinnedDbnPtr<DbnN, AxisT...> h2,
1598 BinnedEstimatePtr<AxisT...> est) const {
1599 return divide(*h1, *h2, est);
1600 }
1601
1605 template<typename... AxisT>
1606 void divide(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1607 BinnedEstimatePtr<AxisT...> est) const {
1608 const string path = est->path();
1609 *est = e1 / e2;
1610 est->setPath(path);
1611 }
1612 //
1613 template<typename... AxisT>
1614 void divide(BinnedEstimatePtr<AxisT...> e1, BinnedEstimatePtr<AxisT...> e2,
1615 BinnedEstimatePtr<AxisT...> est) const {
1616 return divide(*e1, *e2, est);
1617 }
1618
1619
1620
1624 void efficiency(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const {
1625 efficiency(*c1, *c2, est);
1626 }
1627
1631 void efficiency(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const {
1632 const string path = est->path();
1633 *est = YODA::efficiency(c1, c2);
1634 est->setPath(path);
1635 }
1636
1637
1638
1642 template<size_t DbnN, typename... AxisT>
1643 void efficiency(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1644 BinnedEstimatePtr<AxisT...> est) const {
1645 const string path = est->path();
1646 *est = YODA::efficiency(h1, h2);
1647 est->setPath(path);
1648 }
1649 //
1650 template<size_t DbnN, typename... AxisT>
1651 void efficiency(BinnedDbnPtr<DbnN, AxisT...> h1, BinnedDbnPtr<DbnN, AxisT...> h2,
1652 BinnedEstimatePtr<AxisT...> est) const {
1653 efficiency(*h1, *h2, est);
1654 }
1655
1656
1660 template<typename... AxisT>
1661 void efficiency(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1662 BinnedEstimatePtr<AxisT...> est) const {
1663 const string path = est->path();
1664 *est = YODA::efficiency(e1, e2);
1665 est->setPath(path);
1666 }
1667 //
1668 template<typename... AxisT>
1669 void efficiency(BinnedEstimatePtr<AxisT...> e1, BinnedEstimatePtr<AxisT...> e2,
1670 BinnedEstimatePtr<AxisT...> est) const {
1671 efficiency(*e1, *e2, est);
1672 }
1673
1674
1678 template<size_t DbnN, typename... AxisT>
1679 void asymm(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1680 BinnedEstimatePtr<AxisT...> est) const {
1681 const string path = est->path();
1682 *est = YODA::asymm(h1, h2);
1683 est->setPath(path);
1684 }
1685 //
1686 template<size_t DbnN, typename... AxisT>
1687 void asymm(BinnedDbnPtr<DbnN, AxisT...> h1, BinnedDbnPtr<DbnN, AxisT...> h2,
1688 BinnedEstimatePtr<AxisT...> est) const {
1689 asymm(*h1, *h2, est);
1690 }
1691
1695 template<typename... AxisT>
1696 void asymm(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1697 BinnedEstimatePtr<AxisT...> est) const {
1698 const string path = est->path();
1699 *est = YODA::asymm(e1, e2);
1700 est->setPath(path);
1701 }
1702 //
1703 template<typename... AxisT>
1704 void asymm(BinnedEstimatePtr<AxisT...> e1, BinnedEstimatePtr<AxisT...> e2,
1705 BinnedEstimatePtr<AxisT...> est) const {
1706 asymm(*e1, *e2, est);
1707 }
1708
1712 template<size_t DbnN, typename... AxisT>
1713 void integrate(const YODA::BinnedDbn<DbnN, AxisT...>& h, BinnedEstimatePtr<AxisT...> est) const {
1714 const string path = est->path();
1715 *est = mkIntegral(h);
1716 est->setPath(path);
1717 }
1718 //
1719 template<size_t DbnN, typename... AxisT>
1720 void integrate(BinnedDbnPtr<DbnN, AxisT...>& h, BinnedEstimatePtr<AxisT...> est) const {
1721 integrate(*h, est);
1722 }
1723
1725
1726
1727 public:
1728
1730 const vector<MultiplexAOPtr>& analysisObjects() const {
1731 return _analysisobjects;
1732 }
1733
1734
1735 protected:
1736
1739
1741 size_t defaultWeightIndex() const;
1742
1744 template <typename YODAT>
1745 shared_ptr<YODAT> getPreload(const string& path) const {
1746 return dynamic_pointer_cast<YODAT>(_getPreload(path));
1747 }
1748
1749
1751 template <typename YODAT>
1753 using MultiplexerT = Multiplexer<YODAT>;
1754 using YODAPtrT = shared_ptr<YODAT>;
1755 using RAOT = MultiplexPtr<MultiplexerT>;
1756
1757 if ( !_inInit() && !_inFinalize() ) {
1758 MSG_ERROR("Can't book objects outside of init() or finalize()");
1759 throw UserError(name() + ": Can't book objects outside of init() or finalize().");
1760 }
1761
1762 // First check that we haven't booked this before.
1763 // This is allowed when booking in finalize: just warn in that case.
1764 // If in init(), throw an exception: it's 99.9% never going to be intentional.
1765 for (auto& waold : analysisObjects()) {
1766 if ( yao.path() == waold.get()->basePath() ) {
1767 const string msg = "Found double-booking of " + yao.path() + " in " + name();
1768 if ( _inInit() ) {
1769 MSG_ERROR(msg);
1770 throw LookupError(msg);
1771 } else {
1772 MSG_WARNING(msg + ". Keeping previous booking");
1773 }
1774 return RAOT(dynamic_pointer_cast<MultiplexerT>(waold.get()));
1775 }
1776 }
1777
1778 shared_ptr<MultiplexerT> wao = make_shared<MultiplexerT>();
1779 wao->_basePath = yao.path();
1780 YODAPtrT yaop = make_shared<YODAT>(yao);
1781
1782 for (const string& weightname : _weightNames()) {
1783 // Create two YODA objects for each weight. Copy from
1784 // preloaded YODAs if present. First the finalized yoda:
1785 string finalpath = yao.path();
1786 if ( weightname != "" ) finalpath += "[" + weightname + "]";
1787 YODAPtrT preload = getPreload<YODAT>(finalpath);
1788 if ( preload ) {
1789 if ( !bookingCompatible(preload, yaop) ) {
1791 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1792 << finalpath << " for " << name());
1793 preload = nullptr;
1794 } else {
1795 MSG_TRACE("Using preloaded " << finalpath << " in " <<name());
1796 wao->_final.push_back(make_shared<YODAT>(*preload));
1797 }
1798 }
1799 else {
1800 wao->_final.push_back(make_shared<YODAT>(yao));
1801 wao->_final.back()->setPath(finalpath);
1802 }
1803
1804 // Then the raw filling yodas.
1805 string rawpath = "/RAW" + finalpath;
1806 preload = getPreload<YODAT>(rawpath);
1807 if ( preload ) {
1808 if ( !bookingCompatible(preload, yaop) ) {
1809 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1810 << rawpath << " for " << name());
1811 preload = nullptr;
1812 } else {
1813 MSG_TRACE("Using preloaded " << rawpath << " in " <<name());
1814 wao->_persistent.push_back(make_shared<YODAT>(*preload));
1815 }
1816 }
1817 else {
1818 wao->_persistent.push_back(make_shared<YODAT>(yao));
1819 wao->_persistent.back()->setPath(rawpath);
1820 }
1821 }
1823
1824 ret.get()->unsetActiveWeight();
1825 if ( _inFinalize() ) {
1826 // If booked in finalize() we assume it is the first time
1827 // finalize is run.
1828 ret.get()->pushToFinal();
1829 ret.get()->setActiveFinalWeightIdx(0);
1830 }
1831 _analysisobjects.push_back(ret);
1832
1833 return ret;
1834 }
1835
1836
1838 template <typename AO=MultiplexAOPtr>
1839 AO addAnalysisObject(const AO& aonew) {
1840 _checkBookInit();
1841
1842 for (const MultiplexAOPtr& ao : analysisObjects()) {
1843
1844 // Check AO base-name first
1845 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1846 aonew.get()->setActiveWeightIdx(defaultWeightIndex());
1847 if (ao->path() != aonew->path()) continue;
1848
1849 // If base-name matches, check compatibility
1850 // NB. This evil is because dynamic_ptr_cast can't work on MultiplexPtr directly
1851 AO aoold = AO(dynamic_pointer_cast<typename AO::value_type>(ao.get())); //< OMG
1852 if ( !aoold || !bookingCompatible(aonew, aoold) ) {
1853 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1854 << aonew->path() << " for " << name());
1855 throw LookupError("Found incompatible pre-existing data object with same base path during AO booking");
1856 }
1857
1858 // Finally, check all weight variations
1859 for (size_t weightIdx = 0; weightIdx < _weightNames().size(); ++weightIdx) {
1860 aoold.get()->setActiveWeightIdx(weightIdx);
1861 aonew.get()->setActiveWeightIdx(weightIdx);
1862 if (aoold->path() != aonew->path()) {
1863 MSG_WARNING("Found incompatible pre-existing data object with different weight-path "
1864 << aonew->path() << " for " << name());
1865 throw LookupError("Found incompatible pre-existing data object with same weight-path during AO booking");
1866 }
1867 }
1868
1869 // They're fully compatible: bind and return
1870 aoold.get()->unsetActiveWeight();
1871 MSG_TRACE("Bound pre-existing data object " << aoold->path() << " for " << name());
1872 return aoold;
1873 }
1874
1875 // No equivalent found
1876 MSG_TRACE("Registered " << aonew->annotation("Type") << " " << aonew->path() << " for " << name());
1877 aonew.get()->unsetActiveWeight();
1878
1879 _analysisobjects.push_back(aonew);
1880 return aonew;
1881 }
1882
1884 void removeAnalysisObject(const std::string& path);
1885
1887 void removeAnalysisObject(const MultiplexAOPtr& ao);
1888
1890 template <typename AO=MultiplexAOPtr>
1891 const AO getAnalysisObject(const std::string& aoname) const {
1892 for (const MultiplexAOPtr& ao : analysisObjects()) {
1893 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1894 if (ao->path() == histoPath(aoname)) {
1895 // return dynamic_pointer_cast<AO>(ao);
1896 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1897 }
1898 }
1899 throw LookupError("Data object " + histoPath(aoname) + " not found");
1900 }
1901
1902
1903 // /// Get a data object from the histogram system
1904 // template <typename AO=YODA::AnalysisObject>
1905 // const std::shared_ptr<AO> getAnalysisObject(const std::string& name) const {
1906 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1907 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1908 // }
1909 // throw LookupError("Data object " + histoPath(name) + " not found");
1910 // }
1911
1912 // /// Get a data object from the histogram system (non-const)
1913 // template <typename AO=YODA::AnalysisObject>
1914 // std::shared_ptr<AO> getAnalysisObject(const std::string& name) {
1915 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1916 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1917 // }
1918 // throw LookupError("Data object " + histoPath(name) + " not found");
1919 // }
1920
1921
1924 template <typename AO=MultiplexAOPtr>
1925 AO getAnalysisObject(const std::string& ananame,
1926 const std::string& aoname) {
1927 MultiplexAOPtr ao = _getOtherAnalysisObject(ananame, aoname);
1928 // return dynamic_pointer_cast<AO>(ao);
1929 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1930 }
1931
1933
1936
1938 template <
1939 typename... Args, typename CONTAINER,
1940 typename = std::enable_if_t<
1941 is_citerable_v<CONTAINER>,
1942 Jet
1943 >
1944 >
1945 static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args&&... args){
1946 return FastJets::reclusterJets(jetsIn, std::forward<Args>(args)...);
1947 }
1948
1949 template <typename T, typename U, typename... Args>
1950 static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
1951 return FastJets::reclusterJets(jetsMap, std::forward<Args>(args)...);
1952 }
1953
1954 template <
1955 JetAlg JETALG, typename... Args, typename CONTAINER,
1956 typename = std::enable_if_t<
1957 is_citerable_v<CONTAINER>,
1958 Jet
1959 >
1960 >
1961 static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args&&... args){
1962 return FastJets::reclusterJets<JETALG>(jetsIn, std::forward<Args>(args)...);
1963 }
1964
1965 template <JetAlg JETALG, typename T, typename U, typename... Args>
1966 static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
1967 return FastJets::reclusterJets<JETALG>(jetsMap, std::forward<Args>(args)...);
1968 }
1969
1971
1972
1973 private:
1974
1976 string _defaultname;
1977
1979 unique_ptr<AnalysisInfo> _info;
1980
1983 vector<MultiplexAOPtr> _analysisobjects;
1984
1987 double _crossSection;
1988 bool _gotCrossSection;
1990
1992 AnalysisHandler* _analysishandler;
1993
1995 const Event* _currentevent = nullptr;
1996
1999 mutable std::map<std::string, YODA::AnalysisObjectPtr> _refdata;
2000
2002 map<string, string> _options;
2003
2005 string _optstring;
2006
2007
2008 private:
2009
2012
2014 void _cacheRefData() const;
2015
2017
2018 };
2019
2020
2021 // // Template specialisation for literal character strings (which don't play well with stringstream)
2022 // template<>
2023 // inline std::string Analysis::getOption(std::string optname, const char* def) {
2024 // return getOption<std::string>(optname, def); //.c_str();
2025 // }
2026
2027
2028}
2029
2030
2031// Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
2032#include "Rivet/AnalysisBuilder.hh"
2033
2034
2037
2040#define RIVET_DECLARE_PLUGIN(clsname) ::Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
2041
2044#define RIVET_DECLARE_ALIASED_PLUGIN(clsname, alias) RIVET_DECLARE_PLUGIN(clsname)( #alias )
2045
2048#define RIVET_DEFAULT_ANALYSIS_CTOR(clsname) clsname() : Analysis(# clsname) {}
2049
2052#define RIVET_REGISTER_TYPE(...) handler().registerType<__VA_ARGS__>()
2053
2056#define RIVET_REGISTER_BINNED_SET(...) { \
2057 RIVET_REGISTER_TYPE(YODA::BinnedHisto<__VA_ARGS__>); \
2058 RIVET_REGISTER_TYPE(YODA::BinnedProfile<__VA_ARGS__>); \
2059 RIVET_REGISTER_TYPE(YODA::BinnedEstimate<__VA_ARGS__>); }
2060
2062
2063
2064#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
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:1067
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:705
virtual std::string status() const
Whether this analysis is trusted (in any way!).
Definition Analysis.hh:264
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:284
shared_ptr< YODAT > getPreload(const string &path) const
Get a preloaded YODA object.
Definition Analysis.hh:1745
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:171
void scale(std::initializer_list< T > aos, CounterAdapter factor)
Iteratively scale the AOs in the initialiser list aos, by factor factor.
Definition Analysis.hh:1405
virtual std::string collider() const
Collider on which the experiment ran.
Definition Analysis.hh:228
MultiplexPtr< Multiplexer< YODAT > > registerAO(const YODAT &yao)
Register a new data object, optionally read in preloaded data.
Definition Analysis.hh:1752
virtual double luminosityfb() const
The integrated luminosity in inverse femtobarn.
Definition Analysis.hh:238
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:1151
const AnalysisInfo & info() const
Get the actual AnalysisInfo object in which all this metadata is stored.
Definition Analysis.hh:151
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:1498
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:1510
void efficiency(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const
Definition Analysis.hh:1624
virtual const std::vector< std::string > & keywords() const
Get vector of analysis keywords.
Definition Analysis.hh:289
virtual double luminosity() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:242
virtual std::string spiresID() const
Get the SPIRES ID code for this analysis (~deprecated).
Definition Analysis.hh:182
virtual std::string writerDoublePrecision() const
Positive filtering regex for setting double precision in Writer.
Definition Analysis.hh:304
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:1631
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:691
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:858
virtual Analysis & setRequiredBeamIDs(const std::vector< PdgIdPair > &beamids)
Declare the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:313
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:799
AO getAnalysisObject(const std::string &ananame, const std::string &aoname)
Definition Analysis.hh:1925
void barchart(BinnedDbnPtr< DbnN, AxisT... > ao, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1559
AnalysisInfo & info()
Get the actual AnalysisInfo object in which all this metadata is stored (non-const).
Definition Analysis.hh:346
virtual std::string runInfo() const
Information about the events needed as input for this analysis.
Definition Analysis.hh:218
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:1399
virtual std::string year() const
When the original experimental analysis was published.
Definition Analysis.hh:233
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:1079
virtual void setRefDataName(const std::string &ref_data="")
Set name of reference data file, which could be different from plugin name.
Definition Analysis.hh:338
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:1730
double crossSectionPerEvent() const
virtual std::string summary() const
Get a short description of the analysis.
Definition Analysis.hh:199
void scale(AORange &aos, const vector< double > &factors)
Iteratively scale the AOs in the iterable aos, by factors factors.
Definition Analysis.hh:1417
virtual std::string description() const
Get a full description of the analysis.
Definition Analysis.hh:209
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:1411
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:1057
virtual std::vector< std::string > validation() const
make-style commands for validating this analysis.
Definition Analysis.hh:279
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:1542
virtual std::vector< std::string > authors() const
Names & emails of paper/analysis authors.
Definition Analysis.hh:190
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, const vector< double > &factors)
Multiplicatively scale the given histogram group, group, by factors factors.
Definition Analysis.hh:1342
void asymm(const YODA::BinnedEstimate< AxisT... > &e1, const YODA::BinnedEstimate< AxisT... > &e2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1696
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:323
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:1536
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:1446
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:810
virtual std::string refFile() const
Location of reference data YODA file.
Definition Analysis.hh:330
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:1517
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:1643
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:673
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:895
virtual std::vector< std::string > references() const
Journal, and preprint references.
Definition Analysis.hh:249
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:274
virtual std::string inspireID() const
Get the Inspire ID code for this analysis.
Definition Analysis.hh:177
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, CounterAdapter factor)
Multiplicatively scale the given histogram group, group, by factor factor.
Definition Analysis.hh:1319
bool merging() const
Check if we are running rivet-merge.
Definition Analysis.hh:358
void divByGroupWidth(std::initializer_list< T > aos)
Iteratively scale the HistoGroups in the initialiser list aos, by the group axis width.
Definition Analysis.hh:1452
void divide(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1589
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:427
virtual const std::vector< PdgIdPair > & requiredBeamIDs() const
Return the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:309
virtual std::string refUnmatch() const
Negative filtering regex for ref-data HepData sync.
Definition Analysis.hh:299
const std::map< std::string, std::string > & options() const
Return the map of all options given to this analysis.
Definition Analysis.hh:1052
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:1105
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:1291
void scale(CutflowsPtr &group, CounterAdapter factor)
Multiplicatively scale the cutflow group, group, by factor factor.
Definition Analysis.hh:1370
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:884
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:294
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:1548
double luminositypb() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:246
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:1606
void integrate(const YODA::BinnedDbn< DbnN, AxisT... > &h, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1713
const T & refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Definition Analysis.hh:568
virtual std::string warning() const
A warning message from the info file, if there is one.
Definition Analysis.hh:269
AnalysisHandler & handler() const
Access the controlling AnalysisHandler object.
Definition Analysis.hh:424
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:1429
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:1504
bool hasRefData(const string &hname) const
Check if reference data object exists for a specific histo name.
Definition Analysis.hh:534
double sumOfWeights() const
Alias.
Definition Analysis.hh:467
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:758
const AO getAnalysisObject(const std::string &aoname) const
Get a Rivet data object from the histogram system.
Definition Analysis.hh:1891
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:972
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:935
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:528
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:1661
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:713
void asymm(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1679
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:835
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:254
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:259
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:684
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:549
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:612
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:334
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:817
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:1459
virtual std::string name() const
Get the name of the analysis.
Definition Analysis.hh:163
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:1423
void divByGroupWidth(std::map< T, U > &aos)
Iteratively scale the HistoGroups in the map aos, by the group axis width.
Definition Analysis.hh:1440
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:223
void scale(std::map< T, U > &aos, CounterAdapter factor)
Iteratively scale the AOs in the map aos, by factor factor.
Definition Analysis.hh:1393
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:1478
virtual const std::vector< std::pair< double, double > > & requiredBeamEnergies() const
Sets of valid beam energy pairs, in GeV.
Definition Analysis.hh:319
AO addAnalysisObject(const AO &aonew)
Register a data object in the histogram system.
Definition Analysis.hh:1839
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:540
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
Representation of a clustered jet of particles.
Definition Jet.hh:42
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
Definition RivetYODA.hh:1296
shared_ptr< T > get() const
Get the internal shared ptr.
Definition RivetYODA.hh:1384
Type-specific multiplexed YODA analysis object.
Definition RivetYODA.hh:982
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
void markAsOwned() const
Mark this object as owned by a proj-handler.
Definition ProjectionApplier.hh:140
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:998
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:990
static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args &&... args)
Avoid FastJet:: scoping prefix.
Definition Analysis.hh:1945
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 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:1507
static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::JetDefinition &jDef)
Recluster Rivet::Jets.
Definition FastJets.hh:291
#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
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:653
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:157
Definition MC_CENT_PPB_Projections.hh:10
std::shared_ptr< Cutflows > CutflowsPtr
Convenience alias.
Definition Cutflow.hh:499
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
MultiplexPtr< Multiplexer< Cutflow > > CutflowPtr
Convenience alias.
Definition Cutflow.hh:262
Generic runtime Rivet error.
Definition Exceptions.hh:12
Error relating to looking up analysis objects in the register.
Definition Exceptions.hh:73
Error for e.g. use of invalid bin ranges.
Definition Exceptions.hh:22
Error for read failures.
Definition Exceptions.hh:90
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:67