QwAnalysis
QwCombinedPMT.cc
Go to the documentation of this file.
1 
2 #include "QwCombinedPMT.h"
3 
4 // System headers
5 #include <stdexcept>
6 
7 // Qweak headers
8 #include "QwDBInterface.h"
9 
10 void QwCombinedPMT::Add(QwIntegrationPMT* pmt, Double_t weight )
11 {
12  //std::cout<<"QwCombinedPMT: Got "<<pmt->GetElementName()<<" and weight ="<<weight<<"\n";
13  fElement.push_back(pmt);
14  fWeights.push_back(weight);
15 }
16 
17 
18 void QwCombinedPMT::InitializeChannel(TString name, TString datatosave)
19 {
20  SetElementName(name);
21  //SetPedestal(0.);
22  //SetCalibrationFactor(1.);
23  if (datatosave=="raw") fDataToSave=kRaw;
24  else
25  if (datatosave=="derived") fDataToSave=kDerived;
26 
27  fSumADC.InitializeChannel(name, datatosave);
28  SetBlindability(kTRUE);
29  return;
30 }
31 
32 void QwCombinedPMT::InitializeChannel(TString subsystemname, TString name, TString datatosave)
33 {
34  SetElementName(name);
35  //SetPedestal(0.);
36  //SetCalibrationFactor(1.);
37  if (datatosave=="raw") fDataToSave=kRaw;
38  else
39  if (datatosave=="derived") fDataToSave=kDerived;
40 
41  fSumADC.InitializeChannel(subsystemname, "QwCombinedPMT", name, datatosave);
42  SetBlindability(kTRUE);
43 
44  return;
45 }
46 
47 void QwCombinedPMT::LinkChannel(TString name)
48 {
49  Bool_t local_debug = false;
50  SetElementName(name);
51 // TString sumstr = name+TString("_sum");
52  TString sumstr = name+TString("");
53  fSumADC.SetElementName(sumstr);
54 // TString avgstr = name+TString("_avg");
55 // fAvgADC.SetElementName(avgstr);
56  if(local_debug) std::cout<<"linked combined PMT channel "<< GetElementName()<<std::endl;
57 }
58 
60 {
62 // fAvgADC.ClearEventData();
63 }
64 
65 
66 void QwCombinedPMT::SetHardwareSum(Double_t hwsum, UInt_t sequencenumber)
67 {
68 
69 }
70 
71 void QwCombinedPMT::SetEventData(Double_t* block, UInt_t sequencenumber)
72 {
73  fSumADC.SetEventData(block, sequencenumber);
74 // fAvgADC.SetEventData(block, sequencenumber);
75 }
76 
78 {
79 
80  Bool_t ldebug = kFALSE;
81  Double_t total_weights=0.0;
82 
84  static QwIntegrationPMT tmpADC("tmpADC");
85 
86  for (size_t i=0;i<fElement.size();i++)
87  {
88  //std::cout<<"=========fElement["<<i<<"]=========="<<std::endl;
89  //fElement[i]->Print();
90  tmpADC = *(fElement[i]);
91  //std::cout<<"=========tmpADC========="<<std::endl;
92  //tmpADC->Print();
93  tmpADC.Scale(fWeights[i]);
94  fSumADC += tmpADC;
95  total_weights += fWeights[i];
96  }
97 
98 // fAvgADC = fSumADC;
99 // if (total_weights!=0.0)
100 // fAvgADC.Scale(1/total_weights);
101 
102  if (total_weights!=0.0)
103  fSumADC.Scale(1/total_weights);
104 
105 
106  if (ldebug)
107  {
108  std::cout<<"QwCombinedPMT::CalculateAverage()"<<std::endl;
109 // fAvgADC.PrintInfo();
110  fSumADC.PrintInfo();
111 
112 // std::cout<<"QwCombinedPMT: "<<GetElementName()
113 // <<"\nweighted average of hardware sums = "<<fAvgADC.GetValue()<<"\n";
114  std::cout<<"QwCombinedPMT: "<<GetElementName()
115  <<"\nweighted average of hardware sums = "<<fSumADC.GetValue()<<"\n";
116 
117  for (size_t i=0;i<4;i++)
118  {
119  std::cout<<"weighted average of block["<<i<<"] = "<<fSumADC.GetValue(i+1)<<"\n";
120  }
121  }
122 
123 }
124 
125 /********************************************************/
127 {
128  Bool_t eventokay=kTRUE;
129 
130 
131  return eventokay;
132 }
133 /********************************************************/
134 
135 void QwCombinedPMT::SetSingleEventCuts(UInt_t errorflag, Double_t LL=0, Double_t UL=0, Double_t stability=0){
136  //set the unique tag to identify device type (Int.PMT & Comb. PMT)
137  //errorflag|=kPMTErrorFlag;
138  QwMessage<<"QwCombinedPMT Error Code passing to QwIntegrationPMT "<<errorflag<<QwLog::endl;
139  fSumADC.SetSingleEventCuts(errorflag,LL,UL,stability);
140 
141 }
142 
143 
145 {
146 //Calculate the weigted averages of the hardware sum and each of the four blocks.
148  //fSumADC.ProcessEvent(); //This is not necessary for combined devices-Rakitha 11-15-2010
149 
150  return;
151 }
152 
153 
154 void QwCombinedPMT::SetDefaultSampleSize(Int_t sample_size)
155 {
156  fSumADC.SetDefaultSampleSize((size_t)sample_size);
157 }
158 
159 // report number of events failed due to HW and event cut faliure
161 {
163 }
164 
165 /********************************************************/
167 {
168  for (size_t i=0;i<fElement.size();i++) {
170  }
171  return GetEventcutErrorFlag();
172 }
173 
174 /********************************************************/
176  try {
177  if(typeid(*ev_error)==typeid(*this)) {
178  // std::cout<<" Here in QwCombinedPMT::UpdateErrorFlag \n";
179  if (this->GetElementName()!="") {
180  fSumADC.UpdateErrorFlag(&(ev_error->fSumADC));
181  }
182  } else {
183  TString loc="Standard exception from QwCombinedPMT::UpdateErrorFlag :"+
184  ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
185  +"same type";
186  throw std::invalid_argument(loc.Data());
187  }
188  } catch (std::exception& e) {
189  std::cerr<< e.what()<<std::endl;
190  }
191 };
192 
193 
194 /********************************************************/
196  return fSumADC.ApplySingleEventCuts();
197 }
198 
199 /********************************************************/
200 
201 Int_t QwCombinedPMT::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement)
202 {
203  return 0;
204 }
205 
206 
208 {
209  //std::cout<<"Calling QwCombinedPMT::operator="<<std::endl;
210  if ( (GetElementName()!="") && (this->fElement.size()==value.fElement.size()) )
211  {
212  for (size_t i=0; i<value.fElement.size(); i++)
213  {
214  //std::cout<<"value.fWeight["<<i<<"]="<<value.fWeights[i]<<std::endl;
215  //std::cout<<"=========value.fElement["<<i<<"]=========="<<std::endl;
216  //value.fElement[i]->Print();
217  (this->fElement[i]) = (value.fElement[i]);
218  this->fWeights[i] = value.fWeights[i];
219  //std::cout<<"this->fWeight["<<i<<"]="<<fWeights[i]<<std::endl;
220  //std::cout<<"=========this->fElement["<<i<<"]=========="<<std::endl;
221  //fElement[i]->Print();
222  }
223 
224  this->fSumADC=value.fSumADC;
225 // this->fAvgADC=value.fAvgADC;
226 
227  //std::cout<<"value.fSumADC"<<std::endl;
228  //value.fSumADC.Print();
229  //std::cout<<"this->fSumADC"<<std::endl;
230  //fSumADC.Print();
231  }
232 
233  return *this;
234 }
235 
237 {
238  //std::cout<<"Calling QwCombinedPMT::operator+="<<std::endl;
239  if ( (GetElementName()!="") && (this->fElement.size()==value.fElement.size()) )
240  {
241  for (size_t i=0; i<value.fElement.size(); i++)
242  {
243  *(this->fElement[i]) += *(value.fElement[i]);
244  this->fWeights[i] += value.fWeights[i];
245  }
246 
247  this->fSumADC+=value.fSumADC;
248 // this->fAvgADC+=value.fAvgADC;
249  }
250 
251  return *this;
252 }
253 
255 {
256  //std::cout<<"Calling QwCombinedPMT::operator-="<<std::endl;
257  if ( (GetElementName()!="") && (this->fElement.size()==value.fElement.size()) )
258  {
259  for (size_t i=0; i<value.fElement.size(); i++)
260  {
261  *(this->fElement[i]) -= *(value.fElement[i]);
262  this->fWeights[i] -= value.fWeights[i];
263  }
264 
265  this->fSumADC-=value.fSumADC;
266 // this->fAvgADC-=value.fAvgADC;
267  //value.fSumADC.Print();
268  //fSumADC.Print();
269  }
270 
271  return *this;
272 }
273 
275 {
276  //std::cout<<"Calling QwCombinedPMT::Sum"<<std::endl;
277  this->fSumADC = value1.fSumADC;
278 // this->fAvgADC = value1.fAvgADC;
279  this->fSumADC += value2.fSumADC;
280 // this->fAvgADC += value2.fAvgADC;
281 }
282 
284 {
286 }
287 
289 {
291 }
292 
293 
295 {
296  //std::cout<<"Calling QwCombinedPMT::Difference="<<std::endl;
297  this->fSumADC = value1.fSumADC;
298 // this->fAvgADC = value1.fAvgADC;
299  this->fSumADC -= value2.fSumADC;
300 // this->fAvgADC -= value2.fAvgADC;
301 }
302 
304 {
305  //std::cout<<"Calling QwCombinedPMT::Ratio"<<std::endl;
306  fSumADC.Ratio(numer.fSumADC,denom.fSumADC);
307 // fAvgADC.Ratio(numer.fAvgADC,denom.fAvgADC);
308  return;
309 }
310 
311 void QwCombinedPMT::Scale(Double_t factor)
312 {
313  fSumADC.Scale(factor);
314 // fAvgADC.Scale(factor);
315  return;
316 }
318 {
319  fSumADC.Normalize(denom);
320 
321  return;
322 }
323 
324 
326 {
328 // fAvgADC.CalculateRunningAverage();
329 }
330 
331 void QwCombinedPMT::Blind(const QwBlinder *blinder)
332 {
333  fSumADC.Blind(blinder);
334 // fAvgADC.Blind(blinder);
335 }
336 
337 void QwCombinedPMT::Blind(const QwBlinder *blinder, const QwCombinedPMT& yield)
338 {
339  fSumADC.Blind(blinder, yield.fSumADC);
340 // fAvgADC.Blind(blinder, yield.fAvgADC);
341 }
342 
344 {
346 // fAvgADC.PrintValue();
347 }
348 
350 {
351  fSumADC.PrintInfo();
352 // fAvgADC.PrintInfo();
353 }
354 
355 
356 void QwCombinedPMT::ConstructHistograms(TDirectory *folder, TString &prefix)
357 {
358  if (GetElementName()=="")
359  {
360  // This channel is not used, so skip filling the histograms.
361  }
362  else
363  {
364  TString sumprefix = prefix+TString("");
365  fSumADC.ConstructHistograms(folder, sumprefix);
366 // TString avgprefix = prefix+TString("");
367 // fAvgADC.ConstructHistograms(folder, avgprefix);
368  }
369  return;
370 
371 }
372 
374 {
375  if (GetElementName()=="")
376  {
377  // This channel is not used, so skip filling the histograms.
378  }
379  else
380  {
382 // fAvgADC.FillHistograms();
383  }
384 
385 
386  return;
387 }
388 
389 void QwCombinedPMT::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
390 {
391  if (GetElementName()=="")
392  {
393  // This channel is not used, so skip
394  }
395  else
396  {
397  TString sumprefix = prefix+"";
398  fSumADC.ConstructBranchAndVector(tree, sumprefix,values);
399 
400  }
401  return;
402 }
403 
404 void QwCombinedPMT::ConstructBranch(TTree *tree, TString &prefix)
405 {
406  if (GetElementName()=="")
407  {
408  // This channel is not used, so skip
409  }
410  else
411  {
412  TString sumprefix = prefix+"";
413  fSumADC.ConstructBranch(tree, sumprefix);
414  }
415  return;
416 }
417 
418 void QwCombinedPMT::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile &modulelist)
419 {
420  TString devicename;
421  devicename=GetElementName();
422  devicename.ToLower();
423  if (GetElementName()=="")
424  {
425  // This channel is not used, so skip
426  }
427  else
428  {
429  if (modulelist.HasValue(devicename)){
430  TString sumprefix = prefix+"";
431  fSumADC.ConstructBranch(tree, sumprefix);
432  QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
433  }
434  }
435  return;
436 }
437 
438 
439 void QwCombinedPMT::FillTreeVector(std::vector<Double_t> &values) const
440 {
441  if (GetElementName()=="") {
442  // This channel is not used, so skip filling the histograms.
443  } else {
444  fSumADC.FillTreeVector(values);
445 // fAvgADC.FillTreeVector(values);
446  }
447 }
448 
449 /********************************************************/
450 std::vector<QwDBInterface> QwCombinedPMT::GetDBEntry()
451 {
452  return fSumADC.GetDBEntry();
453 }
454 
455 std::vector<QwErrDBInterface> QwCombinedPMT::GetErrDBEntry()
456 {
457  return fSumADC.GetErrDBEntry();
458 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
std::vector< QwDBInterface > GetDBEntry()
void ClearEventData()
Clear the event data in this element.
Bool_t ApplySingleEventCuts()
void AccumulateRunningSum(const QwIntegrationPMT &value)
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
QwCombinedPMT & operator-=(const QwCombinedPMT &value)
void InitializeChannel(TString name, TString datatosave)
void AccumulateRunningSum(const QwCombinedPMT &value)
void Scale(Double_t factor)
void Normalize(VQwDataElement *denom)
void SetSingleEventCuts(UInt_t errorflag, Double_t LL, Double_t UL, Double_t stability)
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel.
Class for blinding data, adapted from G0 blinder class.
Definition: QwBlinder.h:64
void PrintValue() const
Print single line of value and error of this data element.
void ClearEventData()
Clear the event data in this element.
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
void Scale(Double_t factor)
void SetEventData(Double_t *block, UInt_t sequencenumber)
void FillHistograms()
Fill the histograms for this data element.
void DeaccumulateRunningSum(QwCombinedPMT &value)
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
static const double e
Definition: QwUnits.h:91
void InitializeChannel(TString name, TString datatosave)
void Ratio(QwIntegrationPMT &numer, QwIntegrationPMT &denom)
void Ratio(QwCombinedPMT &numer, QwCombinedPMT &denom)
void ConstructBranch(TTree *tree, TString &prefix)
void Normalize(VQwDataElement *denom)
void SetDefaultSampleSize(Int_t sample_size)
void LinkChannel(TString name)
void Difference(QwCombinedPMT &value1, QwCombinedPMT &value2)
void FillHistograms()
Fill the histograms for this data element.
Bool_t HasValue(TString &vname)
void CalculateRunningAverage()
The pure virtual base class of all data elements.
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0)
Process the CODA event buffer for this element.
void Blind(const QwBlinder *blinder)
Blind the asymmetry.
void PrintErrorCounters()
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
void PrintValue() const
Print single line of value and error of this data element.
std::vector< QwDBInterface > GetDBEntry()
Int_t SetSingleEventCuts(Double_t, Double_t)
void SetBlindability(Bool_t isblindable)
void SetElementName(const TString &name)
Set the name of this element.
std::vector< QwIntegrationPMT * > fElement
used to validate sequence number in the IsGoodEvent()
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
Bool_t ApplyHWChecks()
void DeaccumulateRunningSum(QwIntegrationPMT &value)
void Blind(const QwBlinder *blinder)
Blind the asymmetry.
void SetEventData(Double_t *block, UInt_t sequencenumber)
UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
Definition: QwCombinedPMT.h:81
void FillTreeVector(std::vector< Double_t > &values) const
QwCombinedPMT & operator=(const QwCombinedPMT &value)
QwIntegrationPMT fSumADC
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
std::vector< Double_t > fWeights
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void CalculateSumAndAverage()
virtual const TString & GetElementName() const
Get the name of this element.
Bool_t ApplySingleEventCuts()
std::vector< QwErrDBInterface > GetErrDBEntry()
void ConstructBranch(TTree *tree, TString &prefix)
void SetElementName(const TString &name)
std::vector< QwErrDBInterface > GetErrDBEntry()
void FillTreeVector(std::vector< Double_t > &values) const
void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber=0)
void PrintInfo() const
Print multiple lines of information about this data element.
void Add(QwIntegrationPMT *pmt, Double_t weight)
void SetDefaultSampleSize(Int_t sample_size)
void Sum(QwCombinedPMT &value1, QwCombinedPMT &value2)
QwCombinedPMT & operator+=(const QwCombinedPMT &value)
void PrintInfo() const
Print multiple lines of information about this data element.