QwAnalysis
QwTriggerScintillator.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwTriggerScintillator.cc *
3 * *
4 * Author: P. M. King *
5 * Time-stamp: <2009-03-07 11:50> *
6 \**********************************************************/
7 
9 #include "QwParameterFile.h"
11 
12 #include "boost/bind.hpp"
13 
14 // Register this subsystem with the factory
16 
17 
21 
24 {
25  SetEventTypeMask(0xffff);
26 
28 
29  fRegion = "";
31  fCurrentSlot = 0;
33 
34  fBankID[0] = 0;
35  fBankID[1] = 0;
36  fBankID[2] = 0;
37 
38  fNumberOfModules = 0;
39 
44 
45 
46  for (Int_t plane_idx=0; plane_idx<kMaxNumberOfQwHitPlane; plane_idx++)
47  {
49  }
50 
53 
54 }
55 
57 {
58  fPMTs.clear();
59  fSCAs.clear();
60  delete fF1TDContainer;
61  delete fF1RefContainer;
62 
63  for (Int_t plane_idx=0; plane_idx < kMaxNumberOfQwHitPlane; plane_idx++)
64  {
65  delete fSoftwareMeantimeContainer[plane_idx];
66  }
67 
68 };
69 
70 
72 {
73 
74  TString varname = "";
75  TString varvalue = "";
76  UInt_t value = 0;
77 
78  TString modtype = "";
79  TString dettype = "";
80  TString name = "";
81 
82  Int_t modnum = 0;
83  Int_t channum = 0;
84  Int_t slotnum = 0;
85 
86  Int_t ts_chan_num_to_plane = 0;
87  Int_t ts_chan_type_to_element = 0;
88 
89  //
90  // u ->? ts2 --> plane 2
91  // d ->? ts1 --> plane 1
92 
93  // mt -> element 0
94  // p -> element 1
95  // m -> element 2
96 
97 
98  Bool_t local_debug = false;
99  Int_t reference_counter = 0;
100 
101  EQwDetectorPackage package = kPackageNull;
102  EQwDirectionID direction = kDirectionNull;
103 
104  QwParameterFile mapstr(mapfile.Data()); //Open the file
105  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
106 
107  while (mapstr.ReadNextLine()){
108  mapstr.TrimComment('!'); // Remove everything after a '!' character.
109  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
110 
111  if (mapstr.LineIsEmpty()) continue;
112 
113  if (mapstr.HasVariablePair("=",varname,varvalue)){
114  // This is a declaration line. Decode it.
115  varname.ToLower();
116  value = QwParameterFile::GetUInt(varvalue);
117 
118  if (varname=="roc") {
119  RegisterROCNumber(value);
120  } else if (varname=="qdc_bank") {
121  RegisterSubbank(value);
122  fBankID[0] = value;
123  } else if (varname=="sca_bank") {
124  RegisterSubbank(value);
125  fBankID[1] = value;
126  } else if (varname=="f1tdc_bank") {
127  RegisterSubbank(value);
128  fBankID[2] = value;
129  } else if (varname=="slot") {
130  RegisterSlotNumber(value);
131  slotnum = value;
132  } else if (varname=="module") {
133  RegisterModuleType(varvalue);
134  }
135  } else {
136  // Break this line into tokens to process it.
137  modtype = mapstr.GetTypedNextToken<TString>();
138  modnum = mapstr.GetTypedNextToken<Int_t>();
139  channum = mapstr.GetTypedNextToken<Int_t>();
140  dettype = mapstr.GetTypedNextToken<TString>();
141  name = mapstr.GetTypedNextToken<TString>();
142 
143  if (local_debug) printf("%8s, %d, %d %s, %s\n", modtype.Data(), modnum, channum, dettype.Data(), name.Data());
144  // Push a new record into the element array
145  if (modtype=="SIS3801") {
146  QwSIS3801D24_Channel localchannel(name);
147  localchannel.SetNeedsExternalClock(kFALSE);
148  fSCAs.push_back(localchannel);
149  fSCAs_map[name] = fSCAs.size()-1;
150  fSCAs_offset.push_back(QwSIS3801D24_Channel::GetBufferOffset(modnum,channum));
151 
152  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fRegion = kRegionIDTrig;
153  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPackage = package;
154  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPlane = -1;
155  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fDirection = direction;
156  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = -1;
157 
158  }
159  else if (modtype=="V792") { // || modtype=="F1TDC") {
160  RegisterModuleType(modtype);
161  // Check to see if we've encountered this channel or name yet
162  if (fModulePtrs.at(fCurrentModuleIndex).at(channum).first != kUnknownModuleType) {
163  // We've seen this channel
164  } else if (FindSignalIndex(fCurrentType, name)>=0) {
165  // We've seen this signal
166  } else {
167  // If not, push a new record into the element array
168  LinkChannelToSignal(channum, name);
169  }
170  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fRegion = kRegionIDTrig;
171  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPackage = package;
172  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPlane = -1;
173  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fDirection = direction;
174  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = -1;
175  }
176  else if( modtype=="F1TDC") {
177 
178  RegisterModuleType(modtype);
179  // Check to see if we've encountered this channel or name yet
180  if (fModulePtrs.at(fCurrentModuleIndex).at(channum).first != kUnknownModuleType) {
181  // We've seen this channel
182  } else if (FindSignalIndex(fCurrentType, name)>=0) {
183  // We've seen this signal
184  } else {
185  // If not, push a new record into the element array
186  LinkChannelToSignal(channum, name);
187  }
188 
189 
190  if (name=="ts_reftime_f1") {
191 
192  fF1RefContainer -> AddF1TDCReferenceSignal(new F1TDCReferenceSignal(fCurrentBankIndex, slotnum, channum, "MasterTrigger"));
193  reference_counter++;
194 
195  fRefTime_SlotNum = slotnum;
196  fRefTime_ChanNum = channum;
197 
198  // printf("bank index %d Chan %d reference_counter %d\n", fCurrentBankIndex, channum, reference_counter);
200  fReferenceChannels.at ( fCurrentBankIndex ).second = channum;
201 
202  package = kPackageNull;
203 
204  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = fCurrentBankIndex;
206 
207  }
208  else {
209  if (name=="ts2m_f1") {
210  ts_chan_num_to_plane = 2;
211  ts_chan_type_to_element = 2;
212  package = kPackage2;
213  }
214  else if (name=="ts2p_f1") {
215  ts_chan_num_to_plane = 2;
216  ts_chan_type_to_element = 1;
217  package = kPackage2;
218  }
219  else if (name=="ts2mt_f1") {
220  ts_chan_num_to_plane = 2;
221  ts_chan_type_to_element = 0;
222  package = kPackage2;
223  }
224  else if (name=="ts1m_f1") {
225  ts_chan_num_to_plane = 1;
226  ts_chan_type_to_element = 2;
227  package = kPackage1;
228  }
229  else if (name=="ts1p_f1") {
230  ts_chan_num_to_plane = 1;
231  ts_chan_type_to_element = 1;
232  package = kPackage1;
233  }
234  else if (name=="ts1mt_f1") {
235  ts_chan_num_to_plane = 1;
236  ts_chan_type_to_element = 0;
237  package = kPackage1;
238 
239  }
240  else {
241  ts_chan_num_to_plane = -1;
242  ts_chan_type_to_element = -1;
243  package = kPackageNull;
244  }
245  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = ts_chan_type_to_element;
246  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPlane = ts_chan_num_to_plane;
247 
248  }
249 
250  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fRegion = kRegionIDTrig;
251  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPackage = package;
252  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fDirection = direction;
253 
254  }
255  else {
256  std::cerr << "LoadChannelMap: Unknown line: " << mapstr.GetLine().c_str() << std::endl;
257  }
258  }
259  }
260 
261  if(local_debug) {
262 
263 
264  Int_t unused_size_counter = 0;
265  std::size_t i = 0;
266 
267  for( i = 0; i < fModuleIndex.size(); i++)
268  {
269  for(size_t slot_size =0; slot_size < fModuleIndex.at(i).size(); slot_size++)
270  {
271  Int_t m_idx = 0;
272  m_idx = fModuleIndex.at(i).at(slot_size);
273  if(m_idx != -1 ) {
274  std::cout << "[" << i <<","<< slot_size << "] "
275  << " module index " << m_idx
276  << std::endl;
277  }
278  else {
279  unused_size_counter++;
280  }
281  }
282  }
283  // why the bank index is always odd number?
284  //
285 
286  printf("Total unused size of fModuleIndex vector %6d\n", unused_size_counter);
287 
288  for(i = 0; i < fReferenceChannels.size(); i++)
289  {
290  std::cout << "[" << i <<"] "
291  << " fRerenceChannel " << fReferenceChannels.at(i).first
292  << " " << fReferenceChannels.at(i).second
293  << std::endl;
294  }
295 
296  printf("\n------------- TS LoadChannelMap End%s\n\n", mapfile.Data());
297 
298  }
299 
300  ReportConfiguration(local_debug);
301 
302  mapstr.Close(); // Close the file (ifstream)
303  return 0;
304 }
305 
306 
308 {
309  SetDataLoaded(kFALSE);
310 
311 
312  fTDCHits.clear();
313  std::size_t i = 0;
314 
318 
319  // for (i=0; i<fReferenceData.size(); i++)
320  // {
321  // fReferenceData.at(i).clear();
322  // }
323 
324  for (i=0; i<fPMTs.size(); i++)
325  {
326  for (size_t j=0; j<fPMTs.at(i).size(); j++)
327  {
328  fPMTs.at(i).at(j).SetValue(0);
329  }
330  }
331 
332  for (i=0; i<fSCAs.size(); i++)
333  {
334  fSCAs.at(i).ClearEventData();
335  }
336 
337  return;
338 }
339 
340 Int_t QwTriggerScintillator::ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
341 {
342 
343  if( bank_id==fBankID[2] ) {
344 
345  TString subsystem_name;
346 
347  Int_t bank_index = 0;
348  Int_t tdc_index = 0;
349  UInt_t slot_id = 0;
350  UInt_t vme_slot_num = 0;
351 
352  Bool_t local_debug = false;
353 
354  QwF1TDC *local_f1tdc = NULL;
355 
356  bank_index = GetSubbankIndex(roc_id, bank_id);
357 
358  if(bank_index >=0) {
359  if(local_debug) {
360  std::cout << "fF1TDContainer " << fF1TDContainer
361  <<" local_f1tdc " << local_f1tdc << "\n";
362  }
363  subsystem_name = this->GetSubsystemName();
364  fF1TDContainer -> SetSystemName(subsystem_name);
365  fF1RefContainer-> SetSystemName(subsystem_name);
366 
367  for (Int_t plane_idx=0; plane_idx<kMaxNumberOfQwHitPlane; plane_idx++)
368  {
369  fSoftwareMeantimeContainer[plane_idx]->SetSystemName(subsystem_name);
370  fSoftwareMeantimeContainer[plane_idx]->SetPlane(plane_idx+1);
371  }
372 
373  if(local_debug) std::cout << "-----------------------------------------------------" << std::endl;
374 
375  std::cout << "QwTriggerScintillator : "
376  << subsystem_name
377  << ", "
378  << "ProcessConfigurationBuffer"
379  << std::endl;
380  std::cout << "ROC "
381  << std::setw(2) << roc_id
382  << " Bank [index,id]["
383  << bank_index
384  << ","
385  << bank_id
386  << "]"
387  << std::endl;
388  for ( slot_id=0; slot_id<kMaxNumberOfModulesPerROC; slot_id++ ) {
389  // slot id starts from 2, because 0 is one offset (1) difference between QwAnalyzer and VME definition,
390  // and 1 and 2 are used for CPU and TI. Tuesday, August 31 10:57:07 EDT 2010, jhlee
391 
392  tdc_index = GetModuleIndex(bank_index, slot_id);
393  vme_slot_num = slot_id;
394 
395  if(local_debug) {
396  std::cout << " "
397  << "Slot [id, VME num] ["
398  << std::setw(2) << slot_id
399  << ","
400  << std::setw(2) << vme_slot_num
401  << "]";
402  std::cout << " ";
403  }
404 
405 
406  local_f1tdc = NULL;
407 
408  if(slot_id > 2) { // save time
409 
410  if (tdc_index not_eq -1) {
411 
412  if(local_f1tdc) delete local_f1tdc; local_f1tdc = 0;
413 
414  local_f1tdc = new QwF1TDC(roc_id, vme_slot_num);
415 
416  local_f1tdc->SetF1BankIndex(bank_index);
417  local_f1tdc->SetF1TDCIndex(tdc_index);
418  local_f1tdc->SetF1TDCBuffer(buffer, num_words);
419  local_f1tdc->SetF1SystemName(subsystem_name);
420 
421  fF1TDContainer->AddQwF1TDC(local_f1tdc);
422 
423  if(local_debug) {
424  std::cout << "F1TDC index "
425  << std::setw(2)
426  << tdc_index
427  << std::setw(16)
428  << " local_f1tdc "
429  << *local_f1tdc
430  << " at "
431  << local_f1tdc;
432  }
433 
434  }
435  else {
436 
437  if(local_debug) {
438  std::cout << "Unused in "
439  << std::setw(4)
440  << subsystem_name
441  << std::setw(16)
442  << " local_f1tdc at "
443  << local_f1tdc;
444  }
445 
446  }
447 
448  }
449  else { // slot_id == only 0, 1, & 2
450 
451  if(local_debug) {
452  if (slot_id == 0) std::cout << " ";
453  else if (slot_id == 1) std::cout << "MVME CPU ";
454  else std::cout << "Trigger Interface"; // slot_id == 2;
455  }
456 
457  }
458 
459  if(local_debug) std::cout << std::endl;
460  }
461 
463 
464  if(local_debug) {
466  std::cout << "-----------------------------------------------------" << std::endl;
467  }
468  }
469  }
470 
471  return 0;
472 }
473 
474 
475 
476 Int_t QwTriggerScintillator::ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
477 {
478  Int_t index = 0;
479 
480  index = GetSubbankIndex(roc_id,bank_id);
481 
482 
483  if (bank_id==fBankID[0]) { // V792 or V775
484  if (index>=0 && num_words>0) {
485  // We want to process this ROC. Begin looping through the data.
486  SetDataLoaded(kTRUE);
487  for(size_t i=0; i<num_words ; i++) {
488  // Decode this word as a V775TDC word.
489  fQDCTDC.DecodeTDCWord(buffer[i]);
490 
491  if (! IsSlotRegistered(index, fQDCTDC.GetTDCSlotNumber())) continue;
492 
493  if (fQDCTDC.IsValidDataword()) {
494  // This is a V775 TDC data word
495  try {
497  fQDCTDC.GetTDCData());
498 
499  }
500  catch (std::exception& e) {
501  std::cerr << "Standard exception from QwTriggerScintillator::FillRawWord: "
502  << e.what() << std::endl;
503  Int_t chan = fQDCTDC.GetTDCChannelNumber();
504  std::cerr << " Parameters: index=="<<index
505  << "; GetV775SlotNumber()=="<<fQDCTDC.GetTDCSlotNumber()
506  << "; GetV775ChannelNumber()=="<<chan
507  << "; GetV775Data()=="<<fQDCTDC.GetTDCData()
508  << std::endl;
509  Int_t modindex = GetModuleIndex(index, fQDCTDC.GetTDCSlotNumber());
510  std::cerr << " GetModuleIndex()=="<<modindex
511  << "; fModulePtrs.at(modindex).size()=="
512  << fModulePtrs.at(modindex).size()
513  << "; fModulePtrs.at(modindex).at(chan).first {module type}=="
514  << fModulePtrs.at(modindex).at(chan).first
515  << "; fModulePtrs.at(modindex).at(chan).second {signal index}=="
516  << fModulePtrs.at(modindex).at(chan).second
517  << std::endl;
518  }
519  }
520  }
521  }
522  }
523 
524  else if (bank_id==fBankID[1]) { // SIS Scalar
525 
526  // Check if scaler buffer contains more than one event
527  if (buffer[0]/32!=1) return 0;
528 
529  if (index>=0 && num_words>0) {
530  SetDataLoaded(kTRUE);
531  UInt_t words_read = 0;
532  for (size_t i=0; i<fSCAs.size(); i++) {
533  words_read += fSCAs.at(i).ProcessEvBuffer(&(buffer[fSCAs_offset.at(i)]),
534  num_words-fSCAs_offset.at(i));
535  }
536  }
537  }
538 
539  else if (bank_id==fBankID[2]) { // F1TDC
540  // reset the refrence time
541  fRefTime = 0.0;
542 
543  Bool_t local_debug_f1 = false;
544 
545  Int_t bank_index = 0;
546  UInt_t tdc_data = 0;
547 
548 
549  Int_t dummy_slot_number = 0;
550  Int_t dummy_chan_number = 0;
551 
552  Bool_t data_integrity_flag = false;
553  Bool_t temp_print_flag = false;
554 
555  UInt_t hit_counter = 0;
556 
557  bank_index = GetSubbankIndex(roc_id, bank_id);
558 
559  if (bank_index>=0 && num_words>0) {
560  // We want to process this ROC. Begin looping through the data.
561  SetDataLoaded(kTRUE);
562 
563 
564  //
565  // CheckDataIntegrity() do "counter" whatever errors in each F1TDC
566  // and check whether data is OK or not.
567 
568  data_integrity_flag = fF1TDContainer->CheckDataIntegrity(roc_id, buffer, num_words);
569  // if it is false (TFO, EMM, and SYN), the whole buffer is excluded for
570  // the further process, because of multiblock data transfer.
571 
572  if (data_integrity_flag) {
573 
574  dummy_slot_number = 0;
575  dummy_chan_number = 0;
576  hit_counter = 0;
577  if(local_debug_f1) printf("\n");
578  for (UInt_t i=0; i<num_words ; i++) {
579 
580  // Decode this word as a F1TDC word.
581  fF1TDCDecoder.DecodeTDCWord(buffer[i], roc_id);
582 
583  // For MQwF1TDC, roc_id is needed to print out some warning messages.
584 
585  Int_t tdc_slot_number = fF1TDCDecoder.GetTDCSlotNumber();
586  Int_t tdc_chan_number = fF1TDCDecoder.GetTDCChannelNumber();
587  //Int_t tdcindex = GetModuleIndex(bank_index, tdc_slot_number);
588 
589 
590  if ( tdc_slot_number == 31) {
591  // This is a custom word which is not defined in
592  // the F1TDC, so we can use it as a marker for
593  // other data; it may be useful for something.
594  }
595 
596  // Each subsystem has its own interesting slot(s), thus
597  // here, if this slot isn't in its slot(s) (subsystem map file)
598  // we skip this buffer to do the further process
599 
600  if (not IsSlotRegistered(bank_index, tdc_slot_number) ) continue;
601 
602  if(temp_print_flag) std::cout << fF1TDCDecoder << std::endl;
603 
604  if ( fF1TDCDecoder.IsValidDataword() ) {//;;
605  // if decoded F1TDC data has a valid slot, resolution locked, data word, no overflow (0xFFFF), and no fake data
606 
607  try {
608 
609  tdc_data = fF1TDCDecoder.GetTDCData();
610  if (dummy_slot_number == tdc_slot_number && dummy_chan_number == tdc_chan_number) {
611  hit_counter++;
612  }
613  else {
614  hit_counter = 0;
615  }
616 
617  if(local_debug_f1) {
618  printf("TS::ProcessEvBuffer: [%4d] hit counter %d, bank_index %2d slot_number [%2d,%2d] chan [%2d,%2d] data %10d %10.2f\n", i, hit_counter,
619  bank_index, tdc_slot_number, fRefTime_SlotNum, tdc_chan_number, fRefTime_ChanNum,tdc_data, fRefTime);
620  }
621 
622  if (hit_counter == 0) {
623  FillRawWord (bank_index, tdc_slot_number, tdc_chan_number, tdc_data);
624  if ( IsF1ReferenceChannel(tdc_slot_number,tdc_chan_number) ) {
625  fRefTime = (Double_t) tdc_data;
626  }
627  }
628 
629  FillRawTDCWord(bank_index, tdc_slot_number, tdc_chan_number, tdc_data);
630 
631  dummy_slot_number = tdc_slot_number;
632  dummy_chan_number = tdc_chan_number;
633  // printf("\n");
634 
635  }
636  catch (std::exception& e) {
637  std::cerr << "Standard exception from QwTriggerScintillator::FillRawWord: "
638  << e.what() << std::endl;
639  std::cerr << " Parameters: index==" <<bank_index
640  << "; GetF1SlotNumber()==" <<tdc_slot_number
641  << "; GetF1ChannelNumber()=="<<tdc_chan_number
642  << "; GetF1Data()==" <<tdc_data
643  << std::endl;
644  }
645  }//;;
646  } // for (UInt_t i=0; i<num_words ; i++) {
647  }
648  }
649  }
650 
651  return 0;
652 }
653 
654 
656 {
657  if (! HasDataLoaded()) return;
658 
659  TString elementname = "";
660  Double_t rawtime_arb_unit = 0.0;
661  Double_t corrected_time_arb_unit = 0.0;
662  Double_t time_ns = 0.0;
663 
664  Int_t bank_index = 0;
665  Int_t slot_num = 0;
666 
667  for (size_t i=0; i<fPMTs.size(); i++)
668  {//;
669  for (size_t j=0; j<fPMTs.at(i).size(); j++)
670  {//;;
671 
672  elementname = fPMTs.at(i).at(j).GetElementName();
673 
674  if (elementname.EndsWith("f1") ) {
675  rawtime_arb_unit = fPMTs.at(i).at(j).GetValue(); // returns Double_t
676 
677  if ( rawtime_arb_unit not_eq 0.0) {
678 
679  if ( not elementname.Contains("reftime") ) {
680  bank_index = fPMTs.at(i).at(j).GetSubbankID();
681  slot_num = fPMTs.at(i).at(j).GetModule();
682  corrected_time_arb_unit = fF1TDContainer->ReferenceSignalCorrection(rawtime_arb_unit, fRefTime, bank_index, slot_num);
683  time_ns = fF1TDContainer->ReturnTimeCalibration(corrected_time_arb_unit);
684  fPMTs.at(i).at(j).SetValue(time_ns);
685  // if (bank_index == 2 and slot_num == 4) {
686  // printf("TS::ProcessBuffer: bank_index %2d slot_number %2d raw au %10f reftime au %10.2f, corrected au %10.2f, corrected ns %10.2f\n",
687  // bank_index, slot_num, rawtime_arb_unit, reftime, corrected_time_arb_unit, time_ns);
688  // }
689  }
690  else {
691  // // we save the referennce raw time
692  fPMTs.at(i).at(j).SetValue(rawtime_arb_unit);
693  }
694  }
695  else {
696  fPMTs.at(i).at(j).SetValue(rawtime_arb_unit); // zero
697  }
698 
699  }
700  else {
701  fPMTs.at(i).at(j).ProcessEvent();
702  }
703 
704 
705  // fPMTs.at(i).at(j).ProcessEvent();
706  // elementname = fPMTs.at(i).at(j).GetElementName();
707 
708  // // Check whether the element is "reftime"
709  // if ( not elementname.Contains("reftime") ) {
710  // rawtime_arb_unit = fPMTs.at(i).at(j).GetValue();
711 
712  // if (elementname.EndsWith("f1") && rawtime_arb_unit!=0.0) {
713 
714  // bank_index = fPMTs.at(i).at(j).GetSubbankID();
715  // slot_num = fPMTs.at(i).at(j).GetModule();
716  // // if the reference time signal is recorded by (a) channel(s) of F1TDC(s),
717  // // we correct them. And if not, we set them to zero. (jhlee)
718 
719  // if ( reftime!=0.0 ) {
720  // corrected_time_arb_unit = fF1TDContainer->ReferenceSignalCorrection(rawtime_arb_unit, reftime, bank_index, slot_num);
721  // }
722  // else {
723  // corrected_time_arb_unit = 0.0;
724  // }
725  // fPMTs.at(i).at(j).SetValue(corrected_time_arb_unit);
726  // } // if (elementname.EndsWith("f1") && rawtime!=0.0) {
727  // }
728  // // if ( not elementname.Contains("reftime") ) {
729  // //
730  // // we keep the raw reference time information in an output ROOT file.
731  // //
732  }//;;
733  }//;
734 
735 
736  // F1TDCs of QwHit
738  UpdateHits();
740 
741 
742  // SIS3801 scaler
743  std::size_t i = 0;
744  for (i=0; i<fSCAs.size(); i++)
745  {
746  fSCAs.at(i).ProcessEvent();
747  }
748  return;
749 };
750 
751 
752 
753 
755 {
756  options.AddOptions()("enable-ts-software-meantime",
757  po::value<Bool_t>()->default_bool_value(true),
758  "Create Software meantime for TS in QwHits"
759  );
760  options.AddOptions()("set-ts-software-meantime-timewindow",
761  po::value<Double_t>()->default_value(20.0),
762  "TimeWindow (ns) for TS Software meantime"
763  );//max window is 2000 ns
764  return;
765 };
766 
768 {
769  fSoftwareMeantimeOption = options.GetValue<Bool_t> ( "enable-ts-software-meantime" );
770  fSoftwareMeantimeTimeWindowNs = options.GetValue<Double_t> ( "set-ts-software-meantime-timewindow" );
771  return;
772 };
773 
774 
775 
776 void QwTriggerScintillator::ConstructHistograms(TDirectory *folder, TString &prefix){
777 
778  for (size_t i=0; i<fPMTs.size(); i++){
779  for (size_t j=0; j<fPMTs.at(i).size(); j++){
780  fPMTs.at(i).at(j).ConstructHistograms(folder, prefix);
781  }
782  }
783 
784  for (size_t i=0; i<fSCAs.size(); i++) {
785  fSCAs.at(i).ConstructHistograms(folder, prefix);
786  }
787 
788 }
789 
791  if (! HasDataLoaded()) return;
792  for (size_t i=0; i<fPMTs.size(); i++){
793  for (size_t j=0; j<fPMTs.at(i).size(); j++){
794  fPMTs.at(i).at(j).FillHistograms();
795  }
796  }
797 
798  for (size_t i=0; i<fSCAs.size(); i++) {
799  fSCAs.at(i).FillHistograms();
800  }
801 
802 }
803 
804 void QwTriggerScintillator::ConstructBranchAndVector(TTree *tree, TString& prefix, std::vector<Double_t> &values)
805 {
806  fTreeArrayIndex = values.size();
807 
808  TString basename;
809  if (prefix=="") basename = "trigscint";
810  else basename = prefix;
811 
812  TString element_name = "";
813 
814  TString list = "";
815  for (size_t i=0; i<fPMTs.size(); i++){
816  for (size_t j=0; j<fPMTs.at(i).size(); j++){
817  element_name = fPMTs.at(i).at(j).GetElementName();
818  if (element_name!="") {
819  values.push_back(0.0);
820  list += ":" + element_name + "/D";
821  }
822  }
823  }
824 
825  element_name = "";
826 
827  for (size_t i=0; i<fSCAs.size(); i++){
828  element_name = fSCAs.at(i).GetElementName();
829  if (element_name != "") {
830  values.push_back(0.0);
831  list += ":" + element_name + "/D";
832  }
833  }
834 
835  if (list[0]==':') {
836  list = list(1,list.Length()-1);
837  }
838 
839  fTreeArrayNumEntries = values.size() - fTreeArrayIndex;
840  tree->Branch(basename, &values[fTreeArrayIndex], list);
841  return;
842 }
843 
844 void QwTriggerScintillator::FillTreeVector(std::vector<Double_t> &values) const
845 {
846  if (! HasDataLoaded()) return;
847 
848  Int_t index = fTreeArrayIndex;
849  for (size_t i=0; i<fPMTs.size(); i++){
850  for (size_t j=0; j<fPMTs.at(i).size(); j++){
851  if (fPMTs.at(i).at(j).GetElementName()!="") {
852  values[index] = fPMTs.at(i).at(j).GetValue();
853  index++;
854  }
855  }
856  }
857 
858  for (size_t i=0; i<fSCAs.size(); i++) {
859  if (fSCAs.at(i).GetElementName() != "") {
860  values[index] = fSCAs.at(i).GetValue();
861  index++;
862  }
863  }
864  return;
865 }
866 
867 
868 
869 
870 
872 {
873  if (fPMTs.size() == value.fPMTs.size()){
874  for (size_t i=0; i<fPMTs.size(); i++){
875  for (size_t j=0; j<fPMTs.at(i).size(); j++){
876  fPMTs.at(i).at(j) = value.fPMTs.at(i).at(j);
877  }
878  }
879  } else {
880  std::cerr << "QwTriggerScintillator::operator=: Problems!!!"
881  << std::endl;
882  }
883  return *this;
884 }
885 
886 
887 
888 
890 {
892  fModuleIndex.clear();
893  fModulePtrs.clear();
894  fModuleTypes.clear();
895 
896  fDetectorIDs.clear();
897  fTDCHits.clear();
898  fNumberOfModules = 0;
899 }
900 
902 {
903  Int_t status = 0;
904  status = VQwSubsystemTracking::RegisterROCNumber(roc_id, 0);
905  std::vector<Int_t> tmpvec(kMaxNumberOfModulesPerROC,-1);
906  fModuleIndex.push_back(tmpvec);
907  return status;
908 }
909 
910 Int_t QwTriggerScintillator::RegisterSubbank(const UInt_t bank_id)
911 {
912  Int_t status = VQwSubsystem::RegisterSubbank(bank_id);
913  Int_t current_roc_id = VQwSubsystem::fCurrentROC_ID;
914 
915  std::size_t reference_size = fReferenceChannels.size();
916 
917  fCurrentBankIndex = GetSubbankIndex(current_roc_id, bank_id);
918 
919  if ( (Int_t) reference_size <= fCurrentBankIndex) {
922  }
923 
924  std::vector<Int_t> tmpvec(kMaxNumberOfModulesPerROC,-1);
925  fModuleIndex.push_back(tmpvec);
926 
927  std::cout<< "QwTriggerScintillator::RegisterSubbank()"
928  <<" ROC " << current_roc_id
929  <<" Subbank " << bank_id
930  <<" with BankIndex " << fCurrentBankIndex
931  << std::endl;
932 
933  return status;
934 }
935 
937 {
938  std::pair<EQwModuleType, Int_t> tmppair;
939  tmppair.first = kUnknownModuleType;
940  tmppair.second = -1;
941 
942  if (slot_id < kMaxNumberOfModulesPerROC){
943 
944  if ( fCurrentBankIndex <= (Int_t) fModuleIndex.size()) {
945 
946 
947  // fModuleTypes and fModulePtrs could be replaced by fDetectorID,
948  // but I leave them here while .....
949  // Tuesday, January 24 11:49:20 EST 2012, jhlee
950 
951  fModuleTypes.resize(fNumberOfModules+1);
952  fModulePtrs.resize(fNumberOfModules+1);
954  tmppair);
955 
956  // fNumberOfModules = fModulePtrs.size();
957 
958  fDetectorIDs.resize(fNumberOfModules+1);
960 
961  // // reassign kNumberOfModules after resize it
962 
963  fNumberOfModules = (Int_t) fDetectorIDs.size();
965  fCurrentSlot = slot_id;
967  }
968  } else {
969  std::cerr << "QwTriggerScintillator::RegisterSlotNumber: Slot number "
970  << slot_id << " is larger than the number of slots per ROC, "
971  << kMaxNumberOfModulesPerROC << std::endl;
972  }
973  return fCurrentModuleIndex;
974 }
975 
977 {
978  moduletype.ToUpper();
979 
980  // Check to see if we've already registered a type for the current slot,
981  // if so, throw an error...
982 
983  if (moduletype=="V792"){
985  } else if (moduletype=="V775"){
987  } else if (moduletype=="F1TDC") {
989  } else if (moduletype=="SIS3801") {
991  }
993 
994  if ((Int_t) fPMTs.size() <= fCurrentType){
995  fPMTs.resize(fCurrentType+1);
996  }
997  return fCurrentType;
998 }
999 
1000 
1001 Int_t QwTriggerScintillator::LinkChannelToSignal(const UInt_t chan, const TString &name)
1002 {
1003  fPMTs.at(fCurrentType).push_back(QwPMT_Channel(name));
1004  fModulePtrs.at(fCurrentModuleIndex).at(chan).first = fCurrentType;
1005  fModulePtrs.at(fCurrentModuleIndex).at(chan).second = fPMTs.at(fCurrentType).size() -1;
1006 
1007  return 0;
1008 
1009 }
1010 
1012  Int_t slot_num,
1013  Int_t chan, UInt_t data)
1014 {
1015  Int_t modindex = GetModuleIndex(bank_index,slot_num);
1016  if (modindex != -1){
1017  EQwModuleType modtype = fModulePtrs.at(modindex).at(chan).first;
1018  Int_t chanindex = fModulePtrs.at(modindex).at(chan).second;
1019  if (modtype == kUnknownModuleType || chanindex == -1){
1020  // This channel is not connected to anything.
1021  // Do nothing.
1022  } else {
1023  // if (bank_index == 2 and slot_num == 4 and chan == 4) {
1024  // printf("FillRawWord bank_index %2d slot_number %2d chan %2d, data %10d \n",
1025  // bank_index, slot_num, chan, data);
1026  // }
1027  fPMTs.at(modtype).at(chanindex).SetValue(data);
1028  fPMTs.at(modtype).at(chanindex).SetSubbankID(bank_index);
1029  fPMTs.at(modtype).at(chanindex).SetModule(slot_num);
1030  }
1031  }
1032 
1033 }
1034 
1035 
1036 
1038  Int_t slot_num,
1039  Int_t chan,
1040  UInt_t data)
1041 {
1042  Bool_t local_debug = false;
1043  Int_t tdcindex = 0;
1044 
1045  tdcindex = GetModuleIndex(bank_index,slot_num);
1046 
1047 
1048  // I think, it is not necessary, but is just "safe" double check routine.
1049  if (tdcindex not_eq -1) {
1050  // if ( slot_num == 4 and chan == 4) {
1051  // printf("FillRawTDCWord bank_index %2d slot_number %2d chan %2d, data %10d \n",
1052  // bank_index, slot_num, chan, data);
1053  // }
1054  Int_t hitcnt = 0;
1055 
1056  EQwDirectionID direction = kDirectionNull;
1057 
1058  TString name = "";
1059 
1060  fF1RefContainer->SetReferenceSignal(bank_index, slot_num, chan, data, local_debug);
1061 
1062  // ts2 plane 2, ts1 is plane 1
1063  Int_t plane = fDetectorIDs.at(tdcindex).at(chan).fPlane;
1064  // mt is element 0, p is element 1, and m is element 2
1065  Int_t element = fDetectorIDs.at(tdcindex).at(chan).fElement;
1066  EQwDetectorPackage package = fDetectorIDs.at(tdcindex).at(chan).fPackage;
1067  Int_t octant = fDetectorIDs.at(tdcindex).at(chan).fOctant;
1068 
1069  if(local_debug) {
1070  printf("bank_idx %d, slot %d, plane %d, element %d, package %d\n",
1071  bank_index, slot_num, (Int_t) plane, (Int_t) element, (Int_t) package);
1072  }
1073 
1074  if (plane == -1 or element == -1){
1075  // This channel is not connected to anything. Do nothing.
1076  }
1077  else if (plane == kF1ReferenceChannelNumber){
1078  fReferenceData.at(element).push_back(data);
1079  // we assign the reference time into fReferenceData according the module index
1080  // See LocalChannelMap
1081  if(local_debug) {
1082  std::cout << "At QwTriggerScintillator::FillRawTDCWord "
1083  << " bank index " << bank_index
1084  << " slot num " << slot_num
1085  << " chan num " << chan
1086  << " hitcnt " << 0
1087  << " plane " << plane
1088  << " wire " << element
1089  << " package " << package
1090  << " diection " << direction
1091  << " data " << data
1092  << " fTDCHits.size() " << 0
1093  << std::endl;
1094  }
1095  }
1096  else {
1097  direction = fDetectorIDs.at(tdcindex).at(chan).fDirection;
1098 
1099  hitcnt = std::count_if(fTDCHits.begin(), fTDCHits.end(),
1100  boost::bind(
1101  &QwHit::WireMatches, _1, kRegionIDTrig, boost::ref(package), boost::ref(plane), boost::ref(element)
1102  )
1103  );
1104 
1105  fTDCHits.push_back(
1106  QwHit(
1107  bank_index,
1108  slot_num,
1109  chan,
1110  hitcnt,
1111  kRegionIDTrig,
1112  package,
1113  octant,
1114  plane,
1115  direction,
1116  element,
1117  data
1118  )
1119  );
1120 
1121  if(local_debug) {
1122  std::cout << "At QwTriggerScintillator::FillRawTDCWord "
1123  << " bank index " << bank_index
1124  << " slot num " << slot_num
1125  << " chan num " << chan
1126  << " hitcnt " << hitcnt
1127  << " plane " << plane
1128  << " wire " << element
1129  << " package " << package
1130  << " diection " << direction
1131  << " data " << data
1132  << " fTDCHits.size() " << fTDCHits.size()
1133  << std::endl;
1134  }
1135 
1136  }
1137  // }
1138  } // (tdcindex not_eq -1) {
1139 
1140  return;
1141 }
1142 
1143 
1144 
1146 {
1147 
1148  UInt_t bank_index = 0;
1149  Double_t raw_time_arb_unit = 0.0;
1150  Double_t ref_time_arb_unit = 0.0;
1151  Double_t time_arb_unit = 0.0;
1152  // EQwDetectorPackage package = kPackageNull;
1153 
1154  Bool_t local_debug = false;
1155  Int_t slot_num = 0;
1156 
1157  TString reference_name1 = "MasterTrigger";
1158  // TString reference_name2 = "CopyMasterTrigger";
1159 
1160 
1161  for ( std::vector<QwHit>::iterator hit=fTDCHits.begin(); hit!=fTDCHits.end(); hit++ )
1162  {
1163 
1164  bank_index = hit -> GetSubbankID();
1165  slot_num = hit -> GetModule();
1166  raw_time_arb_unit = (Double_t) hit -> GetRawTime();
1167  ref_time_arb_unit = fF1RefContainer -> GetReferenceTimeAU(bank_index, reference_name1);
1168  //
1169  // if there is no reference time due to a channel error, try to use a copy of mater trigger
1170  //
1171  // if(ref_time_arb_unit==0.0) {
1172  // ref_time_arb_unit = fF1RefContainer->GetReferenceTimeAU(bank_index, reference_name2);
1173  // }
1174  // second time, it returns 0.0, we simply ignore this event ....
1175  // set time zero. ReferenceSignalCorrection() will return zero, and increase RFM counter...
1176  //
1177  time_arb_unit = fF1TDContainer->ReferenceSignalCorrection(raw_time_arb_unit, ref_time_arb_unit, bank_index, slot_num);
1178 
1179  hit -> SetTime(time_arb_unit);
1180  hit -> SetRawRefTime((UInt_t) ref_time_arb_unit);
1181 
1182  if(local_debug) {
1183  QwMessage << this->GetSubsystemName()
1184  << " BankIndex " << std::setw(2) << bank_index
1185  << " Slot " << std::setw(2) << slot_num
1186  << " RawTime : " << std::setw(6) << raw_time_arb_unit
1187  << " RefTime : " << std::setw(6) << ref_time_arb_unit
1188  << " time : " << std::setw(6) << time_arb_unit
1189  << std::endl;
1190 
1191  }
1192  }
1193  // std::vector<Double_t> reftimes;
1194  // std::vector<Bool_t> refchecked;
1195  // std::vector<Bool_t> refokay;
1196  // Bool_t allrefsokay;
1197 
1198 
1199  // std::size_t ref_size = 0;
1200  // std::size_t i = 0;
1201  // std::size_t j = 0;
1202 
1203  // ref_size = fReferenceData.size();
1204 
1205  // reftimes.resize ( ref_size );
1206  // refchecked.resize( ref_size );
1207  // refokay.resize ( ref_size );
1208 
1209  // for ( i=0; i<ref_size; i++ ) {
1210  // reftimes.at(i) = 0.0;
1211  // refchecked.at(i) = kFALSE;
1212  // refokay.at(i) = kFALSE;
1213  // }
1214 
1215  // allrefsokay = kTRUE;
1216 
1217 
1218 
1219  // UInt_t bank_index = 0;
1220  // Double_t raw_time_arb_unit = 0.0;
1221  // Double_t ref_time_arb_unit = 0.0;
1222  // Double_t time_arb_unit = 0.0;
1223 
1224  // Bool_t local_debug = false;
1225 
1226  // for ( std::vector<QwHit>::iterator hit=fTDCHits.begin(); hit!=fTDCHits.end(); hit++ )
1227  // {
1228  // // Only try to check the reference time for a bank if there is at least one
1229  // // non-reference hit in the bank.
1230  // bank_index = hit->GetSubbankID();
1231 
1232  // // if(local_debug) printf("QwHit :: bank index %d\n", bank_index);
1233 
1234  // if ( not refchecked.at(bank_index) ) {
1235 
1236  // if ( fReferenceData.at(bank_index).empty() ) {
1237  // std::cout << "QwTriggerScintillator::SubtractReferenceTimes: Subbank ID "
1238  // << bank_index << " is missing a reference time." << std::endl;
1239  // refokay.at(bank_index) = kFALSE;
1240  // allrefsokay = kFALSE;
1241  // }
1242  // else {
1243  // if(fReferenceData.at(bank_index).size() not_eq 1) {
1244  // std::cout << "Multiple hits are recorded in the reference channel, we use the first hit signal as the refererence signal." << std::endl;
1245  // }
1246  // reftimes.at(bank_index) = fReferenceData.at(bank_index).at(0);
1247  // refokay.at(bank_index) = kTRUE;
1248  // }
1249 
1250  // if (refokay.at(bank_index)){
1251  // for ( j=0; j<fReferenceData.at(bank_index).size(); j++ )
1252  // {
1253  // // printf("Reference time %f fReferenceData.at(%d).at(%d) %f\n",
1254  // // reftimes.at(bank_index), (Int_t) bank_index, (Int_t) j, fReferenceData.at(bank_index).at(j));
1255  // fReferenceData.at(bank_index).at(j) -= reftimes.at(bank_index);
1256  // // printf("Reference time %f fReferenceData.at(%d).at(%d) %f\n",
1257  // // reftimes.at(bank_index), (Int_t) bank_index, (Int_t) j, fReferenceData.at(bank_index).at(j));
1258  // }
1259  // }
1260 
1261  // refchecked.at(bank_index) = kTRUE;
1262  // }
1263 
1264  // if ( refokay.at(bank_index) ) {
1265  // Int_t slot_num = hit -> GetModule();
1266  // raw_time_arb_unit = (Double_t) hit -> GetRawTime();
1267  // ref_time_arb_unit = (Double_t) reftimes.at(bank_index);
1268 
1269  // time_arb_unit = fF1TDContainer->ReferenceSignalCorrection(raw_time_arb_unit, ref_time_arb_unit, bank_index, slot_num);
1270 
1271  // hit -> SetTime(time_arb_unit);
1272  // hit -> SetRawRefTime((UInt_t) ref_time_arb_unit);
1273 
1274  // if(local_debug) {
1275  // QwMessage << this->GetSubsystemName()
1276  // << " BankIndex " << std::setw(2) << bank_index
1277  // << " Slot " << std::setw(2) << slot_num
1278  // << " RawTime : " << std::setw(6) << raw_time_arb_unit
1279  // << " RefTime : " << std::setw(6) << ref_time_arb_unit
1280  // << " time : " << std::setw(6) << time_arb_unit
1281  // << std::endl;
1282 
1283  // }
1284  // }
1285  // }
1286 
1287  // // bank_index = 0;
1288 
1289  // if ( not allrefsokay ) {
1290  // std::vector<QwHit> tmp_hits;
1291  // tmp_hits.clear();
1292  // for ( std::vector<QwHit>::iterator hit=fTDCHits.begin(); hit!=fTDCHits.end(); hit++ )
1293  // {
1294  // bank_index = hit->GetSubbankID();
1295  // if ( refokay.at(bank_index) ) tmp_hits.push_back(*hit);
1296  // }
1297  // // std::cout << "FTDC size " << fTDCHits.size() << "tmp hit size " << tmp_hits.size() << std::endl;
1298  // fTDCHits.clear();
1299  // fTDCHits = tmp_hits;
1300  // // std::cout << "FTDC size " << fTDCHits.size() << "tmp hit size " << tmp_hits.size() << std::endl;
1301  // }
1302 
1303  return;
1304 }
1305 
1306 
1307 
1308 
1310 {
1311 
1312  // std::vector... is weird
1313  // I use a plane number to assign a f1tdc channel. Channel 99 is the F1TDC reference channel
1314  // , becaue I see plan is 0 in qweak_new.geo file and I think, nowhere plane is used in analyzer
1315  // But, I am wrong. This double std::vector fDetectorInfo uses plane number as second index,
1316  // So I had the notorious following error
1317  // Terminate called after throwing an instance of 'std::out_of_range'
1318  // what(): vector::_M_range_check
1319  // Abort
1320  //
1321  //
1322  // I don't care about QwDetectorInfo for other tracking subsystems except VDC/HDC,
1323  // I disable to fill QwDetectorInfo into QwHit
1324 
1325  // Thursday, January 26 10:30:09 EST 2012, jhlee
1326 
1327 
1328  // EQwDetectorPackage package = kPackageNull;
1329  // // Int_t plane = 0;
1330 
1331  // QwDetectorID local_id;
1332  // QwDetectorInfo *local_info;
1333 
1334  for(std::vector<QwHit>::iterator iter=fTDCHits.begin(); iter!=fTDCHits.end(); ++iter)
1335  {
1336  // local_id = iter->GetDetectorID();
1337  // package = local_id.fPackage;
1338  // // plane = local_id.fPlane;
1339  // // For TS, we have only 1 plane in each package according to its geometry, but I use a plane
1340  // // number to assign a f1tdc channel. Channel 99 is not assigned into this vector
1341  // //
1342  // local_info = fDetectorInfo.in(package).at(0);
1343  // // local_info = fDetectorInfo.in(package).at(plane);
1344 
1345  // iter->SetDetectorInfo(local_info);
1346  iter->ApplyTimeCalibration(fF1TDCResolutionNS); // Fill fTimeRes and fTimeNs in QwHit
1347 
1348  }
1349 
1350  return;
1351 }
1352 
1353 
1354 
1356 {
1357  // reduce if {},
1358 
1359  // if option is false, end this function
1360  if( !option ) return;
1361  // // if fTDCHits size is zero, end this function
1362  if (fTDCHits.size() ==0) return;
1363 
1364 
1365  Bool_t local_debug = false;
1366 
1367  Long64_t ev_num = 0;
1368  Int_t plane = 0;
1369  Int_t octant = 0;
1370  Int_t element = 0;
1371  Int_t hitnumber = 0;
1372  Double_t timens = 0.0;
1373 
1374 
1375  Int_t bank_index = 0;
1376  Int_t slot_num = 0;
1377  Int_t chan_num = 0;
1378  EQwDetectorPackage package = kPackageNull;
1379  EQwDirectionID direction = kDirectionNull;
1380  EQwRegionID region = kRegionIDTrig;
1381 
1382  MeanTime* ts_mt_time = NULL;
1383 
1384  Int_t v_plane_idx = 0;
1385 
1386  for(std::vector<QwHit>::iterator iter=fTDCHits.begin(); iter!=fTDCHits.end(); ++iter)
1387  {
1388  plane = iter->GetPlane();
1389  if(plane == 1 || plane == 2) {
1390  v_plane_idx = plane -1;
1391  element = iter->GetElement();
1392  hitnumber = iter->GetHitNumber();
1393  timens = iter->GetTimeNs();
1394  fSoftwareMeantimeContainer[v_plane_idx] -> Add(element, hitnumber, timens);
1395  }
1396  }
1397 
1398  // Reset bank_index, slot_num, and chan_num to -9,-99,-999
1399  // because we don't have these numbers for software meantime
1400  // and we don't need these numbers in order to access software meantime from QwHit
1401 
1403  bank_index = -9;
1404  slot_num = -99;
1405  chan_num = -999;
1406 
1407 
1408  for (v_plane_idx=0; v_plane_idx<kMaxNumberOfQwHitPlane; v_plane_idx++)
1409  {
1410 
1411  if(v_plane_idx == 0) {
1412  package = kPackage1;
1413  }
1414  else if (v_plane_idx ==1){
1415  package = kPackage2;
1416  }
1417  else {
1418  break;
1419  }
1420 
1421  fSoftwareMeantimeContainer[v_plane_idx] -> SetEventId(ev_num);
1422  fSoftwareMeantimeContainer[v_plane_idx] -> SetTimeWindow(fSoftwareMeantimeTimeWindowNs);
1423  fSoftwareMeantimeContainer[v_plane_idx] -> ProcessMeanTime();
1424  plane = fSoftwareMeantimeContainer[v_plane_idx]->GetPlane();
1425 
1426  ts_mt_time = NULL;
1427  for (Int_t v_smt_idx=0; v_smt_idx < fSoftwareMeantimeContainer[v_plane_idx]->SoftwareMTSize(); v_smt_idx++ )
1428  {
1429  ts_mt_time = fSoftwareMeantimeContainer[v_plane_idx]->GetMeanTimeObject(v_smt_idx);
1430  ts_mt_time -> Print(local_debug);
1431 
1432  QwHit software_meantime_hit(bank_index, slot_num, chan_num, v_smt_idx,
1433  region, package, octant, plane, direction,
1434  ts_mt_time->GetSoftwareMeantimeHitElement()
1435  );
1436  software_meantime_hit.SetTimens(ts_mt_time->GetMeanTime());
1437  fTDCHits.push_back(software_meantime_hit);
1438 
1439  QwHit software_positive_hit(bank_index, slot_num, chan_num, v_smt_idx,
1440  region, package, octant, plane, direction,
1441  ts_mt_time->GetSoftwarePositiveHitElement()
1442  );
1443  software_positive_hit.SetTimens(ts_mt_time->GetPositiveValue());
1444  software_positive_hit.SetHitNumberR(ts_mt_time->GetPositiveHitId());
1445  fTDCHits.push_back(software_positive_hit);
1446 
1447  QwHit software_negative_hit(bank_index, slot_num, chan_num, v_smt_idx,
1448  region, package, octant, plane, direction,
1449  ts_mt_time->GetSoftwareNegativeHitElement()
1450  );
1451  software_negative_hit.SetTimens(ts_mt_time->GetNegativeValue());
1452  software_negative_hit.SetHitNumberR(ts_mt_time->GetNegativeHitId());
1453  fTDCHits.push_back(software_negative_hit);
1454 
1455  QwHit software_subtract_hit(bank_index, slot_num, chan_num, v_smt_idx,
1456  region, package, octant, plane, direction,
1457  ts_mt_time->GetSoftwareSubtractHitElement()
1458  );
1459  software_subtract_hit.SetTimens(ts_mt_time->GetSubtractTime());
1460  fTDCHits.push_back(software_subtract_hit);
1461  }
1462  }
1463 
1464 
1465  if(local_debug) {
1466 
1467  TString output = "";
1468 
1469  for(std::vector<QwHit>::iterator iter=fTDCHits.begin(); iter!=fTDCHits.end(); ++iter)
1470  {
1471 
1472  bank_index = iter->GetSubbankID();
1473  slot_num = iter->GetModule();
1474  chan_num = iter->GetChannel();
1475  package = iter->GetPackage();
1476  // direction = iter->GetDirection();
1477  plane = iter->GetPlane();
1478  element = iter->GetElement();
1479  hitnumber = iter->GetHitNumber();
1480  timens = iter->GetTimeNs();
1481 
1482 
1483  output += GetSubsystemName();
1484  output += Form(" Bank ID %+2d", bank_index);
1485  output += Form(" Slot %+3d", slot_num);
1486  output += Form(" Chan %+4d", chan_num);
1487  output += Form(" Package %2d", (Int_t) package);
1488  output += Form(" Plane %2d", plane);
1489  output += " Element ";
1490  output += element;
1491  output += " Hit ";
1492  output += hitnumber;
1493  output += Form(" TimeNs %+10.2f\n", timens);
1494 
1495 
1496  }
1497 
1498  std::cout << "Size fTDCHits " << fTDCHits.size()
1499  << " Event Number " << ev_num << "\n" << output << std::endl;
1500  }
1501 
1502  return;
1503 }
1504 
1505 
1506 
1507 
1508 Int_t QwTriggerScintillator::GetModuleIndex(size_t bank_index, size_t slot_num) const
1509 {
1510  Int_t modindex = -1;
1511 
1512  if ( bank_index < fModuleIndex.size()) {
1513  if ( slot_num < fModuleIndex.at(bank_index).size()){
1514  modindex = fModuleIndex.at(bank_index).at(slot_num);
1515  }
1516  }
1517  return modindex;
1518 }
1519 
1520 
1521 Int_t QwTriggerScintillator::FindSignalIndex(const EQwModuleType modtype, const TString &name) const
1522 {
1523  Int_t chanindex = -1;
1524  if (modtype < (Int_t) fPMTs.size()) {
1525  for (size_t chan = 0; chan < fPMTs.at(modtype).size(); chan++) {
1526  if (name == fPMTs.at(modtype).at(chan).GetElementName()) {
1527  chanindex = chan;
1528  break;
1529  }
1530  }
1531  }
1532  return chanindex;
1533 }
1534 
1535 
1537 {
1538  fF1RefContainer -> PrintCounters();
1539  fF1TDContainer -> PrintErrorSummary();
1540  fF1TDContainer -> WriteErrorSummary();
1541  return;
1542 };
1543 
1544 
1545 
1546 
1547 void
1549 {
1550 
1551  if(verbose) {
1552  std::size_t i = 0;
1553  std::size_t j = 0;
1554 
1555  Int_t roc_num = 0;
1556  Int_t bank_flag = 0;
1557  Int_t bank_index = 0;
1558  Int_t module_index = 0;
1559 
1560  UInt_t slot_id = 0;
1561  UInt_t vme_slot_num = 0;
1562 
1563  std::cout << "QwTriggerScintillator Region : "
1564  << this->GetSubsystemName()
1565  << "::ReportConfiguration fDetectorIDs.size() "
1566  << fDetectorIDs.size() << std::endl;
1567 
1568 
1569  for ( i=0; i<fROC_IDs.size(); i++ )
1570  {
1571 
1572  roc_num = fROC_IDs.at(i);
1573 
1574  for ( j=0; j<fBank_IDs.at(i).size(); j++ )
1575  {
1576  bank_flag = fBank_IDs.at(i).at(j);
1577  if(bank_flag == 0) continue;
1578  // must be uncommented if one doesn't define "bank_flag" in a CRL file
1579  // but, now we use "bank_flag" in our crl files, thus skip to print
1580  // unnecessary things on a screen
1581  // Monday, August 30 14:45:34 EDT 2010, jhlee
1582 
1583  bank_index = GetSubbankIndex(roc_num, bank_flag);
1584 
1585  std::cout << "ROC [index, Num]["
1586  << i
1587  << ","
1588  << std::setw(2) << roc_num
1589  << "]"
1590  << " Bank [index,id]["
1591  << bank_index
1592  << ","
1593  << bank_flag
1594  << "]"
1595  << std::endl;
1596 
1597  for ( slot_id=2; slot_id<kMaxNumberOfModulesPerROC; slot_id++ )
1598  {
1599  // slot id starts from 2, because 0 and 1 are used for CPU and TI.
1600  // Tuesday, August 31 10:57:07 EDT 2010, jhlee
1601 
1602  module_index = GetModuleIndex(bank_index, slot_id);
1603 
1604  vme_slot_num = slot_id;
1605 
1606  std::cout << " "
1607  << "Slot [id, VME num] ["
1608  << std::setw(2) << slot_id
1609  << ","
1610  << std::setw(2) << vme_slot_num
1611  << "]";
1612  if ( module_index == -1 ) {
1613  std::cout << " "
1614  << "Unused in "
1615  << GetSubsystemName()
1616  << std::endl;
1617  }
1618  else {
1619  std::cout << " "
1620  << "Module index "
1621  << module_index << std::endl;
1622  }
1623  }
1624  }
1625  }
1626 
1627  for( size_t midx = 0; midx < fDetectorIDs.size(); midx++ )
1628  {
1629  for (size_t chan = 0 ; chan< fDetectorIDs.at(midx).size(); chan++)
1630  {
1631  std::cout << "[" << midx <<","<< chan << "] "
1632  << " detectorID " << fDetectorIDs.at(midx).at(chan)
1633  << std::endl;
1634  }
1635  }
1636  }
1637  return;
1638 }
1639 
1640 
1641 
EQwModuleType RegisterModuleType(TString moduletype)
Int_t GetSubbankIndex() const
Definition: VQwSubsystem.h:303
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
void FillTreeVector(std::vector< Double_t > &values) const
Fill the tree vector.
void AddQwF1TDC(QwF1TDC *in)
std::map< TString, TString > fDetectorMaps
Definition: VQwSubsystem.h:322
F1TDCs configuration and reference siganls container.
virtual ~QwTriggerScintillator()
Virtual destructor.
UInt_t GetTDCChannelNumber()
Definition: MQwV775TDC.h:43
Int_t FindSignalIndex(const EQwModuleType modtype, const TString &name) const
Int_t RegisterSubbank(const UInt_t bank_id)
#define default_bool_value(b)
Definition: QwOptions.h:51
void SetF1TDCBuffer(UInt_t *buffer, UInt_t num_words)
UInt_t GetTDCData()
Definition: MQwV775TDC.h:44
const UInt_t & GetTDCMaxChannels() const
Definition: MQwF1TDC.h:50
An options class.
Definition: QwOptions.h:133
std::vector< std::vector< QwPMT_Channel > > fPMTs
std::vector< std::pair< Int_t, Int_t > > fReferenceChannels
static UInt_t GetUInt(const TString &varvalue)
F1TDCReferenceContainer * fF1RefContainer
void ProcessOptions(QwOptions &options)
Process the command line options.
std::vector< EQwModuleType > fModuleTypes
const UInt_t & GetTDCData() const
Definition: MQwF1TDC.h:49
void ReportConfiguration(Bool_t verbose)
Int_t SoftwareMTSize() const
Bool_t HasDataLoaded() const
Definition: VQwSubsystem.h:94
one F1TDC configuration and reference signal(s) holder
QwTriggerScintillator & operator=(const QwTriggerScintillator &value)
static const double e
Definition: QwUnits.h:91
std::vector< std::vector< QwDetectorID > > fDetectorIDs
Int_t fCurrentBankIndex
Name of this subsystem (the region).
Int_t GetModuleIndex(size_t bank_index, size_t slot_num) const
Bool_t CheckDataIntegrity(const UInt_t roc_id, UInt_t *buffer, UInt_t num_words)
Int_t RegisterROCNumber(const UInt_t roc_id)
EQwDetectorPackage
Definition: QwTypes.h:70
Software Meantime container.
std::vector< std::vector< Double_t > > fReferenceData
static const UInt_t kMaxNumberOfModulesPerROC
void SetSystemName(const TString name)
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Definition: VQwSubsystem.h:209
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
const UInt_t & GetTDCSlotNumber() const
Definition: MQwF1TDC.h:44
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...
T GetValue(const std::string &key)
Get a templated value.
Definition: QwOptions.h:240
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
std::map< TString, size_t > fSCAs_map
const UInt_t & GetTDCChannelNumber() const
Definition: MQwF1TDC.h:45
EQwRegionID
Definition: QwTypes.h:16
std::vector< Int_t > fSCAs_offset
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
Definition: VQwSubsystem.h:88
Int_t GetPlane() const
void DecodeTDCWord(UInt_t &word, const UInt_t roc_id=0)
Definition: MQwV775TDC.cc:53
void SetEventTypeMask(const UInt_t mask)
Set event type mask.
Definition: VQwSubsystem.h:166
size_t fTreeArrayIndex
Tree indices.
one software meantim holder
Double_t ReferenceSignalCorrection(Double_t raw_time, Double_t ref_time, Int_t bank_index, Int_t slot)
MeanTime * GetMeanTimeObject(Int_t index)
void FillRawTDCWord(Int_t bank_index, Int_t slot_num, Int_t chan, UInt_t data)
UInt_t GetTDCSlotNumber()
Definition: MQwV775TDC.h:42
void SetReferenceSignal(Int_t bank_index, Int_t slot, Int_t chan, UInt_t data, Bool_t debug=false)
Double_t DoneF1TDCsConfiguration()
Bool_t WireMatches(EQwRegionID region, EQwDetectorPackage package, Int_t plane, Int_t wire)
Definition: QwHit.cc:357
Int_t RegisterSlotNumber(const UInt_t slot_id)
void SetTimens(const Double_t timens)
Definition: QwHit.h:123
Bool_t IsValidDataword() const
Definition: MQwF1TDC.cc:328
The pure virtual base class of all subsystems.
Definition: VQwSubsystem.h:59
EQwModuleType
Definition: QwTypes.h:148
std::vector< QwSIS3801D24_Channel > fSCAs
UInt_t GetCodaEventNumber() const
Get the internal record of the CODA event number.
void SetF1BankIndex(const Int_t bank_index)
void AddSoftwareMeantimeToHits(Bool_t option)
const MQwF1TDC GetF1TDCDecoder() const
class QwScaler_Channel< 0x00ffffff, 0 > QwSIS3801D24_Channel
void SetF1SystemName(const TString name)
std::vector< std::vector< UInt_t > > fBank_IDs
Vector of Bank IDs per ROC ID associated with this subsystem.
Definition: VQwSubsystem.h:331
Int_t fCurrentROC_ID
ROC ID that is currently being processed.
Definition: VQwSubsystem.h:325
void FillHardwareErrorSummary()
Hardware error summary.
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...
std::vector< QwHit > fTDCHits
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.
Int_t LinkChannelToSignal(const UInt_t chan, const TString &name)
static const Int_t kMaxNumberOfQwHitPlane
void SetPlane(const Int_t in)
Bool_t IsF1ReferenceChannel(Int_t slot, Int_t chan)
std::vector< UInt_t > fROC_IDs
Vector of ROC IDs associated with this subsystem.
Definition: VQwSubsystem.h:329
void SetF1TDCIndex(const Int_t tdc_index)
EQwDirectionID
Definition: QwTypes.h:41
QwTriggerScintillator()
Private default constructor (not implemented, will throw linker error on use)
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Construct the branch and tree vector.
Int_t LoadChannelMap(TString mapfile)
Mandatory map file definition.
QwF1TDContainer * fF1TDContainer
std::vector< std::vector< Int_t > > fModuleIndex
QwSubsystemArray * GetParent(const unsigned int parent=0) const
Get the parent of this subsystem.
Hit structure uniquely defining each hit.
Definition: QwHit.h:43
std::vector< std::vector< std::pair< EQwModuleType, Int_t > > > fModulePtrs
static const Int_t kF1ReferenceChannelNumber
MeanTimeContainer * fSoftwareMeantimeContainer[2]
Double_t ReturnTimeCalibration(Double_t time_arb_unit)
void Print(const Option_t *options=0) const
void FillHistograms()
Fill the histograms for this subsystem.
void DecodeTDCWord(UInt_t &word, const UInt_t roc_id)
Definition: MQwF1TDC.cc:84
void ClearAllBankRegistrations()
Clear all registration of ROC and Bank IDs for this subsystem.
Bool_t IsValidDataword()
Definition: MQwV775TDC.h:39
Bool_t IsSlotRegistered(Int_t bank_index, Int_t slot_num) const
#define RegisterSubsystemFactory(A)
Definition: QwFactory.h:230
void FillRawWord(Int_t bank_index, Int_t slot_num, Int_t chan, UInt_t data)
TString GetSubsystemName() const
Definition: VQwSubsystem.h:93
Int_t GetPlane() const
void SetDataLoaded(Bool_t flag)
Definition: VQwSubsystem.h:305