rivet is hosted by Hepforge, IPPP Durham
Rivet 4.1.0
Analysis.hh
1// -*- C++ -*-
2#ifndef RIVET_Analysis_HH
3#define RIVET_Analysis_HH
4
5#include "Rivet/Config/RivetCommon.hh"
6#include "Rivet/AnalysisInfo.hh"
7#include "Rivet/Event.hh"
8#include "Rivet/Projection.hh"
9#include "Rivet/ProjectionApplier.hh"
10#include "Rivet/ProjectionHandler.hh"
11#include "Rivet/AnalysisLoader.hh"
12#include "Rivet/Tools/Cuts.hh"
13#include "Rivet/Tools/Logging.hh"
14#include "Rivet/Tools/ParticleUtils.hh"
15#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
34
35namespace Rivet {
36
37
38 // Convenience for analysis writers
39 using std::cout;
40 using std::cerr;
41 using std::endl;
42 using std::tuple;
43 using std::stringstream;
44 using std::swap;
45 using std::numeric_limits;
46
47
48 // Forward declaration
49 class AnalysisHandler;
50
51
70 class Analysis : public ProjectionApplier {
71 public:
72
74 friend class AnalysisHandler;
75
76
78 Analysis(const std::string& name);
79
81 virtual ~Analysis() {}
82
84 Analysis& operator = (const Analysis&) = delete;
85
86
87 public:
88
91
95 virtual void init() { }
96
101 virtual void analyze(const Event& event) = 0;
102
108 virtual void finalize() { }
109
111
112
115
117 virtual void preInit() { }
119 virtual void postInit() { }
121 virtual void preAnalyze(const Event&) { }
123 virtual void postAnalyze(const Event&) { }
125 virtual void preFinalize() { }
127 virtual void postFinalize() { }
128
133 this->_syncDeclQueue();
134 this->markAsOwned();
135 }
136
138
139
140 public:
141
147
149 void loadInfo() { info().parseInfoFile(); }
150
152 const AnalysisInfo& info() const {
153 if (!_info) throw Error("No AnalysisInfo object :-O");
154 return *_info;
155 }
156
164 virtual std::string name() const {
165 return ( (info().name().empty()) ? _defaultname : info().name() ) + _optstring;
166 }
167
172 std::string analysisDataPath(const std::string& extn, const std::string& suffix="") {
173 string filename = name() + (suffix.empty() ? "" : "-") + suffix + "." + extn;
174 return findAnalysisDataFile(filename);
175 }
176
178 virtual std::string inspireID() const {
179 return info().inspireID();
180 }
181
183 virtual std::string spiresID() const {
184 return info().spiresID();
185 }
186
191 virtual std::vector<std::string> authors() const {
192 return info().authors();
193 }
194
200 virtual std::string summary() const {
201 return info().summary();
202 }
203
210 virtual std::string description() const {
211 return info().description();
212 }
213
219 virtual std::string runInfo() const {
220 return info().runInfo();
221 }
222
224 virtual std::string experiment() const {
225 return info().experiment();
226 }
227
229 virtual std::string collider() const {
230 return info().collider();
231 }
232
234 virtual std::string year() const {
235 return info().year();
236 }
237
239 virtual double luminosityfb() const {
240 return info().luminosityfb();
241 }
243 virtual double luminosity() const {
244 return info().luminosity();
245 }
247 double luminositypb() const { return luminosity(); }
248
250 virtual std::vector<std::string> references() const {
251 return info().references();
252 }
253
255 virtual std::string bibKey() const {
256 return info().bibKey();
257 }
258
260 virtual std::string bibTeX() const {
261 return info().bibTeX();
262 }
263
265 virtual std::string status() const {
266 return (info().status().empty()) ? "UNVALIDATED" : info().status();
267 }
268
270 virtual std::string warning() const {
271 return info().warning();
272 }
273
275 virtual std::vector<std::string> todos() const {
276 return info().todos();
277 }
278
280 virtual std::vector<std::string> validation() const {
281 return info().validation();
282 }
283
285 virtual bool reentrant() const {
286 return info().reentrant();
287 }
288
290 virtual const std::vector<std::string>& keywords() const {
291 return info().keywords();
292 }
293
295 virtual std::string refMatch() const {
296 return info().refMatch();
297 }
298
300 virtual std::string refUnmatch() const {
301 return info().refUnmatch();
302 }
303
305 virtual std::string writerDoublePrecision() const {
306 return info().writerDoublePrecision();
307 }
308
310 virtual const std::vector<PdgIdPair>& requiredBeamIDs() const {
311 return info().beamIDs();
312 }
314 virtual Analysis& setRequiredBeamIDs(const std::vector<PdgIdPair>& beamids) {
315 info().setBeamIDs(beamids);
316 return *this;
317 }
318
320 virtual const std::vector<std::pair<double, double> >& requiredBeamEnergies() const {
321 return info().energies();
322 }
324 virtual Analysis& setRequiredBeamEnergies(const std::vector<std::pair<double, double> >& energies) {
325 info().setEnergies(energies);
326 return *this;
327 }
328
329
331 virtual std::string refFile() const {
332 return info().refFile();
333 }
335 virtual std::string refDataName() const {
336 return (info().getRefDataName().empty()) ? _defaultname : info().getRefDataName();
337 }
339 virtual void setRefDataName(const std::string& ref_data="") {
340 info().setRefDataName(!ref_data.empty() ? ref_data : name());
341 }
342
343
348 if (!_info) throw Error("No AnalysisInfo object :-O");
349 return *_info;
350 }
351
353
354
357
359 bool merging() const {
360 return sqrtS() <= 0.0;
361 }
362
364 bool compatibleWithRun() const;
365
367
368
372
374 const ParticlePair& beams() const;
375
377 PdgIdPair beamIDs() const;
378
380 pair<double,double> beamEnergies() const;
381
383 vector<double> allowedEnergies() const;
384
386 double sqrtS() const;
387
389 bool beamsMatch(const ParticlePair& beams) const;
390
392 bool beamsMatch(PdgId beam1, PdgId beam2, double e1, double e2) const;
393
395 bool beamsMatch(const PdgIdPair& beams, const std::pair<double,double>& energies) const;
396
398 bool beamIDsMatch(PdgId beam1, PdgId beam2) const;
399
401 bool beamIDsMatch(const PdgIdPair& beamids) const;
402
404 bool beamEnergiesMatch(double e1, double e2) const;
405
407 bool beamEnergiesMatch(const std::pair<double,double>& energies) const;
408
410 bool beamEnergyMatch(const std::pair<double,double>& energies) const;
411
413 bool beamEnergyMatch(double sqrts) const;
414
416 bool isCompatibleWithSqrtS(double energy, double tolerance=1e-5) const;
417
419
420
422 AnalysisHandler& handler() const { return *_analysishandler; }
423
425 const Event& currentEvent() const {
426 if (!_currentevent) throw Error("No current event set: did you try to access it in init() or finalize()?");
427 return *_currentevent;
428 }
429
430
431 protected:
432
434 Log& getLog() const;
435
437 double crossSection() const;
438
441 double crossSectionPerEvent() const;
442
444 double crossSectionError() const;
445
449
453 size_t numEvents() const;
454
458 double sumW() const;
460 double sumOfWeights() const { return sumW(); }
461
465 double sumW2() const;
466
467
468 protected:
469
475
477 const std::string histoDir() const;
478
480 const std::string histoPath(const std::string& hname) const;
481
483 const std::string histoPath(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
484
486 const std::string mkAxisCode(unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID) const;
487
489
490
491 #ifdef HAVE_H5
494
496 H5::File auxFile() const {
497 return H5::readFile(name()+".h5");
498 }
499
501 template <typename T>
502 bool auxData(const string& dsname, T& rtndata) {
504 return H5::readData(name()+".h5", dsname, rtndata);
505 }
506
507 template <typename T>
508 T auxData(const string& dsname) {
510 return H5::readData<T>(name()+".h5", dsname);
511 }
512
514 #endif
515
516
519
521 const std::map<std::string, YODA::AnalysisObjectPtr>& refData() const {
522 _cacheRefData();
523 return _refdata;
524 }
525
526
529 template <typename T=YODA::Estimate1D>
530 const T& refData(const string& hname) const {
531 _cacheRefData();
532 MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
533 if (!_refdata[hname]) {
534 MSG_ERROR("Can't find reference histogram " << hname);
535 throw Exception("Reference data " + hname + " not found.");
536 }
537 try {
538 return dynamic_cast<T&>(*_refdata[hname]);
539 } catch (...) {
540 throw Exception("Expected type " + _refdata[hname]->type()+" for reference data \"" + hname + "\".\n");
541 }
542 }
543
544
547 template <typename T=YODA::Estimate1D>
548 const T& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
549 const string hname = mkAxisCode(datasetId, xAxisId, yAxisId);
550 return refData<T>(hname);
551 }
552
554
555
561
563 CounterPtr& book(CounterPtr&, const std::string& name);
564
568 CounterPtr& book(CounterPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
569
571
572
575
577 Estimate0DPtr& book(Estimate0DPtr&, const std::string& name);
578
582 Estimate0DPtr& book(Estimate0DPtr&, unsigned int datasetID, unsigned int xAxisID, unsigned int yAxisID);
583
584
586
589
591 template<size_t DbnN, typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
593 const std::string& name, const std::vector<size_t>& nbins,
594 const std::vector<std::pair<double,double>>& loUpPairs) {
595 if (nbins.size() != loUpPairs.size()) {
596 throw RangeError("Vectors should have the same size!");
597 }
598 const string path = histoPath(name);
599
600 YODA::BinnedDbn<DbnN, AxisT...> yao(nbins, loUpPairs, path);
601 _setWriterPrecision(path, yao);
602
603 return ao = registerAO(yao);
604 }
605
606 // Specialiation for 1D
607 Histo1DPtr& book(Histo1DPtr& ao, const std::string& name,
608 const size_t nbins, const double lower, const double upper) {
609 return book(ao, name, vector<size_t>{nbins},
610 vector<pair<double,double>>{{lower,upper}});
611 }
612 //
613 Profile1DPtr& book(Profile1DPtr& ao, const std::string& name,
614 const size_t nbins, const double lower, const double upper) {
615 return book(ao, name, vector<size_t>{nbins},
616 vector<pair<double,double>>{{lower,upper}});
617 }
618
619 // Specialiation for 2D
620 Histo2DPtr& book(Histo2DPtr& ao, const std::string& name,
621 const size_t nbinsX, const double lowerX, const double upperX,
622 const size_t nbinsY, const double lowerY, const double upperY) {
623 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
624 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
625 }
626 //
627 Profile2DPtr& book(Profile2DPtr& ao, const std::string& name,
628 const size_t nbinsX, const double lowerX, const double upperX,
629 const size_t nbinsY, const double lowerY, const double upperY) {
630 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
631 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
632 }
633
634 // Specialiation for 3D
635 Histo3DPtr& book(Histo3DPtr& ao, const std::string& name,
636 const size_t nbinsX, const double lowerX, const double upperX,
637 const size_t nbinsY, const double lowerY, const double upperY,
638 const size_t nbinsZ, const double lowerZ, const double upperZ) {
639 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
640 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
641 }
642 //
643 Profile3DPtr& book(Profile3DPtr& ao, const std::string& name,
644 const size_t nbinsX, const double lowerX, const double upperX,
645 const size_t nbinsY, const double lowerY, const double upperY,
646 const size_t nbinsZ, const double lowerZ, const double upperZ) {
647 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
648 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
649 }
650
652 template<size_t DbnN, typename... AxisT>
653 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
654 const std::vector<AxisT>&... binedges) {
655 const string path = histoPath(name);
656 YODA::BinnedDbn<DbnN, AxisT...> yao(binedges..., path);
657 _setWriterPrecision(path, yao);
658
659 return ao = registerAO(yao);
660 }
661
663 template<size_t DbnN, typename... AxisT>
664 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
665 const std::initializer_list<AxisT>&... binedges) {
666 return book(ao, name, vector<AxisT>{binedges} ...);
667 }
668
670 template<size_t DbnN, typename... AxisT>
671 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name,
672 const YODA::BinnedEstimate<AxisT...>& refest) {
673 const string path = histoPath(name);
674
675 YODA::BinnedDbn<DbnN, AxisT...> yao(refest.binning(), path);
676 for (const string& a : yao.annotations()) {
677 if (a != "Path") yao.rmAnnotation(a);
678 }
679 _setWriterPrecision(path, yao);
680 return ao = registerAO(yao);
681 }
682
684 template<size_t DbnN, typename... AxisT>
685 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const std::string& name) {
686 return book(ao, name, refData<YODA::BinnedEstimate<AxisT...>>(name));
687 }
688
692 template<size_t DbnN, typename... AxisT>
693 BinnedDbnPtr<DbnN, AxisT...>& book(BinnedDbnPtr<DbnN, AxisT...>& ao, const unsigned int datasetID,
694 const unsigned int xAxisID, const unsigned int yAxisID) {
695 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
696 return book(ao, name);
697 }
698
700
703
704 template <typename GroupAxisT, typename... AxisT>
705 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
706 const std::vector<GroupAxisT>& edges,
707 const std::vector<std::string>& names) {
708 ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
709 if (ao->numBins() != names.size()) {
710 throw RangeError("Binning and reference-data names don't match!");
711 }
712 for (auto& b : ao->bins()) {
713 const string& refname = names[b.index()-1];
714 book(b, refname, refData<YODA::BinnedEstimate<AxisT...>>(refname));
715 }
716 return ao;
717 }
718
719 template <typename GroupAxisT, typename... AxisT>
720 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
721 const std::vector<GroupAxisT>& edges) {
722 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(edges);
723 }
724
725 template <typename GroupAxisT, typename... AxisT>
726 HistoGroupPtr<GroupAxisT, AxisT...>& book(HistoGroupPtr<GroupAxisT, AxisT...>& ao,
727 std::initializer_list<GroupAxisT>&& edges) {
728 return ao = make_shared<HistoGroup<GroupAxisT, AxisT...>>(std::move(edges));
729 }
730
732
735
737 template<typename... AxisT, typename = YODA::enable_if_all_CAxisT<AxisT...>>
739 const std::string& name, const std::vector<size_t>& nbins,
740 const std::vector<std::pair<double,double>>& loUpPairs) {
741 if (nbins.size() != loUpPairs.size()) {
742 throw RangeError("Vectors should have the same size!");
743 }
744 const string path = histoPath(name);
745
746 YODA::BinnedEstimate<AxisT...> yao(nbins, loUpPairs, path);
747 _setWriterPrecision(path, yao);
748
749 return ao = registerAO(yao);
750 }
751
752
753 // Specialiation for 1D
754 Estimate1DPtr& book(Estimate1DPtr& ao, const std::string& name,
755 const size_t nbins, const double lower, const double upper) {
756 return book(ao, name, vector<size_t>{nbins},
757 vector<pair<double,double>>{{lower,upper}});
758 }
759
760 // Specialiation for 2D
761 Estimate2DPtr& book(Estimate2DPtr& ao, const std::string& name,
762 const size_t nbinsX, const double lowerX, const double upperX,
763 const size_t nbinsY, const double lowerY, const double upperY) {
764 return book(ao, name, vector<size_t>{nbinsX,nbinsY},
765 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}});
766 }
767
768 // Specialiation for 3D
769 Estimate3DPtr& book(Estimate3DPtr& ao, const std::string& name,
770 const size_t nbinsX, const double lowerX, const double upperX,
771 const size_t nbinsY, const double lowerY, const double upperY,
772 const size_t nbinsZ, const double lowerZ, const double upperZ) {
773 return book(ao, name, vector<size_t>{nbinsX,nbinsY,nbinsZ},
774 vector<pair<double,double>>{{lowerX,upperX}, {lowerY,upperY}, {lowerZ,upperZ}});
775 }
776
778 template<typename... AxisT>
779 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
780 const std::vector<AxisT>&... binedges) {
781 const string path = histoPath(name);
782 YODA::BinnedEstimate<AxisT...> yao(binedges..., path);
783 _setWriterPrecision(path, yao);
784
785 return ao = registerAO(yao);
786 }
787
789 template<typename... AxisT>
790 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name,
791 const std::initializer_list<AxisT>&... binedges) {
792 return book(ao, name, vector<AxisT>{binedges} ...);
793 }
794
796 template<typename... AxisT>
797 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const std::string& name) {
798
799 const string path = histoPath(name);
800 YODA::BinnedEstimate<AxisT...> yao;
801 try {
802 yao = YODA::BinnedEstimate<AxisT...>(refData<YODA::BinnedEstimate<AxisT...>>(name).binning());
803 } catch (...) {
804 MSG_DEBUG("Couldn't retrieve reference binning, continue with nullary AO constructor.");
805 }
806 yao.setPath(path);
807 _setWriterPrecision(path, yao);
808 return ao = registerAO(yao);
809 }
810
814 template<typename... AxisT>
815 BinnedEstimatePtr<AxisT...>& book(BinnedEstimatePtr<AxisT...>& ao, const unsigned int datasetID,
816 const unsigned int xAxisID, const unsigned int yAxisID) {
817 const string name = mkAxisCode(datasetID, xAxisID, yAxisID);
818 return book(ao, name);
819 }
820
822
823
826
837 template<size_t N>
838 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const bool copy_pts = false) {
839 const string path = histoPath(name);
840 YODA::ScatterND<N> scat(path);
841 if (copy_pts) {
842 const YODA::ScatterND<N> ref = refData<YODA::EstimateND<N-1>>(name).mkScatter();
843 for (YODA::PointND<N> p : ref.points()) {
844 p.setVal(N-1, 0.0);
845 p.setErr(N-1, 0.0);
846 scat.addPoint(std::move(p));
847 }
848 }
849 _setWriterPrecision(path, scat);
850 return snd = registerAO(scat);
851 }
852
863 template<size_t N>
864 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const unsigned int datasetID, const unsigned int xAxisID,
865 const unsigned int yAxisID, const bool copy_pts = false) {
866 const string axisCode = mkAxisCode(datasetID, xAxisID, yAxisID);
867 return book(snd, axisCode, copy_pts);
868 }
869
875 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
876 const size_t npts, const double lower, const double upper) {
877 const string path = histoPath(name);
878
879 Scatter2D scat(path);
880 const double binwidth = (upper-lower)/npts;
881 for (size_t pt = 0; pt < npts; ++pt) {
882 const double bincentre = lower + (pt + 0.5) * binwidth;
883 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
884 }
885 _setWriterPrecision(path, scat);
886
887 return snd = registerAO(scat);
888 }
889 //
890 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
891 const size_t nptsX, const double lowerX, const double upperX,
892 const size_t nptsY, const double lowerY, const double upperY) {
893 const string path = histoPath(name);
894
895 Scatter3D scat(path);
896 const double xbinwidth = (upperX-lowerX)/nptsX;
897 const double ybinwidth = (upperY-lowerY)/nptsY;
898 for (size_t xpt = 0; xpt < nptsX; ++xpt) {
899 const double xbincentre = lowerX + (xpt + 0.5) * xbinwidth;
900 for (size_t ypt = 0; ypt < nptsY; ++ypt) {
901 const double ybincentre = lowerY + (ypt + 0.5) * ybinwidth;
902 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
903 }
904 }
905 _setWriterPrecision(path, scat);
906
907 return snd = registerAO(scat);
908 }
909
915 Scatter2DPtr& book(Scatter2DPtr& snd, const string& name,
916 const std::vector<double>& binedges) {
917 const string path = histoPath(name);
918
919 Scatter2D scat(path);
920 for (size_t pt = 0; pt < binedges.size()-1; ++pt) {
921 const double bincentre = (binedges[pt] + binedges[pt+1]) / 2.0;
922 const double binwidth = binedges[pt+1] - binedges[pt];
923 scat.addPoint(bincentre, 0, binwidth/2.0, 0);
924 }
925 _setWriterPrecision(path, scat);
926
927 return snd = registerAO(scat);
928 }
929 //
930 Scatter3DPtr& book(Scatter3DPtr& snd, const string& name,
931 const std::vector<double>& binedgesX,
932 const std::vector<double>& binedgesY) {
933 const string path = histoPath(name);
934
935 Scatter3D scat(path);
936 for (size_t xpt = 0; xpt < binedgesX.size()-1; ++xpt) {
937 const double xbincentre = (binedgesX[xpt] + binedgesX[xpt+1]) / 2.0;
938 const double xbinwidth = binedgesX[xpt+1] - binedgesX[xpt];
939 for (size_t ypt = 0; ypt < binedgesY.size()-1; ++ypt) {
940 const double ybincentre = (binedgesY[ypt] + binedgesY[ypt+1]) / 2.0;
941 const double ybinwidth = binedgesY[ypt+1] - binedgesY[ypt];
942 scat.addPoint(xbincentre, ybincentre, 0, 0.5*xbinwidth, 0.5*ybinwidth, 0);
943 }
944 }
945 _setWriterPrecision(path, scat);
946
947 return snd = registerAO(scat);
948 }
949
951 template<size_t N>
952 ScatterNDPtr<N>& book(ScatterNDPtr<N>& snd, const string& name, const YODA::ScatterND<N>& refscatter) {
953 const string path = histoPath(name);
954
955 YODA::ScatterND<N> scat(refscatter, path);
956 for (const string& a : scat.annotations()) {
957 if (a != "Path") scat.rmAnnotation(a);
958 }
959 _setWriterPrecision(path, scat);
960
961 return snd = registerAO(scat);
962 }
963
965
968
970 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::vector<std::string>& edges) {
971 const string path = histoPath(name);
972 Cutflow yao(edges, path);
973 _setWriterPrecision(path, yao);
974 return ao = registerAO(yao);
975 }
976
978 CutflowPtr& book(CutflowPtr& ao, const string& name, const std::initializer_list<std::string>& edges) {
979 return book(ao, name, vector<std::string>{edges});
980 }
981
983
986
987 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges,
988 const std::vector<std::vector<std::string>>& innerEdges) {
989 ao = make_shared<Cutflows>(edges);
990 if (ao->numBins() !=innerEdges.size()) {
991 throw RangeError("Outer and Inner edges don't match");
992 }
993 for (auto& b : ao->bins()) {
994 book(b, b.xEdge(), innerEdges[b.index()-1]);
995 }
996 return ao;
997 }
998
999 CutflowsPtr& book(CutflowsPtr& ao, const std::vector<std::string>& edges) {
1000 return ao = make_shared<Cutflows>(edges);
1001 }
1002
1003 CutflowsPtr& book(CutflowsPtr& ao, std::initializer_list<std::string>&& edges) {
1004 return ao = make_shared<Cutflows>(std::move(edges));
1005 }
1006
1008
1009
1013 virtual void rawHookIn(YODA::AnalysisObjectPtr yao) {
1014 (void) yao; // suppress unused variable warning
1015 }
1016
1020 virtual void rawHookOut(const vector<MultiplexAOPtr>& raos, size_t iW) {
1021 (void) raos; // suppress unused variable warning
1022 (void) iW; // suppress unused variable warning
1023 }
1024
1025
1026 public:
1027
1030
1032 const std::map<std::string,std::string>& options() const {
1033 return _options;
1034 }
1035
1037 std::string getOption(std::string optname, string def="") const {
1038 if ( _options.find(optname) != _options.end() )
1039 return _options.find(optname)->second;
1040 return def;
1041 }
1042
1047 std::string getOption(std::string optname, const char* def) {
1048 return getOption<std::string>(optname, def);
1049 }
1050
1058 template<typename T>
1059 T getOption(std::string optname, T def) const {
1060 if (_options.find(optname) == _options.end()) return def;
1061 std::stringstream ss;
1062 ss.exceptions(std::ios::failbit);
1063 T ret;
1064 ss << _options.find(optname)->second;
1065 try {
1066 ss >> ret;
1067 } catch (...) {
1068 throw ReadError("Could not read user-provided option into requested type");
1069 }
1070 return ret;
1071 }
1072
1083 // template<>
1084 // bool getOption<bool>(std::string optname, bool def) const {
1085 bool getOption(std::string optname, bool def) const {
1086 if (_options.find(optname) == _options.end()) return def;
1087 const std::string val = getOption(optname);
1088 const std::string lval = toLower(val);
1089 if (lval.empty()) return false;
1090 if (lval == "true" || lval == "yes" || lval == "on") return true;
1091 if (lval == "false" || lval == "no" || lval == "off") return false;
1092 return bool(getOption<int>(optname, 0));
1093 }
1094
1096
1097
1100
1119 string calAnaName, string calHistName,
1120 const string projName,
1121 PercentileOrder pctorder=PercentileOrder::DECREASING);
1122
1123
1130 template<typename T>
1131 Percentile<T> book(const string& projName,
1132 const vector<pair<double, double>>& centralityBins,
1133 const vector<tuple<size_t, size_t, size_t>>& ref) {
1134
1135 using RefT = typename ReferenceTraits<T>::RefT;
1136 using WrapT = MultiplexPtr<Multiplexer<T>>;
1137
1138 Percentile<T> pctl(this, projName);
1139
1140 const size_t nCent = centralityBins.size();
1141 for (size_t iCent = 0; iCent < nCent; ++iCent) {
1142 const string axisCode = mkAxisCode(std::get<0>(ref[iCent]),
1143 std::get<1>(ref[iCent]),
1144 std::get<2>(ref[iCent]));
1145 const RefT& refscatter = refData<RefT>(axisCode);
1146
1147 WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1148 wtf = addAnalysisObject(wtf);
1149
1150 CounterPtr cnt(_weightNames(), Counter(histoPath("TMP/COUNTER/" + axisCode)));
1151 cnt = addAnalysisObject(cnt);
1152
1153 pctl.add(wtf, cnt, centralityBins[iCent]);
1154 }
1155 return pctl;
1156 }
1157
1158
1159 // /// @brief Book Percentile Multiplexers around AnalysisObjects.
1160 // ///
1161 // /// Based on a previously registered CentralityProjection named @a
1162 // /// projName book one (or several) AnalysisObject(s) named
1163 // /// according to @a ref where the x-axis will be filled according
1164 // /// to the percentile output(s) of the @projName.
1165 // ///
1166 // /// @todo Convert to just be called book() cf. others
1167 // template <class T>
1168 // PercentileXaxis<T> bookPercentileXaxis(string projName,
1169 // tuple<int, int, int> ref) {
1170
1171 // typedef typename ReferenceTraits<T>::RefT RefT;
1172 // typedef MultiplexPtr<Multiplexer<T>> WrapT;
1173
1174 // PercentileXaxis<T> pctl(this, projName);
1175
1176 // const string axisCode = mkAxisCode(std::get<0>(ref),
1177 // std::get<1>(ref),
1178 // std::get<2>(ref));
1179 // const RefT & refscatter = refData<RefT>(axisCode);
1180
1181 // WrapT wtf(_weightNames(), T(refscatter, histoPath(axisCode)));
1182 // wtf = addAnalysisObject(wtf);
1183
1184 // CounterPtr cnt(_weightNames(), Counter());
1185 // cnt = addAnalysisObject(cnt);
1186
1187 // pctl.add(wtf, cnt);
1188 // return pctl;
1189 // }
1190
1192
1193
1194 private:
1195
1196 // Functions that have to be defined in the .cc file to avoid circular #includes
1197
1199 vector<string> _weightNames() const;
1200
1202 YODA::AnalysisObjectPtr _getPreload (const string& name) const;
1203
1205 MultiplexAOPtr _getOtherAnalysisObject(const std::string & ananame, const std::string& name);
1206
1208 void _checkBookInit() const;
1209
1211 bool _inInit() const;
1212
1214 bool _inFinalize() const;
1215
1217 template <typename YODAT>
1218 void _setWriterPrecision(const string& path, YODAT& yao) {
1219 const string re = _info->writerDoublePrecision();
1220 if (re != "") {
1221 std::smatch match;
1222 const bool needsDP = std::regex_search(path, match, std::regex(re));
1223 if (needsDP) yao.setAnnotation("WriterDoublePrecision", "1");
1224 }
1225 }
1226
1227
1228 private:
1229
1231 class CounterAdapter {
1232 public:
1233
1234 CounterAdapter(double x) : x_(x) {}
1235
1236 CounterAdapter(const YODA::Counter& c) : x_(c.val()) {}
1237
1238 CounterAdapter(const YODA::Estimate& e) : x_(e.val()) {}
1239
1240 CounterAdapter(const YODA::Scatter1D& s) : x_(s.points()[0].x()) {
1241 if (s.numPoints() != 1) throw RangeError("Can only scale by a single value.");
1242 }
1243
1244 operator double() const { return x_; }
1245
1246 private:
1247 double x_;
1248
1249 };
1250
1251
1252 public:
1253
1254 double dbl(double x) { return x; }
1255 double dbl(const YODA::Counter& c) { return c.val(); }
1256 double dbl(const YODA::Estimate0D& e) { return e.val(); }
1257 double dbl(const YODA::Scatter1D& s) {
1258 if ( s.numPoints() != 1 ) throw RangeError("Only scatter with single value supported.");
1259 return s.points()[0].x();
1260 }
1261
1262
1263 protected:
1264
1268
1270 template<typename T>
1271 void scale(MultiplexPtr<Multiplexer<T>>& ao, CounterAdapter factor) {
1272 if (!ao) {
1273 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1274 << name() << " (scale=" << double(factor) << ")");
1275 return;
1276 }
1277 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1278 MSG_WARNING("Failed to scale AnalysisObject=" << ao->path() << " in analysis: "
1279 << name() << " (invalid scale factor = " << double(factor) << ")");
1280 factor = 0;
1281 }
1282 MSG_TRACE("Scaling AnalysisObject " << ao->path() << " by factor " << double(factor));
1283 try {
1284 if constexpr( isFillable<T>::value ) {
1285 ao->scaleW(factor);
1286 }
1287 else {
1288 ao->scale(factor);
1289 }
1290 }
1291 catch (YODA::Exception& we) {
1292 MSG_WARNING("Could not scale AnalysisObject " << ao->path());
1293 return;
1294 }
1295 }
1296
1298 template<typename GroupAxisT, typename... AxisT>
1299 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, CounterAdapter factor) {
1300 if (!group) {
1301 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1302 << name() << " (scale=" << double(factor) << ")");
1303 return;
1304 }
1305 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1306 MSG_WARNING("Failed to scale histo group in analysis: "
1307 << name() << " (invalid scale factor = " << double(factor) << ")");
1308 factor = 0;
1309 }
1310 MSG_TRACE("Scaling histo group by factor " << double(factor));
1311 try {
1312 group->scaleW(factor);
1313 }
1314 catch (YODA::Exception& we) {
1315 MSG_WARNING("Could not scale histo group.");
1316 return;
1317 }
1318 }
1319
1321 template<typename GroupAxisT, typename... AxisT>
1322 void scale(HistoGroupPtr<GroupAxisT, AxisT...>& group, const vector<double>& factors) {
1323 if (!group) {
1324 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis " << name());
1325 return;
1326 }
1327 if (group->numBins(true) != factors.size()) {
1328 throw RangeError(name() + ": Number of scale factors does not match group binning");
1329 return;
1330 }
1331 for (auto& b : group->bins(true)) {
1332 if (!b.get()) continue;
1333 double factor = factors[b.index()];
1334 if (std::isnan(factor) || std::isinf(factor)) {
1335 MSG_WARNING("Failed to scale componment of histo group in analysis: "
1336 << name() << " (invalid scale factor = " << factor << ")");
1337 factor = 0;
1338 }
1339 MSG_TRACE("Scaling histo group element by factor " << factor);
1340 try {
1341 b->scaleW(factor);
1342 }
1343 catch (YODA::Exception& we) {
1344 MSG_WARNING("Could not scale component of histo group.");
1345 }
1346 }
1347 }
1348
1350 void scale(CutflowsPtr& group, CounterAdapter factor) {
1351 if (!group) {
1352 MSG_WARNING("Failed to scale AnalysisObject=NULL in analysis "
1353 << name() << " (scale=" << double(factor) << ")");
1354 return;
1355 }
1356 if (std::isnan(double(factor)) || std::isinf(double(factor))) {
1357 MSG_WARNING("Failed to scale histo group in analysis: "
1358 << name() << " (invalid scale factor = " << double(factor) << ")");
1359 factor = 0;
1360 }
1361 MSG_TRACE("Scaling histo group by factor " << double(factor));
1362 try {
1363 group->scale(factor);
1364 }
1365 catch (YODA::Exception& we) {
1366 MSG_WARNING("Could not scale histo group.");
1367 return;
1368 }
1369 }
1370
1372 template<typename T, typename U>
1373 void scale(std::map<T, U>& aos, CounterAdapter factor) {
1374 for (auto& item : aos) scale(item.second, factor);
1375 }
1376
1378 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1379 void scale(AORange& aos, CounterAdapter factor) {
1380 for (auto& ao : aos) scale(ao, factor);
1381 }
1382
1384 template <typename T>
1385 void scale(std::initializer_list<T> aos, CounterAdapter factor) {
1386 for (auto& ao : std::vector<T>{aos}) scale(ao, factor);
1387 }
1388
1390 template<typename T, typename U>
1391 void scale(std::map<T, U>& aos, const vector<double>& factors) {
1392 for (auto& item : aos) scale(item.second, factors);
1393 }
1394
1396 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1397 void scale(AORange& aos, const vector<double>& factors) {
1398 for (auto& ao : aos) scale(ao, factors);
1399 }
1400
1402 template <typename T>
1403 void scale(std::initializer_list<T> aos, const vector<double>& factors) {
1404 for (auto& ao : std::vector<T>{aos}) scale(ao, factors);
1405 }
1406
1408 template<typename GroupAxisT, typename... AxisT>
1409 void divByGroupWidth(HistoGroupPtr<GroupAxisT, AxisT...>& group) {
1410 if (!group) {
1411 MSG_WARNING("Failed to scale HistoGroup=NULL in analysis "
1412 << name() << " by group axis width");
1413 return;
1414 }
1415 group->divByGroupWidth();
1416 }
1417
1419 template<typename T, typename U>
1420 void divByGroupWidth(std::map<T, U>& aos) {
1421 for (auto& item : aos) divByGroupWidth(item.second);
1422 }
1423
1425 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1426 void divByGroupWidth(AORange& aos) {
1427 for (auto& ao : aos) divByGroupWidth(ao);
1428 }
1429
1431 template <typename T>
1432 void divByGroupWidth(std::initializer_list<T> aos) {
1433 for (auto& ao : std::vector<T>{aos}) divByGroupWidth(ao);
1434 }
1435
1436
1438 template <size_t DbnN, typename... AxisT>
1439 void normalize(BinnedDbnPtr<DbnN, AxisT...> ao, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1440 if (!ao) {
1441 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1442 return;
1443 }
1444 MSG_TRACE("Normalizing histo " << ao->path() << " to " << double(norm));
1445 try {
1446 const double hint = ao->integral(includeoverflows);
1447 if (hint == 0) MSG_DEBUG("Skipping histo with null area " << ao->path());
1448 else ao->normalize(norm, includeoverflows);
1449 }
1450 catch (YODA::Exception& we) {
1451 MSG_WARNING("Could not normalize histo " << ao->path());
1452 return;
1453 }
1454 }
1455
1457 template <typename GroupAxisT, typename... AxisT>
1458 void normalize(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1459 if (!group) {
1460 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1461 return;
1462 }
1463 MSG_TRACE("Normalizing histo group to " << double(norm));
1464 try {
1465 const double hint = group->integral(includeoverflows);
1466 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1467 else group->normalize(norm, includeoverflows);
1468 }
1469 catch (YODA::Exception& we) {
1470 MSG_WARNING("Could not normalize histo group.");
1471 return;
1472 }
1473 }
1474
1475
1477 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1478 void normalize(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1479 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1480 }
1481
1483 template<typename T>
1484 void normalize(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1485 for (auto& ao : aos) normalize(ao, norm, includeoverflows);
1486 }
1487
1489 template<typename T, typename U>
1490 void normalize(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1491 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1492 for (auto& item : aos) normalize(item.second, norm, includeoverflows);
1493 }
1494
1496 template <typename GroupAxisT, typename... AxisT>
1497 void normalizeGroup(HistoGroupPtr<GroupAxisT, AxisT...> group, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1498 if (!group) {
1499 MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << double(norm) << ")");
1500 return;
1501 }
1502 MSG_TRACE("Normalizing histo group to " << double(norm));
1503 try {
1504 const double hint = group->integral(includeoverflows);
1505 if (hint == 0) MSG_DEBUG("Skipping histo group with null area.");
1506 else group->normalizeGroup(norm, includeoverflows);
1507 }
1508 catch (YODA::Exception& we) {
1509 MSG_WARNING("Could not normalize histo group.");
1510 return;
1511 }
1512 }
1513
1515 template <typename AORange, typename = std::enable_if_t<YODA::isIterable<AORange>>>
1516 void normalizeGroup(AORange& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1517 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1518 }
1519
1521 template<typename T>
1522 void normalizeGroup(std::initializer_list<T>&& aos, const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1523 for (auto& ao : aos) normalizeGroup(ao, norm, includeoverflows);
1524 }
1525
1527 template<typename T, typename U>
1528 void normalizeGroup(std::map<T, U>& aos, //BinnedDbnPtr<DbnN, AxisT...>>& aos,
1529 const CounterAdapter norm=1.0, const bool includeoverflows=true) {
1530 for (auto& item : aos) normalizeGroup(item.second, norm, includeoverflows);
1531 }
1532
1533
1538 template<size_t DbnN, typename... AxisT>
1540 const string path = est->path();
1541 *est = ao->mkEstimate(path, "stats", false); //< do NOT divide by bin area cf. a differential dsigma/dX histogram
1542 }
1543
1548
1552 void divide(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const;
1553
1558
1562 void divide(const YODA::Estimate0D& e1, const YODA::Estimate0D& e2, Estimate0DPtr est) const;
1563
1564
1568 template<size_t DbnN, typename... AxisT>
1569 void divide(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1570 BinnedEstimatePtr<AxisT...> est) const {
1571 const string path = est->path();
1572 *est = h1 / h2;
1573 est->setPath(path);
1574 }
1575 //
1576 template<size_t DbnN, typename... AxisT>
1578 BinnedEstimatePtr<AxisT...> est) const {
1579 return divide(*h1, *h2, est);
1580 }
1581
1585 template<typename... AxisT>
1586 void divide(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1587 BinnedEstimatePtr<AxisT...> est) const {
1588 const string path = est->path();
1589 *est = e1 / e2;
1590 est->setPath(path);
1591 }
1592 //
1593 template<typename... AxisT>
1595 BinnedEstimatePtr<AxisT...> est) const {
1596 return divide(*e1, *e2, est);
1597 }
1598
1599
1600
1605 efficiency(*c1, *c2, est);
1606 }
1607
1611 void efficiency(const YODA::Counter& c1, const YODA::Counter& c2, Estimate0DPtr est) const {
1612 const string path = est->path();
1613 *est = YODA::efficiency(c1, c2);
1614 est->setPath(path);
1615 }
1616
1617
1618
1622 template<size_t DbnN, typename... AxisT>
1623 void efficiency(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1624 BinnedEstimatePtr<AxisT...> est) const {
1625 const string path = est->path();
1626 *est = YODA::efficiency(h1, h2);
1627 est->setPath(path);
1628 }
1629 //
1630 template<size_t DbnN, typename... AxisT>
1632 BinnedEstimatePtr<AxisT...> est) const {
1633 efficiency(*h1, *h2, est);
1634 }
1635
1636
1640 template<typename... AxisT>
1641 void efficiency(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1642 BinnedEstimatePtr<AxisT...> est) const {
1643 const string path = est->path();
1644 *est = YODA::efficiency(e1, e2);
1645 est->setPath(path);
1646 }
1647 //
1648 template<typename... AxisT>
1650 BinnedEstimatePtr<AxisT...> est) const {
1651 efficiency(*e1, *e2, est);
1652 }
1653
1654
1658 template<size_t DbnN, typename... AxisT>
1659 void asymm(const YODA::BinnedDbn<DbnN, AxisT...>& h1, const YODA::BinnedDbn<DbnN, AxisT...>& h2,
1660 BinnedEstimatePtr<AxisT...> est) const {
1661 const string path = est->path();
1662 *est = YODA::asymm(h1, h2);
1663 est->setPath(path);
1664 }
1665 //
1666 template<size_t DbnN, typename... AxisT>
1668 BinnedEstimatePtr<AxisT...> est) const {
1669 asymm(*h1, *h2, est);
1670 }
1671
1675 template<typename... AxisT>
1676 void asymm(const YODA::BinnedEstimate<AxisT...>& e1, const YODA::BinnedEstimate<AxisT...>& e2,
1677 BinnedEstimatePtr<AxisT...> est) const {
1678 const string path = est->path();
1679 *est = YODA::asymm(e1, e2);
1680 est->setPath(path);
1681 }
1682 //
1683 template<typename... AxisT>
1685 BinnedEstimatePtr<AxisT...> est) const {
1686 asymm(*e1, *e2, est);
1687 }
1688
1692 template<size_t DbnN, typename... AxisT>
1693 void integrate(const YODA::BinnedDbn<DbnN, AxisT...>& h, BinnedEstimatePtr<AxisT...> est) const {
1694 const string path = est->path();
1695 *est = mkIntegral(h);
1696 est->setPath(path);
1697 }
1698 //
1699 template<size_t DbnN, typename... AxisT>
1701 integrate(*h, est);
1702 }
1703
1705
1706
1707 public:
1708
1710 const vector<MultiplexAOPtr>& analysisObjects() const {
1711 return _analysisobjects;
1712 }
1713
1714
1715 protected:
1716
1719
1721 size_t defaultWeightIndex() const;
1722
1724 template <typename YODAT>
1725 shared_ptr<YODAT> getPreload(const string& path) const {
1726 return dynamic_pointer_cast<YODAT>(_getPreload(path));
1727 }
1728
1729
1731 template <typename YODAT>
1733 using MultiplexerT = Multiplexer<YODAT>;
1734 using YODAPtrT = shared_ptr<YODAT>;
1735 using RAOT = MultiplexPtr<MultiplexerT>;
1736
1737 if ( !_inInit() && !_inFinalize() ) {
1738 MSG_ERROR("Can't book objects outside of init() or finalize()");
1739 throw UserError(name() + ": Can't book objects outside of init() or finalize().");
1740 }
1741
1742 // First check that we haven't booked this before.
1743 // This is allowed when booking in finalize: just warn in that case.
1744 // If in init(), throw an exception: it's 99.9% never going to be intentional.
1745 for (auto& waold : analysisObjects()) {
1746 if ( yao.path() == waold.get()->basePath() ) {
1747 const string msg = "Found double-booking of " + yao.path() + " in " + name();
1748 if ( _inInit() ) {
1749 MSG_ERROR(msg);
1750 throw LookupError(msg);
1751 } else {
1752 MSG_WARNING(msg + ". Keeping previous booking");
1753 }
1754 return RAOT(dynamic_pointer_cast<MultiplexerT>(waold.get()));
1755 }
1756 }
1757
1758 shared_ptr<MultiplexerT> wao = make_shared<MultiplexerT>();
1759 wao->_basePath = yao.path();
1760 YODAPtrT yaop = make_shared<YODAT>(yao);
1761
1762 for (const string& weightname : _weightNames()) {
1763 // Create two YODA objects for each weight. Copy from
1764 // preloaded YODAs if present. First the finalized yoda:
1765 string finalpath = yao.path();
1766 if ( weightname != "" ) finalpath += "[" + weightname + "]";
1767 YODAPtrT preload = getPreload<YODAT>(finalpath);
1768 if ( preload ) {
1769 if ( !bookingCompatible(preload, yaop) ) {
1771 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1772 << finalpath << " for " << name());
1773 preload = nullptr;
1774 } else {
1775 MSG_TRACE("Using preloaded " << finalpath << " in " <<name());
1776 wao->_final.push_back(make_shared<YODAT>(*preload));
1777 }
1778 }
1779 else {
1780 wao->_final.push_back(make_shared<YODAT>(yao));
1781 wao->_final.back()->setPath(finalpath);
1782 }
1783
1784 // Then the raw filling yodas.
1785 string rawpath = "/RAW" + finalpath;
1786 preload = getPreload<YODAT>(rawpath);
1787 if ( preload ) {
1788 if ( !bookingCompatible(preload, yaop) ) {
1789 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1790 << rawpath << " for " << name());
1791 preload = nullptr;
1792 } else {
1793 MSG_TRACE("Using preloaded " << rawpath << " in " <<name());
1794 wao->_persistent.push_back(make_shared<YODAT>(*preload));
1795 }
1796 }
1797 else {
1798 wao->_persistent.push_back(make_shared<YODAT>(yao));
1799 wao->_persistent.back()->setPath(rawpath);
1800 }
1801 }
1803
1804 ret.get()->unsetActiveWeight();
1805 if ( _inFinalize() ) {
1806 // If booked in finalize() we assume it is the first time
1807 // finalize is run.
1808 ret.get()->pushToFinal();
1809 ret.get()->setActiveFinalWeightIdx(0);
1810 }
1811 _analysisobjects.push_back(ret);
1812
1813 return ret;
1814 }
1815
1816
1818 template <typename AO=MultiplexAOPtr>
1819 AO addAnalysisObject(const AO& aonew) {
1820 _checkBookInit();
1821
1822 for (const MultiplexAOPtr& ao : analysisObjects()) {
1823
1824 // Check AO base-name first
1825 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1826 aonew.get()->setActiveWeightIdx(defaultWeightIndex());
1827 if (ao->path() != aonew->path()) continue;
1828
1829 // If base-name matches, check compatibility
1830 // NB. This evil is because dynamic_ptr_cast can't work on MultiplexPtr directly
1831 AO aoold = AO(dynamic_pointer_cast<typename AO::value_type>(ao.get())); //< OMG
1832 if ( !aoold || !bookingCompatible(aonew, aoold) ) {
1833 MSG_WARNING("Found incompatible pre-existing data object with same base path "
1834 << aonew->path() << " for " << name());
1835 throw LookupError("Found incompatible pre-existing data object with same base path during AO booking");
1836 }
1837
1838 // Finally, check all weight variations
1839 for (size_t weightIdx = 0; weightIdx < _weightNames().size(); ++weightIdx) {
1840 aoold.get()->setActiveWeightIdx(weightIdx);
1841 aonew.get()->setActiveWeightIdx(weightIdx);
1842 if (aoold->path() != aonew->path()) {
1843 MSG_WARNING("Found incompatible pre-existing data object with different weight-path "
1844 << aonew->path() << " for " << name());
1845 throw LookupError("Found incompatible pre-existing data object with same weight-path during AO booking");
1846 }
1847 }
1848
1849 // They're fully compatible: bind and return
1850 aoold.get()->unsetActiveWeight();
1851 MSG_TRACE("Bound pre-existing data object " << aoold->path() << " for " << name());
1852 return aoold;
1853 }
1854
1855 // No equivalent found
1856 MSG_TRACE("Registered " << aonew->annotation("Type") << " " << aonew->path() << " for " << name());
1857 aonew.get()->unsetActiveWeight();
1858
1859 _analysisobjects.push_back(aonew);
1860 return aonew;
1861 }
1862
1864 void removeAnalysisObject(const std::string& path);
1865
1868
1870 template <typename AO=MultiplexAOPtr>
1871 const AO getAnalysisObject(const std::string& aoname) const {
1872 for (const MultiplexAOPtr& ao : analysisObjects()) {
1873 ao.get()->setActiveWeightIdx(defaultWeightIndex());
1874 if (ao->path() == histoPath(aoname)) {
1875 // return dynamic_pointer_cast<AO>(ao);
1876 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1877 }
1878 }
1879 throw LookupError("Data object " + histoPath(aoname) + " not found");
1880 }
1881
1882
1883 // /// Get a data object from the histogram system
1884 // template <typename AO=YODA::AnalysisObject>
1885 // const std::shared_ptr<AO> getAnalysisObject(const std::string& name) const {
1886 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1887 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1888 // }
1889 // throw LookupError("Data object " + histoPath(name) + " not found");
1890 // }
1891
1892 // /// Get a data object from the histogram system (non-const)
1893 // template <typename AO=YODA::AnalysisObject>
1894 // std::shared_ptr<AO> getAnalysisObject(const std::string& name) {
1895 // foreach (const AnalysisObjectPtr& ao, analysisObjects()) {
1896 // if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao);
1897 // }
1898 // throw LookupError("Data object " + histoPath(name) + " not found");
1899 // }
1900
1901
1904 template <typename AO=MultiplexAOPtr>
1905 AO getAnalysisObject(const std::string& ananame,
1906 const std::string& aoname) {
1907 MultiplexAOPtr ao = _getOtherAnalysisObject(ananame, aoname);
1908 // return dynamic_pointer_cast<AO>(ao);
1909 return AO(dynamic_pointer_cast<typename AO::value_type>(ao.get()));
1910 }
1911
1913
1916
1918 template <
1919 typename... Args, typename CONTAINER,
1920 typename = std::enable_if_t<
1921 is_citerable_v<CONTAINER>,
1922 Jet
1923 >
1924 >
1925 static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args&&... args){
1926 return FastJets::reclusterJets(jetsIn, std::forward<Args>(args)...);
1927 }
1928
1929 template <typename T, typename U, typename... Args>
1930 static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
1931 return FastJets::reclusterJets(jetsMap, std::forward<Args>(args)...);
1932 }
1933
1934 template <
1935 JetAlg JETALG, typename... Args, typename CONTAINER,
1936 typename = std::enable_if_t<
1937 is_citerable_v<CONTAINER>,
1938 Jet
1939 >
1940 >
1941 static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args&&... args){
1942 return FastJets::reclusterJets<JETALG>(jetsIn, std::forward<Args>(args)...);
1943 }
1944
1945 template <JetAlg JETALG, typename T, typename U, typename... Args>
1946 static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
1947 return FastJets::reclusterJets<JETALG>(jetsMap, std::forward<Args>(args)...);
1948 }
1949
1951
1952
1953 private:
1954
1956 string _defaultname;
1957
1959 unique_ptr<AnalysisInfo> _info;
1960
1963 vector<MultiplexAOPtr> _analysisobjects;
1964
1967 double _crossSection;
1968 bool _gotCrossSection;
1970
1972 AnalysisHandler* _analysishandler;
1973
1975 const Event* _currentevent = nullptr;
1976
1979 mutable std::map<std::string, YODA::AnalysisObjectPtr> _refdata;
1980
1982 map<string, string> _options;
1983
1985 string _optstring;
1986
1987
1988 private:
1989
1992
1994 void _cacheRefData() const;
1995
1997
1998 };
1999
2000
2001 // // Template specialisation for literal character strings (which don't play well with stringstream)
2002 // template<>
2003 // inline std::string Analysis::getOption(std::string optname, const char* def) {
2004 // return getOption<std::string>(optname, def); //.c_str();
2005 // }
2006
2007
2008}
2009
2010
2011// Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
2012#include "Rivet/AnalysisBuilder.hh"
2013
2014
2017
2020#define RIVET_DECLARE_PLUGIN(clsname) ::Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
2021
2024#define RIVET_DECLARE_ALIASED_PLUGIN(clsname, alias) RIVET_DECLARE_PLUGIN(clsname)( #alias )
2025
2028#define RIVET_DEFAULT_ANALYSIS_CTOR(clsname) clsname() : Analysis(# clsname) {}
2029
2032#define RIVET_REGISTER_TYPE(...) handler().registerType<__VA_ARGS__>()
2033
2036#define RIVET_REGISTER_BINNED_SET(...) { \
2037 RIVET_REGISTER_TYPE(YODA::BinnedHisto<__VA_ARGS__>); \
2038 RIVET_REGISTER_TYPE(YODA::BinnedProfile<__VA_ARGS__>); \
2039 RIVET_REGISTER_TYPE(YODA::BinnedEstimate<__VA_ARGS__>); }
2040
2042
2043
2044#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:70
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:1047
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:685
virtual std::string status() const
Whether this analysis is trusted (in any way!)
Definition Analysis.hh:265
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:81
virtual bool reentrant() const
Does this analysis have a reentrant finalize()?
Definition Analysis.hh:285
shared_ptr< YODAT > getPreload(const string &path) const
Get a preloaded YODA object.
Definition Analysis.hh:1725
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:172
void scale(std::initializer_list< T > aos, CounterAdapter factor)
Iteratively scale the AOs in the initialiser list aos, by factor factor.
Definition Analysis.hh:1385
virtual std::string collider() const
Collider on which the experiment ran.
Definition Analysis.hh:229
MultiplexPtr< Multiplexer< YODAT > > registerAO(const YODAT &yao)
Register a new data object, optionally read in preloaded data.
Definition Analysis.hh:1732
virtual double luminosityfb() const
The integrated luminosity in inverse femtobarn.
Definition Analysis.hh:239
void loadInfo()
Get the AnalysisInfo object to parse its info file in which the metadata is stored.
Definition Analysis.hh:149
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:1131
const AnalysisInfo & info() const
Get the actual AnalysisInfo object in which all this metadata is stored.
Definition Analysis.hh:152
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:1478
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:1490
void efficiency(CounterPtr c1, CounterPtr c2, Estimate0DPtr est) const
Definition Analysis.hh:1604
virtual const std::vector< std::string > & keywords() const
Get vector of analysis keywords.
Definition Analysis.hh:290
virtual double luminosity() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:243
virtual std::string spiresID() const
Get the SPIRES ID code for this analysis (~deprecated).
Definition Analysis.hh:183
virtual std::string writerDoublePrecision() const
Positive filtering regex for setting double precision in Writer.
Definition Analysis.hh:305
virtual void preInit()
A method called before init(), for cleaner subclassing.
Definition Analysis.hh:117
void efficiency(const YODA::Counter &c1, const YODA::Counter &c2, Estimate0DPtr est) const
Definition Analysis.hh:1611
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:671
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:838
virtual Analysis & setRequiredBeamIDs(const std::vector< PdgIdPair > &beamids)
Declare the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:314
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:779
AO getAnalysisObject(const std::string &ananame, const std::string &aoname)
Definition Analysis.hh:1905
void barchart(BinnedDbnPtr< DbnN, AxisT... > ao, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1539
AnalysisInfo & info()
Get the actual AnalysisInfo object in which all this metadata is stored (non-const).
Definition Analysis.hh:347
virtual std::string runInfo() const
Information about the events needed as input for this analysis.
Definition Analysis.hh:219
void syncDeclQueue()
Definition Analysis.hh:132
void scale(AORange &aos, CounterAdapter factor)
Iteratively scale the AOs in the iterable aos, by factor factor.
Definition Analysis.hh:1379
virtual std::string year() const
When the original experimental analysis was published.
Definition Analysis.hh:234
virtual void preAnalyze(const Event &)
A method called before analyze(), for cleaner subclassing.
Definition Analysis.hh:121
T getOption(std::string optname, T def) const
Get an option for this analysis instance converted to a specific type.
Definition Analysis.hh:1059
virtual void setRefDataName(const std::string &ref_data="")
Set name of reference data file, which could be different from plugin name.
Definition Analysis.hh:339
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:1710
double crossSectionPerEvent() const
virtual std::string summary() const
Get a short description of the analysis.
Definition Analysis.hh:200
void scale(AORange &aos, const vector< double > &factors)
Iteratively scale the AOs in the iterable aos, by factors factors.
Definition Analysis.hh:1397
virtual std::string description() const
Get a full description of the analysis.
Definition Analysis.hh:210
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:1391
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:1037
virtual std::vector< std::string > validation() const
make-style commands for validating this analysis.
Definition Analysis.hh:280
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:1522
virtual std::vector< std::string > authors() const
Names & emails of paper/analysis authors.
Definition Analysis.hh:191
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, const vector< double > &factors)
Multiplicatively scale the given histogram group, group, by factors factors.
Definition Analysis.hh:1322
void asymm(const YODA::BinnedEstimate< AxisT... > &e1, const YODA::BinnedEstimate< AxisT... > &e2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1676
virtual void postAnalyze(const Event &)
A method called after analyze(), for cleaner subclassing.
Definition Analysis.hh:123
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:324
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:1516
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:1426
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:790
virtual std::string refFile() const
Location of reference data YODA file.
Definition Analysis.hh:331
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:1497
virtual void finalize()
Definition Analysis.hh:108
void efficiency(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1623
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:653
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:875
virtual std::vector< std::string > references() const
Journal, and preprint references.
Definition Analysis.hh:250
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:275
virtual std::string inspireID() const
Get the Inspire ID code for this analysis.
Definition Analysis.hh:178
void scale(HistoGroupPtr< GroupAxisT, AxisT... > &group, CounterAdapter factor)
Multiplicatively scale the given histogram group, group, by factor factor.
Definition Analysis.hh:1299
bool merging() const
Check if we are running rivet-merge.
Definition Analysis.hh:359
void divByGroupWidth(std::initializer_list< T > aos)
Iteratively scale the HistoGroups in the initialiser list aos, by the group axis width.
Definition Analysis.hh:1432
void divide(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1569
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:425
virtual const std::vector< PdgIdPair > & requiredBeamIDs() const
Return the allowed pairs of incoming beams required by this analysis.
Definition Analysis.hh:310
virtual std::string refUnmatch() const
Negative filtering regex for ref-data HepData sync.
Definition Analysis.hh:300
const std::map< std::string, std::string > & options() const
Return the map of all options given to this analysis.
Definition Analysis.hh:1032
virtual void postInit()
A method called after init(), for cleaner subclassing.
Definition Analysis.hh:119
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:1085
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:1271
void scale(CutflowsPtr &group, CounterAdapter factor)
Multiplicatively scale the cutflow group, group, by factor factor.
Definition Analysis.hh:1350
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:864
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:295
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:1528
double luminositypb() const
The integrated luminosity in inverse picobarn.
Definition Analysis.hh:247
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:1586
void integrate(const YODA::BinnedDbn< DbnN, AxisT... > &h, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1693
const T & refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const
Definition Analysis.hh:548
virtual std::string warning() const
A warning message from the info file, if there is one.
Definition Analysis.hh:270
AnalysisHandler & handler() const
Access the controlling AnalysisHandler object.
Definition Analysis.hh:422
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:1409
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:1484
double sumOfWeights() const
Alias.
Definition Analysis.hh:460
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:738
const AO getAnalysisObject(const std::string &aoname) const
Get a Rivet data object from the histogram system.
Definition Analysis.hh:1871
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:952
virtual void postFinalize()
A method called after finalize(), for cleaner subclassing.
Definition Analysis.hh:127
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:915
friend class AnalysisHandler
The AnalysisHandler is a friend.
Definition Analysis.hh:74
const std::map< std::string, YODA::AnalysisObjectPtr > & refData() const
Get all reference data objects for this analysis.
Definition Analysis.hh:521
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:1641
BinnedDbnPtr< DbnN, AxisT... > & book(BinnedDbnPtr< DbnN, AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:693
void asymm(const YODA::BinnedDbn< DbnN, AxisT... > &h1, const YODA::BinnedDbn< DbnN, AxisT... > &h2, BinnedEstimatePtr< AxisT... > est) const
Definition Analysis.hh:1659
BinnedEstimatePtr< AxisT... > & book(BinnedEstimatePtr< AxisT... > &ao, const unsigned int datasetID, const unsigned int xAxisID, const unsigned int yAxisID)
Definition Analysis.hh:815
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:255
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:260
bool compatibleWithRun() const
Check if the given conditions are compatible with this analysis' declared constraints.
virtual void init()
Definition Analysis.hh:95
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:664
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:530
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:592
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:335
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:797
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:1439
virtual std::string name() const
Get the name of the analysis.
Definition Analysis.hh:164
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:1403
void divByGroupWidth(std::map< T, U > &aos)
Iteratively scale the HistoGroups in the map aos, by the group axis width.
Definition Analysis.hh:1420
virtual void preFinalize()
A method called before finalize(), for cleaner subclassing.
Definition Analysis.hh:125
virtual std::string experiment() const
Experiment which performed and published this analysis.
Definition Analysis.hh:224
void scale(std::map< T, U > &aos, CounterAdapter factor)
Iteratively scale the AOs in the map aos, by factor factor.
Definition Analysis.hh:1373
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:1458
virtual const std::vector< std::pair< double, double > > & requiredBeamEnergies() const
Sets of valid beam energy pairs, in GeV.
Definition Analysis.hh:320
AO addAnalysisObject(const AO &aonew)
Register a data object in the histogram system.
Definition Analysis.hh:1819
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: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:140
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:978
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:970
static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args &&... args)
Avoid FastJet:: scoping prefix.
Definition Analysis.hh:1925
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
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
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:499
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:84
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:67