JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwBCM.h
Go to the documentation of this file.
1/*!
2 * \file QwBCM.h
3 * \brief Beam current monitor template class
4 */
5
6#pragma once
7
8// System headers
9#include <vector>
10
11// ROOT headers
12#include <TTree.h>
13#include <ROOT/RNTupleModel.hxx>
14
15#include "QwParameterFile.h"
16#include "VQwDataElement.h"
17#include "VQwHardwareChannel.h"
18#include "VQwBCM.h"
19
20// Forward declarations
21class QwDBInterface;
23
24template<typename T> class QwCombinedBCM;
25
26/**
27 * \class QwBCM
28 * \ingroup QwAnalysis_BeamLine
29 * \brief Templated concrete beam current monitor implementation
30 *
31 * Template class that implements a beam current monitor using a specified
32 * hardware channel type T. Handles event decoding, calibration, single-event
33 * cuts, mock data generation, and database output. Supports external clock
34 * normalization and statistical analysis.
35 */
36template<typename T> class QwBCM : public VQwBCM {
37/////
38 friend class QwCombinedBCM<T>;
39 public:
41 QwBCM(TString name): VQwBCM(fBeamCurrent,name) {
42 InitializeChannel(name,"raw");
43 };
44 QwBCM(TString subsystemname, TString name)
45 : VQwBCM(fBeamCurrent,name) {
46 SetSubsystemName(subsystemname);
47 InitializeChannel(subsystemname,name,"raw");
48 };
49 QwBCM(TString subsystemname, TString name, TString type, TString clock = "")
50 : VQwBCM(fBeamCurrent,name) {
51 fBeamCurrent.SetExternalClockName(clock.Data());
52 SetSubsystemName(subsystemname);
53 InitializeChannel(subsystemname,name,type,"raw");
54 };
55 QwBCM(const QwBCM& source)
56 : VQwBCM(source),
58 { }
59 ~QwBCM() override { };
60
61 Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override;
62
63 void InitializeChannel(TString name, TString datatosave) override;
64 // new routine added to update necessary information for tree trimming
65 void InitializeChannel(TString subsystem, TString name, TString datatosave) override;
66 void InitializeChannel(TString subsystem, TString name, TString type,
67 TString datatosave);
68 void ClearEventData() override;
69
70 void LoadChannelParameters(QwParameterFile &paramfile) override{
71 fBeamCurrent.LoadChannelParameters(paramfile);
72 };
73
74 void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency);
75 void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency) override;
76 void SetRandomEventParameters(Double_t mean, Double_t sigma) override;
77 void SetRandomEventAsymmetry(Double_t asymmetry) override;
78
79 void SetResolution(Double_t resolution){
80 fResolution = resolution;
81 }
82
83 void ApplyResolutionSmearing() override;
84 void FillRawEventData() override;
85
86
87//-----------------------------------------------------------------------------------------------
88 void RandomizeEventData(int helicity = 0, double time = 0) override;
89 void LoadMockDataParameters(QwParameterFile &paramfile) override;
90//-----------------------------------------------------------------------------------------------
91
92 void EncodeEventData(std::vector<UInt_t> &buffer) override;
93
95 void SetExternalRandomVariable(Double_t random_variable);
96
97 void ProcessEvent() override;
98 Bool_t ApplyHWChecks();//Check for hardware errors in the devices
99 Bool_t ApplySingleEventCuts() override;//Check for good events by setting limits on the devices readings
100 void IncrementErrorCounters() override;
101 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure
102 UInt_t GetEventcutErrorFlag() override{//return the error flag
103 return fBeamCurrent.GetEventcutErrorFlag();
104 }
105
106 void UpdateErrorFlag(const VQwBCM *ev_error) override;
107
108 UInt_t GetErrorCode() const {return (fBeamCurrent.GetErrorCode());};
109
110
111 Int_t SetSingleEventCuts(Double_t mean = 0, Double_t sigma = 0);//two limits and sample size
112 /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
113 void SetSingleEventCuts(UInt_t errorflag, Double_t min = 0, Double_t max = 0, Double_t stability = 0, Double_t burplevel = 0) override;
114
115 void SetDefaultSampleSize(Int_t sample_size) override;
116 void SetEventCutMode(Int_t bcuts) override {
117 fBeamCurrent.SetEventCutMode(bcuts);
118 }
119
120 void PrintValue() const override;
121 void PrintInfo() const override;
122
123protected:
125 return &fBeamCurrent;
126 };
127public:
128
129 // These are for the clocks
130 std::string GetExternalClockName() override { return fBeamCurrent.GetExternalClockName(); };
131 Bool_t NeedsExternalClock() override { return fBeamCurrent.NeedsExternalClock(); };
132 void SetExternalClockPtr( const VQwHardwareChannel* clock) override {fBeamCurrent.SetExternalClockPtr(clock);};
133 void SetExternalClockName( const std::string name) override { fBeamCurrent.SetExternalClockName(name);};
134 Double_t GetNormClockValue() override { return fBeamCurrent.GetNormClockValue();}
135
136 // Implementation of Parent class's virtual operators
137 VQwBCM& operator= (const VQwBCM &value) override;
138 VQwBCM& operator+= (const VQwBCM &value) override;
139 VQwBCM& operator-= (const VQwBCM &value) override;
140
141 // This is used only by a QwComboBCM. It is placed here since in QwBeamLine we do
142 // not readily have the appropriate template every time we want to use this
143 // function.
144 void SetBCMForCombo(VQwBCM* bcm, Double_t weight, Double_t sumqw ) override {
145 std::cerr<<"SetBCMForCombo for QwCombinedBCM<T> not defined!!\n";
146 };
147
148 // This class specific operators
149 QwBCM& operator= (const QwBCM &value);
150 QwBCM& operator+= (const QwBCM &value);
151 QwBCM& operator-= (const QwBCM &value);
152 void Ratio(const VQwBCM &numer, const VQwBCM &denom) override;
153 void Ratio(const QwBCM &numer, const QwBCM &denom);
154 void Scale(Double_t factor) override;
155
156 void AccumulateRunningSum(const VQwBCM&, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override;
157 void DeaccumulateRunningSum(VQwBCM& value, Int_t ErrorMask=0xFFFFFFF) override;
158 void CalculateRunningAverage() override;
159
160 Bool_t CheckForBurpFail(const VQwDataElement *ev_error) override;
161
162 void SetPedestal(Double_t ped) override;
163 void SetCalibrationFactor(Double_t calib) override;
164
165 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
166 void FillHistograms() override;
167
168 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
169 void ConstructBranch(TTree *tree, TString &prefix) override;
170 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist) override;
171 void FillTreeVector(QwRootTreeBranchVector &values) const override;
172#ifdef HAS_RNTUPLE_SUPPORT
173 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
174 void FillNTupleVector(std::vector<Double_t>& values) const override;
175#endif
176
177 std::vector<QwDBInterface> GetDBEntry();
178 std::vector<QwErrDBInterface> GetErrDBEntry();
179
180 Double_t GetValue() override;
181 Double_t GetValueError() override;
182 Double_t GetValueWidth() override;
183
184
185/////
186 protected:
188
189/////
190 private:
191 Double_t fResolution;
192
193};
Parameter file parsing and management.
Definition of the pure virtual base class of all data elements.
Virtual base class for beam current monitors.
const TString QwBPMStripline< T >::subelement[4]
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.
Abstract base for concrete hardware channels implementing dual-operator pattern.
Templated concrete beam current monitor implementation.
Definition QwBCM.h:36
UInt_t GetEventcutErrorFlag() override
return the error flag on this channel/device
Definition QwBCM.h:102
void SetExternalRandomVariable(Double_t random_variable)
Set the external random variable to drive mock data.
Definition QwBCM.cc:154
void ConstructBranch(TTree *tree, TString &prefix) override
Construct ROOT branches for this BCM (if enabled).
Definition QwBCM.cc:604
void IncrementErrorCounters() override
Increment error counters (number of failed events).
Definition QwBCM.cc:296
Double_t GetNormClockValue() override
Definition QwBCM.h:134
void SetEventCutMode(Int_t bcuts) override
Definition QwBCM.h:116
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Define histograms for this BCM (delegated to underlying channel).
Definition QwBCM.cc:559
void SetPedestal(Double_t ped) override
Set the pedestal value for the beam current monitor.
Definition QwBCM.cc:33
void DeaccumulateRunningSum(VQwBCM &value, Int_t ErrorMask=0xFFFFFFF) override
Remove a single entry from the running sums using a source value.
Definition QwBCM.cc:534
UInt_t GetErrorCode() const
Definition QwBCM.h:108
void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Configure deterministic drift parameters applied per event.
Definition QwBCM.cc:163
void Scale(Double_t factor) override
Scale the underlying channel by a constant factor.
Definition QwBCM.cc:485
void Ratio(const VQwBCM &numer, const VQwBCM &denom) override
Polymorphic ratio formation for BCM.
Definition QwBCM.cc:465
QwBCM(TString name)
Definition QwBCM.h:41
Bool_t NeedsExternalClock() override
Definition QwBCM.h:131
void ApplyResolutionSmearing() override
Smear the channel by the configured resolution.
Definition QwBCM.cc:191
void FillRawEventData() override
Materialize the current event state as raw event data.
Definition QwBCM.cc:196
void SetCalibrationFactor(Double_t calib) override
Set the calibration factor for the beam current monitor.
Definition QwBCM.cc:43
void RandomizeEventData(int helicity=0, double time=0) override
Generate mock event data for this BCM.
Definition QwBCM.cc:207
void SetExternalClockName(const std::string name) override
Definition QwBCM.h:133
void SetBCMForCombo(VQwBCM *bcm, Double_t weight, Double_t sumqw) override
Definition QwBCM.h:144
Double_t GetValue() override
Get the current value of the beam current.
Definition QwBCM.cc:698
VQwBCM & operator=(const VQwBCM &value) override
Polymorphic copy-assign from VQwBCM if types match.
Definition QwBCM.cc:363
QwBCM(TString subsystemname, TString name)
Definition QwBCM.h:44
void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency) override
Add additional drift parameters to the drift model.
Definition QwBCM.cc:170
void PrintValue() const override
Print a compact value summary for this BCM.
Definition QwBCM.cc:539
Bool_t CheckForBurpFail(const VQwDataElement *ev_error) override
Check for burp failures by delegating to the underlying channel.
Definition QwBCM.cc:503
std::string GetExternalClockName() override
Definition QwBCM.h:130
void SetExternalClockPtr(const VQwHardwareChannel *clock) override
Definition QwBCM.h:132
void SetRandomEventAsymmetry(Double_t asymmetry) override
Set an asymmetry parameter applied to helicity states.
Definition QwBCM.cc:184
void CalculateRunningAverage() override
Update running averages for the underlying channel.
Definition QwBCM.cc:492
Double_t fResolution
Definition QwBCM.h:191
void AccumulateRunningSum(const VQwBCM &, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Accumulate running sums from another BCM into this one.
Definition QwBCM.cc:527
void EncodeEventData(std::vector< UInt_t > &buffer) override
Encode current event data into an output buffer.
Definition QwBCM.cc:216
Double_t GetValueWidth() override
Get the width of the beam current distribution.
Definition QwBCM.cc:713
VQwBCM & operator+=(const VQwBCM &value) override
Polymorphic add-assign from VQwBCM if types match.
Definition QwBCM.cc:403
std::vector< QwErrDBInterface > GetErrDBEntry()
void SetDefaultSampleSize(Int_t sample_size) override
Set the default sample size used by the channel.
Definition QwBCM.cc:268
void SetResolution(Double_t resolution)
Definition QwBCM.h:79
Bool_t ApplyHWChecks()
Apply hardware checks and return whether the event is valid.
Definition QwBCM.cc:235
QwBCM(const QwBCM &source)
Definition QwBCM.h:55
T fBeamCurrent
Definition QwBCM.h:187
Double_t GetValueError() override
Get the statistical error on the beam current.
Definition QwBCM.cc:706
void ProcessEvent() override
Apply hardware checks and process the event for this BCM.
Definition QwBCM.cc:224
void FillHistograms() override
Fill histograms for this BCM if enabled.
Definition QwBCM.cc:573
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override
Process the raw event buffer and decode into the channel.
Definition QwBCM.cc:337
VQwHardwareChannel * GetCharge() override
Definition QwBCM.h:124
void UseExternalRandomVariable()
Use an external random variable source for mock data.
Definition QwBCM.cc:144
std::vector< QwDBInterface > GetDBEntry()
Bool_t ApplySingleEventCuts() override
Apply single-event cuts for this BCM and return pass/fail.
Definition QwBCM.cc:279
~QwBCM() override
Definition QwBCM.h:59
void SetRandomEventParameters(Double_t mean, Double_t sigma) override
Configure Gaussian mock data parameters.
Definition QwBCM.cc:177
void ClearEventData() override
Clear event-scoped data in the underlying channel.
Definition QwBCM.cc:136
QwBCM()
Definition QwBCM.h:40
void PrintErrorCounters() const override
Print error counters (const overload).
Definition QwBCM.cc:303
QwBCM(TString subsystemname, TString name, TString type, TString clock="")
Definition QwBCM.h:49
void InitializeChannel(TString name, TString datatosave) override
Initialize the BCM with a name and data-saving mode.
Definition QwBCM.cc:54
void LoadChannelParameters(QwParameterFile &paramfile) override
Definition QwBCM.h:70
void PrintInfo() const override
Print detailed information for this BCM.
Definition QwBCM.cc:546
Int_t SetSingleEventCuts(Double_t mean=0, Double_t sigma=0)
Set basic single-event cut limits.
Definition QwBCM.cc:248
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Construct ROOT branches and value vector entries.
Definition QwBCM.cc:592
VQwBCM & operator-=(const VQwBCM &value) override
Polymorphic subtract-assign from VQwBCM.
Definition QwBCM.cc:428
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill tree vector entries for this BCM.
Definition QwBCM.cc:639
void LoadMockDataParameters(QwParameterFile &paramfile) override
Load mock-data configuration for the underlying channel.
Definition QwBCM.cc:100
Abstract base for beam current monitors (BCMs)
Definition VQwBCM.h:52
friend class QwCombinedBCM
Definition VQwBCM.h:61
VQwBCM(VQwDataElement &beamcurrent)
Definition VQwBCM.h:64
UInt_t UpdateErrorFlag() override
Update the error flag based on the error flags of internally contained objects Return parameter is th...
Definition VQwBCM.h:93