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;
37 class AnalysisObjectWrapper {
39 virtual ~AnalysisObjectWrapper() {}
41 virtual YODA::AnalysisObject* operator->() = 0;
42 virtual YODA::AnalysisObject* operator->()
const = 0;
43 virtual const YODA::AnalysisObject & operator*()
const = 0;
46 virtual void setActiveWeightIdx(
unsigned int iWeight) = 0;
49 virtual void setActiveFinalWeightIdx(
unsigned int iWeight) = 0;
51 virtual void unsetActiveWeight() = 0;
53 bool operator ==(
const AnalysisObjectWrapper& p) {
return (
this == &p); }
54 bool operator !=(
const AnalysisObjectWrapper& p) {
return (
this != &p); }
139 class MultiweightAOWrapper :
public AnalysisObjectWrapper {
142 using Inner = YODA::AnalysisObject;
144 virtual void newSubEvent() = 0;
146 virtual void pushToPersistent(
const vector<std::valarray<double> >& weight,
147 double nlowfrac = 0.0) = 0;
148 virtual void pushToFinal() = 0;
150 virtual YODA::AnalysisObjectPtr activeYODAPtr()
const = 0;
152 virtual string basePath()
const = 0;
156 using Weight = double;
159 using Fill = pair<typename T::FillType, Weight>;
162 using Fills = multiset<Fill<T>>;
176 class TupleWrapper<
YODA::Counter> :
public YODA::Counter {
178 typedef shared_ptr<TupleWrapper<YODA::Counter>> Ptr;
179 TupleWrapper(
const YODA::Counter & h) :
YODA::Counter(h) {}
181 void fill(
double weight=1.0,
double fraction=1.0 ) {
183 fills_.insert( {YODA::Counter::FillType(),weight} );
185 void reset() { fills_.clear(); }
186 const Fills<YODA::Counter> & fills()
const {
return fills_; }
189 Fills<YODA::Counter> fills_;
193 class TupleWrapper<
YODA::Histo1D> :
public YODA::Histo1D {
195 typedef shared_ptr<TupleWrapper<YODA::Histo1D>> Ptr;
196 TupleWrapper(
const YODA::Histo1D & h) :
YODA::Histo1D(h) {}
198 void fill(
double x,
double weight=1.0,
double fraction=1.0 ) {
200 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
201 fills_.insert( { x , weight } );
203 void reset() { fills_.clear(); }
204 const Fills<YODA::Histo1D> & fills()
const {
return fills_; }
207 Fills<YODA::Histo1D> fills_;
211 class TupleWrapper<
YODA::Profile1D> :
public YODA::Profile1D {
213 typedef shared_ptr<TupleWrapper<YODA::Profile1D>> Ptr;
214 TupleWrapper(
const YODA::Profile1D & h) :
YODA::Profile1D(h) {}
216 void fill(
double x,
double y,
double weight=1.0,
double fraction=1.0 ) {
218 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
219 if ( std::isnan(y) )
throw YODA::RangeError(
"Y is NaN");
220 fills_.insert( { YODA::Profile1D::FillType{x,y}, weight } );
222 void reset() { fills_.clear(); }
223 const Fills<YODA::Profile1D> & fills()
const {
return fills_; }
226 Fills<YODA::Profile1D> fills_;
231 class TupleWrapper<
YODA::Histo2D> :
public YODA::Histo2D {
233 typedef shared_ptr<TupleWrapper<YODA::Histo2D>> Ptr;
234 TupleWrapper(
const YODA::Histo2D & h) :
YODA::Histo2D(h) {}
236 void fill(
double x,
double y,
double weight=1.0,
double fraction=1.0 ) {
238 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
239 if ( std::isnan(y) )
throw YODA::RangeError(
"Y is NaN");
240 fills_.insert( { YODA::Histo2D::FillType{x,y}, weight } );
242 void reset() { fills_.clear(); }
243 const Fills<YODA::Histo2D> & fills()
const {
return fills_; }
246 Fills<YODA::Histo2D> fills_;
250 class TupleWrapper<
YODA::Profile2D> :
public YODA::Profile2D {
252 typedef shared_ptr<TupleWrapper<YODA::Profile2D>> Ptr;
253 TupleWrapper(
const YODA::Profile2D & h) :
YODA::Profile2D(h) {}
255 void fill(
double x,
double y,
double z,
double weight=1.0,
double fraction=1.0 ) {
257 if ( std::isnan(x) )
throw YODA::RangeError(
"X is NaN");
258 if ( std::isnan(y) )
throw YODA::RangeError(
"Y is NaN");
259 if ( std::isnan(z) )
throw YODA::RangeError(
"Z is NaN");
260 fills_.insert( { YODA::Profile2D::FillType{x,y,z}, weight } );
262 void reset() { fills_.clear(); }
263 const Fills<YODA::Profile2D> & fills()
const {
return fills_; }
266 Fills<YODA::Profile2D> fills_;
270 class TupleWrapper<
YODA::Scatter1D> :
public YODA::Scatter1D {
272 typedef shared_ptr<TupleWrapper<YODA::Scatter1D>> Ptr;
273 TupleWrapper(
const YODA::Scatter1D & h) :
YODA::Scatter1D(h) {}
277 class TupleWrapper<
YODA::Scatter2D> :
public YODA::Scatter2D {
279 typedef shared_ptr<TupleWrapper<YODA::Scatter2D>> Ptr;
280 TupleWrapper(
const YODA::Scatter2D & h) :
YODA::Scatter2D(h) {}
284 class TupleWrapper<
YODA::Scatter3D> :
public YODA::Scatter3D {
286 typedef shared_ptr<TupleWrapper<YODA::Scatter3D>> Ptr;
287 TupleWrapper(
const YODA::Scatter3D & h) :
YODA::Scatter3D(h) {}
293 class Wrapper :
public MultiweightAOWrapper {
294 friend class Analysis;
307 Wrapper(
const vector<string>& weightnames,
const T & p);
311 typename T::Ptr active()
const;
314 bool operator!()
const {
return !_active; }
316 explicit operator bool()
const {
return static_cast<bool>(_active); }
318 T * operator->() {
return active().get(); }
320 T * operator->()
const {
return active().get(); }
322 T & operator*() {
return *active(); }
324 const T & operator*()
const {
return *active(); }
327 T * _getPersistent (
unsigned int iWeight) {
return _persistent.at(iWeight).get(); }
329 string basePath()
const {
return _basePath; }
331 string baseName()
const {
return _baseName; }
380 void setActiveWeightIdx(
unsigned int iWeight) {
381 _active = _persistent.at(iWeight);
384 void setActiveFinalWeightIdx(
unsigned int iWeight) {
385 _active = _final.at(iWeight);
390 void unsetActiveWeight() { _active.reset(); }
394 virtual YODA::AnalysisObjectPtr activeYODAPtr()
const {
return _active; }
396 const vector<typename T::Ptr> & persistent()
const {
return _persistent; }
398 const vector<typename T::Ptr> &
final()
const {
return _final; }
401 void pushToPersistent(
const vector<std::valarray<double> >& weight,
402 double nlowfrac = 0.0);
407 vector<typename T::Ptr> _persistent;
410 vector<typename T::Ptr> _final;
413 vector<typename TupleWrapper<T>::Ptr> _evgroup;
415 typename T::Ptr _active;
426 friend class AnalysisHandler;
435 template <
typename T>
436 class rivet_shared_ptr {
438 typedef T value_type;
440 rivet_shared_ptr() =
default;
442 rivet_shared_ptr(decltype(
nullptr)) : _p(nullptr) {}
445 rivet_shared_ptr(
const vector<string>& weightNames,
const typename T::Inner & p)
446 : _p( make_shared<T>(weightNames, p) )
449 template <
typename U>
450 rivet_shared_ptr(
const shared_ptr<U> & p)
454 template <
typename U>
455 rivet_shared_ptr(
const rivet_shared_ptr<U> & p)
461 if (_p ==
nullptr)
throw Error(
"Dereferencing null AnalysisObject pointer. Is there an unbooked histogram variable?");
464 const T & operator->()
const {
465 if (_p ==
nullptr)
throw Error(
"Dereferencing null AnalysisObject pointer. Is there an unbooked histogram variable?");
470 typename T::Inner & operator*() {
return **_p; }
471 const typename T::Inner & operator*()
const {
return **_p; }
473 bool operator!()
const {
return !_p || !(*_p); }
474 explicit operator bool()
const {
return _p && bool(*_p); }
476 template <
typename U>
477 bool operator==(
const rivet_shared_ptr<U> & other)
const {
478 return _p == other._p;
481 template <
typename U>
482 bool operator!=(
const rivet_shared_ptr<U> & other)
const {
483 return _p != other._p;
486 template <
typename U>
487 bool operator<(const rivet_shared_ptr<U> & other)
const {
488 return _p < other._p;
491 template <
typename U>
492 bool operator>(
const rivet_shared_ptr<U> & other)
const {
493 return _p > other._p;
496 template <
typename U>
497 bool operator<=(const rivet_shared_ptr<U> & other)
const {
498 return _p <= other._p;
501 template <
typename U>
502 bool operator>=(
const rivet_shared_ptr<U> & other)
const {
503 return _p >= other._p;
506 shared_ptr<T>
get()
const {
return _p; }
518 using MultiweightAOPtr = rivet_shared_ptr<MultiweightAOWrapper>;
520 using Histo1DPtr = rivet_shared_ptr<Wrapper<YODA::Histo1D>>;
521 using Histo2DPtr = rivet_shared_ptr<Wrapper<YODA::Histo2D>>;
522 using Profile1DPtr = rivet_shared_ptr<Wrapper<YODA::Profile1D>>;
523 using Profile2DPtr = rivet_shared_ptr<Wrapper<YODA::Profile2D>>;
524 using CounterPtr = rivet_shared_ptr<Wrapper<YODA::Counter>>;
525 using Scatter1DPtr = rivet_shared_ptr<Wrapper<YODA::Scatter1D>>;
526 using Scatter2DPtr = rivet_shared_ptr<Wrapper<YODA::Scatter2D>>;
527 using Scatter3DPtr = rivet_shared_ptr<Wrapper<YODA::Scatter3D>>;
531 using YODA::HistoBin1D;
533 using YODA::HistoBin2D;
534 using YODA::Profile1D;
535 using YODA::ProfileBin1D;
536 using YODA::Profile2D;
537 using YODA::ProfileBin2D;
538 using YODA::Scatter1D;
540 using YODA::Scatter2D;
542 using YODA::Scatter3D;
547 map<string, YODA::AnalysisObjectPtr>
getRefData(
const string& papername);
557 template<
typename T>
struct ReferenceTraits {};
558 template<>
struct ReferenceTraits<Counter> {
typedef Counter RefT; };
559 template<>
struct ReferenceTraits<Scatter1D> {
typedef Scatter1D RefT; };
560 template<>
struct ReferenceTraits<Histo1D> {
typedef Scatter2D RefT; };
561 template<>
struct ReferenceTraits<Profile1D> {
typedef Scatter2D RefT; };
562 template<>
struct ReferenceTraits<Scatter2D> {
typedef Scatter2D RefT; };
563 template<>
struct ReferenceTraits<Histo2D> {
typedef Scatter3D RefT; };
564 template<>
struct ReferenceTraits<Profile2D> {
typedef Scatter3D RefT; };
565 template<>
struct ReferenceTraits<Scatter3D> {
typedef Scatter3D RefT; };
571 template <
typename T>
572 inline bool aocopy(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst) {
573 shared_ptr<T> tsrc = dynamic_pointer_cast<T>(src);
574 if ( !tsrc )
return false;
575 shared_ptr<T> tdst = dynamic_pointer_cast<T>(dst);
576 if ( !tdst )
return false;
584 template <
typename T>
585 inline bool aoadd(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src,
double scale) {
586 shared_ptr<T> tsrc = dynamic_pointer_cast<T>(src);
587 if ( !tsrc )
return false;
588 shared_ptr<T> tdst = dynamic_pointer_cast<T>(dst);
589 if ( !tdst )
return false;
597 bool copyao(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst);
602 bool addaos(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src,
double scale);
606 template <
typename TPtr>
608 return a->sameBinning(*b);
614 return a->numPoints() == b->numPoints();
617 return a->numPoints() == b->numPoints();
620 return a->numPoints() == b->numPoints();
626 return a->numPoints() == b->numPoints();
629 return a->numPoints() == b->numPoints();
632 return a->numPoints() == b->numPoints();
641 AOPath(
string fullpath)
642 : _valid(
false), _path(fullpath), _raw(
false), _tmp(
false), _ref(
false) {
643 _valid = init(fullpath);
647 string path()
const {
return _path; }
650 string analysis()
const {
return _analysis; }
653 string analysisWithOptions()
const {
return _analysis + _optionstring; }
656 string name()
const {
return _name; }
659 string weight()
const {
return _weight; }
662 bool isRaw()
const {
return _raw; }
665 bool isTmp()
const {
return _tmp; }
668 bool isRef()
const {
return _ref; }
671 string optionString()
const {
return _optionstring; }
674 bool hasOptions()
const {
return !_options.empty(); }
677 void removeOption(
string opt) { _options.erase(opt); fixOptionString(); }
680 void setOption(
string opt,
string val) { _options[opt] = val; fixOptionString();}
683 bool hasOption(
string opt)
const {
return _options.find(opt) != _options.end(); }
686 string getOption(
string opt)
const {
687 auto it = _options.find(opt);
688 if ( it != _options.end() )
return it->second;
693 void fixOptionString();
696 string mkPath()
const;
697 string setPath() {
return _path = mkPath(); }
703 bool operator<(
const AOPath & other)
const {
704 return _path < other._path;
708 bool valid()
const {
return _valid; };
709 bool operator!()
const {
return !valid(); }
714 bool init(
string fullpath);
715 bool chopweight(
string & fullpath);
716 bool chopoptions(
string & anal);
721 string _optionstring;
727 map<string,string> _options;
Definition: MC_Cent_pPb.hh:10
bool bookingCompatible(TPtr a, TPtr b)
Definition: RivetYODA.hh:607
bool operator==(const Cut &a, const Cut &b)
Compare two cuts for equality, forwards to the cut-specific implementation.
Definition: Cuts.hh:44
map< string, YODA::AnalysisObjectPtr > getRefData(const string &papername)
string getDatafilePath(const string &papername)
Get the file system path to the reference file for this paper.
bool addaos(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src, double scale)
Definition: RivetYODA.hh:18
bool aoadd(YODA::AnalysisObjectPtr dst, YODA::AnalysisObjectPtr src, double scale)
Definition: RivetYODA.hh:585
bool aocopy(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst)
Definition: RivetYODA.hh:572
BoolJetNOT operator!(const JetSelector &a)
Operator syntactic sugar for NOT construction.
Definition: JetUtils.hh:97
bool copyao(YODA::AnalysisObjectPtr src, YODA::AnalysisObjectPtr dst)