JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
VQwBCM.h
Go to the documentation of this file.
1/**********************************************************\
2* File: VQwBCM.h *
3* *
4* Author: (??) & J.C Cornejo *
5* Time-stamp: <2011-05-26> *
6\**********************************************************/
7
8/*!
9 * \file VQwBCM.h
10 * \brief Virtual base class for beam current monitors
11 */
12
13#pragma once
14
15// System headers
16#include <vector>
17
18// ROOT headers
19#include <TTree.h>
20
21// RNTuple headers
22#ifdef HAS_RNTUPLE_SUPPORT
23#include "ROOT/RNTupleModel.hxx"
24#endif // HAS_RNTUPLE_SUPPORT
25
26#include "QwParameterFile.h"
27#include "VQwDataElement.h"
28#include "VQwHardwareChannel.h"
29
30// Forward declarations
31#ifdef __USE_DATABASE__
32class QwDBInterface;
34#endif // __USE_DATABASE__
35
36template<typename T> class QwCombinedBCM;
37template<typename T> class QwBCM;
38
39/**
40 * \ingroup QwAnalysis_BeamLine
41 */
42/**
43 * \class VQwBCM
44 * \ingroup QwAnalysis_BeamLine
45 * \brief Abstract base for beam current monitors (BCMs)
46 *
47 * Provides the interface for current-like data elements used for normalization
48 * and beam quality monitoring. Concrete implementations (e.g., QwBCM<T>,
49 * QwCombinedBCM<T>) implement hardware decoding, event processing, and error
50 * handling, while this base exposes common hooks for the analysis framework.
51 */
52class VQwBCM : public VQwDataElement {
53 /***************************************************************
54 * Class: VQwBCM
55 * Pure Virtual base class for the BCMs in the beamline.
56 * Through use of the Create factory function, one can
57 * get a concrete instance of a templated QwBCM.
58 *
59 ***************************************************************/
60 template <typename T> friend class QwBCM;
61 template <typename T> friend class QwCombinedBCM;
62
63protected:
64 VQwBCM(VQwDataElement& beamcurrent): fBeamCurrent_ref(beamcurrent) { };
65 VQwBCM(VQwDataElement& beamcurrent, TString /*name*/): fBeamCurrent_ref(beamcurrent) { };
66
67public:
68 ~VQwBCM() override { };
69
70 // VQwDataElement virtual functions
71 Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override = 0;
72 void ConstructHistograms(TDirectory *folder, TString &prefix) override = 0;
73 void FillHistograms() override = 0;
74 /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
75 virtual void SetSingleEventCuts(UInt_t errorflag,Double_t min, Double_t max, Double_t stability, Double_t burplevel) = 0;
76 virtual void Ratio( const VQwBCM &/*numer*/, const VQwBCM &/*denom*/)
77 { std::cerr << "Ratio not defined! (VQwBCM)" << std::endl; }
78 void ClearEventData() override = 0;
79
80 // Virtual functions delegated to sub classes
81 virtual void InitializeChannel(TString name, TString datatosave) = 0;
82 // new routine added to update necessary information for tree trimming
83 virtual void InitializeChannel(TString subsystem, TString name, TString datatosave) = 0;
84
85 void LoadChannelParameters(QwParameterFile &paramfile) override = 0;
86 Bool_t NeedsExternalClock() override = 0;
87 void SetExternalClockPtr( const VQwHardwareChannel* clock) override = 0;
88 void SetExternalClockName( const std::string name) override = 0;
89 Double_t GetNormClockValue() override = 0;
90
91 virtual void SetDefaultSampleSize(Int_t sample_size) = 0;
92 virtual void SetEventCutMode(Int_t bcuts) = 0;
93 UInt_t UpdateErrorFlag() override{return this->GetEventcutErrorFlag();};
94 virtual void UpdateErrorFlag(const VQwBCM *ev_error) = 0;
95 virtual void SetPedestal(Double_t ped) = 0;
96 virtual void SetCalibrationFactor(Double_t calib) = 0;
97 virtual void RandomizeEventData(int helicity, double time) = 0;
98 virtual void EncodeEventData(std::vector<UInt_t> &buffer) = 0;
99 virtual Bool_t ApplySingleEventCuts() = 0;//Check for good events by setting limits on the devices readings
100 virtual void IncrementErrorCounters() = 0;
101 virtual void ProcessEvent() = 0;
102 virtual void Scale(Double_t factor) = 0;
103 virtual void CalculateRunningAverage() = 0;
104 virtual void AccumulateRunningSum(const VQwBCM& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) = 0;
105 virtual void DeaccumulateRunningSum(VQwBCM& value, Int_t ErrorMask=0xFFFFFFF) = 0;
106 virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) = 0;
107 virtual void ConstructBranch(TTree *tree, TString &prefix) = 0;
108 virtual void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist) = 0;
109 virtual void FillTreeVector(QwRootTreeBranchVector &values) const = 0;
110
111#ifdef HAS_RNTUPLE_SUPPORT
112 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;
113 virtual void FillNTupleVector(std::vector<Double_t>& values) const = 0;
114#endif // HAS_RNTUPLE_SUPPORT
115
116//----------------------------------------------------------------------------------------------------------------
118 {std::cerr << "ApplyResolutionSmearing is undefined!!!\n";}
119 virtual void FillRawEventData()
120 {std::cerr << "FillRawEventData for VQwBPM not implemented!\n";};
121 virtual void GetProjectedCharge(VQwBCM */*device*/){};
122 virtual size_t GetNumberOfElements(){return size_t(1);}
123 virtual TString GetSubElementName(Int_t /*subindex*/)
124 {
125 std::cerr << "GetSubElementName() is not implemented!! for device: " << GetElementName() << "\n";
126 return TString("OBJECT_UNDEFINED"); // Return an erroneous TString
127 }
128//----------------------------------------------------------------------------------------------------------------
129
130#ifdef __USE_DATABASE__
131 virtual std::vector<QwDBInterface> GetDBEntry() = 0;
132 virtual std::vector<QwErrDBInterface> GetErrDBEntry() = 0;
133#endif // __USE_DATABASE__
134
135 virtual Double_t GetValue() = 0;
136 virtual Double_t GetValueError() = 0;
137 virtual Double_t GetValueWidth() = 0;
138
139//------------------------------------------------------------------------------------------------------------------------------------------
140
141 // virtual const VQwHardwareChannel* GetCharge() const = 0; //Replace this with a const_cast use of the protected function; define a pure virtual protected function that is non-const; In the QwBCM class, change the defined function to be the protected non-const version.
142
143 virtual const VQwHardwareChannel* GetCharge() const{
144 return const_cast<VQwBCM*>(this)->GetCharge();
145 }
146
147 // Ensure polymorphic dispatch for burp-failure checks via VQwBCM*
148 virtual Bool_t CheckForBurpFail(const VQwDataElement* ev_error) {
149 return VQwDataElement::CheckForBurpFail(ev_error);
150 }
151
152protected:
154
155//------------------------------------------------------------------------------------------------------------------------------------------
156
157public:
158
159 virtual void SetRandomEventParameters(Double_t mean, Double_t sigma) = 0;
160 virtual void SetRandomEventAsymmetry(Double_t asymmetry) = 0 ;
161 virtual void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency) =0;
162
163 // Operators
164 virtual VQwBCM& operator= (const VQwBCM &value) =0;
165 virtual VQwBCM& operator+= (const VQwBCM &value) =0;
166 virtual VQwBCM& operator-= (const VQwBCM &value) =0;
167
168 // This one is for QwCombinedBCM (could be done differently)
169 virtual void SetBCMForCombo(VQwBCM* bcm, Double_t weight, Double_t sumqw ) = 0;
170
171
172 // Factory function to produce appropriate BCM
173 static VQwBCM* Create(TString subsystemname, TString type, TString name, TString clock = "");
174 static VQwBCM* Create(const VQwBCM& source); // Create a generic BCM (define properties later)
175 static VQwBCM* CreateCombo(TString subsystemname, TString type, TString name);
176 static VQwBCM* CreateCombo(const VQwBCM& source); // Create a generic BCM (define properties later)
177
178
179protected:
181
182};
183
184typedef std::shared_ptr<VQwBCM> VQwBCM_ptr;
Parameter file parsing and management.
Definition of the pure virtual base class of all data elements.
std::shared_ptr< VQwBCM > VQwBCM_ptr
Definition VQwBCM.h:184
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
VQwDataElement()
Default constructor.
virtual UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
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.
Template for a combined beam current monitor using weighted inputs.
Templated concrete beam current monitor implementation.
Definition QwBCM.h:36
virtual void DeaccumulateRunningSum(VQwBCM &value, Int_t ErrorMask=0xFFFFFFF)=0
virtual void EncodeEventData(std::vector< UInt_t > &buffer)=0
virtual VQwHardwareChannel * GetCharge()=0
~VQwBCM() override
Definition VQwBCM.h:68
virtual VQwBCM & operator-=(const VQwBCM &value)=0
virtual void InitializeChannel(TString name, TString datatosave)=0
virtual void CalculateRunningAverage()=0
virtual void SetCalibrationFactor(Double_t calib)=0
friend class QwCombinedBCM
Definition VQwBCM.h:61
virtual void FillTreeVector(QwRootTreeBranchVector &values) const =0
friend class QwBCM
Definition VQwBCM.h:60
virtual Double_t GetValueWidth()=0
virtual void SetBCMForCombo(VQwBCM *bcm, Double_t weight, Double_t sumqw)=0
static VQwBCM * CreateCombo(TString subsystemname, TString type, TString name)
Factory method to create a concrete Combined BCM for the requested module type.
Definition VQwBCM.cc:101
void LoadChannelParameters(QwParameterFile &paramfile) override=0
virtual void RandomizeEventData(int helicity, double time)=0
virtual void AccumulateRunningSum(const VQwBCM &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)=0
virtual size_t GetNumberOfElements()
Definition VQwBCM.h:122
VQwDataElement & fBeamCurrent_ref
Definition VQwBCM.h:180
virtual Bool_t ApplySingleEventCuts()=0
virtual VQwBCM & operator=(const VQwBCM &value)=0
void ConstructHistograms(TDirectory *folder, TString &prefix) override=0
Construct the histograms for this data element.
virtual void Ratio(const VQwBCM &, const VQwBCM &)
Definition VQwBCM.h:76
virtual VQwBCM & operator+=(const VQwBCM &value)=0
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override=0
Process the CODA event buffer for this element.
virtual void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile &modulelist)=0
virtual void FillRawEventData()
Definition VQwBCM.h:119
Bool_t NeedsExternalClock() override=0
void SetExternalClockPtr(const VQwHardwareChannel *clock) override=0
virtual void SetRandomEventAsymmetry(Double_t asymmetry)=0
virtual Double_t GetValue()=0
virtual void SetPedestal(Double_t ped)=0
virtual void Scale(Double_t factor)=0
VQwBCM(VQwDataElement &beamcurrent)
Definition VQwBCM.h:64
virtual void GetProjectedCharge(VQwBCM *)
Definition VQwBCM.h:121
virtual void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)=0
virtual void UpdateErrorFlag(const VQwBCM *ev_error)=0
void FillHistograms() override=0
Fill the histograms for this data element.
virtual Double_t GetValueError()=0
virtual Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Definition VQwBCM.h:148
virtual void ConstructBranch(TTree *tree, TString &prefix)=0
virtual const VQwHardwareChannel * GetCharge() const
Definition VQwBCM.h:143
virtual void IncrementErrorCounters()=0
void SetExternalClockName(const std::string name) override=0
virtual TString GetSubElementName(Int_t)
Definition VQwBCM.h:123
void ClearEventData() override=0
Clear the event data in this element.
virtual void InitializeChannel(TString subsystem, TString name, TString datatosave)=0
virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)=0
virtual void SetSingleEventCuts(UInt_t errorflag, Double_t min, Double_t max, Double_t stability, Double_t burplevel)=0
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit),...
Double_t GetNormClockValue() override=0
virtual void ProcessEvent()=0
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
virtual void SetDefaultSampleSize(Int_t sample_size)=0
virtual void SetRandomEventParameters(Double_t mean, Double_t sigma)=0
static VQwBCM * Create(TString subsystemname, TString type, TString name, TString clock="")
Factory method to create a concrete BCM instance for the requested module type.
Definition VQwBCM.cc:41
VQwBCM(VQwDataElement &beamcurrent, TString)
Definition VQwBCM.h:65
virtual void SetEventCutMode(Int_t bcuts)=0
virtual void ApplyResolutionSmearing()
Definition VQwBCM.h:117