JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwMollerADC_Channel.h
Go to the documentation of this file.
1
2/*!
3 * \file QwMollerADC_Channel.h
4 * \brief Decoding and management for Moller ADC channels (6x32-bit datawords)
5 * \author Kevin Ward (Original code by P.M. King)
6 * \date 20021-05-25
7 */
8
9#pragma once
10
11// System headers
12#include <vector>
13
14// ROOT headers
15#include "TTree.h"
16
17// Qweak headers
18#include "VQwHardwareChannel.h"
19#include "MQwMockable.h"
20#include "QwRootFile.h"
21
22// Forward declarations
23class QwBlinder;
24class QwParameterFile;
25#ifdef __USE_DATABASE__
27#endif
28
29///
30/// \ingroup QwAnalysis_ADC
31///
32/// \ingroup QwAnalysis_BL
33/**
34 * \class QwMollerADC_Channel
35 * \ingroup QwAnalysis_ADC
36 * \brief Concrete hardware channel for Moller ADC modules (6x32-bit words)
37 *
38 * Decodes and processes the data for a single Moller ADC channel and exposes
39 * block-level values, sums, and statistical moments. Supports single-event
40 * cuts, error propagation, blinding, and running statistics. Follows the
41 * dual-operator pattern to provide both type-specific operators and
42 * polymorphic operator overrides via VQwHardwareChannel.
43 */
45/****************************************************************//**
46 * Class: QwMollerADC_Channel
47 * Base class containing decoding functions for the MollerADC_Channel
48 * 6 32-bit datawords.
49 * The functions in this class will decode a single channel
50 * worth of MollerADC_Channel data and provide the components
51 * through member functions.
52 ******************************************************************/
53 public:
54 static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex);
55 static void PrintErrorCounterHead();
56 static void PrintErrorCounterTail();
57
58 static const Double_t kTimePerSample;
59
61
67
70
71 public:
73 InitializeChannel("","");
74 SetMollerADCSaturationLimt(8.5);//set the default saturation limit
75 };
76 QwMollerADC_Channel(TString name, TString datatosave = "raw"): MQwMockable() {
77 InitializeChannel(name, datatosave);
78 SetMollerADCSaturationLimt(8.5);//set the default saturation limit
79 };
96 ~QwMollerADC_Channel() override { };
97
105
106
108
110 return new QwMollerADC_Channel(*this,datatosave);
111 };
112
113 /// \brief Initialize the fields in this object
114 void InitializeChannel(TString name, TString datatosave) override;
115
116 /// \brief Initialize the fields in this object
117 void InitializeChannel(TString subsystem, TString instrumenttype, TString name, TString datatosave) override;
118
119 void LoadChannelParameters(QwParameterFile &paramfile) override;
120
121 // Will update the default sample size for the module.
122 void SetDefaultSampleSize(size_t num_samples_map) {
123 // This will be checked against the no.of samples read by the module
124 fNumberOfSamples_map = num_samples_map;
125 };
126
127 void ClearEventData() override;
128
129 /// Internally generate random event data
130 void RandomizeEventData(int helicity = 0.0, double time = 0.0) override;
131
132 /// Forces the event "number of samples" variable to be what was expected from the mapfile.
133 /// NOTE: this should only be used in mock data generation!
135
136//------------------------------------------------------------------------------------------
137 void SmearByResolution(double resolution) override;
138//------------------------------------------------------------------------------------------
139
140 /// TODO: SetHardwareSum should be removed, and SetEventData
141 /// should be made protected.
142 void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber = 0);
143 void SetEventData(Double_t* block, UInt_t sequencenumber = 0);
144 void SetRawEventData() override;
145
146 /// Encode the event data into a CODA buffer
147 void EncodeEventData(std::vector<UInt_t> &buffer) override;
148 /// Decode the event data from a CODA buffer
149 Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t num_words_left, UInt_t index = 0) override;
150 /// Process the event data according to pedestal and calibration factor
151 void ProcessEvent() override;
152
153
155 void AssignScaledValue(const QwMollerADC_Channel &value, Double_t scale);
156 void AssignValueFrom(const VQwDataElement* valueptr) override;
157 void AddValueFrom(const VQwHardwareChannel* valueptr) override;
158 void SubtractValueFrom(const VQwHardwareChannel* valueptr) override;
159 void MultiplyBy(const VQwHardwareChannel* valueptr) override;
160 void DivideBy(const VQwHardwareChannel* valueptr) override;
161 void ArcTan(const QwMollerADC_Channel &value);
162
166
167 VQwHardwareChannel& operator+=(const VQwHardwareChannel& input) override;
168 VQwHardwareChannel& operator-=(const VQwHardwareChannel& input) override;
169 VQwHardwareChannel& operator*=(const VQwHardwareChannel& input) override;
170 VQwHardwareChannel& operator/=(const VQwHardwareChannel& input) override;
171
172 const QwMollerADC_Channel operator+ (const QwMollerADC_Channel &value) const;
173 const QwMollerADC_Channel operator- (const QwMollerADC_Channel &value) const;
174 const QwMollerADC_Channel operator* (const QwMollerADC_Channel &value) const;
175 void Sum(const QwMollerADC_Channel &value1, const QwMollerADC_Channel &value2);
176 void Difference(const QwMollerADC_Channel &value1, const QwMollerADC_Channel &value2);
177 void Ratio(const QwMollerADC_Channel &numer, const QwMollerADC_Channel &denom);
178 void Product(const QwMollerADC_Channel &value1, const QwMollerADC_Channel &value2);
179 void DivideBy(const QwMollerADC_Channel& denom);
180 void AddChannelOffset(Double_t Offset);
181 void Scale(Double_t Offset) override;
182
183
184 /**
185 * Accumulate event values into the running sum with optional scaling.
186 * @param value Source channel to accumulate from.
187 * @param count Event count scaling (0 means use value.fGoodEventCount).
188 * @param ErrorMask Bit mask of error flags to exclude when accumulating.
189 */
190 void AccumulateRunningSum(const QwMollerADC_Channel& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
191 void AccumulateRunningSum(const VQwHardwareChannel *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override{
192 const QwMollerADC_Channel *tmp_ptr = dynamic_cast<const QwMollerADC_Channel*>(value);
193 if (tmp_ptr != NULL) {
194 AccumulateRunningSum(*tmp_ptr, count, ErrorMask);
195 } else {
196 throw std::invalid_argument("Standard exception from QwMollerADC_Channel::AccumulateRunningSum: incompatible hardware channel type");
197 }
198 };
199 ////deaccumulate one value from the running sum
200 inline void DeaccumulateRunningSum(const QwMollerADC_Channel& value, Int_t ErrorMask=0xFFFFFFF){
201 AccumulateRunningSum(value, -1, ErrorMask);
202 };
203 /*
204 void DeaccumulateRunningSum(VQwHardwareChannel *value){
205 const QwMollerADC_Channel *tmp_ptr = dynamic_cast<const QwMollerADC_Channel*>(value);
206 if (tmp_ptr != NULL) {
207 DeaccumulateRunningSum(*tmp_ptr);
208 } else {
209 throw std::invalid_argument("Standard exception from QwMollerADC_Channel::DeaccumulateRunningSum: incompatible hardware channel type");
210 }
211 };
212 */
213
214 void CalculateRunningAverage() override;
215
216 Bool_t MatchSequenceNumber(size_t seqnum);
217 Bool_t MatchNumberOfSamples(size_t numsamp);
218
219 /*Event cut related routines*/
220 Bool_t ApplySingleEventCuts(Double_t LL,Double_t UL);//check values read from modules are at desired level
221 Bool_t ApplySingleEventCuts() override;//check values read from modules are at desired level by comparing upper and lower limits (fULimit and fLLimit) set on this channel
222 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure
223
224 void SetMollerADCSaturationLimt(Double_t sat_volts=8.5){//Set the absolute staturation limit in volts.
225 fSaturationABSLimit=sat_volts;
226 }
227
228 Double_t GetMollerADCSaturationLimt(){//Get the absolute staturation limit in volts.
229 return fSaturationABSLimit;
230 }
231
232
233 Int_t ApplyHWChecks() override; //Check for hardware errors in the devices. This will return the device error code.
234
235 void IncrementErrorCounters() override;//update the error counters based on the internal fErrorFlag
236
237 /*End*/
238
239 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
240 void FillHistograms() override;
241
242 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
243 void ConstructBranch(TTree *tree, TString &prefix) override;
244 void FillTreeVector(QwRootTreeBranchVector &values) const override;
245#ifdef HAS_RNTUPLE_SUPPORT
246 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
247 void FillNTupleVector(std::vector<Double_t>& values) const override;
248#endif // HAS_RNTUPLE_SUPPORT
249
250 void CopyParameters(const VQwHardwareChannel* valueptr) override;
251
252 Int_t GetRawValue(size_t element) const override {
253 RangeCheck(element);
254 if (element==0) return fHardwareBlockSum_raw;
255 return fBlock_raw[element-1];
256 }
257 Double_t GetValue(size_t element) const override {
258 RangeCheck(element);
259 if (element==0) return fHardwareBlockSum;
260 return fBlock[element-1];
261 }
262 Double_t GetValueM2(size_t element) const override {
263 RangeCheck(element);
264 if (element==0) return fHardwareBlockSumM2;
265 return fBlockM2[element-1];
266 }
267 Double_t GetValueError(size_t element) const override {
268 RangeCheck(element);
269 if (element==0) return fHardwareBlockSumError;
270 return fBlockError[element-1];
271 }
272
273
274 Double_t GetAverageVolts() const;
275
276 size_t GetSequenceNumber() const {return (fSequenceNumber);};
277 size_t GetNumberOfSamples() const {return (fNumberOfSamples);};
278
280
281 friend std::ostream& operator<< (std::ostream& stream, const QwMollerADC_Channel& channel);
282 void PrintValue() const override;
283 void PrintInfo() const override;
284
285 /// \brief Blind this channel as an asymmetry
286 void Blind(const QwBlinder *blinder);
287 /// \brief Blind this channel as a difference
288 void Blind(const QwBlinder *blinder, const QwMollerADC_Channel& yield);
289
290 void ScaledAdd(Double_t scale, const VQwHardwareChannel *value) override;
291
292#ifdef __USE_DATABASE__
293 // Error Counters exist in QwMollerADC_Channel, not in VQwHardwareChannel
294 //
295 void AddErrEntriesToList(std::vector<QwErrDBInterface> &row_list);
296#endif
297
298 protected:
300
301private:
302 // The following specific access methods should only be used internally,
303 // if at all.
304 Double_t GetBlockValue(size_t blocknum) const { return GetValue(blocknum+1);};
305 Double_t GetBlockErrorValue(size_t blocknum) const { return GetValueError(blocknum+1);};
306
307 Double_t GetHardwareSum() const { return GetValue(0);};
308 Double_t GetHardwareSumM2() const { return GetValueM2(0); };
309 Double_t GetHardwareSumWidth() const { return GetValueWidth(0); };
310 Double_t GetHardwareSumError() const { return GetValueError(0); };
311 // Double_t GetSoftwareSum() const {return fSoftwareBlockSum;};
312
313 Int_t GetRawBlockValue(size_t blocknum) const {return GetRawValue(blocknum+1);};
314 Int_t GetRawHardwareSum() const { return GetRawValue(0);};
316
317 private:
318 static const Bool_t kDEBUG;
319 static const Int_t kWordsPerChannel; //no.of words per channel in the CODA buffer
320 static const Int_t kMaxChannels; //no.of channels per module
321
322 /*! \name ADC Calibration */
323 // @{
324 static const Double_t kMollerADC_VoltsPerBit;
325 //@}
326
327
328 /*! \name Channel information data members */
329
330 /*! \name Channel configuration data members */
331 // @{
332
333 //UInt_t fBlocksPerEvent;
335 // @}
336
337
338 /*! \name Event data members---Raw values */
339 // @{
340 Int_t fBlock_raw[4]; ///< Array of the sub-block data as read from the module
341 Int_t fHardwareBlockSum_raw; ///< Module-based sum of the four sub-blocks as read from the module
342 Int_t fSoftwareBlockSum_raw; ///< Sum of the data in the four sub-blocks raw
343 Long64_t fBlockSumSq_raw[5];
344 Int_t fBlock_min[5];
345 Int_t fBlock_max[5];
347 // @}
348
349 /*! \name Event data members---Potentially calibrated values*/
350 // @{
351 // The following values potentially have pedestal removed and calibration applied
352 Double_t fBlock[4]; ///< Array of the sub-block data
353 Double_t fHardwareBlockSum; ///< Module-based sum of the four sub-blocks
354 // @}
355
356
357 /// \name Calculation of the statistical moments
358 // @{
359 // Moments of the separate blocks
360 Double_t fBlockM2[4]; ///< Second moment of the sub-block
361 Double_t fBlockError[4]; ///< Uncertainty on the sub-block
362 // Moments of the hardware sum
363 Double_t fHardwareBlockSumM2; ///< Second moment of the hardware sum
364 Double_t fHardwareBlockSumError; ///< Uncertainty on the hardware sum
365 // @}
366
367
368 UInt_t fSequenceNumber; ///< Event sequence number for this channel
369 UInt_t fPreviousSequenceNumber; ///< Previous event sequence number for this channel
370 UInt_t fNumberOfSamples; ///< Number of samples read through the module
371 UInt_t fNumberOfSamples_map; ///< Number of samples in the expected to read through the module. This value is set in the QwBeamline map file
372
373
374 // Set of error counters for each HW test.
375 Int_t fErrorCount_HWSat; ///< check to see ADC channel is saturated
376 Int_t fErrorCount_sample; ///< for sample size check
377 Int_t fErrorCount_SW_HW; ///< HW_sum==SW_sum check
378 Int_t fErrorCount_Sequence; ///< sequence number check
379 Int_t fErrorCount_SameHW; ///< check to see ADC returning same HW value
380 Int_t fErrorCount_ZeroHW; ///< check to see ADC returning zero
381
382 Int_t fNumEvtsWithEventCutsRejected; ///< Counts the Event cut rejected events
383
384
385
386
387
388
389 Int_t fADC_Same_NumEvt; ///< Keep track of how many events with same ADC value returned
390 Int_t fSequenceNo_Prev; ///< Keep the sequence number of the last event
391 Int_t fSequenceNo_Counter; ///< Internal counter to keep track of the sequence number
392 Double_t fPrev_HardwareBlockSum; ///< Previous Module-based sum of the four sub-blocks
393
394
395
396 Double_t fSaturationABSLimit;///<absolute value of the MollerADC saturation volt
397
398
399 const static Bool_t bDEBUG=kFALSE;///<debugging display purposes
400
401 ///<For MollerADC data element trimming uses
402 Bool_t bHw_sum;
404 Bool_t bBlock;
409
410private:
411
412
413
414
415
416
417};
ROOT file and tree management wrapper classes.
virtual void LoadMockDataParameters(QwParameterFile &paramfile)
Load the mock data parameters from the current line in the param file.
Concrete hardware channel for Moller ADC modules (6x32-bit words)
Int_t GetRawSoftwareSum() const
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t index=0) override
Decode the event data from a CODA buffer.
Double_t GetHardwareSumM2() const
Double_t GetValueError() const
const QwMollerADC_Channel operator*(const QwMollerADC_Channel &value) const
void AssignValueFrom(const VQwDataElement *valueptr) override
Double_t GetValueError(size_t element) const override
Int_t fErrorCount_SW_HW
HW_sum==SW_sum check.
VQwHardwareChannel & operator/=(const VQwHardwareChannel &input) override
QwMollerADC_Channel(TString name, TString datatosave="raw")
void AddChannelOffset(Double_t Offset)
void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber=0)
static void PrintErrorCounterHead()
void LoadChannelParameters(QwParameterFile &paramfile) override
Double_t GetValueM2() const
QwMollerADC_Channel & operator+=(const QwMollerADC_Channel &value)
void DeaccumulateRunningSum(const QwMollerADC_Channel &value, Int_t ErrorMask=0xFFFFFFF)
UInt_t fSequenceNumber
Event sequence number for this channel.
void RandomizeEventData(int helicity=0.0, double time=0.0) override
Internally generate random event data.
static const Bool_t kDEBUG
QwMollerADC_Channel(const QwMollerADC_Channel &value)
QwMollerADC_Channel & operator=(const QwMollerADC_Channel &value)
Double_t fPrev_HardwareBlockSum
Previous Module-based sum of the four sub-blocks.
QwMollerADC_Channel & operator*=(const QwMollerADC_Channel &value)
const QwMollerADC_Channel operator-(const QwMollerADC_Channel &value) const
Bool_t ApplySingleEventCuts() override
Int_t GetRawValue(size_t element) const override
void MultiplyBy(const VQwHardwareChannel *valueptr) override
Double_t fBlockError[4]
Uncertainty on the sub-block.
void PrintValue() const override
Print single line of value and error of this data element.
void ScaledAdd(Double_t scale, const VQwHardwareChannel *value) override
void Sum(const QwMollerADC_Channel &value1, const QwMollerADC_Channel &value2)
void ProcessEvent() override
Process the event data according to pedestal and calibration factor.
Int_t fSequenceNo_Counter
Internal counter to keep track of the sequence number.
Int_t GetRawBlockValue(size_t blocknum) const
QwMollerADC_Channel & operator-=(const QwMollerADC_Channel &value)
void PrintErrorCounters() const override
report number of events failed due to HW and event cut failure
Bool_t MatchSequenceNumber(size_t seqnum)
Double_t fHardwareBlockSum
Module-based sum of the four sub-blocks.
void InitializeChannel(TString name, TString datatosave) override
Initialize the fields in this object.
Double_t GetBlockErrorValue(size_t blocknum) const
Int_t fErrorCount_sample
for sample size check
static const Int_t kMaxChannels
UInt_t fNumberOfSamples_map
Number of samples in the expected to read through the module. This value is set in the QwBeamline map...
void SetDefaultSampleSize(size_t num_samples_map)
void Blind(const QwBlinder *blinder)
Blind this channel as an asymmetry.
Int_t fErrorCount_ZeroHW
check to see ADC returning zero
void ArcTan(const QwMollerADC_Channel &value)
void DivideBy(const VQwHardwareChannel *valueptr) override
Int_t fNumEvtsWithEventCutsRejected
Counts the Event cut rejected events.
void SetEventData(Double_t *block, UInt_t sequencenumber=0)
void Scale(Double_t Offset) override
Double_t GetMollerADCSaturationLimt()
Int_t fErrorCount_HWSat
check to see ADC channel is saturated
QwMollerADC_Channel(const QwMollerADC_Channel &value, VQwDataElement::EDataToSave datatosave)
void Ratio(const QwMollerADC_Channel &numer, const QwMollerADC_Channel &denom)
void CopyParameters(const VQwHardwareChannel *valueptr) override
void SetRawEventData() override
Int_t fSoftwareBlockSum_raw
Sum of the data in the four sub-blocks raw.
Double_t fSaturationABSLimit
absolute value of the MollerADC saturation volt
Double_t GetValue(size_t element) const override
Int_t fBlock_raw[4]
Array of the sub-block data as read from the module.
static const Double_t kTimePerSample
void EncodeEventData(std::vector< UInt_t > &buffer) override
Encode the event data into a CODA buffer.
void AddValueFrom(const VQwHardwareChannel *valueptr) override
void AccumulateRunningSum(const VQwHardwareChannel *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
Int_t fErrorCount_SameHW
check to see ADC returning same HW value
void FillHistograms() override
Fill the histograms for this data element.
Double_t fBlockM2[4]
Second moment of the sub-block.
Int_t GetRawHardwareSum() const
Double_t GetValueM2(size_t element) const override
Int_t ApplyHWChecks() override
void SetMollerADCSaturationLimt(Double_t sat_volts=8.5)
Int_t fErrorCount_Sequence
sequence number check
static void PrintErrorCounterTail()
Int_t fHardwareBlockSum_raw
Module-based sum of the four sub-blocks as read from the module.
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
VQwHardwareChannel * Clone(VQwDataElement::EDataToSave datatosave) const override
UInt_t fPreviousSequenceNumber
Previous event sequence number for this channel.
static const Int_t kWordsPerChannel
Double_t GetValueWidth() const
void IncrementErrorCounters() override
Double_t fHardwareBlockSumError
Uncertainty on the hardware sum.
friend std::ostream & operator<<(std::ostream &stream, const QwMollerADC_Channel &channel)
void CopyFrom(const QwMollerADC_Channel &value)
Double_t GetBlockValue(size_t blocknum) const
Double_t fBlock[4]
Array of the sub-block data.
void PrintInfo() const override
Print multiple lines of information about this data element.
void SubtractValueFrom(const VQwHardwareChannel *valueptr) override
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Double_t GetHardwareSum() const
void FillTreeVector(QwRootTreeBranchVector &values) const override
Double_t GetValue() const
Int_t fADC_Same_NumEvt
Keep track of how many events with same ADC value returned.
size_t GetNumberOfSamples() const
void CalculateRunningAverage() override
void AccumulateRunningSum(const QwMollerADC_Channel &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
const QwMollerADC_Channel operator+(const QwMollerADC_Channel &value) const
static const Bool_t bDEBUG
debugging display purposes
Double_t GetHardwareSumWidth() const
Double_t GetAverageVolts() const
Int_t fSequenceNo_Prev
Keep the sequence number of the last event.
void Product(const QwMollerADC_Channel &value1, const QwMollerADC_Channel &value2)
void AssignScaledValue(const QwMollerADC_Channel &value, Double_t scale)
void SmearByResolution(double resolution) override
Double_t fHardwareBlockSumM2
Second moment of the hardware sum.
static const Double_t kMollerADC_VoltsPerBit
void ClearEventData() override
Clear the event data in this element.
void Difference(const QwMollerADC_Channel &value1, const QwMollerADC_Channel &value2)
size_t GetSequenceNumber() const
UInt_t fNumberOfSamples
Number of samples read through the module.
Bool_t MatchNumberOfSamples(size_t numsamp)
Double_t GetHardwareSumError() const
void ConstructBranch(TTree *tree, TString &prefix) override
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.
Abstract base for concrete hardware channels implementing dual-operator pattern.
Double_t GetValueError() const
Double_t GetValueM2() const
void SetCalibrationFactor(Double_t factor)
void CopyFrom(const VQwHardwareChannel &value)
virtual VQwHardwareChannel * Clone() const
virtual void AddErrEntriesToList(std::vector< QwErrDBInterface > &)
Double_t GetValueWidth() const
void RangeCheck(size_t element) const
Checks that the requested element is in range, to be used in accesses to subelements similar to std::...
Double_t GetValue() const
virtual void DeaccumulateRunningSum(const VQwHardwareChannel *value, Int_t ErrorMask=0xFFFFFFF)
virtual void AccumulateRunningSum(const VQwHardwareChannel *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
Data blinding utilities for parity violation analysis.
Definition QwBlinder.h:57