JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwIntegrationPMT.h
Go to the documentation of this file.
1/*!
2 * \file QwIntegrationPMT.h
3 * \brief Integration PMT detector for charge and asymmetry measurements
4 */
5
6#pragma once
7
8// System headers
9#include <vector>
10
11// ROOT headers
12#include <TTree.h>
13#ifdef HAS_RNTUPLE_SUPPORT
14#include "ROOT/RNTupleModel.hxx"
15#include "ROOT/RField.hxx"
16#endif // HAS_RNTUPLE_SUPPORT
17
18// Qweak headers
19#include "QwMollerADC_Channel.h"
20#include "QwParameterFile.h"
21
22// Forward declarations
23class QwBlinder;
24class QwDBInterface;
25
26
27/*****************************************************************
28* Class:
29******************************************************************/
30///
31/// \ingroup QwAnalysis_BL
32/**
33 * \class QwIntegrationPMT
34 * \ingroup QwAnalysis_BL
35 * \brief Integration PMT providing yield/diff/asym readout from Moller ADC
36 */
38/////
39 public:
41 InitializeChannel("","raw");
42 };
43 QwIntegrationPMT(TString name){
44 InitializeChannel(name,"raw");
45 };
46 QwIntegrationPMT(TString subsystemname, TString name){
47 SetSubsystemName(subsystemname);
48 InitializeChannel(subsystemname, name,"raw");
49 };
58 ~QwIntegrationPMT() override { };
59
60 void LoadChannelParameters(QwParameterFile &paramfile) override{};
61
62 /**
63 * Decode the Moller ADC block for this PMT from an event buffer.
64 * @param buffer Event buffer pointer.
65 * @param word_position_in_buffer Current word index in buffer.
66 * @param subelement Block index within the PMT (default 0).
67 * @return 0 on success; negative on error.
68 */
69 Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override;
70
71 void InitializeChannel(TString name, TString datatosave);
72 // new routine added to update necessary information for tree trimming
73 void InitializeChannel(TString subsystem, TString name, TString datatosave);
74 // same purpose as above but this was needed to accormodate combinedPMT. Unlike Beamline combined devices where they have MollerADC channels, Combined PMT has integration PMT
75 void InitializeChannel(TString subsystem, TString module, TString name, TString datatosave);
76 void SetElementName(const TString &name) { fElementName = name; fTriumf_ADC.SetElementName(name);};
77
78 const QwMollerADC_Channel* GetChannel(const TString name) const {
79 if (fTriumf_ADC.GetElementName() == name) return &fTriumf_ADC;
80 else return 0;
81 };
82
83
84
85 void ClearEventData() override;
86 void PrintErrorCounters();
87/********************************************************/
88
89 void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency);
90 void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency);
91 void SetRandomEventParameters(Double_t mean, Double_t sigma);
92 void SetRandomEventAsymmetry(Double_t asymmetry);
93 void RandomizeEventData(int helicity = 0, double time = 0.0);
94 void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber = 0);
95 void SetEventData(Double_t* block, UInt_t sequencenumber);
96 void EncodeEventData(std::vector<UInt_t> &buffer);
97void RandomizeMollerEvent(int helicity, const QwBeamCharge& charge, const QwBeamPosition& xpos, const QwBeamPosition& ypos, const QwBeamAngle& xprime, const QwBeamAngle& yprime, const QwBeamEnergy& energy);
98
99
101 void SetExternalRandomVariable(Double_t random_variable);
102
103 Double_t GetValue();
104 Double_t GetValue(Int_t blocknum);
105
106 void ProcessEvent();
107 Bool_t ApplyHWChecks();//Check for hardware errors in the devices
108 Bool_t ApplySingleEventCuts();//Check for good events by setting limits on the devices readings
110 fTriumf_ADC.IncrementErrorCounters();
111 }
112 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure
113 Int_t SetSingleEventCuts(Double_t, Double_t);//set two limits
114 /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
115 void SetSingleEventCuts(UInt_t errorflag, Double_t LL, Double_t UL, Double_t stability, Double_t burplevel);
116 void SetDefaultSampleSize(Int_t sample_size);
117 void SetSaturationLimit(Double_t saturation_volt );
118 UInt_t GetEventcutErrorFlag() override{//return the error flag
119 return fTriumf_ADC.GetEventcutErrorFlag();
120 }
121
122 Bool_t CheckForBurpFail(const VQwDataElement *ev_error);
123
124 UInt_t UpdateErrorFlag() override {return GetEventcutErrorFlag();};
125 void UpdateErrorFlag(const QwIntegrationPMT *ev_error);
126
127 void SetEventCutMode(Int_t bcuts){
128 bEVENTCUTMODE=bcuts;
129 fTriumf_ADC.SetEventCutMode(bcuts);
130 }
131
132 void SetBlindability(Bool_t isblindable){fIsBlindable=isblindable;};
133 void SetNormalizability(Bool_t isnormalizable){fIsNormalizable = isnormalizable;};
134
135 /// \brief Blind the asymmetry
136 void Blind(const QwBlinder *blinder);
137 /// \brief Blind the difference using the yield
138 void Blind(const QwBlinder *blinder, const QwIntegrationPMT& yield);
139
140 void PrintValue() const override;
141 void PrintInfo() const override;
142
143/* Double_t GetRawBlockValue(size_t blocknum) */
144/* {return fTriumf_ADC.GetRawBlockValue(blocknum);}; */
145
146
147
151 void Sum(const QwIntegrationPMT &value1, const QwIntegrationPMT &value2);
152 void Difference(const QwIntegrationPMT &value1, const QwIntegrationPMT &value2);
153 void Ratio(QwIntegrationPMT &numer, QwIntegrationPMT &denom);
154 void Scale(Double_t factor);
155 void Normalize(VQwDataElement* denom);
156 void AccumulateRunningSum(const QwIntegrationPMT& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
157 void DeaccumulateRunningSum(QwIntegrationPMT& value, Int_t ErrorMask=0xFFFFFFF);
159
160 void SetPedestal(Double_t ped);
161 void SetCalibrationFactor(Double_t calib);
162
163 void SetNormRate(Double_t value) {fNormRate = value;};
164 void SetVoltPerHz(Double_t value) {fVoltPerHz = value;};
165
166 void SetAsymmetry(Double_t value) {fAsym = value;};
167 void SetCoefficientCx(Double_t value) {fCoeff_x = value;};
168 void SetCoefficientCy(Double_t value) {fCoeff_y = value;};
169 void SetCoefficientCxp(Double_t value){fCoeff_xp = value;};
170 void SetCoefficientCyp(Double_t value){fCoeff_yp = value;};
171 void SetCoefficientCe(Double_t value) {fCoeff_e = value;};
172
173 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
174 void FillHistograms() override;
175
176 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values);
177 void ConstructBranch(TTree *tree, TString &prefix);
178 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& trim_file);
179 void FillTreeVector(QwRootTreeBranchVector &values) const;
180
181#ifdef HAS_RNTUPLE_SUPPORT
182 // RNTuple methods
183 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs);
184 void FillNTupleVector(std::vector<Double_t>& values) const;
185#endif // HAS_RNTUPLE_SUPPORT
186
187 std::vector<QwDBInterface> GetDBEntry();
188 std::vector<QwErrDBInterface> GetErrDBEntry();
189
190 protected:
191
192
193 private:
194
195 Double_t fPedestal;
196 Double_t fCalibration;
197 Double_t fNormRate;
198 Double_t fVoltPerHz;
199 Double_t fAsym;
200 Double_t fCoeff_x;
201 Double_t fCoeff_y;
202 Double_t fCoeff_xp;
203 Double_t fCoeff_yp;
204 Double_t fCoeff_e;
205
206 Bool_t fGoodEvent;//used to validate sequence number in the IsGoodEvent()
207
209
210 Int_t fDeviceErrorCode;//keep the device HW status using a unique code from the QwMollerADC_Channel::fDeviceErrorCode
211
212 Bool_t fIsBlindable; //
214
215 const static Bool_t bDEBUG=kFALSE;//debugging display purposes
216 Bool_t bEVENTCUTMODE; //global switch to turn event cuts ON/OFF
217};
Parameter file parsing and management.
Decoding and management for Moller ADC channels (6x32-bit datawords)
class QwMollerADC_Channel QwBeamCharge
Definition QwTypes.h:321
class QwMollerADC_Channel QwBeamEnergy
Definition QwTypes.h:324
class QwMollerADC_Channel QwBeamAngle
Definition QwTypes.h:323
class QwMollerADC_Channel QwBeamPosition
Definition QwTypes.h:322
const TString QwBPMStripline< T >::subelement[4]
Concrete hardware channel for Moller ADC modules (6x32-bit words)
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.
VQwDataElement()
Default constructor.
void SetSubsystemName(TString sysname)
Set the name of the inheriting subsystem name.
TString fElementName
Name of this data element.
Data blinding utilities for parity violation analysis.
Definition QwBlinder.h:57
Integration PMT providing yield/diff/asym readout from Moller ADC.
QwIntegrationPMT(TString subsystemname, TString name)
QwIntegrationPMT & operator-=(const QwIntegrationPMT &value)
void SetAsymmetry(Double_t value)
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 ADC channel.
void FillHistograms() override
Fill the histograms for this data element.
void SetCalibrationFactor(Double_t calib)
Set the calibration factor and propagate to the underlying ADC channel.
void RandomizeMollerEvent(int helicity, const QwBeamCharge &charge, const QwBeamPosition &xpos, const QwBeamPosition &ypos, const QwBeamAngle &xprime, const QwBeamAngle &yprime, const QwBeamEnergy &energy)
Generate a mock MOLLER detector event using beam parameters.
void LoadChannelParameters(QwParameterFile &paramfile) override
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
Bool_t ApplyHWChecks()
Apply hardware checks and return whether the event is valid.
void PrintInfo() const override
Print multiple lines of information about this data element.
void RandomizeEventData(int helicity=0, double time=0.0)
Generate mock data for a single event.
const QwMollerADC_Channel * GetChannel(const TString name) const
void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber=0)
Set the hardware-level sum measurement for a sequence.
void SetCoefficientCx(Double_t value)
void SetCoefficientCy(Double_t value)
void SetSaturationLimit(Double_t saturation_volt)
Set the saturation voltage limit for the ADC front-end.
Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Check for burp failures by comparing against a reference PMT.
QwIntegrationPMT & operator=(const QwIntegrationPMT &value)
Copy-assign from another PMT (event-scoped data).
void Difference(const QwIntegrationPMT &value1, const QwIntegrationPMT &value2)
void PrintErrorCounters()
Print accumulated error counters for this PMT.
void DeaccumulateRunningSum(QwIntegrationPMT &value, Int_t ErrorMask=0xFFFFFFF)
void InitializeChannel(TString name, TString datatosave)
Initialize the PMT channel with a name and data-saving mode.
~QwIntegrationPMT() override
void UseExternalRandomVariable()
Use an external random variable source for mock data.
void Sum(const QwIntegrationPMT &value1, const QwIntegrationPMT &value2)
void FillTreeVector(QwRootTreeBranchVector &values) const
void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Add additional drift parameters to the existing drift model.
void SetBlindability(Bool_t isblindable)
void SetDefaultSampleSize(Int_t sample_size)
Set the default sample size used by the ADC channel.
void SetElementName(const TString &name)
void ConstructBranch(TTree *tree, TString &prefix)
UInt_t GetEventcutErrorFlag() override
return the error flag on this channel/device
void Scale(Double_t factor)
UInt_t UpdateErrorFlag() override
Update the error flag based on the error flags of internally contained objects Return parameter is th...
void SetExternalRandomVariable(Double_t random_variable)
Set the external random variable to drive mock data.
QwIntegrationPMT(TString name)
void SetRandomEventAsymmetry(Double_t asymmetry)
Set an asymmetry parameter applied to helicity states.
static const Bool_t bDEBUG
QwIntegrationPMT(const QwIntegrationPMT &source)
std::vector< QwErrDBInterface > GetErrDBEntry()
void AccumulateRunningSum(const QwIntegrationPMT &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
void SetEventData(Double_t *block, UInt_t sequencenumber)
Set the block data for the current event sequence.
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
QwIntegrationPMT & operator+=(const QwIntegrationPMT &value)
Add-assign from another PMT (sum raw channels).
void SetNormalizability(Bool_t isnormalizable)
Double_t GetValue()
Get the integrated value over the current event window.
void SetCoefficientCxp(Double_t value)
QwMollerADC_Channel fTriumf_ADC
void SetVoltPerHz(Double_t value)
void SetCoefficientCyp(Double_t value)
void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Configure deterministic drift parameters applied per event.
void EncodeEventData(std::vector< UInt_t > &buffer)
Encode current event data into an output buffer.
Bool_t ApplySingleEventCuts()
Apply single-event cuts for this PMT and return pass/fail.
void ClearEventData() override
Clear event-scoped data in the underlying ADC channel.
void SetPedestal(Double_t ped)
Set the pedestal value and propagate to the underlying ADC channel.
void SetEventCutMode(Int_t bcuts)
void SetCoefficientCe(Double_t value)
void Ratio(QwIntegrationPMT &numer, QwIntegrationPMT &denom)
void SetNormRate(Double_t value)
void ProcessEvent()
Apply hardware checks and process the event for this PMT.
void PrintValue() const override
Print single line of value and error of this data element.
std::vector< QwDBInterface > GetDBEntry()
void SetRandomEventParameters(Double_t mean, Double_t sigma)
Configure Gaussian mock data parameters.
void Blind(const QwBlinder *blinder)
Blind the asymmetry.
void Normalize(VQwDataElement *denom)
Int_t SetSingleEventCuts(Double_t, Double_t)
Set basic single-event cut limits.