1 #ifndef RIVET_RIVETYODA_HH 2 #define RIVET_RIVETYODA_HH 4 #include "Rivet/Config/RivetCommon.hh" 5 #include "YODA/AnalysisObject.h" 6 #include "YODA/Counter.h" 7 #include "YODA/Histo1D.h" 8 #include "YODA/Histo2D.h" 9 #include "YODA/Profile1D.h" 10 #include "YODA/Profile2D.h" 11 #include "YODA/Scatter1D.h" 12 #include "YODA/Scatter2D.h" 13 #include "YODA/Scatter3D.h" 20 typedef std::shared_ptr<YODA::AnalysisObject> AnalysisObjectPtr;
22 typedef std::shared_ptr<YODA::Counter> CounterPtr;
23 typedef std::shared_ptr<YODA::Histo1D> Histo1DPtr;
24 typedef std::shared_ptr<YODA::Histo2D> Histo2DPtr;
25 typedef std::shared_ptr<YODA::Profile1D> Profile1DPtr;
26 typedef std::shared_ptr<YODA::Profile2D> Profile2DPtr;
27 typedef std::shared_ptr<YODA::Scatter1D> Scatter1DPtr;
28 typedef std::shared_ptr<YODA::Scatter2D> Scatter2DPtr;
29 typedef std::shared_ptr<YODA::Scatter3D> Scatter3DPtr;
49 using Fill = pair<typename T::FillType, Weight>;
54 using Fills = multiset<Fill<T>>;
72 class TupleWrapper<
YODA::Counter> :
public YODA::Counter {
76 typedef shared_ptr<TupleWrapper<YODA::Counter>> Ptr;
79 TupleWrapper(
const YODA::Counter& h) :
YODA::Counter(h) {}
84 void fill(
double weight=1.0,
double fraction=1.0) {
86 _fills.insert( { YODA::Counter::FillType(), weight } );
90 void reset() { _fills.clear(); }
104 class TupleWrapper<
YODA::Histo1D> :
public YODA::Histo1D {
108 typedef shared_ptr<TupleWrapper<YODA::Histo1D>> Ptr;
111 TupleWrapper(
const YODA::Histo1D& h) :
YODA::Histo1D(h) {}
116 void fill(
double x,
double weight=1.0,
double fraction=1.0 ) {
118 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
119 _fills.insert( { x, weight } );
123 void reset() { _fills.clear(); }
137 class TupleWrapper<
YODA::Profile1D> :
public YODA::Profile1D {
141 typedef shared_ptr<TupleWrapper<YODA::Profile1D>> Ptr;
144 TupleWrapper(
const YODA::Profile1D& h) :
YODA::Profile1D(h) {}
149 void fill(
double x,
double y,
double weight=1.0,
double fraction=1.0 ) {
151 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
152 if ( std::isnan(y) )
throw YODA::RangeError(
"Y is NaN");
153 _fills.insert( { YODA::Profile1D::FillType{x,y}, weight } );
157 void reset() { _fills.clear(); }
171 class TupleWrapper<
YODA::Histo2D> :
public YODA::Histo2D {
175 typedef shared_ptr<TupleWrapper<YODA::Histo2D>> Ptr;
178 TupleWrapper(
const YODA::Histo2D& h) :
YODA::Histo2D(h) {}
183 void fill(
double x,
double y,
double weight=1.0,
double fraction=1.0 ) {
185 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
186 if ( std::isnan(y) )
throw YODA::RangeError(
"Y is NaN");
187 _fills.insert( { YODA::Histo2D::FillType{x,y}, weight } );
191 void reset() { _fills.clear(); }
205 class TupleWrapper<
YODA::Profile2D> :
public YODA::Profile2D {
209 typedef shared_ptr<TupleWrapper<YODA::Profile2D>> Ptr;
212 TupleWrapper(
const YODA::Profile2D& h) :
YODA::Profile2D(h) {}
217 void fill(
double x,
double y,
double z,
double weight=1.0,
double fraction=1.0 ) {
219 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
220 if ( std::isnan(y) )
throw YODA::RangeError(
"Y is NaN");
221 if ( std::isnan(z) )
throw YODA::RangeError(
"Z is NaN");
222 _fills.insert( { YODA::Profile2D::FillType{x,y,z}, weight } );
226 void reset() { _fills.clear(); }
240 class TupleWrapper<
YODA::Scatter1D> :
public YODA::Scatter1D {
244 typedef shared_ptr<TupleWrapper<YODA::Scatter1D>> Ptr;
247 TupleWrapper(
const YODA::Scatter1D& h) :
YODA::Scatter1D(h) {}
254 class TupleWrapper<
YODA::Scatter2D> :
public YODA::Scatter2D {
258 typedef shared_ptr<TupleWrapper<YODA::Scatter2D>> Ptr;
261 TupleWrapper(
const YODA::Scatter2D& h) :
YODA::Scatter2D(h) {}
268 class TupleWrapper<
YODA::Scatter3D> :
public YODA::Scatter3D {
272 typedef shared_ptr<TupleWrapper<YODA::Scatter3D>> Ptr;
275 TupleWrapper(
const YODA::Scatter3D& h) :
YODA::Scatter3D(h) {}
294 class AnalysisObjectWrapper {
297 virtual ~AnalysisObjectWrapper() {}
300 virtual YODA::AnalysisObject* operator -> () = 0;
302 virtual YODA::AnalysisObject* operator -> ()
const = 0;
304 virtual const YODA::AnalysisObject& operator * ()
const = 0;
307 virtual void setActiveWeightIdx(
size_t iWeight) = 0;
310 virtual void setActiveFinalWeightIdx(
size_t iWeight) = 0;
315 virtual void unsetActiveWeight() = 0;
318 bool operator == (
const AnalysisObjectWrapper& p) {
return (
this == &p); }
320 bool operator != (
const AnalysisObjectWrapper& p) {
return (
this != &p); }
409 class MultiweightAOWrapper :
public AnalysisObjectWrapper {
413 using Inner = YODA::AnalysisObject;
416 virtual void newSubEvent() = 0;
419 virtual void pushToPersistent(
const vector<std::valarray<double> >& weight,
double nlowfrac=0.0) = 0;
422 virtual void pushToFinal() = 0;
425 virtual YODA::AnalysisObjectPtr activeYODAPtr()
const = 0;
428 virtual string basePath()
const = 0;
448 class Wrapper :
public MultiweightAOWrapper {
458 using TPtr = shared_ptr<T>;
463 Wrapper(
const vector<string>& weightnames,
const T& p);
469 shared_ptr<T> active()
const;
472 string basePath()
const {
return _basePath; }
475 string baseName()
const {
return _baseName; }
479 explicit operator bool()
const {
return static_cast<bool>(_active); }
486 T* operator -> () {
return active().get(); }
489 T* operator -> ()
const {
return active().get(); }
492 T& operator * () {
return *active(); }
495 const T& operator * ()
const {
return *active(); }
500 friend bool operator == (Wrapper a, Wrapper b){
501 if (a._persistent.size() != b._persistent.size())
504 for (
size_t i = 0; i < a._persistent.size(); i++) {
505 if (a._persistent.at(i) != b._persistent.at(i)) {
513 friend bool operator != (Wrapper a, Wrapper b) {
518 friend bool operator < (Wrapper a, Wrapper b) {
519 if (a._persistent.size() >= b._persistent.size())
521 for (
size_t i = 0; i < a._persistent.size(); i++) {
522 if (*(a._persistent.at(i)) >= *(b._persistent.at(i))) {
538 T* _getPersistent(
size_t iWeight) {
return _persistent.at(iWeight).get(); }
558 void setActiveWeightIdx(
size_t iWeight) {
559 _active = _persistent.at(iWeight);
563 void setActiveFinalWeightIdx(
size_t iWeight) {
564 _active = _final.at(iWeight);
568 void unsetActiveWeight() { _active.reset(); }
571 void reset() { active()->reset(); }
581 void pushToPersistent(
const vector<std::valarray<double> >& weight,
double nlowfrac=0.0);
588 const vector<shared_ptr<T>>& persistent()
const {
return _persistent; }
591 const vector<shared_ptr<T>>&
final()
const {
return _final; }
594 virtual YODA::AnalysisObjectPtr activeYODAPtr()
const {
return _active; }
606 vector<shared_ptr<T>> _persistent;
609 vector<shared_ptr<T>> _final;
612 vector<shared_ptr<TupleWrapper<T>>> _evgroup;
615 shared_ptr<T> _active;
636 template <
typename T>
637 class rivet_shared_ptr {
639 typedef T value_type;
641 rivet_shared_ptr() =
default;
643 rivet_shared_ptr(decltype(
nullptr)) : _p(nullptr) {}
646 rivet_shared_ptr(
const vector<string>& weightNames,
const typename T::Inner& p)
647 : _p( make_shared<T>(weightNames, p) )
651 template <
typename U>
652 rivet_shared_ptr(
const shared_ptr<U>& p)
657 template <
typename U>
658 rivet_shared_ptr(
const rivet_shared_ptr<U>& p)
664 if (_p ==
nullptr)
throw Error(
"Dereferencing null AnalysisObject pointer. Is there an unbooked histogram variable?");
669 const T& operator -> ()
const {
670 if (_p ==
nullptr)
throw Error(
"Dereferencing null AnalysisObject pointer. Is there an unbooked histogram variable?");
675 typename T::Inner & operator * () {
return **_p; }
676 const typename T::Inner & operator * ()
const {
return **_p; }
679 explicit operator bool()
const {
return _p && bool(*_p); }
682 bool operator ! ()
const {
return !_p || !(*_p); }
685 template <
typename U>
686 bool operator == (
const rivet_shared_ptr<U>& other)
const {
687 return _p == other._p;
691 template <
typename U>
692 bool operator != (
const rivet_shared_ptr<U>& other)
const {
693 return _p != other._p;
697 template <
typename U>
698 bool operator < (const rivet_shared_ptr<U>& other)
const {
699 return _p < other._p;
703 template <
typename U>
704 bool operator > (
const rivet_shared_ptr<U>& other)
const {
705 return _p > other._p;
709 template <
typename U>
710 bool operator <= (const rivet_shared_ptr<U> & other)
const {
711 return _p <= other._p;
715 template <
typename U>
716 bool operator >= (
const rivet_shared_ptr<U> & other)
const {
717 return _p >= other._p;
721 shared_ptr<T>
get()
const {
return _p; }
738 using MultiweightAOPtr = rivet_shared_ptr<MultiweightAOWrapper>;
740 using Histo1DPtr = rivet_shared_ptr<Wrapper<YODA::Histo1D>>;
741 using Histo2DPtr = rivet_shared_ptr<Wrapper<YODA::Histo2D>>;
742 using Profile1DPtr = rivet_shared_ptr<Wrapper<YODA::Profile1D>>;
743 using Profile2DPtr = rivet_shared_ptr<Wrapper<YODA::Profile2D>>;
744 using CounterPtr = rivet_shared_ptr<Wrapper<YODA::Counter>>;
745 using Scatter1DPtr = rivet_shared_ptr<Wrapper<YODA::Scatter1D>>;
746 using Scatter2DPtr = rivet_shared_ptr<Wrapper<YODA::Scatter2D>>;
747 using Scatter3DPtr = rivet_shared_ptr<Wrapper<YODA::Scatter3D>>;
751 using YODA::HistoBin1D;
753 using YODA::HistoBin2D;
754 using YODA::Profile1D;
755 using YODA::ProfileBin1D;
756 using YODA::Profile2D;
757 using YODA::ProfileBin2D;
758 using YODA::Scatter1D;
760 using YODA::Scatter2D;
762 using YODA::Scatter3D;
776 map<string, YODA::AnalysisObjectPtr>
getRefData(
const string& papername);
785 template<
typename T>
struct ReferenceTraits {};
786 template <>
struct ReferenceTraits<Counter> {
typedef Counter RefT; };
787 template <>
struct ReferenceTraits<Scatter1D> {
typedef Scatter1D RefT; };
788 template <>
struct ReferenceTraits<Histo1D> {
typedef Scatter2D RefT; };
789 template <>
struct ReferenceTraits<Profile1D> {
typedef Scatter2D RefT; };
790 template <>
struct ReferenceTraits<Scatter2D> {
typedef Scatter2D RefT; };
791 template <>
struct ReferenceTraits<Histo2D> {
typedef Scatter3D RefT; };
792 template <>
struct ReferenceTraits<Profile2D> {
typedef Scatter3D RefT; };
793 template <>
struct ReferenceTraits<Scatter3D> {
typedef Scatter3D RefT; };
798 template <
typename T>
799 inline bool aocopy(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst) {
800 shared_ptr<T> tsrc = dynamic_pointer_cast<T>(src);
801 if ( !tsrc )
return false;
802 shared_ptr<T> tdst = dynamic_pointer_cast<T>(dst);
803 if ( !tdst )
return false;
812 template <
typename T>
813 inline bool aocopy(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst,
double scale) {
814 if (!aocopy<T>(src, dst))
return false;
815 dynamic_pointer_cast<T>(dst)->scaleW(scale);
822 template <
typename T>
823 inline bool aoadd(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src,
double scale) {
824 shared_ptr<T> tsrc = dynamic_pointer_cast<T>(src);
825 if ( !tsrc )
return false;
826 shared_ptr<T> tdst = dynamic_pointer_cast<T>(dst);
827 if ( !tdst )
return false;
831 }
catch (YODA::LogicError&) {
839 bool copyao(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst,
double scale=1.0);
844 bool addaos(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src,
double scale);
848 template <
typename TPtr>
850 return a->sameBinning(*b);
856 return a->numPoints() == b->numPoints();
859 return a->numPoints() == b->numPoints();
862 return a->numPoints() == b->numPoints();
868 return a->numPoints() == b->numPoints();
871 return a->numPoints() == b->numPoints();
874 return a->numPoints() == b->numPoints();
886 AOPath(
string fullpath)
887 : _valid(
false), _path(fullpath), _raw(
false), _tmp(
false), _ref(
false) {
888 _valid = init(fullpath);
892 string path()
const {
return _path; }
895 string analysis()
const {
return _analysis; }
898 string analysisWithOptions()
const {
return _analysis + _optionstring; }
901 string name()
const {
return _name; }
904 string weight()
const {
return _weight; }
907 string weightComponent()
const {
908 if (_weight ==
"")
return _weight;
909 return "[" + _weight +
"]";
913 bool isRaw()
const {
return _raw; }
916 bool isTmp()
const {
return _tmp; }
919 bool isRef()
const {
return _ref; }
922 string optionString()
const {
return _optionstring; }
925 bool hasOptions()
const {
return !_options.empty(); }
928 void removeOption(
string opt) { _options.erase(opt); fixOptionString(); }
931 void setOption(
string opt,
string val) { _options[opt] = val; fixOptionString();}
934 bool hasOption(
string opt)
const {
return _options.find(opt) != _options.end(); }
937 string getOption(
string opt)
const {
938 auto it = _options.find(opt);
939 if ( it != _options.end() )
return it->second;
944 void fixOptionString();
947 string mkPath()
const;
948 string setPath() {
return _path = mkPath(); }
954 bool operator<(
const AOPath & other)
const {
955 return _path < other._path;
959 bool valid()
const {
return _valid; };
960 bool operator!()
const {
return !valid(); }
965 bool init(
string fullpath);
966 bool chopweight(
string & fullpath);
967 bool chopoptions(
string & anal);
972 string _optionstring;
978 map<string,string> _options;
Definition: MC_Cent_pPb.hh:10
bool aoadd(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src, double scale)
Definition: RivetYODA.hh:823
bool bookingCompatible(TPtr a, TPtr b)
Definition: RivetYODA.hh:849
bool copyao(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst, double scale=1.0)
Generic runtime Rivet error.
Definition: Exceptions.hh:12
This is the base class of all analysis classes in Rivet.
Definition: Analysis.hh:64
Definition: RivetYODA.hh:18
bool aocopy(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst, double scale)
Definition: RivetYODA.hh:813
pair< typename T::FillType, Weight > Fill
A single fill is a (FillType, Weight) pair.
Definition: RivetYODA.hh:49
The key class for coordination of Analysis objects and the event loop.
Definition: AnalysisHandler.hh:23
multiset< Fill< T > > Fills
Definition: RivetYODA.hh:54
map< string, YODA::AnalysisObjectPtr > getRefData(const string &papername)
BoolJetNOT operator!(const JetSelector &a)
Operator syntactic sugar for NOT construction.
Definition: JetUtils.hh:97
bool addaos(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src, double scale)
double Weight
Typedef for weights.
Definition: RivetYODA.hh:45
string getDatafilePath(const string &papername)
Get the file system path to the reference file for this paper.