JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwHelicity.h
Go to the documentation of this file.
1/**********************************************************\
2* File: QwHelicity.h *
3* *
4* Author: *
5* Time-stamp: *
6\**********************************************************/
7
8/*!
9 * \file QwHelicity.h
10 * \brief Helicity state management and pattern recognition
11 */
12
13#pragma once
14
15// System headers
16#include <vector>
17
18// ROOT headers
19#include "TTree.h"
20#ifdef HAS_RNTUPLE_SUPPORT
21#include "ROOT/RNTupleModel.hxx"
22#include "ROOT/RNTupleWriter.hxx"
23#include "ROOT/RField.hxx"
24#endif // HAS_RNTUPLE_SUPPORT
25
26// Qweak headers
27#include "VQwSubsystemParity.h"
28#include "QwWord.h"
29
30// Forward declarations
31#ifdef __USE_DATABASE__
32class QwParityDB;
33#endif
34
38// this emun vector needs to be coherent with the DetectorTypes declaration in the QwBeamLine constructor
39
40
41
42/**
43 * \class QwHelicity
44 * \ingroup QwAnalysis_BeamLine
45 * \brief Subsystem for helicity state management and pattern recognition
46 *
47 * Manages helicity information from the polarized electron beam, including
48 * helicity state determination, pattern recognition, delayed helicity decoding,
49 * and helicity-correlated systematic checks. Supports multiple helicity
50 * encoding modes and provides helicity information to other subsystems.
51 */
52class QwHelicity: public VQwSubsystemParity, public MQwSubsystemCloneable<QwHelicity> {
53
54 private:
55 /// Private default constructor (not implemented, will throw linker error on use)
57
58 public:
59 /// Constructor with name
60 QwHelicity(const TString& name);
61 /// Copy constructor
62 QwHelicity(const QwHelicity& source);
63 /// Virtual destructor
64 ~QwHelicity() override { }
65
66
67
68 /* derived from VQwSubsystem */
69 /// \brief Define options function
70
71 static void DefineOptions(QwOptions &options);
72 void ProcessOptions(QwOptions &options) override;
73 Int_t LoadChannelMap(TString mapfile) override;
74 Int_t LoadInputParameters(TString pedestalfile) override;
75 Int_t LoadEventCuts(TString filename) override;//Loads event cuts applicable to QwHelicity class, derived from VQwSubsystemParity
76 Bool_t ApplySingleEventCuts() override;//Apply event cuts in the QwHelicity class, derived from VQwSubsystemParity
77
78 Bool_t CheckForBurpFail(const VQwSubsystem *ev_error) override{
79 return kFALSE;
80 };
81
82 void IncrementErrorCounters() override;
83 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure, derived from VQwSubsystemParity
84 UInt_t GetEventcutErrorFlag() override;//return the error flag
85 //update the error flag in the subsystem level from the top level routines related to stability checks. This will uniquely update the errorflag at each channel based on the error flag in the corresponding channel in the ev_error subsystem
86 void UpdateErrorFlag(const VQwSubsystem *ev_error) override{
87 };
88
89 Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id,
90 UInt_t* buffer, UInt_t num_words) override;
91 Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words) override {
92 return ProcessEvBuffer(0x1,roc_id,bank_id,buffer,num_words);
93 };
94 Int_t ProcessEvBuffer(UInt_t ev_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words) override;
95 void ProcessEventUserbitMode();//ProcessEvent has two modes Userbit and Inputregister modes
98
99 void EncodeEventData(std::vector<UInt_t> &buffer) override;
100
101
102 void ClearEventData() override;
103 void ProcessEvent() override;
104
105 UInt_t GetRandomSeedActual() { return iseed_Actual; };
107
108 void PredictHelicity();
109 void RunPredictor();
110 void SetHelicityDelay(Int_t delay);
111 void SetHelicityBitPattern(TString hex);
112
113 Int_t GetHelicityReported();
114 Int_t GetHelicityActual();
115 Int_t GetHelicityDelayed();
116 Long_t GetEventNumber();
117 Long_t GetPatternNumber();
118 Int_t GetPhaseNumber();
120 return fMaxPatternPhase;
121 };
123 return fMinPatternPhase;
124 }
125 void SetFirstBits(UInt_t nbits, UInt_t firstbits);
126 void SetEventPatternPhase(Int_t event, Int_t pattern, Int_t phase);
127
128 VQwSubsystem& operator= (VQwSubsystem *value) override;
129 VQwSubsystem& operator+= (VQwSubsystem *value) override;
130
131 //the following functions do nothing really : adding and subtracting helicity doesn't mean anything
132 VQwSubsystem& operator-= (VQwSubsystem *value) override {return *this;};
133 void Scale(Double_t factor) override {return;};
134 void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override;
135 // end of "empty" functions
136
137 void AccumulateRunningSum(VQwSubsystem* value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override;
138 //remove one entry from the running sums for devices
139 void DeaccumulateRunningSum(VQwSubsystem* value, Int_t ErrorMask=0xFFFFFFF) override{
140 };
141 void CalculateRunningAverage() override { };
142
144 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
145 void FillHistograms() override;
146
148 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
149 void ConstructBranch(TTree *tree, TString &prefix) override;
150 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& trim_file) override;
151 void FillTreeVector(QwRootTreeBranchVector &values) const override;
152
153#ifdef HAS_RNTUPLE_SUPPORT
154 using VQwSubsystem::ConstructNTupleAndVector;
155 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString &prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
156 void FillNTupleVector(std::vector<Double_t>& values) const override;
157#endif // HAS_RNTUPLE_SUPPORT
158
159#ifdef __USE_DATABASE__
160 void FillDB(QwParityDB *db, TString type);
161 void FillErrDB(QwParityDB *db, TString datatype);
162#endif // __USE_DATABASE__
163
164 void Print() const;
165
167
168 virtual Bool_t IsGoodHelicity();
169
170/////
171 protected:
172 void CheckPatternNum(VQwSubsystem *value);
173 void MergeCounters(VQwSubsystem *value);
174
175 Bool_t CheckIORegisterMask(const UInt_t& ioregister, const UInt_t& mask) const {
176 return ((mask != 0)&&((ioregister & mask) == mask));
177 };
178
179 protected:
183
188 // this values allow to switch the code between different helicity encoding mode.
189
194
200
201 static const std::vector<UInt_t> kDefaultHelicityBitPattern;
202
203 std::vector<UInt_t> fHelicityBitPattern;
204
205 std::vector <QwWord> fWord;
206 std::vector < std::pair<Int_t, Int_t> > fWordsPerSubbank; // The indices of the first & last word in each subbank
207
209 // this variable is set at initialization in function QwHelicity::LoadChannelMap
210 // it allows one to customize the helicity decoding mode
211 // the helicity decoding mode will take one of the value of enum HelicityEncodingType
212
213
214
215 Int_t kUserbit;
216 // this is used to tagged the userbit info among all the fWords
217 // if we run the local helicity mode, the userbit contains the info
218 // about helicity, event number, pattern number etc.
220 // again this is used in the case we are running the local helicity mode
221 // the scalercounter counts how many events happened since the last reading
222 // should be one all the time if not the event is suspicious and not used for analysis
224
226
231 Int_t fActualPatternPolarity; ///< True polarity of the current pattern
232 Int_t fDelayedPatternPolarity; ///< Reported polarity of the current pattern
233 Int_t fPreviousPatternPolarity; ///< True polarity of the previous pattern.
235 // reported is what is registered in the coda file (it is the actual beam helicity fHelicityDelay pattern before this event)
236 // actual is the helicity of the beam for this event
237 // delayed is the expected reported helicity predicted by the random generator
238 // std::vector <Int_t> fCheckHelicityDelay;// this is obsolete
239 //this array keeps in memory the Actual helicity up to when it can be compared to the reported helicity
244
246 //allow one to select which types of histograms are created and filled
247 void SetHistoTreeSave(const TString &prefix);
248
249
250
251 static const Bool_t kDEBUG=kFALSE;
252 // local helicity is a special mode for encoding helicity info
253 // it is not the fullblown helicity encoding we want to use for the main
254 // data taking. For example this was used during the injector data taking
255 // in winter 2008-09 injector tests
256 static const Int_t kUndefinedHelicity= -9999;
257
258
259 /* Ntuple array indices */
262 UInt_t n_ranbits; //counts how many ranbits we have collected
263 UInt_t iseed_Actual; //stores the random seed for the helicity predictor
265 //stores the random seed to predict the reported helicity
267 //number of events the helicity is delayed by before being reported
268 //static const Int_t MaxPatternPhase =4;
271 Bool_t IsGoodPatternNumber();
272 Bool_t IsGoodEventNumber();
273 Bool_t MatchActualHelicity(Int_t actual);
274 Bool_t IsGoodPhaseNumber();
275 Bool_t IsContinuous();
276
277 virtual UInt_t GetRandbit(UInt_t& ranseed);
278 UInt_t GetRandbit24(UInt_t& ranseed);//for 24bit pattern
279 UInt_t GetRandbit30(UInt_t& ranseed);//for 30bit pattern
280 UInt_t GetRandomSeed(UShort_t* first24randbits);
281 virtual Bool_t CollectRandBits();
282 Bool_t CollectRandBits24();//for 24bit pattern
283 Bool_t CollectRandBits30();//for 30bit pattern
284
285
286 void ResetPredictor();
287
288 Bool_t Compare(VQwSubsystem *source);
289
290 Int_t fRandBits;//sets the random seed size 24bit/30bits
294
296
298
299
302
309
310 // Error counters
311 Int_t fNumMissedGates; // Total number of missed events
312 Int_t fNumMissedEventBlocks; // Number of groups of missed events
313 Int_t fNumMultSyncErrors; // Number of errors reading the multiplet sync
314 Int_t fNumHelicityErrors; // Number of errors predicting the helicity
315
317
318 /// Flag to disable the printing os missed MPS error messages during
319 /// online running
321
322 private:
323
324 UInt_t BuildHelicityBitPattern(Int_t patternsize);
325
326 unsigned int parity(unsigned int v) {
327 // http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel
328 v ^= v >> 16;
329 v ^= v >> 8;
330 v ^= v >> 4;
331 v &= 0xf;
332 return (0x6996 >> v) & 1;
333 }
334
335};
Word-level data manipulation and bit operations.
ULong64_t BankID_t
Definition QwTypes.h:21
UInt_t ROCID_t
Definition QwTypes.h:20
HelicityRootSavingType
Definition QwHelicity.h:35
@ kHelSaveMPS
Definition QwHelicity.h:35
@ kHelSavePattern
Definition QwHelicity.h:36
@ kHelNoSave
Definition QwHelicity.h:37
Virtual base class for parity analysis subsystems.
Command-line and configuration file options processor.
Definition QwOptions.h:141
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
Base class for subsystems implementing container-delegation pattern.
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
VQwSubsystem(const TString &name)
Constructor with name.
virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)=0
Construct the branch and tree vector.
void ResetPredictor()
Int_t LoadEventCuts(TString filename) override
Optional event cut file.
~QwHelicity() override
Virtual destructor.
Definition QwHelicity.h:64
Int_t kUserbit
Definition QwHelicity.h:215
Bool_t Compare(VQwSubsystem *source)
Int_t fNumMissedEventBlocks
Definition QwHelicity.h:312
void ConstructBranch(TTree *tree, TString &prefix) override
Construct the branch and tree vector.
Bool_t CheckIORegisterMask(const UInt_t &ioregister, const UInt_t &mask) const
Definition QwHelicity.h:175
Int_t GetMinPatternPhase()
Definition QwHelicity.h:122
void SetHelicityBitPattern(TString hex)
Int_t fPatternNumberOld
Definition QwHelicity.h:229
void ProcessEventInputRegisterMode()
virtual Bool_t IsGoodHelicity()
void ProcessOptions(QwOptions &options) override
Process the command line options.
Int_t GetPhaseNumber()
unsigned int parity(unsigned int v)
Definition QwHelicity.h:326
Int_t kPatternCounter
Definition QwHelicity.h:223
void MergeCounters(VQwSubsystem *value)
Int_t fPatternNumber
Definition QwHelicity.h:229
Bool_t IsHelicityIgnored()
Definition QwHelicity.h:166
void SetFirstBits(UInt_t nbits, UInt_t firstbits)
UInt_t GetRandbit30(UInt_t &ranseed)
Int_t GetHelicityDelayed()
Int_t fPatternNumberFirst
Definition QwHelicity.h:301
Long_t GetPatternNumber()
Int_t kMpsCounter
Definition QwHelicity.h:223
Int_t fDelayedPatternPolarity
Reported polarity of the current pattern.
Definition QwHelicity.h:232
VQwSubsystem & operator-=(VQwSubsystem *value) override
Definition QwHelicity.h:132
void ClearEventData() override
Int_t fMaxPatternPhase
Definition QwHelicity.h:269
Bool_t CollectRandBits30()
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
Int_t fHelicityDelayed
Definition QwHelicity.h:234
Int_t fPatternPhaseOffset
Definition QwHelicity.h:293
UInt_t fInputReg_FakeMPS
Definition QwHelicity.h:195
Bool_t IsGoodPatternNumber()
UInt_t n_ranbits
Definition QwHelicity.h:262
Int_t fPatternPhaseNumberOld
Definition QwHelicity.h:228
Bool_t IsGoodPhaseNumber()
Int_t kScalerCounter
Definition QwHelicity.h:219
virtual UInt_t GetRandbit(UInt_t &ranseed)
Int_t fPatternPhaseNumber
Definition QwHelicity.h:228
std::vector< QwWord > fWord
Definition QwHelicity.h:205
Bool_t fHelicityInfoOK
Definition QwHelicity.h:292
UInt_t GetRandomSeedDelayed()
Definition QwHelicity.h:106
UInt_t kEventTypeHelMinus
Definition QwHelicity.h:225
void FillHistograms() override
Fill the histograms for this subsystem.
UInt_t fEventType
Definition QwHelicity.h:297
VQwSubsystem & operator+=(VQwSubsystem *value) override
void SetHelicityDelay(Int_t delay)
static const Int_t kUndefinedHelicity
Definition QwHelicity.h:256
Int_t fHelicityDelay
Definition QwHelicity.h:266
Int_t LoadInputParameters(TString pedestalfile) override
Mandatory parameter file definition.
void SetHistoTreeSave(const TString &prefix)
virtual Bool_t CollectRandBits()
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Int_t kPatternPhase
Definition QwHelicity.h:223
Int_t fRandBits
Definition QwHelicity.h:290
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Construct the branch and tree vector.
Bool_t fIgnoreHelicity
Definition QwHelicity.h:295
UInt_t fErrorFlag
Definition QwHelicity.h:316
UInt_t GetEventcutErrorFlag() override
Return the error flag to the top level routines related to stability checks and ErrorFlag updates.
UInt_t iseed_Actual
Definition QwHelicity.h:263
UInt_t iseed_Delayed
Definition QwHelicity.h:264
void RunPredictor()
Bool_t fGoodHelicity
Definition QwHelicity.h:242
Int_t LoadChannelMap(TString mapfile) override
Mandatory map file definition.
void PrintErrorCounters() const override
Bool_t IsGoodEventNumber()
Long_t GetEventNumber()
Int_t fPreviousPatternPolarity
True polarity of the previous pattern.
Definition QwHelicity.h:233
void DeaccumulateRunningSum(VQwSubsystem *value, Int_t ErrorMask=0xFFFFFFF) override
remove one entry from the running sums for devices
Definition QwHelicity.h:139
Int_t fHelicityDecodingMode
Definition QwHelicity.h:208
QwHelicity()
Private default constructor (not implemented, will throw linker error on use)
UInt_t fInputReg_HelMinus
Definition QwHelicity.h:197
Int_t fHistoType
Definition QwHelicity.h:245
Int_t fPatternSeed
Definition QwHelicity.h:230
Bool_t fUsePredictor
Definition QwHelicity.h:291
UInt_t BuildHelicityBitPattern(Int_t patternsize)
@ kDefaultInputReg_FakeMPS
Definition QwHelicity.h:193
@ kDefaultInputReg_PatternSync
Definition QwHelicity.h:192
@ kDefaultInputReg_HelPlus
Definition QwHelicity.h:190
@ kDefaultInputReg_HelMinus
Definition QwHelicity.h:191
void CheckPatternNum(VQwSubsystem *value)
@ kHelInputMollerMode
Definition QwHelicity.h:187
@ kHelInputRegisterMode
Definition QwHelicity.h:185
Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
Definition QwHelicity.h:91
void SetEventPatternPhase(Int_t event, Int_t pattern, Int_t phase)
Bool_t fHelicityBitPlus
Definition QwHelicity.h:240
Int_t kInputRegister
Definition QwHelicity.h:223
UInt_t fInputReg_HelPlus
Definition QwHelicity.h:196
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill the tree vector.
void ProcessEventUserbitMode()
Process helicity information from userbit configuration data.
UInt_t GetRandomSeedActual()
Definition QwHelicity.h:105
void Scale(Double_t factor) override
Definition QwHelicity.h:133
VQwSubsystem & operator=(VQwSubsystem *value) override
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override
static const std::vector< UInt_t > kDefaultHelicityBitPattern
Definition QwHelicity.h:43
UInt_t fInputReg_PairSync
Definition QwHelicity.h:199
UInt_t kEventTypeHelPlus
Definition QwHelicity.h:225
void ClearErrorCounters()
Definition QwHelicity.h:303
Bool_t fHelicityBitMinus
Definition QwHelicity.h:241
void Print() const
static const Bool_t kDEBUG
Definition QwHelicity.h:251
Int_t GetHelicityActual()
Int_t fHelicityReported
Definition QwHelicity.h:234
Bool_t fSuppressMPSErrorMsgs
Definition QwHelicity.h:320
std::vector< UInt_t > fHelicityBitPattern
Definition QwHelicity.h:203
UInt_t fInputReg_PatternSync
Definition QwHelicity.h:198
Bool_t ApplySingleEventCuts() override
Apply the single event cuts.
Int_t fEventNumberOld
Definition QwHelicity.h:227
Int_t fHelicityActual
Definition QwHelicity.h:234
Bool_t MatchActualHelicity(Int_t actual)
Int_t fNumMultSyncErrors
Definition QwHelicity.h:313
void ProcessEventInputMollerMode()
size_t fTreeArrayNumEntries
Definition QwHelicity.h:261
size_t fTreeArrayIndex
Definition QwHelicity.h:260
Int_t fNumHelicityErrors
Definition QwHelicity.h:314
void ProcessEvent() override
Int_t fNumMissedGates
Definition QwHelicity.h:311
UInt_t GetRandbit24(UInt_t &ranseed)
void UpdateErrorFlag(const VQwSubsystem *ev_error) override
update the error flag in the subsystem level from the top level routines related to stability checks....
Definition QwHelicity.h:86
void CalculateRunningAverage() override
Calculate the average for all good events.
Definition QwHelicity.h:141
Int_t GetMaxPatternPhase()
Definition QwHelicity.h:119
Int_t fEventNumberFirst
Definition QwHelicity.h:300
void AccumulateRunningSum(VQwSubsystem *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Update the running sums for devices.
Bool_t IsContinuous()
std::vector< std::pair< Int_t, Int_t > > fWordsPerSubbank
Definition QwHelicity.h:206
Bool_t CollectRandBits24()
Bool_t CheckForBurpFail(const VQwSubsystem *ev_error) override
Report the number of events failed due to HW and event cut failures.
Definition QwHelicity.h:78
void IncrementErrorCounters() override
Increment the error counters.
Int_t GetHelicityReported()
UInt_t GetRandomSeed(UShort_t *first24randbits)
void EncodeEventData(std::vector< UInt_t > &buffer) override
Int_t fActualPatternPolarity
True polarity of the current pattern.
Definition QwHelicity.h:231
Bool_t fGoodPattern
Definition QwHelicity.h:243
Int_t fEventNumber
Definition QwHelicity.h:227
void PredictHelicity()
Int_t fMinPatternPhase
Definition QwHelicity.h:270
VQwSubsystemParity()
Private default constructor (not implemented, will throw linker error on use)
virtual void FillDB(QwParityDB *, TString)
Fill the database.
virtual void FillErrDB(QwParityDB *, TString)