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),
59 fCavity(source.fCavity),
63 { this->CopyTemplatedDataElements(&source); }
64 /// Virtual destructor
65 ~QwBeamLine() override { };
66
67 void CopyTemplatedDataElements(const VQwSubsystem *source);
68
69 /* derived from VQwSubsystem */
70
71 void ProcessOptions(QwOptions &options) override;//Handle command line options
72 Int_t LoadChannelMap(TString mapfile) override;
73 Int_t LoadInputParameters(TString pedestalfile) override;
74 void LoadEventCuts_Init() override {};
75 void LoadEventCuts_Line(QwParameterFile &mapstr, TString &varvalue, Int_t &eventcut_flag) override;
76 void LoadEventCuts_Fin(Int_t &eventcut_flag) override;
77 Int_t LoadGeometryDefinition(TString mapfile) override;
78 void LoadMockDataParameters(TString mapfile) override;
79 void AssignGeometry(QwParameterFile* mapstr, VQwBPM * bpm);
80
81 Bool_t ApplySingleEventCuts() override;//derived from VQwSubsystemParity
82 void IncrementErrorCounters() override;
83
84 Bool_t CheckForBurpFail(const VQwSubsystem *subsys) override;
85
86 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failures
87 UInt_t GetEventcutErrorFlag() override;//return the error flag
88
89 UInt_t UpdateErrorFlag() override;//Update and return the error flags
90
91 //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
92 void UpdateErrorFlag(const VQwSubsystem *ev_error) override;
93
94 Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words) override;
95 Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words) override;
96 void PrintDetectorID() const;
97
98 void ClearEventData() override;
99 void ProcessEvent() override;
100
101 Bool_t PublishInternalValues() const override;
102 Bool_t PublishByRequest(TString device_name) override;
103
104
105 public:
107 void RandomizeEventData(int helicity = 0, double time = 0.0) override;
108 void SetRandomEventAsymmetry(Double_t asymmetry);
109 void EncodeEventData(std::vector<UInt_t> &buffer) override;
110
111 VQwSubsystem& operator= (VQwSubsystem *value) override;
112 VQwSubsystem& operator+= (VQwSubsystem *value) override;
113 VQwSubsystem& operator-= (VQwSubsystem *value) override;
114 void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override;
115
116 void Scale(Double_t factor) override;
117
118 void AccumulateRunningSum(VQwSubsystem* value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override;
119 //remove one entry from the running sums for devices
120 void DeaccumulateRunningSum(VQwSubsystem* value, Int_t ErrorMask=0xFFFFFFF) override;
121
122
123 void CalculateRunningAverage() override;
124
126 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
127 void FillHistograms() override;
128
130 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
131 void ConstructBranch(TTree *tree, TString &prefix) override;
132 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& trim_file ) override;
133 void FillTreeVector(QwRootTreeBranchVector &values) const override;
134
135#ifdef HAS_RNTUPLE_SUPPORT
136 using VQwSubsystem::ConstructNTupleAndVector;
137 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
138 void FillNTupleVector(std::vector<Double_t>& values) const override;
139#endif
140
141#ifdef __USE_DATABASE__
142 void FillDB(QwParityDB *db, TString datatype);
143 void FillErrDB(QwParityDB *db, TString datatype);
144#endif // __USE_DATABASE__
145
146 Bool_t Compare(VQwSubsystem *source);
147
148 void PrintValue() const override;
149 void PrintInfo() const override;
150 void WritePromptSummary(QwPromptSummary *ps, TString type) override;
151
153 VQwDataElement* GetElement(EQwBeamInstrumentType TypeID, TString name);
154 VQwDataElement* GetElement(EQwBeamInstrumentType TypeID, Int_t index);
155 const VQwDataElement* GetElement(EQwBeamInstrumentType TypeID, Int_t index) const;
156
157 const VQwHardwareChannel* GetChannel(EQwBeamInstrumentType TypeID, Int_t index, TString device_prop) const;
158
159 VQwBPM* GetBPMStripline(const TString name);
160 VQwBCM* GetBCM(const TString name);
161 VQwClock* GetClock(const TString name);
162 QwBPMCavity* GetBPMCavity(const TString name);
163 VQwBCM* GetCombinedBCM(const TString name);
164 VQwBPM* GetCombinedBPM(const TString name);
165 QwEnergyCalculator* GetEnergyCalculator(const TString name);
166 QwHaloMonitor* GetScalerChannel(const TString name);
167 const QwBPMCavity* GetBPMCavity(const TString name) const;
168 const VQwBPM* GetBPMStripline(const TString name) const;
169 const VQwBCM* GetBCM(const TString name) const;
170 const VQwClock* GetClock(const TString name) const;
171 const VQwBCM* GetCombinedBCM(const TString name) const;
172 const VQwBPM* GetCombinedBPM(const TString name) const;
173 const QwEnergyCalculator* GetEnergyCalculator(const TString name) const;
174 const QwHaloMonitor* GetScalerChannel(const TString name) const;
175
176
177/////
178protected:
179
180 /// \brief Adds a new element to a vector of data elements, and returns
181 /// the index of that element within the array.
182 template <typename TT>
183 Int_t AddToElementList(std::vector<TT> &elementlist, QwBeamDetectorID &detector_id);
184
185 Int_t GetDetectorIndex(EQwBeamInstrumentType TypeID, TString name) const;
186 //when the type and the name is passed the detector index from appropriate vector will be returned
187 //for example if TypeID is bcm then the index of the detector from fBCM vector for given name will be returned.
188
189 std::vector <VQwBPM_ptr> fStripline;
190 std::vector <VQwBPM_ptr> fBPMCombo;
191
192 std::vector <VQwBCM_ptr> fBCM;
193 std::vector <VQwBCM_ptr> fBCMCombo;
194
195 std::vector <VQwClock_ptr> fClock;
196
197 std::vector <QwQPD> fQPD;
198 std::vector <QwLinearDiodeArray> fLinearArray;
199 std::vector <QwBPMCavity> fCavity;
200 std::vector <QwHaloMonitor> fHaloMonitor;
201
202
203 std::vector <QwEnergyCalculator> fECalculator;
204 std::vector <QwBeamDetectorID> fBeamDetectorID;
205
206
207
208/////
209private:
210 // std::vector<TString> DetectorTypes;// for example could be BCM, LUMI,BPMSTRIPLINE, etc..
212
213
214 static const Bool_t bDEBUG=kFALSE;
215
216
217
218};
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
Combined beam position monitor using weighted average.
Quadrant photodiode beam position monitor implementation.
Beam detector identification and mapping class.
Virtual base class for parity analysis subsystems.
Halo monitor using scaler channels for beam monitoring.
Linear diode array beam position monitor implementation.
Virtual base class for beam current monitors.
Stripline beam position monitor implementation.
Cavity beam position monitor implementation.
Beam energy calculation from BPM position measurements.
Combined beam current monitor using weighted average of multiple BCMs.
Beam current monitor template class.
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:53
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.
void IncrementErrorCounters() override
std::vector< VQwBCM_ptr > fBCM
Definition QwBeamLine.h:192
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:43
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:95
~QwBeamLine() override
Virtual destructor.
Definition QwBeamLine.h:65
std::vector< QwLinearDiodeArray > fLinearArray
Definition QwBeamLine.h:198
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:203
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override
std::vector< QwBeamDetectorID > fBeamDetectorID
Definition QwBeamLine.h:204
std::vector< VQwBPM_ptr > fStripline
Definition QwBeamLine.h:189
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:199
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:74
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
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:197
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:190
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:211
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:200
void PrintErrorCounters() const override
std::vector< VQwBCM_ptr > fBCMCombo
Definition QwBeamLine.h:193
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:214
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:195
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)