JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwBPMStripline.h
Go to the documentation of this file.
1/*!
2 * \file QwBPMStripline.h
3 * \brief Stripline beam position monitor implementation
4 */
5
6#pragma once
7
8// System headers
9#include <vector>
10
11// ROOT headers
12#include <TTree.h>
13#ifdef HAS_RNTUPLE_SUPPORT
14#include "ROOT/RNTupleModel.hxx"
15#include "ROOT/RField.hxx"
16#endif // HAS_RNTUPLE_SUPPORT
17
18// Qweak headers
19#include "VQwBPM.h"
20#include "QwParameterFile.h"
21#include "QwUtil.h"
22
23// Forward declarations
24#ifdef __USE_DATABASE__
25class QwDBInterface;
27#endif // __USE_DATABASE__
28class QwPromptSummary;
29
30/**
31 * \class QwBPMStripline
32 * \ingroup QwAnalysis_BeamLine
33 * \brief Templated concrete stripline beam position monitor implementation
34 *
35 * Template class for stripline BPMs using hardware channel type T.
36 * Implements position calculation from four stripline signals (XP, XM, YP, YM),
37 * coordinate transformations, effective charge calculation, and calibration.
38 * Supports rotation corrections and geometry-based position calculations.
39 */
40template<typename T>
41class QwBPMStripline : public VQwBPM {
42 template <typename TT> friend class QwCombinedBPM;
43 friend class QwEnergyCalculator;
44
45 public:
46 static UInt_t GetSubElementIndex(TString subname);
47
48 public:
50 QwBPMStripline(TString name) {
52 fRotationAngle = 45.0;
54 bRotated=kTRUE;
55 };
56 QwBPMStripline(TString subsystemname, TString name) {
57 SetSubsystemName(subsystemname);
58 InitializeChannel(subsystemname, name);
59 fRotationAngle = 45.0;
61 bRotated=kTRUE;
62 };
63 QwBPMStripline(TString subsystemname, TString name, TString type) {
64 SetSubsystemName(subsystemname);
65 InitializeChannel(subsystemname, name, type);
66 fRotationAngle = 45.0;
68 bRotated=kTRUE;
69 };
71 : VQwBPM(source),
73 {
74 QwCopyArray(source.fWire, fWire);
77 }
78 ~QwBPMStripline() override { };
79
80 void InitializeChannel(TString name);
81 // new routine added to update necessary information for tree trimming
82 void InitializeChannel(TString subsystem, TString name);
83 void InitializeChannel(TString subsystem, TString name, TString type);
84 void ClearEventData() override;
85
86 void LoadChannelParameters(QwParameterFile &paramfile) override{
87 for(Short_t i=0;i<4;i++){
88 fWire[i].LoadChannelParameters(paramfile);
89 }
90 fAbsPos[0].LoadChannelParameters(paramfile);
91 fAbsPos[1].LoadChannelParameters(paramfile);
92 }
93
94 Int_t ProcessEvBuffer(UInt_t* buffer,
95 UInt_t word_position_in_buffer,UInt_t indexnumber) override;
96 void ProcessEvent() override;
97 void PrintValue() const override;
98 void PrintInfo() const override;
99 void WritePromptSummary(QwPromptSummary *ps, TString type);
100
101
103 if (axis<0 || axis>2){
104 TString loc="QwBPMStripline::GetPosition for "
105 +this->GetElementName()+" failed for axis value "+Form("%d",axis);
106 throw std::out_of_range(loc.Data());
107 }
108 return &fAbsPos[axis];
109 }
110 const VQwHardwareChannel* GetEffectiveCharge() const override {return &fEffectiveCharge;}
112
113 TString GetSubElementName(Int_t subindex) override;
114 void GetAbsolutePosition() override;
115
116 Bool_t ApplyHWChecks();//Check for hardware errors in the devices
117 Bool_t ApplySingleEventCuts() override;//Check for good events by setting limits on the devices readings
118 //void SetSingleEventCuts(TString ch_name, Double_t minX, Double_t maxX);
119 /* /\*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel *\/ */
120 void SetSingleEventCuts(TString ch_name, UInt_t errorflag,Double_t minX, Double_t maxX, Double_t stability, Double_t burplevel);
121 //void SetSingleEventCuts(TString ch_name, UInt_t errorflag,Double_t min, Double_t max, Double_t stability, Double_t burplevel){return;};
122 void SetEventCutMode(Int_t bcuts) override;
123 void IncrementErrorCounters() override;
124 void PrintErrorCounters() const override; // report number of events failed due to HW and event cut failure
125 UInt_t GetEventcutErrorFlag() override;
126 UInt_t UpdateErrorFlag() override;
127
128 Bool_t CheckForBurpFail(const VQwDataElement *ev_error) override;
129 void UpdateErrorFlag(const VQwBPM *ev_error) override;
130
131
132 void SetDefaultSampleSize(Int_t sample_size) override;
133 void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY) override;
134 void RandomizeEventData(int helicity = 0, double time = 0.0) override;
135 void LoadMockDataParameters(QwParameterFile &paramfile) override;
136 void ApplyResolutionSmearing() override;
138 void FillRawEventData() override;
139 void EncodeEventData(std::vector<UInt_t> &buffer) override;
140 void SetSubElementPedestal(Int_t j, Double_t value) override;
141 void SetSubElementCalibrationFactor(Int_t j, Double_t value) override;
142
143 void Ratio(VQwBPM &numer, VQwBPM &denom) override;
144 void Ratio(QwBPMStripline &numer, QwBPMStripline &denom);
145 void Scale(Double_t factor) override;
146
147 VQwBPM& operator= (const VQwBPM &value) override;
148 VQwBPM& operator+= (const VQwBPM &value) override;
149 VQwBPM& operator-= (const VQwBPM &value) override;
150
151 virtual QwBPMStripline& operator= (const QwBPMStripline &value);
152 virtual QwBPMStripline& operator+= (const QwBPMStripline &value);
153 virtual QwBPMStripline& operator-= (const QwBPMStripline &value);
154
155 void AccumulateRunningSum(const QwBPMStripline& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
156 void AccumulateRunningSum(const VQwBPM& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override;
157 void DeaccumulateRunningSum(VQwBPM& value, Int_t ErrorMask=0xFFFFFFF) override;
158 void DeaccumulateRunningSum(QwBPMStripline& value, Int_t ErrorMask=0xFFFFFFF);
159
160 void CalculateRunningAverage() override;
161
162 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
163 void FillHistograms() override;
164
165 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
166 void ConstructBranch(TTree *tree, TString &prefix) override;
167 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist) override;
168 void FillTreeVector(QwRootTreeBranchVector &values) const override;
169
170#ifdef HAS_RNTUPLE_SUPPORT
171 // RNTuple methods
172 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
173 void FillNTupleVector(std::vector<Double_t>& values) const override;
174#endif
175
176
177#ifdef __USE_DATABASE__
178 std::vector<QwDBInterface> GetDBEntry();
179 std::vector<QwErrDBInterface> GetErrDBEntry();
180#endif // __USE_DATABASE__
181
182 protected:
183 /// Should be used inside the QwCombinedBPM::GetProjectedPosition function to assign the
184 /// BPM's X and Y values based on the slope and intercept of the combinedBPM.
186 if (axis<0 || axis>2){
187 TString loc="QwBPMStripline::GetPosition for "
188 +this->GetElementName()+" failed for axis value "+Form("%d",axis);
189 throw std::out_of_range(loc.Data());
190 }
191 return &fAbsPos[axis];
192 }
193
194 VQwHardwareChannel* GetSubelementByName(TString ch_name) override;
195
196
197 /////
198 private:
199 /* /\* Position calibration factor, transform ADC counts in mm *\/ */
200 /* static Double_t kQwStriplineCalibration; */
201 /* static Double_t fRelativeGains[2]; */
202 /* Rotation factor for the BPM which antenna are at 45 deg */
203 static const Double_t kRotationCorrection;
204 static const TString subelement[4];
205
206
207
208 protected:
209 std::array<T,4> fWire;//[4];
210 std::array<T,2> fRelPos;//[2];
211
212 // These are the "real" data elements, to which the base class
213 // fAbsPos_base and fEffectiveCharge_base are pointers.
214 std::array<T,2> fAbsPos;//[2];
217
218private:
219 // Functions to be removed
220 void SetEventData(Double_t* block, UInt_t sequencenumber);
221 std::vector<T> fBPMElementList;
222 void MakeBPMList();
223
224
225
226
227};
Parameter file parsing and management.
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.
void SetSubsystemName(TString sysname)
Set the name of the inheriting subsystem name.
virtual const TString & GetElementName() const
Get the name of this element.
Abstract base for concrete hardware channels implementing dual-operator pattern.
Templated concrete stripline beam position monitor implementation.
void SetSubElementCalibrationFactor(Int_t j, Double_t value) override
void AccumulateRunningSum(const QwBPMStripline &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
friend class QwEnergyCalculator
Bool_t ApplyHWChecks()
Apply hardware checks across all wires and derived channels.
friend class QwCombinedBPM
const VQwHardwareChannel * GetEffectiveCharge() const override
void LoadMockDataParameters(QwParameterFile &paramfile) override
const VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis) const override
std::array< T, 4 > fWire
QwBPMStripline(TString subsystemname, TString name)
void PrintInfo() const override
Print multiple lines of information about this data element.
VQwBPM & operator=(const VQwBPM &value) 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 ProcessEvent() override
void CalculateRunningAverage() override
~QwBPMStripline() override
void SetEventCutMode(Int_t bcuts) override
void RandomizeEventData(int helicity=0, double time=0.0) override
UInt_t UpdateErrorFlag() override
Update and return the aggregated event-cut error flag.
UInt_t GetEventcutErrorFlag() override
Aggregate and return the event-cut error flag for this BPM.
std::array< T, 2 > fAbsPos
void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY) override
void ApplyResolutionSmearing() override
void LoadChannelParameters(QwParameterFile &paramfile) override
VQwHardwareChannel * GetSubelementByName(TString ch_name) override
static UInt_t GetSubElementIndex(TString subname)
VQwBPM & operator-=(const VQwBPM &value) override
void GetAbsolutePosition() override
QwBPMStripline(const QwBPMStripline &source)
void Scale(Double_t factor) override
void SetEventData(Double_t *block, UInt_t sequencenumber)
void WritePromptSummary(QwPromptSummary *ps, TString type)
static const TString subelement[4]
std::vector< T > fBPMElementList
Bool_t ApplySingleEventCuts() override
VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis) override
void ConstructBranch(TTree *tree, TString &prefix) override
QwBPMStripline(TString subsystemname, TString name, TString type)
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
static const Double_t kRotationCorrection
void EncodeEventData(std::vector< UInt_t > &buffer) override
VQwBPM & operator+=(const VQwBPM &value) override
void InitializeChannel(TString name)
Initialize this BPM stripline with a detector name.
void Ratio(VQwBPM &numer, VQwBPM &denom) override
void SetSingleEventCuts(TString ch_name, UInt_t errorflag, Double_t minX, Double_t maxX, Double_t stability, Double_t burplevel)
const VQwHardwareChannel * GetEllipticity() const
void FillHistograms() override
Fill the histograms for this data element.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
void SetDefaultSampleSize(Int_t sample_size) override
void FillTreeVector(QwRootTreeBranchVector &values) const override
Bool_t CheckForBurpFail(const VQwDataElement *ev_error) override
Check for burp failures against another BPM of the same type.
void PrintValue() const override
Print single line of value and error of this data element.
void IncrementErrorCounters() override
Increment error counters for all internal channels.
TString GetSubElementName(Int_t subindex) override
void SetSubElementPedestal(Int_t j, Double_t value) override
QwBPMStripline(TString name)
void DeaccumulateRunningSum(VQwBPM &value, Int_t ErrorMask=0xFFFFFFF) override
void PrintErrorCounters() const override
Print error counters for all internal channels.
void ClearEventData() override
Clear event-scoped data in all channels of this BPM.
void FillRawEventData() override
std::array< T, 2 > fRelPos
Abstract base for beam position monitors (BPMs)
Definition VQwBPM.h:52
EBeamPositionMonitorAxis
Definition VQwBPM.h:72
void SetRotation(Double_t)
Set detector rotation angle and update cached trigonometric values.
Definition VQwBPM.cc:108
Double_t fRotationAngle
Definition VQwBPM.h:337
static const TString axis[3]
Definition VQwBPM.h:333
Bool_t bRotated
Definition VQwBPM.h:336
VQwBPM()
Definition VQwBPM.h:76