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