QwAnalysis
VQwBPM.h
Go to the documentation of this file.
1 /**********************************************************\
2 * File: VQwBPM.h *
3 * *
4 * Author: B.Waidyawansa *
5 * Time-stamp: <2010-05-24> *
6 \**********************************************************/
7 
8 
9 #ifndef __VQWBPM__
10 #define __VQWBPM__
11 
12 // System headers
13 #include <boost/shared_ptr.hpp>
14 
15 // ROOT headers
16 #include <TTree.h>
17 #include <TMath.h>
18 
19 // Qweak headers
20 #include "VQwDataElement.h"
21 #include "VQwHardwareChannel.h"
22 
23 class QwParameterFile;
24 template<typename T> class QwCombinedBPM;
25 template<typename T> class QwBPMStripline;
26 
27 class QwDBInterface;
28 class QwErrDBInterface;
29 
30 ///
31 /// \ingroup QwAnalysis_BeamLine
32 ///
33 
34 class VQwBPM : public VQwDataElement {
35  /******************************************************************
36  * Class: VQwBPM
37  * Virtual base class for the BPMs in the beamline.
38  * This will define a set of functions that are used by the
39  * BPMStripline and CombinedBPM classes for data decoding.
40  * This parent class will define the basic structure of a
41  * BPM. The basic object doesn't care about the inputs.
42  * It only defines absoloute positions and an effective charge.
43  * BPMs have 4 input wires for position: XP, XM, YP, YM
44  * Cavityy monitors have 3 wires: X, Y and I
45  * CombinedBPM use absolute X and Y derived from BPM X and Ys.
46  ******************************************************************/
47  template <typename TT> friend class QwBPMStripline;
48  template <typename TT> friend class QwCombinedBPM;
49  friend class QwEnergyCalculator;
50 
51  public:
52  /// Axis enumerator for the BPMs;
53  /// Z will never be an instrumented axis.
55 
56  public:
57  // Default constructor
59  VQwBPM(TString& name) {InitializeChannel_base();};
60  VQwBPM(const VQwBPM& source)
61  : VQwDataElement(source),
62  bRotated(source.bRotated),
63  bFullSave(source.bFullSave)
64  {
65  for (size_t i = 0; i < 3; i++)
66  fPositionCenter[i] = source.fPositionCenter[i];
67  }
68  virtual ~VQwBPM() { };
69 
70 
71  void InitializeChannel(TString name);
72  // virtual void ClearEventData() = 0;
73 
74  virtual void LoadChannelParameters(QwParameterFile &paramfile) = 0;
75 
76  void GetSurveyOffsets(Double_t Xoffset, Double_t Yoffset, Double_t Zoffset);
77  void GetElectronicFactors(Double_t BSENfactor, Double_t AlphaX, Double_t AlphaY);
78  void SetRotation(Double_t);
79  void SetRotationOff();
80 
81  void SetSingleEventCuts(TString, Double_t, Double_t);
82  void SetSingleEventCuts(TString, UInt_t, Double_t, Double_t, Double_t);
83  virtual UInt_t UpdateErrorFlag() = 0;
84  virtual void UpdateErrorFlag(const VQwBPM *ev_error) = 0;
85 
86  virtual void Scale(Double_t factor) {
87  std::cerr << "Scale for VQwBPM not implemented!\n";
88  }
89  void SetGains(TString pos, Double_t value);
90 
91  // Operators subclasses MUST support!
92  virtual VQwBPM& operator= (const VQwBPM &value) =0;
93  virtual VQwBPM& operator+= (const VQwBPM &value) =0;
94  virtual VQwBPM& operator-= (const VQwBPM &value) =0;
95 
96  void SetRootSaveStatus(TString &prefix);
97 
98 
99 /* VQwDataElement* GetPositionX(){ */
100 /* return fAbsPos_base[0]; */
101 /* }; */
102 /* const VQwDataElement* GetPositionX() const{ */
103 /* return const_cast<VQwBPM*>(this)->GetPositionX(); */
104 /* }; */
105 /* VQwDataElement* GetPositionY(){ */
106 /* return fAbsPos_base[1]; */
107 /* }; */
108 /* const VQwDataElement* GetPositionY() const{ */
109 /* return const_cast<VQwBPM*>(this)->GetPositionY(); */
110 /* }; */
111 
112 /* VQwHardwareChannel* GetPosition(size_t axis){ */
113 /* if (axis<0 || axis>2){ */
114 /* TString loc="VQwBPM::GetPosition for " */
115 /* +this->GetElementName()+" failed for axis value "+Form("%d",axis); */
116 /* throw std::out_of_range(loc.Data()); */
117 /* } */
118 /* return fAbsPos_base[axis]; */
119 /* } */
120 /* const VQwHardwareChannel* GetPosition(size_t axis) const{ */
121 /* return const_cast<VQwBPM*>(this)->GetPosition(axis); */
122 /* } */
123 
125 
126 
127 /* VQwHardwareChannel* GetEffectiveCharge(){ */
128 /* return fEffectiveCharge_base; */
129 /* } */
130  virtual const VQwHardwareChannel* GetEffectiveCharge() const = 0;
131 
132  Double_t GetPositionInZ() const{
133  return fPositionCenter[2];
134  };
135 
136 /* void PrintValue() const; */
137 /* void PrintInfo() const; */
138  virtual void CalculateRunningAverage() = 0;
139  virtual void AccumulateRunningSum(const VQwBPM& value) {
140  std::cerr << "AccumulateRunningSum not implemented for BPM named="
141  <<GetElementName()<<"\n";
142  };
143  virtual void DeaccumulateRunningSum(VQwBPM& value) = 0;
144 
145  virtual void ConstructHistograms(TDirectory *folder, TString &prefix) = 0;
146  virtual void FillHistograms() = 0;
147 
148  virtual void ConstructBranchAndVector(TTree *tree, TString &prefix,
149  std::vector<Double_t> &values) = 0;
150  virtual void ConstructBranch(TTree *tree, TString &prefix) = 0;
151  virtual void ConstructBranch(TTree *tree, TString &prefix,
152  QwParameterFile& modulelist) = 0;
153  virtual void FillTreeVector(std::vector<Double_t> &values) const = 0;
154 
155  virtual std::vector<QwDBInterface> GetDBEntry() = 0;
156  virtual std::vector<QwErrDBInterface> GetErrDBEntry() = 0;
157 
158  virtual void Ratio(VQwBPM &numer, VQwBPM &denom) {
159  std::cerr << "Ratio() is not defined for BPM named="<<GetElementName()<<"\n";
160  }
161 
162  // Stuff required for QwBPMStripLine
163 /* virtual UInt_t GetSubElementIndex(TString subname) { */
164 /* std::cerr << "GetSubElementIndex() is not implemented for BPM named=" */
165 /* <<GetElementName()<< "!!\n"; */
166 /* return 0; */
167 /* } */
168  virtual TString GetSubElementName(Int_t subindex) {
169  std::cerr << "GetSubElementName() is not implemented!!\n";
170  return TString("OBJECT_UNDEFINED"); // Return an erroneous TString
171  }
172  virtual void GetAbsolutePosition() {
173  std::cerr << "GetAbsolutePosition() is not implemented!!\n";
174  }
175  virtual void SetEventCutMode(Int_t bcuts) = 0;
176  virtual void PrintErrorCounters() const {// report number of events failed due to HW and event cut faliure
177  std::cerr << "PrintErrorCounters() is not implemented!!\n";
178  }
179  virtual Bool_t ApplySingleEventCuts() = 0;//Check for good events by stting limits on the devices readings
180  virtual void IncrementErrorCounters() = 0;
181  virtual void ProcessEvent() = 0;
182 
183  // These only applies to a combined BPM
184  virtual const VQwHardwareChannel* GetAngleX() const {
185  std::cerr << "GetAngleX() is not implemented for VQwBPM, must be"
186  "used in a CombinedBPM!\n";
187  return 0;
188  }
189  virtual const VQwHardwareChannel* GetAngleY() const {
190  std::cerr << "GetAngleY() is not implemented for VQwBPM, must be"
191  "used in a CombinedBPM!\n";
192  return 0;
193  }
194  virtual void SetBPMForCombo(const VQwBPM* bpm, Double_t charge_weight,
195  Double_t x_weight, Double_t y_weight,Double_t sumqw) {
196  std::cerr << "VQwBPM::SetBPMForCombo only defined for CombinedBPM's!!!\n";
197  }
198 
199 
200  virtual void SetDefaultSampleSize(Int_t sample_size) {
201  std::cerr << "SetDefaultSampleSize() is undefined!!!\n";
202  }
203  virtual void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY) {
204  std::cerr<< "SetRandomEventParameters undefined!!\n";
205  }
206  virtual void RandomizeEventData(int helicity = 0, double time = 0.0) {
207  std::cerr << "RandomizeEventData is undefined!!!\n";
208  }
209  virtual void EncodeEventData(std::vector<UInt_t> &buffer) {
210  std::cerr << "EncodeEventData is undefined!!!\n";
211  }
212  virtual void SetSubElementPedestal(Int_t j, Double_t value) {
213  std::cerr << "SetSubElementPedestal is undefined!!!\n";
214  }
215  virtual void SetSubElementCalibrationFactor(Int_t j, Double_t value) {
216  std::cerr << "SetSubElementCalibrationFactor is undefined!!!\n";
217  }
218  virtual void PrintInfo() const {
219  std::cout<<"PrintInfo() for VQwBPM not impletemented\n";
220  };
221 
222  // Factory function to produce appropriate BCM
223  static VQwBPM* CreateStripline(TString subsystemname, TString type, TString name);
224  static VQwBPM* CreateStripline(const VQwBPM& source);
225  static VQwBPM* CreateCombo(TString subsystemname, TString type, TString name);
226  static VQwBPM* CreateCombo(const VQwBPM& source);
227 
228  private:
229 
231 /* fAbsPos_base[0] = NULL; */
232 /* fAbsPos_base[1] = NULL; */
233 /* fEffectiveCharge_base = NULL; */
234  fQwStriplineCalibration = 18.81; // adc counts/mm default value
235  for(Short_t i=0;i<2;i++) {
236  fRelativeGains[i]=1.0;
237  fGains[i]=1.0;
238  }
239  };
240 
241 
242  protected:
243  /// Axis labels for the instrumented directions;
244  /// Z will never be an instrumented axis.
245  static const TString kAxisLabel[2];
246 
247  virtual VQwHardwareChannel* GetSubelementByName(TString ch_name) = 0;
249  return GetSubelementByName(fSubelementNames.at(index));
250  };
251 
252  protected:
253  std::vector<TString> fSubelementNames;
254 
255  // Position calculation related paramters
256  Double_t fPositionCenter[3];
258  Double_t fRelativeGains[2];
259  Double_t fGains[2];
260  static const TString axis[3];
261 
262  // Rotation related paramters
263  Bool_t bRotated;
264  Double_t fRotationAngle;
265  Double_t fCosRotation;
266  Double_t fSinRotation;
267 
268 
269  // Data quality checks related flags
270  Bool_t fGoodEvent;
271  // Bool_t bEVENTCUTMODE;//If this set to kFALSE then Event cuts are OFF
272  // Int_t fDeviceErrorCode;//keep the device HW status using a unique code from the QwVQWK_Channel::fDeviceErrorCode
273  Bool_t bFullSave; // used to restrict the amount of data histogramed
274 
275  const static Bool_t bDEBUG=kFALSE;//debugging display purposes
276 
277 };
278 
279 typedef boost::shared_ptr<VQwBPM> VQwBPM_ptr;
280 
281 #endif
282 
283 
Double_t fQwStriplineCalibration
Definition: VQwBPM.h:257
virtual void CalculateRunningAverage()=0
virtual std::vector< QwErrDBInterface > GetErrDBEntry()=0
Double_t fRelativeGains[2]
Definition: VQwBPM.h:258
virtual void ProcessEvent()=0
Bool_t fGoodEvent
Definition: VQwBPM.h:270
virtual std::vector< QwDBInterface > GetDBEntry()=0
void SetRootSaveStatus(TString &prefix)
Definition: VQwBPM.cc:178
static const Bool_t bDEBUG
Definition: VQwBPM.h:275
virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)=0
virtual void DeaccumulateRunningSum(VQwBPM &value)=0
virtual VQwHardwareChannel * GetSubelementByName(TString ch_name)=0
virtual void ConstructHistograms(TDirectory *folder, TString &prefix)=0
Construct the histograms for this data element.
Double_t fGains[2]
Definition: VQwBPM.h:259
virtual void PrintInfo() const
Print multiple lines of information about this data element.
Definition: VQwBPM.h:218
Bool_t bRotated
Definition: VQwBPM.h:263
virtual void LoadChannelParameters(QwParameterFile &paramfile)=0
Double_t GetPositionInZ() const
Definition: VQwBPM.h:132
virtual const VQwHardwareChannel * GetEffectiveCharge() const =0
void SetSingleEventCuts(TString, Double_t, Double_t)
Definition: VQwBPM.cc:97
Double_t fRotationAngle
Definition: VQwBPM.h:264
void GetSurveyOffsets(Double_t Xoffset, Double_t Yoffset, Double_t Zoffset)
Definition: VQwBPM.cc:36
virtual void SetSubElementCalibrationFactor(Int_t j, Double_t value)
Definition: VQwBPM.h:215
virtual ~VQwBPM()
Definition: VQwBPM.h:68
Double_t fPositionCenter[3]
Definition: VQwBPM.h:256
virtual Bool_t ApplySingleEventCuts()=0
VQwBPM(TString &name)
Definition: VQwBPM.h:59
static const TString kAxisLabel[2]
Definition: VQwBPM.h:239
virtual void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY)
Definition: VQwBPM.h:203
void SetRotationOff()
Definition: VQwBPM.cc:85
virtual const VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis) const =0
virtual void FillHistograms()=0
Fill the histograms for this data element.
virtual void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
Definition: VQwBPM.h:176
Definition of the pure virtual base class of all data elements.
Bool_t bFullSave
Definition: VQwBPM.h:273
virtual UInt_t UpdateErrorFlag()=0
Update the error flag based on the error flags of internally contained objects Return paramter is the...
The pure virtual base class of all data elements.
virtual const VQwHardwareChannel * GetAngleX() const
Definition: VQwBPM.h:184
virtual VQwBPM & operator-=(const VQwBPM &value)=0
virtual TString GetSubElementName(Int_t subindex)
Definition: VQwBPM.h:168
virtual void FillTreeVector(std::vector< Double_t > &values) const =0
void SetRotation(Double_t)
Definition: VQwBPM.cc:68
virtual void SetSubElementPedestal(Int_t j, Double_t value)
Definition: VQwBPM.h:212
virtual void Scale(Double_t factor)
Definition: VQwBPM.h:86
virtual void EncodeEventData(std::vector< UInt_t > &buffer)
Definition: VQwBPM.h:209
virtual void AccumulateRunningSum(const VQwBPM &value)
Definition: VQwBPM.h:139
Double_t fCosRotation
Definition: VQwBPM.h:265
virtual void SetDefaultSampleSize(Int_t sample_size)
Definition: VQwBPM.h:200
static const TString axis[3]
Definition: VQwBPM.h:260
void InitializeChannel_base()
Definition: VQwBPM.h:230
VQwBPM(const VQwBPM &source)
Definition: VQwBPM.h:60
void InitializeChannel(TString name)
Definition: VQwBPM.cc:25
EBeamPositionMonitorAxis
Definition: VQwBPM.h:54
VQwBPM()
Definition: VQwBPM.h:58
virtual void SetEventCutMode(Int_t bcuts)=0
virtual void IncrementErrorCounters()=0
Double_t fSinRotation
Definition: VQwBPM.h:266
virtual const VQwHardwareChannel * GetAngleY() const
Definition: VQwBPM.h:189
virtual VQwBPM & operator+=(const VQwBPM &value)=0
std::vector< TString > fSubelementNames
Definition: VQwBPM.h:250
Definition: VQwBPM.h:34
virtual const TString & GetElementName() const
Get the name of this element.
static VQwBPM * CreateCombo(TString subsystemname, TString type, TString name)
A fast way of creating a BPM stripline of specified type.
Definition: VQwBPM.cc:268
void SetGains(TString pos, Double_t value)
Definition: VQwBPM.cc:92
virtual void SetBPMForCombo(const VQwBPM *bpm, Double_t charge_weight, Double_t x_weight, Double_t y_weight, Double_t sumqw)
Definition: VQwBPM.h:194
static VQwBPM * CreateStripline(TString subsystemname, TString type, TString name)
A fast way of creating a BPM stripline of specified type.
Definition: VQwBPM.cc:225
virtual void Ratio(VQwBPM &numer, VQwBPM &denom)
Definition: VQwBPM.h:158
virtual VQwBPM & operator=(const VQwBPM &value)=0
Definition: VQwBPM.cc:115
virtual void RandomizeEventData(int helicity=0, double time=0.0)
Definition: VQwBPM.h:206
boost::shared_ptr< VQwBPM > VQwBPM_ptr
Definition: VQwBPM.h:279
void GetElectronicFactors(Double_t BSENfactor, Double_t AlphaX, Double_t AlphaY)
Definition: VQwBPM.cc:47
virtual void ConstructBranch(TTree *tree, TString &prefix)=0
virtual void GetAbsolutePosition()
Definition: VQwBPM.h:172
VQwHardwareChannel * GetSubelementByIndex(size_t index)
Definition: VQwBPM.h:248