QwAnalysis
QwBCM.h
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwBCM.h *
3 * *
4 * Author: *
5 * Time-stamp: *
6 \**********************************************************/
7 
8 #ifndef __QWBCM__
9 #define __QWBCM__
10 
11 // System headers
12 #include <vector>
13 
14 // ROOT headers
15 #include <TTree.h>
16 
17 #include "QwParameterFile.h"
18 #include "VQwDataElement.h"
19 #include "VQwHardwareChannel.h"
20 #include "VQwBCM.h"
21 
22 // Forward declarations
23 class QwDBInterface;
24 class QwErrDBInterface;
25 
26 template<typename T> class QwCombinedBCM;
27 
28 /*****************************************************************
29 * Class:
30 ******************************************************************/
31 ///
32 /// \ingroup QwAnalysis_BL
33 template<typename T>
34 class QwBCM : public VQwBCM {
35 /////
36  friend class QwCombinedBCM<T>;
37  public:
39  QwBCM(TString name): VQwBCM(fBeamCurrent,name) {
40  InitializeChannel(name,"raw");
41  };
42  QwBCM(TString subsystemname, TString name)
43  : VQwBCM(fBeamCurrent,name) {
44  SetSubsystemName(subsystemname);
45  InitializeChannel(subsystemname,name,"raw");
46  };
47  QwBCM(TString subsystemname, TString name, TString type, TString clock = "")
48  : VQwBCM(fBeamCurrent,name) {
49  fBeamCurrent.SetExternalClockName(clock.Data());
50  SetSubsystemName(subsystemname);
51  InitializeChannel(subsystemname,name,type,"raw");
52  };
53  QwBCM(const QwBCM& source)
54  : VQwBCM(source),
56  { }
57  virtual ~QwBCM() { };
58 
59  Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement=0);
60 
61  void InitializeChannel(TString name, TString datatosave);
62  // new routine added to update necessary information for tree trimming
63  void InitializeChannel(TString subsystem, TString name, TString datatosave);
64  void InitializeChannel(TString subsystem, TString name, TString type,
65  TString datatosave);
66  void ClearEventData();
67 
69  fBeamCurrent.LoadChannelParameters(paramfile);
70  };
71 
72  void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency);
73  void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency);
74  void SetRandomEventParameters(Double_t mean, Double_t sigma);
75  void SetRandomEventAsymmetry(Double_t asymmetry);
76  void RandomizeEventData(int helicity = 0, double time = 0);
77  void EncodeEventData(std::vector<UInt_t> &buffer);
78 
80  void SetExternalRandomVariable(Double_t random_variable);
81 
82  void ProcessEvent();
83  Bool_t ApplyHWChecks();//Check for harware errors in the devices
84  Bool_t ApplySingleEventCuts();//Check for good events by stting limits on the devices readings
86  void PrintErrorCounters() const;// report number of events failed due to HW and event cut faliure
87  UInt_t GetEventcutErrorFlag(){//return the error flag
88  return fBeamCurrent.GetEventcutErrorFlag();
89  }
90 
91  void UpdateErrorFlag(const VQwBCM *ev_error);
92 
93  UInt_t GetErrorCode() const {return (fBeamCurrent.GetErrorCode());};
94 
95 
96  Int_t SetSingleEventCuts(Double_t mean = 0, Double_t sigma = 0);//two limts and sample size
97  /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
98  void SetSingleEventCuts(UInt_t errorflag, Double_t min = 0, Double_t max = 0, Double_t stability = 0);
99 
100  void SetDefaultSampleSize(Int_t sample_size);
101  void SetEventCutMode(Int_t bcuts) {
102  fBeamCurrent.SetEventCutMode(bcuts);
103  }
104 
105  void PrintValue() const;
106  void PrintInfo() const;
107 
108  const VQwHardwareChannel* GetCharge() const {
109  return &fBeamCurrent;
110  };
111 
112 
113  // These are for the clocks
114  std::string GetExternalClockName() { return fBeamCurrent.GetExternalClockName(); };
115  Bool_t NeedsExternalClock() { return fBeamCurrent.NeedsExternalClock(); };
116  void SetExternalClockPtr( const VQwHardwareChannel* clock) {fBeamCurrent.SetExternalClockPtr(clock);};
117  void SetExternalClockName( const std::string name) { fBeamCurrent.SetExternalClockName(name);};
118  Double_t GetNormClockValue() { return fBeamCurrent.GetNormClockValue();}
119 
120  // Implementation of Parent class's virtual operators
121  VQwBCM& operator= (const VQwBCM &value);
122  VQwBCM& operator+= (const VQwBCM &value);
123  VQwBCM& operator-= (const VQwBCM &value);
124 
125  // This is used only by a QwComboBCM. It is placed here since in QwBeamLine we do
126  // not readily have the appropriate template every time we want to use this
127  // function.
128  virtual void SetBCMForCombo(VQwBCM* bcm, Double_t weight, Double_t sumqw ) {
129  std::cerr<<"SetBCMForCombo for QwCombinedBCM<T> not defined!!\n";
130  };
131 
132  // This class specific operators
133  QwBCM& operator= (const QwBCM &value);
134  QwBCM& operator+= (const QwBCM &value);
135  QwBCM& operator-= (const QwBCM &value);
136  void Sum(QwBCM &value1, QwBCM &value2);
137  void Difference(QwBCM &value1, QwBCM &value2);
138  void Ratio(const VQwBCM &numer, const VQwBCM &denom);
139  void Ratio(const QwBCM &numer, const QwBCM &denom);
140  void Scale(Double_t factor);
141 
142  void AccumulateRunningSum(const VQwBCM& value);
143  void DeaccumulateRunningSum(VQwBCM& value);
145 
146  void SetPedestal(Double_t ped);
147  void SetCalibrationFactor(Double_t calib);
148 
149  void ConstructHistograms(TDirectory *folder, TString &prefix);
150  void FillHistograms();
151 
152  void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values);
153  void ConstructBranch(TTree *tree, TString &prefix);
154  void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist);
155  void FillTreeVector(std::vector<Double_t> &values) const;
156 
157  std::vector<QwDBInterface> GetDBEntry();
158  std::vector<QwErrDBInterface> GetErrDBEntry();
159 
160  Double_t GetValue();
161  Double_t GetValueError();
162  Double_t GetValueWidth();
163 
164 
165 /////
166  protected:
167 
169 
170 /////
171  private:
172 
173 };
174 
175 
176 #endif // __QWBCM__
void FillHistograms()
Fill the histograms for this data element.
Definition: QwBCM.cc:410
VQwBCM & operator+=(const VQwBCM &value)
Definition: QwBCM.cc:271
Double_t GetValue()
Definition: QwBCM.cc:498
VQwBCM & operator-=(const VQwBCM &value)
Definition: QwBCM.cc:295
Double_t GetValueError()
Definition: QwBCM.cc:505
void SetDefaultSampleSize(Int_t sample_size)
Definition: QwBCM.cc:151
virtual UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
Definition: VQwBCM.h:70
Definition: VQwBCM.h:32
void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Definition: QwBCM.cc:87
std::vector< QwErrDBInterface > GetErrDBEntry()
Definition: QwBCM.cc:489
void EncodeEventData(std::vector< UInt_t > &buffer)
Definition: QwBCM.cc:111
VQwBCM & operator=(const VQwBCM &value)
Definition: QwBCM.cc:233
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
Definition: QwBCM.cc:397
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Definition: QwBCM.cc:423
void PrintValue() const
Print single line of value and error of this data element.
Definition: QwBCM.cc:383
void Difference(QwBCM &value1, QwBCM &value2)
Definition: QwBCM.cc:337
void AccumulateRunningSum(const VQwBCM &value)
Definition: QwBCM.cc:373
Bool_t NeedsExternalClock()
Definition: QwBCM.h:115
Bool_t ApplyHWChecks()
Definition: QwBCM.cc:124
std::vector< QwDBInterface > GetDBEntry()
Definition: QwBCM.cc:479
void SetPedestal(Double_t ped)
Definition: QwBCM.cc:22
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0)
Process the CODA event buffer for this element.
Definition: QwBCM.cc:209
void SetEventCutMode(Int_t bcuts)
Definition: QwBCM.h:101
Definition of the pure virtual base class of all data elements.
QwBCM(TString subsystemname, TString name)
Definition: QwBCM.h:42
void ClearEventData()
Clear the event data in this element.
Definition: QwBCM.cc:62
void SetRandomEventParameters(Double_t mean, Double_t sigma)
Definition: QwBCM.cc:93
void SetSubsystemName(TString sysname)
Set the name of the inheriting subsystem name.
Int_t SetSingleEventCuts(Double_t mean=0, Double_t sigma=0)
Definition: QwBCM.cc:136
void FillTreeVector(std::vector< Double_t > &values) const
Definition: QwBCM.cc:467
void Sum(QwBCM &value1, QwBCM &value2)
Definition: QwBCM.cc:331
virtual void SetBCMForCombo(VQwBCM *bcm, Double_t weight, Double_t sumqw)
Definition: QwBCM.h:128
void PrintInfo() const
Print multiple lines of information about this data element.
Definition: QwBCM.cc:389
QwBCM()
Definition: QwBCM.h:38
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
Bool_t ApplySingleEventCuts()
Definition: QwBCM.cc:158
void IncrementErrorCounters()
Definition: QwBCM.cc:174
virtual ~QwBCM()
Definition: QwBCM.h:57
void SetExternalClockName(const std::string name)
Definition: QwBCM.h:117
void ConstructBranch(TTree *tree, TString &prefix)
Definition: QwBCM.cc:434
static const double min
Definition: QwUnits.h:76
void Ratio(const VQwBCM &numer, const VQwBCM &denom)
Definition: QwBCM.cc:343
QwBCM(TString name)
Definition: QwBCM.h:39
void RandomizeEventData(int helicity=0, double time=0)
Definition: QwBCM.cc:105
const VQwHardwareChannel * GetCharge() const
Definition: QwBCM.h:108
void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Definition: QwBCM.cc:81
void SetExternalRandomVariable(Double_t random_variable)
Definition: QwBCM.cc:75
void Scale(Double_t factor)
Definition: QwBCM.cc:361
void SetRandomEventAsymmetry(Double_t asymmetry)
Definition: QwBCM.cc:99
void ProcessEvent()
Definition: QwBCM.cc:117
void InitializeChannel(TString name, TString datatosave)
Definition: QwBCM.cc:34
void SetExternalClockPtr(const VQwHardwareChannel *clock)
Definition: QwBCM.h:116
Definition: QwBCM.h:34
void DeaccumulateRunningSum(VQwBCM &value)
Definition: QwBCM.cc:379
UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
Definition: QwBCM.h:87
UInt_t GetErrorCode() const
Definition: QwBCM.h:93
QwBCM(const QwBCM &source)
Definition: QwBCM.h:53
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
Definition: QwBCM.cc:180
void SetCalibrationFactor(Double_t calib)
Definition: QwBCM.cc:28
void CalculateRunningAverage()
Definition: QwBCM.cc:367
Double_t GetNormClockValue()
Definition: QwBCM.h:118
void UseExternalRandomVariable()
Definition: QwBCM.cc:69
std::string GetExternalClockName()
Definition: QwBCM.h:114
QwBCM(TString subsystemname, TString name, TString type, TString clock="")
Definition: QwBCM.h:47
void LoadChannelParameters(QwParameterFile &paramfile)
Definition: QwBCM.h:68
T fBeamCurrent
Definition: QwBCM.h:168
Double_t GetValueWidth()
Definition: QwBCM.cc:511