QwAnalysis
QwIntegratedRasterChannel.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwIntegratedRasterChannel.h *
3 * *
4 * Author: *
5 * Time-stamp: *
6 \**********************************************************/
7 
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>
23 {
24  fPedestal=pedestal;
25  fTriumf_ADC.SetPedestal(fPedestal);
26  return;
27 }
28 
29 template<typename T>
31 {
32  fCalibration=calib;
33  fTriumf_ADC.SetCalibrationFactor(fCalibration);
34  return;
35 }
36 /********************************************************/
37 template<typename T>
38 void QwIntegratedRasterChannel<T>::InitializeChannel(TString name, TString datatosave)
39 {
40  SetPedestal(0.);
41  SetCalibrationFactor(1.);
42  fTriumf_ADC.InitializeChannel(name,datatosave);
43  SetElementName(name);
44  //set default limits to event cuts
45  fLLimit=0;//init two timits
46  fULimit=0;//init two timits
47  return;
48 }
49 /********************************************************/
50 template<typename T>
51 void QwIntegratedRasterChannel<T>::InitializeChannel(TString subsystem, TString name, TString datatosave){
52  SetPedestal(0.);
53  SetCalibrationFactor(1.);
54  fTriumf_ADC.InitializeChannel(subsystem, "QwIntegratedRasterChannel", name, datatosave);
55  SetElementName(name);
56  //set default limits to event cuts
57  fLLimit=0;//init two timits
58  fULimit=0;//init two timits
59  return;
60 }
61 /********************************************************/
62 template<typename T>
64 {
65  fTriumf_ADC.ClearEventData();
66  return;
67 }
68 
69 
70 /********************************************************/
71 template<typename T>
73 {
74  fTriumf_ADC.UseExternalRandomVariable();
75  return;
76 }
77 /********************************************************/
78 template<typename T>
80 {
81  fTriumf_ADC.SetExternalRandomVariable(random_variable);
82  return;
83 }
84 /********************************************************/
85 template<typename T>
86 void QwIntegratedRasterChannel<T>::SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
87 {
88  fTriumf_ADC.SetRandomEventDriftParameters(amplitude, phase, frequency);
89  return;
90 }
91 /********************************************************/
92 template<typename T>
93 void QwIntegratedRasterChannel<T>::AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
94 {
95  fTriumf_ADC.AddRandomEventDriftParameters(amplitude, phase, frequency);
96  return;
97 }
98 /********************************************************/
99 template<typename T>
101 {
102  fTriumf_ADC.SetRandomEventParameters(mean, sigma);
103  return;
104 }
105 /********************************************************/
106 template<typename T>
108 {
109  fTriumf_ADC.SetRandomEventAsymmetry(asymmetry);
110  return;
111 }
112 /********************************************************/
113 template<typename T>
115 {
116  fTriumf_ADC.RandomizeEventData(helicity, time);
117  return;
118 }
119 /********************************************************/
120 template<typename T>
121 void QwIntegratedRasterChannel<T>::SetHardwareSum(Double_t hwsum, UInt_t sequencenumber)
122 {
123  fTriumf_ADC.SetHardwareSum(hwsum, sequencenumber);
124  return;
125 }
126 /********************************************************/
127 template<typename T>
128 void QwIntegratedRasterChannel<T>::SetEventData(Double_t* block, UInt_t sequencenumber)
129 {
130  fTriumf_ADC.SetEventData(block, sequencenumber);
131  return;
132 }
133 /********************************************************/
134 template<typename T>
135 void QwIntegratedRasterChannel<T>::EncodeEventData(std::vector<UInt_t> &buffer)
136 {
137  fTriumf_ADC.EncodeEventData(buffer);
138 }
139 /********************************************************/
140 template<typename T>
142 {
143  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.
144  fTriumf_ADC.ProcessEvent();
145  return;
146 }
147 /********************************************************/
148 template<typename T>
150 {
151  Bool_t fEventIsGood=kTRUE;
152 
153  fDeviceErrorCode=fTriumf_ADC.ApplyHWChecks();//will check for HW consistancy and return the error code (=0 is HW good)
154  fEventIsGood=(fDeviceErrorCode & 0x0);//if no HW error return true
155 
156 
157  return fEventIsGood;
158 }
159 /********************************************************/
160 
161 template<typename T>
162 Int_t QwIntegratedRasterChannel<T>::SetSingleEventCuts(Double_t LL, Double_t UL){
163  fTriumf_ADC.SetSingleEventCuts(LL,UL);
164  return 1;
165 }
166 
167 /********************************************************/
168 
169 template<typename T>
170 void QwIntegratedRasterChannel<T>::SetSingleEventCuts(UInt_t errorflag, Double_t LL, Double_t UL, Double_t stability){
171  //set the unique tag to identify device type (bcm,bpm & etc)
172  //errorflag|=kBCMErrorFlag;
173  QwMessage<<"QwIntegratedRasterChannel<T> Error Code passing to QwVQWK_Ch "<<errorflag<<QwLog::endl;
174  fTriumf_ADC.SetSingleEventCuts(errorflag,LL,UL,stability);
175 
176 }
177 
178 template<typename T>
180  fTriumf_ADC.SetDefaultSampleSize((size_t)sample_size);
181 }
182 
183 
184 /********************************************************/
185 template<typename T>
187  //std::cout<<" QwIntegratedRasterChannel<T>::SingleEventCuts() "<<std::endl;
188  Bool_t status=kTRUE;
189 
190 
191  if (fTriumf_ADC.ApplySingleEventCuts()){
192  status=kTRUE;
193  }
194  else{
195 
196  if (bDEBUG) std::cout<<" evnt cut failed:-> set limit "<<fULimit;
197  status&=kFALSE;
198  }
199  fDeviceErrorCode|=fTriumf_ADC.GetEventcutErrorFlag();//retrun the error flag for event cuts
200 
201 
202  return status;
203 
204 }
205 
206 /********************************************************/
207 
208 template<typename T>
209 void QwIntegratedRasterChannel<T>::PrintErrorCounters() const{// report number of events failed due to HW and event cut faliure
210  fTriumf_ADC.PrintErrorCounters();
211 }
212 
213 
214 
215 template<typename T>
216 Int_t QwIntegratedRasterChannel<T>::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement)
217 {
218  fTriumf_ADC.ProcessEvBuffer(buffer,word_position_in_buffer);
219 
220  return word_position_in_buffer;
221 }
222 /********************************************************/
223 template<typename T>
225 {
226 // std::cout<<" Here in QwIntegratedRasterChannel<T>::operator= \n";
227  if (GetElementName()!="")
228  {
229  this->fTriumf_ADC=value.fTriumf_ADC;
230  this->fPedestal=value.fPedestal;
231  this->fCalibration=value.fCalibration;
232  }
233 // std::cout<<" to be copied \n";
234 // value.Print();
235 // std::cout<<" copied \n";
236 // this->Print();
237 
238  return *this;
239 }
240 
241 template<typename T>
243 {
244  if (GetElementName()!="")
245  {
246  this->fTriumf_ADC+=value.fTriumf_ADC;
247  this->fPedestal+=value.fPedestal;
248  this->fCalibration=0;
249  }
250  return *this;
251 }
252 
253 template<typename T>
255 {
256  if (GetElementName()!="")
257  {
258  this->fTriumf_ADC-=value.fTriumf_ADC;
259  this->fPedestal-=value.fPedestal;
260  this->fCalibration=0;
261  }
262  return *this;
263 }
264 
265 
266 template<typename T>
268  *this = value1;
269  *this += value2;
270 }
271 
272 template<typename T>
274  *this = value1;
275  *this -= value2;
276 }
277 
278 template<typename T>
280 {
281  *this = numer;
282  return;
283 }
284 
285 template<typename T>
287 {
288  fTriumf_ADC.Scale(factor);
289  return;
290 }
291 
292 template<typename T>
294  fTriumf_ADC.CalculateRunningAverage();
295 }
296 
297 template<typename T>
299  fTriumf_ADC.AccumulateRunningSum(value.fTriumf_ADC);
300 }
301 
302 
303 template<typename T>
305 {
306  fTriumf_ADC.PrintValue();
307 }
308 
309 template<typename T>
311 {
312  std::cout << "QwVQWK_Channel Info " << std::endl;
313  fTriumf_ADC.PrintInfo();
314 }
315 
316 /********************************************************/
317 template<typename T>
318 void QwIntegratedRasterChannel<T>::ConstructHistograms(TDirectory *folder, TString &prefix)
319 {
320  if (GetElementName()=="")
321  {
322  // This channel is not used, so skip filling the histograms.
323  }
324  else
325  {
326  fTriumf_ADC.ConstructHistograms(folder, prefix);
327  }
328  return;
329 }
330 
331 template<typename T>
333 {
334  if (GetElementName()=="")
335  {
336  // This channel is not used, so skip filling the histograms.
337  }
338  else
339  {
340  fTriumf_ADC.FillHistograms();
341  }
342 
343 
344  return;
345 }
346 
347 template<typename T>
348 void QwIntegratedRasterChannel<T>::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
349 {
350  if (GetElementName()==""){
351  // This channel is not used, so skip
352  } else
353  {
354  TString thisprefix=prefix;
355  if(prefix=="asym_"){
356  if (GetElementName()=="qwk_raster_x"||GetElementName()=="qwk_raster_y"||GetElementName()=="qwk_raster_sumxy") thisprefix="diff_";
357  }
358  fTriumf_ADC.ConstructBranchAndVector(tree, thisprefix,values);
359  }
360  return;
361 }
362 
363 template<typename T>
364 void QwIntegratedRasterChannel<T>::ConstructBranch(TTree *tree, TString &prefix)
365 {
366  if (GetElementName()==""){
367  // This channel is not used, so skip filling the histograms.
368  } else
369  {
370  fTriumf_ADC.ConstructBranch(tree, prefix);
371  // this functions doesn't do anything yet
372  }
373  return;
374 }
375 
376 template<typename T>
377 void QwIntegratedRasterChannel<T>::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist)
378 {
379  TString devicename;
380 
381  devicename=GetElementName();
382  devicename.ToLower();
383  if (GetElementName()==""){
384  // This channel is not used, so skip filling the histograms.
385  } else
386  {
387 
388  //QwMessage <<" QwIntegratedRasterChannel<T> "<<devicename<<QwLog::endl;
389  if (modulelist.HasValue(devicename)){
390  fTriumf_ADC.ConstructBranch(tree, prefix);
391  QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
392  }
393  // this functions doesn't do anything yet
394  }
395  return;
396 }
397 
398 template<typename T>
399 void QwIntegratedRasterChannel<T>::FillTreeVector(std::vector<Double_t> &values) const
400 {
401  if (GetElementName()==""){
402  // This channel is not used, so skip filling the histograms.
403  } else
404  {
405  fTriumf_ADC.FillTreeVector(values);
406  // this functions doesn't do anything yet
407  }
408  return;
409 }
410 
411 template<typename T>
412 std::vector<QwDBInterface> QwIntegratedRasterChannel<T>::GetDBEntry()
413 {
414  std::vector <QwDBInterface> row_list;
415  fTriumf_ADC.AddEntriesToList(row_list);
416  return row_list;
417 }
418 
419 
420 template<typename T>
421 std::vector<QwErrDBInterface> QwIntegratedRasterChannel<T>::GetErrDBEntry()
422 {
423  std::vector <QwErrDBInterface> row_list;
424  fTriumf_ADC.AddErrEntriesToList(row_list);
425  return row_list;
426 }
427 
428 
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
QwIntegratedRasterChannel & operator=(const QwIntegratedRasterChannel &value)
Double_t fULimit
void EncodeEventData(std::vector< UInt_t > &buffer)
void FillHistograms()
Fill the histograms for this data element.
void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
QwIntegratedRasterChannel & operator-=(const QwIntegratedRasterChannel &value)
void SetCalibrationFactor(Double_t calib)
QwIntegratedRasterChannel & operator+=(const QwIntegratedRasterChannel &value)
void SetDefaultSampleSize(Int_t sample_size)
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
void AccumulateRunningSum(const QwIntegratedRasterChannel &value)
void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0)
Process the CODA event buffer for this element.
std::vector< QwErrDBInterface > GetErrDBEntry()
void FillTreeVector(std::vector< Double_t > &values) const
void SetRandomEventParameters(Double_t mean, Double_t sigma)
void Difference(QwIntegratedRasterChannel &value1, QwIntegratedRasterChannel &value2)
Bool_t HasValue(TString &vname)
void ConstructBranch(TTree *tree, TString &prefix)
void RandomizeEventData(int helicity=0, double time=0)
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Int_t SetSingleEventCuts(Double_t mean=0, Double_t sigma=0)
void SetExternalRandomVariable(Double_t random_variable)
void Sum(QwIntegratedRasterChannel &value1, QwIntegratedRasterChannel &value2)
void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber=0)
Double_t fLLimit
void SetEventData(Double_t *block, UInt_t sequencenumber)
void SetRandomEventAsymmetry(Double_t asymmetry)
std::vector< QwDBInterface > GetDBEntry()
void PrintValue() const
Print single line of value and error of this data element.
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
void Ratio(QwIntegratedRasterChannel &numer, QwIntegratedRasterChannel &denom)
void InitializeChannel(TString name, TString datatosave)
void ClearEventData()
Clear the event data in this element.
void PrintInfo() const
Print multiple lines of information about this data element.