JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
VQwBPM.h
Go to the documentation of this file.
1/**********************************************************\
2* File: VQwBPM.h *
3* *
4* Author: B.Waidyawansa *
5* Time-stamp: <2010-05-24> *
6\**********************************************************/
7
8/*!
9 * \file VQwBPM.h
10 * \brief Virtual base class for beam position monitors
11 */
12
13#pragma once
14
15// ROOT headers
16#include <TTree.h>
17#include <TMath.h>
18
19// RNTuple headers
20#ifdef HAS_RNTUPLE_SUPPORT
21#include "ROOT/RNTupleModel.hxx"
22#endif // HAS_RNTUPLE_SUPPORT
23
24// Qweak headers
26#include "VQwHardwareChannel.h"
27
28class QwParameterFile;
29template<typename T> class QwCombinedBPM;
30template<typename T> class QwBPMStripline;
31
32#ifdef __USE_DATABASE__
33class QwDBInterface;
35#endif // __USE_DATABASE__
36
37///
38/// \ingroup QwAnalysis_BeamLine
39///
40
41/**
42 * \class VQwBPM
43 * \ingroup QwAnalysis_BeamLine
44 * \brief Abstract base for beam position monitors (BPMs)
45 *
46 * Defines the common interface for BPM-like data elements, including decoding
47 * of position channels, per-event cuts, error propagation, and output. Concrete
48 * implementations such as QwBPMStripline<T> and QwCombinedBPM<T> inherit from
49 * this base to provide hardware-specific logic while sharing the higher-level
50 * processing contract.
51 */
52class VQwBPM : public VQwDataElement {
53 /******************************************************************
54 * Class: VQwBPM
55 * Virtual base class for the BPMs in the beamline.
56 * This will define a set of functions that are used by the
57 * BPMStripline and CombinedBPM classes for data decoding.
58 * This parent class will define the basic structure of a
59 * BPM. The basic object doesn't care about the inputs.
60 * It only defines absolute positions and an effective charge.
61 * BPMs have 4 input wires for position: XP, XM, YP, YM
62 * Cavityy monitors have 3 wires: X, Y and I
63 * CombinedBPM use absolute X and Y derived from BPM X and Ys.
64 ******************************************************************/
65 template <typename TT> friend class QwBPMStripline;
66 template <typename TT> friend class QwCombinedBPM;
67 friend class QwEnergyCalculator;
68
69 public:
70 /// Axis enumerator for the BPMs;
71 /// Z will never be an instrumented axis.
73
74 public:
75 // Default constructor
77 VQwBPM(TString& /*name*/) {InitializeChannel_base();};
78 VQwBPM(const VQwBPM& source)
79 : VQwDataElement(source),
80 bRotated(source.bRotated),
81 bFullSave(source.bFullSave)
82 {
83 for (size_t i = 0; i < 3; i++)
84 fPositionCenter[i] = source.fPositionCenter[i];
85 }
86 ~VQwBPM() override { };
87
88
89 void InitializeChannel(TString name);
90 // virtual void ClearEventData() = 0;
91
92 void LoadChannelParameters(QwParameterFile &paramfile) override = 0;
93
94//-------------------------------------------------------------------------------------
95
96 virtual void GetProjectedPosition(VQwBPM * /*device*/){}; // The base class function GetProjectedPosition is defined to have no effect.
97 virtual size_t GetNumberOfElements(){return size_t(1);}
98 virtual void FillRawEventData()
99 {std::cerr << "FillRawEventData for VQwBPM not implemented for device " << GetElementName() << "!\n";};
100
101//-------------------------------------------------------------------------------------
102
103 void GetSurveyOffsets(Double_t Xoffset, Double_t Yoffset, Double_t Zoffset);
104 void GetElectronicFactors(Double_t BSENfactor, Double_t AlphaX, Double_t AlphaY);
105 void SetRotation(Double_t);
106 void SetRotationOff();
107
108 void SetSingleEventCuts(TString, Double_t, Double_t);
109 void SetSingleEventCuts(TString, UInt_t, Double_t, Double_t, Double_t, Double_t);
110 UInt_t UpdateErrorFlag() override = 0;
111 virtual void UpdateErrorFlag(const VQwBPM *ev_error) = 0;
112
113 virtual void Scale(Double_t /*factor*/) {
114 std::cerr << "Scale for VQwBPM not implemented!\n";
115 }
116 void SetGains(TString pos, Double_t value);
117
118 // Operators subclasses MUST support!
119 virtual VQwBPM& operator= (const VQwBPM &value) =0;
120 virtual VQwBPM& operator+= (const VQwBPM &value) =0;
121 virtual VQwBPM& operator-= (const VQwBPM &value) =0;
122
123 void SetRootSaveStatus(TString &prefix);
124
125
126/* VQwDataElement* GetPositionX(){ */
127/* return fAbsPos_base[0]; */
128/* }; */
129/* const VQwDataElement* GetPositionX() const{ */
130/* return const_cast<VQwBPM*>(this)->GetPositionX(); */
131/* }; */
132/* VQwDataElement* GetPositionY(){ */
133/* return fAbsPos_base[1]; */
134/* }; */
135/* const VQwDataElement* GetPositionY() const{ */
136/* return const_cast<VQwBPM*>(this)->GetPositionY(); */
137/* }; */
138
139
141 return const_cast<VQwBPM*>(this)->GetPosition(axis);
142 }
143
144
145
146
147protected:
149 VQwHardwareChannel* tmpptr = NULL;
150 if (axis==kXAxis){
151 tmpptr = GetSubelementByName("x");
152 } else if (axis==kYAxis){
153 tmpptr = GetSubelementByName("y");
154 } else {
155 TString loc="VQwBPM::GetPosition for "
156 +this->GetElementName()+" failed for axis value "+Form("%d",axis);
157 throw std::out_of_range(loc.Data());
158 }
159 return tmpptr;
160 }
161
162public:
163
164
165
166/* VQwHardwareChannel* GetEffectiveCharge(){ */
167/* return fEffectiveCharge_base; */
168/* } */
169 virtual const VQwHardwareChannel* GetEffectiveCharge() const = 0;
170
171 Double_t GetPositionInZ() const{
172 return fPositionCenter[2];
173 };
174
175/* void PrintValue() const; */
176/* void PrintInfo() const; */
177 virtual void CalculateRunningAverage() = 0;
178 virtual void AccumulateRunningSum(const VQwBPM& /*value*/, Int_t /*count*/=0, Int_t /*ErrorMask*/=0xFFFFFFF) {
179 std::cerr << "AccumulateRunningSum not implemented for BPM named="
180 <<GetElementName()<<"\n";
181 };
182 virtual void DeaccumulateRunningSum(VQwBPM& value, Int_t ErrorMask=0xFFFFFFF) = 0;
183
184 void ConstructHistograms(TDirectory *folder, TString &prefix) override = 0;
185 void FillHistograms() override = 0;
186
187 virtual void ConstructBranchAndVector(TTree *tree, TString &prefix,
188 QwRootTreeBranchVector &values) = 0;
189 virtual void ConstructBranch(TTree *tree, TString &prefix) = 0;
190 virtual void ConstructBranch(TTree *tree, TString &prefix,
191 QwParameterFile& modulelist) = 0;
192 virtual void FillTreeVector(QwRootTreeBranchVector &values) const = 0;
193
194#ifdef HAS_RNTUPLE_SUPPORT
195 virtual void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) = 0;
196 virtual void FillNTupleVector(std::vector<Double_t>& values) const = 0;
197#endif // HAS_RNTUPLE_SUPPORT
198
199#ifdef __USE_DATABASE__
200 virtual std::vector<QwDBInterface> GetDBEntry() = 0;
201 virtual std::vector<QwErrDBInterface> GetErrDBEntry() = 0;
202#endif // __USE_DATABASE__
203
204 virtual void Ratio(VQwBPM & /*numer*/, VQwBPM & /*denom*/) {
205 std::cerr << "Ratio() is not defined for BPM named="<<GetElementName()<<"\n";
206 }
207
208 // Ensure polymorphic dispatch of burp-failure checks when called via VQwBPM*
209 virtual Bool_t CheckForBurpFail(const VQwDataElement *ev_error) {
210 // Default: delegate to VQwDataElement (throws). Derived classes should override.
211 return VQwDataElement::CheckForBurpFail(ev_error);
212 }
213
214 // Stuff required for QwBPMStripLine
215/* virtual UInt_t GetSubElementIndex(TString subname) { */
216/* std::cerr << "GetSubElementIndex() is not implemented for BPM named=" */
217/* <<GetElementName()<< "!!\n"; */
218/* return 0; */
219/* } */
220 virtual TString GetSubElementName(Int_t /*subindex*/) {
221 std::cerr << "GetSubElementName() is not implemented!! for device: " << GetElementName() << "\n";
222 return TString("OBJECT_UNDEFINED"); // Return an erroneous TString
223 }
224 virtual void GetAbsolutePosition() {
225 std::cerr << "GetAbsolutePosition() is not implemented!!\n";
226 }
227 virtual void SetEventCutMode(Int_t bcuts) = 0;
228 void PrintErrorCounters() const override {// report number of events failed due to HW and event cut failure
229 std::cerr << "PrintErrorCounters() is not implemented!!\n";
230 }
231 virtual Bool_t ApplySingleEventCuts() = 0;//Check for good events by setting limits on the devices readings
232 virtual void IncrementErrorCounters() = 0;
233 virtual void ProcessEvent() = 0;
234
235 // These only applies to a combined BPM
236 virtual const VQwHardwareChannel* GetAngleX() const {
237 std::cerr << "GetAngleX() is not implemented for VQwBPM, must be"
238 "used in a CombinedBPM!\n";
239 return 0;
240 }
241 virtual const VQwHardwareChannel* GetAngleY() const {
242 std::cerr << "GetAngleY() is not implemented for VQwBPM, must be"
243 "used in a CombinedBPM!\n";
244 return 0;
245 }
246 virtual void SetBPMForCombo(const VQwBPM* /*bpm*/, Double_t /*charge_weight*/,
247 Double_t /*x_weight*/, Double_t /*y_weight*/,Double_t /*sumqw*/) {
248 std::cerr << "VQwBPM::SetBPMForCombo only defined for CombinedBPM's!!!\n";
249 }
250
251
252 virtual void SetDefaultSampleSize(Int_t /*sample_size*/) {
253 std::cerr << "SetDefaultSampleSize() is undefined!!!\n";
254 }
255
256 virtual void SetResolution(Double_t resolutionX, Double_t resolutionY){
257 fResolution[kXAxis] = resolutionX;
258 fResolution[kYAxis] = resolutionY;
259 }
260
261 virtual void SetRandomEventParameters(Double_t /*meanX*/, Double_t /*sigmaX*/, Double_t /*meanY*/, Double_t /*sigmaY*/) {
262 std::cerr<< "SetRandomEventParameters undefined!!\n";
263 }
264 virtual 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*/) {
265 std::cerr<< "SetRandomEventParameters undefined!!\n";
266 }
267 virtual void SetRandomEventAsymmetry(Double_t /*asymmetry*/) {
268 std::cerr<< "SetRandomEventAsymmetry undefined!!\n";
269 }
270 virtual void RandomizeEventData(int /*helicity*/ = 0, double /*time*/ = 0.0) {
271 std::cerr << "RandomizeEventData is undefined for device" << GetElementName() << "!!!\n";
272 }
274 std::cerr << "ApplyResolutionSmearing is undefined" << GetElementName() << "!!!\n";
275 }
277 std::cerr << "ApplyResolutionSmearing(EBeamPositionMonitorAxis iaxis) is undefined!!!\n";
278 }
279 virtual void EncodeEventData(std::vector<UInt_t> & /*buffer*/) {
280 std::cerr << "EncodeEventData is undefined!!!\n";
281 }
282 virtual void SetSubElementPedestal(Int_t /*j*/, Double_t /*value*/) {
283 std::cerr << "SetSubElementPedestal is undefined!!!\n";
284 }
285 virtual void SetSubElementCalibrationFactor(Int_t /*j*/, Double_t /*value*/) {
286 std::cerr << "SetSubElementCalibrationFactor is undefined!!!\n";
287 }
288 void PrintInfo() const override {
289 std::cout<<"PrintInfo() for VQwBPM not impletemented\n";
290 };
291
292 // Factory function to produce appropriate BCM
293 static VQwBPM* CreateStripline(TString subsystemname, TString type, TString name);
294 static VQwBPM* CreateStripline(const VQwBPM& source);
295 static VQwBPM* CreateCombo(TString subsystemname, TString type, TString name);
296 static VQwBPM* CreateCombo(const VQwBPM& source);
297
298 private:
299
301/* fAbsPos_base[0] = NULL; */
302/* fAbsPos_base[1] = NULL; */
303/* fEffectiveCharge_base = NULL; */
304 fQwStriplineCalibration = 18.81; // adc counts/mm default value
305 fQwStriplineCorrection = 0.250014;
306 for(Short_t i=0;i<2;i++) {
307 fRelativeGains[i]=1.0;
308 fGains[i]=1.0;
309 fResolution[i]=0.0001;
310 }
311 };
312
313
314 protected:
315 /// Axis labels for the instrumented directions;
316 /// Z will never be an instrumented axis.
317 static const TString kAxisLabel[2];
318
319 virtual VQwHardwareChannel* GetSubelementByName(TString ch_name) = 0;
323
324 protected:
325 std::vector<TString> fSubelementNames;
326
327 // Position calculation related parameters
328 Double_t fPositionCenter[3];
331 Double_t fRelativeGains[2];
332 Double_t fGains[2];
333 static const TString axis[3];
334
335 // Rotation related parameters
336 Bool_t bRotated;
338 Double_t fCosRotation;
339 Double_t fSinRotation;
340
341 // Mock Data parameters
342 Double_t fResolution[2];
343
344 // Data quality checks related flags
346 // Bool_t bEVENTCUTMODE;//If this set to kFALSE then Event cuts are OFF
347 // Int_t fDeviceErrorCode;//keep the device HW status using a unique code from the QwVQWK_Channel::fDeviceErrorCode
348 Bool_t bFullSave; // used to restrict the amount of data histogramed
349
350 const static Bool_t bDEBUG=kFALSE;//debugging display purposes
351
352};
353
354typedef std::shared_ptr<VQwBPM> VQwBPM_ptr;
Definition of the pure virtual base class of all data elements.
std::shared_ptr< VQwBPM > VQwBPM_ptr
Definition VQwBPM.h:354
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
VQwDataElement()
Default constructor.
virtual const TString & GetElementName() const
Get the name of this element.
Bool_t CheckForBurpFail(const VQwDataElement *)
Abstract base for concrete hardware channels implementing dual-operator pattern.
Abstract base for beam position monitors (BPMs)
Definition VQwBPM.h:52
Double_t fPositionCenter[3]
Definition VQwBPM.h:328
virtual void SetSubElementPedestal(Int_t, Double_t)
Definition VQwBPM.h:282
virtual void SetSubElementCalibrationFactor(Int_t, Double_t)
Definition VQwBPM.h:285
friend class QwEnergyCalculator
Definition VQwBPM.h:67
virtual void ApplyResolutionSmearing()
Definition VQwBPM.h:273
virtual void UpdateErrorFlag(const VQwBPM *ev_error)=0
friend class QwCombinedBPM
Definition VQwBPM.h:66
virtual TString GetSubElementName(Int_t)
Definition VQwBPM.h:220
void PrintErrorCounters() const override
report number of events failed due to HW and event cut failure
Definition VQwBPM.h:228
EBeamPositionMonitorAxis
Definition VQwBPM.h:72
@ kXAxis
Definition VQwBPM.h:72
@ kYAxis
Definition VQwBPM.h:72
@ kNumAxes
Definition VQwBPM.h:72
VQwBPM(TString &)
Definition VQwBPM.h:77
friend class QwBPMStripline
Definition VQwBPM.h:65
void ConstructHistograms(TDirectory *folder, TString &prefix) override=0
Construct the histograms for this data element.
virtual void EncodeEventData(std::vector< UInt_t > &)
Definition VQwBPM.h:279
virtual VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis)
Definition VQwBPM.h:148
virtual void SetRandomEventParameters(Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t)
Definition VQwBPM.h:264
Double_t fResolution[2]
Definition VQwBPM.h:342
virtual void ConstructBranch(TTree *tree, TString &prefix)=0
std::vector< TString > fSubelementNames
Definition VQwBPM.h:325
virtual void FillTreeVector(QwRootTreeBranchVector &values) const =0
virtual void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile &modulelist)=0
void LoadChannelParameters(QwParameterFile &paramfile) override=0
virtual void IncrementErrorCounters()=0
virtual void SetRandomEventParameters(Double_t, Double_t, Double_t, Double_t)
Definition VQwBPM.h:261
void GetSurveyOffsets(Double_t Xoffset, Double_t Yoffset, Double_t Zoffset)
Store geometry/survey offsets for absolute position calibration.
Definition VQwBPM.cc:56
void SetRotation(Double_t)
Set detector rotation angle and update cached trigonometric values.
Definition VQwBPM.cc:108
Double_t fQwStriplineCalibration
Definition VQwBPM.h:329
virtual VQwBPM & operator-=(const VQwBPM &value)=0
void SetRootSaveStatus(TString &prefix)
Definition VQwBPM.cc:220
static const TString kAxisLabel[2]
Definition VQwBPM.h:25
virtual void SetResolution(Double_t resolutionX, Double_t resolutionY)
Definition VQwBPM.h:256
virtual void SetRandomEventAsymmetry(Double_t)
Definition VQwBPM.h:267
virtual size_t GetNumberOfElements()
Definition VQwBPM.h:97
virtual Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Definition VQwBPM.h:209
Double_t fGains[2]
Definition VQwBPM.h:332
Double_t fRotationAngle
Definition VQwBPM.h:337
~VQwBPM() override
Definition VQwBPM.h:86
virtual void GetAbsolutePosition()
Definition VQwBPM.h:224
virtual void SetEventCutMode(Int_t bcuts)=0
Double_t fCosRotation
Definition VQwBPM.h:338
virtual const VQwHardwareChannel * GetAngleY() const
Definition VQwBPM.h:241
void SetSingleEventCuts(TString, Double_t, Double_t)
Definition VQwBPM.cc:139
static VQwBPM * CreateCombo(TString subsystemname, TString type, TString name)
A fast way of creating a BPM stripline of specified type.
Definition VQwBPM.cc:314
Double_t fRelativeGains[2]
Definition VQwBPM.h:331
virtual Bool_t ApplySingleEventCuts()=0
virtual void SetDefaultSampleSize(Int_t)
Definition VQwBPM.h:252
void FillHistograms() override=0
Fill the histograms for this data element.
virtual void DeaccumulateRunningSum(VQwBPM &value, Int_t ErrorMask=0xFFFFFFF)=0
void InitializeChannel(TString name)
Initialize common BPM state and set the element name.
Definition VQwBPM.cc:35
Bool_t fGoodEvent
Definition VQwBPM.h:345
virtual void AccumulateRunningSum(const VQwBPM &, Int_t=0, Int_t=0xFFFFFFF)
Definition VQwBPM.h:178
static const Bool_t bDEBUG
Definition VQwBPM.h:350
void PrintInfo() const override
Print multiple lines of information about this data element.
Definition VQwBPM.h:288
virtual void Ratio(VQwBPM &, VQwBPM &)
Definition VQwBPM.h:204
VQwHardwareChannel * GetSubelementByIndex(size_t index)
Definition VQwBPM.h:320
UInt_t UpdateErrorFlag() override=0
Update the error flag based on the error flags of internally contained objects Return parameter is th...
virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)=0
virtual void SetBPMForCombo(const VQwBPM *, Double_t, Double_t, Double_t, Double_t)
Definition VQwBPM.h:246
void SetRotationOff()
Definition VQwBPM.cc:126
virtual void FillRawEventData()
Definition VQwBPM.h:98
virtual void RandomizeEventData(int=0, double=0.0)
Definition VQwBPM.h:270
void GetElectronicFactors(Double_t BSENfactor, Double_t AlphaX, Double_t AlphaY)
Apply per-detector electronic calibration and relative gains.
Definition VQwBPM.cc:77
virtual VQwHardwareChannel * GetSubelementByName(TString ch_name)=0
virtual const VQwHardwareChannel * GetAngleX() const
Definition VQwBPM.h:236
void SetGains(TString pos, Double_t value)
Definition VQwBPM.cc:134
virtual void GetProjectedPosition(VQwBPM *)
Definition VQwBPM.h:96
Bool_t bFullSave
Definition VQwBPM.h:348
Double_t fQwStriplineCorrection
Definition VQwBPM.h:330
virtual void CalculateRunningAverage()=0
static VQwBPM * CreateStripline(TString subsystemname, TString type, TString name)
A fast way of creating a BPM stripline of specified type.
Definition VQwBPM.cc:267
static const TString axis[3]
Definition VQwBPM.h:333
virtual const VQwHardwareChannel * GetEffectiveCharge() const =0
virtual VQwBPM & operator=(const VQwBPM &value)=0
Definition VQwBPM.cc:156
Bool_t bRotated
Definition VQwBPM.h:336
virtual void Scale(Double_t)
Definition VQwBPM.h:113
VQwBPM(const VQwBPM &source)
Definition VQwBPM.h:78
virtual void ApplyResolutionSmearing(EBeamPositionMonitorAxis)
Definition VQwBPM.h:276
virtual VQwBPM & operator+=(const VQwBPM &value)=0
void InitializeChannel_base()
Definition VQwBPM.h:300
virtual const VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis) const
Definition VQwBPM.h:140
VQwBPM()
Definition VQwBPM.h:76
Double_t fSinRotation
Definition VQwBPM.h:339
virtual void ProcessEvent()=0
Double_t GetPositionInZ() const
Definition VQwBPM.h:171