JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwCombinedPMT.cc
Go to the documentation of this file.
1
2/*!
3 * \file QwCombinedPMT.cc
4 * \brief Combined PMT detector implementation using Moller ADC channels
5 */
6
7#include "QwCombinedPMT.h"
8
9// System headers
10#include <stdexcept>
11
12// ROOT headers
13#include "ROOT/RNTupleModel.hxx"
14#include "ROOT/RField.hxx"
15
16// Qweak headers
17#ifdef __USE_DATABASE__
18#include "QwDBInterface.h"
19#endif
20
21/**
22 * \brief Add a PMT channel to this combination with a weight.
23 * \param pmt Pointer to the PMT to include.
24 * \param weight Weight applied to the PMT in the sum/average.
25 */
26void QwCombinedPMT::Add(QwIntegrationPMT* pmt, Double_t weight )
27{
28 //std::cout<<"QwCombinedPMT: Got "<<pmt->GetElementName()<<" and weight ="<<weight<<"\n";
29 fElement.push_back(pmt);
30 fWeights.push_back(weight);
31}
32
33
34/**
35 * \brief Initialize the combined PMT with a name and data-saving mode.
36 * \param name Detector name used for branches and histograms.
37 * \param datatosave Storage mode (e.g., "raw" or "derived").
38 */
39void QwCombinedPMT::InitializeChannel(TString name, TString datatosave)
40{
41 SetElementName(name);
42 //SetPedestal(0.);
43 //SetCalibrationFactor(1.);
44 if (datatosave=="raw") fDataToSave=kRaw;
45 else
46 if (datatosave=="derived") fDataToSave=kDerived;
47
48 fSumADC.InitializeChannel(name, datatosave);
49 SetBlindability(kTRUE);
50 return;
51}
52
53/**
54 * \brief Initialize the combined PMT with subsystem and name.
55 * \param subsystemname Subsystem identifier.
56 * \param name Detector name used for branches and histograms.
57 * \param datatosave Storage mode (e.g., "raw" or "derived").
58 */
59void QwCombinedPMT::InitializeChannel(TString subsystemname, TString name, TString datatosave)
60{
61 SetElementName(name);
62 //SetPedestal(0.);
63 //SetCalibrationFactor(1.);
64 if (datatosave=="raw") fDataToSave=kRaw;
65 else
66 if (datatosave=="derived") fDataToSave=kDerived;
67
68 fSumADC.InitializeChannel(subsystemname, "QwCombinedPMT", name, datatosave);
69 SetBlindability(kTRUE);
70
71 return;
72}
73
74/** \brief Link internal sum channel names to the given detector name. */
76{
77 Bool_t local_debug = false;
78 SetElementName(name);
79// TString sumstr = name+TString("_sum");
80 TString sumstr = name+TString("");
81 fSumADC.SetElementName(sumstr);
82// TString avgstr = name+TString("_avg");
83// fAvgADC.SetElementName(avgstr);
84 if(local_debug) std::cout<<"linked combined PMT channel "<< GetElementName()<<std::endl;
85}
86
87/** \brief Clear event-scoped data for the sum channel. */
89{
90 fSumADC.ClearEventData();
91// fAvgADC.ClearEventData();
92}
93
94
95/** \brief Set the hardware-level sum for a sequence (unused for combo). */
96void QwCombinedPMT::SetHardwareSum(Double_t hwsum, UInt_t sequencenumber)
97{
98
99}
100
101/** \brief Set the block data for the current event sequence. */
102void QwCombinedPMT::SetEventData(Double_t* block, UInt_t sequencenumber)
103{
104 fSumADC.SetEventData(block, sequencenumber);
105// fAvgADC.SetEventData(block, sequencenumber);
106}
107
108/** \brief Compute the weighted sum (and average) from member PMTs. */
110{
111
112 Bool_t ldebug = kFALSE;
113 Double_t total_weights=0.0;
114
115 fSumADC.ClearEventData();
116 static QwIntegrationPMT tmpADC("tmpADC");
117
118 for (size_t i=0;i<fElement.size();i++)
119 {
120 //std::cout<<"=========fElement["<<i<<"]=========="<<std::endl;
121 //fElement[i]->Print();
122 tmpADC = *(fElement[i]);
123 //std::cout<<"=========tmpADC========="<<std::endl;
124 //tmpADC->Print();
125 tmpADC.Scale(fWeights[i]);
126 fSumADC += tmpADC;
127 total_weights += fWeights[i];
128 }
129
130// fAvgADC = fSumADC;
131// if (total_weights!=0.0)
132// fAvgADC.Scale(1/total_weights);
133
134 if (total_weights!=0.0)
135 fSumADC.Scale(1/total_weights);
136
137
138 if (ldebug)
139 {
140 std::cout<<"QwCombinedPMT::CalculateAverage()"<<std::endl;
141// fAvgADC.PrintInfo();
142 fSumADC.PrintInfo();
143
144// std::cout<<"QwCombinedPMT: "<<GetElementName()
145// <<"\nweighted average of hardware sums = "<<fAvgADC.GetValue()<<"\n";
146 std::cout<<"QwCombinedPMT: "<<GetElementName()
147 <<"\nweighted average of hardware sums = "<<fSumADC.GetValue()<<"\n";
148
149 for (size_t i=0;i<4;i++)
150 {
151 std::cout<<"weighted average of block["<<i<<"] = "<<fSumADC.GetValue(i+1)<<"\n";
152 }
153 }
154
155}
156
157/********************************************************/
158/** \brief Apply hardware checks (none needed at combiner level). */
160{
161 Bool_t eventokay=kTRUE;
162
163
164 return eventokay;
165}
166/********************************************************/
167
168/** \brief Configure detailed single-event cuts forwarded to the sum ADC. */
169void QwCombinedPMT::SetSingleEventCuts(UInt_t errorflag, Double_t LL=0, Double_t UL=0, Double_t stability=0, Double_t burplevel=0){
170 //set the unique tag to identify device type (Int.PMT & Comb. PMT)
171 //errorflag|=kPMTErrorFlag;
172 QwMessage<<"QwCombinedPMT Error Code passing to QwIntegrationPMT "<<errorflag<<QwLog::endl;
173 fSumADC.SetSingleEventCuts(errorflag,LL,UL,stability,burplevel);
174
175}
176
177
178/** \brief Process event by computing the weighted average of members. */
180{
181//Calculate the weigted averages of the hardware sum and each of the four blocks.
183 //fSumADC.ProcessEvent(); //This is not necessary for combined devices-Rakitha 11-15-2010
184
185 return;
186}
187
188
189/** \brief Set default sample size on the sum ADC. */
191{
192 fSumADC.SetDefaultSampleSize((size_t)sample_size);
193}
194
195// report number of events failed due to HW and event cut failure
196/** \brief Print error counters aggregated by the sum ADC. */
198{
199 fSumADC.PrintErrorCounters();
200}
201/*********************************************************/
202/**
203 * \brief Check for burp failures by delegating to the sum ADC channel.
204 * \param ev_error Reference combined PMT to compare against.
205 * \return kTRUE if a burp failure was detected; otherwise kFALSE.
206 */
208 Bool_t burpstatus = kFALSE;
209 try {
210 if(typeid(*ev_error)==typeid(*this)) {
211 //std::cout<<" Here in QwCombinedPMT::CheckForBurpFail \n";
212 if (this->GetElementName()!="") {
213 const QwCombinedPMT* value_pmt = dynamic_cast<const QwCombinedPMT* >(ev_error);
214 burpstatus |= fSumADC.CheckForBurpFail(&(value_pmt->fSumADC));
215 }
216 } else {
217 TString loc="Standard exception from QwCombinedPMT::CheckForBurpFail :"+
218 ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
219 +"same type";
220 throw std::invalid_argument(loc.Data());
221 }
222 } catch (std::exception& e) {
223 std::cerr<< e.what()<<std::endl;
224 }
225 return burpstatus;
226};
227
228
229/********************************************************/
230/** \brief Update the sum ADC error flag from member PMTs. */
232{
233 for (size_t i=0;i<fElement.size();i++) {
234 fSumADC.UpdateErrorFlag(fElement[i]);
235 }
236 return GetEventcutErrorFlag();
237}
238
239/********************************************************/
240/** \brief Merge error flags from a reference combined PMT. */
242 try {
243 if(typeid(*ev_error)==typeid(*this)) {
244 // std::cout<<" Here in QwCombinedPMT::UpdateErrorFlag \n";
245 if (this->GetElementName()!="") {
246 fSumADC.UpdateErrorFlag(&(ev_error->fSumADC));
247 }
248 } else {
249 TString loc="Standard exception from QwCombinedPMT::UpdateErrorFlag :"+
250 ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
251 +"same type";
252 throw std::invalid_argument(loc.Data());
253 }
254 } catch (std::exception& e) {
255 std::cerr<< e.what()<<std::endl;
256 }
257};
258
259
260/********************************************************/
262 return fSumADC.ApplySingleEventCuts();
263}
264
265/********************************************************/
266
267Int_t QwCombinedPMT::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement)
268{
269 return 0;
270}
271
272
274{
275 //std::cout<<"Calling QwCombinedPMT::operator="<<std::endl;
276 if ( (GetElementName()!="") && (this->fElement.size()==value.fElement.size()) )
277 {
278 for (size_t i=0; i<value.fElement.size(); i++)
279 {
280 //std::cout<<"value.fWeight["<<i<<"]="<<value.fWeights[i]<<std::endl;
281 //std::cout<<"=========value.fElement["<<i<<"]=========="<<std::endl;
282 //value.fElement[i]->Print();
283 (this->fElement[i]) = (value.fElement[i]);
284 this->fWeights[i] = value.fWeights[i];
285 //std::cout<<"this->fWeight["<<i<<"]="<<fWeights[i]<<std::endl;
286 //std::cout<<"=========this->fElement["<<i<<"]=========="<<std::endl;
287 //fElement[i]->Print();
288 }
289
290 this->fSumADC=value.fSumADC;
291// this->fAvgADC=value.fAvgADC;
292
293 //std::cout<<"value.fSumADC"<<std::endl;
294 //value.fSumADC.Print();
295 //std::cout<<"this->fSumADC"<<std::endl;
296 //fSumADC.Print();
297 }
298
299 return *this;
300}
301
303{
304 //std::cout<<"Calling QwCombinedPMT::operator+="<<std::endl;
305 if ( (GetElementName()!="") && (this->fElement.size()==value.fElement.size()) )
306 {
307 for (size_t i=0; i<value.fElement.size(); i++)
308 {
309 *(this->fElement[i]) += *(value.fElement[i]);
310 this->fWeights[i] += value.fWeights[i];
311 }
312
313 this->fSumADC+=value.fSumADC;
314// this->fAvgADC+=value.fAvgADC;
315 }
316
317 return *this;
318}
319
321{
322 //std::cout<<"Calling QwCombinedPMT::operator-="<<std::endl;
323 if ( (GetElementName()!="") && (this->fElement.size()==value.fElement.size()) )
324 {
325 for (size_t i=0; i<value.fElement.size(); i++)
326 {
327 *(this->fElement[i]) -= *(value.fElement[i]);
328 this->fWeights[i] -= value.fWeights[i];
329 }
330
331 this->fSumADC-=value.fSumADC;
332// this->fAvgADC-=value.fAvgADC;
333 //value.fSumADC.Print();
334 //fSumADC.Print();
335 }
336
337 return *this;
338}
339
340void QwCombinedPMT::Sum(const QwCombinedPMT &value1, const QwCombinedPMT &value2) {
341 *this = value1;
342 *this += value2;
343}
344
345void QwCombinedPMT::Difference(const QwCombinedPMT &value1, const QwCombinedPMT &value2) {
346 *this = value1;
347 *this -= value2;
348}
349
350void QwCombinedPMT::AccumulateRunningSum(const QwCombinedPMT& value, Int_t count, Int_t ErrorMask)
351{
352 fSumADC.AccumulateRunningSum(value.fSumADC, count, ErrorMask);
353}
354
356{
357 fSumADC.DeaccumulateRunningSum(value.fSumADC, ErrorMask);
358}
359
361{
362 //std::cout<<"Calling QwCombinedPMT::Ratio"<<std::endl;
363 fSumADC.Ratio(numer.fSumADC,denom.fSumADC);
364// fAvgADC.Ratio(numer.fAvgADC,denom.fAvgADC);
365 return;
366}
367
368void QwCombinedPMT::Scale(Double_t factor)
369{
370 fSumADC.Scale(factor);
371// fAvgADC.Scale(factor);
372 return;
373}
375{
376 fSumADC.Normalize(denom);
377
378 return;
379}
380
381
383{
384 fSumADC.CalculateRunningAverage();
385// fAvgADC.CalculateRunningAverage();
386}
387
388void QwCombinedPMT::Blind(const QwBlinder *blinder)
389{
390 fSumADC.Blind(blinder);
391// fAvgADC.Blind(blinder);
392}
393
394void QwCombinedPMT::Blind(const QwBlinder *blinder, const QwCombinedPMT& yield)
395{
396 fSumADC.Blind(blinder, yield.fSumADC);
397// fAvgADC.Blind(blinder, yield.fAvgADC);
398}
399
401{
402 fSumADC.PrintValue();
403// fAvgADC.PrintValue();
404}
405
407{
408 fSumADC.PrintInfo();
409// fAvgADC.PrintInfo();
410}
411
412
413void QwCombinedPMT::ConstructHistograms(TDirectory *folder, TString &prefix)
414{
415 if (GetElementName()=="")
416 {
417 // This channel is not used, so skip filling the histograms.
418 }
419 else
420 {
421 TString sumprefix = prefix+TString("");
422 fSumADC.ConstructHistograms(folder, sumprefix);
423// TString avgprefix = prefix+TString("");
424// fAvgADC.ConstructHistograms(folder, avgprefix);
425 }
426 return;
427
428}
429
431{
432 if (GetElementName()=="")
433 {
434 // This channel is not used, so skip filling the histograms.
435 }
436 else
437 {
438 fSumADC.FillHistograms();
439// fAvgADC.FillHistograms();
440 }
441
442
443 return;
444}
445
446void QwCombinedPMT::ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
447{
448 if (GetElementName()=="")
449 {
450 // This channel is not used, so skip
451 }
452 else
453 {
454 TString sumprefix = prefix+"";
455 fSumADC.ConstructBranchAndVector(tree, sumprefix,values);
456
457 }
458 return;
459}
460
461void QwCombinedPMT::ConstructBranch(TTree *tree, TString &prefix)
462{
463 if (GetElementName()=="")
464 {
465 // This channel is not used, so skip
466 }
467 else
468 {
469 TString sumprefix = prefix+"";
470 fSumADC.ConstructBranch(tree, sumprefix);
471 }
472 return;
473}
474
475void QwCombinedPMT::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile &modulelist)
476{
477 TString devicename;
478 devicename=GetElementName();
479 devicename.ToLower();
480 if (GetElementName()=="")
481 {
482 // This channel is not used, so skip
483 }
484 else
485 {
486 if (modulelist.HasValue(devicename)){
487 TString sumprefix = prefix+"";
488 fSumADC.ConstructBranch(tree, sumprefix);
489 QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
490 }
491 }
492 return;
493}
494
495
497{
498 if (GetElementName()=="") {
499 // This channel is not used, so skip filling the histograms.
500 } else {
501 fSumADC.FillTreeVector(values);
502// fAvgADC.FillTreeVector(values);
503 }
504}
505
506#ifdef HAS_RNTUPLE_SUPPORT
507void QwCombinedPMT::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
508{
509 if (GetElementName()=="")
510 {
511 // This channel is not used, so skip
512 }
513 else
514 {
515 TString sumprefix = prefix+"";
516 fSumADC.ConstructNTupleAndVector(model, sumprefix, values, fieldPtrs);
517 }
518}
519
520void QwCombinedPMT::FillNTupleVector(std::vector<Double_t>& values) const
521{
522 if (GetElementName()=="") {
523 // This channel is not used, so skip filling the RNTuple.
524 } else {
525 fSumADC.FillNTupleVector(values);
526// fAvgADC.FillNTupleVector(values);
527 }
528}
529#endif // HAS_RNTUPLE_SUPPORT
530
531#ifdef __USE_DATABASE__
532/********************************************************/
533std::vector<QwDBInterface> QwCombinedPMT::GetDBEntry()
534{
535 return fSumADC.GetDBEntry();
536}
537
538std::vector<QwErrDBInterface> QwCombinedPMT::GetErrDBEntry()
539{
540 return fSumADC.GetErrDBEntry();
541}
542#endif
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
Database interface for QwIntegrationPMT and subsystems.
Combined PMT detector using Moller ADC channels.
const TString QwBPMStripline< T >::subelement[4]
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Configuration file parser with flexible tokenization and search capabilities.
Bool_t HasValue(TString &vname)
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:53
VQwDataElement()
Default constructor.
virtual const TString & GetElementName() const
Get the name of this element.
void SetElementName(const TString &name)
Set the name of this element.
Data blinding utilities for parity violation analysis.
Definition QwBlinder.h:57
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override
Process the CODA event buffer for this element.
void Sum(const QwCombinedPMT &value1, const QwCombinedPMT &value2)
void FillTreeVector(QwRootTreeBranchVector &values) const
void AccumulateRunningSum(const QwCombinedPMT &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
void PrintInfo() const override
Print multiple lines of information about this data element.
void DeaccumulateRunningSum(QwCombinedPMT &value, Int_t ErrorMask=0xFFFFFFF)
QwCombinedPMT & operator=(const QwCombinedPMT &value)
void Normalize(VQwDataElement *denom)
void ClearEventData() override
Clear event-scoped data for the sum channel.
void CalculateRunningAverage()
void ConstructBranch(TTree *tree, TString &prefix)
void Blind(const QwBlinder *blinder)
Blind the asymmetry.
Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Check for burp failures by delegating to the sum ADC channel.
void ProcessEvent()
Process event by computing the weighted average of members.
void Scale(Double_t factor)
UInt_t UpdateErrorFlag() override
Update the sum ADC error flag from member PMTs.
UInt_t GetEventcutErrorFlag() override
return the error flag on this channel/device
void LinkChannel(TString name)
Link internal sum channel names to the given detector name.
void SetBlindability(Bool_t isblindable)
void PrintErrorCounters()
Bool_t ApplyHWChecks()
Apply hardware checks (none needed at combiner level).
void Ratio(QwCombinedPMT &numer, QwCombinedPMT &denom)
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
void InitializeChannel(TString name, TString datatosave)
Initialize the combined PMT with a name and data-saving mode.
QwIntegrationPMT fSumADC
std::vector< Double_t > fWeights
void PrintValue() const override
Print single line of value and error of this data element.
void SetEventData(Double_t *block, UInt_t sequencenumber)
Set the block data for the current event sequence.
void Difference(const QwCombinedPMT &value1, const QwCombinedPMT &value2)
void Add(QwIntegrationPMT *pmt, Double_t weight)
Add a PMT channel to this combination with a weight.
void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber=0)
Set the hardware-level sum for a sequence (unused for combo).
void SetDefaultSampleSize(Int_t sample_size)
Set default sample size on the sum ADC.
Bool_t ApplySingleEventCuts()
QwCombinedPMT & operator+=(const QwCombinedPMT &value)
std::vector< QwIntegrationPMT * > fElement
used to validate sequence number in the IsGoodEvent()
void CalculateSumAndAverage()
Compute the weighted sum (and average) from member PMTs.
void FillHistograms() override
Fill the histograms for this data element.
std::vector< QwErrDBInterface > GetErrDBEntry()
void SetSingleEventCuts(UInt_t errorflag, Double_t LL, Double_t UL, Double_t stability, Double_t burplevel)
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit),...
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
std::vector< QwDBInterface > GetDBEntry()
QwCombinedPMT & operator-=(const QwCombinedPMT &value)
Integration PMT providing yield/diff/asym readout from Moller ADC.
void Scale(Double_t factor)