QwAnalysis
QwCombinedBCM.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwCombinedBCM.cc *
3 * *
4 * Author: *
5 * Time-stamp: *
6 \**********************************************************/
7 
8 #include "QwCombinedBCM.h"
9 
10 // System headers
11 #include <stdexcept>
12 
13 // Qweak 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 
22 //this is a combined BCM made out of BCMs that are already callibrated and have pedstals removed.
23 //This will be used for projection of charge at the target
24 
25 template<typename T>
26 void QwCombinedBCM<T>::SetBCMForCombo(VQwBCM* bcm, Double_t weight, Double_t sumqw )
27 {
28  // Convert back to QWBCM<T>* from generic VQwBCM*
29  fElement.push_back(dynamic_cast<QwBCM<T>* >(bcm));
30  fWeights.push_back(weight);
31  fSumQweights = sumqw;
32 }
33 
34 /********************************************************/
35 
36 template<typename T>
37 void QwCombinedBCM<T>::InitializeChannel(TString name, TString datatosave)
38 {
39  SetPedestal(0.);
40  SetCalibrationFactor(1.);
41  this->SetElementName(name);
42  this->fBeamCurrent.InitializeChannel(name,"derived");
43 }
44 
45 template<typename T>
46 void QwCombinedBCM<T>::InitializeChannel(TString subsystem, TString name, TString datatosave)
47 {
48  SetPedestal(0.);
49  SetCalibrationFactor(1.);
50  this->SetElementName(name);
51  this->fBeamCurrent.InitializeChannel(subsystem, "QwCombinedBCM", name,"derived");
52 }
53 
54 template<typename T>
55 void QwCombinedBCM<T>::InitializeChannel(TString subsystem, TString name,
56  TString type, TString datatosave)
57 {
58  SetPedestal(0.);
59  SetCalibrationFactor(1.);
60  this->SetElementName(name);
61  this->SetModuleType(type);
62  this->fBeamCurrent.InitializeChannel(subsystem, "QwCombinedBCM", name,"derived");
63 }
64 
65 
66 /********************************************************/
67 template<typename T>
69 {
70  static T tmpADC;
71  tmpADC.InitializeChannel("tmp","derived");
72 
73  for (size_t i = 0; i < fElement.size(); i++) {
74  tmpADC = fElement[i]->fBeamCurrent;
75  tmpADC.Scale(fWeights[i]);
76  this->fBeamCurrent += tmpADC;
77  }
78  this->fBeamCurrent.Scale(1.0/fSumQweights);
79 
80  Bool_t ldebug = kFALSE;
81  if (ldebug) {
82  QwMessage << "*****************" << QwLog::endl;
83  QwMessage << "QwCombinedBCM: " << this->GetElementName() << QwLog::endl
84  << "weighted average of hardware sums = " << this->fBeamCurrent.GetValue() << QwLog::endl;
85  if (this->fBeamCurrent.GetNumberOfSubelements() > 1) {
86  for (size_t i = 0; i < 4; i++) {
87  QwMessage << "weighted average of block[" << i << "] = " << this->fBeamCurrent.GetValue(i) << QwLog::endl;
88  }
89  }
90  QwMessage << "*****************" << QwLog::endl;
91  }
92 }
93 
94 
95 /********************************************************/
96 template<typename T>
98 {
99 
100  //This is required to update single event cut faliures in individual channels
101  // First update the error code based on the codes
102  // of the elements. This requires that the BCMs
103  // have had ApplySingleEventCuts run on them already.
104 
105  for (size_t i=0;i<fElement.size();i++){
106  this->fBeamCurrent.UpdateErrorFlag(fElement.at(i)->fBeamCurrent.GetErrorCode());
107  }
108 
109 
110  // Everything is identical as for a regular BCM
112 }
113 
114 template<typename T>
116  for (size_t i=0;i<fElement.size();i++){
117  this->fBeamCurrent.UpdateErrorFlag(fElement.at(i)->fBeamCurrent.GetErrorCode());
118  }
119  return this->fBeamCurrent.GetEventcutErrorFlag();
120 }
121 
122 
123 /********************************************************/
124 /*
125 template<typename T>
126 void QwCombinedBCM<T>::UpdateErrorFlag(const VQwBCM *ev_error){
127 
128  try {
129  if(typeid(*ev_error)==typeid(*this)) {
130  // std::cout<<" Here in QwCombinedBCM::UpdateErrorFlag \n";
131  if (this->GetElementName()!="") {
132  QwCombinedBCM<T>* value_bcm = dynamic_cast<QwCombinedBCM<T>* >(ev_error);
133  VQwDataElement *value_data = dynamic_cast<VQwDataElement *>(&(value_bcm->fBeamCurrent));
134  fBeamCurrent.UpdateErrorFlag(value_data->GetErrorCode());//the routine GetErrorCode() return the error flag + configuration flag unconditionally
135  }
136  } else {
137  TString loc="Standard exception from QwCombinedBCM::UpdateErrorFlag :"+
138  ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
139  +"same type";
140  throw std::invalid_argument(loc.Data());
141  }
142  } catch (std::exception& e) {
143  std::cerr<< e.what()<<std::endl;
144  }
145 
146  QwBCM<T>::UpdateErrorFlag(const ev_error);
147 };
148 */
149 
150 /********************************************************/
151 /*
152 template<typename T>
153 void QwCombinedBCM<T>::CalculateRunningAverage(){
154  fBeamCurrent.CalculateRunningAverage();
155 =======
156  return eventokay;
157 >>>>>>> .merge-right.r3406
158 }
159 */
160 /********************************************************/
161 /*
162 template<typename T>
163 <<<<<<< .working
164 void QwCombinedBCM<T>::AccumulateRunningSum(const VQwBCM &value){
165  fBeamCurrent.AccumulateRunningSum(dynamic_cast<const QwCombinedBCM<T>* >(&value)->fBeamCurrent);
166 }
167 */
168 /********************************************************/
169 /*
170 template<typename T>
171 void QwCombinedBCM<T>::DeaccumulateRunningSum(VQwBCM &value){
172  fBeamCurrent.DeaccumulateRunningSum(dynamic_cast<QwCombinedBCM<T>* >(&value)->fBeamCurrent);
173 }
174 */
175 
176 
177 /********************************************************/
178 template<typename T>
180 {
181  if (this->GetElementName()!="")
182  this->fBeamCurrent=value.fBeamCurrent;
183 
184  return *this;
185 }
186 
187 template<typename T>
189 {
190  if (this->GetElementName()!="")
191  dynamic_cast<QwCombinedBCM<T>* >(this)->fBeamCurrent=
192  dynamic_cast<const QwCombinedBCM<T>* >(&value)->fBeamCurrent;
193 
194  return *this;
195 }
196 
197 /********************************************************/
198 /*
199 template<typename T>
200 Bool_t QwCombinedBCM<T>::ApplyHWChecks()
201 {
202  // For the combined devices there are no physical channels that we can relate to because they are being
203  // derived from combinations of physical channels. Therefore, this is not exactly a "HW Check"
204  // but just a check of the HW checks of the combined channels.
205 
206  Bool_t eventokay=kTRUE;
207 
208  return eventokay;
209 }
210 */
211 
212 /*
213 template<typename T>
214 Int_t QwCombinedBCM<T>::SetSingleEventCuts(Double_t LL=0, Double_t UL=0){
215  fBeamCurrent.SetSingleEventCuts(LL,UL);
216  return 1;
217 }
218 
219 
220 template<typename T>
221 void QwCombinedBCM<T>::SetSingleEventCuts(UInt_t errorflag, Double_t LL=0, Double_t UL=0, Double_t stability=0){
222  //set the unique tag to identify device type (bcm,bpm & etc)
223  errorflag|=kBCMErrorFlag;//currently I use the same flag for bcm & combinedbcm
224  QwMessage<<"QwCombinedBCM Error Code passing to QwVQWK_Ch "<<errorflag<<" "<<stability<<QwLog::endl;
225  fBeamCurrent.SetSingleEventCuts(errorflag,LL,UL,stability);
226 
227 }
228 
229 
230 template<typename T>
231 void QwCombinedBCM<T>::ConstructHistograms(TDirectory *folder, TString &prefix)
232 {
233  if (this->GetElementName()=="")
234  {
235  // This channel is not used, so skip filling the histograms.
236  }
237  else
238  {
239  fBeamCurrent.ConstructHistograms(folder, prefix);
240  }
241  return;
242 
243 }
244 
245 template<typename T>
246 void QwCombinedBCM<T>::FillHistograms()
247 {
248  if (this->GetElementName()=="")
249  {
250  // This channel is not used, so skip filling the histograms.
251  }
252  else
253  {
254  fBeamCurrent.FillHistograms();
255  }
256 
257 
258  return;
259 }
260 
261 template<typename T>
262 void QwCombinedBCM<T>::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
263 {
264  if (this->GetElementName()==""){
265  // This channel is not used, so skip filling the histograms.
266  } else
267  {
268  fBeamCurrent.ConstructBranchAndVector(tree,prefix,values);
269  }
270  return;
271 }
272 
273 template<typename T>
274 void QwCombinedBCM<T>::ConstructBranch(TTree *tree, TString &prefix)
275 {
276  if (this->GetElementName()==""){
277  // This channel is not used, so skip filling the histograms.
278  } else
279  {
280  fBeamCurrent.ConstructBranch(tree,prefix);
281  }
282  return;
283 }
284 
285 template<typename T>
286 void QwCombinedBCM<T>::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist)
287 {
288  TString devicename;
289  devicename=this->GetElementName();
290  devicename.ToLower();
291 
292  if (this->GetElementName()==""){
293  // This channel is not used, so skip filling the histograms.
294  } else
295  {
296  if (modulelist.HasValue(devicename)){
297  fBeamCurrent.ConstructBranch(tree,prefix);
298  QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
299  }
300  }
301  return;
302 }
303 
304 
305 template<typename T>
306 void QwCombinedBCM<T>::FillTreeVector(std::vector<Double_t> &values) const
307 {
308  if (this->GetElementName()==""){
309  // This channel is not used, so skip filling the histograms.
310  } else
311  {
312  fBeamCurrent.FillTreeVector(values);
313  }
314  return;
315 }
316 
317 */
318 
319 /********************************************************/
320 template class QwCombinedBCM<QwVQWK_Channel>;
321 template class QwCombinedBCM<QwSIS3801_Channel>;
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
Definition: VQwBCM.h:32
VQwBCM & operator=(const VQwBCM &value)
void SetBCMForCombo(VQwBCM *bcm, Double_t weight, Double_t sumqw)
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
Bool_t ApplySingleEventCuts()
Definition: QwBCM.cc:158
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Definition: QwBCM.h:34
void ProcessEvent()
Bool_t ApplySingleEventCuts()
void InitializeChannel(TString name, TString datatosave)
T fBeamCurrent
Definition: QwBCM.h:168