JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwEnergyCalculator.h
Go to the documentation of this file.
1/*!
2 * \file QwEnergyCalculator.h
3 * \brief Beam energy calculation from BPM position measurements
4 *
5 * \author B.Waidyawansa
6 * \date 05-24-2010
7 */
8
9#pragma once
10
11// System headers
12#include <vector>
13
14// Root headers
15#include <TTree.h>
16
17// RNTuple headers
18#ifdef HAS_RNTUPLE_SUPPORT
19#include "ROOT/RNTupleModel.hxx"
20#endif // HAS_RNTUPLE_SUPPORT
21
22// Qweak headers
23#include "QwVQWK_Channel.h"
24#include "QwBPMStripline.h"
25#include "QwCombinedBPM.h"
26#include "VQwBPM.h"
27#include "VQwHardwareChannel.h"
28#include "QwMollerADC_Channel.h"
29
30// Forward declarations
31#ifdef __USE_DATABASE__
32class QwDBInterface;
33#endif // __USE_DATABASE__
34
35/**
36 * \class QwEnergyCalculator
37 * \ingroup QwAnalysis_BL
38 * \brief Computes beam energy change from BPM information
39 *
40 * Uses measured angles and dispersive positions to estimate relative
41 * beam energy variations; exposes a single hardware-like channel.
42 */
44 /******************************************************************
45 * Class:QwEnergyCalculator
46 * Performs the beam energy calculation using the beam angle
47 * amnd position at the target and the beam position at the
48 * highest dispersive region on the beamline.
49 *
50 ******************************************************************/
51
52
53 public:
54 // Default constructor
56 QwEnergyCalculator(TString name){
57 InitializeChannel(name,"derived");
58 };
59 QwEnergyCalculator(TString subsystem, TString name){
60 InitializeChannel(subsystem, name,"derived");
61 };
65 ~QwEnergyCalculator() override { };
66
67 void InitializeChannel(TString name,TString datatosave);
68 // new routine added to update necessary information for tree trimming
69 void InitializeChannel(TString subsystem, TString name, TString datatosave);
70
71 void LoadChannelParameters(QwParameterFile &paramfile) override{};
72
73//------------------------------------------------------------------------------------
74 void SetRandomEventParameters(Double_t mean, Double_t sigma);
75 void RandomizeEventData(int helicity = 0, double time = 0.0);
76 void GetProjectedPosition(VQwBPM *device);
77 size_t GetNumberOfElements() {return fDevice.size();};
78 TString GetSubElementName(Int_t index) {return fDevice.at(index)->GetElementName();};
79 void LoadMockDataParameters(QwParameterFile &paramfile) override;
80//------------------------------------------------------------------------------------
81
82 void ClearEventData() override;
83 Int_t ProcessEvBuffer(UInt_t* buffer,
84 UInt_t word_position_in_buffer,UInt_t indexnumber) override;
85 void ProcessEvent();
86 void PrintValue() const override;
87 void PrintInfo() const override;
88 void SetRootSaveStatus(TString &prefix);
89
90 Bool_t ApplyHWChecks();//Check for hardware errors in the devices
91 Bool_t ApplySingleEventCuts();//Check for good events by setting limits on the devices readings
92 Int_t SetSingleEventCuts(Double_t mean, Double_t sigma);//two limits and sample size
93 /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
94 void SetSingleEventCuts(UInt_t errorflag,Double_t min, Double_t max, Double_t stability, Double_t burplevel);
95 void SetEventCutMode(Int_t bcuts){
96 bEVENTCUTMODE=bcuts;
97 fEnergyChange.SetEventCutMode(bcuts);
98 }
99 Bool_t CheckForBurpFail(const VQwDataElement *ev_error);
100
102 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure
103 UInt_t GetEventcutErrorFlag() override{//return the error flag
104 return fEnergyChange.GetEventcutErrorFlag();
105 }
106 UInt_t UpdateErrorFlag() override;
107
108 void UpdateErrorFlag(const QwEnergyCalculator *ev_error);
109
110
111 void Set(const VQwBPM* device,TString type, TString property ,Double_t tmatrix_ratio);
112 void Ratio(QwEnergyCalculator &numer,QwEnergyCalculator &denom);
113 void Scale(Double_t factor);
114
118 void Sum(const QwEnergyCalculator &value1, const QwEnergyCalculator &value2);
119 void Difference(const QwEnergyCalculator &value1, const QwEnergyCalculator &value2);
120
121 void AccumulateRunningSum(const QwEnergyCalculator& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
122 void DeaccumulateRunningSum(QwEnergyCalculator& value, Int_t ErrorMask=0xFFFFFFF);
124
125 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
126 void FillHistograms() override;
127
128 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values);
129 void ConstructBranch(TTree *tree, TString &prefix);
130 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& trim_file);
131 void FillTreeVector(QwRootTreeBranchVector &values) const;
132
133#ifdef HAS_RNTUPLE_SUPPORT
134 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs);
135 void FillNTupleVector(std::vector<Double_t>& values) const;
136#endif // HAS_RNTUPLE_SUPPORT
137
141
143 return const_cast<QwEnergyCalculator*>(this)->GetEnergy();
144 };
145
146#ifdef __USE_DATABASE__
147 std::vector<QwDBInterface> GetDBEntry();
148 std::vector<QwErrDBInterface> GetErrDBEntry();
149#endif // __USE_DATABASE__
150
151 protected:
153
154
155 private:
156 std::vector <const VQwBPM*> fDevice;
157 std::vector <Double_t> fTMatrixRatio;
158 std::vector <TString> fProperty;
159 std::vector <TString> fType;
160 Int_t fDeviceErrorCode;//keep the device HW status using a unique code from the QwVQWK_Channel::fDeviceErrorCode
161 Bool_t bEVENTCUTMODE;//If this set to kFALSE then Event cuts do not depend on HW checks. This is set externally through the qweak_beamline_eventcuts.map
162 Bool_t bFullSave; // used to restrict the amount of data histogramed
163
164
165
166};
Decoding and management for Moller ADC channels (6x32-bit datawords)
Decoding and management for VQWK ADC channels (6x32-bit datawords)
Combined beam position monitor using weighted average.
Stripline beam position monitor implementation.
Virtual base class for beam position monitors.
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.
Abstract base for concrete hardware channels implementing dual-operator pattern.
Computes beam energy change from BPM information.
void SetEventCutMode(Int_t bcuts)
QwEnergyCalculator(TString name)
void ClearEventData() override
Clear event-scoped data of this calculator and underlying channel.
void RandomizeEventData(int helicity=0, double time=0.0)
Generate mock event data for testing.
std::vector< const VQwBPM * > fDevice
void PrintInfo() const override
Print detailed information for this calculator.
void Difference(const QwEnergyCalculator &value1, const QwEnergyCalculator &value2)
QwEnergyCalculator & operator-=(const QwEnergyCalculator &value)
Subtract-assign from another calculator (difference energy change).
TString GetSubElementName(Int_t index)
void ConstructBranch(TTree *tree, TString &prefix)
Construct ROOT branches for this calculator (if enabled).
void CalculateRunningAverage()
Update running averages for the underlying energy channel.
std::vector< TString > fType
void PrintValue() const override
Print a compact value summary for this calculator.
void LoadChannelParameters(QwParameterFile &paramfile) override
void FillHistograms() override
Fill histograms for this calculator if enabled.
void Scale(Double_t factor)
Scale the underlying energy channel by a constant factor.
void SetRootSaveStatus(TString &prefix)
Determine whether to save full ROOT output based on the prefix.
QwEnergyCalculator & operator+=(const QwEnergyCalculator &value)
Add-assign from another calculator (sum energy change).
void FillTreeVector(QwRootTreeBranchVector &values) const
Int_t SetSingleEventCuts(Double_t mean, Double_t sigma)
Set single-event cut limits on the underlying energy channel.
QwEnergyCalculator(TString subsystem, TString name)
std::vector< Double_t > fTMatrixRatio
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
Construct ROOT branches and value vector entries.
void LoadMockDataParameters(QwParameterFile &paramfile) override
Load mock-data configuration for the underlying channel from a file.
void PrintErrorCounters() const override
Print accumulated error counters for diagnostic purposes.
void Set(const VQwBPM *device, TString type, TString property, Double_t tmatrix_ratio)
Register a BPM-based device contributing to the energy calculation.
UInt_t UpdateErrorFlag() override
Update and return the composite event-cut error flag.
void GetProjectedPosition(VQwBPM *device)
Back-project a BPM position from the current dp/p estimate.
void ProcessEvent()
Compute per-event energy change by summing configured device terms.
Bool_t ApplySingleEventCuts()
Apply single-event cuts to the energy channel and contributing devices.
void AccumulateRunningSum(const QwEnergyCalculator &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
Accumulate running sums from another calculator into this one.
QwMollerADC_Channel fEnergyChange
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t indexnumber) override
Process a configuration/event buffer (no-op for this calculator).
void SetRandomEventParameters(Double_t mean, Double_t sigma)
Configure Gaussian mock data parameters for the underlying channel.
std::vector< TString > fProperty
void DeaccumulateRunningSum(QwEnergyCalculator &value, Int_t ErrorMask=0xFFFFFFF)
Remove a single entry from the running sums using a source value.
void Ratio(QwEnergyCalculator &numer, QwEnergyCalculator &denom)
Define the ratio for asymmetry formation (here acts as pass-through).
Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Check for burp failures by delegating to the energy channel.
void InitializeChannel(TString name, TString datatosave)
Initialize this energy calculator with a name and data-saving mode.
UInt_t GetEventcutErrorFlag() override
return the error flag on this channel/device
VQwHardwareChannel * GetEnergy()
void Sum(const QwEnergyCalculator &value1, const QwEnergyCalculator &value2)
const VQwHardwareChannel * GetEnergy() const
QwEnergyCalculator & operator=(const QwEnergyCalculator &value)
Copy-assign from another calculator (event-scoped data).
QwEnergyCalculator(const QwEnergyCalculator &source)
Bool_t ApplyHWChecks()
Apply hardware checks (delegated to contributing channels if any).
void IncrementErrorCounters()
Increment error counters in the underlying energy channel.
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Define histograms for this calculator (delegated to energy channel).
Abstract base for beam position monitors (BPMs)
Definition VQwBPM.h:52