QwAnalysis
QwPMT_Channel.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwPMT_Channel.cc *
3 * *
4 * Author: P. M. King *
5 * Time-stamp: <2009-03-07 12:00> *
6 \**********************************************************/
7 
8 #include "QwPMT_Channel.h"
9 
10 // Qweak headers
11 #include "QwLog.h"
12 #include "QwHistogramHelper.h"
13 
14 const Bool_t QwPMT_Channel::kDEBUG = kFALSE;
15 
16 
17 /*! Conversion factor to translate the average bit count in an ADC
18  * channel into average voltage.
19  * The base factor is roughly 76 uV per count, and zero counts corresponds
20  * to zero voltage.
21  * Store as the exact value for 20 V range, 18 bit ADC.
22  */
23 const Double_t QwPMT_Channel::kPMT_VoltsPerBit = (20./(1<<18));
24 
25 
27  fValue = 0;
28 }
29 
30 void QwPMT_Channel::RandomizeEventData(int helicity, int SlotNum, int ChanNum){
31 
32  Double_t mean = 1500.0;
33  Double_t sigma = 300.0;
34  UInt_t fV775Dataword = abs( (Int_t)gRandom->Gaus(mean,sigma) );
35 
36  UInt_t fV775SlotNumber = SlotNum;
37  UInt_t fV775ChannelNumber = ChanNum;
38  const UInt_t fV775DataValidBit = 0x00004000;
39 
40  UInt_t word = fV775Dataword | (fV775SlotNumber<<27);
41  word = word | (fV775ChannelNumber<<16) | fV775DataValidBit;
42  fValue = word;
43 }
44 
45 void QwPMT_Channel::EncodeEventData(std::vector<UInt_t> &TrigBuffer)
46 {
47 // std::cout<<"QwPMT_Channel::EncodeEventData() not fully implemented yet."<<std::endl;
48 
49  Long_t localbuf;
50 
51  if (IsNameEmpty()) {
52  // This channel is not used, but is present in the data stream.
53  // Skip over this data.
54  } else {
55  localbuf = (Long_t) (this->fValue);
56  TrigBuffer.push_back(localbuf);
57  }
58 
59 }
60 
62 {
63 
64 }
65 
66 
67 void QwPMT_Channel::ConstructHistograms(TDirectory *folder, TString &prefix)
68 {
69  // If we have defined a subdirectory in the ROOT file, then change into it.
70  if (folder != NULL) folder->cd();
71 
72  if (GetElementName() == "") {
73  // This channel is not used, so skip filling the histograms.
74  } else {
75  // Now create the histograms.
76  TString basename, fullname;
77  basename = prefix + GetElementName();
78 
79  fHistograms.resize(1, NULL);
80  size_t index = 0;
81  fHistograms[index] = gQwHists.Construct1DHist(basename);
82  index++;
83  }
84 }
85 
87 {
88  size_t index = 0;
89  if (GetElementName() == "") {
90  // This channel is not used, so skip creating the histograms.
91  } else {
92  if (fHistograms[index] != NULL)
93  fHistograms[index]->Fill(fValue);
94  index++;
95  }
96 }
97 
98 void QwPMT_Channel::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
99 {
100  if (GetElementName() == "") {
101  // This channel is not used, so skip setting up the tree.
102  } else {
103  TString basename = prefix + GetElementName();
104  fTreeArrayIndex = values.size();
105 
106  values.push_back(0.0);
107  TString list = basename + "/D";
108 
109  fTreeArrayNumEntries = values.size() - fTreeArrayIndex;
110  tree->Branch(basename, &(values[fTreeArrayIndex]), list);
111  }
112 }
113 
114 void QwPMT_Channel::FillTreeVector(std::vector<Double_t> &values) const
115 {
116  if (GetElementName()==""){
117  // This channel is not used, so skip filling the tree vector.
118  } else if (fTreeArrayNumEntries<=0){
119  std::cerr << "QwPMT_Channel::FillTreeVector: fTreeArrayNumEntries=="
120  << fTreeArrayNumEntries << std::endl;
121  } else if (values.size() < fTreeArrayIndex+fTreeArrayNumEntries){
122  std::cerr << "QwPMT_Channel::FillTreeVector: values.size()=="
123  << values.size()
124  << "; fTreeArrayIndex+fTreeArrayNumEntries=="
126  << std::endl;
127  } else {
128  size_t index=fTreeArrayIndex;
129  values[index++] = this->fValue;
130  }
131 }
132 
133 
134 
136  if (GetElementName()!=""){
137  this->fValue = value.fValue;
138  }
139  return *this;
140 }
141 
143 {
144  QwMessage << std::setprecision(4)
145  << std::setw(18) << std::left << GetElementName() << ", "
146  << std::setw(15) << std::left << GetValue()
147  << QwLog::endl;
148 }
149 
151 {
152  std::cout << "QwPMT_Channel::Print() not implemented yet." << std::endl;
153 }
void PrintInfo() const
Print multiple lines of information about this data element.
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
void FillTreeVector(std::vector< Double_t > &values) const
void ProcessEvent()
Bool_t IsNameEmpty() const
Is the name of this element empty?
void RandomizeEventData(int helicity, int SlotNum, int ChanNum)
std::vector< TH1_ptr > fHistograms
Histograms associated with this data element.
Definition: MQwHistograms.h:46
void PrintValue() const
Print single line of value and error of this data element.
void EncodeEventData(std::vector< UInt_t > &TrigBuffer)
A logfile class, based on an identical class in the Hermes analyzer.
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
void ClearEventData()
Clear the event data in this element.
size_t fTreeArrayIndex
Definition: QwPMT_Channel.h:91
Double_t fValue
Definition: QwPMT_Channel.h:95
static const Double_t kPMT_VoltsPerBit
Definition: QwPMT_Channel.h:85
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
void FillHistograms()
Fill the histograms for this data element.
QwPMT_Channel & operator=(const QwPMT_Channel &value)
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
virtual const TString & GetElementName() const
Get the name of this element.
size_t fTreeArrayNumEntries
Definition: QwPMT_Channel.h:92
Double_t GetValue() const
Definition: QwPMT_Channel.h:57
static const Bool_t kDEBUG
Definition: QwPMT_Channel.h:75
TH1F * Construct1DHist(const TString &inputfile, const TString &name_title)