QwAnalysis
QwLumi.cc
Go to the documentation of this file.
1 /**********************************************************\
2  * File: QwLumi.C *
3  * *
4  * Author: *
5  * Time-stamp: *
6 \**********************************************************/
7 
8 #include "QwLumi.h"
9 
10 // System headers
11 #include <stdexcept>
12 #include <iostream>
13 
14 // Qweak headers
15 #include "QwSubsystemArray.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 
25 {
26  options.AddOptions()
27  ("QwLumi.normalize",
28  po::value<bool>()->default_bool_value(true),
29  "Normalize the detectors by beam current");
30 }
31 
32 
33 //*****************************************************************
35 {
36  bNormalization = options.GetValue<bool>("QwLumi.normalize");
37  if (! bNormalization){
38  QwWarning << "QwLumi::ProcessOptions: "
39  << "Detector yields WILL NOT be normalized."
40  << QwLog::endl;
41  }
42 }
43 
44 //*****************************************************************
45 Int_t QwLumi::LoadChannelMap(TString mapfile)
46 {
47  Bool_t ldebug=kFALSE;
48 
49  TString varname, varvalue;
50  TString modtype, dettype, namech, nameofcombinedchan, keyword, keyword2;
51  Int_t modnum = 0;
52  Int_t channum = 0;
53  Int_t combinedchans = 0;
54  std::vector<TString> combinedchannelnames;
55  std::vector<Double_t> weight;
56  Int_t currentrocread=0;
57  Int_t currentbankread=0;
58  Int_t offset = -1;
59  Int_t currentsubbankindex=-1;
60  Int_t fSample_size=0;
61 
62  QwParameterFile mapstr(mapfile.Data()); //Open the file
63  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
64  while (mapstr.ReadNextLine())
65  {
66  mapstr.TrimComment('!'); // Remove everything after a '!' character.
67  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
68  if (mapstr.LineIsEmpty()) continue;
69 
70  if (mapstr.HasVariablePair("=",varname,varvalue))
71  {
72  // This is a declaration line. Decode it.
73  varname.ToLower();
74  UInt_t value = QwParameterFile::GetUInt(varvalue);
75 
76  if (varname=="roc")
77  {
78  currentrocread=value;
79  RegisterROCNumber(value,0);
80  }
81  else if (varname=="bank")
82  {
83  currentbankread=value;
84  RegisterSubbank(value);
85  }
86  else if (varname=="sample_size")
87  {
88  fSample_size=value;
89  }
90  }
91  else
92  {
93  Bool_t lineok=kTRUE;
94  keyword = "";
95  keyword2 = "";
96  // Break this line into tokens to process it.
97  modtype = mapstr.GetTypedNextToken<TString>(); // module type
98  if (modtype == "VQWK" || modtype == "SCALER")
99  {
100  modnum = mapstr.GetTypedNextToken<Int_t>(); //slot number
101  channum = mapstr.GetTypedNextToken<Int_t>(); //channel number
102  dettype = mapstr.GetTypedNextToken<TString>(); //type-purpose of the detector
103  dettype.ToLower();
104  namech = mapstr.GetTypedNextToken<TString>(); //name of the detector
105  namech.ToLower();
106  keyword = mapstr.GetTypedNextToken<TString>();
107  keyword2 = mapstr.GetTypedNextToken<TString>();
108  keyword.ToLower();
109  keyword2.ToLower();
110  }
111  else if (modtype == "VPMT")
112  {
113  channum = mapstr.GetTypedNextToken<Int_t>(); //channel number
114  combinedchans = mapstr.GetTypedNextToken<Int_t>(); //number of combined channels
115  dettype = mapstr.GetTypedNextToken<TString>(); //type-purpose of the detector
116  dettype.ToLower();
117  namech = mapstr.GetTypedNextToken<TString>(); //name of the detector
118  namech.ToLower();
119  //TString nameofchannel;
120  combinedchannelnames.clear();
121  for (int i=0; i<combinedchans; i++)
122  {
123  nameofcombinedchan = mapstr.GetTypedNextToken<TString>();
124  nameofcombinedchan.ToLower();
125  combinedchannelnames.push_back(nameofcombinedchan);
126  }
127  weight.clear();
128  for (int i=0; i<combinedchans; i++)
129  {
130  weight.push_back( mapstr.GetTypedNextToken<Double_t>());
131  }
132  keyword = mapstr.GetTypedNextToken<TString>();
133  keyword2 = mapstr.GetTypedNextToken<TString>();
134  keyword.ToLower();
135  keyword2.ToLower();
136 
137 
138 
139 
140 
141 
142 
143  }
144  if(currentsubbankindex!=GetSubbankIndex(currentrocread,currentbankread))
145  {
146  currentsubbankindex=GetSubbankIndex(currentrocread,currentbankread);
147  }
148 
149 
150 
151  QwLumiDetectorID localLumiDetectorID;
152  localLumiDetectorID.fdetectorname=namech;
153  localLumiDetectorID.fmoduletype=modtype;
154  localLumiDetectorID.fSubbankIndex=currentsubbankindex;
155  localLumiDetectorID.fdetectortype=dettype;
156 
157 
158  if(modtype=="VQWK")
159  {
160  offset = QwVQWK_Channel::GetBufferOffset(modnum, channum);
161  localLumiDetectorID.fWordInSubbank = offset;
162  }
163  else if(modtype=="SCALER")
164  {
165  offset = QwSIS3801D24_Channel::GetBufferOffset(modnum, channum);
166  localLumiDetectorID.fWordInSubbank = offset;
167  }
168  else if (modtype=="VPMT")
169  {
170  localLumiDetectorID.fCombinedChannelNames = combinedchannelnames;
171  localLumiDetectorID.fWeight = weight;
172  //std::cout<<"Add in a combined channel"<<std::endl;
173  }
174 
175  if(offset<0)
176  {
177  QwError << "QwLumi::LoadChannelMap: Unknown module type: "
178  << modtype <<", the detector "<<namech<<" will not be decoded "
179  << QwLog::endl;
180  lineok=kFALSE;
181  continue;
182  }
183 
184 
185 
186 
187  localLumiDetectorID.fTypeID=GetDetectorTypeID(dettype);
188  if(localLumiDetectorID.fTypeID==-1)
189  {
190  QwError << "QwLumi::LoadChannelMap: Unknown detector type: "
191  << dettype <<", the detector "<<namech<<" will not be decoded "
192  << QwLog::endl;
193  lineok=kFALSE;
194  continue;
195  }
196 
197  localLumiDetectorID.fIndex=
198  GetDetectorIndex(localLumiDetectorID.fTypeID,
199  localLumiDetectorID.fdetectorname);
200 
201  if(localLumiDetectorID.fIndex==-1)
202  {
203  if(localLumiDetectorID.fTypeID==kQwIntegrationPMT)
204  {
205  QwIntegrationPMT localIntegrationPMT(GetSubsystemName(),localLumiDetectorID.fdetectorname);
206 
207  // Force all Lumi PMTs to be not_blindable.
208  // This isn't really needed, since the subsystem
209  // doesn't call QwIntegrationPMT::Blind, but let's
210  // do it anyway.
211  localIntegrationPMT.SetBlindability(kFALSE);
212  if (keyword=="not_normalizable"
213  || keyword2=="not_normalizable")
214  localIntegrationPMT.SetNormalizability(kFALSE);
215  else
216  localIntegrationPMT.SetNormalizability(kTRUE);
217 
218  fIntegrationPMT.push_back(localIntegrationPMT);
219  fIntegrationPMT[fIntegrationPMT.size()-1].SetDefaultSampleSize(fSample_size);
220  localLumiDetectorID.fIndex=fIntegrationPMT.size()-1;
221  }
222  else if (localLumiDetectorID.fTypeID==kQwCombinedPMT)
223  {
224  QwCombinedPMT localcombinedPMT(GetSubsystemName(),localLumiDetectorID.fdetectorname);
225  // Force all Lumi PMTs to be not_blindable.
226  // This isn't really needed, since the subsystem
227  // doesn't call QwCombinedPMT::Blind, but let's
228  // do it anyway.
229  localcombinedPMT.SetBlindability(kFALSE);
230  if (keyword=="not_normalizable"
231  || keyword2=="not_normalizable")
232  localcombinedPMT.SetNormalizability(kFALSE);
233  else
234  localcombinedPMT.SetNormalizability(kTRUE);
235 
236  fCombinedPMT.push_back(localcombinedPMT);
237  fCombinedPMT[fCombinedPMT.size()-1].SetDefaultSampleSize(fSample_size);
238  localLumiDetectorID.fIndex=fCombinedPMT.size()-1;
239  }
240 
241 
242 
243 
244 
245 
246 
247 
248  if(localLumiDetectorID.fTypeID==kQwScalerPMT)
249  {
250  QwSIS3801D24_Channel localcounter(localLumiDetectorID.fdetectorname);
251  /// TODO: Instead of just forcing the external clock to not be used, we should
252  /// figure out how to use the clock from teh beamline subsystem.
253  localcounter.SetNeedsExternalClock(kFALSE);
254  fScalerPMT.push_back(localcounter);
255  localLumiDetectorID.fIndex=fScalerPMT.size()-1;
256  }
257 
258  }
259 
260 
261  if(ldebug)
262  {
263  localLumiDetectorID.Print();
264  std::cout<<"line ok=";
265  if(lineok) std::cout<<"TRUE"<<std::endl;
266  else
267  std::cout<<"FALSE"<<std::endl;
268  }
269 
270  if(lineok)
271  fLumiDetectorID.push_back(localLumiDetectorID);
272  }
273  }
274 
275 
276 
277 
278 
279  //std::cout<<"linking combined channels"<<std::endl;
280 
281  for (size_t i=0; i<fLumiDetectorID.size(); i++)
282  {
283  if (fLumiDetectorID[i].fTypeID==kQwCombinedPMT)
284  {
285  Int_t ind = fLumiDetectorID[i].fIndex;
286 
287  //check to see if all required channels are available
288  if (ldebug)
289  {
290  std::cout<<"fLumiDetectorID[i].fCombinedChannelNames.size()="
291  <<fLumiDetectorID[i].fCombinedChannelNames.size()<<std::endl<<"name list: ";
292  for (size_t n=0; n<fLumiDetectorID[i].fCombinedChannelNames.size(); n++)
293  std::cout<<" "<<fLumiDetectorID[i].fCombinedChannelNames[n];
294  std::cout<<std::endl;
295  }
296 
297  Int_t chanmatched=0;
298  for (size_t j=0; j<fLumiDetectorID[i].fCombinedChannelNames.size(); j++)
299  {
300 
301  for (size_t k=0; k<fLumiDetectorID.size(); k++)
302  {
303  if (fLumiDetectorID[i].fCombinedChannelNames[j]==fLumiDetectorID[k].fdetectorname)
304  {
305  if (ldebug)
306  std::cout<<"found a to-be-combined channel candidate"<<std::endl;
307  chanmatched ++;
308  break;
309  }
310  }
311  }
312 
313  if ((Int_t) fLumiDetectorID[i].fCombinedChannelNames.size()==chanmatched)
314  {
315  for (size_t l=0; l<fLumiDetectorID[i].fCombinedChannelNames.size(); l++)
316  {
317  Int_t ind_pmt = GetDetectorIndex(GetDetectorTypeID("integrationpmt"),
318  fLumiDetectorID[i].fCombinedChannelNames[l]);
319 
320  fCombinedPMT[ind].Add(&fIntegrationPMT[ind_pmt],fLumiDetectorID[i].fWeight[l]);
321 
322  if (ldebug) std::cout<<"added combined pmt "<<fLumiDetectorID[i].fWeight[l] <<" to array"<<std::endl;
323  }
324  fCombinedPMT[ind].LinkChannel(fLumiDetectorID[i].fdetectorname);
325  if (ldebug)
326  std::cout<<"linked a combined channel"<<std::endl;
327  }
328  else
329  {
330  std::cerr<<"cannot combine void channels for "<<fLumiDetectorID[i].fdetectorname<<std::endl;
331  fLumiDetectorID[i].fIndex = -1;
332  continue;
333  }
334  }
335  }
336 
337 
338  if(ldebug)
339  {
340  std::cout<<"QwLumi::Done with Load map channel \n";
341  for(size_t i=0;i<fLumiDetectorID.size();i++)
342  fLumiDetectorID[i].Print();
343  }
344  ldebug=kFALSE;
345  mapstr.Close(); // Close the file (ifstream)
346 
347  return 0;
348 }
349 
350 
351 //*****************************************************************
352 Int_t QwLumi::LoadEventCuts(TString filename)
353 {
354  Int_t eventcut_flag = 1;
355 
356  // Open the file
357  QwParameterFile mapstr(filename.Data());
358  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
359  while (mapstr.ReadNextLine()){
360  //std::cout<<"********* In the loop *************"<<std::endl;
361  mapstr.TrimComment('!'); // Remove everything after a '!' character.
362  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
363  if (mapstr.LineIsEmpty()) continue;
364 
365  TString varname, varvalue;
366  if (mapstr.HasVariablePair("=",varname,varvalue)){
367  if (varname == "EVENTCUTS"){
368  //varname="";
369  eventcut_flag = QwParameterFile::GetUInt(varvalue);
370  //std::cout<<"EVENT CUT FLAG "<<eventcut_flag<<std::endl;
371  }
372  }
373  else{
374  TString device_type = mapstr.GetTypedNextToken<TString>();
375  device_type.ToLower();
376  TString device_name = mapstr.GetTypedNextToken<TString>();
377  device_name.ToLower();
378 
379  Int_t det_index = GetDetectorIndex(GetDetectorTypeID(device_type),device_name);
380  if (det_index == -1) {
381  QwWarning << " Device not found " << device_name << " of type " << device_type << QwLog::endl;
382  continue;
383  }
384 
385  if (device_type == GetQwPMTInstrumentTypeName(kQwIntegrationPMT)){
386  Double_t LLX = mapstr.GetTypedNextToken<Double_t>(); //lower limit for IntegrationPMT value
387  Double_t ULX = mapstr.GetTypedNextToken<Double_t>(); //upper limit for IntegrationPMT value
388  varvalue = mapstr.GetTypedNextToken<TString>();//global/loacal
389  Double_t stabilitycut = mapstr.GetTypedNextToken<Double_t>();
390  varvalue.ToLower();
391  QwMessage << "QwLumi Error Code passing to QwIntegrationPMT " << GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut) << QwLog::endl;
392 
393  //std::cout<<"*****************************"<<std::endl;
394  //std::cout<<" Type "<<device_type<<" Name "<<device_name<<" Index ["<<det_index <<"] "<<" device flag "<<check_flag<<std::endl;
395 
396  fIntegrationPMT[det_index].SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut),LLX,ULX,stabilitycut);
397  //std::cout<<"*****************************"<<std::endl;
398 
399  } else if (device_type == GetQwPMTInstrumentTypeName(kQwCombinedPMT)){
400  Double_t LLX = mapstr.GetTypedNextToken<Double_t>(); //lower limit for IntegrationPMT value
401  Double_t ULX = mapstr.GetTypedNextToken<Double_t>(); //upper limit for IntegrationPMT value
402  varvalue = mapstr.GetTypedNextToken<TString>();//global/loacal
403  Double_t stabilitycut=mapstr.GetTypedNextToken<Double_t>();
404  varvalue.ToLower();
405  QwMessage << "QwLumi Error Code passing to QwCombinedPMT " << GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut) << QwLog::endl;
406 
407  //std::cout<<"*****************************"<<std::endl;
408  //std::cout<<" Type "<<device_type<<" Name "<<device_name<<" Index ["<<det_index <<"] "<<" device flag "<<check_flag<<std::endl;
409 
410  fCombinedPMT[det_index].SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut),LLX,ULX,stabilitycut);
411  //std::cout<<"*****************************"<<std::endl;
412 
413  }
414 
415  }
416 
417  }
418  for (size_t i=0;i<fIntegrationPMT.size();i++)
419  fIntegrationPMT[i].SetEventCutMode(eventcut_flag);
420  for (size_t i=0;i<fCombinedPMT.size();i++)
421  fCombinedPMT[i].SetEventCutMode(eventcut_flag);
422 
423  fQwLumiErrorCount=0; //set the error counter to zero
424  mapstr.Close(); // Close the file (ifstream)
425  return 0;
426 }
427 
428 //*****************************************************************
429 Int_t QwLumi::LoadInputParameters(TString pedestalfile)
430 {
431  Bool_t ldebug=kFALSE;
432  TString varname;
433  Double_t varped;
434  Double_t varcal;
435  TString localname;
436 
437  Int_t lineread=0;
438 
439  if(ldebug)std::cout<<"QwLumi::LoadInputParameters("<< pedestalfile<<")\n";
440 
441  QwParameterFile mapstr(pedestalfile.Data()); //Open the file
442  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
443 
444  while (mapstr.ReadNextLine())
445  {
446  lineread+=1;
447  if(ldebug)std::cout<<" line read so far ="<<lineread<<"\n";
448  mapstr.TrimComment('!'); // Remove everything after a '!' character.
449  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
450  if (mapstr.LineIsEmpty()) continue;
451  else
452  {
453  varname = mapstr.GetTypedNextToken<TString>(); //name of the channel
454  varname.ToLower();
455  varname.Remove(TString::kBoth,' ');
456  varped= mapstr.GetTypedNextToken<Double_t>(); // value of the pedestal
457  varcal= mapstr.GetTypedNextToken<Double_t>(); // value of the calibration factor
458  if(ldebug) std::cout<<"inputs for channel "<<varname
459  <<": ped="<<varped<<": cal="<<varcal<<"\n";
460  Bool_t notfound=kTRUE;
461 
462  if(notfound)
463  for(size_t i=0;i<fIntegrationPMT.size();i++)
464  if(fIntegrationPMT[i].GetElementName()==varname)
465  {
466  fIntegrationPMT[i].SetPedestal(varped);
467  fIntegrationPMT[i].SetCalibrationFactor(varcal);
468  i=fIntegrationPMT.size()+1;
469  notfound=kFALSE;
470  i=fIntegrationPMT.size()+1;
471  }
472  }
473 
474  }
475  if(ldebug) std::cout<<" line read in the pedestal + cal file ="<<lineread<<" \n";
476 
477  ldebug=kFALSE;
478  mapstr.Close(); // Close the file (ifstream)
479  return 0;
480 }
481 
482 //*****************************************************************
483 void QwLumi::SetRandomEventParameters(Double_t mean, Double_t sigma)
484 {
485  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
487 }
488 
489 //*****************************************************************
490 void QwLumi::SetRandomEventAsymmetry(Double_t asymmetry)
491 {
492  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
494 }
495 
496 //*****************************************************************
497 void QwLumi::RandomizeEventData(int helicity, double time)
498 {
499  // Randomize all QwIntegrationPMT buffers
500  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
501  fIntegrationPMT[i].RandomizeEventData(helicity, time);
502 }
503 
504 //*****************************************************************
505 void QwLumi::EncodeEventData(std::vector<UInt_t> &buffer)
506 {
507  std::vector<UInt_t> elements;
508  elements.clear();
509 
510  // Get all buffers in the order they are defined in the map file
511  for (size_t i = 0; i < fLumiDetectorID.size(); i++) {
512  // This is a QwIntegrationPMT
513  if (fLumiDetectorID.at(i).fTypeID == kQwIntegrationPMT)
514  fIntegrationPMT[fLumiDetectorID.at(i).fIndex].EncodeEventData(elements);
515  }
516 
517  // If there is element data, generate the subbank header
518  std::vector<UInt_t> subbankheader;
519  std::vector<UInt_t> rocheader;
520  if (elements.size() > 0) {
521 
522  // Form CODA subbank header
523  subbankheader.clear();
524  subbankheader.push_back(elements.size() + 1); // subbank size
525  subbankheader.push_back((fCurrentBank_ID << 16) | (0x01 << 8) | (1 & 0xff));
526  // subbank tag | subbank type | event number
527 
528  // Form CODA bank/roc header
529  rocheader.clear();
530  rocheader.push_back(subbankheader.size() + elements.size() + 1); // bank/roc size
531  rocheader.push_back((fCurrentROC_ID << 16) | (0x10 << 8) | (1 & 0xff));
532  // bank tag == ROC | bank type | event number
533 
534  // Add bank header, subbank header and element data to output buffer
535  buffer.insert(buffer.end(), rocheader.begin(), rocheader.end());
536  buffer.insert(buffer.end(), subbankheader.begin(), subbankheader.end());
537  buffer.insert(buffer.end(), elements.begin(), elements.end());
538  }
539 }
540 
541 //*****************************************************************
542 Int_t QwLumi::ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
543 {
544  Bool_t lkDEBUG=kFALSE;
545  Bool_t firsttime=kTRUE;
546  Bool_t issingleevent=kTRUE;
547 
548  Int_t index = GetSubbankIndex(roc_id,bank_id);
549 
550  if (index>=0 && num_words>0){
551  // We want to process this ROC. Begin looping through the data.
552  if (lkDEBUG)
553  std::cout << "QwLumi::ProcessEvBuffer: "
554  << "Begin processing ROC" << roc_id
555  << " and subbank "<<bank_id
556  << " number of words="<<num_words<<std::endl;
557 
558  for(size_t i=0;i<fLumiDetectorID.size();i++)
559  {
560  if(fLumiDetectorID[i].fSubbankIndex==index)
561  {
562 
563  if(fLumiDetectorID[i].fTypeID == kQwIntegrationPMT)
564  {
565  if (lkDEBUG)
566  {
567  std::cout<<"found IntegrationPMT data for "<<fLumiDetectorID[i].fdetectorname<<std::endl;
568  std::cout<<"words left to read in this buffer:"<<num_words-fLumiDetectorID[i].fWordInSubbank<<std::endl;
569  }
570  fIntegrationPMT[fLumiDetectorID[i].fIndex].
571  ProcessEvBuffer(&(buffer[fLumiDetectorID[i].fWordInSubbank]),
572  num_words-fLumiDetectorID[i].fWordInSubbank);
573  }
574 
575  if(fLumiDetectorID[i].fTypeID == kQwScalerPMT)
576  {
577  if (lkDEBUG)
578  {
579  std::cout<<"found ScalerPMT data for "<<fLumiDetectorID[i].fdetectorname<<std::endl;
580  std::cout<<"word left to read in this buffer:"<<num_words-fLumiDetectorID[i].fWordInSubbank<<std::endl;
581  }
582 
583  // This was added to check if the buffer contains more than one event. If it does then throw those events away. A better way to do this would be to find how many events were in the buffer then change the offset to be able to read them all.
584  if (firsttime)
585  {
586  firsttime=kFALSE;
587  if (buffer[0]/32!=1)
588  {
589  issingleevent=kFALSE;
590  if(lkDEBUG) {
591  std::cout<<"QwLumi::ProcessEvBuffer: More than one event was found in the buffer. Setting these events to zero."<<std::endl;
592  }
593  }
594  }
595  if (issingleevent==kFALSE) continue;
596 
597 
598 
599 
600 
601  fScalerPMT[fLumiDetectorID[i].fIndex].
602  ProcessEvBuffer(&(buffer[fLumiDetectorID[i].fWordInSubbank]),
603  num_words-fLumiDetectorID[i].fWordInSubbank);
604  }
605 
606  }
607  }
608  SetDataLoaded(kTRUE);
609  }
610 
611  return 0;
612 }
613 
614 //*****************************************************************
616 
617  Bool_t status=kTRUE;
618  for(size_t i=0;i<fIntegrationPMT.size();i++){
619  status &= fIntegrationPMT[i].ApplySingleEventCuts();
620  if(!status && bDEBUG) std::cout<<"******* QwLumi::SingleEventCuts()->IntegrationPMT[ "<<i<<" , "<<fIntegrationPMT[i].GetElementName()<<" ] ******\n";
621  }
622  for(size_t i=0;i<fCombinedPMT.size();i++){
623  status &= fCombinedPMT[i].ApplySingleEventCuts();
624  if(!status && bDEBUG) std::cout<<"******* QwLumi::SingleEventCuts()->CombinedPMT[ "<<i<<" , "<<fCombinedPMT[i].GetElementName()<<" ] ******\n";
625  }
626 
627 
628  if (!status)
629  fQwLumiErrorCount++;//failed event counter for QwLumi
630 
631  return status;
632 }
633 
634 
636 {
637  for(size_t i=0;i<fIntegrationPMT.size();i++){
638  fIntegrationPMT[i].IncrementErrorCounters();
639  }
640  for(size_t i=0;i<fCombinedPMT.size();i++){
641  fCombinedPMT[i].IncrementErrorCounters();
642  }
643 }
644 
645 //*****************************************************************
647 {
648  //inherited from the VQwSubsystemParity; this will display the error summary
649  QwMessage<<"*********QwLumi Error Summary****************"<<QwLog::endl;
651  for(size_t i=0;i<fIntegrationPMT.size();i++){
652  //std::cout<<" IntegrationPMT ["<<i<<"] "<<std::endl;
653  fIntegrationPMT[i].PrintErrorCounters();
654  }
655  for(size_t i=0;i<fCombinedPMT.size();i++){
656  //std::cout<<" CombinedPMT ["<<i<<"] "<<std::endl;
657  fCombinedPMT[i].PrintErrorCounters();
658  }
660 }
661 
662 
663 //*****************************************************************
664 UInt_t QwLumi::GetEventcutErrorFlag(){//return the error flag
665  UInt_t ErrorFlag;
666  ErrorFlag=0;
667  for(size_t i=0;i<fIntegrationPMT.size();i++){
668  ErrorFlag |= fIntegrationPMT[i].GetEventcutErrorFlag();
669  }
670  for(size_t i=0;i<fCombinedPMT.size();i++){
671  ErrorFlag |= fCombinedPMT[i].GetEventcutErrorFlag();
672  }
673  return ErrorFlag;
674 }
675 
676 void QwLumi::UpdateErrorFlag(const VQwSubsystem *ev_error){
677  VQwSubsystem* tmp = const_cast<VQwSubsystem*>(ev_error);
678  if(Compare(tmp)){
679  const QwLumi * input = dynamic_cast<const QwLumi *> (ev_error);
680 
681  for (size_t i=0;i<input->fIntegrationPMT.size();i++)
682  (this->fIntegrationPMT[i]).UpdateErrorFlag(&(input->fIntegrationPMT[i]));
683 
684  for (size_t i=0;i<input->fCombinedPMT.size();i++)
685  (this->fCombinedPMT[i]).UpdateErrorFlag(&(input->fCombinedPMT[i]));
686  }
687 };
688 
689 
690 //*****************************************************************
692 {
693  if (! HasDataLoaded()) return;
694 
695  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
697  for (size_t i = 0; i < fCombinedPMT.size(); i++)
699  for (size_t i = 0; i < fScalerPMT.size(); i++)
701 }
702 
703 
704 /**
705  * Exchange data between subsystems
706  */
708 {
709  if (! HasDataLoaded()) return;
710 
711  bIsExchangedDataValid = kTRUE;
712  if (bNormalization){
713  if(RequestExternalValue("q_targ", &fTargetCharge)){
714  if (bDEBUG){
715  QwWarning << "QwLumi::ExchangeProcessedData Found "<<fTargetCharge.GetElementName()<< QwLog::endl;
716  //QwWarning <<"****QwMainCerenkovDetector****"<< QwLog::endl;
717  (dynamic_cast<QwVQWK_Channel*>(&fTargetCharge))->PrintInfo();
718  }
719  }
720  }
721 }
722 
723 
724 
725 
727 {
728  if (! HasDataLoaded()) return;
729 
731  {
732  //data is valid, process it
733  if (bDEBUG)
734  {
735  Double_t pedestal = fTargetCharge.GetPedestal();
736  Double_t calfactor = fTargetCharge.GetCalibrationFactor();
737  Double_t volts = fTargetCharge.GetAverageVolts();
738  std::cout<<"QwLumi::ProcessEvent_2(): processing with exchanged data"<<std::endl;
739  std::cout<<"pedestal, calfactor, average volts = "<<pedestal<<", "<<calfactor<<", "<<volts<<std::endl;
740  }
741 
742  // assume fTargetCharge.fHardwareSum is a calibrated value,
743  // detector signals will be normalized to it
744  if (bNormalization) this->DoNormalization();
745  }
746  else
747  {
748  QwWarning <<"QwLumi::ProcessEvent_2(): could not get all external values."<<QwLog::endl;
749  }
750 }
751 
753 {
754  // Publish variables
755  Bool_t status = kTRUE;
756 
757  // Don't publish anything explicitly, use the PublishByRequest
758  // mechanism instead.
759 
760  return status;
761 }
762 
763 Bool_t QwLumi::PublishByRequest(TString device_name)
764 {
765  Bool_t status = kFALSE;
766  for(size_t i=0;i<fLumiDetectorID.size();i++) {
767  if(device_name.CompareTo(fLumiDetectorID[i].fdetectorname)!=0) continue;
768 
769  if (fLumiDetectorID[i].fTypeID == kQwCombinedPMT){
770  status = PublishInternalValue(device_name, "published-by-request",
771  fCombinedPMT[fLumiDetectorID[i].fIndex].GetChannel(device_name));
772  } else if (fLumiDetectorID[i].fTypeID == kQwIntegrationPMT) {
773  status = PublishInternalValue(device_name, "published-by-request",
774  fIntegrationPMT[fLumiDetectorID[i].fIndex].GetChannel(device_name));
775  } else {
776  QwError << "Unknown channel name: " << device_name << QwLog::endl;
777  }
778  break;
779  }
780  if (!status)
781  QwError << "QwLumi::PublishByRequest: Failed to publish channel name: " << device_name << QwLog::endl;
782  return status;
783 }
784 
785 //*****************************************************************
786 Int_t QwLumi::ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
787 {
788  return 0;
789 }
790 
791 //*****************************************************************
793 {
794  Bool_t test=kTRUE;
795 
796  return test;
797 }
798 
799 
800 //*****************************************************************
802 {
803  SetDataLoaded(kFALSE);
804  for(size_t i=0;i<fIntegrationPMT.size();i++)
806  for (size_t i=0;i<fCombinedPMT.size();i++)
808  for(size_t i=0;i<fScalerPMT.size();i++)
810 }
811 
813 {
814  return GetQwPMTInstrumentType(name);
815 }
816 
817 //*****************************************************************
818 Int_t QwLumi::GetDetectorIndex(EQwPMTInstrumentType type_id, TString name)
819 {
820  Bool_t ldebug=kFALSE;
821  if(ldebug)
822  {
823  std::cout<<"QwLumi::GetDetectorIndex\n";
824  std::cout<<"type_id=="<<type_id<<" name="<<name<<"\n";
825  std::cout<<fLumiDetectorID.size()<<" already registered detector\n";
826  }
827 
828  Int_t result=-1;
829  for(size_t i=0;i<fLumiDetectorID.size();i++)
830  {
831  if(fLumiDetectorID[i].fTypeID==type_id)
832  if(fLumiDetectorID[i].fdetectorname==name)
833  result=fLumiDetectorID[i].fIndex;
834  if(ldebug)
835  {
836  std::cout<<"testing against ("<<fLumiDetectorID[i].fTypeID
837  <<","<<fLumiDetectorID[i].fdetectorname<<")=>"<<result<<"\n";
838  }
839  }
840 
841  return result;
842 }
843 
844 //*****************************************************************
845 const QwIntegrationPMT* QwLumi::GetChannel(const TString name) const
846 {
847  return GetIntegrationPMT(name);
848 }
849 
850 
851 //*****************************************************************
852 const QwIntegrationPMT* QwLumi::GetIntegrationPMT(const TString name) const
853 {
854  if (! fIntegrationPMT.empty()) {
855  for (std::vector<QwIntegrationPMT>::const_iterator IntegrationPMT = fIntegrationPMT.begin(); IntegrationPMT != fIntegrationPMT.end(); ++IntegrationPMT) {
856  if (IntegrationPMT->GetElementName() == name) {
857  return &(*IntegrationPMT);
858  }
859  }
860  }
861  return 0;
862 }
863 
864 
865 const QwCombinedPMT* QwLumi::GetCombinedPMT(const TString name) const
866 {
867  TString tmpname = name;
868  tmpname.ToLower();
869  if (! fCombinedPMT.empty())
870  {
871  for (size_t i=0;i<fCombinedPMT.size();i++)
872  {
873  if (fCombinedPMT.at(i).GetElementName() == tmpname)
874  {
875  //std::cout<<"Get CombinedPMT "<<tmpname<<std::endl;
876  return &(fCombinedPMT.at(i));
877  }
878  }
879  }
880  QwMessage << "QwLumi::GetCombinedPMT: cannot find channel " << tmpname << QwLog::endl;
881  return NULL;
882 }
883 
884 
885 
886 
887 //*****************************************************************
889 {
890  // std::cout<<" here in QwLumi::operator= \n";
891  if (Compare(value))
892  {
894  QwLumi* input = dynamic_cast<QwLumi*> (value);
895 
896  for (size_t i = 0; i < input->fIntegrationPMT.size(); i++)
897  this->fIntegrationPMT[i] = input->fIntegrationPMT[i];
898  for (size_t i = 0; i < input->fCombinedPMT.size(); i++)
899  this->fCombinedPMT[i] = input->fCombinedPMT[i];
900  for (size_t i = 0; i < input->fScalerPMT.size(); i++)
901  this->fScalerPMT[i] = input->fScalerPMT[i];
902 
903  }
904  return *this;
905 }
906 
907 //*****************************************************************
909 {
910  if (Compare(value))
911  {
912  QwLumi* input= dynamic_cast<QwLumi*>(value);
913 
914  for (size_t i = 0; i < input->fIntegrationPMT.size(); i++)
915  this->fIntegrationPMT[i] += input->fIntegrationPMT[i];
916  for (size_t i = 0; i < input->fCombinedPMT.size(); i++)
917  this->fCombinedPMT[i] += input->fCombinedPMT[i];
918  for (size_t i = 0; i < input->fScalerPMT.size(); i++)
919  this->fScalerPMT[i] += input->fScalerPMT[i];
920  }
921  return *this;
922 }
923 
924 //*****************************************************************
926 {
927 
928  if (Compare(value))
929  {
930  QwLumi* input= dynamic_cast<QwLumi*>(value);
931 
932  for (size_t i = 0; i < input->fIntegrationPMT.size(); i++)
933  this->fIntegrationPMT[i] -= input->fIntegrationPMT[i];
934  for (size_t i = 0; i < input->fCombinedPMT.size(); i++)
935  this->fCombinedPMT[i] -= input->fCombinedPMT[i];
936  for (size_t i = 0; i < input->fScalerPMT.size(); i++)
937  this->fScalerPMT[i] -= input->fScalerPMT[i];
938  }
939  return *this;
940 }
941 
942 //*****************************************************************
943 void QwLumi::Sum(VQwSubsystem *value1, VQwSubsystem *value2)
944 {
945  if (Compare(value1) && Compare(value2))
946  {
947  *this = value1;
948  *this += value2;
949  }
950 }
951 
952 //*****************************************************************
954 {
955  if (Compare(value1) && Compare(value2))
956  {
957  *this = value1;
958  *this -= value2;
959  }
960 }
961 
962 //*****************************************************************
964 {
965  if (Compare(numer) && Compare(denom))
966  {
967  QwLumi* innumer = dynamic_cast<QwLumi*>(numer);
968  QwLumi* indenom = dynamic_cast<QwLumi*>(denom);
969 
970  for (size_t i = 0; i < innumer->fIntegrationPMT.size(); i++)
971  this->fIntegrationPMT[i].Ratio(innumer->fIntegrationPMT[i],indenom->fIntegrationPMT[i]);
972  for (size_t i = 0; i < innumer->fCombinedPMT.size(); i++)
973  this->fCombinedPMT[i].Ratio(innumer->fCombinedPMT[i],indenom->fCombinedPMT[i]);
974  for (size_t i = 0; i < innumer->fScalerPMT.size(); i++)
975  this->fScalerPMT[i].Ratio(innumer->fScalerPMT[i],indenom->fScalerPMT[i]);
976  }
977 }
978 
979 //*****************************************************************
980 void QwLumi::Scale(Double_t factor)
981 {
982  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
983  fIntegrationPMT[i].Scale(factor);
984  for (size_t i = 0; i < fCombinedPMT.size(); i++)
985  fCombinedPMT[i].Scale(factor);
986  for (size_t i = 0; i < fScalerPMT.size(); i++)
987  fScalerPMT[i].Scale(factor);
988 }
989 
990 //*****************************************************************
992 {
993  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
994  fIntegrationPMT[i].Normalize(denom);
995  for (size_t i = 0; i < fCombinedPMT.size(); i++)
996  fCombinedPMT[i].Normalize(denom);
997  //for (size_t i = 0; i < fScalerPMT.size(); i++)
998  //fScalerPMT[i].Normalize(denom);
999 }
1000 
1001 
1002 //*****************************************************************
1004 {
1005  // std::cout<<" Here in QwLumi::Compare \n";
1006 
1007  Bool_t res=kTRUE;
1008  if(typeid(*value)!=typeid(*this))
1009  {
1010  res=kFALSE;
1011  // std::cout<<" types are not ok \n";
1012  // std::cout<<" this is bypassed just for now but should be fixed eventually \n";
1013  }
1014  else
1015  {
1016  QwLumi* input= dynamic_cast<QwLumi*>(value);
1017  if(input->fIntegrationPMT.size()!=fIntegrationPMT.size() ||
1018  input->fCombinedPMT.size()!=fCombinedPMT.size() )
1019  {
1020  res=kFALSE;
1021  }
1022  if(input->fScalerPMT.size()!=fScalerPMT.size())
1023  {
1024  res=kFALSE;
1025  }
1026  }
1027  return res;
1028 }
1029 
1030 
1031 //*****************************************************************
1032 void QwLumi::ConstructHistograms(TDirectory *folder, TString &prefix)
1033 {
1034  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1035  fIntegrationPMT[i].ConstructHistograms(folder,prefix);
1036  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1037  fCombinedPMT[i].ConstructHistograms(folder,prefix);
1038  for (size_t i = 0; i < fScalerPMT.size(); i++)
1039  fScalerPMT[i].ConstructHistograms(folder,prefix);
1040 }
1041 
1042 
1043 //*****************************************************************
1045 {
1046  if (! HasDataLoaded()) return;
1047 
1048  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1050  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1052  for (size_t i = 0; i < fScalerPMT.size(); i++)
1054 }
1055 
1056 
1057 //*****************************************************************
1058 void QwLumi::ConstructBranchAndVector(TTree *tree, TString & prefix, std::vector <Double_t> &values)
1059 {
1060  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1061  fIntegrationPMT[i].ConstructBranchAndVector(tree, prefix, values);
1062  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1063  fCombinedPMT[i].ConstructBranchAndVector(tree, prefix, values);
1064  for (size_t i = 0; i < fScalerPMT.size(); i++)
1065  fScalerPMT[i].ConstructBranchAndVector(tree, prefix, values);
1066 }
1067 
1068 //*****************************************************************
1069 void QwLumi::ConstructBranch(TTree *tree, TString & prefix)
1070 {
1071  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1072  fIntegrationPMT[i].ConstructBranch(tree, prefix);
1073  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1074  fCombinedPMT[i].ConstructBranch(tree, prefix);
1075  for (size_t i = 0; i < fScalerPMT.size(); i++)
1076  fScalerPMT[i].ConstructBranch(tree, prefix);
1077 }
1078 
1079 //*****************************************************************
1080 void QwLumi::ConstructBranch(TTree *tree, TString & prefix, QwParameterFile& trim_file)
1081 {
1082  TString tmp;
1083  QwParameterFile* nextmodule;
1084 
1085  tmp="QwIntegrationPMT";
1086  trim_file.RewindToFileStart();
1087  if (trim_file.FileHasModuleHeader(tmp)){
1088  nextmodule=trim_file.ReadUntilNextModule();
1089  //This section contains sub modules and or channels to be included in the tree
1090 
1091  for(size_t i = 0; i < fIntegrationPMT.size(); i++)
1092  fIntegrationPMT[i].ConstructBranch(tree, prefix,*nextmodule);
1093  for(size_t i = 0; i < fIntegrationPMT.size(); i++)
1094  fScalerPMT[i].ConstructBranch(tree, prefix);
1095 
1096  }
1097 
1098  tmp="QwCombinedPMT";
1099  trim_file.RewindToFileStart();
1100  if (trim_file.FileHasModuleHeader(tmp)){
1101  nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
1102  for (size_t i=0;i<fCombinedPMT.size();i++)
1103  fCombinedPMT[i].ConstructBranch(tree, prefix, *nextmodule );
1104  }
1105 }
1106 
1107 //*****************************************************************
1108 void QwLumi::FillTreeVector(std::vector<Double_t> &values) const
1109 {
1110  if (! HasDataLoaded()) return;
1111 
1112  for(size_t i = 0; i < fIntegrationPMT.size(); i++)
1113  fIntegrationPMT[i].FillTreeVector(values);
1114  for (size_t i=0;i<fCombinedPMT.size();i++)
1115  fCombinedPMT[i].FillTreeVector(values);
1116  for(size_t i = 0; i < fScalerPMT.size(); i++)
1117  fScalerPMT[i].FillTreeVector(values);
1118 }
1119 
1120 
1121 //*****************************************************************
1123 {
1124  QwMessage << "=== QwLumi: " << GetSubsystemName() << " ===" << QwLog::endl;
1125  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1127  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1128  fCombinedPMT[i].PrintValue();
1129  for (size_t i = 0; i < fScalerPMT.size(); i++)
1130  fScalerPMT[i].PrintValue();
1131 }
1132 
1133 //*****************************************************************
1134 void QwLumi::PrintInfo() const
1135 {
1136  QwMessage << "Name of the subsystem = " << fSystemName << QwLog::endl;
1137  QwMessage << "There are " << fIntegrationPMT.size() << " IntegrationPMT" << QwLog::endl;
1138  QwMessage << " " << fCombinedPMT.size() << " CombinedPMT" << QwLog::endl;
1139  QwMessage << "There are " << fScalerPMT.size() << " halo counters" << QwLog::endl;
1140 
1141  QwMessage << " Printing Running AVG and other channel info" << QwLog::endl;
1142  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1144  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1145  fCombinedPMT[i].PrintInfo();
1146  for (size_t i = 0; i < fScalerPMT.size(); i++)
1147  fScalerPMT[i].PrintInfo();
1148 }
1149 
1150 //*****************************************************************
1152 {
1153  for (size_t i=0;i<fLumiDetectorID.size();i++)
1154  {
1155  std::cout<<"============================="<<std::endl;
1156  std::cout<<" Detector ID="<<i<<std::endl;
1157  fLumiDetectorID[i].Print();
1158  }
1159 }
1160 
1161 //*****************************************************************
1163 {
1164  std::cout<<std::endl<<"Detector name= "<<fdetectorname<<std::endl;
1165  std::cout<<"SubbankkIndex= "<<fSubbankIndex<<std::endl;
1166  std::cout<<"word index in subbank= "<<fWordInSubbank<<std::endl;
1167  std::cout<<"module type= "<<fmoduletype<<std::endl;
1168  std::cout<<"detector type= "<<fdetectortype<<" that is index="<<fTypeID<<std::endl;
1169  std::cout<<"Index of this detector in the vector of similar detector= "<<
1170  fIndex<<std::endl;
1171  std::cout<<"Subelement index= "<<
1172  fSubelement<<std::endl;
1173  std::cout<<"==========================================\n";
1174 }
1175 
1176 //*****************************************************************
1178 {
1179  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1181 
1182  for (size_t i=0;i<fCombinedPMT.size();i++)
1184 }
1185 
1186 //*****************************************************************
1188 {
1189  if (Compare(value1)) {
1190  QwLumi* value = dynamic_cast<QwLumi*>(value1);
1191 
1192  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1194 
1195  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1197  }
1198 }
1199 
1201  if (Compare(value1)) {
1202  QwLumi* value = dynamic_cast<QwLumi *>(value1);
1203 
1204  for (size_t i = 0; i < fIntegrationPMT.size(); i++)
1206  for (size_t i = 0; i < fCombinedPMT.size(); i++)
1208  }
1209 };
1210 
1211 
1212 
1213 void QwLumi::DoNormalization(Double_t factor)
1214 {
1216  {
1217  if (bDEBUG)
1218  {
1219  Double_t pedestal = fTargetCharge.GetPedestal();
1220  Double_t calfactor = fTargetCharge.GetCalibrationFactor();
1221  Double_t volts = fTargetCharge.GetAverageVolts();
1222  std::cout<<"QwLumi::ProcessEvent_2(): processing with exchanged data"<<std::endl;
1223  std::cout<<"pedestal, calfactor, average volts = "<<pedestal<<", "<<calfactor<<", "<<volts<<std::endl;
1224  }
1225  try
1226  {
1227  this->Normalize(&fTargetCharge);
1228  }
1229  catch (std::exception& e)
1230  {
1231  std::cerr << e.what() << std::endl;
1232  }
1233  }
1234 }
1235 
1236 
1237 
1238 
1239 
1240 
1241 
1242 //*****************************************************************
1243 void QwLumi::FillDB(QwParityDB *db, TString datatype)
1244 {
1245 
1246  Bool_t local_print_flag = false;
1247  if(local_print_flag){
1248  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1249  QwMessage << " QwLumi::FillDB " << QwLog::endl;
1250  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1251  }
1252 
1253  std::vector<QwDBInterface> interface;
1254  std::vector<QwParitySSQLS::lumi_data> entrylist;
1255 
1256  UInt_t analysis_id = db->GetAnalysisID();
1257 
1258  TString measurement_type;
1259  measurement_type = QwDBInterface::DetermineMeasurementTypeID(datatype);
1260 
1261  UInt_t i,j;
1262  i = j = 0;
1263  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "IntegrationPMT" <<QwLog::endl;
1264 
1265  for(i=0; i< fIntegrationPMT.size(); i++) {
1266  interface.clear();
1267  interface = fIntegrationPMT[i].GetDBEntry();
1268  for(j=0; j<interface.size(); j++){
1269  interface.at(j).SetAnalysisID( analysis_id );
1270  interface.at(j).SetLumiDetectorID( db );
1271  interface.at(j).SetMeasurementTypeID( measurement_type );
1272  interface.at(j).PrintStatus( local_print_flag );
1273  interface.at(j).AddThisEntryToList( entrylist );
1274  }
1275  }
1276  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined PMT" <<QwLog::endl;
1277 
1278  for(i=0; i< fCombinedPMT.size(); i++)
1279  {
1280  interface.clear();
1281  interface = fCombinedPMT[i].GetDBEntry();
1282  for(j=0; j<interface.size(); j++) {
1283  interface.at(j).SetAnalysisID( analysis_id );
1284  interface.at(j).SetLumiDetectorID( db );
1285  interface.at(j).SetMeasurementTypeID( measurement_type );
1286  interface.at(j).PrintStatus( local_print_flag );
1287  interface.at(j).AddThisEntryToList( entrylist );
1288  }
1289  }
1290 
1291 
1292 
1293 
1294  if(local_print_flag) {
1295  QwMessage << QwColor(Qw::kGreen) << "Entrylist Size : "
1296  << QwColor(Qw::kBoldRed) << entrylist.size()
1298  }
1299 
1300  db->Connect();
1301  // Check the entrylist size, if it isn't zero, start to query..
1302  if( entrylist.size() ) {
1303  mysqlpp::Query query= db->Query();
1304  query.insert(entrylist.begin(), entrylist.end());
1305  query.execute();
1306  }
1307  else {
1308  QwMessage << "QwLumi::FillDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() << QwLog::endl;
1309  }
1310 
1311  db->Disconnect();
1312 
1313  return;
1314 }
1315 
1316 
1317 
1318 
1319 void QwLumi::FillErrDB(QwParityDB *db, TString datatype)
1320 {
1321 
1322  Bool_t local_print_flag = false;
1323  if(local_print_flag){
1324  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1325  QwMessage << " QwLumi::FillErrDB " << QwLog::endl;
1326  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1327  }
1328 
1329  std::vector<QwErrDBInterface> interface;
1330  std::vector<QwParitySSQLS::lumi_errors> entrylist;
1331 
1332  UInt_t analysis_id = db->GetAnalysisID();
1333 
1334  UInt_t i,j;
1335  i = j = 0;
1336  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "IntegrationPMT" <<QwLog::endl;
1337 
1338  for(i=0; i< fIntegrationPMT.size(); i++) {
1339  interface.clear();
1340  interface = fIntegrationPMT[i].GetErrDBEntry();
1341  for(j=0; j<interface.size(); j++){
1342  interface.at(j).SetAnalysisID ( analysis_id );
1343  interface.at(j).SetLumiDetectorID ( db );
1344  interface.at(j).PrintStatus ( local_print_flag );
1345  interface.at(j).AddThisEntryToList( entrylist );
1346  }
1347  }
1348  if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined PMT" <<QwLog::endl;
1349 
1350  for(i=0; i< fCombinedPMT.size(); i++)
1351  {
1352  interface.clear();
1353  interface = fCombinedPMT[i].GetErrDBEntry();
1354  for(j=0; j<interface.size(); j++) {
1355  interface.at(j).SetAnalysisID ( analysis_id );
1356  interface.at(j).SetLumiDetectorID ( db );
1357  interface.at(j).PrintStatus ( local_print_flag );
1358  interface.at(j).AddThisEntryToList( entrylist );
1359  }
1360  }
1361 
1362 
1363 
1364 
1365  if(local_print_flag) {
1366  QwMessage << QwColor(Qw::kGreen) << "Entrylist Size : "
1367  << QwColor(Qw::kBoldRed) << entrylist.size()
1369  }
1370 
1371  db->Connect();
1372  // Check the entrylist size, if it isn't zero, start to query..
1373  if( entrylist.size() ) {
1374  mysqlpp::Query query= db->Query();
1375  query.insert(entrylist.begin(), entrylist.end());
1376  query.execute();
1377  }
1378  else {
1379  QwMessage << "QwLumi::FillErrDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() << QwLog::endl;
1380  }
1381 
1382  db->Disconnect();
1383 
1384  return;
1385 };
1386 
1387 
1388 
1390 {
1391 
1392  Bool_t local_print_flag = true;
1393  if(local_print_flag){
1394  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1395  QwMessage << " QwLumi::WritePromptSummary() " << QwLog::endl;
1396  QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
1397  }
1398 
1399  return;
1400 }
Int_t GetSubbankIndex() const
Definition: VQwSubsystem.h:303
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
std::map< TString, TString > fDetectorMaps
Definition: VQwSubsystem.h:322
void Print() const
Definition: QwLumi.cc:1162
const QwIntegrationPMT * GetIntegrationPMT(const TString name) const
Definition: QwLumi.cc:852
EQwPMTInstrumentType GetQwPMTInstrumentType(TString name)
Definition: QwTypes.cc:11
#define default_bool_value(b)
Definition: QwOptions.h:51
void Sum(VQwSubsystem *value1, VQwSubsystem *value2)
Definition: QwLumi.cc:943
void Disconnect()
Definition: QwDatabase.h:59
void DeaccumulateRunningSum(VQwSubsystem *value)
remove one entry from the running sums for devices
Definition: QwLumi.cc:1200
Int_t LoadChannelMap(TString mapfile)
Mandatory map file definition.
Definition: QwLumi.cc:45
Bool_t Connect()
Open a connection to the database using the predefined parameters.
Definition: QwDatabase.cc:175
TString fdetectorname
Definition: QwLumi.h:45
void SetNormalizability(Bool_t isnormalizable)
An options class.
Definition: QwOptions.h:133
Int_t fQwLumiErrorCount
Definition: QwLumi.h:181
static UInt_t GetUInt(const TString &varvalue)
void FillTreeVector(std::vector< Double_t > &values) const
Fill the tree vector.
Definition: QwLumi.cc:1108
void Normalize(VQwDataElement *denom)
Definition: QwLumi.cc:991
std::vector< Double_t > fWeight
Definition: QwLumi.h:48
Bool_t bIsExchangedDataValid
Definition: QwLumi.h:176
void PrintInfo() const
Print some information about the subsystem.
Definition: QwLumi.cc:1134
virtual UInt_t UpdateErrorFlag()
Uses the error flags of contained data elements to update Returns the error flag to the top level rou...
void FillErrDB(QwParityDB *db, TString datatype)
Definition: QwLumi.cc:1319
TString fdetectortype
Definition: QwLumi.h:46
EQwPMTInstrumentType
Definition: QwTypes.h:124
int fSubbankIndex
Definition: QwLumi.h:33
void PrintValue() const
Print values of all channels.
Definition: QwLumi.cc:1122
Bool_t HasDataLoaded() const
Definition: VQwSubsystem.h:94
UInt_t fSubelement
Definition: QwLumi.h:42
void UpdateErrorFlag(const VQwSubsystem *ev_error)
update the error flag in the subsystem level from the top level routines related to stability checks...
Definition: QwLumi.cc:676
static const double e
Definition: QwUnits.h:91
void FillHistograms()
Fill the histograms for this subsystem.
Definition: QwLumi.cc:1044
void ConstructBranch(TTree *tree, TString &prefix)
Construct the branch and tree vector.
Definition: QwLumi.cc:1069
void DoNormalization(Double_t factor=1.0)
Definition: QwLumi.cc:1213
void Difference(VQwSubsystem *value1, VQwSubsystem *value2)
Definition: QwLumi.cc:953
Int_t LoadEventCuts(TString filename)
Load the event cuts file.
Definition: QwLumi.cc:352
const QwIntegrationPMT * GetChannel(const TString name) const
Definition: QwLumi.cc:845
UInt_t GetAnalysisID()
Definition: QwParityDB.h:71
TString GetQwPMTInstrumentTypeName(EQwPMTInstrumentType type)
Definition: QwTypes.cc:76
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...
Definition: QwLumi.cc:542
std::vector< QwCombinedPMT > fCombinedPMT
Definition: QwLumi.h:169
Bool_t ApplySingleEventCuts()
Apply the single event cuts.
Definition: QwLumi.cc:615
Bool_t bNormalization
Definition: QwLumi.h:177
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Definition: VQwSubsystem.h:209
Bool_t PublishByRequest(TString device_name)
Try to publish an internal variable matching the submitted name.
Definition: QwLumi.cc:763
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
static void PrintErrorCounterHead()
void ProcessOptions(QwOptions &options)
Process the command line options.
Definition: QwLumi.cc:34
T GetValue(const std::string &key)
Get a templated value.
Definition: QwOptions.h:240
VQwSubsystem & operator+=(VQwSubsystem *value)
Definition: QwLumi.cc:908
virtual VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Bool_t FileHasModuleHeader(const std::string &secname)
The pure virtual base class of all data elements.
static const Bool_t bDEBUG
Definition: QwLumi.h:183
VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Definition: QwLumi.cc:888
void WritePromptSummary(QwPromptSummary *ps, TString type)
Definition: QwLumi.cc:1389
int fWordInSubbank
Definition: QwLumi.h:36
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
Definition: VQwSubsystem.h:88
void PrintErrorCounters() const
Report the number of events failed due to HW and event cut failures.
Definition: QwLumi.cc:646
EQwPMTInstrumentType fTypeID
Definition: QwLumi.h:40
void RandomizeEventData(int helicity=0, double time=0.0)
Definition: QwLumi.cc:497
TString fSystemName
Name of this subsystem.
Definition: VQwSubsystem.h:315
void ClearEventData()
Definition: QwLumi.cc:801
mysqlpp::Query Query(const char *qstr=0)
Definition: QwDatabase.h:66
void SetBlindability(Bool_t isblindable)
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
Definition: QwLumi.cc:786
void CalculateRunningAverage()
Calculate the average for all good events.
Definition: QwLumi.cc:1177
void SetBlindability(Bool_t isblindable)
std::vector< QwLumiDetectorID > fLumiDetectorID
Definition: QwLumi.h:172
The pure virtual base class of all subsystems.
Definition: VQwSubsystem.h:59
Int_t GetDetectorIndex(EQwPMTInstrumentType TypeID, TString name)
Definition: QwLumi.cc:818
std::vector< QwIntegrationPMT > fIntegrationPMT
Definition: QwLumi.h:168
void EncodeEventData(std::vector< UInt_t > &buffer)
Definition: QwLumi.cc:505
Bool_t IsGoodEvent()
Definition: QwLumi.cc:792
void ProcessEvent_2()
Process the event data again, including data from other subsystems. Not all derived classes will requ...
Definition: QwLumi.cc:726
A color changing class for the output stream.
Definition: QwColor.h:98
class QwScaler_Channel< 0x00ffffff, 0 > QwSIS3801D24_Channel
Int_t fCurrentROC_ID
ROC ID that is currently being processed.
Definition: VQwSubsystem.h:325
void SetRandomEventParameters(Double_t mean, Double_t sigma)
Definition: QwLumi.cc:483
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.
Bool_t Compare(VQwSubsystem *source)
Definition: QwLumi.cc:1003
void SetNormalizability(Bool_t isnormalizable)
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Construct the branch and tree vector.
Definition: QwLumi.cc:1058
Int_t LoadInputParameters(TString pedestalfile)
Mandatory parameter file definition.
Definition: QwLumi.cc:429
void SetRandomEventAsymmetry(Double_t asymmetry)
Definition: QwLumi.cc:490
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...
Definition: QwLumi.h:57
void Scale(Double_t factor)
Definition: QwLumi.cc:980
static TString DetermineMeasurementTypeID(TString type, TString suffix="", Bool_t forcediffs=kFALSE)
void ProcessEvent()
Definition: QwLumi.cc:691
Bool_t PublishInternalValue(const TString &name, const TString &desc, const VQwHardwareChannel *value) const
Publish a variable name to the parent subsystem array.
Bool_t PublishInternalValues() const
Publish all variables of the subsystem.
Definition: QwLumi.cc:752
static void PrintErrorCounterTail()
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
void PrintDetectorID() const
Definition: QwLumi.cc:1151
std::vector< QwSIS3801D24_Channel > fScalerPMT
Definition: QwLumi.h:170
QwBeamCharge fTargetCharge
Definition: QwLumi.h:175
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
void IncrementErrorCounters()
Increment the error counters.
Definition: QwLumi.cc:635
void FillDB(QwParityDB *db, TString datatype)
Fill the database.
Definition: QwLumi.cc:1243
std::vector< TString > fCombinedChannelNames
Definition: QwLumi.h:47
void ExchangeProcessedData()
Definition: QwLumi.cc:707
TString fmoduletype
Definition: QwLumi.h:44
Int_t fCurrentBank_ID
Bank ID that is currently being processed.
Definition: VQwSubsystem.h:326
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom)
Definition: QwLumi.cc:963
UInt_t GetEventcutErrorFlag()
Return the error flag to the top level routines related to stability checks and ErrorFlag updates...
Definition: QwLumi.cc:664
const QwCombinedPMT * GetCombinedPMT(const TString name) const
Definition: QwLumi.cc:865
QwParameterFile * ReadUntilNextModule(const bool add_current_line=false)
void AccumulateRunningSum(VQwSubsystem *value)
Update the running sums for devices.
Definition: QwLumi.cc:1187
VQwSubsystem & operator-=(VQwSubsystem *value)
Definition: QwLumi.cc:925
#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
EQwPMTInstrumentType GetDetectorTypeID(TString name)
Definition: QwLumi.cc:812
TString GetSubsystemName() const
Definition: VQwSubsystem.h:93
void SetDataLoaded(Bool_t flag)
Definition: VQwSubsystem.h:305