QwAnalysis
QwBCM.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwBCM.h *
3 * *
4 * Author: *
5 * Time-stamp: *
6 \**********************************************************/
7 
8 #include "QwBCM.h"
9 
10 // System headers
11 #include <stdexcept>
12 
13 // Qweak database headers
14 #include "QwDBInterface.h"
15 
16 // Qweak types that we want to use in this template
17 #include "QwVQWK_Channel.h"
18 #include "QwScaler_Channel.h"
19 
20 /********************************************************/
21 template<typename T>
22 void QwBCM<T>::SetPedestal(Double_t pedestal)
23 {
24  fBeamCurrent.SetPedestal(pedestal);
25 }
26 
27 template<typename T>
28 void QwBCM<T>::SetCalibrationFactor(Double_t calibration)
29 {
30  fBeamCurrent.SetCalibrationFactor(calibration);
31 }
32 /********************************************************/
33 template<typename T>
34 void QwBCM<T>::InitializeChannel(TString name, TString datatosave)
35 {
36  SetPedestal(0.);
37  SetCalibrationFactor(1.);
38  fBeamCurrent.InitializeChannel(name,datatosave);
39  this->SetElementName(name);
40 }
41 /********************************************************/
42 template<typename T>
43 void QwBCM<T>::InitializeChannel(TString subsystem, TString name, TString datatosave){
44  SetPedestal(0.);
45  SetCalibrationFactor(1.);
46  fBeamCurrent.InitializeChannel(subsystem, "QwBCM", name, datatosave);
47  SetElementName(name);
48 }
49 /********************************************************/
50 template<typename T>
51 void QwBCM<T>::InitializeChannel(TString subsystem, TString name, TString type,
52  TString datatosave){
53  SetPedestal(0.);
54  SetCalibrationFactor(1.);
55  SetModuleType(type);
56  fBeamCurrent.InitializeChannel(subsystem, "QwBCM", name, datatosave);
57  SetElementName(name);
58 }
59 
60 /********************************************************/
61 template<typename T>
63 {
64  fBeamCurrent.ClearEventData();
65 }
66 
67 /********************************************************/
68 template<typename T>
70 {
71  fBeamCurrent.UseExternalRandomVariable();
72 }
73 /********************************************************/
74 template<typename T>
75 void QwBCM<T>::SetExternalRandomVariable(double random_variable)
76 {
77  fBeamCurrent.SetExternalRandomVariable(random_variable);
78 }
79 /********************************************************/
80 template<typename T>
81 void QwBCM<T>::SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
82 {
83  fBeamCurrent.SetRandomEventDriftParameters(amplitude, phase, frequency);
84 }
85 /********************************************************/
86 template<typename T>
87 void QwBCM<T>::AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
88 {
89  fBeamCurrent.AddRandomEventDriftParameters(amplitude, phase, frequency);
90 }
91 /********************************************************/
92 template<typename T>
93 void QwBCM<T>::SetRandomEventParameters(Double_t mean, Double_t sigma)
94 {
95  fBeamCurrent.SetRandomEventParameters(mean, sigma);
96 }
97 /********************************************************/
98 template<typename T>
99 void QwBCM<T>::SetRandomEventAsymmetry(Double_t asymmetry)
100 {
101  fBeamCurrent.SetRandomEventAsymmetry(asymmetry);
102 }
103 /********************************************************/
104 template<typename T>
105 void QwBCM<T>::RandomizeEventData(int helicity, double time)
106 {
107  fBeamCurrent.RandomizeEventData(helicity, time);
108 }
109 /********************************************************/
110 template<typename T>
111 void QwBCM<T>::EncodeEventData(std::vector<UInt_t> &buffer)
112 {
113  fBeamCurrent.EncodeEventData(buffer);
114 }
115 /********************************************************/
116 template<typename T>
118 {
119  this->ApplyHWChecks();//first apply HW checks and update HW error flags. Calling this routine either in ApplySingleEventCuts or here do not make any difference for a BCM but do for a BPMs because they have derrived devices.
120  fBeamCurrent.ProcessEvent();
121 }
122 /********************************************************/
123 template<typename T>
125 {
126  Bool_t eventokay=kTRUE;
127 
128  UInt_t deviceerror=fBeamCurrent.ApplyHWChecks();//will check for HW consistancy and return the error code (=0 is HW good)
129  eventokay=(deviceerror & 0x0);//if no HW error return true
130 
131  return eventokay;
132 }
133 /********************************************************/
134 
135 template<typename T>
136 Int_t QwBCM<T>::SetSingleEventCuts(Double_t LL, Double_t UL){//std::vector<Double_t> & dEventCuts){//two limts and sample size
137  fBeamCurrent.SetSingleEventCuts(LL,UL);
138  return 1;
139 }
140 
141 template<typename T>
142 void QwBCM<T>::SetSingleEventCuts(UInt_t errorflag, Double_t LL, Double_t UL, Double_t stability){
143  //set the unique tag to identify device type (bcm,bpm & etc)
144  errorflag|=kBCMErrorFlag;
145  QwMessage<<"QwBCM Error Code passing to QwVQWK_Ch "<<errorflag<<" "<<stability<<QwLog::endl;
146  fBeamCurrent.SetSingleEventCuts(errorflag,LL,UL,stability);
147 
148 }
149 
150 template<typename T>
151 void QwBCM<T>::SetDefaultSampleSize(Int_t sample_size){
152  fBeamCurrent.SetDefaultSampleSize((size_t)sample_size);
153 }
154 
155 
156 /********************************************************/
157 template<typename T>
159 {
160  //std::cout<<" QwBCM::SingleEventCuts() "<<std::endl;
161  Bool_t status = kTRUE;
162 
163  if (fBeamCurrent.ApplySingleEventCuts()) {
164  status = kTRUE;
165  } else {
166  status &= kFALSE;
167  }
168  return status;
169 }
170 
171 /********************************************************/
172 
173 template<typename T>
175 {// report number of events failed due to HW and event cut faliure
176  fBeamCurrent.IncrementErrorCounters();
177 }
178 
179 template<typename T>
181 {// report number of events failed due to HW and event cut faliure
182  fBeamCurrent.PrintErrorCounters();
183 }
184 
185 /********************************************************/
186 template<typename T>
187 void QwBCM<T>::UpdateErrorFlag(const VQwBCM *ev_error){
188  try {
189  if(typeid(*ev_error)==typeid(*this)) {
190  // std::cout<<" Here in QwBCM::UpdateErrorFlag \n";
191  if (this->GetElementName()!="") {
192  const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(ev_error);
193  fBeamCurrent.UpdateErrorFlag(value_bcm->fBeamCurrent);
194  }
195  } else {
196  TString loc="Standard exception from QwBCM::UpdateErrorFlag :"+
197  ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
198  +"same type";
199  throw std::invalid_argument(loc.Data());
200  }
201  } catch (std::exception& e) {
202  std::cerr<< e.what()<<std::endl;
203  }
204 };
205 
206 
207 /********************************************************/
208 template<typename T>
209 Int_t QwBCM<T>::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement)
210 {
211  fBeamCurrent.ProcessEvBuffer(buffer,word_position_in_buffer);
212 
213  return word_position_in_buffer;
214 }
215 /********************************************************/
216 template<typename T>
218 {
219 // std::cout<<" Here in QwBCM::operator= \n";
220  if (this->GetElementName()!="")
221  {
222  this->fBeamCurrent=value.fBeamCurrent;
223  }
224 // std::cout<<" to be copied \n";
225 // value.Print();
226 // std::cout<<" copied \n";
227 // this->Print();
228 
229  return *this;
230 }
231 
232 template<typename T>
234 {
235  try {
236  if(typeid(value)==typeid(*this)) {
237  // std::cout<<" Here in QwBCM::operator= \n";
238  if (this->GetElementName()!="") {
239  const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
240  QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
241  this_cast->fBeamCurrent= value_bcm->fBeamCurrent;
242  }
243  } else {
244  TString loc="Standard exception from QwBCM::operato= :"+
245  value.GetElementName()+" "+this->GetElementName()+" are not of the "
246  +"same type";
247  throw std::invalid_argument(loc.Data());
248  }
249  } catch (std::exception& e) {
250  std::cerr<< e.what()<<std::endl;
251  }
252 // std::cout<<" to be copied \n";
253 // value.Print();
254 // std::cout<<" copied \n";
255 // this->Print();
256 
257  return *this;
258 }
259 
260 template<typename T>
262 {
263  if (this->GetElementName()!="")
264  {
265  this->fBeamCurrent+=value.fBeamCurrent;
266  }
267  return *this;
268 }
269 
270 template<typename T>
272 {
273  try {
274  if(typeid(value)==typeid(*this)) {
275  // std::cout<<" Here in QwBCM::operator+= \n";
276  if (this->GetElementName()!="") {
277  const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
278  QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
279  this_cast->fBeamCurrent+=value_bcm->fBeamCurrent;
280  }
281  } else {
282  TString loc="Standard exception from QwBCM::operator+= :"+
283  value.GetElementName()+" "+this->GetElementName()+" are not of the "
284  +"same type";
285  throw std::invalid_argument(loc.Data());
286  }
287  } catch (std::exception& e) {
288  std::cerr<< e.what()<<std::endl;
289  }
290 
291  return *this;
292 }
293 
294 template<typename T>
296 {
297  if (this->GetElementName()!="")
298  {
299  const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
300  QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
301  this_cast->fBeamCurrent-=value_bcm->fBeamCurrent;
302  }
303  return *this;
304 }
305 
306 template<typename T>
308 {
309  try {
310  if(typeid(value)==typeid(*this)) {
311  // std::cout<<" Here in QwBCM::operator-= \n";
312  if (this->GetElementName()!="") {
313  const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
314  QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
315  this_cast->fBeamCurrent-=value_bcm->fBeamCurrent;
316  }
317  } else {
318  TString loc="Standard exception from QwBCM::operator-= :"+
319  value.GetElementName()+" "+this->GetElementName()+" are not of the "
320  +"same type";
321  throw std::invalid_argument(loc.Data());
322  }
323  } catch (std::exception& e) {
324  std::cerr<< e.what()<<std::endl;
325  }
326  return *this;
327 }
328 
329 
330 template<typename T>
331 void QwBCM<T>::Sum(QwBCM<T> &value1, QwBCM<T> &value2){
332  *this = value1;
333  *this += value2;
334 }
335 
336 template<typename T>
337 void QwBCM<T>::Difference(QwBCM<T> &value1, QwBCM<T> &value2){
338  *this = value1;
339  *this -= value2;
340 }
341 
342 template<typename T>
343 void QwBCM<T>::Ratio(const VQwBCM &numer, const VQwBCM &denom)
344 {
345  Ratio(*dynamic_cast<const QwBCM<T>* >(&numer),
346  *dynamic_cast<const QwBCM<T>* >(&denom));
347 }
348 
349 template<typename T>
350 void QwBCM<T>::Ratio(const QwBCM<T> &numer, const QwBCM<T> &denom)
351 {
352  // std::cout<<"QwBCM::Ratio element name ="<<GetElementName()<<" \n";
353  if (this->GetElementName()!="")
354  {
355  // std::cout<<"here in \n";
356  this->fBeamCurrent.Ratio(numer.fBeamCurrent,denom.fBeamCurrent);
357  }
358 }
359 
360 template<typename T>
361 void QwBCM<T>::Scale(Double_t factor)
362 {
363  fBeamCurrent.Scale(factor);
364 }
365 
366 template<typename T>
368 {
369  fBeamCurrent.CalculateRunningAverage();
370 }
371 
372 template<typename T>
374  fBeamCurrent.AccumulateRunningSum(
375  dynamic_cast<const QwBCM<T>* >(&value)->fBeamCurrent);
376 }
377 
378 template<typename T>
380  fBeamCurrent.DeaccumulateRunningSum(dynamic_cast<QwBCM<T>* >(&value)->fBeamCurrent);
381 }
382 template<typename T>
384 {
385  fBeamCurrent.PrintValue();
386 }
387 
388 template<typename T>
390 {
391  std::cout << "QwVQWK_Channel Info " << std::endl;
392  fBeamCurrent.PrintInfo();
393 }
394 
395 /********************************************************/
396 template<typename T>
397 void QwBCM<T>::ConstructHistograms(TDirectory *folder, TString &prefix)
398 {
399  if (this->GetElementName()=="")
400  {
401  // This channel is not used, so skip filling the histograms.
402  }
403  else
404  {
405  fBeamCurrent.ConstructHistograms(folder, prefix);
406  }
407 }
408 
409 template<typename T>
411 {
412  if (this->GetElementName()=="")
413  {
414  // This channel is not used, so skip filling the histograms.
415  }
416  else
417  {
418  fBeamCurrent.FillHistograms();
419  }
420 }
421 
422 template<typename T>
423 void QwBCM<T>::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
424 {
425  if (this->GetElementName()==""){
426  // This channel is not used, so skip
427  } else
428  {
429  fBeamCurrent.ConstructBranchAndVector(tree, prefix,values);
430  }
431 }
432 
433 template<typename T>
434 void QwBCM<T>::ConstructBranch(TTree *tree, TString &prefix)
435 {
436  if (GetElementName()==""){
437  // This channel is not used, so skip filling the histograms.
438  } else
439  {
440  fBeamCurrent.ConstructBranch(tree, prefix);
441  // this functions doesn't do anything yet
442  }
443 }
444 
445 template<typename T>
446 void QwBCM<T>::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist)
447 {
448  TString devicename;
449 
450  devicename=GetElementName();
451  devicename.ToLower();
452  if (GetElementName()==""){
453  // This channel is not used, so skip filling the histograms.
454  } else
455  {
456 
457  //QwMessage <<" QwBCM "<<devicename<<QwLog::endl;
458  if (modulelist.HasValue(devicename)){
459  fBeamCurrent.ConstructBranch(tree, prefix);
460  QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
461  }
462  // this functions doesn't do anything yet
463  }
464 }
465 
466 template<typename T>
467 void QwBCM<T>::FillTreeVector(std::vector<Double_t> &values) const
468 {
469  if (this->GetElementName()==""){
470  // This channel is not used, so skip filling the histograms.
471  } else
472  {
473  fBeamCurrent.FillTreeVector(values);
474  // this functions doesn't do anything yet
475  }
476 }
477 
478 template<typename T>
479 std::vector<QwDBInterface> QwBCM<T>::GetDBEntry()
480 {
481  std::vector <QwDBInterface> row_list;
482  fBeamCurrent.AddEntriesToList(row_list);
483  return row_list;
484 }
485 
486 
487 
488 template<typename T>
489 std::vector<QwErrDBInterface> QwBCM<T>::GetErrDBEntry()
490 {
491  std::vector <QwErrDBInterface> row_list;
492  fBeamCurrent.AddErrEntriesToList(row_list);
493  return row_list;
494 }
495 
496 
497 template<typename T>
499 {
500  return fBeamCurrent.GetValue();
501 }
502 
503 
504 template<typename T>
506 {
507  return fBeamCurrent.GetValueError();
508 }
509 
510 template<typename T>
512 {
513  return fBeamCurrent.GetValueWidth();
514 }
515 
516 template class QwBCM<QwVQWK_Channel>;
517 template class QwBCM<QwSIS3801_Channel>;
518 template class QwBCM<QwSIS3801D24_Channel>;
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
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
static const UInt_t kBCMErrorFlag
Definition: QwTypes.h:167
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 ApplyHWChecks()
Definition: QwBCM.cc:124
std::vector< QwDBInterface > GetDBEntry()
Definition: QwBCM.cc:479
static const double e
Definition: QwUnits.h:91
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 ClearEventData()
Clear the event data in this element.
Definition: QwBCM.cc:62
Bool_t HasValue(TString &vname)
void SetRandomEventParameters(Double_t mean, Double_t sigma)
Definition: QwBCM.cc:93
void UpdateErrorFlag(const VQwBCM *ev_error)
Definition: QwBCM.cc:187
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
void PrintInfo() const
Print multiple lines of information about this data element.
Definition: QwBCM.cc:389
Bool_t ApplySingleEventCuts()
Definition: QwBCM.cc:158
void IncrementErrorCounters()
Definition: QwBCM.cc:174
void ConstructBranch(TTree *tree, TString &prefix)
Definition: QwBCM.cc:434
void Ratio(const VQwBCM &numer, const VQwBCM &denom)
Definition: QwBCM.cc:343
void RandomizeEventData(int helicity=0, double time=0)
Definition: QwBCM.cc:105
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
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
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
virtual const TString & GetElementName() const
Get the name of this element.
Definition: QwBCM.h:34
void DeaccumulateRunningSum(VQwBCM &value)
Definition: QwBCM.cc:379
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
void UseExternalRandomVariable()
Definition: QwBCM.cc:69
T fBeamCurrent
Definition: QwBCM.h:168
Double_t GetValueWidth()
Definition: QwBCM.cc:511