QwAnalysis
QwHelicity.h
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwHelicity.h *
3 * *
4 * Author: *
5 * Time-stamp: *
6 \**********************************************************/
7 
8 #ifndef __QwHELICITY__
9 #define __QwHELICITY__
10 
11 // System headers
12 #include <vector>
13 
14 // ROOT headers
15 #include "TTree.h"
16 
17 // Qweak headers
18 #include "VQwSubsystemParity.h"
19 #include "QwWord.h"
20 
21 // Forward declarations
22 class QwParityDB;
23 
27 // this emun vector needs to be coherent with the DetectorTypes declaration in the QwBeamLine constructor
28 
29 
30 
31 /*****************************************************************
32 * Class:
33 ******************************************************************/
34 ///
35 /// \ingroup QwAnalysis_ADC
36 ///
37 /// \ingroup QwAnalysis_BL
38 class QwHelicity: public VQwSubsystemParity, public MQwSubsystemCloneable<QwHelicity> {
39 
40  private:
41  /// Private default constructor (not implemented, will throw linker error on use)
42  QwHelicity();
43 
44  public:
45  /// Constructor with name
46  QwHelicity(const TString& name);
47  /// Copy constructor
48  QwHelicity(const QwHelicity& source);
49  /// Virtual destructor
50  virtual ~QwHelicity() { }
51 
52 
53 
54  /* derived from VQwSubsystem */
55  /// \brief Define options function
56 
57  static void DefineOptions(QwOptions &options);
58  void ProcessOptions(QwOptions &options);
59  Int_t LoadChannelMap(TString mapfile);
60  Int_t LoadInputParameters(TString pedestalfile);
61  Int_t LoadEventCuts(TString filename);//Loads event cuts applicable to QwHelicity class, derived from VQwSubsystemParity
62  Bool_t ApplySingleEventCuts();//Apply event cuts in the QwHelicity class, derived from VQwSubsystemParity
64  void PrintErrorCounters() const;// report number of events failed due to HW and event cut failure, derived from VQwSubsystemParity
65  UInt_t GetEventcutErrorFlag();//return the error flag
66  //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
67  void UpdateErrorFlag(const VQwSubsystem *ev_error){
68  };
69 
70  Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id,
71  UInt_t* buffer, UInt_t num_words);
72  Int_t ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words) {
73  return ProcessEvBuffer(0x1,roc_id,bank_id,buffer,num_words);
74  };
75  Int_t ProcessEvBuffer(UInt_t ev_type, const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words);
76  void ProcessEventUserbitMode();//ProcessEvent has two modes Userbit and Inputregister modes
79 
80  void EncodeEventData(std::vector<UInt_t> &buffer);
81 
82 
83  virtual void ClearEventData();
84  virtual void ProcessEvent();
85 
86  UInt_t GetRandomSeedActual() { return iseed_Actual; };
87  UInt_t GetRandomSeedDelayed() { return iseed_Delayed; };
88 
89  void PredictHelicity();
90  void RunPredictor();
91  void SetHelicityDelay(Int_t delay);
92  void SetHelicityBitPattern(UInt_t bits);
93 
94  Int_t GetHelicityReported();
95  Int_t GetHelicityActual();
96  Int_t GetHelicityDelayed();
97  Long_t GetEventNumber();
98  Long_t GetPatternNumber();
99  Int_t GetPhaseNumber();
101  return fMaxPatternPhase;
102  };
104  return fMinPatternPhase;
105  }
106  void SetFirstBits(UInt_t nbits, UInt_t firstbits);
107  void SetEventPatternPhase(Int_t event, Int_t pattern, Int_t phase);
108 
111  void Sum(VQwSubsystem *value1, VQwSubsystem *value2);
112 
113  //the following functions do nothing really : adding and subtracting helicity doesn't mean anything
114  VQwSubsystem& operator-= (VQwSubsystem *value) {return *this;};
115  void Scale(Double_t factor) {return;};
116  void Difference(VQwSubsystem *value1, VQwSubsystem *value2);
117  void Ratio(VQwSubsystem *numer, VQwSubsystem *denom);
118  // end of "empty" functions
119 
121  //remove one entry from the running sums for devices
123  };
125 
127  void ConstructHistograms(TDirectory *folder, TString &prefix);
128  void FillHistograms();
129 
131  void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values);
132  void ConstructBranch(TTree *tree, TString &prefix);
133  void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& trim_file);
134  void FillTreeVector(std::vector<Double_t> &values) const;
135  void FillDB(QwParityDB *db, TString type);
136  void FillErrDB(QwParityDB *db, TString datatype);
137 
138  void Print() const;
139 
141 
142  virtual Bool_t IsGoodHelicity();
143 
144 /////
145  protected:
146  Bool_t CheckIORegisterMask(const UInt_t& ioregister, const UInt_t& mask) const {
147  return ((ioregister & mask) == mask);
148  };
149 
150  protected:
154 
159  // this values allow to switch the code between different helicity encoding mode.
160 
164 
165  static const UInt_t kInputReg_FakeMPS;
167 
168  static const UInt_t kDefaultHelicityBitPattern;
169 
171 
172  std::vector <QwWord> fWord;
173  std::vector < std::pair<Int_t, Int_t> > fWordsPerSubbank; // The indices of the first & last word in each subbank
174 
176  // this variable is set at initialization in function QwHelicity::LoadChannelMap
177  // it allows one to customize the helicity decoding mode
178  // the helicity decoding mode will take one of the value of enum HelicityEncodingType
179 
180 
181 
182  Int_t kUserbit;
183  // this is used to tagged the userbit info among all the fWords
184  // if we run the local helicity mode, the userbit contains the info
185  // about helicity, event number, pattern number etc.
187  // again this is used in the case we are running the local helicity mode
188  // the scalercounter counts how many events happened since the last reading
189  // should be one all the time if not the event is suspicious and not used for analysis
191 
193 
198  Int_t fActualPatternPolarity; ///< True polarity of the current pattern
199  Int_t fDelayedPatternPolarity; ///< Reported polarity of the current pattern
200  Int_t fPreviousPatternPolarity; ///< True polarity of the previous pattern.
202  // reported is what is registered in the coda file (it is the actual beam helicity fHelicityDelay pattern before this event)
203  // actual is the helicity of the beam for this event
204  // delayed is the expected reported helicity predicted by the random generator
205  // std::vector <Int_t> fCheckHelicityDelay;// this is obsolete
206  //this array keeps in memory the Actual helicity up to when it can be compared to the reported helicity
210  Bool_t fGoodPattern;
211 
212  Int_t fHistoType;
213  //allow one to select which types of histograms are created and filled
214  void SetHistoTreeSave(const TString &prefix);
215 
216 
217 
218  static const Bool_t kDEBUG=kFALSE;
219  // local helicity is a special mode for encoding helicity info
220  // it is not the fullblown helicity encoding we want to use for the main
221  // data taking. For example this was used during the injector data taking
222  // in winter 2008-09 injector tests
223  static const Int_t kUndefinedHelicity= -9999;
224 
225 
226  /* Ntuple array indices */
229  UInt_t n_ranbits; //counts how many ranbits we have collected
230  UInt_t iseed_Actual; //stores the random seed for the helicity predictor
232  //stores the random seed to predict the reported helicity
234  //number of events the helicity is delayed by before being reported
235  //static const Int_t MaxPatternPhase =4;
238  Bool_t IsGoodPatternNumber();
239  Bool_t IsGoodEventNumber();
240  Bool_t MatchActualHelicity(Int_t actual);
241  Bool_t IsGoodPhaseNumber();
242  Bool_t IsContinuous();
243 
244  virtual UInt_t GetRandbit(UInt_t& ranseed);
245  UInt_t GetRandbit24(UInt_t& ranseed);//for 24bit pattern
246  UInt_t GetRandbit30(UInt_t& ranseed);//for 30bit pattern
247  UInt_t GetRandomSeed(UShort_t* first24randbits);
248  virtual Bool_t CollectRandBits();
249  Bool_t CollectRandBits24();//for 24bit pattern
250  Bool_t CollectRandBits30();//for 30bit pattern
251 
252 
253  void ResetPredictor();
254 
255  Bool_t Compare(VQwSubsystem *source);
256 
257  Int_t fRandBits;//sets the random seed size 24bit/30bits
261 
263 
264  UInt_t fEventType;
265 
266 
269 
271  fNumMissedGates = 0;
273  fNumMultSyncErrors = 0;
274  fNumHelicityErrors = 0;
275  };
276 
277  // Error counters
278  Int_t fNumMissedGates; // Total number of missed events
279  Int_t fNumMissedEventBlocks; // Number of groups of missed events
280  Int_t fNumMultSyncErrors; // Number of errors reading the multiplet sync
281  Int_t fNumHelicityErrors; // Number of errors predicting the helicity
282 
283 
284  /// Flag to disable the printing os missed MPS error messags during
285  /// online running
287 
288  private:
289 
290  UInt_t BuildHelicityBitPattern(Int_t patternsize);
291 
292  unsigned int parity(unsigned int v) {
293  // http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel
294  v ^= v >> 16;
295  v ^= v >> 8;
296  v ^= v >> 4;
297  v &= 0xf;
298  return (0x6996 >> v) & 1;
299  }
300 
301 };
302 
303 
304 #endif
305 
306 
Int_t fHelicityDelay
Definition: QwHelicity.h:233
void ProcessEventInputRegisterMode()
Definition: QwHelicity.cc:518
Int_t fNumMissedGates
Definition: QwHelicity.h:275
Int_t GetPhaseNumber()
Definition: QwHelicity.cc:1084
Int_t fEventNumber
Definition: QwHelicity.h:194
Bool_t IsHelicityIgnored()
Definition: QwHelicity.h:140
UInt_t GetRandbit24(UInt_t &ranseed)
Definition: QwHelicity.cc:1484
Int_t kScalerCounter
Definition: QwHelicity.h:186
void PredictHelicity()
Definition: QwHelicity.cc:1849
size_t fTreeArrayNumEntries
Definition: QwHelicity.h:228
void SetFirstBits(UInt_t nbits, UInt_t firstbits)
Definition: QwHelicity.cc:1096
void Difference(VQwSubsystem *value1, VQwSubsystem *value2)
Definition: QwHelicity.cc:2000
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom)
Definition: QwHelicity.cc:2006
void FillErrDB(QwParityDB *db, TString datatype)
Definition: QwHelicity.cc:1467
Int_t kInputRegister
Definition: QwHelicity.h:190
UInt_t GetRandbit30(UInt_t &ranseed)
Definition: QwHelicity.cc:1541
Int_t ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
Definition: QwHelicity.h:72
virtual UInt_t GetRandbit(UInt_t &ranseed)
Definition: QwHelicity.cc:1473
void Sum(VQwSubsystem *value1, VQwSubsystem *value2)
Definition: QwHelicity.cc:1988
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
Definition: QwHelicity.cc:384
An options class.
Definition: QwOptions.h:133
std::vector< std::pair< Int_t, Int_t > > fWordsPerSubbank
Definition: QwHelicity.h:173
void ProcessOptions(QwOptions &options)
Process the command line options.
Definition: QwHelicity.cc:173
Bool_t IsGoodPhaseNumber()
Definition: QwHelicity.cc:283
void ProcessEventUserbitMode()
Definition: QwHelicity.cc:441
virtual Bool_t CollectRandBits()
Definition: QwHelicity.cc:1670
Int_t fHistoType
Definition: QwHelicity.h:212
Int_t fNumHelicityErrors
Definition: QwHelicity.h:281
Long_t GetPatternNumber()
Definition: QwHelicity.cc:1074
Bool_t fIgnoreHelicity
Definition: QwHelicity.h:262
virtual Bool_t IsGoodHelicity()
Definition: QwHelicity.cc:314
Virtual base class for the parity subsystems.
void Scale(Double_t factor)
Definition: QwHelicity.h:115
static const UInt_t kInputReg_FakeMPS
Default mask for fake MPS latch bit.
Definition: QwHelicity.h:165
void IncrementErrorCounters()
Increment the error counters.
Definition: QwHelicity.cc:403
void ClearErrorCounters()
Definition: QwHelicity.h:270
Int_t fPatternNumberOld
Definition: QwHelicity.h:196
Int_t fPatternSeed
Definition: QwHelicity.h:197
unsigned int parity(unsigned int v)
Definition: QwHelicity.h:292
UInt_t GetRandomSeedActual()
Definition: QwHelicity.h:86
UInt_t kEventTypeHelMinus
Definition: QwHelicity.h:192
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Definition: VQwSubsystem.h:209
Int_t GetMaxPatternPhase()
Definition: QwHelicity.h:100
void SetHelicityDelay(Int_t delay)
Definition: QwHelicity.cc:1881
static const Int_t kUndefinedHelicity
Definition: QwHelicity.h:223
size_t fTreeArrayIndex
Definition: QwHelicity.h:227
Long_t GetEventNumber()
Definition: QwHelicity.cc:1079
Int_t GetMinPatternPhase()
Definition: QwHelicity.h:103
UInt_t fHelicityBitPattern
Definition: QwHelicity.h:170
Int_t fEventNumberFirst
Definition: QwHelicity.h:267
void PrintErrorCounters() const
Report the number of events failed due to HW and event cut failures.
Definition: QwHelicity.cc:408
void FillDB(QwParityDB *db, TString type)
Fill the database.
Definition: QwHelicity.cc:1454
Int_t fHelicityReported
Definition: QwHelicity.h:201
Bool_t CollectRandBits30()
Definition: QwHelicity.cc:1773
Int_t fPatternPhaseOffset
Definition: QwHelicity.h:260
Bool_t IsGoodPatternNumber()
Definition: QwHelicity.cc:248
Int_t GetHelicityDelayed()
Definition: QwHelicity.cc:1069
VQwSubsystem & operator+=(VQwSubsystem *value)
Definition: QwHelicity.cc:1965
VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Definition: QwHelicity.cc:1927
Int_t GetHelicityReported()
Definition: QwHelicity.cc:1059
Int_t fDelayedPatternPolarity
Reported polarity of the current pattern.
Definition: QwHelicity.h:199
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
Definition: VQwSubsystem.h:88
Int_t fNumMultSyncErrors
Definition: QwHelicity.h:280
void EncodeEventData(std::vector< UInt_t > &buffer)
Definition: QwHelicity.cc:714
Int_t fMaxPatternPhase
Definition: QwHelicity.h:236
Int_t LoadEventCuts(TString filename)
Load the event cuts file.
Definition: QwHelicity.cc:1015
Bool_t Compare(VQwSubsystem *source)
Definition: QwHelicity.cc:2013
Int_t fRandBits
Definition: QwHelicity.h:257
UInt_t fInputReg_FakeMPS
Definition: QwHelicity.h:166
UInt_t n_ranbits
Definition: QwHelicity.h:229
Bool_t fHelicityInfoOK
Definition: QwHelicity.h:259
Bool_t fUsePredictor
Definition: QwHelicity.h:258
Bool_t fGoodPattern
Definition: QwHelicity.h:210
Int_t fMinPatternPhase
Definition: QwHelicity.h:237
Int_t fEventNumberOld
Definition: QwHelicity.h:194
Int_t LoadChannelMap(TString mapfile)
Mandatory map file definition.
Definition: QwHelicity.cc:804
Int_t fActualPatternPolarity
True polarity of the current pattern.
Definition: QwHelicity.h:198
Int_t kMpsCounter
Definition: QwHelicity.h:190
virtual void ClearEventData()
Definition: QwHelicity.cc:347
UInt_t GetEventcutErrorFlag()
Return the error flag to the top level routines related to stability checks and ErrorFlag updates...
Definition: QwHelicity.cc:435
void SetHelicityBitPattern(UInt_t bits)
Definition: QwHelicity.cc:1904
QwHelicity()
Private default constructor (not implemented, will throw linker error on use)
VQwSubsystem & operator-=(VQwSubsystem *value)
Definition: QwHelicity.h:114
void FillHistograms()
Fill the histograms for this subsystem.
Definition: QwHelicity.cc:1171
UInt_t BuildHelicityBitPattern(Int_t patternsize)
Definition: QwHelicity.cc:2028
Int_t fPreviousPatternPolarity
True polarity of the previous pattern.
Definition: QwHelicity.h:200
Int_t fNumMissedEventBlocks
Definition: QwHelicity.h:279
The pure virtual base class of all subsystems.
Definition: VQwSubsystem.h:59
Bool_t fSuppressMPSErrorMsgs
Definition: QwHelicity.h:286
Int_t fHelicityDelayed
Definition: QwHelicity.h:201
void SetEventPatternPhase(Int_t event, Int_t pattern, Int_t phase)
Definition: QwHelicity.cc:1089
void DeaccumulateRunningSum(VQwSubsystem *value)
remove one entry from the running sums for devices
Definition: QwHelicity.h:122
HelicityRootSavingType
Definition: QwHelicity.h:24
void ResetPredictor()
Definition: QwHelicity.cc:1914
Bool_t fHelicityBitMinus
Definition: QwHelicity.h:208
UInt_t GetRandomSeedDelayed()
Definition: QwHelicity.h:87
virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)=0
Construct the branch and tree vector.
Int_t LoadInputParameters(TString pedestalfile)
Mandatory parameter file definition.
Definition: QwHelicity.cc:391
Bool_t CheckIORegisterMask(const UInt_t &ioregister, const UInt_t &mask) const
Definition: QwHelicity.h:146
static const Bool_t kDEBUG
Definition: QwHelicity.h:218
void FillTreeVector(std::vector< Double_t > &values) const
Fill the tree vector.
Definition: QwHelicity.cc:1423
UInt_t GetRandomSeed(UShort_t *first24randbits)
Definition: QwHelicity.cc:1562
void UpdateErrorFlag(const VQwSubsystem *ev_error)
update the error flag in the subsystem level from the top level routines related to stability checks...
Definition: QwHelicity.h:67
Int_t kPatternCounter
Definition: QwHelicity.h:190
std::vector< QwWord > fWord
Definition: QwHelicity.h:172
void RunPredictor()
Definition: QwHelicity.cc:1608
UInt_t iseed_Delayed
Definition: QwHelicity.h:231
Bool_t fHelicityBitPlus
Definition: QwHelicity.h:207
Int_t fHelicityDecodingMode
Definition: QwHelicity.h:175
void ProcessEventInputMollerMode()
Definition: QwHelicity.cc:613
Int_t kUserbit
Definition: QwHelicity.h:182
Int_t fPatternPhaseNumber
Definition: QwHelicity.h:195
void SetHistoTreeSave(const TString &prefix)
Definition: QwHelicity.cc:1108
UInt_t iseed_Actual
Definition: QwHelicity.h:230
Int_t GetHelicityActual()
Definition: QwHelicity.cc:1064
Bool_t MatchActualHelicity(Int_t actual)
virtual void ProcessEvent()
Definition: QwHelicity.cc:658
Bool_t IsContinuous()
Definition: QwHelicity.cc:239
HelicityEncodingType
Definition: QwHelicity.h:155
void AccumulateRunningSum(VQwSubsystem *value)
Update the running sums for devices.
Definition: QwHelicity.h:120
Int_t fHelicityActual
Definition: QwHelicity.h:201
virtual ~QwHelicity()
Virtual destructor.
Definition: QwHelicity.h:50
static const UInt_t kDefaultHelicityBitPattern
Definition: QwHelicity.h:168
Bool_t CollectRandBits24()
Definition: QwHelicity.cc:1684
UInt_t fEventType
Definition: QwHelicity.h:264
Int_t fPatternNumber
Definition: QwHelicity.h:196
HelicityRootSavingType
Definition: QwHelicity.h:151
Bool_t ApplySingleEventCuts()
Apply the single event cuts.
Definition: QwHelicity.cc:397
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Construct the branch and tree vector.
Definition: QwHelicity.cc:1222
Int_t kPatternPhase
Definition: QwHelicity.h:190
Bool_t fGoodHelicity
Definition: QwHelicity.h:209
Bool_t IsGoodEventNumber()
Definition: QwHelicity.cc:267
Int_t fPatternPhaseNumberOld
Definition: QwHelicity.h:195
UInt_t kEventTypeHelPlus
Definition: QwHelicity.h:192
void CalculateRunningAverage()
Calculate the average for all good events.
Definition: QwHelicity.h:124
void Print() const
Definition: QwHelicity.cc:782
Int_t fPatternNumberFirst
Definition: QwHelicity.h:268
void ConstructBranch(TTree *tree, TString &prefix)
Construct the branch and tree vector.
Definition: QwHelicity.cc:1303