QwAnalysis
VQwBPM.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: VQwBPM.cc *
3 * *
4 * Author:B.Waidyawansa *
5 * Time-stamp:03-06-2010 *
6 \**********************************************************/
7 
8 #include "VQwBPM.h"
9 
10 // System headers
11 #include <stdexcept>
12 
13 // Qweak headers
14 #include "QwLog.h"
15 #include "QwBPMStripline.h"
16 #include "QwCombinedBPM.h"
17 #include "QwVQWK_Channel.h"
18 #include "QwScaler_Channel.h"
19 
20 
21 /* With X being vertical up and Z being the beam direction toward the beamdump */
22 const TString VQwBPM::kAxisLabel[2]={"X","Y"};
23 
24 
25 void VQwBPM::InitializeChannel(TString name)
26 {
27  Short_t i = 0;
28 
29  for(i=0;i<3;i++) fPositionCenter[i] = 0.0;
30 
31  SetElementName(name);
32 
33  return;
34 }
35 
36 void VQwBPM::GetSurveyOffsets(Double_t Xoffset, Double_t Yoffset, Double_t Zoffset)
37 {
38  // Read in the position offsets from the geometry map file
39  for(Short_t i=0;i<3;i++) fPositionCenter[i]=0.0;
40  fPositionCenter[0]=Xoffset;
41  fPositionCenter[1]=Yoffset;
42  fPositionCenter[2]=Zoffset;
43  return;
44 }
45 
46 
47 void VQwBPM::GetElectronicFactors(Double_t BSENfactor, Double_t AlphaX, Double_t AlphaY)
48 {
49  // Read in the electronic factors from the file
50  Bool_t ldebug = kFALSE;
51 
52  fQwStriplineCalibration = BSENfactor*18.81;
53 
54  fRelativeGains[0]=AlphaX;
55  fRelativeGains[1]=AlphaY;
56 
57  if(ldebug){
58  std::cout<<"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
59  std::cout<<this->GetElementName();
60  std::cout<<"\nfQwStriplineCalibration = "<<fQwStriplineCalibration<<std::endl;
61  std::cout<<"AlphaX = "<<fRelativeGains[0]<<std::endl;
62  std::cout<<"AlphaY = "<<fRelativeGains[1]<<std::endl;
63 
64  }
65  return;
66 }
67 
68 void VQwBPM::SetRotation(Double_t rotation_angle){
69  // Read the rotation angle in degrees (to beam right)
70  Bool_t ldebug = kFALSE;
71  fSinRotation = 0;
72  fCosRotation = 0;
73  fRotationAngle = rotation_angle;
74  fSinRotation = TMath::Sin(fRotationAngle*(TMath::DegToRad()));
75  fCosRotation = TMath::Cos(fRotationAngle*(TMath::DegToRad()));
76 
77  if(ldebug){
78  std::cout<<"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
79  std::cout<<this->GetElementName();
80  std::cout<<" is rotated by angle = "<<rotation_angle<<std::endl;
81 
82  }
83 }
84 
86  // Turn off rotation. This object is already in accelerator coordinates.
87  fRotationAngle = 0.0;
89  bRotated=kFALSE;
90 }
91 
92 void VQwBPM::SetGains(TString pos, Double_t value){
93  if(pos.Contains("X")) fGains[0] = value;
94  if(pos.Contains("Y")) fGains[1] = value;
95 }
96 
97 void VQwBPM::SetSingleEventCuts(TString ch_name, Double_t minX, Double_t maxX)
98 {
99  VQwHardwareChannel* tmpptr = GetSubelementByName(ch_name);
100  QwMessage << GetElementName() << " " << ch_name
101  << " LL " << minX <<" UL " << maxX <<QwLog::endl;
102  tmpptr->SetSingleEventCuts(minX,maxX);
103 }
104 
105 void VQwBPM::SetSingleEventCuts(TString ch_name, UInt_t errorflag,Double_t minX, Double_t maxX, Double_t stability)
106 {
107  VQwHardwareChannel* tmpptr = GetSubelementByName(ch_name);
108  errorflag|=kBPMErrorFlag;//update the device flag
109  QwMessage << GetElementName() << " " << ch_name
110  << " LL " << minX <<" UL " << maxX <<QwLog::endl;
111  tmpptr->SetSingleEventCuts(errorflag,minX,maxX,stability);
112 }
113 
114 
116 {
117  if (GetElementName()!=""){
119  bRotated = value.bRotated;
121  fCosRotation = value.fCosRotation;
122  fSinRotation = value.fSinRotation;
123  fGoodEvent = value.fGoodEvent;
124  // fDeviceErrorCode = value.fDeviceErrorCode;
125  // bFullSave = value.bFullSave;
126  for(size_t axis=kXAxis;axis<kNumAxes;axis++){
129  }
130  // Copy Z center position
131  this->fPositionCenter[2]=value.fPositionCenter[2];
132  }
133  return *this;
134 }
135 
136 // VQwBPM& VQwBPM::operator+= (const VQwBPM &value)
137 // {
138 // if (GetElementName()!=""){
139 // this->fEffectiveCharge+=value.fEffectiveCharge;
140 // for(Short_t i=kXAxis;i<kNumAxes;i++) this->fAbsPos[i]+=value.fAbsPos[i];
141 // }
142 // return *this;
143 // }
144 
145 // VQwBPM& VQwBPM::operator-= (const VQwBPM &value)
146 // {
147 // if (GetElementName()!=""){
148 // this->fEffectiveCharge-=value.fEffectiveCharge;
149 // for(Short_t i=kXAxis;i<kNumAxes;i++) this->fAbsPos[i]-=value.fAbsPos[i];
150 // }
151 // return *this;
152 // }
153 
154 
155 // void VQwBPM::Sum(VQwBPM &value1, VQwBPM &value2)
156 // {
157 // *this = value1;
158 // *this += value2;
159 // }
160 
161 // void VQwBPM::Difference(VQwBPM &value1, VQwBPM &value2)
162 // {
163 // *this = value1;
164 // *this -= value2;
165 // }
166 
167 
168 // void VQwBPM::Scale(Double_t factor)
169 // {
170 // fEffectiveCharge_base->Scale(factor);
171 // for(Short_t i = 0;i<2;i++)fAbsPos_base[i]->Scale(factor);
172 // return;
173 // }
174 
175 
176 
177 
178 void VQwBPM::SetRootSaveStatus(TString &prefix)
179 {
180  if(prefix=="diff_"||prefix=="yield_"|| prefix=="asym_")
181  bFullSave=kFALSE;
182 
183  return;
184 }
185 
186 // void VQwBPM::PrintValue() const
187 // {
188 // Short_t i;
189 // for (i = 0; i < 2; i++) fAbsPos_base[i]->PrintValue();
190 // fEffectiveCharge_base->PrintValue();
191 
192 // return;
193 // }
194 
195 // void VQwBPM::PrintInfo() const
196 // {
197 // Short_t i = 0;
198 // for (i = 0; i < 4; i++) fAbsPos_base[i]->PrintInfo();
199 // fEffectiveCharge_base->PrintInfo();
200 // }
201 
202 
203 // void VQwBPM::CalculateRunningAverage()
204 // {
205 // Short_t i = 0;
206 // for (i = 0; i < 2; i++) fAbsPos_base[i]->CalculateRunningAverage();
207 // fEffectiveCharge_base->CalculateRunningAverage();
208 
209 // return;
210 // }
211 
212 
213 // void VQwBPM::AccumulateRunningSum(const VQwBPM& value)
214 // {
215 // // TODO This is unsafe, see QwBeamline::AccumulateRunningSum
216 // Short_t i = 0;
217 // for (i = 0; i < 2; i++) fAbsPos_base[i]->AccumulateRunningSum(value.fAbsPos_base[i]);
218 // fEffectiveCharge_base->AccumulateRunningSum(value.fEffectiveCharge_base);
219 // return;
220 // }
221 
222 /**
223  * \brief A fast way of creating a BPM stripline of specified type
224  */
225 VQwBPM* VQwBPM::CreateStripline(TString subsystemname, TString name, TString type)
226 {
227  Bool_t localDebug = kFALSE;
228  type.ToUpper();
229  if( localDebug ) QwMessage<<"Creating BPM of type: "<<type<<" with name: "<<
230  name<<". Subsystem Name: " <<subsystemname<<"\n";
231  // (jc2) As a first try, let's do this the ugly way (but rather very
232  // simple), just list out the types of BPM's supported by this code!!!
233  if( type == "VQWK") {
234  return new QwBPMStripline<QwVQWK_Channel>(subsystemname,name,type);
235  } else if ( type == "SIS3801" ) {
236  return new QwBPMStripline<QwSIS3801_Channel>(subsystemname,name,type);
237  } else if ( type == "SCALER" || type == "SIS3801D24" ) {
238  return new QwBPMStripline<QwSIS3801D24_Channel>(subsystemname,name,type);
239  } else { // Unsupported one!
240  QwWarning << "BPM of type="<<type<<" is UNSUPPORTED!!\n";
241  exit(-1);
242  }
243 }
244 
246 {
247  Bool_t localDebug = kFALSE;
248  TString type = source.GetModuleType();
249  type.ToUpper();
250  if( localDebug ) QwMessage<<"Creating BPM of type: "<<type << QwLog::endl;
251  // (jc2) As a first try, let's do this the ugly way (but rather very
252  // simple), just list out the types of BPM's supported by this code!!!
253  if( type == "VQWK") {
254  return new QwBPMStripline<QwVQWK_Channel>(dynamic_cast<const QwBPMStripline<QwVQWK_Channel>&>(source));
255  } else if ( type == "SIS3801" ) {
256  return new QwBPMStripline<QwSIS3801_Channel>(dynamic_cast<const QwBPMStripline<QwSIS3801_Channel>&>(source));
257  } else if ( type == "SCALER" || type == "SIS3801D24" ) {
258  return new QwBPMStripline<QwSIS3801D24_Channel>(dynamic_cast<const QwBPMStripline<QwSIS3801D24_Channel>&>(source));
259  } else { // Unsupported one!
260  QwWarning << "BPM of type="<<type<<" is UNSUPPORTED!!\n";
261  exit(-1);
262  }
263 }
264 
265 /**
266  * \brief A fast way of creating a BPM stripline of specified type
267  */
268 VQwBPM* VQwBPM::CreateCombo(TString subsystemname, TString name,
269  TString type)
270 {
271  Bool_t localDebug = kFALSE;
272  type.ToUpper();
273  if( localDebug ) QwMessage<<"Creating CombinedBPM of type: "<<type<<" with name: "<<
274  name<<". Subsystem Name: " <<subsystemname<<"\n";
275  // (jc2) As a first try, let's do this the ugly way (but rather very
276  // simple), just list out the types of BPM's supported by this code!!!
277  if( type == "VQWK") {
278  return new QwCombinedBPM<QwVQWK_Channel>(subsystemname,name,type);
279  } else if (type == "SIS3801" ) { // Default SCALER channel
280  return new QwCombinedBPM<QwSIS3801_Channel>(subsystemname,name,type);
281  } else if ( type == "SCALER" || type == "SIS3801D24" ) {
282  return new QwCombinedBPM<QwSIS3801D24_Channel>(subsystemname,name,type);
283  } else { // Unsupported one!
284  QwWarning << "BPM of type="<<type<<" is UNSUPPORTED!!\n";
285  exit(-1);
286  }
287 }
288 
290 {
291  Bool_t localDebug = kFALSE;
292  TString type = source.GetModuleType();
293  type.ToUpper();
294  if( localDebug ) QwMessage<<"Creating CombinedBCM of type: "<<type<< QwLog::endl;
295  // (jc2) As a first try, let's do this the ugly way (but rather very
296  // simple), just list out the types of BCM's supported by this code!!!
297  if( type == "VQWK") {
298  return new QwCombinedBPM<QwVQWK_Channel>(dynamic_cast<const QwCombinedBPM<QwVQWK_Channel>&>(source));
299  } else if ( type == "SIS3801" ) { // Default SCALER channel
300  return new QwCombinedBPM<QwSIS3801_Channel>(dynamic_cast<const QwCombinedBPM<QwSIS3801_Channel>&>(source));
301  } else if ( type == "SCALER" || type == "SIS3801D24" ) {
302  return new QwCombinedBPM<QwSIS3801D24_Channel>(dynamic_cast<const QwCombinedBPM<QwSIS3801D24_Channel>&>(source));
303  } else { // Unsupported one!
304  QwWarning << "BPM of type="<<type<<" is UNSUPPORTED!!\n";
305  exit(-1);
306  }
307 }
308 
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
Double_t fQwStriplineCalibration
Definition: VQwBPM.h:257
Double_t fRelativeGains[2]
Definition: VQwBPM.h:258
Bool_t fGoodEvent
Definition: VQwBPM.h:270
void SetRootSaveStatus(TString &prefix)
Definition: VQwBPM.cc:178
void SetSingleEventCuts(Double_t min, Double_t max)
Set the upper and lower limits (fULimit and fLLimit) for this channel.
virtual VQwHardwareChannel * GetSubelementByName(TString ch_name)=0
Double_t fGains[2]
Definition: VQwBPM.h:259
Bool_t bRotated
Definition: VQwBPM.h:263
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
Double_t fPositionCenter[3]
Definition: VQwBPM.h:256
static const TString kAxisLabel[2]
Definition: VQwBPM.h:239
TString GetModuleType() const
Return the type of the beam instrument.
void SetRotationOff()
Definition: VQwBPM.cc:85
Bool_t bFullSave
Definition: VQwBPM.h:273
A logfile class, based on an identical class in the Hermes analyzer.
void SetRotation(Double_t)
Definition: VQwBPM.cc:68
Double_t fCosRotation
Definition: VQwBPM.h:265
static const TString axis[3]
Definition: VQwBPM.h:260
void SetElementName(const TString &name)
Set the name of this element.
void InitializeChannel(TString name)
Definition: VQwBPM.cc:25
Double_t fSinRotation
Definition: VQwBPM.h:266
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
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
static const UInt_t kBPMErrorFlag
Definition: QwTypes.h:169
void SetGains(TString pos, Double_t value)
Definition: VQwBPM.cc:92
static VQwBPM * CreateStripline(TString subsystemname, TString type, TString name)
A fast way of creating a BPM stripline of specified type.
Definition: VQwBPM.cc:225
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
virtual VQwBPM & operator=(const VQwBPM &value)=0
Definition: VQwBPM.cc:115
void GetElectronicFactors(Double_t BSENfactor, Double_t AlphaX, Double_t AlphaY)
Definition: VQwBPM.cc:47