HighLAND
EventWeightManager.hxx
1 #ifndef EventWeightManager_h
2 #define EventWeightManager_h
3 
4 #include "EventWeightBase.hxx"
5 #include "SelectionManager.hxx"
6 #include "TString.h"
7 #include "ToyExperiment.hxx"
8 
9 /// The maximum number of EventWeights that is supported.
10 const UInt_t NMAXEVENTWEIGHTS=100;
11 
12 /// Manager for EventWeights
13 /// This manager handles the registration, enabling and disabling of the
14 /// EventWeights.
16 
17 public:
18 
20  virtual ~EventWeightManager();
21 
22  /// Compute all eventWeights. Returns the total event normalization weight
23  Weight_h ComputeEventWeights(const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox );
24 
25  /// Compute all eventWeights. Returns the total event normalization weight and vector of weights as argument (one for each EventWeight)
26  Weight_h ComputeEventWeights(const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox, Weight_h* weights);
27 
28  /// Compute all eventWeights for a given selection. Returns the total event normalization weight and vector of weights as argument (one for each EventWeight)
29  Weight_h ComputeEventWeights(const SelectionBase& sel, const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox, Weight_h* weights);
30 
31  /// Compute EventWeight with a given index. Returns the event normalization weight
32  Weight_h ComputeEventWeight(Int_t index, const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox);
33 
34  /// Get the EventWeight registered with the given name.
35  EventWeightBase* GetEventWeight(const std::string& name) const;
36 
37  /// Get the EventWeight registered with the given index.
38  EventWeightBase* GetEventWeight(Int_t index) const;
39 
40  /// Get the index of a EventWeight registered with the given name.
41  Int_t GetEventWeightIndex(const std::string& name);
42 
43  /// Get the vector of EventWeights
44  std::vector<EventWeightBase*>& GetEventWeights(){return _eventWeights;}
45 
46  /// Get the vector containing EventWeights with specific indices
47  std::vector<EventWeightBase*> GetEventWeights(const std::vector<Int_t>& indices) const;
48 
49  /// Enable the EventWeight registered with the given index
50  void EnableEventWeight(Int_t index);
51 
52  /// Disable the EventWeight registered with the given index
53  void DisableEventWeight(Int_t index);
54 
55  /// Enable the EventWeights registered with the given indices
56  void EnableEventWeights(const std::vector<Int_t>& systs);
57 
58  /// Disable the EventWeights registered with the given indices
59  void DisableEventWeights(const std::vector<Int_t>& systs);
60 
61  /// Disable all eventWeights
63 
64  /// Enable all EventWeight eventWeights
65  void EnableAllEventWeights();
66 
67  /// Add a new Event Weight provided its index in the manager and a pointer to it
68  void AddEventWeight(Int_t index, EventWeightBase* sys);
69 
70  /// Add a new Event Weight provided its index in the manager, its name and a pointer to it
71  void AddEventWeight(Int_t index, const std::string& name, EventWeightBase* sys);
72 
73  /// Replace one of the existing EventWeightBase
74  void ReplaceEventWeight(Int_t index, EventWeightBase* sys);
75 
76  /// Fill the SystBox for the enabled EventWeights
77  void InitializeEvent(SelectionManager& sel, AnaEventC& event);
78 
79  /// Delete the SystBox for all EventWeights
80  void FinalizeEvent(AnaEventC& event);
81 
82  // Create the arrays of SystBox's
83  void Initialize(SelectionManager& sel,Int_t nevents);
84 
85  /// Is there any EventWeight added ?
86  bool HasEventWeights() const {return (_eventWeights.size()!=0);}
87 
88  /// Returns the number of EventWeights
89  UInt_t GetNEventWeights() const {return _eventWeights.size();}
90 
91  /// Returns the vector of indices for all enabled EventWeights
92  const Int_t* GetEnabledEventWeights(int& nSys){
93  nSys = _nEventWeightsEnabled;
94  return _eventWeightsEnabled;
95  }
96 
97  /// Returns the number of enabled EventWeights
98  UInt_t GetNEnabledEventWeights(){ return _nEventWeightsEnabled;}
99 
100  /// Dump all eventWeights
101  void DumpEventWeights();
102 
103  /// Check if an EventWeight with a given name already exists in the manager
104  bool HasEventWeight(const std::string& name);
105 
106 protected:
107 
108  /// The systematics that were registered as eventWeights.
109  std::vector<EventWeightBase*> _eventWeights;
110 
111  /// The systematics that were registered as eventWeights.
112  std::vector<EventWeightBase*> _eventWeightsWithNull;
113 
114  /// The weight systematics that are enabled
115  Int_t _eventWeightsEnabled[NMAXEVENTWEIGHTS];
116  int _nEventWeightsEnabled;
117 };
118 
119 #endif
Int_t GetEventWeightIndex(const std::string &name)
Get the index of a EventWeight registered with the given name.
UInt_t GetNEnabledEventWeights()
Returns the number of enabled EventWeights.
void DumpEventWeights()
Dump all eventWeights.
EventWeightBase * GetEventWeight(const std::string &name) const
Get the EventWeight registered with the given name.
Int_t _eventWeightsEnabled[NMAXEVENTWEIGHTS]
The weight systematics that are enabled.
std::vector< EventWeightBase * > _eventWeights
The systematics that were registered as eventWeights.
UInt_t GetNEventWeights() const
Returns the number of EventWeights.
void InitializeEvent(SelectionManager &sel, AnaEventC &event)
Fill the SystBox for the enabled EventWeights.
std::vector< EventWeightBase * > _eventWeightsWithNull
The systematics that were registered as eventWeights.
void ReplaceEventWeight(Int_t index, EventWeightBase *sys)
Replace one of the existing EventWeightBase.
void FinalizeEvent(AnaEventC &event)
Delete the SystBox for all EventWeights.
void DisableEventWeights(const std::vector< Int_t > &systs)
Disable the EventWeights registered with the given indices.
void EnableAllEventWeights()
Enable all EventWeight eventWeights.
void DisableAllEventWeights()
Disable all eventWeights.
Weight_h ComputeEventWeight(Int_t index, const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &ToyBox)
Compute EventWeight with a given index. Returns the event normalization weight.
bool HasEventWeights() const
Is there any EventWeight added ?
void AddEventWeight(Int_t index, EventWeightBase *sys)
Add a new Event Weight provided its index in the manager and a pointer to it.
std::vector< EventWeightBase * > & GetEventWeights()
Get the vector of EventWeights.
void EnableEventWeight(Int_t index)
Enable the EventWeight registered with the given index.
void EnableEventWeights(const std::vector< Int_t > &systs)
Enable the EventWeights registered with the given indices.
Weight_h ComputeEventWeights(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &ToyBox)
Compute all eventWeights. Returns the total event normalization weight.
const Int_t * GetEnabledEventWeights(int &nSys)
Returns the vector of indices for all enabled EventWeights.
bool HasEventWeight(const std::string &name)
Check if an EventWeight with a given name already exists in the manager.
void DisableEventWeight(Int_t index)
Disable the EventWeight registered with the given index.