JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwCombinedBPM.h
Go to the documentation of this file.
1/*!
2 * \file QwCombinedBPM.h
3 * \brief Combined beam position monitor using weighted average
4 * \author B. Waidyawansa
5 */
6
7#pragma once
8
9// System headers
10#include <vector>
11
12// ROOT headers
13#include <TTree.h>
14#ifdef HAS_RNTUPLE_SUPPORT
15#include "ROOT/RNTupleModel.hxx"
16#include "ROOT/RField.hxx"
17#endif // HAS_RNTUPLE_SUPPORT
18
19// Qweak headers
20#include "VQwHardwareChannel.h"
21#include "VQwBPM.h"
22#include "QwUtil.h"
23
24// Forward declarations
25#ifdef __USE_DATABASE__
26class QwDBInterface;
27#endif // __USE_DATABASE__
28class QwParameterFile;
29
30/**
31 * \class QwCombinedBPM
32 * \ingroup QwAnalysis_BL
33 * \brief Template for combined beam position monitor using multiple BPMs
34 *
35 * Maintains a weighted combination of individual BPMs to estimate
36 * position and angle at a virtual location, supporting fits and
37 * effective charge computation.
38 */
39template<typename T>
40class QwCombinedBPM : public VQwBPM {
41 friend class QwEnergyCalculator;
42
43 /////
44 public:
45
46//-------------------------------------------------------------------------
47 size_t GetNumberOfElements() override {return fElement.size();};
48 TString GetSubElementName(Int_t index) override {return fElement.at(index)->GetElementName();};
49//-------------------------------------------------------------------------
50
52 };
53 QwCombinedBPM(TString name):VQwBPM(name){
55 };
56 QwCombinedBPM(TString subsystem, TString name): VQwBPM(name){
57 InitializeChannel(subsystem, name);
58 };
59
60 QwCombinedBPM(TString subsystem, TString name, TString type): VQwBPM(name){
61 InitializeChannel(subsystem, name,type);
62 };
72 ~QwCombinedBPM() override { };
73
75
76 void InitializeChannel(TString name);
77 // new routine added to update necessary information for tree trimming
78 void InitializeChannel(TString subsystem, TString name);
79 void InitializeChannel(TString subsystem, TString name, TString type) {
80 SetModuleType(type);
81 InitializeChannel(subsystem, name);
82 }
83
84 void LoadChannelParameters(QwParameterFile &paramfile) override{};
85 void ClearEventData() override;
86 Int_t ProcessEvBuffer(UInt_t* buffer,
87 UInt_t word_position_in_buffer,UInt_t indexnumber) override;
88 void ProcessEvent() override;
89 void PrintValue() const override;
90 void PrintInfo() const override;
91
93 if (axis<0 || axis>2){
94 TString loc="QwLinearDiodeArray::GetPosition for "
95 +this->GetElementName()+" failed for axis value "+Form("%d",axis);
96 throw std::out_of_range(loc.Data());
97 }
98 return &fAbsPos[axis];
99 }
100
102 if (axis<0 || axis>2){
103 TString loc="QwLinearDiodeArray::GetPosition for "
104 +this->GetElementName()+" failed for axis value "+Form("%d",axis);
105 throw std::out_of_range(loc.Data());
106 }
107 return &fSlope[axis];
108 }
109 const VQwHardwareChannel* GetEffectiveCharge() const override {
110 return &fEffectiveCharge;
111 }
112
113
114 Bool_t ApplyHWChecks();//Check for hardware errors in the devices
115 Bool_t ApplySingleEventCuts() override;//Check for good events by setting limits on the devices readings
116 //void SetSingleEventCuts(TString ch_name, Double_t minX, Double_t maxX);
117 /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
118 //void SetSingleEventCuts(TString ch_name, UInt_t errorflag,Double_t min, Double_t max, Double_t stability);
119 void SetEventCutMode(Int_t bcuts) override;
120 void IncrementErrorCounters() override;
121 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure
122 UInt_t GetEventcutErrorFlag() override;
123 UInt_t UpdateErrorFlag() override;
124 void UpdateErrorFlag(const VQwBPM *ev_error) override;
125
126 // Polymorphic burp-failure check when called via VQwBPM*
127 Bool_t CheckForBurpFail(const VQwDataElement *ev_error);
128
129
130 void SetBPMForCombo(const VQwBPM* bpm, Double_t charge_weight, Double_t x_weight, Double_t y_weight,Double_t sumqw) override;
131
132 void Ratio(QwCombinedBPM &numer, QwCombinedBPM &denom);
133 void Ratio(VQwBPM &numer, VQwBPM &denom) override;
134 void Scale(Double_t factor) override;
135
136 VQwBPM& operator= (const VQwBPM &value) override;
137 VQwBPM& operator+= (const VQwBPM &value) override;
138 VQwBPM& operator-= (const VQwBPM &value) override;
139
140 virtual QwCombinedBPM& operator= (const QwCombinedBPM &value);
141 virtual QwCombinedBPM& operator+= (const QwCombinedBPM &value);
142 virtual QwCombinedBPM& operator-= (const QwCombinedBPM &value);
143
144 void AccumulateRunningSum(const VQwBPM& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override;
145 void AccumulateRunningSum(const QwCombinedBPM& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
146 void DeaccumulateRunningSum(VQwBPM& value, Int_t ErrorMask=0xFFFFFFF) override;
147 void DeaccumulateRunningSum(QwCombinedBPM& value, Int_t ErrorMask=0xFFFFFFF);
148 void CalculateRunningAverage() override;
149
150 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
151 void FillHistograms() override;
152
153 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
154 void ConstructBranch(TTree *tree, TString &prefix) override;
155 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist) override;
156 void FillTreeVector(QwRootTreeBranchVector &values) const override;
157
158#ifdef HAS_RNTUPLE_SUPPORT
159 // RNTuple methods
160 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
161 void FillNTupleVector(std::vector<Double_t>& values) const override;
162#endif // HAS_RNTUPLE_SUPPORT
163
164//------------------------------------------------------------------------------------------------
165 void RandomizeEventData(int helicity = 0, double time = 0.0) override;
166 void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY,
167 Double_t meanXslope, Double_t sigmaXslope, Double_t meanYslope, Double_t sigmaYslope) override;
168 void GetProjectedPosition(VQwBPM *device) override;
169 void LoadMockDataParameters(QwParameterFile &paramfile) override;
170//------------------------------------------------------------------------------------------------
171
172 VQwHardwareChannel* GetAngleX(){ //At present this returns the slope not the angle
173 return &fSlope[0];
174 };
175
176 const VQwHardwareChannel* GetAngleX() const override { //At present this returns the slope not the angle
177 return const_cast<QwCombinedBPM*>(this)->GetAngleX();
178 };
179
180 VQwHardwareChannel* GetAngleY(){//At present this returns the slope not the angle
181 return &fSlope[1];
182 };
183
184 const VQwHardwareChannel* GetAngleY() const override { //At present this returns the slope not the angle
185 return const_cast<QwCombinedBPM*>(this)->GetAngleY();
186 };
187
188
189#ifdef __USE_DATABASE__
190 std::vector<QwDBInterface> GetDBEntry();
191 std::vector<QwErrDBInterface> GetErrDBEntry();
192#endif // __USE_DATABASE__
193
194 protected:
195 VQwHardwareChannel* GetSubelementByName(TString ch_name) override;
196
197 /* Functions for least square fit */
198 void CalculateFixedParameter(std::vector<Double_t> fWeights, Int_t pos);
199 Double_t SumOver( std::vector <Double_t> weight , std::vector <T> val);
200 void LeastSquareFit(VQwBPM::EBeamPositionMonitorAxis axis, std::vector<Double_t> fWeights) ; //bbbbb
201
202
203
204 /////
205 private:
207
208 //used for least squares fit
209 Double_t erra[2],errb[2],covab[2];
210 Double_t A[2], B[2], D[2], m[2];
211 Double_t chi_square[2];
212 Double_t fSumQweights;
213
214 std::vector <const VQwBPM*> fElement;
215 std::vector <Double_t> fQWeights;
216 std::vector <Double_t> fXWeights;
217 std::vector <Double_t> fYWeights;
218
219
220 protected:
221 /* This channel contains the beam slope w.r.t the X & Y axis at the target */
222 std::array<T,2> fSlope;//[2];
223
224 /* This channel contains the beam intercept w.r.t the X & Y axis at the target */
225 std::array<T,2> fIntercept;//[2];
226
227 /*This channel gives the minimum chisquare value for the fit over target bpms*/
228 std::array<T,2> fMinimumChiSquare;//[2];
229
230 // These are the "real" data elements, to which the base class
231 // fAbsPos_base and fEffectiveCharge_base are pointers.
232 std::array<T,2> fAbsPos;//[2];
234
235private:
236 // Functions to be removed
237 void MakeBPMComboList();
238 std::vector<T> fBPMComboElementList;
239
240};
Helper functions and utilities for analysis operations.
void QwCopyArray(const T &a, T &b)
Definition QwUtil.h:15
Virtual base class for beam position monitors.
Configuration file parser with flexible tokenization and search capabilities.
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:53
The pure virtual base class of all data elements.
virtual const TString & GetElementName() const
Get the name of this element.
void SetModuleType(TString ModuleType)
set the type of the beam instrument
Abstract base for concrete hardware channels implementing dual-operator pattern.
Template for combined beam position monitor using multiple BPMs.
void GetProjectedPosition(VQwBPM *device) override
void Scale(Double_t factor) override
void FillTreeVector(QwRootTreeBranchVector &values) const override
friend class QwEnergyCalculator
std::vector< Double_t > fQWeights
VQwBPM & operator-=(const VQwBPM &value) override
Bool_t ApplyHWChecks()
size_t GetNumberOfElements() override
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t indexnumber) override
Process the CODA event buffer for this element.
void LoadChannelParameters(QwParameterFile &paramfile) override
void DeaccumulateRunningSum(VQwBPM &value, Int_t ErrorMask=0xFFFFFFF) override
EBeamPositionMonitorAxis
Definition VQwBPM.h:72
VQwHardwareChannel * GetAngleX()
void RandomizeEventData(int helicity=0, double time=0.0) override
Double_t D[2]
VQwHardwareChannel * GetSubelementByName(TString ch_name) override
void LoadMockDataParameters(QwParameterFile &paramfile) override
UInt_t UpdateErrorFlag() override
Update the error flag based on the error flags of internally contained objects Return parameter is th...
Double_t erra[2]
std::array< T, 2 > fSlope
const VQwHardwareChannel * GetAngleY() const override
VQwHardwareChannel * GetAngleY()
Double_t SumOver(std::vector< Double_t > weight, std::vector< T > val)
std::vector< T > fBPMComboElementList
const VQwHardwareChannel * GetSlope(EBeamPositionMonitorAxis axis) const
Double_t A[2]
void InitializeChannel(TString subsystem, TString name, TString type)
std::vector< Double_t > fYWeights
void InitializeChannel(TString name)
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
Double_t fSumQweights
Double_t chi_square[2]
Double_t m[2]
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
std::array< T, 2 > fIntercept
void LeastSquareFit(VQwBPM::EBeamPositionMonitorAxis axis, std::vector< Double_t > fWeights)
void Ratio(QwCombinedBPM &numer, QwCombinedBPM &denom)
std::array< T, 2 > fAbsPos
void IncrementErrorCounters() override
Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
void PrintValue() const override
Print single line of value and error of this data element.
void ClearEventData() override
void ProcessEvent() override
const VQwHardwareChannel * GetAngleX() const override
QwCombinedBPM(TString subsystem, TString name, TString type)
Bool_t ApplySingleEventCuts() override
Double_t errb[2]
void CalculateFixedParameter(std::vector< Double_t > fWeights, Int_t pos)
std::array< T, 2 > fMinimumChiSquare
void FillHistograms() override
Fill the histograms for this data element.
void SetEventCutMode(Int_t bcuts) override
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit),...
QwCombinedBPM(TString subsystem, TString name)
TString GetSubElementName(Int_t index) override
std::vector< Double_t > fXWeights
VQwBPM & operator+=(const VQwBPM &value) override
Bool_t fixedParamCalculated
void ConstructBranch(TTree *tree, TString &prefix) override
const VQwHardwareChannel * GetEffectiveCharge() const override
Double_t covab[2]
void AccumulateRunningSum(const VQwBPM &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY, Double_t meanXslope, Double_t sigmaXslope, Double_t meanYslope, Double_t sigmaYslope) override
UInt_t GetEventcutErrorFlag() override
VQwBPM & operator=(const VQwBPM &value) override
void SetBPMForCombo(const VQwBPM *bpm, Double_t charge_weight, Double_t x_weight, Double_t y_weight, Double_t sumqw) override
void PrintErrorCounters() const override
std::vector< const VQwBPM * > fElement
const VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis) const override
~QwCombinedBPM() override
QwCombinedBPM(TString name)
QwCombinedBPM(const QwCombinedBPM &source)
Double_t B[2]
void PrintInfo() const override
Print multiple lines of information about this data element.
void CalculateRunningAverage() override
Abstract base for beam position monitors (BPMs)
Definition VQwBPM.h:52
EBeamPositionMonitorAxis
Definition VQwBPM.h:72
static const TString axis[3]
Definition VQwBPM.h:333
VQwBPM()
Definition VQwBPM.h:76