JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwBeamLine.h
Go to the documentation of this file.
1/*!
2 * \file QwBeamLine.h
3 * \brief Beamline subsystem containing BPMs, BCMs, and other beam monitoring devices
4 */
5
6#pragma once
7
8// System headers
9#include <vector>
10
11// ROOT headers
12#include "TTree.h"
13#include "TString.h"
14
15// Qweak headers
16#include "VQwSubsystemParity.h"
17#include "QwTypes.h"
18#include "QwBPMStripline.h"
19#include "VQwBCM.h"
20#include "QwBCM.h"
21#include "QwBPMCavity.h"
22#include "QwCombinedBCM.h"
23#include "QwCombinedBPM.h"
24#include "QwEnergyCalculator.h"
25#include "QwHaloMonitor.h"
26#include "QwQPD.h"
27#include "QwLinearDiodeArray.h"
28#include "VQwClock.h"
29#include "QwBeamDetectorID.h"
30
31
32/**
33 * \class QwBeamLine
34 * \ingroup QwAnalysis_BeamLine
35 * \brief Subsystem aggregating beamline instruments (BPMs, BCMs, clocks, etc.)
36 *
37 * QwBeamLine owns and orchestrates multiple beam monitoring devices and
38 * provides a unified subsystem interface for map loading, event decoding,
39 * event processing, cuts, error propagation, histogram/tree output, and
40 * publishing. It supports combinations (e.g., combined BPM/BCM), mock-data
41 * generation, and stability/burp checks at the subsystem level.
42 */
43class QwBeamLine : public VQwSubsystemParity, public MQwSubsystemCloneable<QwBeamLine> {
44
45 private:
46 /// Private default constructor (not implemented, will throw linker error on use)
48
49 public:
50 /// Constructor with name
51 QwBeamLine(const TString& name)
53 { };
54 /// Copy constructor
55 QwBeamLine(const QwBeamLine& source)
56 : VQwSubsystem(source),VQwSubsystemParity(source),
57 fQPD(source.fQPD),
58 fCavity(source.fCavity),
62 { this->CopyTemplatedDataElements(&source); }
63 /// Virtual destructor
64 ~QwBeamLine() override { };
65
66 void CopyTemplatedDataElements(const VQwSubsystem *source);
67
68 /* derived from VQwSubsystem */
69
70 void ProcessOptions(QwOptions &options) override;//Handle command line options
71 Int_t LoadChannelMap(TString mapfile) override;
72 Int_t LoadInputParameters(TString pedestalfile) override;
73 void LoadEventCuts_Init() override {};
74 void LoadEventCuts_Line(QwParameterFile &mapstr, TString &varvalue, Int_t &eventcut_flag) override;
75 void LoadEventCuts_Fin(Int_t &eventcut_flag) override;
76 Int_t LoadGeometryDefinition(TString mapfile) override;
77 void LoadMockDataParameters(TString mapfile) override;
78 void AssignGeometry(QwParameterFile* mapstr, VQwBPM * bpm);
79
80 Bool_t ApplySingleEventCuts() override;//derived from VQwSubsystemParity
81 void IncrementErrorCounters() override;
82
83 Bool_t CheckForBurpFail(const VQwSubsystem *subsys) override;
84
85 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failures
86 UInt_t GetEventcutErrorFlag() override;//return the error flag
87
88 UInt_t UpdateErrorFlag() override;//Update and return the error flags
89
90 //update the error flag in the subsystem level from the top level routines related to stability checks. This will uniquely update the errorflag at each channel based on the error flag in the corresponding channel in the ev_error subsystem
91 void UpdateErrorFlag(const VQwSubsystem *ev_error) override;
92
93 Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words) override;
94 Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words) override;
95 void PrintDetectorID() const;
96
97 void ClearEventData() override;
98 void ProcessEvent() override;
99
100 Bool_t PublishInternalValues() const override;
101 Bool_t PublishByRequest(TString device_name) override;
102
103
104 public:
106 void RandomizeEventData(int helicity = 0, double time = 0.0) override;
107 void SetRandomEventAsymmetry(Double_t asymmetry);
108 void EncodeEventData(std::vector<UInt_t> &buffer) override;
109
110 VQwSubsystem& operator= (VQwSubsystem *value) override;
111 VQwSubsystem& operator+= (VQwSubsystem *value) override;
112 VQwSubsystem& operator-= (VQwSubsystem *value) override;
113 void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override;
114
115 void Scale(Double_t factor) override;
116
117 void AccumulateRunningSum(VQwSubsystem* value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override;
118 //remove one entry from the running sums for devices
119 void DeaccumulateRunningSum(VQwSubsystem* value, Int_t ErrorMask=0xFFFFFFF) override;
120
121
122 void CalculateRunningAverage() override;
123
125 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
126 void FillHistograms() override;
127
129 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
130 void ConstructBranch(TTree *tree, TString &prefix) override;
131 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& trim_file ) override;
132 void FillTreeVector(QwRootTreeBranchVector &values) const override;
133
134#ifdef HAS_RNTUPLE_SUPPORT
135 using VQwSubsystem::ConstructNTupleAndVector;
136 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
137 void FillNTupleVector(std::vector<Double_t>& values) const override;
138#endif
139
140#ifdef __USE_DATABASE__
141 void FillDB(QwParityDB *db, TString datatype) override;
142 void FillErrDB(QwParityDB *db, TString datatype) override;
143#endif // __USE_DATABASE__
144
145 Bool_t Compare(VQwSubsystem *source);
146
147 void PrintValue() const override;
148 void PrintInfo() const override;
149 void WritePromptSummary(QwPromptSummary *ps, TString type) override;
150
152 VQwDataElement* GetElement(EQwBeamInstrumentType TypeID, TString name);
153 VQwDataElement* GetElement(EQwBeamInstrumentType TypeID, Int_t index);
154 const VQwDataElement* GetElement(EQwBeamInstrumentType TypeID, Int_t index) const;
155
156 const VQwHardwareChannel* GetChannel(EQwBeamInstrumentType TypeID, Int_t index, TString device_prop) const;
157
158 VQwBPM* GetBPMStripline(const TString name);
159 VQwBCM* GetBCM(const TString name);
160 VQwClock* GetClock(const TString name);
161 QwBPMCavity* GetBPMCavity(const TString name);
162 VQwBCM* GetCombinedBCM(const TString name);
163 VQwBPM* GetCombinedBPM(const TString name);
164 QwEnergyCalculator* GetEnergyCalculator(const TString name);
165 QwHaloMonitor* GetScalerChannel(const TString name);
166 const QwBPMCavity* GetBPMCavity(const TString name) const;
167 const VQwBPM* GetBPMStripline(const TString name) const;
168 const VQwBCM* GetBCM(const TString name) const;
169 const VQwClock* GetClock(const TString name) const;
170 const VQwBCM* GetCombinedBCM(const TString name) const;
171 const VQwBPM* GetCombinedBPM(const TString name) const;
172 const QwEnergyCalculator* GetEnergyCalculator(const TString name) const;
173 const QwHaloMonitor* GetScalerChannel(const TString name) const;
174
175
176/////
177protected:
178
179 /// \brief Adds a new element to a vector of data elements, and returns
180 /// the index of that element within the array.
181 template <typename TT>
182 Int_t AddToElementList(std::vector<TT> &elementlist, QwBeamDetectorID &detector_id);
183
184 Int_t GetDetectorIndex(EQwBeamInstrumentType TypeID, TString name) const;
185 //when the type and the name is passed the detector index from appropriate vector will be returned
186 //for example if TypeID is bcm then the index of the detector from fBCM vector for given name will be returned.
187
188 std::vector <VQwBPM_ptr> fStripline;
189 std::vector <VQwBPM_ptr> fBPMCombo;
190
191 std::vector <VQwBCM_ptr> fBCM;
192 std::vector <VQwBCM_ptr> fBCMCombo;
193
194 std::vector <VQwClock_ptr> fClock;
195
196 std::vector <QwQPD> fQPD;
197 std::vector <QwLinearDiodeArray_ptr> fLinearArray;
198 std::vector <QwBPMCavity> fCavity;
199 std::vector <QwHaloMonitor> fHaloMonitor;
200
201
202 std::vector <QwEnergyCalculator> fECalculator;
203 std::vector <QwBeamDetectorID> fBeamDetectorID;
204
205
206
207/////
208private:
209 // std::vector<TString> DetectorTypes;// for example could be BCM, LUMI,BPMSTRIPLINE, etc..
211
212
213 static const Bool_t bDEBUG=kFALSE;
214
215
216
217};
218
219// Register this subsystem with the factory
#define REGISTER_SUBSYSTEM_FACTORY(A)
Definition QwFactory.h:270
Basic data types and constants used throughout the Qweak analysis framework.
ULong64_t BankID_t
Definition QwTypes.h:21
UInt_t ROCID_t
Definition QwTypes.h:20
EQwBeamInstrumentType
Definition QwTypes.h:143
Beam detector identification and mapping class.
Beam current monitor template class.
Quadrant photodiode beam position monitor implementation.
Virtual base class for beam current monitors.
Cavity beam position monitor implementation.
Beam energy calculation from BPM position measurements.
Halo monitor using scaler channels for beam monitoring.
Virtual base class for parity analysis subsystems.
Stripline beam position monitor implementation.
Linear diode array beam position monitor implementation.
Combined beam position monitor using weighted average.
Combined beam current monitor using weighted average of multiple BCMs.
Command-line and configuration file options processor.
Definition QwOptions.h:141
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:55
The pure virtual base class of all data elements.
Abstract base for concrete hardware channels implementing dual-operator pattern.
Base class for subsystems implementing container-delegation pattern.
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
VQwSubsystem(const TString &name)
Constructor with name.
virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)=0
Construct the branch and tree vector.
Beam detector mapping/ID decoded from map files.
Subsystem aggregating beamline instruments (BPMs, BCMs, clocks, etc.)
Definition QwBeamLine.h:43
void IncrementErrorCounters() override
std::vector< VQwBCM_ptr > fBCM
Definition QwBeamLine.h:191
QwBeamLine(const TString &name)
Constructor with name.
Definition QwBeamLine.h:51
void Scale(Double_t factor) override
void ProcessOptions(QwOptions &options) override
Definition QwBeamLine.cc:40
VQwSubsystem & operator=(VQwSubsystem *value) override
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
void CopyTemplatedDataElements(const VQwSubsystem *source)
size_t GetNumberOfElements()
Int_t AddToElementList(std::vector< TT > &elementlist, QwBeamDetectorID &detector_id)
Adds a new element to a vector of data elements, and returns the index of that element within the arr...
Definition QwBeamLine.cc:99
~QwBeamLine() override
Virtual destructor.
Definition QwBeamLine.h:64
VQwSubsystem & operator+=(VQwSubsystem *value) override
VQwDataElement * GetElement(QwBeamDetectorID det_id)
void LoadMockDataParameters(TString mapfile) override
Bool_t Compare(VQwSubsystem *source)
std::vector< QwEnergyCalculator > fECalculator
Definition QwBeamLine.h:202
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override
std::vector< QwBeamDetectorID > fBeamDetectorID
Definition QwBeamLine.h:203
std::vector< VQwBPM_ptr > fStripline
Definition QwBeamLine.h:188
Int_t GetDetectorIndex(EQwBeamInstrumentType TypeID, TString name) const
void FillHistograms() override
Fill the histograms for this subsystem.
const VQwHardwareChannel * GetChannel(EQwBeamInstrumentType TypeID, Int_t index, TString device_prop) const
Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
Route raw ROC/bank buffer data to the correct devices and subelements.
Bool_t PublishInternalValues() const override
std::vector< QwBPMCavity > fCavity
Definition QwBeamLine.h:198
UInt_t UpdateErrorFlag() override
void AssignGeometry(QwParameterFile *mapstr, VQwBPM *bpm)
void WritePromptSummary(QwPromptSummary *ps, TString type) override
void SetRandomEventAsymmetry(Double_t asymmetry)
QwBeamLine()
Private default constructor (not implemented, will throw linker error on use)
VQwBPM * GetBPMStripline(const TString name)
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
void LoadEventCuts_Init() override
Definition QwBeamLine.h:73
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
std::vector< QwLinearDiodeArray_ptr > fLinearArray
Definition QwBeamLine.h:197
Bool_t CheckForBurpFail(const VQwSubsystem *subsys) override
void CalculateRunningAverage() override
Calculate the average for all good events.
Int_t LoadGeometryDefinition(TString mapfile) override
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill the tree vector.
std::vector< QwQPD > fQPD
Definition QwBeamLine.h:196
Bool_t PublishByRequest(TString device_name) override
QwBeamLine(const QwBeamLine &source)
Copy constructor.
Definition QwBeamLine.h:55
std::vector< VQwBPM_ptr > fBPMCombo
Definition QwBeamLine.h:189
void LoadEventCuts_Fin(Int_t &eventcut_flag) override
Int_t LoadChannelMap(TString mapfile) override
Bool_t ApplySingleEventCuts() override
QwHaloMonitor * GetScalerChannel(const TString name)
VQwBCM * GetBCM(const TString name)
void PrintInfo() const override
Print some information about the subsystem.
VQwClock * GetClock(const TString name)
QwEnergyCalculator * GetEnergyCalculator(const TString name)
Int_t fQwBeamLineErrorCount
Definition QwBeamLine.h:210
void PrintValue() const override
Print values of all channels.
void LoadEventCuts_Line(QwParameterFile &mapstr, TString &varvalue, Int_t &eventcut_flag) override
std::vector< QwHaloMonitor > fHaloMonitor
Definition QwBeamLine.h:199
void PrintErrorCounters() const override
std::vector< VQwBCM_ptr > fBCMCombo
Definition QwBeamLine.h:192
void AccumulateRunningSum(VQwSubsystem *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Update the running sums for devices.
UInt_t GetEventcutErrorFlag() override
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Construct the branch and tree vector.
static const Bool_t bDEBUG
Definition QwBeamLine.h:213
VQwSubsystem & operator-=(VQwSubsystem *value) override
void ProcessEvent() override
void RandomizeEventData(int helicity=0, double time=0.0) override
void EncodeEventData(std::vector< UInt_t > &buffer) override
VQwBCM * GetCombinedBCM(const TString name)
std::vector< VQwClock_ptr > fClock
Definition QwBeamLine.h:194
void ConstructBranch(TTree *tree, TString &prefix) override
Construct the branch and tree vector.
VQwBPM * GetCombinedBPM(const TString name)
void PrintDetectorID() const
QwBPMCavity * GetBPMCavity(const TString name)
void ClearEventData() override
void DeaccumulateRunningSum(VQwSubsystem *value, Int_t ErrorMask=0xFFFFFFF) override
remove one entry from the running sums for devices
Int_t LoadInputParameters(TString pedestalfile) override
Cavity-style BPM using VQWK channels.
Definition QwBPMCavity.h:38
Computes beam energy change from BPM information.
Wrapper around a scaler channel to monitor beam halo rates.
Abstract base for beam current monitors (BCMs)
Definition VQwBCM.h:52
Abstract base for beam position monitors (BPMs)
Definition VQwBPM.h:52
Abstract base for beam clocks used to normalize rates and yields.
Definition VQwClock.h:47
VQwSubsystemParity()
Private default constructor (not implemented, will throw linker error on use)
virtual void FillDB(QwParityDB *, TString)
Fill the database.
virtual void FillErrDB(QwParityDB *, TString)