QwAnalysis
QwEnergyCalculator.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwEnergyCalculator.cc *
3 * *
4 * Author: B.Waidyawansa *
5 * Time-stamp: 05-24-2010 *
6 \**********************************************************/
7 
8 #include "QwEnergyCalculator.h"
9 
10 // System headers
11 #include <stdexcept>
12 
13 // Qweak headers
14 #include "QwDBInterface.h"
15 
16 
17 // static QwVQWK_Channel targetbeamangle;
18 // static QwVQWK_Channel targetbeamx;
19 // static QwVQWK_Channel beamx;
20 
21 void QwEnergyCalculator::InitializeChannel(TString name,TString datatosave )
22 {
23  SetElementName(name);
24  fEnergyChange.InitializeChannel(name,datatosave);
25  // beamx.InitializeChannel("beamx","derived");
26  return;
27 }
28 
29 void QwEnergyCalculator::InitializeChannel(TString subsystem, TString name,TString datatosave )
30 {
31  SetElementName(name);
32  fEnergyChange.InitializeChannel(subsystem, "QwEnergyCalculator", name,datatosave);
33  // beamx.InitializeChannel("beamx","derived");
34  return;
35 }
36 
37 void QwEnergyCalculator::Set(const VQwBPM* device, TString type, TString property,Double_t tmatrix_ratio)
38 {
39  Bool_t ldebug = kFALSE;
40 
41  fDevice.push_back(device);
42  fProperty.push_back(property);
43  fType.push_back(type);
44  fTMatrixRatio.push_back(tmatrix_ratio);
45 
46  if(ldebug)
47  std::cout<<"QwEnergyCalculator:: Using "<<device->GetElementName()<<" with ratio "<< tmatrix_ratio <<" for "<<property<<std::endl;
48 
49  return;
50 }
51 
53 {
54  if(prefix=="diff_"||prefix=="yield_"|| prefix=="asym_")
55  bFullSave=kFALSE;
56 
57  return;
58 }
59 
62  return;
63 }
64 
65 
66 
68 
69  Bool_t ldebug = kFALSE;
70  Double_t targetbeamangle = 0;
71 
72  static QwVQWK_Channel tmp;
73  tmp.InitializeChannel("tmp","derived");
74  tmp.ClearEventData();
75 
76  for(UInt_t i = 0; i<fProperty.size(); i++){
77  if(fProperty[i].Contains("targetbeamangle")){
78  targetbeamangle = atan((((QwCombinedBPM<QwVQWK_Channel>*)fDevice[i])->fSlope[VQwBPM::kXAxis]).GetValue());
79  targetbeamangle *= fTMatrixRatio[i];
80  if(ldebug) std::cout<<"QwEnegyCalculator::ProcessEvent() :: Beam angle in X at target = "<<targetbeamangle<<std::endl;
81  fEnergyChange.AddChannelOffset(targetbeamangle);
82  if(ldebug) std::cout<<"QwEnegyCalculator::ProcessEvent() :: dp/p += (M12/M16)*X angle = "<<fEnergyChange.GetValue()<<std::endl;
83  }
84  else {
85  tmp.AssignValueFrom(fDevice[i]->GetPosition(VQwBPM::kXAxis));
86  if(ldebug) std::cout<<"QwEnegyCalculator::ProcessEvent() :: X position from "<<fDevice[i]->GetElementName()<<" = "<<tmp.GetValue()<<std::endl;
87  tmp.Scale(fTMatrixRatio[i]);
88  if(ldebug) std::cout<<"QwEnegyCalculator::ProcessEvent() :: (M11/M16)*X position = "<<tmp.GetValue()<<std::endl;
89  fEnergyChange += tmp;
90  }
91  }
92  if(ldebug) std::cout<<"QwEnegyCalculator::ProcessEvent() :: dp/p = "<<fEnergyChange.GetValue()<<std::endl;
93  return;
94 }
95 
96 
98  Bool_t status=kTRUE;
99 
100  UInt_t error_code = 0;
101  for(UInt_t i = 0; i<fProperty.size(); i++){
102  if(fProperty[i].Contains("targetbeamangle")){
103  error_code |= ((QwCombinedBPM<QwVQWK_Channel>*)fDevice[i])->fSlope[0].GetErrorCode();
104  } else {
105  error_code |= fDevice[i]->GetPosition(VQwBPM::kXAxis)->GetErrorCode();
106  }
107  }
108  //fEnergyChange.UpdateErrorFlag(error_code);//No need to do this. error codes are ORed when energy is calculated
109 
111  status=kTRUE;
112  }
113  else{
114  status&=kFALSE;
115  }
116  return status;
117 }
118 
120 {
122 }
123 
124 
126  // report number of events failed due to HW and event cut faliure
128 }
129 
131 {
132  UInt_t error_code = 0;
133  for(UInt_t i = 0; i<fProperty.size(); i++){
134  if(fProperty[i].Contains("targetbeamangle")){
135  error_code |= ((QwCombinedBPM<QwVQWK_Channel>*)fDevice[i])->fSlope[0].GetErrorCode();
136  } else {
137  error_code |= fDevice[i]->GetPosition(VQwBPM::kXAxis)->GetErrorCode();
138  }
139  }
140  fEnergyChange.UpdateErrorFlag(error_code);
142 }
143 
144 
147 };
148 
149 
152 }
153 
154 
155 
158 }
159 
162 }
163 
164 
165 
166 Int_t QwEnergyCalculator::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer,UInt_t subelement){
167  return 0;
168 }
169 
170 
172  if (GetElementName()!="")
173  this->fEnergyChange=value.fEnergyChange;
174 
175  return *this;
176 }
177 
179 
180  if (GetElementName()!="")
181  this->fEnergyChange+=value.fEnergyChange;
182 
183  return *this;
184 }
185 
187  if (GetElementName()!="")
188  this->fEnergyChange-=value.fEnergyChange;
189 
190  return *this;
191 }
192 
193 
195  // this function is called when forming asymmetries. In this case waht we actually want for the
196  // qwk_energy/(dp/p) is the difference only not the asymmetries
197 
198  *this=numer;
199  return;
200 }
201 
202 
203 void QwEnergyCalculator::Scale(Double_t factor){
204  fEnergyChange.Scale(factor);
205  return;
206 }
207 
208 
211  return;
212 }
213 
214 
217  return;
218 }
219 
221  // For the energy calculator there are no physical channels that we can relate to because it is being
222  // derived from combinations of physical channels. Therefore, this is not exactly a "HW Check"
223  // but just a check of the HW checks of the used channels.
224 
225  Bool_t eventokay=kTRUE;
226  return eventokay;
227 }
228 
229 
230 Int_t QwEnergyCalculator::SetSingleEventCuts(Double_t minX, Double_t maxX){
232  return 1;
233 }
234 
235 void QwEnergyCalculator::SetSingleEventCuts(UInt_t errorflag, Double_t LL=0, Double_t UL=0, Double_t stability=0){
236  //set the unique tag to identify device type (bcm,bpm & etc)
237  errorflag|=kBCMErrorFlag;//currently I use the same flag for bcm
238  QwMessage<<"QwEnergyCalculator Error Code passing to QwVQWK_Ch "<<errorflag<<QwLog::endl;
239  fEnergyChange.SetSingleEventCuts(errorflag,LL,UL,stability);
240 }
241 
242 
243 void QwEnergyCalculator::ConstructHistograms(TDirectory *folder, TString &prefix){
244  if (GetElementName()==""){
245  // This channel is not used, so skip filling the histograms.
246  }
247  else{
248  TString thisprefix=prefix;
249  if(prefix=="asym_")
250  thisprefix="diff_";
251  SetRootSaveStatus(thisprefix);
252  fEnergyChange.ConstructHistograms(folder, thisprefix);
253  }
254  return;
255 }
256 
258  if (GetElementName()==""){
259  // This channel is not used, so skip filling the histograms.
260  }
261  else
263 
264  return;
265 }
266 
267 void QwEnergyCalculator::ConstructBranchAndVector(TTree *tree, TString &prefix,
268  std::vector<Double_t> &values){
269  if (GetElementName()==""){
270  // This channel is not used, so skip filling the histograms.
271  }
272  else{
273  TString thisprefix=prefix;
274  if(prefix=="asym_")
275  thisprefix="diff_";
276 
277  SetRootSaveStatus(thisprefix);
278 
279  fEnergyChange.ConstructBranchAndVector(tree,thisprefix,values);
280  }
281  return;
282 }
283 
284 
285 
286 void QwEnergyCalculator::ConstructBranch(TTree *tree, TString &prefix){
287  if (GetElementName()==""){
288  // This channel is not used, so skip filling the histograms.
289  }
290  else{
291  TString thisprefix=prefix;
292  if(prefix=="asym_")
293  thisprefix="diff_";
294 
295  SetRootSaveStatus(thisprefix);
296  fEnergyChange.ConstructBranch(tree,thisprefix);
297  }
298  return;
299 }
300 
301 void QwEnergyCalculator::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist){
302 
303  TString devicename;
304  devicename=GetElementName();
305  devicename.ToLower();
306  if (GetElementName()==""){
307  // This channel is not used, so skip filling the histograms.
308  }
309  else
310  if (modulelist.HasValue(devicename)){
311  TString thisprefix=prefix;
312  if(prefix=="asym_")
313  thisprefix="diff_";
314  SetRootSaveStatus(thisprefix);
315  fEnergyChange.ConstructBranch(tree,thisprefix);
316  QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
317  }
318  return;
319 }
320 
321 void QwEnergyCalculator::FillTreeVector(std::vector<Double_t> &values) const
322 {
323  if (GetElementName()==""){
324  // This channel is not used, so skip filling the histograms.
325  }
326  else
328  return;
329 }
330 
331 
332 std::vector<QwDBInterface> QwEnergyCalculator::GetDBEntry()
333 {
334  std::vector <QwDBInterface> row_list;
335  row_list.clear();
337  return row_list;
338 
339 }
340 
341 std::vector<QwErrDBInterface> QwEnergyCalculator::GetErrDBEntry()
342 {
343  std::vector <QwErrDBInterface> row_list;
344  row_list.clear();
346  return row_list;
347 }
348 
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static const UInt_t kBCMErrorFlag
Definition: QwTypes.h:167
void AccumulateRunningSum(const QwEnergyCalculator &value)
void AssignValueFrom(const VQwDataElement *valueptr)
void ConstructBranch(TTree *tree, TString &prefix)
void SetRootSaveStatus(TString &prefix)
void DeaccumulateRunningSum(const QwVQWK_Channel &value)
std::vector< TString > fType
void SetSingleEventCuts(Double_t min, Double_t max)
Set the upper and lower limits (fULimit and fLLimit) for this channel.
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
void InitializeChannel(TString name, TString datatosave)
void Ratio(QwEnergyCalculator &numer, QwEnergyCalculator &denom)
std::vector< const VQwBPM * > fDevice
void PrintInfo() const
Print multiple lines of information about this data element.
Double_t GetValue(size_t element) const
void Set(const VQwBPM *device, TString type, TString property, Double_t tmatrix_ratio)
void FillHistograms()
Fill the histograms for this data element.
void Scale(Double_t Offset)
void ConstructBranch(TTree *tree, TString &prefix)
std::vector< TString > fProperty
std::vector< QwErrDBInterface > GetErrDBEntry()
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
void DeaccumulateRunningSum(QwEnergyCalculator &value)
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
Bool_t HasValue(TString &vname)
virtual UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
std::vector< Double_t > fTMatrixRatio
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
void PrintValue() const
Print single line of value and error of this data element.
void AddEntriesToList(std::vector< QwDBInterface > &row_list)
virtual QwEnergyCalculator & operator+=(const QwEnergyCalculator &value)
void ClearEventData()
Clear the event data in this element.
void PrintInfo() const
Print multiple lines of information about this data element.
Bool_t ApplySingleEventCuts(Double_t LL, Double_t UL)
void Scale(Double_t factor)
void FillTreeVector(std::vector< Double_t > &values) const
void SetElementName(const TString &name)
Set the name of this element.
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
void FillHistograms()
Fill the histograms for this data element.
virtual QwEnergyCalculator & operator=(const QwEnergyCalculator &value)
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Definition: VQwBPM.h:34
virtual const TString & GetElementName() const
Get the name of this element.
void FillTreeVector(std::vector< Double_t > &values) const
void ClearEventData()
Clear the event data in this element.
void PrintValue() const
Print single line of value and error of this data element.
void InitializeChannel(TString name, TString datatosave)
Initialize the fields in this object.
void AddChannelOffset(Double_t Offset)
void AddErrEntriesToList(std::vector< QwErrDBInterface > &row_list)
Int_t SetSingleEventCuts(Double_t mean, Double_t sigma)
void IncrementErrorCounters()
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t indexnumber)
Process the CODA event buffer for this element.
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
virtual QwEnergyCalculator & operator-=(const QwEnergyCalculator &value)
void CalculateRunningAverage()
std::vector< QwDBInterface > GetDBEntry()
QwVQWK_Channel fEnergyChange
void AccumulateRunningSum(const QwVQWK_Channel &value)