JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwHaloMonitor.h
Go to the documentation of this file.
1/*!
2 * \file QwHaloMonitor.h
3 * \brief Halo monitor using scaler channels for beam monitoring
4 * \author B. Waidyawansa
5 * \date 2010-06-24
6 */
7
8#pragma once
9
10// System headers
11#include <vector>
12
13// ROOT headers
14#include <TTree.h>
15
16// RNTuple headers
17#ifdef HAS_RNTUPLE_SUPPORT
18#include "ROOT/RNTupleModel.hxx"
19#endif // HAS_RNTUPLE_SUPPORT
20
21// Qweak headers
22#include "QwParameterFile.h"
23#include "QwScaler_Channel.h"
24#include "VQwHardwareChannel.h"
25
26// Forward declarations
27#ifdef __USE_DATABASE__
28class QwDBInterface;
29#endif // __USE_DATABASE__
30
31/*****************************************************************
32* Class: QwHaloMonitor handles the halo counters. This use
33 QwSIS3801_Channel scaler channels.
34******************************************************************/
35/**
36 * \class QwHaloMonitor
37 * \ingroup QwAnalysis_BL
38 * \brief Wrapper around a scaler channel to monitor beam halo rates
39 */
41/////
42
43 public:
45 QwHaloMonitor(TString name){
47 };
48 QwHaloMonitor(TString subsystemname, TString name){
49 InitializeChannel(subsystemname, name);
50 };
52 : VQwDataElement(source),
54 { }
55 ~QwHaloMonitor() override { };
56
57 void InitializeChannel(TString name);
58 // new routine added to update necessary information for tree trimming
59 void InitializeChannel(TString subsystem, TString name);
60 void ClearEventData() override;
61
62 void LoadChannelParameters(QwParameterFile &paramfile) override{
63 fHalo_Counter.LoadChannelParameters(paramfile);
64 }
65 std::string GetExternalClockName() override { return fHalo_Counter.GetExternalClockName(); };
66 Bool_t NeedsExternalClock() override { return fHalo_Counter.NeedsExternalClock(); };
67 void SetExternalClockPtr( const VQwHardwareChannel* clock) override {fHalo_Counter.SetExternalClockPtr(clock);};
68 void SetExternalClockName( const std::string name) override { fHalo_Counter.SetExternalClockName(name);};
69 Double_t GetNormClockValue() override { return fHalo_Counter.GetNormClockValue();}
70
71
72
73 void PrintErrorCounters();//This will display the error summary for each device
74 void UpdateHWErrorCount();//Update error counter for HW failure
75
76 Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t num_words_left,UInt_t index=0) override;
77 void ProcessEvent();
78
82 void Sum(QwHaloMonitor &value1, QwHaloMonitor &value2);
83 void Difference(QwHaloMonitor &value1, QwHaloMonitor &value2);
84 void Ratio(QwHaloMonitor &numer, QwHaloMonitor &denom);
85 void Offset(Double_t Offset);
86 void Scale(Double_t Offset);
87
88 void SetPedestal(Double_t ped) { fHalo_Counter.SetPedestal(ped); };
89 void SetCalibrationFactor(Double_t factor) { fHalo_Counter.SetCalibrationFactor(factor); };
90 void AccumulateRunningSum(const QwHaloMonitor& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
91 void DeaccumulateRunningSum(QwHaloMonitor& value, Int_t ErrorMask=0xFFFFFFF);
93
94 Bool_t ApplySingleEventCuts();//check values read from modules are at desired level
95 void IncrementErrorCounters(){fHalo_Counter.IncrementErrorCounters();};
96 UInt_t GetEventcutErrorFlag() override{return fHalo_Counter.GetEventcutErrorFlag();};
97
98 Bool_t CheckForBurpFail(const VQwDataElement *ev_error);
99
100 UInt_t UpdateErrorFlag() override {return GetEventcutErrorFlag();};
101 void UpdateErrorFlag(const QwHaloMonitor *ev_error){
102 fHalo_Counter.UpdateErrorFlag(ev_error->fHalo_Counter);
103 };
104
105 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure
106 Bool_t ApplyHWChecks();
107 void SetSingleEventCuts(UInt_t errorflag,Double_t min, Double_t max, Double_t stability, Double_t burplevel){
108 QwError<<"***************************"<<QwLog::endl;
109 fHalo_Counter.SetSingleEventCuts(errorflag,min,max,stability,burplevel);
110 };
111 void SetEventCutMode(Int_t bcuts){
112 fHalo_Counter.SetEventCutMode(bcuts);
113 }
114
115
116 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
117 void FillHistograms() override;
118
119 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values);
120 void ConstructBranch(TTree *tree, TString &prefix);
121 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist);
122 void FillTreeVector(QwRootTreeBranchVector &values) const;
123
124#ifdef HAS_RNTUPLE_SUPPORT
125 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs);
126 void FillNTupleVector(std::vector<Double_t>& values) const;
127#endif // HAS_RNTUPLE_SUPPORT
128
132
134 return const_cast<QwHaloMonitor*>(this)->GetScaler();
135 };
136
137 Double_t GetValue() {
138 return fHalo_Counter.GetValue();
139 }
140
141 void PrintValue() const override;
142 void PrintInfo() const override;
143
144#ifdef __USE_DATABASE__
145 std::vector<QwDBInterface> GetDBEntry();
146 std::vector<QwErrDBInterface> GetErrDBEntry();
147#endif // __USE_DATABASE__
148
149 protected:
150
151 private:
152 static const Bool_t kDEBUG;
153
155
156 Int_t fDeviceErrorCode;//keep the device HW status using a unique code from the QwVQWK_Channel::fDeviceErrorCode
157 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
158
159};
Base and derived classes for scaler channel data handling.
class QwScaler_Channel< 0x00ffffff, 0 > QwSIS3801D24_Channel
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
Parameter file parsing and management.
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
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.
Wrapper around a scaler channel to monitor beam halo rates.
void ProcessEvent()
Process event (delegated to the underlying counter).
void UpdateHWErrorCount()
void ConstructBranch(TTree *tree, TString &prefix)
void PrintValue() const override
Print a compact value summary for this monitor.
void SetSingleEventCuts(UInt_t errorflag, Double_t min, Double_t max, Double_t stability, Double_t burplevel)
QwHaloMonitor & operator=(const QwHaloMonitor &value)
Copy-assign from another halo monitor.
static const Bool_t kDEBUG
QwSIS3801D24_Channel fHalo_Counter
Bool_t NeedsExternalClock() override
void ClearEventData() override
Clear event-scoped data in the underlying counter.
void SetExternalClockName(const std::string name) override
void SetExternalClockPtr(const VQwHardwareChannel *clock) override
QwHaloMonitor(TString name)
Double_t GetNormClockValue() override
void SetPedestal(Double_t ped)
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Define histograms for this monitor (delegated to underlying counter).
void LoadChannelParameters(QwParameterFile &paramfile) override
const VQwHardwareChannel * GetScaler() const
UInt_t UpdateErrorFlag() override
Update the error flag based on the error flags of internally contained objects Return parameter is th...
QwHaloMonitor(TString subsystemname, TString name)
std::string GetExternalClockName() override
void PrintErrorCounters()
void Sum(QwHaloMonitor &value1, QwHaloMonitor &value2)
Sum two halo monitors into this instance.
void InitializeChannel(TString name)
Initialize the halo monitor with a detector name.
void AccumulateRunningSum(const QwHaloMonitor &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
Accumulate running sums from another monitor into this one.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
Construct ROOT branches and value vector entries.
QwHaloMonitor(const QwHaloMonitor &source)
void Difference(QwHaloMonitor &value1, QwHaloMonitor &value2)
Compute the difference of two halo monitors into this instance.
QwHaloMonitor & operator-=(const QwHaloMonitor &value)
Subtract-assign from another halo monitor (difference counters).
void FillHistograms() override
Fill histograms for this monitor if enabled.
Bool_t ApplyHWChecks()
Apply hardware checks (no hardware errors for simple counters).
QwHaloMonitor & operator+=(const QwHaloMonitor &value)
Add-assign from another halo monitor (sum counters).
Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Check for burp failures by delegating to the underlying counter.
void FillTreeVector(QwRootTreeBranchVector &values) const
void Ratio(QwHaloMonitor &numer, QwHaloMonitor &denom)
Form the ratio of two halo monitors into this instance.
void SetEventCutMode(Int_t bcuts)
void DeaccumulateRunningSum(QwHaloMonitor &value, Int_t ErrorMask=0xFFFFFFF)
Remove a single entry from the running sums using a source value.
~QwHaloMonitor() override
void CalculateRunningAverage()
Update running averages for the underlying counter.
void SetCalibrationFactor(Double_t factor)
void IncrementErrorCounters()
void Scale(Double_t Offset)
Scale the underlying counter by a constant factor.
void UpdateErrorFlag(const QwHaloMonitor *ev_error)
UInt_t GetEventcutErrorFlag() override
return the error flag on this channel/device
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t index=0) override
Decode the raw event buffer into the underlying counter.
Double_t GetValue()
void Offset(Double_t Offset)
VQwHardwareChannel * GetScaler()
void PrintInfo() const override
Print detailed information for this monitor.
Bool_t ApplySingleEventCuts()
Apply single-event cuts on the underlying counter.