QwAnalysis
QwCombinedBPM.h
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwCombinedBPM.h *
3 * *
4 * Author:B. Waidyawansa *
5 * Time-stamp: *
6 \**********************************************************/
7 
8 #ifndef __QwCOMBINEDBPM__
9 #define __QwCOMBINEDBPM__
10 
11 // System headers
12 #include <vector>
13 
14 // ROOT headers
15 #include <TTree.h>
16 
17 // Qweak headers
18 #include "VQwHardwareChannel.h"
19 #include "VQwBPM.h"
20 
21 // Forward declarations
22 class QwDBInterface;
23 class QwParameterFile;
24 
25 /*****************************************************************
26 * Class:
27 ******************************************************************/
28 ///
29 /// \ingroup QwAnalysis_BL
30 template<typename T>
31 class QwCombinedBPM : public VQwBPM {
32  friend class QwEnergyCalculator;
33 
34  /////
35  public:
37  };
38  QwCombinedBPM(TString name):VQwBPM(name){
39  InitializeChannel(name);
40  };
41  QwCombinedBPM(TString subsystem, TString name): VQwBPM(name){
42  InitializeChannel(subsystem, name);
43  };
44 
45  QwCombinedBPM(TString subsystem, TString name, TString type): VQwBPM(name){
46  InitializeChannel(subsystem, name,type);
47  };
49  : VQwBPM(source),
50  fSlope(source.fSlope),
51  fIntercept(source.fIntercept),
53  fAbsPos(source.fAbsPos),
55  { }
56  virtual ~QwCombinedBPM() { };
57 
59 
60  void InitializeChannel(TString name);
61  // new routine added to update necessary information for tree trimming
62  void InitializeChannel(TString subsystem, TString name);
63  void InitializeChannel(TString subsystem, TString name, TString type) {
64  SetModuleType(type);
65  InitializeChannel(subsystem, name);
66  }
67 
69 
70  void ClearEventData();
71  Int_t ProcessEvBuffer(UInt_t* buffer,
72  UInt_t word_position_in_buffer,UInt_t indexnumber);
73  void ProcessEvent();
74  void PrintValue() const;
75  void PrintInfo() const;
76 
78  if (axis<0 || axis>2){
79  TString loc="QwLinearDiodeArray::GetPosition for "
80  +this->GetElementName()+" failed for axis value "+Form("%d",axis);
81  throw std::out_of_range(loc.Data());
82  }
83  return &fAbsPos[axis];
84  }
85 
87  if (axis<0 || axis>2){
88  TString loc="QwLinearDiodeArray::GetPosition for "
89  +this->GetElementName()+" failed for axis value "+Form("%d",axis);
90  throw std::out_of_range(loc.Data());
91  }
92  return &fSlope[axis];
93  }
95  return &fEffectiveCharge;
96  }
97 
98 
99  Bool_t ApplyHWChecks();//Check for harware errors in the devices
100  Bool_t ApplySingleEventCuts();//Check for good events by stting limits on the devices readings
101  //void SetSingleEventCuts(TString ch_name, Double_t minX, Double_t maxX);
102  /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
103  //void SetSingleEventCuts(TString ch_name, UInt_t errorflag,Double_t min, Double_t max, Double_t stability);
104  void SetEventCutMode(Int_t bcuts);
105  void IncrementErrorCounters();
106  void PrintErrorCounters() const;// report number of events failed due to HW and event cut faliure
107  UInt_t GetEventcutErrorFlag();
108  UInt_t UpdateErrorFlag();
109  void UpdateErrorFlag(const VQwBPM *ev_error);
110 
111 
112  void SetBPMForCombo(const VQwBPM* bpm, Double_t charge_weight, Double_t x_weight, Double_t y_weight,Double_t sumqw);
113 
114  void Ratio(QwCombinedBPM &numer, QwCombinedBPM &denom);
115  void Ratio(VQwBPM &numer, VQwBPM &denom);
116  void Scale(Double_t factor);
117 
118  VQwBPM& operator= (const VQwBPM &value);
119  VQwBPM& operator+= (const VQwBPM &value);
120  VQwBPM& operator-= (const VQwBPM &value);
121 
122  virtual QwCombinedBPM& operator= (const QwCombinedBPM &value);
123  virtual QwCombinedBPM& operator+= (const QwCombinedBPM &value);
124  virtual QwCombinedBPM& operator-= (const QwCombinedBPM &value);
125 
126  void AccumulateRunningSum(const VQwBPM& value);
127  void AccumulateRunningSum(const QwCombinedBPM& value);
128  void DeaccumulateRunningSum(VQwBPM& value);
131 
132  void ConstructHistograms(TDirectory *folder, TString &prefix);
133  void FillHistograms();
134 
135  void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values);
136  void ConstructBranch(TTree *tree, TString &prefix);
137  void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist);
138  void FillTreeVector(std::vector<Double_t> &values) const;
139 
140 
141 
142 
143  VQwHardwareChannel* GetAngleX(){ //At present this returns the slope not the angle
144  return &fSlope[0];
145  };
146 
147  const VQwHardwareChannel* GetAngleX() const { //At present this returns the slope not the angle
148  return const_cast<QwCombinedBPM*>(this)->GetAngleX();
149  };
150 
151  VQwHardwareChannel* GetAngleY(){//At present this returns the slope not the angle
152  return &fSlope[1];
153  };
154 
155  const VQwHardwareChannel* GetAngleY() const { //At present this returns the slope not the angle
156  return const_cast<QwCombinedBPM*>(this)->GetAngleY();
157  };
158 
159 
160 
161  std::vector<QwDBInterface> GetDBEntry();
162  std::vector<QwErrDBInterface> GetErrDBEntry();
163 
164  protected:
165  VQwHardwareChannel* GetSubelementByName(TString ch_name);
166 
167  /* Functions for least square fit */
168  void CalculateFixedParameter(std::vector<Double_t> fWeights, Int_t pos);
169  Double_t SumOver( std::vector <Double_t> weight , std::vector <T> val);
170  void LeastSquareFit(VQwBPM::EBeamPositionMonitorAxis axis, std::vector<Double_t> fWeights) ; //bbbbb
171 
172 
173 
174  /////
175  private:
177 
178  //used for least squares fit
179  Double_t erra[2],errb[2],covab[2];
180  Double_t A[2], B[2], D[2], m[2];
181  Double_t chi_square[2];
182  Double_t fSumQweights;
183 
184  std::vector <const VQwBPM*> fElement;
185  std::vector <Double_t> fQWeights;
186  std::vector <Double_t> fXWeights;
187  std::vector <Double_t> fYWeights;
188 
189 
190  protected:
191  /* This channel contains the beam slope w.r.t the X & Y axis at the target */
192  T fSlope[2];
193 
194  /* This channel contains the beam intercept w.r.t the X & Y axis at the target */
196 
197  /*This channel gives the minimum chisquare value for the fit over target bpms*/
199 
200  // These are the "real" data elements, to which the base class
201  // fAbsPos_base and fEffectiveCharge_base are pointers.
202  T fAbsPos[2];
204 
205 private:
206  // Functions to be removed
207  void MakeBPMComboList();
208  std::vector<T> fBPMComboElementList;
209 
210 };
211 
212 
213 
214 #endif
215 
Double_t covab[2]
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
void CalculateRunningAverage()
VQwHardwareChannel * GetAngleY()
std::vector< Double_t > fXWeights
void InitializeChannel(TString name)
Double_t fSumQweights
void IncrementErrorCounters()
VQwBPM & operator-=(const VQwBPM &value)
void CalculateFixedParameter(std::vector< Double_t > fWeights, Int_t pos)
VQwBPM & operator=(const VQwBPM &value)
void SetEventCutMode(Int_t bcuts)
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel.
Double_t m[2]
const VQwHardwareChannel * GetAngleY() const
virtual ~QwCombinedBPM()
Definition: QwCombinedBPM.h:56
Bool_t ApplySingleEventCuts()
const VQwHardwareChannel * GetAngleX() const
void FillTreeVector(std::vector< Double_t > &values) const
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
const VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis) const
Definition: QwCombinedBPM.h:77
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
Double_t SumOver(std::vector< Double_t > weight, std::vector< T > val)
void ClearEventData()
Clear the event data in this element.
VQwHardwareChannel * GetSubelementByName(TString ch_name)
void FillHistograms()
Fill the histograms for this data element.
QwCombinedBPM(TString subsystem, TString name, TString type)
Definition: QwCombinedBPM.h:45
UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
void DeaccumulateRunningSum(VQwBPM &value)
Bool_t fixedParamCalculated
void LeastSquareFit(VQwBPM::EBeamPositionMonitorAxis axis, std::vector< Double_t > fWeights)
void Scale(Double_t factor)
static const TString axis[3]
Definition: VQwBPM.h:260
void SetBPMForCombo(const VQwBPM *bpm, Double_t charge_weight, Double_t x_weight, Double_t y_weight, Double_t sumqw)
QwCombinedBPM(TString name)
Definition: QwCombinedBPM.h:38
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
EBeamPositionMonitorAxis
Definition: VQwBPM.h:54
Double_t D[2]
QwCombinedBPM(TString subsystem, TString name)
Definition: QwCombinedBPM.h:41
Double_t errb[2]
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
Definition: VQwBPM.h:34
void SetModuleType(TString ModuleType)
set the type of the beam instrument
T fMinimumChiSquare[2]
Double_t A[2]
virtual const TString & GetElementName() const
Get the name of this element.
void PrintInfo() const
Print multiple lines of information about this data element.
Double_t B[2]
const VQwHardwareChannel * GetEffectiveCharge() const
Definition: QwCombinedBPM.h:94
VQwBPM & operator+=(const VQwBPM &value)
std::vector< const VQwBPM * > fElement
const VQwHardwareChannel * GetSlope(EBeamPositionMonitorAxis axis) const
Definition: QwCombinedBPM.h:86
std::vector< T > fBPMComboElementList
std::vector< Double_t > fQWeights
void MakeBPMComboList()
std::vector< QwErrDBInterface > GetErrDBEntry()
VQwHardwareChannel * GetAngleX()
void InitializeChannel(TString subsystem, TString name, TString type)
Definition: QwCombinedBPM.h:63
Double_t erra[2]
std::vector< QwDBInterface > GetDBEntry()
Double_t chi_square[2]
std::vector< Double_t > fYWeights
void LoadChannelParameters(QwParameterFile &paramfile)
Definition: QwCombinedBPM.h:68
Bool_t ApplyHWChecks()
void Ratio(QwCombinedBPM &numer, QwCombinedBPM &denom)
QwCombinedBPM(const QwCombinedBPM &source)
Definition: QwCombinedBPM.h:48
void PrintValue() const
Print single line of value and error of this data element.
void ConstructBranch(TTree *tree, TString &prefix)
void AccumulateRunningSum(const VQwBPM &value)
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t indexnumber)
Process the CODA event buffer for this element.