QwAnalysis
QwQPD.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwQPD.cc *
3 * *
4 * Author: B. Waidyawansa *
5 * Time-stamp: 09-14-2010 *
6 \**********************************************************/
7 
8 #include "QwQPD.h"
9 
10 // System headers
11 #include <stdexcept>
12 
13 // Qweak headers
14 #include "QwDBInterface.h"
15 
16 /* Position calibration factor, transform ADC counts in mm*/
17 const TString QwQPD::subelement[4]={"BR","TR","BL","TL"};
18 
19 
20 void QwQPD::InitializeChannel(TString name)
21 {
22  Short_t i=0;
23  Bool_t localdebug = kFALSE;
24 
26 
27  fEffectiveCharge.InitializeChannel(name+"_EffectiveCharge","derived");
28 
29  for(i=0;i<4;i++) {
30  fPhotodiode[i].InitializeChannel(name+subelement[i],"raw");
31 
32  if(localdebug)
33  std::cout<<" photodiode ["<<i<<"]="<<fPhotodiode[i].GetElementName()<<"\n";
34  }
35 
36  for(i=kXAxis;i<kNumAxes;i++) {
37  fRelPos[i].InitializeChannel(name+"Rel"+kAxisLabel[i],"derived");
38  fAbsPos[i].InitializeChannel(name+kAxisLabel[i],"derived");
39  }
40 
41  bFullSave=kTRUE;
42 
43  return;
44 }
45 
46 void QwQPD::InitializeChannel(TString subsystem, TString name)
47 {
48  Short_t i=0;
49  Bool_t localdebug = kFALSE;
50 
52 
53  fEffectiveCharge.InitializeChannel(subsystem, "QwQPD", name+"_EffectiveCharge","derived");
54 
55  for(i=0;i<4;i++) {
56  fPhotodiode[i].InitializeChannel(subsystem, "QwQPD", name+subelement[i],"raw");
57  if(localdebug)
58  std::cout<<" photodiode ["<<i<<"]="<<fPhotodiode[i].GetElementName()<<"\n";
59  }
60  for(i=kXAxis;i<kNumAxes;i++) fRelPos[i].InitializeChannel(subsystem, "QwQPD", name+"Rel"+kAxisLabel[i],"derived");
61  for(i=kXAxis;i<kNumAxes;i++) fAbsPos[i].InitializeChannel(subsystem, "QwQPD", name+kAxisLabel[i],"derived");
62 
63  bFullSave=kTRUE;
64 
65  return;
66 }
67 
68 void QwQPD::GetCalibrationFactors(Double_t AlphaX, Double_t AlphaY)
69 {
70  // Read in the calibration factors from the injector_beamline_geometry.map
71  // for the QPD, AlphaX and AlphaY gives the conversion from adc counts to mm.
72 
73  Bool_t ldebug = kFALSE;
74 
75  fQwQPDCalibration[0]=1.0/AlphaX;
76  fQwQPDCalibration[1]=1.0/AlphaY;
77 
78  if(ldebug){
79  std::cout<<"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
80  std::cout<<this->GetElementName();
81  std::cout<<"\nfQwQPDCalibration[0] = "<<fQwQPDCalibration[0]<<std::endl;
82  std::cout<<"\nfQwQPDCalibration[1] = "<<fQwQPDCalibration[1]<<std::endl;
83  std::cout<<"AlphaX = "<<fRelativeGains[0]<<std::endl;
84  std::cout<<"AlphaY = "<<fRelativeGains[1]<<std::endl;
85  }
86  return;
87 }
88 
90 {
91  Short_t i=0;
92 
93  for(i=0;i<4;i++) fPhotodiode[i].ClearEventData();
94 
95  for(i=kXAxis;i<kNumAxes;i++) {
98  }
99 
101 
102  return;
103 }
104 
105 
107 {
108  Bool_t eventokay=kTRUE;
109 
110  UInt_t deviceerror=0;
111  for(Short_t i=0;i<4;i++)
112  {
113  deviceerror|= fPhotodiode[i].ApplyHWChecks(); //OR the error code from each wire
114  eventokay &= (deviceerror & 0x0);//AND with 0 since zero means HW is good.
115 
116  if (bDEBUG) std::cout<<" Inconsistent within QPD terminals photodiode[ "<<i<<" ] "<<std::endl;
117  if (bDEBUG) std::cout<<" photodiode[ "<<i<<" ] sequence num "<<fPhotodiode[i].GetSequenceNumber()<<" sample size "<<fPhotodiode[i].GetNumberOfSamples()<<std::endl;
118  }
119 
120  return eventokay;
121 }
122 
124 {
125  Short_t i=0;
126  for(i=0;i<4;i++)
128  for(i=kXAxis;i<kNumAxes;i++) {
131  }
133 }
134 
136 {
137  Short_t i=0;
138  for(i=0;i<4;i++)
140  for(i=kXAxis;i<kNumAxes;i++) {
143  }
145 }
146 
148 {
149  Short_t i=0;
150  UInt_t error=0;
151  for(i=0;i<4;i++)
152  error|=fPhotodiode[i].GetEventcutErrorFlag();
153 
154  for(i=kXAxis;i<kNumAxes;i++) {
155  error|=fRelPos[i].GetEventcutErrorFlag();
156  error|=fAbsPos[i].GetEventcutErrorFlag();
157  }
158 
160  return error;
161 }
162 
164 {
165  Short_t i=0;
166  UInt_t error1=0;
167  UInt_t error2=0;
168  for(i=0;i<4;i++){
169  error1|=fPhotodiode[i].GetErrorCode();
170  error2|=fPhotodiode[i].GetEventcutErrorFlag();
171  }
172  for(i=kXAxis;i<kNumAxes;i++) {
173  fRelPos[i].UpdateErrorFlag(error1);
174  fAbsPos[i].UpdateErrorFlag(error1);
175  error2|=fRelPos[i].GetEventcutErrorFlag();
176  error2|=fAbsPos[i].GetEventcutErrorFlag();
177  }
180  return error2;
181 }
182 
184 {
185  Bool_t status=kTRUE;
186  Int_t i=0;
187  UInt_t error_code = 0;
188  //Event cuts for four pads
189  for(i=0;i<4;i++){
190  if (fPhotodiode[i].ApplySingleEventCuts()){ //for RelX
191  status&=kTRUE;
192  }
193  else{
194  status&=kFALSE;
195  if (bDEBUG) std::cout<<" single pad "<<fPhotodiode[i].GetElementName()<<" event cut failed ";
196  }
197  //Get the Event cut error flag for the pads
198  error_code|=fPhotodiode[i].GetErrorCode();
199  }
200 
201  for(i=0;i<2;i++){
202  fRelPos[i].UpdateErrorFlag(error_code);//To update the rel/abs error code from the channels/wires event cut error codes
203  status &= fRelPos[i].ApplySingleEventCuts();
204 
205  fAbsPos[i].UpdateErrorFlag(error_code);//To update the rel/abs error code from the channels/wires event cut error codes
206  status &= fAbsPos[i].ApplySingleEventCuts();
207  }
208  fEffectiveCharge.UpdateErrorFlag(error_code);// To update the eff-charge error code from the channels/wires event cut error codes
210 
211  return status;
212 }
213 
215 {
216  VQwHardwareChannel* tmpptr = NULL;
217  ch_name.ToLower();
218  if (ch_name=="tl"){
219  tmpptr = &fPhotodiode[0];
220  }else if (ch_name=="tr"){
221  tmpptr = &fPhotodiode[1];
222  }else if (ch_name=="br"){
223  tmpptr = &fPhotodiode[2];
224  }else if (ch_name=="bl"){
225  tmpptr = &fPhotodiode[3];
226  }else if (ch_name=="relx"){
227  tmpptr = &fRelPos[0];
228  }else if (ch_name=="rely"){
229  tmpptr = &fRelPos[1];
230  }else if (ch_name=="absx" || ch_name=="x" ){
231  tmpptr = &fAbsPos[0];
232  }else if (ch_name=="absy" || ch_name=="y"){
233  tmpptr = &fAbsPos[1];
234  }else if (ch_name=="effectivecharge" || ch_name=="charge"){
235  tmpptr = &fEffectiveCharge;
236  } else {
237  TString loc="QwQPD::GetSubelementByName for"
238  + this->GetElementName() + " was passed "
239  + ch_name + ", which is an unrecognized subelement name.";
240  throw std::invalid_argument(loc.Data());
241  }
242  return tmpptr;
243 }
244 
245 /*
246 void QwQPD::SetSingleEventCuts(TString ch_name, Double_t minX, Double_t maxX)
247 {
248 
249  if (ch_name=="tl"){
250  QwMessage<<"TL LL " << minX <<" UL " << maxX <<QwLog::endl;
251  fPhotodiode[0].SetSingleEventCuts(minX,maxX);
252 
253  }else if (ch_name=="tr"){
254  QwMessage<<"TR LL " << minX <<" UL " << maxX <<QwLog::endl;
255  fPhotodiode[1].SetSingleEventCuts(minX,maxX);
256 
257  }else if (ch_name=="br"){
258  QwMessage<<"BR LL " << minX <<" UL " << maxX <<QwLog::endl;
259  fPhotodiode[2].SetSingleEventCuts(minX,maxX);
260 
261  }else if (ch_name=="bl"){
262  QwMessage<<"BL LL " << minX <<" UL " << maxX <<QwLog::endl;
263  fPhotodiode[3].SetSingleEventCuts(minX,maxX);
264 
265  }else if (ch_name=="relx"){
266  QwMessage<<"RelX LL " << minX <<" UL " << maxX <<QwLog::endl;
267  fRelPos[0].SetSingleEventCuts(minX,maxX);
268 
269  }else if (ch_name=="rely"){
270  QwMessage<<"RelY LL " << minX <<" UL " << maxX <<QwLog::endl;
271  fRelPos[1].SetSingleEventCuts(minX,maxX);
272 
273  }else if (ch_name=="x" || ch_name=="y" || ch_name=="effectivecharge" ){
274 
275  VQwBPM::SetSingleEventCuts(ch_name, minX, maxX);
276  }
277 
278 }
279 
280 void QwQPD::SetSingleEventCuts(TString ch_name, UInt_t errorflag,Double_t minX, Double_t maxX, Double_t stability){
281  errorflag|=kBPMErrorFlag;//update the device flag
282  if (ch_name=="tl"){
283  QwMessage<<"TL LL " << minX <<" UL " << maxX <<QwLog::endl;
284  fPhotodiode[0].SetSingleEventCuts(errorflag,minX,maxX,stability);
285 
286  }else if (ch_name=="tr"){
287  QwMessage<<"TR LL " << minX <<" UL " << maxX <<QwLog::endl;
288  fPhotodiode[1].SetSingleEventCuts(errorflag,minX,maxX,stability);
289 
290  }else if (ch_name=="br"){
291  QwMessage<<"BR LL " << minX <<" UL " << maxX <<QwLog::endl;
292  fPhotodiode[2].SetSingleEventCuts(errorflag,minX,maxX,stability);
293 
294  }else if (ch_name=="bl"){
295  QwMessage<<"BL LL " << minX <<" UL " << maxX <<QwLog::endl;
296  fPhotodiode[3].SetSingleEventCuts(errorflag,minX,maxX,stability);
297 
298  }else if (ch_name=="relx"){
299  QwMessage<<"RelX LL " << minX <<" UL " << maxX <<QwLog::endl;
300  fRelPos[0].SetSingleEventCuts(errorflag,minX,maxX,stability);
301 
302  }else if (ch_name=="rely"){
303  QwMessage<<"RelY LL " << minX <<" UL " << maxX <<QwLog::endl;
304  fRelPos[1].SetSingleEventCuts(errorflag,minX,maxX,stability);
305 
306  }else if (ch_name=="absx"){
307  QwMessage<<"AbsX LL " << minX <<" UL " << maxX <<QwLog::endl;
308  fAbsPos[0].SetSingleEventCuts(errorflag,minX,maxX,stability);
309 
310  }else if (ch_name=="absy"){
311  QwMessage<<"AbsY LL " << minX <<" UL " << maxX <<QwLog::endl;
312  fAbsPos[1].SetSingleEventCuts(errorflag,minX,maxX,stability);
313 
314  }else if (ch_name=="effectivecharge"){
315  QwMessage<<"EffectveQ LL " << minX <<" UL " << maxX <<QwLog::endl;
316  fEffectiveCharge.SetSingleEventCuts(errorflag,minX,maxX,stability);
317 
318  }
319 
320 }
321 
322 */
323 
324 void QwQPD::UpdateErrorFlag(const VQwBPM *ev_error){
325  Short_t i=0;
326  try {
327  if(typeid(*ev_error)==typeid(*this)) {
328  // std::cout<<" Here in QwQPD::UpdateErrorFlag \n";
329  if (this->GetElementName()!="") {
330  const QwQPD* value_bpm = dynamic_cast<const QwQPD* >(ev_error);
331  for(i=0;i<4;i++){
332  fPhotodiode[i].UpdateErrorFlag(value_bpm->fPhotodiode[i]);
333  }
334  for(i=kXAxis;i<kNumAxes;i++) {
335  fRelPos[i].UpdateErrorFlag(value_bpm->fRelPos[i]);
336  fAbsPos[i].UpdateErrorFlag(value_bpm->fAbsPos[i]);
337  }
339  }
340  } else {
341  TString loc="Standard exception from QwQPD::UpdateErrorFlag :"+
342  ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
343  +"same type";
344  throw std::invalid_argument(loc.Data());
345  }
346  } catch (std::exception& e) {
347  std::cerr<< e.what()<<std::endl;
348  }
349 
350 };
351 
352 
353 
355 {
356  Bool_t localdebug = kFALSE;
357  static QwVQWK_Channel numer[2];
358  static QwVQWK_Channel tmp("tmp");
359  static QwVQWK_Channel tmp1("tmp1");
360  static QwVQWK_Channel tmp2("tmp2");
361 
362  numer[0].InitializeChannel("Xnumerator","raw");
363  numer[1].InitializeChannel("Ynumerator","raw");
364 
365  Short_t i = 0;
366 
367  ApplyHWChecks();
368  /* Frst apply HW checks and update HW error flags.
369  Calling this routine here and not in ApplySingleEventCuts
370  makes a difference for a QPDs because they are derrived devices.
371  */
372 
374 
375  for(i=0;i<4;i++){
378  }
379 
380  if (localdebug) fEffectiveCharge.PrintInfo();
381 
382 
383  /** The positions X and Y from a QPD are calculated using following equations,
384 
385  TL --------- TR
386  | 4 | 2 |
387  ---------
388  BL | 3 | 1 | BR
389  ---------
390 
391 
392  (4-2) + (3-1) (4-3) + (2-1)
393  X = ------------ Y = -------------
394  1+2+3+4 1+2+3+4
395  **/
396 
397  if(localdebug){
398  std::cout<<"#############################\n";
399  std::cout<<" QPD name = "<<fElementName<<std::endl;
400  std::cout<<" event number = "<<fPhotodiode[0].GetSequenceNumber()<<"\n";
401  std::cout<<" hw BR ="<<fPhotodiode[0].GetValue()<<"\n";
402  std::cout<<" hw TR ="<<fPhotodiode[1].GetValue()<<"\n";
403  std::cout<<" hw BL ="<<fPhotodiode[2].GetValue()<<"\n";
404  std::cout<<" hw TL ="<<fPhotodiode[3].GetValue()<<"\n\n";
405  }
406 
407  // X numerator
408  tmp1.ClearEventData();
409  tmp1.Difference(fPhotodiode[3],fPhotodiode[1]); // 4-2
410  tmp2.ClearEventData();
411  tmp2.Difference(fPhotodiode[2],fPhotodiode[0]); // 3-1
412  tmp.ClearEventData();
413  numer[0].Sum(tmp1,tmp2);
414 
415  // Y numerator
416  tmp1.ClearEventData();
417  tmp1.Difference(fPhotodiode[3],fPhotodiode[2]); // 4-3
418  tmp2.ClearEventData();
419  tmp2.Difference(fPhotodiode[1],fPhotodiode[0]); // 2-1
420  tmp.ClearEventData();
421  numer[1].Sum(tmp1,tmp2);
422 
423  for(i=kXAxis;i<kNumAxes;i++){
424  tmp.ClearEventData();
425  tmp.Sum(fPhotodiode[0],fPhotodiode[1]);
426  tmp1.ClearEventData();
427  tmp1.Sum(fPhotodiode[2],fPhotodiode[3]);
428  fEffectiveCharge.Sum(tmp,tmp1);
429 
430  // X/Y reading in ADC counts
431  fRelPos[i].Ratio(numer[i],fEffectiveCharge);
432 
433  // X/Y reading in mm.
434  fAbsPos[i]=fRelPos[i];
436 
437  if(localdebug){
438  std::cout<<" hw numerator= "<<numer[i].GetValue()<<" ";
439  std::cout<<" hw denominator (== Effective_Charge)= "<<fEffectiveCharge.GetValue()<<"\n";
440  std::cout<<" hw clibration factors= "<<fQwQPDCalibration[i]<<"\n";
441  std::cout<<" hw fRelPos["<<kAxisLabel[i]<<"]="<<fRelPos[i].GetValue()<<"\n \n";
442  std::cout<<" hw fAbsPos["<<kAxisLabel[i]<<"]="<<fAbsPos[i].GetValue()<<"\n \n";
443  }
444  }
445 
446  return;
447 }
448 
449 
450 Int_t QwQPD::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer,UInt_t index)
451 {
452  if(index<4)
453  {
454  fPhotodiode[index].ProcessEvBuffer(buffer,word_position_in_buffer);
455  }
456  else
457  {
458  std::cerr <<
459  "QwQPD::ProcessEvBuffer(): attemp to fill in raw date for a wire that doesn't exist \n";
460  }
461  return word_position_in_buffer;
462 }
463 
464 
465 TString QwQPD::GetSubElementName(Int_t subindex)
466 {
467  TString thisname;
468  if(subindex<4&&subindex>-1)
469  thisname=fPhotodiode[subindex].GetElementName();
470  else
471  std::cerr<<"QwQPD::GetSubElementName for "<<
472  GetElementName()<<" this subindex doesn't exists \n";
473 
474  return thisname;
475 }
476 
477 UInt_t QwQPD::GetSubElementIndex(TString subname)
478 {
479  subname.ToUpper();
480  UInt_t localindex=kInvalidSubelementIndex;
481  for(Short_t i=0;i<4;i++) if(subname==subelement[i])localindex=i;
482 
483  if(localindex>3)
484  std::cerr << "QwQPD::GetSubElementIndex is unable to associate the string -"
485  <<subname<<"- to any index"<<std::endl;
486 
487  return localindex;
488 }
489 
491 {
492  *(dynamic_cast<QwQPD*>(this)) = *(dynamic_cast<const QwQPD*>(&value));
493  return *this;
494 }
495 
497 {
498  if (GetElementName()!=""){
499  Short_t i = 0;
501  for(i=0;i<4;i++) this->fPhotodiode[i]=value.fPhotodiode[i];
502  for(i=kXAxis;i<kNumAxes;i++){
503  this->fRelPos[i]=value.fRelPos[i];
504  this->fAbsPos[i]=value.fAbsPos[i];
505  }
506  }
507  return *this;
508 }
509 
511 {
512  *(dynamic_cast<QwQPD*>(this)) += *(dynamic_cast<const QwQPD*>(&value));
513  return *this;
514 }
515 
517 {
518  if (GetElementName()!=""){
519  Short_t i = 0;
520  this->fEffectiveCharge+=value.fEffectiveCharge;
521  for(i=0;i<4;i++) this->fPhotodiode[i]+=value.fPhotodiode[i];
522 
523  for(i=kXAxis;i<kNumAxes;i++){
524  this->fRelPos[i]+=value.fRelPos[i];
525  this->fAbsPos[i]+=value.fAbsPos[i];
526  }
527  }
528  return *this;
529 }
530 
532 {
533  *(dynamic_cast<QwQPD*>(this)) -= *(dynamic_cast<const QwQPD*>(&value));
534  return *this;
535 }
536 
538 {
539  if (GetElementName()!=""){
540  Short_t i = 0;
541  this->fEffectiveCharge-=value.fEffectiveCharge;
542  for(i=0;i<4;i++) this->fPhotodiode[i]-=value.fPhotodiode[i];
543 
544  for(i=kXAxis;i<kNumAxes;i++){
545  this->fRelPos[i]-=value.fRelPos[i];
546  this->fAbsPos[i]-=value.fAbsPos[i];
547  }
548  }
549  return *this;
550 }
551 
552 
553 void QwQPD::Ratio(QwQPD &numer, QwQPD &denom)
554 {
555  // this function is called when forming asymmetries. In this case what we actually want for the
556  // QPD is the difference only not the asymmetries
557 
558  *this=numer;
560  return;
561 }
562 
563 
564 
565 void QwQPD::Scale(Double_t factor)
566 {
567  Short_t i = 0;
568 
569  for(i=0;i<4;i++) fPhotodiode[i].Scale(factor);
570  for(i=kXAxis;i<kNumAxes;i++){
571  fRelPos[i].Scale(factor);
572  fAbsPos[i].Scale(factor);
573  }
574  fEffectiveCharge.Scale(factor);
575  return;
576 }
577 
579 {
580  Short_t i = 0;
581  for(i=0;i<4;i++) fPhotodiode[i].CalculateRunningAverage();
582  for (i = 0; i < 2; i++){
585  }
587  return;
588 }
589 
591 {
592  AccumulateRunningSum(*dynamic_cast<const QwQPD* >(&value));
593 }
594 
596 {
597  Short_t i = 0;
598  for(i=0;i<4;i++) fPhotodiode[i].AccumulateRunningSum(value.fPhotodiode[i]);
599  for (i = 0; i < 2; i++){
600  fRelPos[i].AccumulateRunningSum(value.fRelPos[i]);
601  fAbsPos[i].AccumulateRunningSum(value.fAbsPos[i]);
602  }
604  return;
605 
606 
607 }
608 
610 {
611  DeaccumulateRunningSum(*dynamic_cast<QwQPD* >(&value));
612 }
613 
615 {
616 
617  Short_t i = 0;
618  for(i=0;i<4;i++) fPhotodiode[i].DeaccumulateRunningSum(value.fPhotodiode[i]);
619  for (i = 0; i < 2; i++){
622  }
624  return;
625 
626 
627 }
628 
629 
630 
631 void QwQPD::ConstructHistograms(TDirectory *folder, TString &prefix)
632 {
633 
634  if (GetElementName()=="") {
635  // This channel is not used, so skip filling the histograms.
636  } else {
637  fEffectiveCharge.ConstructHistograms(folder, prefix);
638  TString thisprefix=prefix;
639 
640  if(prefix=="asym_")
641  thisprefix="diff_";
642  SetRootSaveStatus(prefix);
643  Short_t i = 0;
644  if(bFullSave) {
645  for(i=0;i<4;i++) fPhotodiode[i].ConstructHistograms(folder, thisprefix);
646  }
647  for(i=kXAxis;i<kNumAxes;i++) {
648  fAbsPos[i].ConstructHistograms(folder, thisprefix);
649  fRelPos[i].ConstructHistograms(folder, thisprefix);
650  }
651  }
652  return;
653 }
654 
656 {
657  if (GetElementName()=="") {
658  // This channel is not used, so skip filling the histograms.
659  }
660  else {
662  Short_t i = 0;
663  if(bFullSave) {
664  for(i=0;i<4;i++) fPhotodiode[i].FillHistograms();
665  }
666  for(i=kXAxis;i<kNumAxes;i++){
667  fAbsPos[i].FillHistograms();
668  fRelPos[i].FillHistograms();
669  }
670  }
671  return;
672 }
673 
674 void QwQPD::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
675 {
676  if (GetElementName()==""){
677  // This channel is not used, so skip constructing trees.
678  }
679  else {
680  TString thisprefix=prefix;
681  if(prefix=="asym_")
682  thisprefix="diff_";
683 
684  SetRootSaveStatus(prefix);
685 
686  fEffectiveCharge.ConstructBranchAndVector(tree,prefix,values);
687  Short_t i = 0;
688  if(bFullSave) {
689  for(i=0;i<4;i++) fPhotodiode[i].ConstructBranchAndVector(tree,thisprefix,values);
690  }
691  for(i=kXAxis;i<kNumAxes;i++) {
692  fAbsPos[i].ConstructBranchAndVector(tree,thisprefix,values);
693  fRelPos[i].ConstructBranchAndVector(tree,thisprefix,values);
694  }
695 
696  }
697  return;
698 }
699 
700 void QwQPD::ConstructBranch(TTree *tree, TString &prefix)
701 {
702  if (GetElementName()==""){
703  // This channel is not used, so skip constructing trees.
704  }
705  else {
706  TString thisprefix=prefix;
707  if(prefix=="asym_")
708  thisprefix="diff_";
709 
710  SetRootSaveStatus(prefix);
711 
712  fEffectiveCharge.ConstructBranch(tree,prefix);
713  Short_t i = 0;
714  if(bFullSave) {
715  for(i=0;i<4;i++) fPhotodiode[i].ConstructBranch(tree,thisprefix);
716  }
717  for(i=kXAxis;i<kNumAxes;i++) {
718  fAbsPos[i].ConstructBranch(tree,thisprefix);
719  fRelPos[i].ConstructBranch(tree,thisprefix);
720  }
721 
722  }
723  return;
724 }
725 
726 void QwQPD::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist)
727 {
728  TString devicename;
729 
730  devicename=GetElementName();
731  devicename.ToLower();
732  if (GetElementName()==""){
733  // This channel is not used, so skip filling the histograms.
734  } else
735  {
736  if (modulelist.HasValue(devicename)){
737  TString thisprefix=prefix;
738  if(prefix=="asym_")
739  thisprefix="diff_";
740 
741  SetRootSaveStatus(prefix);
742 
743  fEffectiveCharge.ConstructBranch(tree,prefix);
744  Short_t i = 0;
745  if(bFullSave) {
746  for(i=0;i<4;i++) fPhotodiode[i].ConstructBranch(tree,thisprefix);
747  }
748  for(i=kXAxis;i<kNumAxes;i++) {
749  fAbsPos[i].ConstructBranch(tree,thisprefix);
750  fRelPos[i].ConstructBranch(tree,thisprefix);
751  }
752 
753  QwMessage <<" Tree leaves added to "<<devicename<<" Corresponding channels"<<QwLog::endl;
754  }
755  // this functions doesn't do anything yet
756  }
757 
758 
759 
760 
761 
762  return;
763 }
764 
765 void QwQPD::FillTreeVector(std::vector<Double_t> &values) const
766 {
767  if (GetElementName()=="") {
768  // This channel is not used, so skip filling the tree.
769  }
770  else {
772  Short_t i = 0;
773  if(bFullSave) {
774  for(i=0;i<4;i++) fPhotodiode[i].FillTreeVector(values);
775  }
776 
777  for(i=kXAxis;i<kNumAxes;i++){
778  fAbsPos[i].FillTreeVector(values);
779  fRelPos[i].FillTreeVector(values);
780  }
781  }
782  return;
783 }
784 
785 
786 
787 void QwQPD::SetEventCutMode(Int_t bcuts)
788 {
789  Short_t i = 0;
790  // bEVENTCUTMODE=bcuts;
791  for (i=0;i<4;i++) fPhotodiode[i].SetEventCutMode(bcuts);
792  for (i=kXAxis;i<kNumAxes;i++) {
793  fAbsPos[i].SetEventCutMode(bcuts);
794  fRelPos[i].SetEventCutMode(bcuts);
795  }
797 }
798 
799 
801 {
802  for (size_t i = kXAxis; i < kNumAxes; i++) {
803  QwVQWK_Channel abspos(fAbsPos[i]);
804  abspos = fAbsPos[i];
805  fQPDElementList.push_back(abspos);
806  }
807  QwVQWK_Channel effectivecharge(fEffectiveCharge);
808  effectivecharge = fEffectiveCharge;
809  fQPDElementList.push_back(effectivecharge);
810 }
811 
812 
813 std::vector<QwDBInterface> QwQPD::GetDBEntry()
814 {
815  std::vector <QwDBInterface> row_list;
816  row_list.clear();
817  for(size_t i=kXAxis;i<kNumAxes;i++) {
818  fAbsPos[i].AddEntriesToList(row_list);
819  }
821  return row_list;
822 
823 
824 }
825 
826 
827 std::vector<QwErrDBInterface> QwQPD::GetErrDBEntry()
828 {
829  std::vector <QwErrDBInterface> row_list;
830  row_list.clear();
831  for(size_t i=kXAxis;i<kNumAxes;i++) {
832  fAbsPos[i].AddErrEntriesToList(row_list);
833  }
835  return row_list;
836 
837 
838 }
839 
840 
841 
842 /**********************************
843  * Mock data generation routines
844  **********************************/
845 
846 void QwQPD::SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY)
847 {
848  // Average values of the signals in the stripline ADCs
849  Double_t sumX = 1.1e8; // These are just guesses, but I made X and Y different
850  Double_t sumY = 0.9e8; // to make it more interesting for the analyzer...
851 
852 
853  // Determine the asymmetry from the position
854  Double_t meanXP = (1.0 + meanX / fQwQPDCalibration[0]) * sumX / 2.0;
855  Double_t meanXM = (1.0 - meanX / fQwQPDCalibration[0]) * sumX / 2.0; // = sumX - meanXP;
856  Double_t meanYP = (1.0 + meanY / fQwQPDCalibration[1]) * sumY / 2.0;
857  Double_t meanYM = (1.0 - meanY / fQwQPDCalibration[1]) * sumY / 2.0; // = sumY - meanYP;
858 
859  // Determine the spread of the asymmetry (this is not tested yet)
860  // (negative sigma should work in the QwVQWK_Channel, but still using fabs)
861  Double_t sigmaXP = fabs(sumX * sigmaX / meanX);
862  Double_t sigmaXM = sigmaXP;
863  Double_t sigmaYP = fabs(sumY * sigmaY / meanY);
864  Double_t sigmaYM = sigmaYP;
865 
866  // Propagate these parameters to the ADCs
867  fPhotodiode[0].SetRandomEventParameters(meanXP, sigmaXP);
868  fPhotodiode[1].SetRandomEventParameters(meanXM, sigmaXM);
869  fPhotodiode[2].SetRandomEventParameters(meanYP, sigmaYP);
870  fPhotodiode[3].SetRandomEventParameters(meanYM, sigmaYM);
871 }
872 
873 
874 void QwQPD::RandomizeEventData(int helicity, double time)
875 {
876  for (Short_t i=0; i<4; i++) fPhotodiode[i].RandomizeEventData(helicity, time);
877 
878  return;
879 }
880 
881 
882 void QwQPD::SetEventData(Double_t* relpos, UInt_t sequencenumber)
883 {
884  for (Short_t i=0; i<2; i++)
885  {
886  fAbsPos[i].SetHardwareSum(relpos[i], sequencenumber);
887  }
888 
889  return;
890 }
891 
892 
893 void QwQPD::EncodeEventData(std::vector<UInt_t> &buffer)
894 {
895  for (Short_t i=0; i<4; i++) fPhotodiode[i].EncodeEventData(buffer);
896 }
897 
898 
899 void QwQPD::SetDefaultSampleSize(Int_t sample_size)
900 {
901  for(Short_t i=0;i<4;i++) fPhotodiode[i].SetDefaultSampleSize((size_t)sample_size);
902  return;
903 }
904 
905 
906 void QwQPD::SetSubElementPedestal(Int_t j, Double_t value)
907 {
908  fPhotodiode[j].SetPedestal(value);
909  return;
910 }
911 
912 void QwQPD::SetSubElementCalibrationFactor(Int_t j, Double_t value)
913 {
915  return;
916 }
917 
void MakeQPDList()
Definition: QwQPD.cc:800
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
Bool_t ApplySingleEventCuts()
Definition: QwQPD.cc:183
void CalculateRunningAverage()
Definition: QwQPD.cc:578
Double_t fRelativeGains[2]
Definition: VQwBPM.h:258
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t index=0)
Decode the event data from a CODA buffer.
void SetSubElementCalibrationFactor(Int_t j, Double_t value)
Definition: QwQPD.cc:912
void ProcessEvent()
Process the event data according to pedestal and calibration factor.
size_t GetNumberOfSamples() const
Int_t ApplyHWChecks()
void SetEventData(Double_t *block, UInt_t sequencenumber)
Definition: QwQPD.cc:882
void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY)
Definition: QwQPD.cc:846
void SetRootSaveStatus(TString &prefix)
Definition: VQwBPM.cc:178
void SetRandomEventParameters(Double_t mean, Double_t sigma)
Set the normal random event parameters.
Definition: MQwMockable.cc:41
void FillTreeVector(std::vector< Double_t > &values) const
Definition: QwQPD.cc:765
static const Bool_t bDEBUG
Definition: VQwBPM.h:275
void ClearEventData()
Clear the event data in this element.
Definition: QwQPD.cc:89
void InitializeChannel(TString name)
Definition: QwQPD.cc:20
void SetDefaultSampleSize(Int_t sample_size)
Definition: QwQPD.cc:899
void DeaccumulateRunningSum(const QwVQWK_Channel &value)
void IncrementErrorCounters()
Definition: QwQPD.cc:123
void Ratio(const QwVQWK_Channel &numer, const QwVQWK_Channel &denom)
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
void PrintInfo() const
Print multiple lines of information about this data element.
void SetPedestal(Double_t ped)
VQwBPM & operator-=(const VQwBPM &value)
Definition: QwQPD.cc:531
void AccumulateRunningSum(const QwQPD &value)
Definition: QwQPD.cc:595
Double_t GetValue(size_t element) const
std::vector< QwErrDBInterface > GetErrDBEntry()
Definition: QwQPD.cc:827
Double_t fQwQPDCalibration[2]
Definition: QwQPD.h:148
void SetEventCutMode(Int_t bcuts)
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel.
Definition: QwQPD.cc:787
static const double e
Definition: QwUnits.h:91
void SetEventCutMode(Int_t bcuts)
VQwBPM & operator=(const VQwBPM &value)
Definition: QwQPD.cc:490
void Scale(Double_t Offset)
void ProcessEvent()
Definition: QwQPD.cc:354
void ConstructBranch(TTree *tree, TString &prefix)
static const TString kAxisLabel[2]
Definition: VQwBPM.h:239
static const UInt_t kInvalidSubelementIndex
Definition: QwTypes.h:191
QwVQWK_Channel fPhotodiode[4]
Definition: QwQPD.h:152
virtual UInt_t GetErrorCode() const
Bool_t ApplyHWChecks()
Definition: QwQPD.cc:106
void FillHistograms()
Fill the histograms for this data element.
Definition: QwQPD.cc:655
void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber=0)
std::vector< QwVQWK_Channel > fQPDElementList
Definition: QwQPD.h:160
void RandomizeEventData(int helicity=0, double time=0.0)
Definition: QwQPD.cc:874
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
VQwHardwareChannel * GetSubelementByName(TString ch_name)
Definition: QwQPD.cc:214
Bool_t bFullSave
Definition: VQwBPM.h:273
Bool_t HasValue(TString &vname)
void Scale(Double_t factor)
Definition: QwQPD.cc:565
void DeaccumulateRunningSum(VQwBPM &value)
Definition: QwQPD.cc:609
virtual UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
void SetCalibrationFactor(Double_t factor)
void ConstructBranch(TTree *tree, TString &prefix)
Definition: QwQPD.cc:700
void AddEntriesToList(std::vector< QwDBInterface > &row_list)
void ClearEventData()
Clear the event data in this element.
QwVQWK_Channel fAbsPos[2]
Definition: QwQPD.h:157
Bool_t ApplySingleEventCuts(Double_t LL, Double_t UL)
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
Definition: QwQPD.cc:631
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t indexnumber)
Process the CODA event buffer for this element.
Definition: QwQPD.cc:450
void FillTreeVector(std::vector< Double_t > &values) const
QwVQWK_Channel fRelPos[2]
Definition: QwQPD.h:153
void InitializeChannel(TString name)
Definition: VQwBPM.cc:25
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Definition: QwQPD.cc:674
TString GetSubElementName(Int_t subindex)
Definition: QwQPD.cc:465
VQwBPM & operator+=(const VQwBPM &value)
Definition: QwQPD.cc:510
std::vector< QwDBInterface > GetDBEntry()
Definition: QwQPD.cc:813
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
Definition: QwQPD.cc:163
void FillHistograms()
Fill the histograms for this data element.
void Ratio(QwQPD &numer, QwQPD &denom)
Definition: QwQPD.cc:553
void Sum(const QwVQWK_Channel &value1, const QwVQWK_Channel &value2)
static UInt_t GetSubElementIndex(TString subname)
Definition: QwQPD.cc:477
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
Definition: QwQPD.cc:135
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Definition: VQwBPM.h:34
TString fElementName
Name of this data element.
virtual const TString & GetElementName() const
Get the name of this element.
void Difference(const QwVQWK_Channel &value1, const QwVQWK_Channel &value2)
void EncodeEventData(std::vector< UInt_t > &buffer)
Definition: QwQPD.cc:893
void GetCalibrationFactors(Double_t AlphaX, Double_t AlphaY)
Definition: QwQPD.cc:68
static const TString subelement[4]
Definition: QwQPD.h:146
size_t GetSequenceNumber() const
void InitializeChannel(TString name, TString datatosave)
Initialize the fields in this object.
void AddErrEntriesToList(std::vector< QwErrDBInterface > &row_list)
void IncrementErrorCounters()
QwVQWK_Channel fEffectiveCharge
Definition: QwQPD.h:158
void CalculateRunningAverage()
UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
Definition: QwQPD.cc:147
void AccumulateRunningSum(const QwVQWK_Channel &value)
void SetSubElementPedestal(Int_t j, Double_t value)
Definition: QwQPD.cc:906
Definition: QwQPD.h:32