QwAnalysis
QwMainCerenkovDetector.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwMainCerenkovDetector.cc *
3 * *
4 * Author: P. M. King *
5 * Time-stamp: <2007-05-08 15:40> *
6 \**********************************************************/
7 
9 
10 // System headers
11 #include <sstream>
12 
13 // Qweak headers
14 #include "QwSubsystemArray.h"
15 #include "QwLog.h"
16 #define MYSQLPP_SSQLS_NO_STATICS
17 #include "QwParitySSQLS.h"
18 #include "QwParityDB.h"
19 #include "QwPromptSummary.h"
20 
21 // Register this subsystem with the factory
23 
24 /**
25  * Defines configuration options for QwEventBuffer class using QwOptions
26  * functionality.
27  *
28  * @param options Options object
29  */
31  // Define the execution options
32  options.AddOptions()
33  ("QwMainCerenkovDetector.normalize",
34  po::value<bool>()->default_bool_value(true),
35  "Normalize the detectors by beam current");
36 }
37 
38 
39 /*!
40  * Loads the configuration options into this instance of
41  * QwMainCerenkovDetector from the QwOptions object.
42  *
43  * @param options Options object
44  */
46  bNormalization = options.GetValue<bool>("QwMainCerenkovDetector.normalize");
47  if (! bNormalization){
48  QwWarning << "QwMainCerenkovDetector::ProcessOptions: "
49  << "Detector yields WILL NOT be normalized."
50  << QwLog::endl;
51  }
52 }
53 
54 
55 //*****************************************************************//
56 /**
57  * Publish internal values
58  * @return
59  */
61 {
62  // Publish variables
63  Bool_t status = kTRUE;
64 
65  status = status && PublishInternalValue("qwk_md1neg", "qwk_md1neg", GetIntegrationPMT("qwk_md1neg")->GetChannel("qwk_md1neg"));
66  status = status && PublishInternalValue("qwk_md1pos", "qwk_md1pos", GetIntegrationPMT("qwk_md1pos")->GetChannel("qwk_md1pos"));
67  status = status && PublishInternalValue("qwk_md2neg", "qwk_md2neg", GetIntegrationPMT("qwk_md2neg")->GetChannel("qwk_md2neg"));
68  status = status && PublishInternalValue("qwk_md2pos", "qwk_md2pos", GetIntegrationPMT("qwk_md2pos")->GetChannel("qwk_md2pos"));
69  status = status && PublishInternalValue("qwk_md3neg", "qwk_md3neg", GetIntegrationPMT("qwk_md3neg")->GetChannel("qwk_md3neg"));
70  status = status && PublishInternalValue("qwk_md3pos", "qwk_md3pos", GetIntegrationPMT("qwk_md3pos")->GetChannel("qwk_md3pos"));
71  status = status && PublishInternalValue("qwk_md4neg", "qwk_md4neg", GetIntegrationPMT("qwk_md4neg")->GetChannel("qwk_md4neg"));
72  status = status && PublishInternalValue("qwk_md4pos", "qwk_md4pos", GetIntegrationPMT("qwk_md4pos")->GetChannel("qwk_md4pos"));
73  status = status && PublishInternalValue("qwk_md5neg", "qwk_md5neg", GetIntegrationPMT("qwk_md5neg")->GetChannel("qwk_md5neg"));
74  status = status && PublishInternalValue("qwk_md5pos", "qwk_md5pos", GetIntegrationPMT("qwk_md5pos")->GetChannel("qwk_md5pos"));
75  status = status && PublishInternalValue("qwk_md6neg", "qwk_md6neg", GetIntegrationPMT("qwk_md6neg")->GetChannel("qwk_md6neg"));
76  status = status && PublishInternalValue("qwk_md6pos", "qwk_md6pos", GetIntegrationPMT("qwk_md6pos")->GetChannel("qwk_md6pos"));
77  status = status && PublishInternalValue("qwk_md7neg", "qwk_md7neg", GetIntegrationPMT("qwk_md7neg")->GetChannel("qwk_md7neg"));
78  status = status && PublishInternalValue("qwk_md7pos", "qwk_md7pos", GetIntegrationPMT("qwk_md7pos")->GetChannel("qwk_md7pos"));
79  status = status && PublishInternalValue("qwk_md8neg", "qwk_md8neg", GetIntegrationPMT("qwk_md8neg")->GetChannel("qwk_md8neg"));
80  status = status && PublishInternalValue("qwk_md8pos", "qwk_md8pos", GetIntegrationPMT("qwk_md8pos")->GetChannel("qwk_md8pos"));
81  status = status && PublishInternalValue("qwk_md9neg", "qwk_md9neg", GetIntegrationPMT("qwk_md9neg")->GetChannel("qwk_md9neg"));
82  status = status && PublishInternalValue("qwk_md9pos", "qwk_md9pos", GetIntegrationPMT("qwk_md9pos")->GetChannel("qwk_md9pos"));
83 
84  status = status && PublishInternalValue("qwk_md1barsum","qwk_md1barsum", GetCombinedPMT("qwk_md1barsum")->GetChannel("qwk_md1barsum"));
85  status = status && PublishInternalValue("qwk_md2barsum","qwk_md2barsum", GetCombinedPMT("qwk_md2barsum")->GetChannel("qwk_md2barsum"));
86  status = status && PublishInternalValue("qwk_md3barsum","qwk_md3barsum", GetCombinedPMT("qwk_md3barsum")->GetChannel("qwk_md3barsum"));
87  status = status && PublishInternalValue("qwk_md4barsum","qwk_md4barsum", GetCombinedPMT("qwk_md4barsum")->GetChannel("qwk_md4barsum"));
88  status = status && PublishInternalValue("qwk_md5barsum","qwk_md5barsum", GetCombinedPMT("qwk_md5barsum")->GetChannel("qwk_md5barsum"));
89  status = status && PublishInternalValue("qwk_md6barsum","qwk_md6barsum", GetCombinedPMT("qwk_md6barsum")->GetChannel("qwk_md6barsum"));
90  status = status && PublishInternalValue("qwk_md7barsum","qwk_md7barsum", GetCombinedPMT("qwk_md7barsum")->GetChannel("qwk_md7barsum"));
91  status = status && PublishInternalValue("qwk_md8barsum","qwk_md8barsum", GetCombinedPMT("qwk_md8barsum")->GetChannel("qwk_md8barsum"));
92 
93  status = status && PublishInternalValue("qwk_mdallbars","qwk_mdallbars", GetCombinedPMT("qwk_mdallbars")->GetChannel("qwk_mdallbars"));
94 
95  return status;
96 
97 
98  // TODO:
99  // The variables should be published based on the parameter file.
100  // See QwBeamLine class for an implementation.
101 
102  // Publish variables through map file
103  // This should work with bcm, bpmstripline, bpmcavity, combo bpm and combo bcm
104  for (size_t pp = 0; pp < fPublishList.size(); pp++) {
105  TString publish_name = fPublishList.at(pp).at(0);
106  TString device_type = fPublishList.at(pp).at(1);
107  TString device_name = fPublishList.at(pp).at(2);
108  TString device_prop = fPublishList.at(pp).at(3);
109  device_type.ToLower();
110  device_prop.ToLower();
111 
112  const VQwHardwareChannel* tmp_channel;
113  if (device_type == "integrationpmt") {
114  tmp_channel = GetIntegrationPMT(device_name)->GetChannel(device_name);
115  } else if (device_type == "combinedpmt") {
116  tmp_channel = GetCombinedPMT(device_name)->GetChannel(device_name);
117  } else
118  QwError << "QwBeamLine::PublishInternalValues() error "<< QwLog::endl;
119 
120  if (tmp_channel == NULL) {
121  QwError << "QwBeamLine::PublishInternalValues(): " << publish_name << " not found" << QwLog::endl;
122  status |= kFALSE;
123  } else {
124  QwDebug << "QwBeamLine::PublishInternalValues(): " << publish_name << " found" << QwLog::endl;
125  }
126  status = status && PublishInternalValue(publish_name, publish_name, tmp_channel);
127 
128  }
129 
130  return status;
131 }
132 
133 
134 //*****************************************************************//
136 {
137  Bool_t ldebug=kFALSE;
138 
139  std::vector<TString> combinedchannelnames;
140  std::vector<Double_t> weight;
141  Int_t currentrocread=0;
142  Int_t currentbankread=0;
143  Int_t wordsofar=0;
144  Int_t currentsubbankindex=-1;
145  Int_t sample_size=0;
146 
147 
148 
149  // Open the file
150  QwParameterFile mapstr(mapfile.Data());
151  TString varname, varvalue;
152 
153  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
154  while (mapstr.ReadNextLine())
155  {
156  mapstr.TrimComment('!'); // Remove everything after a '!' character.
157  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
158  if (mapstr.LineIsEmpty()) continue;
159 
160  if (mapstr.HasVariablePair("=",varname,varvalue))
161  {
162  // This is a declaration line. Decode it.
163  varname.ToLower();
164  UInt_t value = QwParameterFile::GetUInt(varvalue);
165 
166  if (varname=="roc")
167  {
168  currentrocread=value;
169  RegisterROCNumber(value,0);
170  }
171  else if (varname=="bank")
172  {
173  currentbankread=value;
174  RegisterSubbank(value);
175  }
176  else if (varname=="sample_size")
177  {
178  sample_size=value;
179  }
180  }
181  else
182  {
183  Bool_t lineok = kTRUE;
184  TString keyword = "";
185  TString keyword2 = "";
186  TString modtype = "";
187  TString dettype = "";
188  TString namech = "";
189  Int_t modnum = 0;
190  Int_t channum = 0;
191 
192  modtype = mapstr.GetTypedNextToken<TString>(); // module type
193 
194  if (modtype == "VQWK")
195  {
196  modnum = mapstr.GetTypedNextToken<Int_t>(); //slot number
197  channum = mapstr.GetTypedNextToken<Int_t>(); //channel number
198  dettype = mapstr.GetTypedNextToken<TString>(); //type-purpose of the detector
199  dettype.ToLower();
200  namech = mapstr.GetTypedNextToken<TString>(); //name of the detector
201  namech.ToLower();
202 
203  keyword = mapstr.GetTypedNextToken<TString>();
204  keyword.ToLower();
205  keyword2 = mapstr.GetTypedNextToken<TString>();
206  keyword2.ToLower();
207  }
208  else if (modtype == "VPMT")
209  {
210  channum = mapstr.GetTypedNextToken<Int_t>(); //channel number
211  Int_t combinedchans = mapstr.GetTypedNextToken<Int_t>(); //number of combined channels
212  dettype = mapstr.GetTypedNextToken<TString>(); //type-purpose of the detector
213  dettype.ToLower();
214  namech = mapstr.GetTypedNextToken<TString>(); //name of the detector
215  namech.ToLower();
216  combinedchannelnames.clear();
217  for (int i=0; i<combinedchans; i++)
218  {
219  TString nameofcombinedchan = mapstr.GetTypedNextToken<TString>();
220  nameofcombinedchan.ToLower();
221  combinedchannelnames.push_back(nameofcombinedchan);
222  }
223  weight.clear();
224  for (int i=0; i<combinedchans; i++)
225  {
226  weight.push_back( mapstr.GetTypedNextToken<Double_t>());
227  }
228  keyword = mapstr.GetTypedNextToken<TString>();
229  keyword.ToLower();
230  keyword2 = mapstr.GetTypedNextToken<TString>();
231  keyword2.ToLower();
232  }
233 
234 
235  if (currentsubbankindex!=GetSubbankIndex(currentrocread,currentbankread))
236  {
237  currentsubbankindex=GetSubbankIndex(currentrocread,currentbankread);
238  wordsofar=0;
239  }
240 
241  QwMainCerenkovDetectorID localMainDetID;
242  localMainDetID.fdetectorname=namech;
243  localMainDetID.fmoduletype=modtype;
244  localMainDetID.fSubbankIndex=currentsubbankindex;
245  localMainDetID.fdetectortype=dettype;
246 
247  // localMainDetID.fWordInSubbank=wordsofar;
248  if (modtype=="VQWK"){
249  Int_t offset = QwVQWK_Channel::GetBufferOffset(modnum, channum);
250  if (offset>0){
251  localMainDetID.fWordInSubbank = wordsofar + offset;
252  }
253  }
254  else if (modtype=="VPMT")
255  {
256  localMainDetID.fCombinedChannelNames = combinedchannelnames;
257  localMainDetID.fWeight = weight;
258  //std::cout<<"Add in a combined channel"<<std::endl;
259  }
260  else
261  {
262  QwError << "QwMainCerenkovDetector::LoadChannelMap: Unknown module type: "
263  << modtype <<", the detector "<<namech<<" will not be decoded "
264  << QwLog::endl;
265  lineok=kFALSE;
266  continue;
267  }
268 
269  localMainDetID.fTypeID=GetDetectorTypeID(dettype);
270  if (localMainDetID.fTypeID==kQwUnknownPMT) {
271  QwError << "QwMainCerenkovDetector::LoadChannelMap: Unknown detector type: "
272  << dettype <<", the detector "<<namech<<" will not be decoded "
273  << QwLog::endl;
274  lineok=kFALSE;
275  continue;
276  }
277 
278  localMainDetID.fIndex= GetDetectorIndex(localMainDetID.fTypeID,
279  localMainDetID.fdetectorname);
280 
281  if (localMainDetID.fIndex==-1)
282  {
283  if (localMainDetID.fTypeID==kQwIntegrationPMT)
284  {
285  QwIntegrationPMT localIntegrationPMT(GetSubsystemName(),localMainDetID.fdetectorname);
286  if (keyword=="not_blindable"
287  || keyword2=="not_blindable")
288  localIntegrationPMT.SetBlindability(kFALSE);
289  else
290  localIntegrationPMT.SetBlindability(kTRUE);
291  if (keyword=="not_normalizable"
292  || keyword2=="not_normalizable")
293  localIntegrationPMT.SetNormalizability(kFALSE);
294  else
295  localIntegrationPMT.SetNormalizability(kTRUE);
296  fIntegrationPMT.push_back(localIntegrationPMT);
297  fIntegrationPMT[fIntegrationPMT.size()-1].SetDefaultSampleSize(sample_size);
298  localMainDetID.fIndex=fIntegrationPMT.size()-1;
299  }
300 
301  else if (localMainDetID.fTypeID==kQwCombinedPMT)
302  {
303  QwCombinedPMT localcombinedPMT(GetSubsystemName(),localMainDetID.fdetectorname);
304  if (keyword=="not_normalizable"
305  || keyword2=="not_normalizable")
306  localcombinedPMT.SetNormalizability(kFALSE);
307  else
308  localcombinedPMT.SetNormalizability(kTRUE);
309  if (keyword=="not_blindable"
310  || keyword2 =="not_blindable")
311  localcombinedPMT.SetBlindability(kFALSE);
312  else
313  localcombinedPMT.SetBlindability(kTRUE);
314  fCombinedPMT.push_back(localcombinedPMT);
315  fCombinedPMT[fCombinedPMT.size()-1].SetDefaultSampleSize(sample_size);
316  localMainDetID.fIndex=fCombinedPMT.size()-1;
317  }
318  }
319 
320  if (ldebug)
321  {
322  localMainDetID.Print();
323  std::cout<<"line ok=";
324  if (lineok) std::cout<<"TRUE"<<std::endl;
325  else
326  std::cout<<"FALSE"<<std::endl;
327  }
328 
329  if (lineok)
330  fMainDetID.push_back(localMainDetID);
331  }
332  }
333 
334 
335  //std::cout<<"linking combined channels"<<std::endl;
336 
337  for (size_t i=0; i<fMainDetID.size(); i++)
338  {
339  if (fMainDetID[i].fTypeID==kQwCombinedPMT)
340  {
341  Int_t ind = fMainDetID[i].fIndex;
342 
343  //check to see if all required channels are available
344  if (ldebug)
345  {
346  std::cout<<"fMainDetID[i].fCombinedChannelNames.size()="
347  <<fMainDetID[i].fCombinedChannelNames.size()<<std::endl<<"name list: ";
348  for (size_t n=0; n<fMainDetID[i].fCombinedChannelNames.size(); n++)
349  std::cout<<" "<<fMainDetID[i].fCombinedChannelNames[n];
350  std::cout<<std::endl;
351  }
352 
353  Int_t chanmatched=0;
354  for (size_t j=0; j<fMainDetID[i].fCombinedChannelNames.size(); j++)
355  {
356 
357  for (size_t k=0; k<fMainDetID.size(); k++)
358  {
359  if (fMainDetID[i].fCombinedChannelNames[j]==fMainDetID[k].fdetectorname)
360  {
361  if (ldebug)
362  std::cout<<"found a to-be-combined channel candidate"<<std::endl;
363  chanmatched ++;
364  break;
365  }
366  }
367  }
368 
369  if ((Int_t) fMainDetID[i].fCombinedChannelNames.size()==chanmatched)
370  {
371  for (size_t l=0; l<fMainDetID[i].fCombinedChannelNames.size(); l++)
372  {
373  Int_t ind_pmt = GetDetectorIndex(GetDetectorTypeID("integrationpmt"),
374  fMainDetID[i].fCombinedChannelNames[l]);
375 
376  fCombinedPMT[ind].Add(&fIntegrationPMT[ind_pmt],fMainDetID[i].fWeight[l]);
377  }
378  fCombinedPMT[ind].LinkChannel(fMainDetID[i].fdetectorname);
379  if (ldebug)
380  std::cout<<"linked a combined channel"<<std::endl;
381  }
382  else
383  {
384  std::cerr<<"cannot combine void channels for "<<fMainDetID[i].fdetectorname<<std::endl;
385  fMainDetID[i].fIndex = -1;
386  continue;
387  }
388  }
389  }
390 
391 
392  // Now load the variables to publish
393  mapstr.RewindToFileStart();
394  QwParameterFile *section;
395  std::vector<TString> publishinfo;
396  while ((section = mapstr.ReadNextSection(varvalue))) {
397  if (varvalue == "PUBLISH") {
398  fPublishList.clear();
399  while (section->ReadNextLine()) {
400  section->TrimComment(); // Remove everything after a comment character
401  section->TrimWhitespace(); // Get rid of leading and trailing spaces
402  for (int ii = 0; ii < 4; ii++) {
403  varvalue = section->GetNextToken().c_str();
404  if (varvalue.Length()) {
405  publishinfo.push_back(varvalue);
406  }
407  }
408  if (publishinfo.size() == 4)
409  fPublishList.push_back(publishinfo);
410  publishinfo.clear();
411  }
412  }
413  }
414  // Print list of variables to publish
415  QwMessage << "Variables to publish:" << QwLog::endl;
416  for (size_t jj = 0; jj < fPublishList.size(); jj++)
417  QwMessage << fPublishList.at(jj).at(0) << " " << fPublishList.at(jj).at(1) << " "
418  << fPublishList.at(jj).at(2) << " " << fPublishList.at(jj).at(3) << QwLog::endl;
419 
420  if (ldebug)
421  {
422  std::cout<<"Done with Load channel map\n";
423  for (size_t i=0;i<fMainDetID.size();i++)
424  if (fMainDetID[i].fIndex>=0)
425  fMainDetID[i].Print();
426  }
427  ldebug=kFALSE;
428  mapstr.Close(); // Close the file (ifstream)
429  return 0;
430 }
431 
432 
434 {
435  Int_t eventcut_flag = 1;
436 
437  // Open the file
438  QwParameterFile mapstr(filename.Data());
439  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
440  while (mapstr.ReadNextLine())
441  {
442  //std::cout<<"********* In the loop *************"<<std::endl;
443  mapstr.TrimComment('!'); // Remove everything after a '!' character.
444  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
445  if (mapstr.LineIsEmpty()) continue;
446  TString varname, varvalue;
447  if (mapstr.HasVariablePair("=",varname,varvalue))
448  {
449  if (varname=="EVENTCUTS")
450  {
451  //varname="";
452  eventcut_flag = QwParameterFile::GetUInt(varvalue);
453  //std::cout<<"EVENT CUT FLAG "<<eventcut_flag<<std::endl;
454  }
455  }
456  else
457  {
458  TString device_type = mapstr.GetTypedNextToken<TString>();
459  device_type.ToLower();
460  TString device_name = mapstr.GetTypedNextToken<TString>();
461  device_name.ToLower();
462  Int_t det_index = GetDetectorIndex(GetDetectorTypeID(device_type),device_name);
463  if (det_index == -1) {
464  QwWarning << " Device not found " << device_name << " of type " << device_type << QwLog::endl;
465  continue;
466  }
467 
468  if (device_type == GetQwPMTInstrumentTypeName(kQwIntegrationPMT)){
469  Double_t LLX = mapstr.GetTypedNextToken<Double_t>(); //lower limit for IntegrationPMT value
470  Double_t ULX = mapstr.GetTypedNextToken<Double_t>(); //upper limit for IntegrationPMT value
471  varvalue = mapstr.GetTypedNextToken<TString>();//global/local
472  varvalue.ToLower();
473  Double_t stabilitycut = mapstr.GetTypedNextToken<Double_t>();
474  QwMessage << "QwMainCerenkovDetector Error Code passing to QwIntegrationPMT " << GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut) << QwLog::endl;
475 
476  //std::cout<<"*****************************"<<std::endl;
477  //std::cout<<" Type "<<device_type<<" Name "<<device_name<<" Index ["<<det_index <<"] "<<" device flag "<<check_flag<<std::endl;
478 
479  fIntegrationPMT[det_index].SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut),LLX,ULX,stabilitycut);
480  //std::cout<<"*****************************"<<std::endl;
481 
482  } else if (device_type == GetQwPMTInstrumentTypeName(kQwCombinedPMT)){
483  Double_t LLX = mapstr.GetTypedNextToken<Double_t>(); //lower limit for CombinedPMT value
484  Double_t ULX = mapstr.GetTypedNextToken<Double_t>(); //upper limit for CombinedPMT value
485  varvalue = mapstr.GetTypedNextToken<TString>();//global/local
486  varvalue.ToLower();
487  Double_t stabilitycut = mapstr.GetTypedNextToken<Double_t>();
488  QwMessage << "QwMainCerenkovDetector Error Code passing to QwCombinedPMT " << GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut) << QwLog::endl;
489 
490  //std::cout<<"*****************************"<<std::endl;
491  //std::cout<<" Type "<<device_type<<" Name "<<device_name<<" Index ["<<det_index <<"] "<<" device flag "<<check_flag<<std::endl;
492 
493  fCombinedPMT[det_index].SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut),LLX,ULX,stabilitycut);
494  //std::cout<<"*****************************"<<std::endl;
495 
496  }
497 
498  }
499 
500  }
501  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
502  fIntegrationPMT[i].SetEventCutMode(eventcut_flag);
503  for (size_t i = 0; i < fCombinedPMT.size(); i++)
504  fCombinedPMT[i].SetEventCutMode(eventcut_flag);
505 
506  fMainDetErrorCount = 0; //set the error counter to zero
507  mapstr.Close(); // Close the file (ifstream)
508  return 0;
509 }
510 
511 
512 
514 {
515  Bool_t ldebug=kFALSE;
516  TString varname;
517  Double_t varped;
518  Double_t varcal;
519  TString localname;
520 
521  Int_t lineread=0;
522 
523  QwParameterFile mapstr(pedestalfile.Data()); //Open the file
524  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
525 
526  while (mapstr.ReadNextLine())
527  {
528  lineread+=1;
529  if (ldebug)std::cout<<" line read so far ="<<lineread<<"\n";
530  mapstr.TrimComment('!'); // Remove everything after a '!' character.
531  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
532  if (mapstr.LineIsEmpty()) continue;
533  else
534  {
535  varname = mapstr.GetTypedNextToken<TString>(); //name of the channel
536  varname.ToLower();
537  varname.Remove(TString::kBoth,' ');
538  varped= mapstr.GetTypedNextToken<Double_t>(); // value of the pedestal
539  varcal= mapstr.GetTypedNextToken<Double_t>(); // value of the calibration factor
540  if (ldebug) std::cout<<"inputs for channel "<<varname
541  <<": ped="<<varped<<": cal="<<varcal<<"\n";
542  Bool_t notfound=kTRUE;
543 
544  if (notfound)
545  for (size_t i=0;i<fIntegrationPMT.size();i++)
546  if (fIntegrationPMT[i].GetElementName()==varname)
547  {
548  fIntegrationPMT[i].SetPedestal(varped);
549  fIntegrationPMT[i].SetCalibrationFactor(varcal);
550  i=fIntegrationPMT.size()+1;
551  notfound=kFALSE;
552  i=fIntegrationPMT.size()+1;
553  }
554  }
555 
556  }
557  if (ldebug) std::cout<<" line read in the pedestal + cal file ="<<lineread<<" \n";
558 
559  ldebug=kFALSE;
560  mapstr.Close(); // Close the file (ifstream)
561  return 0;
562 }
563 
564 
566 {
567  Bool_t test=kTRUE;
568  return test;
569 }
570 
572 {
573  for (size_t i=0;i<fIntegrationPMT.size();i++){
574  fIntegrationPMT[i].ClearEventData();
575  }
576  for (size_t i=0;i<fCombinedPMT.size();i++)
578 
579  return;
580 }
581 
582 
583 /********************************************************/
584 void QwMainCerenkovDetector::SetRandomEventParameters(Double_t mean, Double_t sigma)
585 {
586  for (size_t i = 0; i < fMainDetID.size(); i++)
587  {
588  // This is a QwIntegrationPMT
589  if (fMainDetID.at(i).fTypeID == kQwIntegrationPMT)
590  fIntegrationPMT[fMainDetID.at(i).fIndex].SetRandomEventParameters(mean, sigma);
591  }
592 
593 }
594 
596 {
597  for (size_t i = 0; i < fMainDetID.size(); i++)
598  {
599  // This is a QwIntegrationPMT
600  if (fMainDetID.at(i).fTypeID == kQwIntegrationPMT)
601  fIntegrationPMT[fMainDetID.at(i).fIndex].SetRandomEventAsymmetry(asymmetry);
602  }
603 
604 }
605 
606 void QwMainCerenkovDetector::RandomizeEventData(int helicity, double time)
607 {
608  for (size_t i = 0; i < fMainDetID.size(); i++)
609  {
610  // This is a QwIntegrationPMT
611  if (fMainDetID.at(i).fTypeID == kQwIntegrationPMT)
612  fIntegrationPMT[fMainDetID.at(i).fIndex].RandomizeEventData(helicity, time);
613  }
614 
615 }
616 
617 void QwMainCerenkovDetector::EncodeEventData(std::vector<UInt_t> &buffer)
618 {
619  std::vector<UInt_t> elements;
620  elements.clear();
621 
622  // Get all buffers in the order they are defined in the map file
623  for (size_t i = 0; i < fMainDetID.size(); i++)
624  {
625  // This is a QwIntegrationPMT
626  if (fMainDetID.at(i).fTypeID == kQwIntegrationPMT)
627  fIntegrationPMT[fMainDetID.at(i).fIndex].EncodeEventData(elements);
628  }
629 
630  // If there is element data, generate the subbank header
631  std::vector<UInt_t> subbankheader;
632  std::vector<UInt_t> rocheader;
633  if (elements.size() > 0)
634  {
635 
636  // Form CODA subbank header
637  subbankheader.clear();
638  subbankheader.push_back(elements.size() + 1); // subbank size
639  subbankheader.push_back((fCurrentBank_ID << 16) | (0x01 << 8) | (1 & 0xff));
640  // subbank tag | subbank type | event number
641 
642  // Form CODA bank/roc header
643  rocheader.clear();
644  rocheader.push_back(subbankheader.size() + elements.size() + 1); // bank/roc size
645  rocheader.push_back((fCurrentROC_ID << 16) | (0x10 << 8) | (1 & 0xff));
646  // bank tag == ROC | bank type | event number
647 
648  // Add bank header, subbank header and element data to output buffer
649  buffer.insert(buffer.end(), rocheader.begin(), rocheader.end());
650  buffer.insert(buffer.end(), subbankheader.begin(), subbankheader.end());
651  buffer.insert(buffer.end(), elements.begin(), elements.end());
652  }
653 }
654 
655 
656 
657 Int_t QwMainCerenkovDetector::ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
658 {
659 
660  /* Int_t index = GetSubbankIndex(roc_id,bank_id);
661  if (index>=0 && num_words>0){
662  // We want to process the configuration data for this ROC.
663  UInt_t words_read = 0;
664  for (size_t i = 0; i < fMainDetID.size(); i++) {
665  words_read += fIntegrationPMT[i].ProcessConfigurationBuffer(&(buffer[words_read]),
666  num_words-words_read);
667  }
668  }*/
669  return 0;
670 }
671 
672 
673 Int_t QwMainCerenkovDetector::ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
674 {
675  Bool_t lkDEBUG=kFALSE;
676 
677  Int_t index = GetSubbankIndex(roc_id,bank_id);
678 
679  if (index>=0 && num_words>0)
680  {
681  // We want to process this ROC. Begin looping through the data.
682  if (lkDEBUG)
683  std::cout << "QwMainCerenkovDetector::ProcessEvBuffer: "
684  << "Begin processing ROC" << roc_id
685  << " and subbank "<<bank_id
686  << " number of words="<<num_words<<std::endl;
687 
688  for (size_t i=0;i<fMainDetID.size();i++)
689  {
690  if (fMainDetID[i].fSubbankIndex==index)
691  {
692 
693  if (fMainDetID[i].fTypeID == kQwIntegrationPMT)
694  {
695  if (lkDEBUG)
696  {
697  std::cout<<"found IntegrationPMT data for "<<fMainDetID[i].fdetectorname<<std::endl;
698  std::cout<<"word left to read in this buffer:"<<num_words-fMainDetID[i].fWordInSubbank<<std::endl;
699  }
700  fIntegrationPMT[fMainDetID[i].fIndex].ProcessEvBuffer(&(buffer[fMainDetID[i].fWordInSubbank]),
701  num_words-fMainDetID[i].fWordInSubbank);
702  }
703  }
704  }
705  }
706 
707  return 0;
708 }
709 
710 
711 
713 {
714  Bool_t status=kTRUE;
715  for(size_t i=0;i<fIntegrationPMT.size();i++){
716  status &= fIntegrationPMT[i].ApplySingleEventCuts();
717  if(!status && bDEBUG) std::cout<<"******* QwMainCerenkovDetector::SingleEventCuts()->IntegrationPMT[ "<<i<<" , "<<fIntegrationPMT[i].GetElementName()<<" ] ******\n";
718  }
719  for(size_t i=0;i<fCombinedPMT.size();i++){
720  status &= fCombinedPMT[i].ApplySingleEventCuts();
721  if(!status && bDEBUG) std::cout<<"******* QwMainCerenkovDetector::SingleEventCuts()->CombinedPMT[ "<<i<<" , "<<fCombinedPMT[i].GetElementName()<<" ] ******\n";
722  }
723 
724 
725  if (!status)
726  fMainDetErrorCount++;//failed event counter for QwMainCerenkovDetector
727 
728  return status;
729 
730 
731 }
732 
733 
734 UInt_t QwMainCerenkovDetector::GetEventcutErrorFlag() //return the error flag
735 {
736  UInt_t ErrorFlag;
737  ErrorFlag=0;
738  for(size_t i=0;i<fIntegrationPMT.size();i++){
739  ErrorFlag |= fIntegrationPMT[i].GetEventcutErrorFlag();
740  }
741  for(size_t i=0;i<fCombinedPMT.size();i++){
742  ErrorFlag |= fCombinedPMT[i].GetEventcutErrorFlag();
743  }
744  return ErrorFlag;
745 }
746 
748 {
749  for(size_t i=0;i<fIntegrationPMT.size();i++){
750  fIntegrationPMT[i].IncrementErrorCounters();
751  }
752  for(size_t i=0;i<fCombinedPMT.size();i++){
753  fCombinedPMT[i].IncrementErrorCounters();
754  }
755 }
756 
757 //inherited from the VQwSubsystemParity; this will display the error summary
759 {
760  QwMessage<<"*********QwMainCerenkovDetector Error Summary****************"<<QwLog::endl;
762  for(size_t i=0;i<fIntegrationPMT.size();i++){
763  //std::cout<<" IntegrationPMT ["<<i<<"] "<<std::endl;
764  fIntegrationPMT[i].PrintErrorCounters();
765  }
766  for(size_t i=0;i<fCombinedPMT.size();i++){
767  //std::cout<<" CombinedPMT ["<<i<<"] "<<std::endl;
768  fCombinedPMT[i].PrintErrorCounters();
769  }
771 }
772 
774  VQwSubsystem* tmp = const_cast<VQwSubsystem*>(ev_error);
775  if(Compare(tmp)){
776  const QwMainCerenkovDetector* input = dynamic_cast<const QwMainCerenkovDetector*> (ev_error);
777 
778  for (size_t i=0;i<input->fIntegrationPMT.size();i++)
779  this->fIntegrationPMT[i].UpdateErrorFlag(&(input->fIntegrationPMT[i]));
780 
781  for (size_t i=0;i<input->fCombinedPMT.size();i++)
782  this->fCombinedPMT[i].UpdateErrorFlag(&(input->fCombinedPMT[i]));
783  }
784 };
785 
786 
788 {
789  for (size_t i=0;i<fIntegrationPMT.size();i++)
791 
792  for (size_t i=0;i<fCombinedPMT.size();i++)
793  {
794  //std::cout<<"Process combination "<<i<<std::endl;
795  fCombinedPMT[i].ProcessEvent();
796 
797  }
798 
799  return;
800 }
801 
802 /**
803  * Exchange data between subsystems
804  */
806 {
807  //QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData "<< QwLog::endl;
808  bIsExchangedDataValid = kTRUE;
809  if (bNormalization){
810  // Create a list of all variables that we need
811  // TODO This could be a static list to avoid repeated vector initializiations
812  /*
813  std::vector<VQwDataElement*> variable_list;
814  variable_list.push_back(&fTargetCharge);
815  variable_list.push_back(&fTargetX);
816  variable_list.push_back(&fTargetY);
817  variable_list.push_back(&fTargetXprime);
818  variable_list.push_back(&fTargetYprime);
819  variable_list.push_back(&fTargetEnergy);
820  */
821 
822  // Loop over all variables in the list
823  /*
824  //IMPORTANT NOTE ABOUT THE COMMENTED LOOP
825  //NAMES OF THE variable_list DEVICES WILL BE OVER WRITTEN BY ACTUAL NAMES OF DATA ELEMENTS THAT WE ARE READING FROM THE
826  //ROUTINE RequestExternalValue(variable->GetElementName(), variable). DO TRY THIS AT HOME!
827 
828 
829  std::vector<VQwDataElement*>::iterator variable_iter;
830  for (variable_iter = variable_list.begin(); variable_iter != variable_list.end(); variable_iter++){
831  VQwDataElement* variable = *variable_iter;
832  //QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData for loop "<<variable->GetElementName()<< QwLog::endl;
833  if (RequestExternalValue(variable->GetElementName(), variable))
834  {
835  if (bDEBUG)
836  dynamic_cast<QwVQWK_Channel*>(variable)->PrintInfo();
837  //QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData Found "<<variable->GetElementName()<< QwLog::endl;
838  }
839  else
840  {
841  bIsExchangedDataValid = kFALSE;
842  QwError << GetSubsystemName() << " could not get external value for "
843  << variable->GetElementName() << QwLog::endl;
844  }
845  } // end of loop over variables
846 
847  */
848 
849  if(RequestExternalValue("q_targ", &fTargetCharge)){
850  if (bDEBUG){
851  QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData Found "<<fTargetCharge.GetElementName()<< QwLog::endl;
852  //QwWarning <<"****QwMainCerenkovDetector****"<< QwLog::endl;
853  (dynamic_cast<QwVQWK_Channel*>(&fTargetCharge))->PrintInfo();
854  }
855  }
856  else{
857  bIsExchangedDataValid = kFALSE;
858  QwError << GetSubsystemName() << " could not get external value for "
859  << fTargetCharge.GetElementName() << QwLog::endl;
860  }
861  /*
862  if(RequestExternalValue("x_targ", &fTargetX)){
863  if (bDEBUG){
864  dynamic_cast<QwVQWK_Channel*>(&fTargetX)->PrintInfo();
865  QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData Found "<<fTargetX.GetElementName()<< QwLog::endl;
866  }
867  }else{
868  bIsExchangedDataValid = kFALSE;
869  QwError << GetSubsystemName() << " could not get external value for "
870  << fTargetX.GetElementName() << QwLog::endl;
871  }
872 
873  if(RequestExternalValue("y_targ", &fTargetY)){
874  if (bDEBUG){
875  dynamic_cast<QwVQWK_Channel*>(&fTargetY)->PrintInfo();
876  QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData Found "<<fTargetY.GetElementName()<< QwLog::endl;
877  }
878  }else{
879  bIsExchangedDataValid = kFALSE;
880  QwError << GetSubsystemName() << " could not get external value for "
881  << fTargetY.GetElementName() << QwLog::endl;
882  }
883 
884  if(RequestExternalValue("xp_targ", &fTargetXprime)){
885  if (bDEBUG){
886  dynamic_cast<QwVQWK_Channel*>(&fTargetXprime)->PrintInfo();
887  QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData Found "<<fTargetXprime.GetElementName()<< QwLog::endl;
888  }
889  }else{
890  bIsExchangedDataValid = kFALSE;
891  QwError << GetSubsystemName() << " could not get external value for "
892  << fTargetXprime.GetElementName() << QwLog::endl;
893  }
894 
895  if(RequestExternalValue("yp_targ", &fTargetYprime)){
896  if (bDEBUG){
897  dynamic_cast<QwVQWK_Channel*>(&fTargetYprime)->PrintInfo();
898  QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData Found "<<fTargetYprime.GetElementName()<< QwLog::endl;
899  }
900  }else{
901  bIsExchangedDataValid = kFALSE;
902  QwError << GetSubsystemName() << " could not get external value for "
903  << fTargetYprime.GetElementName() << QwLog::endl;
904  }
905 
906  if(RequestExternalValue("e_targ", &fTargetEnergy)){
907  if (bDEBUG){
908  dynamic_cast<QwVQWK_Channel*>(&fTargetEnergy)->PrintInfo();
909  QwWarning << "QwMainCerenkovDetector::ExchangeProcessedData Found "<<fTargetEnergy.GetElementName()<< QwLog::endl;
910  }
911  }else{
912  bIsExchangedDataValid = kFALSE;
913  QwError << GetSubsystemName() << " could not get external value for "
914  << fTargetEnergy.GetElementName() << QwLog::endl;
915  }
916  */
917 
918 
919  }
920 }
921 
922 
924 {
926  {
927  //data is valid, process it
928  if (bDEBUG)
929  {
930  Double_t pedestal = fTargetCharge.GetPedestal();
931  Double_t calfactor = fTargetCharge.GetCalibrationFactor();
932  Double_t volts = fTargetCharge.GetAverageVolts();
933  std::cout<<"QwMainCerenkovDetector::ProcessEvent_2(): processing with exchanged data"<<std::endl;
934  std::cout<<"pedestal, calfactor, average volts = "<<pedestal<<", "<<calfactor<<", "<<volts<<std::endl;
935  }
936 
937  if (bNormalization) this->DoNormalization();
938  }
939  else
940  {
941  QwWarning<<"QwMainCerenkovDetector::ProcessEvent_2(): could not get all external values."<<QwLog::endl;
942  }
943 }
944 
945 
946 
947 
948 void QwMainCerenkovDetector::ConstructHistograms(TDirectory *folder, TString &prefix)
949 {
950  for (size_t i=0;i<fIntegrationPMT.size();i++)
951  fIntegrationPMT[i].ConstructHistograms(folder,prefix);
952 
953  for (size_t i=0;i<fCombinedPMT.size();i++)
954  fCombinedPMT[i].ConstructHistograms(folder,prefix);
955  return;
956 }
957 
958 
960 {
961  for (size_t i=0;i<fIntegrationPMT.size();i++)
963 
964  for (size_t i=0;i<fCombinedPMT.size();i++)
966 
967  return;
968 }
969 
970 
971 void QwMainCerenkovDetector::ConstructBranchAndVector(TTree *tree, TString & prefix, std::vector <Double_t> &values)
972 {
973  for (size_t i=0;i<fIntegrationPMT.size();i++)
974  fIntegrationPMT[i].ConstructBranchAndVector(tree, prefix, values);
975 
976  for (size_t i=0;i<fCombinedPMT.size();i++)
977  fCombinedPMT[i].ConstructBranchAndVector(tree, prefix, values);
978 
979  return;
980 }
981 
982 void QwMainCerenkovDetector::ConstructBranch(TTree *tree, TString & prefix)
983 {
984  for (size_t i=0;i<fIntegrationPMT.size();i++)
985  fIntegrationPMT[i].ConstructBranch(tree, prefix);
986 
987  for (size_t i=0;i<fCombinedPMT.size();i++)
988  fCombinedPMT[i].ConstructBranch(tree, prefix);
989 
990  return;
991 }
992 
993 void QwMainCerenkovDetector::ConstructBranch(TTree *tree, TString & prefix, QwParameterFile& trim_file)
994 {
995  TString tmp;
996  QwParameterFile* nextmodule;
997  trim_file.RewindToFileStart();
998  tmp="QwIntegrationPMT";
999  trim_file.RewindToFileStart();
1000  if (trim_file.FileHasModuleHeader(tmp)){
1001  nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
1002  for (size_t i=0;i<fIntegrationPMT.size();i++)
1003 
1004  fIntegrationPMT[i].ConstructBranch(tree, prefix, *nextmodule);
1005  }
1006 
1007  tmp="QwCombinedPMT";
1008  trim_file.RewindToFileStart();
1009  if (trim_file.FileHasModuleHeader(tmp)){
1010  nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
1011  for (size_t i=0;i<fCombinedPMT.size();i++)
1012  fCombinedPMT[i].ConstructBranch(tree, prefix, *nextmodule );
1013  }
1014 
1015  return;
1016 }
1017 
1018 void QwMainCerenkovDetector::FillTreeVector(std::vector<Double_t> &values) const
1019 {
1020  for (size_t i=0;i<fIntegrationPMT.size();i++)
1021  fIntegrationPMT[i].FillTreeVector(values);
1022 
1023  for (size_t i=0;i<fCombinedPMT.size();i++)
1024  fCombinedPMT[i].FillTreeVector(values);
1025 
1026  return;
1027 }
1028 
1029 
1031 {
1032  return GetIntegrationPMT(name);
1033 }
1034 
1035 
1037 {
1038  // std::cout<<" Here in QwLumi::Compare \n";
1039 
1040  Bool_t res=kTRUE;
1041  if (typeid(*value)!=typeid(*this))
1042  {
1043  res=kFALSE;
1044  // std::cout<<" types are not ok \n";
1045  // std::cout<<" this is bypassed just for now but should be fixed eventually \n";
1046  }
1047  else
1048  {
1049  QwMainCerenkovDetector* input = dynamic_cast<QwMainCerenkovDetector*>(value);
1050  if (input->fIntegrationPMT.size()!=fIntegrationPMT.size() ||
1051  input->fCombinedPMT.size()!=fCombinedPMT.size() )
1052  {
1053  res=kFALSE;
1054  // std::cout<<" not the same number of channels \n";
1055  }
1056  }
1057  return res;
1058 }
1059 
1060 
1062 {
1063  // std::cout<<" here in QwMainCerenkovDetector::operator= \n";
1064  if (Compare(value))
1065  {
1066 // VQwSubsystem::operator=(value);
1067  QwMainCerenkovDetector* input = dynamic_cast<QwMainCerenkovDetector*> (value);
1068 
1069  for (size_t i=0;i<input->fIntegrationPMT.size();i++)
1070  this->fIntegrationPMT[i]=input->fIntegrationPMT[i];
1071 
1072  for (size_t i=0;i<input->fCombinedPMT.size();i++)
1073  (this->fCombinedPMT[i])=(input->fCombinedPMT[i]);
1074  }
1075  return *this;
1076 }
1077 
1078 
1080 {
1081  if (Compare(value))
1082  {
1083  QwMainCerenkovDetector* input= dynamic_cast<QwMainCerenkovDetector*>(value) ;
1084 
1085  for (size_t i=0;i<input->fIntegrationPMT.size();i++)
1086  this->fIntegrationPMT[i]+=input->fIntegrationPMT[i];
1087 
1088  for (size_t i=0;i<input->fCombinedPMT.size();i++)
1089  this->fCombinedPMT[i]+=input->fCombinedPMT[i];
1090 
1091  }
1092  return *this;
1093 }
1094 
1095 
1097 {
1098 
1099  if (Compare(value))
1100  {
1101  QwMainCerenkovDetector* input= dynamic_cast<QwMainCerenkovDetector*>(value);
1102 
1103  for (size_t i=0;i<input->fIntegrationPMT.size();i++)
1104  this->fIntegrationPMT[i]-=input->fIntegrationPMT[i];
1105 
1106  for (size_t i=0;i<input->fCombinedPMT.size();i++)
1107  this->fCombinedPMT[i]-=input->fCombinedPMT[i];
1108 
1109  }
1110  return *this;
1111 }
1112 
1113 
1114 
1116 {
1117  if (Compare(value1)&&Compare(value2))
1118  {
1119  *this = value1;
1120  *this += value2;
1121  }
1122 }
1123 
1125 {
1126  if (Compare(value1)&&Compare(value2))
1127  {
1128  *this = value1;
1129  *this -= value2;
1130  }
1131 }
1132 
1134 {
1135  if (Compare(numer)&&Compare(denom))
1136  {
1137  QwMainCerenkovDetector* innumer= dynamic_cast<QwMainCerenkovDetector*>(numer) ;
1138  QwMainCerenkovDetector* indenom= dynamic_cast<QwMainCerenkovDetector*>(denom) ;
1139 
1140  for (size_t i=0;i<innumer->fIntegrationPMT.size();i++)
1141  this->fIntegrationPMT[i].Ratio(innumer->fIntegrationPMT[i],indenom->fIntegrationPMT[i]);
1142 
1143  for (size_t i=0;i<innumer->fCombinedPMT.size();i++)
1144  this->fCombinedPMT[i].Ratio(innumer->fCombinedPMT[i],indenom->fCombinedPMT[i]);
1145 
1146  }
1147  return;
1148 }
1149 
1150 
1151 void QwMainCerenkovDetector::Scale(Double_t factor)
1152 {
1153  for (size_t i=0;i<fIntegrationPMT.size();i++)
1154  fIntegrationPMT[i].Scale(factor);
1155 
1156  for (size_t i=0;i<fCombinedPMT.size();i++)
1157  fCombinedPMT[i].Scale(factor);
1158 
1159  return;
1160 }
1161 
1162 //*****************************************************************//
1164 {
1165  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1166  fIntegrationPMT[i].Normalize(denom);
1167  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1168  fCombinedPMT[i].Normalize(denom);
1169 }
1170 
1171 
1172 
1174 {
1175  for (size_t i=0;i<fIntegrationPMT.size();i++)
1177 
1178  for (size_t i=0;i<fCombinedPMT.size();i++)
1180 
1181  return;
1182 }
1183 
1185 {
1186  if (Compare(value1)) {
1187  QwMainCerenkovDetector* value = dynamic_cast<QwMainCerenkovDetector*>(value1);
1188 
1189  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1191  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1193  }
1194 }
1195 
1197  if (Compare(value1)) {
1198  QwMainCerenkovDetector* value = dynamic_cast<QwMainCerenkovDetector*>(value1);
1199 
1200  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1202  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1204  }
1205 };
1206 
1207 
1208 /**
1209  * Blind the asymmetry
1210  * @param blinder Blinder
1211  */
1213 {
1214  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1215  fIntegrationPMT[i].Blind(blinder);
1216  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1217  fCombinedPMT[i].Blind(blinder);
1218 }
1219 
1220 /**
1221  * Blind the difference using the yield
1222  * @param blinder Blinder
1223  * @param subsys Subsystem
1224  */
1226 {
1227  /// \todo TODO (wdc) At some point we should introduce const-correctness in
1228  /// the Compare() routine to ensure nothing funny happens. This const_casting
1229  /// is just an ugly stop-gap measure.
1230  if (Compare(const_cast<VQwSubsystemParity*>(subsys))) {
1231 
1232  const QwMainCerenkovDetector* yield = dynamic_cast<const QwMainCerenkovDetector*>(subsys);
1233  if (yield == 0) return;
1234 
1235  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1236  fIntegrationPMT[i].Blind(blinder, yield->fIntegrationPMT[i]);
1237  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1238  fCombinedPMT[i].Blind(blinder, yield->fCombinedPMT[i]);
1239  }
1240 }
1241 
1243 {
1244  return GetQwPMTInstrumentType(name);
1245 }
1246 
1247 //*****************************************************************//
1249 {
1250  Bool_t ldebug=kFALSE;
1251  if (ldebug)
1252  {
1253  std::cout<<"QwMainCerenkovDetector::GetDetectorIndex\n";
1254  std::cout<<"type_id=="<<type_id<<" name="<<name<<"\n";
1255  std::cout<<fMainDetID.size()<<" already registered detector\n";
1256  }
1257 
1258  Int_t result=-1;
1259  for (size_t i=0;i<fMainDetID.size();i++)
1260  {
1261  if (fMainDetID[i].fTypeID==type_id)
1262  if (fMainDetID[i].fdetectorname==name)
1263  {
1264  result=fMainDetID[i].fIndex;
1265  if (ldebug)
1266  std::cout<<"testing against ("<<fMainDetID[i].fTypeID
1267  <<","<<fMainDetID[i].fdetectorname<<")=>"<<result<<"\n";
1268  }
1269  }
1270 
1271  return result;
1272 }
1273 
1275 {
1276  TString tmpname = name;
1277  tmpname.ToLower();
1278  if (! fIntegrationPMT.empty())
1279  {
1280  for (size_t i=0;i<fIntegrationPMT.size();i++)
1281  {
1282  if (fIntegrationPMT.at(i).GetElementName() == tmpname)
1283  {
1284  //std::cout<<"Get IntegrationPMT "<<tmpname<<std::endl;
1285  return &(fIntegrationPMT.at(i));
1286  }
1287  }
1288  }
1289  QwMessage << "QwMainCerenkovDetector::GetIntegrationPMT: cannot find channel " << tmpname << QwLog::endl;
1290  return NULL;
1291 }
1292 
1294 {
1295  TString tmpname = name;
1296  tmpname.ToLower();
1297  if (! fCombinedPMT.empty())
1298  {
1299  for (size_t i=0;i<fCombinedPMT.size();i++)
1300  {
1301  if (fCombinedPMT.at(i).GetElementName() == tmpname)
1302  {
1303  //std::cout<<"Get CombinedPMT "<<tmpname<<std::endl;
1304  return &(fCombinedPMT.at(i));
1305  }
1306  }
1307  }
1308  QwMessage << "QwMainCerenkovDetector::GetCombinedPMT: cannot find channel " << tmpname << QwLog::endl;
1309  return NULL;
1310 }
1311 
1313 {
1315  {
1316  try
1317  {
1318  this->Normalize(&fTargetCharge);
1319  }
1320  catch (std::exception& e)
1321  {
1322  std::cerr << e.what() << std::endl;
1323  }
1324  }
1325 }
1326 
1327 void QwMainCerenkovDetector::FillDB(QwParityDB *db, TString datatype)
1328 {
1329  Bool_t local_print_flag = false;
1330 
1331  if(local_print_flag) {
1332  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1333  QwMessage << " QwMainCerenkovDetector::FillDB " << QwLog::endl;
1334  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1335  }
1336 
1337  std::vector<QwDBInterface> interface;
1338  std::vector<QwParitySSQLS::md_data> entrylist;
1339 
1340  UInt_t analysis_id = db->GetAnalysisID();
1341 
1342  TString measurement_type;
1343  measurement_type = QwDBInterface::DetermineMeasurementTypeID(datatype);
1344 
1345  UInt_t i,j;
1346  i = j = 0;
1347  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "IntegrationPMT" <<QwLog::endl;
1348 
1349  for(i=0; i<fIntegrationPMT.size(); i++) {
1350  interface.clear();
1351  interface = fIntegrationPMT[i].GetDBEntry();
1352  for(j=0; j<interface.size(); j++) {
1353  interface.at(j).SetAnalysisID( analysis_id );
1354  interface.at(j).SetMainDetectorID( db );
1355  interface.at(j).SetMeasurementTypeID( measurement_type );
1356  interface.at(j).PrintStatus( local_print_flag );
1357  interface.at(j).AddThisEntryToList( entrylist );
1358  }
1359  }
1360 
1361  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined PMT" <<QwLog::endl;
1362 
1363  for(i=0; i< fCombinedPMT.size(); i++)
1364  {
1365  interface.clear();
1366  interface = fCombinedPMT[i].GetDBEntry();
1367  for(j=0; j<interface.size(); j++) {
1368  interface.at(j).SetAnalysisID( analysis_id );
1369  interface.at(j).SetMainDetectorID( db );
1370  interface.at(j).SetMeasurementTypeID( measurement_type );
1371  interface.at(j).PrintStatus( local_print_flag );
1372  interface.at(j).AddThisEntryToList( entrylist );
1373  }
1374  }
1375  if(local_print_flag) {
1376  QwMessage << QwColor(Qw::kGreen) << "Entrylist Size : "
1377  << QwColor(Qw::kBoldRed) << entrylist.size()
1379  }
1380 
1381  db->Connect();
1382  // Check the entrylist size, if it isn't zero, start to query..
1383  if( entrylist.size() ) {
1384  mysqlpp::Query query= db->Query();
1385  query.insert(entrylist.begin(), entrylist.end());
1386  query.execute();
1387  }
1388  else {
1389  QwMessage << "QwMainCerenkovDetector::FillDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() << QwLog::endl;
1390  }
1391  db->Disconnect();
1392  return;
1393 }
1394 
1396 {
1397  QwMessage << "=== QwMainCerenkovDetector: " << GetSubsystemName() << " ===" << QwLog::endl;
1398  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1400  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1401  fCombinedPMT[i].PrintValue();
1402 }
1403 
1405 {
1406  std::cout<<"Name of the subsystem ="<<fSystemName<<"\n";
1407 
1408  std::cout<<"there are "<<fIntegrationPMT.size()<<" IntegrationPMT \n";
1409  std::cout<<" "<<fCombinedPMT.size()<<" CombinedPMT \n";
1410 
1411  std::cout<<" Printing Running AVG and other channel info"<<std::endl;
1412 
1413  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1415  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1416  fCombinedPMT[i].PrintInfo();
1417 }
1418 
1420 {
1421  for (size_t i=0;i<fMainDetID.size();i++)
1422  {
1423  std::cout<<"============================="<<std::endl;
1424  std::cout<<" Detector ID="<<i<<std::endl;
1425  fMainDetID[i].Print();
1426  }
1427  return;
1428 }
1429 
1430 
1431 
1432 
1434 {
1435 
1436  Bool_t local_print_flag = false;
1437  if(local_print_flag){
1438  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1439  QwMessage << " QwMainCerenkovDetectorID::FillErrDB " << QwLog::endl;
1440  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1441  }
1442 
1443 
1444  std::vector<QwErrDBInterface> interface;
1445  std::vector<QwParitySSQLS::md_errors> entrylist;
1446 
1447  UInt_t analysis_id = db->GetAnalysisID();
1448 
1449  UInt_t i,j;
1450  i = j = 0;
1451  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "IntegrationPMT" <<QwLog::endl;
1452 
1453  for(i=0; i<fIntegrationPMT.size(); i++) {
1454  interface.clear();
1455  interface = fIntegrationPMT[i].GetErrDBEntry();
1456  for(j=0; j<interface.size(); j++) {
1457  interface.at(j).SetAnalysisID ( analysis_id );
1458  interface.at(j).SetMainDetectorID ( db );
1459  interface.at(j).PrintStatus ( local_print_flag );
1460  interface.at(j).AddThisEntryToList( entrylist );
1461  }
1462  }
1463 
1464  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined PMT" <<QwLog::endl;
1465 
1466  for(i=0; i< fCombinedPMT.size(); i++)
1467  {
1468  interface.clear();
1469  interface = fCombinedPMT[i].GetErrDBEntry();
1470  for(j=0; j<interface.size(); j++) {
1471  interface.at(j).SetAnalysisID ( analysis_id );
1472  interface.at(j).SetMainDetectorID ( db );
1473  interface.at(j).PrintStatus ( local_print_flag );
1474  interface.at(j).AddThisEntryToList( entrylist );
1475  }
1476  }
1477  if(local_print_flag) {
1478  QwMessage << QwColor(Qw::kGreen) << "Entrylist Size : "
1479  << QwColor(Qw::kBoldRed) << entrylist.size()
1481  }
1482 
1483  db->Connect();
1484  // Check the entrylist size, if it isn't zero, start to query..
1485  if( entrylist.size() ) {
1486  mysqlpp::Query query= db->Query();
1487  query.insert(entrylist.begin(), entrylist.end());
1488  query.execute();
1489  }
1490  else {
1491  QwMessage << "QwMainCerenkovDetector::FillErrDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() << QwLog::endl;
1492  }
1493  db->Disconnect();
1494 
1495  return;
1496 };
1497 
1498 
1499 
1501 {
1502 
1503  Bool_t local_print_flag = true;
1504  if(local_print_flag){
1505  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1506  QwMessage << " QwMainCerenkovDetectorID::WritePromptSummary() " << QwLog::endl;
1507  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1508  }
1509 
1510  // ps->PrintCSV();
1511 
1512  return;
1513 }
1514 
1515 
1516 
1518 {
1519 
1520  std::cout<<std::endl<<"Detector name= "<<fdetectorname<<std::endl;
1521  std::cout<<"SubbankkIndex= "<<fSubbankIndex<<std::endl;
1522  std::cout<<"word index in subbank= "<<fWordInSubbank<<std::endl;
1523  std::cout<<"module type= "<<fmoduletype<<std::endl;
1524  std::cout<<"detector type= "<<fdetectortype<<" index= "<<fTypeID<<std::endl;
1525  std::cout<<"Index of this detector in the vector of similar detector= "<<fIndex<<std::endl;
1526  std::cout<<"Subelement index= "<<fSubelement<<std::endl;
1527  std::cout<<"==========================================\n";
1528 
1529  return;
1530 }
1531 
1532 
1533 
1534 
Int_t GetSubbankIndex() const
Definition: VQwSubsystem.h:303
void ConstructBranch(TTree *tree, TString &prefix)
Construct the branch and tree vector.
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
void Normalize(VQwDataElement *denom)
std::map< TString, TString > fDetectorMaps
Definition: VQwSubsystem.h:322
EQwPMTInstrumentType GetQwPMTInstrumentType(TString name)
Definition: QwTypes.cc:11
UInt_t GetEventcutErrorFlag()
Return the error flag to the top level routines related to stability checks and ErrorFlag updates...
void FillTreeVector(std::vector< Double_t > &values) const
Fill the tree vector.
#define default_bool_value(b)
Definition: QwOptions.h:51
void FillHistograms()
Fill the histograms for this subsystem.
void WritePromptSummary(QwPromptSummary *ps, TString type)
void Disconnect()
Definition: QwDatabase.h:59
std::vector< Double_t > fWeight
Bool_t Connect()
Open a connection to the database using the predefined parameters.
Definition: QwDatabase.cc:175
void SetNormalizability(Bool_t isnormalizable)
void SetRandomEventAsymmetry(Double_t asymmetry)
An options class.
Definition: QwOptions.h:133
Int_t LoadEventCuts(TString filename)
Load the event cuts file.
const QwIntegrationPMT * GetChannel(const TString name) const
void IncrementErrorCounters()
Increment the error counters.
static UInt_t GetUInt(const TString &varvalue)
std::string GetNextToken(const std::string &separatorchars)
Get next token as a string.
void Difference(VQwSubsystem *value1, VQwSubsystem *value2)
Class for blinding data, adapted from G0 blinder class.
Definition: QwBlinder.h:64
virtual UInt_t UpdateErrorFlag()
Uses the error flags of contained data elements to update Returns the error flag to the top level rou...
EQwPMTInstrumentType
Definition: QwTypes.h:124
void TrimComment(const char commentchar)
const QwIntegrationPMT * GetIntegrationPMT(const TString name) const
std::vector< QwIntegrationPMT > fIntegrationPMT
static const double e
Definition: QwUnits.h:91
Virtual base class for the parity subsystems.
void Blind(const QwBlinder *blinder)
Blind the asymmetry.
void ProcessOptions(QwOptions &options)
UInt_t GetAnalysisID()
Definition: QwParityDB.h:71
EQwPMTInstrumentType GetDetectorTypeID(TString name)
TString GetQwPMTInstrumentTypeName(EQwPMTInstrumentType type)
Definition: QwTypes.cc:76
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Definition: VQwSubsystem.h:209
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
std::vector< QwMainCerenkovDetectorID > fMainDetID
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Definition: QwOptions.h:164
void SetRandomEventParameters(Double_t mean, Double_t sigma)
static void PrintErrorCounterHead()
void FillDB(QwParityDB *db, TString datatype)
Fill the database.
QwParameterFile * ReadNextSection(std::string &secname, const bool keep_header=false)
std::vector< QwCombinedPMT > fCombinedPMT
T GetValue(const std::string &key)
Get a templated value.
Definition: QwOptions.h:240
Bool_t PublishInternalValues() const
void PrintValue() const
Print values of all channels.
Bool_t FileHasModuleHeader(const std::string &secname)
The pure virtual base class of all data elements.
#define QwDebug
Predefined log drain for debugging output.
Definition: QwLog.h:60
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
Definition: VQwSubsystem.h:88
A logfile class, based on an identical class in the Hermes analyzer.
void FillErrDB(QwParityDB *db, TString datatype)
Int_t LoadChannelMap(TString mapfile)
Mandatory map file definition.
void DoNormalization(Double_t factor=1.0)
VQwSubsystem & operator-=(VQwSubsystem *value)
TString fSystemName
Name of this subsystem.
Definition: VQwSubsystem.h:315
void PrintInfo() const
Print some information about the subsystem.
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Construct the branch and tree vector.
mysqlpp::Query Query(const char *qstr=0)
Definition: QwDatabase.h:66
void SetBlindability(Bool_t isblindable)
Bool_t ReadNextLine()
void SetBlindability(Bool_t isblindable)
void CalculateRunningAverage()
Calculate the average for all good events.
Bool_t Compare(VQwSubsystem *source)
void ProcessEvent_2()
Process the event data again, including data from other subsystems. Not all derived classes will requ...
std::vector< std::vector< TString > > fPublishList
List of parameters to be published (loaded at the channel map)
Definition: VQwSubsystem.h:144
const QwCombinedPMT * GetCombinedPMT(const TString name) const
void PrintErrorCounters() const
Report the number of events failed due to HW and event cut failures.
The pure virtual base class of all subsystems.
Definition: VQwSubsystem.h:59
Bool_t ApplySingleEventCuts()
Apply the single event cuts.
A color changing class for the output stream.
Definition: QwColor.h:98
Int_t fCurrentROC_ID
ROC ID that is currently being processed.
Definition: VQwSubsystem.h:325
Int_t RegisterSubbank(const UInt_t bank_id)
Tell the object that it will decode data from this sub-bank in the ROC currently open for registratio...
virtual Int_t RegisterROCNumber(const UInt_t roc_id, const UInt_t bank_id=0)
Tell the object that it will decode data from this ROC and sub-bank.
void SetNormalizability(Bool_t isnormalizable)
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
std::vector< TString > fCombinedChannelNames
VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
const QwVQWK_Channel * GetChannel(const TString name) const
Definition: QwCombinedPMT.h:48
Int_t LoadInputParameters(TString pedestalfile)
Mandatory parameter file definition.
Bool_t RequestExternalValue(const TString &name, VQwHardwareChannel *value) const
Request a named value which is owned by an external subsystem; the request will be handled by the par...
VQwSubsystem & operator+=(VQwSubsystem *value)
Int_t GetDetectorIndex(EQwPMTInstrumentType TypeID, TString name)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
void AccumulateRunningSum(VQwSubsystem *value)
Update the running sums for devices.
static TString DetermineMeasurementTypeID(TString type, TString suffix="", Bool_t forcediffs=kFALSE)
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom)
Int_t ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
void DeaccumulateRunningSum(VQwSubsystem *value)
remove one entry from the running sums for devices
void EncodeEventData(std::vector< UInt_t > &buffer)
Bool_t PublishInternalValue(const TString &name, const TString &desc, const VQwHardwareChannel *value) const
Publish a variable name to the parent subsystem array.
static void PrintErrorCounterTail()
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
const QwVQWK_Channel * GetChannel(const TString name) const
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
void RandomizeEventData(int helicity=0, Double_t time=0.0)
Int_t fCurrentBank_ID
Bank ID that is currently being processed.
Definition: VQwSubsystem.h:326
QwParameterFile * ReadUntilNextModule(const bool add_current_line=false)
#define RegisterSubsystemFactory(A)
Definition: QwFactory.h:230
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40
UInt_t GetGlobalErrorFlag(TString evtype, Int_t evMode, Double_t stabilitycut)
Definition: QwTypes.cc:127
TString GetSubsystemName() const
Definition: VQwSubsystem.h:93
void Sum(VQwSubsystem *value1, VQwSubsystem *value2)