HighLAND
SystematicManager.hxx
1 #ifndef SystematicManager_h
2 #define SystematicManager_h
3 
4 #include "EventVariationBase.hxx"
5 #include "EventWeightBase.hxx"
6 #include "SystematicCovariance.hxx"
7 #include "SelectionManager.hxx"
8 #include "TRandom3.h"
9 #include "TString.h"
10 #include "HLClonesArray.hxx"
11 #include "ToyExperiment.hxx"
12 
14 
15 /// The maximum number of systematics that is supported.
16 //const int NMAXSYSTEMATICS=30;
17 
18 /// Manager for Systematics. A systematic can be of type "variation" or "weight". The former
19 /// modifies a particular aspect of the Input data. The last computes a event weight.
20 /// Two different base classes are used EventVariationBase and EventWeightBase
21 
22 /// This manager handles the registration, enabling and disabling of the
23 /// systematics.
25 
26 public:
27 
29  virtual ~SystematicManager();
30 
31  /// Apply all variationSystematics
32  void ApplyVariationSystematics(const ToyExperiment& toy, AnaEventC& event);
33 
34  /// Aplpy all weightSystematics. Returns the total event normalization weight
35  Weight_h ApplyWeightSystematics(const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox );
36 
37  /// Apply all weightSystematics. Returns the total event normalization weight and vector of weights as argument (one for each systematic parameter)
38  Weight_h ApplyWeightSystematics(const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox, Weight_h* weights);
39 
40  /// Apply all weightSystematics for a given selection. Returns the total event normalization weight and vector of weights as argument (one for each systematic parameter)
41  Weight_h ApplyWeightSystematics(const SelectionBase& sel, const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox, Weight_h* weights);
42 
43  /// Apply all fluxSystematics. Returns the total event Weight
44  Weight_h ApplyFluxSystematics(const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox);
45 
46  /// Apply weight Systematics with a given index. Returns the event normalization weight
47  Weight_h ApplyWeightSystematic(Int_t index, const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& ToyBox);
48 
49  /// Undo the variation systematic (Undo the variation, that is, go back to the previous values of modified observables
51 
52  /// Get the systematic registered with the given name.
53  EventVariationBase* GetSystematicVariation(const std::string& name) const;
54  EventWeightBase* GetSystematicWeight(const std::string& name) const;
55  EventWeightBase* GetSystematicFlux(const std::string& name) const;
56  SystematicBase* GetSystematic(const std::string& name) const;
57 
58  /// Get the systematic registered with the given index.
59  EventVariationBase* GetSystematicVariation(Int_t index) const;
60  EventWeightBase* GetSystematicWeight(Int_t index) const;
61  EventWeightBase* GetSystematicFlux(Int_t index) const;
62  SystematicBase* GetSystematic(Int_t index) const;
63 
64  /// Get the index of a systematic registered with the given name.
65  Int_t GetSystematicVariationIndex(const std::string& name);
66  Int_t GetSystematicWeightIndex(const std::string& name);
67  Int_t GetSystematicFluxIndex(const std::string& name);
68 
69  /// Get the vector of variationSystematics
71  nSys = _nVariationSystematics;
72  return _variationSystematics;
73  }
74 
75  /// Get the vector of weightsSystematics
77  nSys = _nWeightSystematics;
78  return _weightSystematics;
79  }
80 
81  /// Get the vector of fluxSystematics
83  nSys = _nFluxSystematics;
84  return _fluxSystematics;
85  }
86 
87  /// Get the vector containing all systematics (contains NULL pointers)
88  std::vector<SystematicBase*>& GetSystematics() {
89  return _systematics;
90  }
91 
92  /// Get the vector containing systematics with specific indices
93  std::vector<SystematicBase*> GetSystematics(const std::vector<Int_t>& indices) const;
94 
95  /// Enable the systematic registered with the given index
96  void EnableSystematic(Int_t index);
97 
98  /// Disable the systematic registered with the given index
99  void DisableSystematic(Int_t index);
100 
101  /// Enable the systematics registered with the given indices
102  void EnableSystematics(const std::vector<Int_t>& systs);
103 
104  /// Disable the systematics registered with the given indices
105  void DisableSystematics(const std::vector<Int_t>& systs);
106 
107  /// Disable all variationSystematics
109 
110  /// Enable all variationSystematics
112 
113  /// Disable all weightSystematics
115 
116  /// Enable all systematic weightSystematics
118 
119  /// Disable all fluxSystematics
121 
122  /// Enable all systematic fluxSystematics
124 
125  /// Disable all Systematics
126  void DisableAllSystematics();
127 
128  /// Enable all Systematics
129  void EnableAllSystematics();
130 
131  /// Register an EventVariationBase as a variation systematic
132  void AddVariationSystematic(Int_t index, EventVariationBase* sys);
133 
134  /// Register an EventVariationBase as a variation systematic provided the index and name
135  void AddVariationSystematic(Int_t index, const std::string& name, EventVariationBase* sys);
136 
137  /// Replace one of the existing EventVariationBase
138  void ReplaceVariationSystematic(Int_t index, EventVariationBase* sys);
139 
140  /// Register an SystematicBase as a weight systematic
141  void AddWeightSystematic(Int_t index, EventWeightBase* sys);
142 
143  /// Register an SystematicBase as a weight systematic provided the index and name
144  void AddWeightSystematic(Int_t index, const std::string& name, EventWeightBase* sys);
145 
146  /// Replace one of the existing EventWeightBase
147  void ReplaceWeightSystematic(Int_t index, EventWeightBase* sys);
148 
149  /// Register an SystematicBase as a flux systematic
150  void AddFluxSystematic(Int_t index, EventWeightBase* sys);
151 
152  /// Register an SystematicBase as a flux systematic
153  void AddFluxSystematic(Int_t index, const std::string& name, EventWeightBase* sys);
154 
155  /// Replace one of the existing EventWeightBase
156  void ReplaceFluxSystematic(Int_t index, EventWeightBase* sys);
157 
158  // Delete the SystBox for all systematics
159  void FinalizeEventSystematics(AnaEventC& event);
160 
161  // Fill the SystBox for the enabled systematics
162  void InitializeEventSystematics(SelectionManager& sel, AnaEventC& event);
163 
164  // Create the arrays of SysteBox's
165  void Initialize(SelectionManager& sel,Int_t nevents);
166 
167  /// Is there any systematic added ?
168  bool HasSystematics() const {return (_nVariationSystematics+_nWeightSystematics+_nFluxSystematics!=0);}
169 
170  /// Returns the number of VariationSystematics
171  UInt_t GetNVariationSystematics() const {return _nVariationSystematics;}
172 
173  /// Returns the number of WeightSystematics
174  UInt_t GetNWeightSystematics() const {return _nWeightSystematics;}
175 
176  /// Returns the number of Flux Systematics
177  UInt_t GetNFluxSystematics() const {return _nFluxSystematics;}
178 
179  /// Returns the vector of indices for all enabled weight systematics
180  const Int_t* GetEnabledWeightSystematics(int& nSys){
181  nSys = _nWeightSystematicsEnabled;
183  }
184 
185  /// Returns the number of enabled weight systematics
186  UInt_t GetNEnabledWeightSystematics(){ return _nWeightSystematicsEnabled;}
187 
188  /// Returns the vector of indices for all enabled variation systematics
189  const Int_t* GetEnabledVariationSystematics(int& nSys){
190  nSys = _nVariationSystematicsEnabled;
192  }
193 
194  /// Returns the number of enabled variation systematics
195  UInt_t GetNEnabledVariationSystematics(){ return _nVariationSystematicsEnabled;}
196 
197  /// Read the systematics from a file
198  void ReadSystematics(const std::string& file);
199 
200  /// Dump all systematics
201  void DumpSystematics();
202 
203  /// Dump all variationSystematics
205 
206  /// Dump all weightSystematics
207  void DumpWeightSystematics();
208 
209  /// Dump all fluxSystematics
210  void DumpFluxSystematics();
211 
212  /// Gets the PDF bin for a systematic variation with a given with index
213  Int_t GetPDFBin(int syst);
214 
215  /// Sets the PDF bin for a systematic variation with a given with index
216  void SetPDFBin(int syst, int bin);
217 
218  /// Check if a systematic already exists
219  bool HasSystematic(const std::string& name);
220 
221  /// Make the covariance
223 
224  /// Get the covariance matrix
225  TMatrixT<double>* GetCovarianceMatrix() const;
226 
227 
228 protected:
229 
230  /// The systematics that were registered as variationSystematics.
232  int _nVariationSystematics;
233 
234  /// The systematics that were registered as weightSystematics.
235  EventWeightBase* _weightSystematics[NMAXSYSTEMATICS]; //!
236  int _nWeightSystematics;
237 
238  /// The systematics that were registered as fluxSystematics.
239  EventWeightBase* _fluxSystematics[NMAXSYSTEMATICS]; //!
240  int _nFluxSystematics;
241 
242  /// The systematics that were registered
243  std::vector<SystematicBase*> _systematics;
244 
245  /// The variation systematics that are enabled
246  Int_t _variationSystematicsEnabled[NMAXSYSTEMATICS];
247  int _nVariationSystematicsEnabled;
248 
249  /// The weight systematics that are enabled
250  Int_t _weightSystematicsEnabled[NMAXSYSTEMATICS];
251  int _nWeightSystematicsEnabled;
252 
253  /// The weight systematics that are enabled
254  Int_t _fluxSystematicsEnabled[NMAXSYSTEMATICS];
255  int _nFluxSystematicsEnabled;
256 
257  /// A random generator that can be used to generate throws.
258  TRandom3 _RandomGenerator; //!
259 
260  ///The associated systematic covariance
262 
263 };
264 
265 #endif
bool UndoVariationSystematics(AnaEventC &event)
Undo the variation systematic (Undo the variation, that is, go back to the previous values of modifie...
TRandom3 _RandomGenerator
A random generator that can be used to generate throws.
TMatrixT< double > * GetCovarianceMatrix() const
Get the covariance matrix.
void AddWeightSystematic(Int_t index, EventWeightBase *sys)
Register an SystematicBase as a weight systematic.
void DisableAllFluxSystematics()
Disable all fluxSystematics.
EventWeightBase * _weightSystematics[NMAXSYSTEMATICS]
The systematics that were registered as weightSystematics.
UInt_t GetNEnabledWeightSystematics()
Returns the number of enabled weight systematics.
void DisableAllVariationSystematics()
Disable all variationSystematics.
void DumpFluxSystematics()
Dump all fluxSystematics.
void DisableAllWeightSystematics()
Disable all weightSystematics.
void EnableAllSystematics()
Enable all Systematics.
UInt_t GetNVariationSystematics() const
Returns the number of VariationSystematics.
void ReplaceFluxSystematic(Int_t index, EventWeightBase *sys)
Replace one of the existing EventWeightBase.
EventVariationBase * _variationSystematics[NMAXSYSTEMATICS]
The systematics that were registered as variationSystematics.
EventVariationBase ** GetVariationSystematics(int &nSys)
Get the vector of variationSystematics.
const Int_t * GetEnabledWeightSystematics(int &nSys)
Returns the vector of indices for all enabled weight systematics.
void ReplaceVariationSystematic(Int_t index, EventVariationBase *sys)
Replace one of the existing EventVariationBase.
void EnableSystematic(Int_t index)
Enable the systematic registered with the given index.
Int_t GetPDFBin(int syst)
Gets the PDF bin for a systematic variation with a given with index.
void DumpVariationSystematics()
Dump all variationSystematics.
void AddFluxSystematic(Int_t index, EventWeightBase *sys)
Register an SystematicBase as a flux systematic.
Int_t _fluxSystematicsEnabled[NMAXSYSTEMATICS]
The weight systematics that are enabled.
Int_t _variationSystematicsEnabled[NMAXSYSTEMATICS]
The variation systematics that are enabled.
void ReplaceWeightSystematic(Int_t index, EventWeightBase *sys)
Replace one of the existing EventWeightBase.
Int_t GetSystematicVariationIndex(const std::string &name)
Get the index of a systematic registered with the given name.
SystematicCovariance * _covariance
The associated systematic covariance.
void DisableSystematic(Int_t index)
Disable the systematic registered with the given index.
void DumpSystematics()
Dump all systematics.
const Int_t * GetEnabledVariationSystematics(int &nSys)
Returns the vector of indices for all enabled variation systematics.
UInt_t GetNWeightSystematics() const
Returns the number of WeightSystematics.
Weight_h ApplyFluxSystematics(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &ToyBox)
Apply all fluxSystematics. Returns the total event Weight.
Weight_h ApplyWeightSystematics(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &ToyBox)
Aplpy all weightSystematics. Returns the total event normalization weight.
bool HasSystematics() const
Is there any systematic added ?
std::vector< SystematicBase * > _systematics
The systematics that were registered.
The maximum number of systematics that is supported.
Weight_h ApplyWeightSystematic(Int_t index, const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &ToyBox)
Apply weight Systematics with a given index. Returns the event normalization weight.
void ApplyVariationSystematics(const ToyExperiment &toy, AnaEventC &event)
Apply all variationSystematics.
void SetPDFBin(int syst, int bin)
Sets the PDF bin for a systematic variation with a given with index.
void ConstructCovarianceMatrix()
Make the covariance.
UInt_t GetNEnabledVariationSystematics()
Returns the number of enabled variation systematics.
std::vector< SystematicBase * > & GetSystematics()
Get the vector containing all systematics (contains NULL pointers)
bool HasSystematic(const std::string &name)
Check if a systematic already exists.
void DisableAllSystematics()
Disable all Systematics.
EventWeightBase ** GetWeightSystematics(int &nSys)
Get the vector of weightsSystematics.
void EnableAllFluxSystematics()
Enable all systematic fluxSystematics.
EventWeightBase ** GetFluxSystematics(int &nSys)
Get the vector of fluxSystematics.
void DumpWeightSystematics()
Dump all weightSystematics.
EventVariationBase * GetSystematicVariation(const std::string &name) const
Get the systematic registered with the given name.
Int_t _weightSystematicsEnabled[NMAXSYSTEMATICS]
The weight systematics that are enabled.
void DisableSystematics(const std::vector< Int_t > &systs)
Disable the systematics registered with the given indices.
void EnableSystematics(const std::vector< Int_t > &systs)
Enable the systematics registered with the given indices.
UInt_t GetNFluxSystematics() const
Returns the number of Flux Systematics.
EventWeightBase * _fluxSystematics[NMAXSYSTEMATICS]
The systematics that were registered as fluxSystematics.
void ReadSystematics(const std::string &file)
Read the systematics from a file.
void EnableAllWeightSystematics()
Enable all systematic weightSystematics.
void AddVariationSystematic(Int_t index, EventVariationBase *sys)
Register an EventVariationBase as a variation systematic.
void EnableAllVariationSystematics()
Enable all variationSystematics.