QwAnalysis
QwScanner.cc
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwScanner.cc *
3 * *
4 * Author: J. Pan *
5 * jpan@jlab.org *
6 * *
7 * Thu May 21 21:48:20 CDT 2009 *
8 \**********************************************************/
9 
10 #include "QwScanner.h"
11 
12 // Qweak headers
13 #include "QwParameterFile.h"
14 #include "QwHistogramHelper.h"
15 //#include "TString.h"
16 #include "boost/bind.hpp"
17 
18 
19 // Register this subsystem with the factory
21 
22 const Bool_t QwScanner::bStoreRawData = kTRUE;
23 const UInt_t QwScanner::kMaxNumberOfModulesPerROC = 21;
25 
26 //const UInt_t QwScanner::kMaxNumberOfChannelsPerModule = 32;
27 
28 QwScanner::QwScanner(const TString& name)
29 : VQwSubsystem(name),
30  VQwSubsystemParity(name),
32 { fDEBUG = 0;
33  fEventTypeMask = 0xffff; // explicit because of diamond inheritance
35 
36  fRegion = "";
38  fCurrentSlot = 0;
40 
41  fNumberOfModules = 0;
42 
43  fScaEventCounter = 0;
47 }
48 
50 : VQwSubsystem(source),VQwSubsystemParity(source),VQwSubsystemTracking(source),
51  fPMTs(source.fPMTs),fSCAs(source.fSCAs),fADCs(source.fADCs)
52 {
54 
61 
66 
67  fRateMapCM = source.fRateMapCM;
68  fRateMapEM = source.fRateMapEM;
69 }
70 
72 {
73  fPMTs.clear();
74  fSCAs.clear();
75  fADCs.clear();
76 
77  delete fF1TDContainer;
78 }
79 
81 {
82  //Handle command line options
83 }
84 
85 Int_t QwScanner::LoadChannelMap(TString mapfile)
86 {
87  Bool_t local_debug = false;
88 
89  TString varname = "";
90  TString varvalue = "";
91  UInt_t value = 0;
92 
93  TString modtype = "";
94  TString dettype = "";
95  TString name = "";
96 
97  Int_t modnum = 0;
98  Int_t channum = 0;
99  Int_t slotnum = 0;
100 
101  Int_t ts_chan_num_to_plane = 0;
102  Int_t ts_chan_type_to_element = 0;
103 
104  Int_t reference_counter = 0;
105 
106  EQwDetectorPackage package = kPackageNull;
107  EQwDirectionID direction = kDirectionNull;
108 
109 
110  // plane = 0
111  //
112  // element
113  // front_f1 -> 1
114  // back__f1 -> 2
115  // coinc_f1 -> 0
116  //
117 
118  QwParameterFile mapstr(mapfile.Data()); //Open the file
119  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
120 
121  while (mapstr.ReadNextLine())
122  {
123  mapstr.TrimComment('!'); // Remove everything after a '!' character.
124  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
125  if (mapstr.LineIsEmpty()) continue;
126 
127  if (mapstr.HasVariablePair("=",varname,varvalue))
128  {
129  // This is a declaration line. Decode it.
130  varname.ToLower();
131  //UInt_t value = atol(varvalue.Data());
132  value = QwParameterFile::GetUInt(varvalue);
133  if (varname=="roc")
134  {
135  RegisterROCNumber(value);
136  }
137  else if (varname=="qdc_bank")
138  {
139  RegisterSubbank(value);
140  fBankID[0] = value;
141  }
142  else if (varname=="sca_bank")
143  {
144  fBankID[1] = value;
145  RegisterSubbank(value);
146  }
147  else if (varname=="f1tdc_bank")
148  {
149  RegisterSubbank(value);
150  fBankID[2] = value;
151  }
152  else if (varname=="vqwk_bank")
153  {
154  RegisterSubbank(value);
155  fBankID[3] = value;
156  }
157  else if (varname=="slot")
158  {
159  RegisterSlotNumber(value);
160  slotnum=value;
161  }
162  }
163  else
164  {
165  // Break this line into tokens to process it.
166  modtype = mapstr.GetTypedNextToken<TString>();
167  modnum = mapstr.GetTypedNextToken<Int_t>();
168  channum = mapstr.GetTypedNextToken<Int_t>();
169  dettype = mapstr.GetTypedNextToken<TString>();
170  name = mapstr.GetTypedNextToken<TString>();
171 
172  if (local_debug) printf("%8s, %d, %d %s, %s\n", modtype.Data(), modnum, channum, dettype.Data(), name.Data());
173 
174  // Push a new record into the element array
175  if (modtype=="VQWK")
176  {
177  QwVQWK_Channel localchannel(name);
178  fADCs.push_back(localchannel);
179  fADCs_map[name] = fADCs.size()-1;
180  Int_t offset = QwVQWK_Channel::GetBufferOffset(modnum,channum);
181  fADCs_offset.push_back(offset);
182  }
183 
184  else if (modtype=="SIS3801")
185  {
186  QwSIS3801D24_Channel localchannel(name);
187  localchannel.SetNeedsExternalClock(kFALSE);
188  fSCAs.push_back(localchannel);
189  fSCAs_map[name] = fSCAs.size()-1;
190  Int_t offset = QwSIS3801D24_Channel::GetBufferOffset(modnum,channum);
191  fSCAs_offset.push_back(offset);
192 
193  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fRegion = kRegionIDScanner;
194  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPackage = package;
195  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPlane = -1;
196  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fDirection = direction;
197  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = -1;
198  }
199 
200  else if (modtype=="V792" )// || modtype=="V775" || modtype=="F1TDC")
201  {
202  RegisterModuleType(modtype);
203  // Check to see if we've encountered this channel or name yet
204  if (fModulePtrs.at(fCurrentModuleIndex).at(channum).first != kUnknownModuleType)
205  {
206  // We've seen this channel
207  }
208  else if (FindSignalIndex(fCurrentType, name) >= 0)
209  {
210  // We've seen this signal
211  }
212  else
213  {
214  // if(local_debug) {
215  // // If not, push a new record into the element array
216  // if (modtype=="V792") std::cout<<"V792: ";
217  // else if (modtype=="V775") std::cout<<"V775: ";
218  // else if (modtype=="F1TDC") std::cout<<"F1TDC: ";
219  // }
220  LinkChannelToSignal(channum, name);
221  }
222  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fRegion = kRegionIDScanner;
223  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPackage = package;
224  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPlane = -1;
225  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fDirection = direction;
226  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = -1;
227  }
228  else if( modtype=="F1TDC") {
229 
230  RegisterModuleType(modtype);
231  // Check to see if we've encountered this channel or name yet
232  if (fModulePtrs.at(fCurrentModuleIndex).at(channum).first != kUnknownModuleType) {
233  // We've seen this channel
234  } else if (FindSignalIndex(fCurrentType, name)>=0) {
235  // We've seen this signal
236  } else {
237  // If not, push a new record into the element array
238  LinkChannelToSignal(channum, name);
239  }
240 
241 
242  if (name=="ref_t_f1") {
243 
244  fRefTime_SlotNum = slotnum;
245  fRefTime_ChanNum = channum;
246  reference_counter++;
247  // printf("bank index %d Chan %d reference_counter %d\n", fCurrentBankIndex, channum, reference_counter);
249  fReferenceChannels.at ( fCurrentBankIndex ).second = channum;
250 
251  package = kPackageNull;
252 
253  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = fCurrentBankIndex;
255 
256  }
257  else {
258  ts_chan_num_to_plane = 0;
259 
260  if (name=="front_f1") {
261  ts_chan_type_to_element = 1;
262  }
263  else if (name=="back__f1") {
264  ts_chan_type_to_element = 2;
265  }
266  else if (name=="coinc_f1") {
267  ts_chan_type_to_element = 0;
268  }
269  else {
270  ts_chan_type_to_element = -1;
271  }
272 
273  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fElement = ts_chan_type_to_element;
274  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPlane = ts_chan_num_to_plane;
275 
276  }
277 
278  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fRegion = kRegionIDScanner;
279  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fPackage = package;
280  fDetectorIDs.at(fCurrentModuleIndex).at(channum).fDirection = direction;
281  }
282 
283  else
284  {
285  if(local_debug) {
286  std::cerr << "LoadChannelMap: Unknown line: " << mapstr.GetLine().c_str()
287  << std::endl;
288  }
289  }
290  }
291  }
292 
293 
294  mapstr.Close(); // Close the file (ifstream)
295 
296  if(local_debug) {
297 
298 
299  Int_t unused_size_counter = 0;
300  std::size_t i = 0;
301 
302  for( i = 0; i < fModuleIndex.size(); i++)
303  {
304  for(size_t slot_size =0; slot_size < fModuleIndex.at(i).size(); slot_size++)
305  {
306  Int_t m_idx = 0;
307  m_idx = fModuleIndex.at(i).at(slot_size);
308  if(m_idx != -1 ) {
309  std::cout << "[" << i <<","<< slot_size << "] "
310  << " module index " << m_idx
311  << std::endl;
312  }
313  else {
314  unused_size_counter++;
315  }
316  }
317  }
318  // why the bank index is always odd number?
319  //
320 
321  printf("Total unused size of fModuleIndex vector %6d\n", unused_size_counter);
322 
323  for(i = 0; i < fReferenceChannels.size(); i++)
324  {
325  std::cout << "[" << i <<"] "
326  << " fRerenceChannel " << fReferenceChannels.at(i).first
327  << " " << fReferenceChannels.at(i).second
328  << std::endl;
329  }
330 
331  printf("\n------------- QwScanner LoadChannelMap End%s\n\n", mapfile.Data());
332 
333  }
334 
335 
336  if(local_debug) ReportConfiguration(local_debug);
337  return 0;
338 }
339 
340 Int_t QwScanner::LoadInputParameters(TString parameterfile)
341 {
342  Bool_t ldebug=kFALSE;
343  TString localname;
344 
345  Int_t lineread=0;
346 
347  QwParameterFile mapstr(parameterfile.Data()); //Open the file
348  fDetectorMaps.insert(mapstr.GetParamFileNameContents());
349 
350  while (mapstr.ReadNextLine())
351  {
352  lineread+=1;
353  mapstr.TrimComment('!'); // Remove everything after a '!' character.
354  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
355  if (mapstr.LineIsEmpty()) continue;
356 
357  TString varname, varvalue;
358  if (mapstr.HasVariablePair("=",varname,varvalue))
359  {
360  varname.ToLower();
361  Double_t value = atof(varvalue.Data());
362  if (varname=="helicityfrequency")
363  {
364  fHelicityFrequency = value;
365  }
366  else if (varname=="homepositionx")
367  {
368  fHomePositionX = value;
369  }
370  else if (varname=="homepositiony")
371  {
372  fHomePositionY = value;
373  }
374  else if (varname=="cal_factor_vqwk_x")
375  {
376  fCal_Factor_VQWK_X = value;
377  }
378  else if (varname=="cal_factor_vqwk_y")
379  {
380  fCal_Factor_VQWK_Y = value;
381  }
382  else if (varname=="cal_factor_qdc_x")
383  {
384  fCal_Factor_QDC_X = value;
385  }
386  else if (varname=="cal_factor_qdc_y")
387  {
388  fCal_Factor_QDC_Y = value;
389  }
390  else if (varname=="voltage_offset_x")
391  {
392  fVoltage_Offset_X = value;
393  }
394  else if (varname=="voltage_offset_y")
395  {
396  fVoltage_Offset_Y = value;
397  }
398  else if (varname=="channel_offset_x")
399  {
400  fChannel_Offset_X = value;
401  }
402  else if (varname=="channel_offset_y")
403  {
404  fChannel_Offset_Y = value;
405  }
406  if (ldebug) std::cout<<"inputs for "<<varname<<": "<<value<<"\n";
407  }
408 
409  else
410  {
411  varname = mapstr.GetTypedNextToken<TString>(); //name of the channel
412  varname.ToLower();
413  varname.Remove(TString::kBoth,' ');
414  Double_t varped = mapstr.GetTypedNextToken<Double_t>(); // value of the pedestal
415  Double_t varcal = mapstr.GetTypedNextToken<Double_t>(); // value of the calibration factor
416  if (ldebug)
417  std::cout<<"inputs for channel "<<varname
418  <<": ped="<<varped<<", cal="<<varcal<<"\n";
419  }
420  }
421  if (ldebug) std::cout<<" line read in the parameter file ="<<lineread<<" \n";
422 
423  ldebug=kFALSE;
424  mapstr.Close(); // Close the file (ifstream)
425  return 0;
426 }
427 
428 
430 {
431  SetDataLoaded(kFALSE);
432 
433 
434 
435  fTDCHits.clear();
436  std::size_t i = 0;
437 
438  for (i=0; i<fReferenceData.size(); i++) {
439  fReferenceData.at(i).clear();
440  }
441 
442 
443  for (size_t i=0; i<fPMTs.size(); i++)
444  {
445  for (size_t j=0; j<fPMTs.at(i).size(); j++)
446  {
447  fPMTs.at(i).at(j).SetValue(0);
448  }
449  }
450 
451  for (size_t i=0; i<fSCAs.size(); i++)
452  {
453  fSCAs.at(i).ClearEventData();
454  }
455 
456  for (size_t i=0; i<fADCs.size(); i++)
457  {
458  fADCs.at(i).ClearEventData();
459  }
460 
461 }
462 
463 
464 Int_t QwScanner::ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
465 {
466  if( bank_id==fBankID[2] ) {
467 
468  TString subsystem_name;
469 
470  Int_t bank_index = 0;
471  Int_t tdc_index = 0;
472  UInt_t slot_id = 0;
473  UInt_t vme_slot_num = 0;
474 
475  Bool_t local_debug = false;
476 
477  QwF1TDC *local_f1tdc = NULL;
478 
479  bank_index = GetSubbankIndex(roc_id, bank_id);
480 
481  if(bank_index >=0) {
482  if(local_debug) {
483  std::cout << "fF1TDContainer " << fF1TDContainer
484  <<" local_f1tdc " << local_f1tdc << "\n";
485  }
486  subsystem_name = this->GetSubsystemName();
487  fF1TDContainer -> SetSystemName(subsystem_name);
488 
489  if(local_debug) {
490  std::cout << "-----------------------------------------------------" << std::endl;
491 
492  std::cout << "QwScanner : "
493  << subsystem_name
494  << ", "
495  << "ProcessConfigurationBuffer"
496  << std::endl;
497  std::cout << "ROC "
498  << std::setw(2) << roc_id
499  << " Bank [index,id]["
500  << bank_index
501  << ","
502  << bank_id
503  << "]"
504  << std::endl;
505  }
506  for ( slot_id=0; slot_id<kMaxNumberOfModulesPerROC; slot_id++ ) {
507  // slot id starts from 2, because 0 is one offset (1) difference between QwAnalyzer and VME definition,
508  // and 1 and 2 are used for CPU and TI. Tuesday, August 31 10:57:07 EDT 2010, jhlee
509 
510  tdc_index = GetModuleIndex(bank_index, slot_id);
511  vme_slot_num = slot_id;
512 
513  if(local_debug) {
514  std::cout << " "
515  << "Slot [id, VME num] ["
516  << std::setw(2) << slot_id
517  << ","
518  << std::setw(2) << vme_slot_num
519  << "]";
520  std::cout << " ";
521  }
522 
523 
524  local_f1tdc = NULL;
525 
526  if(slot_id > 2) { // save time
527 
528  if (tdc_index not_eq -1) {
529 
530  if(local_f1tdc) delete local_f1tdc; local_f1tdc = 0;
531 
532  local_f1tdc = new QwF1TDC(roc_id, vme_slot_num);
533 
534  local_f1tdc->SetF1BankIndex(bank_index);
535  local_f1tdc->SetF1TDCIndex(tdc_index);
536  local_f1tdc->SetF1TDCBuffer(buffer, num_words);
537  local_f1tdc->SetF1SystemName(subsystem_name);
538 
539  fF1TDContainer->AddQwF1TDC(local_f1tdc);
540 
541  if(local_debug) {
542  std::cout << "F1TDC index "
543  << std::setw(2)
544  << tdc_index
545  << std::setw(16)
546  << " local_f1tdc "
547  << *local_f1tdc
548  << " at "
549  << local_f1tdc;
550  }
551 
552  }
553  else {
554 
555  if(local_debug) {
556  std::cout << "Unused in "
557  << std::setw(4)
558  << subsystem_name
559  << std::setw(16)
560  << " local_f1tdc at "
561  << local_f1tdc;
562  }
563 
564  }
565 
566  }
567  else { // slot_id == only 0, 1, & 2
568 
569  if(local_debug) {
570  if (slot_id == 0) std::cout << " ";
571  else if (slot_id == 1) std::cout << "MVME CPU ";
572  else std::cout << "Trigger Interface"; // slot_id == 2;
573  }
574 
575  }
576 
577  if(local_debug) std::cout << std::endl;
578  }
579 
581 
582  if(local_debug) {
584  std::cout << "-----------------------------------------------------" << std::endl;
585  }
586  }
587  }
588 
589  return 0;
590 }
591 
592 
593 Int_t QwScanner::ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words)
594 {
595 
596  Int_t index = 0;
597 
598  index = GetSubbankIndex(roc_id,bank_id);
599 
600  if (fDEBUG)
601  std::cout << "FocalPlaneScanner::ProcessEvBuffer: "
602  << "Begin processing ROC" << roc_id <<", Bank "<<bank_id
603  <<"(hex: "<<std::hex<<bank_id<<std::dec<<")"
604  << ", num_words "<<num_words<<", index "<<index<<std::endl;
605 
606  // This is a VQWK bank
607  if (bank_id==fBankID[3]) {
608 
609  if (index>=0 && num_words>0) {
610  SetDataLoaded(kTRUE);
611 
612  UInt_t words_read = 0;
613  for (size_t i=0; i<fADCs.size(); i++) {
614  words_read += fADCs.at(i).ProcessEvBuffer(&(buffer[fADCs_offset.at(i)]),
615  num_words-fADCs_offset.at(i));
616  }
617  }
618  }
619 
620  // This is a F1TDC bank
621  else if (bank_id==fBankID[2]) {
622 
623  // reset the refrence time
624  fRefTime = 0.0;
625 
626  Bool_t local_debug_f1 = false;
627 
628  Int_t bank_index = 0;
629  UInt_t tdc_data = 0;
630 
631 
632  Int_t dummy_slot_number = 0;
633  Int_t dummy_chan_number = 0;
634 
635  Bool_t data_integrity_flag = false;
636  Bool_t temp_print_flag = false;
637 
638  UInt_t hit_counter = 0;
639 
640  bank_index = GetSubbankIndex(roc_id, bank_id);
641 
642  if (bank_index>=0 && num_words>0) {
643  // We want to process this ROC. Begin looping through the data.
644  SetDataLoaded(kTRUE);
645 
646 
647  // if (local_debug_f1 ) {
648  // std::cout << "\nQwMainDetector::ProcessEvBuffer: "
649  // << "Begin processing ROC"
650  // << std::setw(2)
651  // << roc_id
652  // << " bank id "
653  // << bank_id
654  // << " Subbbank Index "
655  // << bank_index
656  // << " Region "
657  // << GetSubsystemName()
658  // << std::endl;
659  // }
660 
661  //
662  // CheckDataIntegrity() do "counter" whatever errors in each F1TDC
663  // and check whether data is OK or not.
664 
665  data_integrity_flag = fF1TDContainer->CheckDataIntegrity(roc_id, buffer, num_words);
666  // if it is false (TFO, EMM, and SYN), the whole buffer is excluded for
667  // the further process, because of multiblock data transfer.
668 
669  if (data_integrity_flag) {
670 
671  dummy_slot_number = 0;
672  dummy_chan_number = 0;
673  hit_counter = 0;
674  for (UInt_t i=0; i<num_words ; i++) {
675 
676  // Decode this word as a F1TDC word.
677  fF1TDCDecoder.DecodeTDCWord(buffer[i], roc_id); // MQwF1TDC or MQwV775TDC
678 
679  // For MQwF1TDC, roc_id is needed to print out some warning messages.
680 
681  Int_t tdc_slot_number = fF1TDCDecoder.GetTDCSlotNumber();
682  Int_t tdc_chan_number = fF1TDCDecoder.GetTDCChannelNumber();
683  //Int_t tdcindex = GetModuleIndex(bank_index, tdc_slot_number);
684 
685  if ( tdc_slot_number == 31) {
686  // This is a custom word which is not defined in
687  // the F1TDC, so we can use it as a marker for
688  // other data; it may be useful for something.
689  }
690 
691  // Each subsystem has its own interesting slot(s), thus
692  // here, if this slot isn't in its slot(s) (subsystem map file)
693  // we skip this buffer to do the further process
694 
695  if (not IsSlotRegistered(bank_index, tdc_slot_number) ) continue;
696 
697  if(temp_print_flag) std::cout << fF1TDCDecoder << std::endl;
698 
699  if ( fF1TDCDecoder.IsValidDataword() ) {//;;
700  // if decoded F1TDC data has a valid slot, resolution locked, data word, no overflow (0xFFFF), and no fake data
701 
702  try {
703 
704  tdc_data = fF1TDCDecoder.GetTDCData();
705  if (dummy_slot_number == tdc_slot_number && dummy_chan_number == tdc_chan_number) {
706  hit_counter++;
707  }
708  else {
709  hit_counter = 0;
710  }
711 
712  if(local_debug_f1) {
713  printf("QwScanner::ProcessEvBuffer: [%4d] hit counter %d, bank_index %2d slot_number [%2d,%2d] chan [%2d,%2d] data %10d %10.2f\n", i, hit_counter,
714  bank_index, tdc_slot_number, fRefTime_SlotNum, tdc_chan_number, fRefTime_ChanNum,tdc_data, fRefTime);
715  }
716 
717  if (hit_counter == 0) {
718  FillRawWord (bank_index, tdc_slot_number, tdc_chan_number, tdc_data);
719  if ( IsF1ReferenceChannel(tdc_slot_number,tdc_chan_number) ) {
720  fRefTime = (Double_t) tdc_data;
721  }
722  }
723 
724  FillRawTDCWord(bank_index, tdc_slot_number, tdc_chan_number, tdc_data);
725 
726  dummy_slot_number = tdc_slot_number;
727  dummy_chan_number = tdc_chan_number;
728 
729 
730  }
731  catch (std::exception& e) {
732  std::cerr << "Standard exception from QwScanner::FillRawWord: "
733  << e.what() << std::endl;
734  std::cerr << " Parameters: index==" <<bank_index
735  << "; GetF1SlotNumber()==" <<tdc_slot_number
736  << "; GetF1ChannelNumber()=="<<tdc_chan_number
737  << "; GetF1Data()==" <<tdc_data
738  << std::endl;
739  }
740  }//;;
741  } // for (UInt_t i=0; i<num_words ; i++) {
742  }
743  }
744 
745 
746  // Int_t bank_index = 0;
747  // Int_t tdc_slot_number = 0;
748  // Int_t tdc_chan_number = 0;
749  // UInt_t tdc_data = 0;
750 
751  // Bool_t data_integrity_flag = false;
752  // Bool_t temp_print_flag = false;
753  // // Int_t tmp_last_chan = 65535; // for removing the multiple hits....
754 
755  // bank_index = GetSubbankIndex(roc_id, bank_id);
756 
757  // if (bank_index>=0 && num_words>0) {
758  // // We want to process this ROC. Begin looping through the data.
759  // SetDataLoaded(kTRUE);
760 
761 
762  // if (temp_print_flag ) {
763  // std::cout << "QwScanner::ProcessEvBuffer: "
764  // << "Begin processing ROC"
765  // << std::setw(2)
766  // << roc_id
767  // << " bank id "
768  // << bank_id
769  // << " Subbbank Index "
770  // << bank_index
771  // << " Region "
772  // << GetSubsystemName()
773  // << std::endl;
774  // }
775 
776  // //
777  // // CheckDataIntegrity() do "counter" whatever errors in each F1TDC
778  // // and check whether data is OK or not.
779 
780  // data_integrity_flag = fF1TDContainer->CheckDataIntegrity(roc_id, buffer, num_words);
781  // // if it is false (TFO, EMM, and SYN), the whole buffer is excluded for
782  // // the further process, because of multiblock data transfer.
783 
784  // if (data_integrity_flag) {
785 
786  // for (UInt_t i=0; i<num_words ; i++) {
787 
788  // // Decode this word as a F1TDC word.
789  // fF1TDCDecoder.DecodeTDCWord(buffer[i], roc_id); // MQwF1TDC or MQwV775TDC
790 
791  // // For MQwF1TDC, roc_id is needed to print out some warning messages.
792 
793  // tdc_slot_number = fF1TDCDecoder.GetTDCSlotNumber();
794  // tdc_chan_number = fF1TDCDecoder.GetTDCChannelNumber();
795  // //Int_t tdcindex = GetModuleIndex(bank_index, tdc_slot_number);
796 
797  // if ( tdc_slot_number == 31) {
798  // // This is a custom word which is not defined in
799  // // the F1TDC, so we can use it as a marker for
800  // // other data; it may be useful for something.
801  // }
802 
803  // // Each subsystem has its own interesting slot(s), thus
804  // // here, if this slot isn't in its slot(s) (subsystem map file)
805  // // we skip this buffer to do the further process
806 
807  // if (not IsSlotRegistered(bank_index, tdc_slot_number) ) continue;
808 
809  // if(temp_print_flag) std::cout << fF1TDCDecoder << std::endl;
810 
811  // if ( fF1TDCDecoder.IsValidDataword() ) {//;;
812  // // if decoded F1TDC data has a valid slot, resolution locked, data word, no overflow (0xFFFF), and no fake data
813 
814  // try {
815  // // if(tdc_chan_number != tmp_last_chan)
816  // // {
817  // tdc_data = fF1TDCDecoder.GetTDCData();
818  // FillRawWord(bank_index, tdc_slot_number, tdc_chan_number, tdc_data);
819  // // // Check if this is reference time data
820  // // if (tdc_slot_number == reftime_slotnum && tdc_chan_number == reftime_channum)
821  // // reftime = fF1TDCDecoder.GetTDCData();
822  // // tmp_last_chan = tdc_chan_number;
823  // // }
824  // }
825  // catch (std::exception& e) {
826  // std::cerr << "Standard exception from QwScanner::FillRawWord: "
827  // << e.what() << std::endl;
828  // std::cerr << " Parameters: index==" <<bank_index
829  // << "; GetF1SlotNumber()==" <<tdc_slot_number
830  // << "; GetF1ChannelNumber()=="<<tdc_chan_number
831  // << "; GetF1Data()==" <<tdc_data
832  // << std::endl;
833  // }
834  // }//;;
835  // } // for (UInt_t i=0; i<num_words ; i++) {
836  // }
837 
838  // }
839 
840 
841  }
842 
843  // This is a SCA bank
844  else if (bank_id==fBankID[1]) {
845 
846  // Check if scaler buffer contains more than one event
847  if (buffer[0]/32!=1) return 0;
848 
849  if (index>=0 && num_words>0) {
850  SetDataLoaded(kTRUE);
852  // This is a SCA bank We want to process this ROC. Begin looping through the data.
853 
854  UInt_t words_read = 0;
855  for (size_t i=0; i<fSCAs.size(); i++) {
856  words_read += fSCAs.at(i).ProcessEvBuffer(&(buffer[fSCAs_offset.at(i)]),
857  num_words-fSCAs_offset.at(i));
858  }
859  }
860  }
861  else if (bank_id==fBankID[0])
862  {
863  if (index>=0 && num_words>0)
864  {
865  SetDataLoaded(kTRUE);
866  // We want to process this ROC. Begin looping through the data.
867  if (fDEBUG) std::cout << "FocalPlaneScanner::ProcessEvBuffer: "
868  << "Begin processing ROC" << roc_id <<", Bank "<<bank_id
869  <<"(hex: "<<std::hex<<bank_id<<std::dec<<")"<< std::endl;
870 
871 
872  if (fDEBUG)
873  std::cout<<"QwScanner::ProcessEvBuffer (trig) Data: \n";
874 
875  for (size_t i=0; i<num_words ; i++)
876  {
877  // Decode this word as a V775TDC word.
878  fQDCTDC.DecodeTDCWord(buffer[i]);
879 
880  if (! IsSlotRegistered(index, fQDCTDC.GetTDCSlotNumber())) continue;
881 
882  if (fQDCTDC.IsValidDataword())
883  {
884  // This is a V775 TDC data word
885  if (fDEBUG)
886  {
887  std::cout<<"This is a valid QDC/TDC data word. Index="<<index
888  <<" slot="<<fQDCTDC.GetTDCSlotNumber()<<" Ch="<<fQDCTDC.GetTDCChannelNumber()
889  <<" Data="<<fQDCTDC.GetTDCData()<<"\n";
890  }
891 
892  try
893  {
894  // The slot number should be set properly in DAQ
895  // using 0 if it is not set
897  fQDCTDC.GetTDCData());
898  //FillRawWord(index,0,GetTDCChannelNumber(),GetTDCData());
899  }
900  catch (std::exception& e)
901  {
902  std::cerr << "Standard exception from FocalPlaneScanner::FillRawTDCWord: "
903  << e.what() << std::endl;
904  Int_t chan = fQDCTDC.GetTDCChannelNumber();
905  std::cerr << " Parameters: index=="<<index
906  << "; GetV775SlotNumber()=="<<fQDCTDC.GetTDCSlotNumber()
907  << "; GetV775ChannelNumber()=="<<chan
908  << "; GetV775Data()=="<<fQDCTDC.GetTDCData()
909  << std::endl;
910  Int_t modindex = GetModuleIndex(index, fQDCTDC.GetTDCSlotNumber());
911  std::cerr << " GetModuleIndex()=="<<modindex
912  << "; fModulePtrs.at(modindex).size()=="
913  << fModulePtrs.at(modindex).size()
914  << "; fModulePtrs.at(modindex).at(chan).first {module type}=="
915  << fModulePtrs.at(modindex).at(chan).first
916  << "; fModulePtrs.at(modindex).at(chan).second {signal index}=="
917  << fModulePtrs.at(modindex).at(chan).second
918  << std::endl;
919  }
920  }
921  }
922  }
923  }
924 
925  return 0;
926 }
927 
928 
930 {
931  if (! HasDataLoaded()) return;
932  //std::cout<<"Scanner Events will be processed here."<<std::endl;
933 
934  // TString elementname = "";
935  // Double_t rawtime = 0.0;
936  // Double_t reftime = 0.0;
937 
938  // for (size_t i=0; i<fPMTs.size(); i++)
939  // {
940  // for (size_t j=0; j<fPMTs.at(i).size(); j++)
941  // {
942  // fPMTs.at(i).at(j).ProcessEvent();
943  // if (fPMTs.at(i).at(j).GetElementName() == TString("ref_t_f1"))
944  // reftime = fPMTs.at(i).at(j).GetValue();
945  // }
946  // }
947 
948  // Int_t bank_index = 0;
949  // Int_t slot_num = 0;
950  // Double_t newdata = 0.0;
951 
952  // // F1TDC reference time subtraction
953  // for (size_t i=0; i<fPMTs.size(); i++)
954  // {
955  // for (size_t j=0; j<fPMTs.at(i).size(); j++)
956  // {
957  // elementname = fPMTs.at(i).at(j).GetElementName();
958  // if (elementname.EndsWith("f1") && elementname != TString("ref_t_f1"))
959  // {
960  // rawtime = fPMTs.at(i).at(j).GetValue();
961 
962  // // only subtract reftime if channel value is nonzero
963  // if (rawtime!=0)
964  // {
965  // bank_index = fPMTs.at(i).at(j).GetSubbankID();
966  // slot_num = fPMTs.at(i).at(j).GetModule();
967  // newdata = fF1TDContainer->ReferenceSignalCorrection(rawtime, reftime, bank_index, slot_num);
968  // fPMTs.at(i).at(j).SetValue(newdata);
969  // }
970  // }
971  // }
972  // }
973 
974 
975  TString elementname = "";
976 
977  Double_t rawtime_arb_unit = 0.0;
978  Double_t corrected_time_arb_unit = 0.0;
979  Double_t time_ns = 0.0;
980 
981 
982  Int_t bank_index = 0;
983  Int_t slot_num = 0;
984 
985  for (size_t i=0; i<fPMTs.size(); i++)
986  {//;
987  for (size_t j=0; j<fPMTs.at(i).size(); j++)
988  {//;;
989  elementname = fPMTs.at(i).at(j).GetElementName();
990 
991 
992  if (elementname.EndsWith("f1") ) {
993  rawtime_arb_unit = fPMTs.at(i).at(j).GetValue(); // returns Double_t
994 
995  if ( rawtime_arb_unit not_eq 0.0) {
996 
997  if ( not elementname.Contains("ref") ) {
998  // printf("element name %s rawtime a.u. %f \n", elementname.Data(), rawtime_arb_unit);
999  bank_index = fPMTs.at(i).at(j).GetSubbankID();
1000  slot_num = fPMTs.at(i).at(j).GetModule();
1001  corrected_time_arb_unit = fF1TDContainer->ReferenceSignalCorrection(rawtime_arb_unit, fRefTime, bank_index, slot_num);
1002  time_ns = fF1TDContainer->ReturnTimeCalibration(corrected_time_arb_unit);
1003  fPMTs.at(i).at(j).SetValue(time_ns);
1004  // printf("Scanner::ProcessBuffer: bank_index %2d slot_number %2d data %10f %10.2f, %10.2f\n",
1005  /// bank_index, slot_num, rawtime_arb_unit, reftime, corrected_time_arb_unit);
1006  }
1007  else {
1008  // // we save the referennce raw time
1009  fPMTs.at(i).at(j).SetValue(rawtime_arb_unit);
1010  }
1011  }
1012  else {
1013  fPMTs.at(i).at(j).SetValue(rawtime_arb_unit); // zero
1014  }
1015 
1016  }
1017  else {
1018  fPMTs.at(i).at(j).ProcessEvent();
1019  }
1020 
1021 
1022 
1023  // fPMTs.at(i).at(j).ProcessEvent();
1024  // elementname = fPMTs.at(i).at(j).GetElementName();
1025 
1026  // // Check whether the element is "reftime"
1027  // if ( not elementname.Contains("reftime") ) {
1028  // rawtime = fPMTs.at(i).at(j).GetValue();
1029 
1030  // if (elementname.EndsWith("f1") && rawtime!=0.0) {
1031  // bank_index = fPMTs.at(i).at(j).GetSubbankID();
1032  // slot_num = fPMTs.at(i).at(j).GetModule();
1033  // // if the reference time signal is recorded by (a) channel(s) of F1TDC(s),
1034  // // we correct them. And if not, we set them to zero. (jhlee)
1035  // if ( reftime!=0.0 ) {
1036  // corrected_time = fF1TDContainer->ReferenceSignalCorrection(rawtime, reftime, bank_index, slot_num);
1037  // }
1038  // else {
1039  // corrected_time = 0.0;
1040  // }
1041 
1042  // fPMTs.at(i).at(j).SetValue(corrected_time);
1043  // } // if (elementname.EndsWith("f1") && rawtime!=0.0) {
1044  // }
1045  // // if ( not elementname.Contains("reftime") ) {
1046  // //
1047  // // we keep the raw reference time information in an output ROOT file.
1048  // //
1049  }//;;
1050  }//;
1051 
1052  // F1TDCs of QwHit
1054  UpdateHits();
1055 
1056 
1057  for (size_t i=0; i<fADCs.size(); i++)
1058  {
1059  fADCs.at(i).ProcessEvent();
1060  }
1061 
1062  for (size_t i=0; i<fSCAs.size(); i++)
1063  {
1064  fSCAs.at(i).ProcessEvent();
1065  }
1066 
1067  //Fill trigger data
1068  for (size_t i=0; i<fPMTs.size(); i++)
1069  {
1070  for (size_t j=0; j<fPMTs.at(i).size(); j++)
1071  {
1072 
1073  TString element_name = fPMTs.at(i).at(j).GetElementName();
1074  Double_t tmpvalue = fPMTs.at(i).at(j).GetValue();
1075 
1076  if (element_name==TString("front_adc")) {
1077  fFrontADC = tmpvalue;
1078  }
1079  else if (element_name==TString("back__adc")) {
1080  fBackADC = tmpvalue;
1081  }
1082  else if (element_name=="front_f1") {
1083  fFrontTDC = tmpvalue;
1084  // printf("%f\n", fFrontTDC);
1085  }
1086  else if (element_name=="back__f1") {
1087  fBackTDC = tmpvalue;
1088  // printf("%f\n", fBackTDC);
1089  // TODO jpan: replace the position determination with interplation table
1090  }
1091  else if (element_name==TString("pos_x_adc"))
1092  {
1093  if (tmpvalue>0)
1094  {
1095  fPositionX_ADC = tmpvalue;
1097 
1098  if (fScaEventCounter>1)
1099  {
1101  }
1102  else
1103  {
1105  }
1106  }
1107  }
1108  else if (element_name==TString("pos_y_adc"))
1109  {
1110  if (tmpvalue>0)
1111  {
1112  fPositionY_ADC = tmpvalue;
1114 
1115  if (fScaEventCounter>1)
1116  {
1118  }
1119  else
1120  {
1122  }
1123  }
1124  }
1125 
1126  /* std::cout<<"fPositionX_ADC="<<fPositionX_ADC<<", fPositionY_ADC="<<fPositionY_ADC<<"\n";
1127  std::cout<<"fMeanPositionX_ADC="<<fMeanPositionX_ADC
1128  <<",fMeanPositionY_ADC="<<fMeanPositionY_ADC<<"\n";*/
1129  }
1130  }
1131 
1132  // Fill position data
1133  for (size_t i=0; i<fADCs.size(); i++)
1134  {
1135  // TODO replace the position determination with interplation table
1136  const double volts_per_bit = (20./(1<<18));
1137  double num_samples;
1138  fPowSupply_VQWK = fADCs.at(fADCs_map["power_vqwk"]).GetRawValue();
1139  //std::cout<<"fPowSupply_VQWK_HardSum = "<<fPowSupply_VQWK;
1140  num_samples = fADCs.at(fADCs_map["power_vqwk"]).GetNumberOfSamples();
1141  //std::cout<<", num_samples = "<<num_samples;
1142  fPowSupply_VQWK = fPowSupply_VQWK * volts_per_bit / num_samples;
1143  //std::cout<<" fPowSupply_VQWK = "<<fPowSupply_VQWK<<std::endl<<std::endl;
1144 
1145 
1146  fPositionX_VQWK = fADCs.at(fADCs_map["pos_x_vqwk"]).GetRawValue();
1147  //std::cout<<"fPositionX_VQWK_HardSum = "<<fPositionX_VQWK;
1148  num_samples = fADCs.at(fADCs_map["pos_x_vqwk"]).GetNumberOfSamples();
1149  //std::cout<<", num_samples = "<<num_samples;
1150  fPositionX_VQWK = fPositionX_VQWK * volts_per_bit / num_samples;
1151  //std::cout<<" fPositionX = "<<fPositionX_VQWK<<" [V]";
1153  //std::cout<<" fPositionX = "<<fPositionX_VQWK<<std::endl<<std::endl;
1154 
1155  //fPositionY_VQWK = fADC_Data.at(i)->GetChannel(TString("pos_y_vqwk"))->GetAverageVolts();
1156  fPositionY_VQWK = fADCs.at(fADCs_map["pos_y_vqwk"]).GetRawValue();
1157  //std::cout<<"fPositionY_VQWK_HardSum = "<<fPositionY_VQWK;
1158  num_samples = fADCs.at(fADCs_map["pos_y_vqwk"]).GetNumberOfSamples();
1159  //std::cout<<", num_samples = "<<num_samples;
1160  fPositionY_VQWK = fPositionY_VQWK * volts_per_bit / num_samples;
1161  //std::cout<<" fPositionY = "<<fPositionY_VQWK<<" [V]";
1163  //std::cout<<" fPositionY = "<<fPositionY_VQWK<<std::endl<<std::endl;
1164  }
1165 
1166  // Fill scaler data
1167  for (size_t i=0; i<fSCAs.size(); i++)
1168  {
1169  fCoincidenceSCA = fHelicityFrequency*(fSCAs.at(fSCAs_map["coinc_sca"]).GetValue());
1170  fFrontSCA = fHelicityFrequency*(fSCAs.at(fSCAs_map["front_sca"]).GetValue());
1171  fBackSCA = fHelicityFrequency*(fSCAs.at(fSCAs_map["back__sca"]).GetValue());
1172  }
1173 
1174 }
1175 
1176 
1177 void QwScanner::ConstructHistograms(TDirectory *folder, TString &prefix)
1178 {
1179  // TODO (wdc) disabled due to restriction imposed by memory mapped file
1180  // Also changes to ConstructHistograms() calls below.
1181  //TDirectory* scannerfolder = folder->mkdir("scanner");
1182 
1183  if (folder != NULL) folder->cd();
1184 
1185  TString basename = prefix + "scanner_";
1186  if (bStoreRawData)
1187  {
1188  for (size_t i=0; i<fPMTs.size(); i++)
1189  {
1190  for (size_t j=0; j<fPMTs.at(i).size(); j++)
1191  fPMTs.at(i).at(j).ConstructHistograms(folder,basename);
1192  }
1193 
1194  for (size_t i=0; i<fSCAs.size(); i++)
1195  {
1196  fSCAs.at(i).ConstructHistograms(folder,basename);
1197  }
1198 
1199  for (size_t i=0; i<fADCs.size(); i++)
1200  {
1201  fADCs.at(i).ConstructHistograms(folder,basename);
1202  }
1203  }
1204 
1205 
1206  fHistograms.push_back( gQwHists.Construct1DHist(TString("scanner_vqwk_power")));
1207  fHistograms.push_back( gQwHists.Construct1DHist(TString("scanner_position_x")));
1208  fHistograms.push_back( gQwHists.Construct1DHist(TString("scanner_position_y")));
1209  fHistograms.push_back( gQwHists.Construct1DHist(TString("scanner_ref_posi_x")));
1210  fHistograms.push_back( gQwHists.Construct1DHist(TString("scanner_ref_posi_y")));
1211 
1212  //fHistograms.push_back( gQwHists.Construct2DProf(TString("scanner_rate_map_cm")));
1213  //fHistograms.push_back( gQwHists.Construct2DProf(TString("scanner_rate_map_em")));
1214 
1215  fRateMapCM = new TProfile2D("scanner_rate_map_cm",
1216  "Scanner Rate Map (Current Mode)",110,-55.0,55.0,40,-360.0,-320.0);
1217  fRateMapCM->GetXaxis()->SetTitle("PositionX [cm]");
1218  fRateMapCM->GetYaxis()->SetTitle("PositionY [cm]");
1219  fRateMapCM->SetOption("colz");
1220 
1221  fRateMapEM = new TProfile2D("scanner_rate_map_em",
1222  "Scanner Rate Map (Event Mode)",110,-55.0,55.0,40,-360.0,-320.0);
1223  fRateMapEM->GetXaxis()->SetTitle("PositionX [cm]");
1224  fRateMapEM->GetYaxis()->SetTitle("PositionY [cm]");
1225  fRateMapEM->SetOption("colz");
1226 
1227  // fParameterFileNamesHist = new TH1F("scanner_parameter_files", "scanner_parameter_files", 10,0,10);
1228  // fParameterFileNamesHist -> SetBit(TH1::kCanRebin);
1229  // fParameterFileNamesHist -> SetStats(0);
1230  // for (std::size_t i=0; i< fParameterFileNames.size(); i++) {
1231  // fParameterFileNamesHist -> Fill(fParameterFileNames[i].Data(), 1);
1232  // }
1233  // const char* opt = "TEXT";
1234  // fParameterFileNamesHist->SetMarkerSize(1.4);
1235  // fParameterFileNamesHist->SetOption(opt);
1236  // fParameterFileNamesHist->LabelsDeflate("X");
1237  // fParameterFileNamesHist->LabelsOption("avu", "X");
1238 }
1239 
1241 {
1242  if (! HasDataLoaded()) return;
1243 
1244  if (bStoreRawData)
1245  {
1246  // Fill trigger data
1247  for (size_t i=0; i<fPMTs.size(); i++)
1248  {
1249  for (size_t j=0; j<fPMTs.at(i).size(); j++)
1250  {
1251  fPMTs.at(i).at(j).FillHistograms();
1252  }
1253  }
1254 
1255  // Fill scaler data
1256  for (size_t i=0; i<fSCAs.size(); i++)
1257  {
1258  fSCAs.at(i).FillHistograms();
1259  }
1260 
1261  // Fill position data
1262  for (size_t i=0; i<fADCs.size(); i++)
1263  {
1264  fADCs.at(i).FillHistograms();
1265  }
1266 
1267  }
1268 
1269  for (size_t j=0; j<fHistograms.size();j++)
1270  {
1271 
1272  if (fHistograms.at(j)->GetTitle()==TString("scanner_position_x"))
1273  {
1274  fHistograms.at(j)->Fill(fPositionX_VQWK);
1275  }
1276 
1277  if (fHistograms.at(j)->GetTitle()==TString("scanner_position_y"))
1278  {
1279  fHistograms.at(j)->Fill(fPositionY_VQWK);
1280  }
1281 
1282  if (fHistograms.at(j)->GetTitle()==TString("scanner_ref_posi_x"))
1283  {
1284  fHistograms.at(j)->Fill(fPositionX_ADC);
1285  }
1286 
1287  if (fHistograms.at(j)->GetTitle()==TString("scanner_ref_posi_y"))
1288  {
1289  fHistograms.at(j)->Fill(fPositionY_ADC);
1290  }
1291  }
1292 
1293  //Fill rate map
1294 // Double_t rate;
1295 // for (size_t j=0; j<fHistograms.size();j++)
1296 // {
1297 // if (fHistograms.at(j)->GetTitle()==TString("scanner_rate_map"))
1298 // {
1299 // Int_t checkvalidity = 1;
1300 // Double_t prevalue = get_value( fHistograms.at(j), fPositionX_ADC, fPositionY_ADC, checkvalidity);
1301 // if (checkvalidity!=0)
1302 // {
1303 // rate = (prevalue + fCoincidenceSCA)*0.5; //average value for this bin
1304 //
1305 // fHistograms.at(j)->SetBinContent((Int_t) fPositionX_ADC, (Int_t)fPositionY_ADC,rate);
1306 // Int_t xbin = fHistograms.at(j)->GetXaxis()->FindBin( fPositionX_ADC );
1307 // Int_t ybin = fHistograms.at(j)->GetYaxis()->FindBin( fPositionY_ADC );
1308 // fHistograms.at(j)->SetBinContent( fHistograms.at(j)->GetBin( xbin, ybin ), rate);
1309 // }
1310 // }
1311 // }
1312 
1314 
1315  if ( fScaEventCounter>1 && fCoincidenceSCA>0)
1316  {
1317  //std::cout<<"Fill histo: "<<fMeanPositionX_ADC<<", "<<fMeanPositionY_ADC<<", "<<fCoincidenceSCA<<"\n";
1319  }
1320 
1321 
1322 }
1323 
1324 
1325 void QwScanner::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
1326 {
1327  fTreeArrayIndex = values.size();
1328 
1329  values.push_back(0.0);
1330  TString list = prefix + "PowSupply_VQWK/D";
1331  values.push_back(0.0);
1332  list += ":" + prefix + "PositionX_VQWK/D";
1333  values.push_back(0.0);
1334  list += ":" + prefix + "PositionY_VQWK/D";
1335  values.push_back(0.0);
1336  list += ":" + prefix + "FrontSCA/D";
1337  values.push_back(0.0);
1338  list += ":" + prefix + "BackSCA/D";
1339  values.push_back(0.0);
1340  list += ":" + prefix + "CoincidenceSCA/D";
1341  values.push_back(0.0);
1342  list += ":" + prefix + "FrontADC/D";
1343  values.push_back(0.0);
1344  list += ":" + prefix + "BackADC/D";
1345  values.push_back(0.0);
1346  list += ":" + prefix + "FrontTDC/D";
1347  values.push_back(0.0);
1348  list += ":" + prefix + "BackTDC/D";
1349  values.push_back(0.0);
1350  //list += ":" + prefix + "PowSupply_QDC/D";
1351  //values.push_back(0.0);
1352  list += ":" + prefix + "PositionX_QDC/D";
1353  values.push_back(0.0);
1354  list += ":" + prefix + "PositionY_QDC/D";
1355 
1356  if (bStoreRawData) {
1357  for (size_t i=0; i<fPMTs.size(); i++) {
1358  for (size_t j=0; j<fPMTs.at(i).size(); j++) {
1359  if (fPMTs.at(i).at(j).GetElementName() != "") {
1360  values.push_back(0.0);
1361  list += ":" + fPMTs.at(i).at(j).GetElementName() + "_raw/D";
1362  }
1363  }
1364  }
1365 
1366  for (size_t i=0; i<fSCAs.size(); i++) {
1367  if (fSCAs.at(i).GetElementName() != "") {
1368  values.push_back(0.0);
1369  list += ":" + fSCAs.at(i).GetElementName() + "_raw/D";
1370  }
1371  }
1372 
1373  for (size_t i=0; i<fADCs.size(); i++) {
1374  TString channelname = fADCs.at(i).GetElementName();
1375  channelname.ToLower();
1376  if ( (channelname == "")
1377  || (channelname == "empty")
1378  || (channelname == "spare")) {}
1379  else {
1380  values.push_back(0.0);
1381  list += ":" + fADCs.at(i).GetElementName() + "_raw/D";
1382  }
1383  }
1384  }
1385 
1386  fTreeArrayNumEntries = values.size() - fTreeArrayIndex;
1387 
1388  TString basename = "scanner";
1389  if (gQwHists.MatchDeviceParamsFromList(basename.Data()))
1390  tree->Branch(basename, &values[fTreeArrayIndex], list);
1391 }
1392 
1393 
1394 void QwScanner::FillTreeVector(std::vector<Double_t> &values) const
1395 {
1396  if (! HasDataLoaded()) return;
1397 
1398  Int_t index = fTreeArrayIndex;
1399  values[index++] = fPowSupply_VQWK;
1400  values[index++] = fPositionX_VQWK;
1401  values[index++] = fPositionY_VQWK;
1402  values[index++] = fFrontSCA;
1403  values[index++] = fBackSCA;
1404  values[index++] = fCoincidenceSCA;
1405  values[index++] = fFrontADC;
1406  values[index++] = fBackADC;
1407  values[index++] = fFrontTDC;
1408  values[index++] = fBackTDC;
1409 // values[index++] = fPowSupply_ADC;
1410  values[index++] = fPositionX_ADC;
1411  values[index++] = fPositionY_ADC;
1412 
1413  if (bStoreRawData) {
1414 
1415  // Fill trigger values
1416  for (size_t i=0; i<fPMTs.size(); i++) {
1417  for (size_t j=0; j<fPMTs.at(i).size(); j++) {
1418  if (fPMTs.at(i).at(j).GetElementName() != "") {
1419  values[index++] = fPMTs.at(i).at(j).GetValue();
1420  }
1421  }
1422  }
1423 
1424  for (size_t i=0; i<fSCAs.size(); i++) {
1425  if (fSCAs.at(i).GetElementName() != "") {
1426  values[index++] = fSCAs.at(i).GetValue();
1427  }
1428  }
1429 
1430  // Fill sumvalues
1431  for (size_t i=0; i<fADCs.size(); i++) {
1432  TString channelname = fADCs.at(i).GetElementName();
1433  channelname.ToLower();
1434  if ( (channelname =="")
1435  || (channelname.BeginsWith("empty"))
1436  || (channelname.BeginsWith("spare")) ) { }
1437  else {
1438  //values[index++] = fADC_Data.at(i)->fChannels.at(j).GetValue();
1439  values[index++] = fADCs.at(i).GetAverageVolts();
1440  }
1441  }
1442  }
1443 }
1444 
1445 
1447 {
1448  if(verbose) {
1449  std::cout << "Configuration of the focal plane scanner:"<< std::endl;
1450  for (size_t i = 0; i<fROC_IDs.size(); i++)
1451  {
1452  for (size_t j=0; j<fBank_IDs.at(i).size(); j++)
1453  {
1454 
1455  Int_t ind = GetSubbankIndex(fROC_IDs.at(i),fBank_IDs.at(i).at(j));
1456  std::cout << "ROC " << fROC_IDs.at(i)
1457  << ", subbank 0x" << std::hex<<fBank_IDs.at(i).at(j)<<std::dec
1458  << ": subbank index==" << ind << std::endl;
1459 
1460  if (fBank_IDs.at(i).at(j)==fBankID[0])
1461  {
1462  for (size_t k=0; k<kMaxNumberOfModulesPerROC; k++)
1463  {
1464  Int_t QadcTdcindex = GetModuleIndex(ind,k);
1465  if (QadcTdcindex != -1)
1466  {
1467  std::cout << " Slot "<<k<<" Module#"<<QadcTdcindex<< std::endl;
1468  }
1469  }
1470  }
1471  else if (fBank_IDs.at(i).at(j)==fBankID[1])
1472  {
1473  std::cout << " Number of SIS3801 Scaler: " << fSCAs.size() << std::endl;
1474  }
1475  else if (fBank_IDs.at(i).at(j)==fBankID[2])
1476  {
1477  std::cout << " F1TDC added." << std::endl;
1478  }
1479  else if (fBank_IDs.at(i).at(j)==fBankID[3])
1480  {
1481  std::cout << " Number of TRIUMF ADC: " << fADCs.size() << std::endl;
1482  }
1483  }
1484  }
1485  }
1486 
1487 }
1488 
1490 {
1491  if (typeid(*value) != typeid(*this)) {
1492  QwError << "QwScanner::Compare: "
1493  << "value is " << typeid(*value).name() << ", "
1494  << "but this is " << typeid(*this).name() << "!"
1495  << QwLog::endl;
1496  return kFALSE;
1497  } else {
1498  QwScanner* input = dynamic_cast<QwScanner*>(value);
1499  if (input->fSCAs.size() != fSCAs.size() ||
1500  input->fPMTs.size() != fPMTs.size() ||
1501  input->fADCs.size() != fADCs.size()) {
1502  QwError << "QwScanner::Compare: "
1503  << "value is " << input->fSCAs.size() << "," << input->fPMTs.size() << "," << input->fADCs.size() << ", "
1504  << "but this is " << fSCAs.size() << "," << fPMTs.size() << "," << fADCs.size() << "!"
1505  << QwLog::endl;
1506  return kFALSE;
1507  } else {
1508  return kTRUE;
1509  }
1510  }
1511 }
1512 
1513 
1515 {
1516  if (Compare(value)) {
1517  VQwSubsystem::operator=(value);
1518  QwScanner* input = dynamic_cast<QwScanner*>(value);
1519  for (size_t i = 0; i < fPMTs.size(); i++)
1520  for (size_t j = 0; j < fPMTs.at(i).size(); j++)
1521  fPMTs.at(i).at(j) = input->fPMTs.at(i).at(j);
1522  for (size_t i = 0; i < fADCs.size(); i++)
1523  fADCs.at(i) = input->fADCs.at(i);
1524  for (size_t i = 0; i < fSCAs.size(); i++)
1525  fSCAs.at(i) = input->fSCAs.at(i);
1526 
1528 
1532  fFrontSCA = input->fFrontSCA;
1533  fBackSCA = input->fBackSCA;
1535 
1536  fFrontADC = input->fFrontADC;
1537  fFrontTDC = input->fFrontTDC;
1538  fBackADC = input->fBackADC;
1539  fBackTDC = input->fBackTDC;
1540  fPositionX_ADC = input->fPositionX_ADC;
1541  fPositionY_ADC = input->fPositionY_ADC;
1542 
1545 
1546  for (size_t i = 0; i < 4; i++)
1547  fBankID[i] = input->fBankID[i];
1548 
1549  } else {
1550  QwError << "QwScanner::operator=: Problems!!!"
1551  << QwLog::endl;
1552  }
1553  return *this;
1554 }
1555 
1556 
1558 {
1559  if (Compare(value)) {
1560  QwScanner* input = dynamic_cast<QwScanner*>(value);
1561  // operator+= not defined for tracking-type data element QwPMT_Channel
1562  //for (size_t i = 0; i < fPMTs.size(); i++)
1563  // for (size_t j = 0; j < fPMTs.at(i).size(); j++)
1564  // fPMTs.at(i).at(j) += input->fPMTs.at(i).at(j);
1565  for (size_t i = 0; i < fADCs.size(); i++)
1566  fADCs.at(i) += input->fADCs.at(i);
1567  for (size_t i = 0; i < fSCAs.size(); i++)
1568  fSCAs.at(i) += input->fSCAs.at(i);
1569 
1570  fFrontSCA += input->fFrontSCA;
1571  fBackSCA += input->fBackSCA;
1572  fCoincidenceSCA += input->fCoincidenceSCA;
1573 
1574  } else {
1575  QwError << "QwScanner::operator+=: Problems!!!"
1576  << QwLog::endl;
1577  }
1578  return *this;
1579 }
1580 
1581 
1583 {
1584  if (Compare(value)) {
1585  QwScanner* input = dynamic_cast<QwScanner*>(value);
1586  // operator-= not defined for tracking-type data element QwPMT_Channel
1587  //for (size_t i = 0; i < fPMTs.size(); i++)
1588  // for (size_t j = 0; j < fPMTs.at(i).size(); j++)
1589  // fPMTs.at(i).at(j) -= input->fPMTs.at(i).at(j);
1590  for (size_t i = 0; i < fADCs.size(); i++)
1591  fADCs.at(i) -= input->fADCs.at(i);
1592  for (size_t i = 0; i < fSCAs.size(); i++)
1593  fSCAs.at(i) -= input->fSCAs.at(i);
1594 
1595  fFrontSCA -= input->fFrontSCA;
1596  fBackSCA -= input->fBackSCA;
1597  fCoincidenceSCA -= input->fCoincidenceSCA;
1598 
1599  } else {
1600  QwError << "QwScanner::operator-=: Problems!!!"
1601  << QwLog::endl;
1602  }
1603  return *this;
1604 }
1605 
1606 
1608 {
1610  fModuleIndex.clear();
1611  fModulePtrs.clear();
1612  fModuleTypes.clear();
1613 
1614  fDetectorIDs.clear();
1615  fTDCHits.clear();
1616 
1617 
1618  fNumberOfModules = 0;
1619 }
1620 
1621 Int_t QwScanner::RegisterROCNumber(const UInt_t roc_id)
1622 {
1623  Int_t status = 0;
1624  status = VQwSubsystemTracking::RegisterROCNumber(roc_id, 0);
1625  std::vector<Int_t> tmpvec(kMaxNumberOfModulesPerROC,-1);
1626  fModuleIndex.push_back(tmpvec);
1627  return status;
1628 }
1629 
1630 Int_t QwScanner::RegisterSubbank(const UInt_t bank_id)
1631 {
1632  Int_t status = VQwSubsystem::RegisterSubbank(bank_id);
1633  Int_t current_roc_id = VQwSubsystem::fCurrentROC_ID;
1634 
1635  std::size_t reference_size = fReferenceChannels.size();
1636 
1637  fCurrentBankIndex = GetSubbankIndex(current_roc_id, bank_id);
1638 
1639  if ( (Int_t) reference_size <= fCurrentBankIndex) {
1642  }
1643 
1644  std::vector<Int_t> tmpvec(kMaxNumberOfModulesPerROC,-1);
1645  fModuleIndex.push_back(tmpvec);
1646 
1647  std::cout<< "QwScanner::RegisterSubbank()"
1648  <<" ROC " << current_roc_id
1649  <<" Subbank " << bank_id
1650  <<" with BankIndex " << fCurrentBankIndex
1651  << std::endl;
1652  return status;
1653 
1654  // Int_t stat = VQwSubsystem::RegisterSubbank(bank_id);
1655  // fCurrentBankIndex++;
1656  // std::vector<Int_t> tmpvec(kMaxNumberOfModulesPerROC,-1);
1657  // fModuleIndex.push_back(tmpvec);
1658  // //std::cout<<"Register Subbank "<<bank_id<<" with BankIndex "<<fCurrentBankIndex<<std::endl;
1659  // return stat;
1660 }
1661 
1662 
1663 Int_t QwScanner::RegisterSlotNumber(UInt_t slot_id)
1664 {
1665 
1666  std::pair<EQwModuleType, Int_t> tmppair;
1667  tmppair.first = kUnknownModuleType;
1668  tmppair.second = -1;
1669  if (slot_id<kMaxNumberOfModulesPerROC)
1670  {
1671  if (fCurrentBankIndex <= (Int_t) fModuleIndex.size())
1672  {
1673  fModuleTypes.resize(fNumberOfModules+1);
1674  fModulePtrs.resize(fNumberOfModules+1);
1676  tmppair);
1677 
1678  fDetectorIDs.resize(fNumberOfModules+1);
1680  // reassign kNumberOfModules after resize it
1681  fNumberOfModules = (Int_t) fDetectorIDs.size();
1682 
1684  fCurrentSlot = slot_id;
1686  }
1687  }
1688  else
1689  {
1690  std::cerr << "QwScanner::RegisterSlotNumber: Slot number "
1691  << slot_id << " is larger than the number of slots per ROC, "
1692  << kMaxNumberOfModulesPerROC << std::endl;
1693  }
1694  return fCurrentModuleIndex;
1695 }
1696 
1698 {
1699  moduletype.ToUpper();
1700 
1701  // Check to see if we've already registered a type for the current slot,
1702  // if so, throw an error...
1703 
1704  if (moduletype=="V792")
1705  {
1708  if ( (Int_t) fPMTs.size() <= fCurrentType)
1709  {
1710  fPMTs.resize(fCurrentType+1);
1711  }
1712  }
1713 
1714  else if (moduletype=="V775")
1715  {
1718  if ( (Int_t) fPMTs.size() <= fCurrentType)
1719  {
1720  fPMTs.resize(fCurrentType+1);
1721  }
1722  }
1723 
1724  else if (moduletype=="F1TDC")
1725  {
1726  fCurrentType = kF1TDC;
1728  if ( (Int_t) fPMTs.size() <= fCurrentType)
1729  {
1730  fPMTs.resize(fCurrentType+1);
1731  }
1732  }
1733 
1734  else if (moduletype=="SIS3801")
1735  {
1736 
1737  }
1738 
1739  return fCurrentType;
1740 }
1741 
1742 
1743 Int_t QwScanner::LinkChannelToSignal(const UInt_t chan, const TString &name)
1744 {
1745  // Bool_t local_debug = false;
1746  // if (fCurrentType == kV775_TDC || fCurrentType == kV792_ADC || fCurrentType == kF1TDC)
1747  // {
1748  fPMTs.at(fCurrentType).push_back(QwPMT_Channel(name));
1749  fModulePtrs.at(fCurrentModuleIndex).at(chan).first = fCurrentType;
1750  fModulePtrs.at(fCurrentModuleIndex).at(chan).second = fPMTs.at(fCurrentType).size() -1;
1751  // }
1752  // else if (fCurrentType == kSIS3801)
1753  // {
1754  // if(local_debug) std::cout<<"scaler module has not been implemented yet."<<std::endl;
1755  // }
1756  // if (local_debug)
1757  // std::cout<<"Linked channel"<<chan<<" to signal "<<name<<std::endl;
1758  return 0;
1759 }
1760 
1761 void QwScanner::FillRawWord(Int_t bank_index,
1762  Int_t slot_num,
1763  Int_t chan, UInt_t data)
1764 {
1765  Int_t modindex = GetModuleIndex(bank_index,slot_num);
1766 
1767  // std::cout<<"modtype="<< fModulePtrs.at(modindex).at(chan).first
1768  // <<" chanindex="<<fModulePtrs.at(modindex).at(chan).second<<" data="<<data<<"\n";
1769 
1770  if (modindex != -1)
1771  {
1772  EQwModuleType modtype = fModulePtrs.at(modindex).at(chan).first;
1773  Int_t chanindex = fModulePtrs.at(modindex).at(chan).second;
1774 
1775  if (modtype == kUnknownModuleType || chanindex == -1)
1776  {
1777  // This channel is not connected to anything.
1778  // Do nothing.
1779  }
1780  else
1781  {
1782  fPMTs.at(modtype).at(chanindex).SetValue(data);
1783  fPMTs.at(modtype).at(chanindex).SetSubbankID(bank_index);
1784  fPMTs.at(modtype).at(chanindex).SetModule(slot_num);
1785  }
1786  }
1787 }
1788 
1789 
1790 
1791 void QwScanner::FillRawTDCWord (Int_t bank_index,
1792  Int_t slot_num,
1793  Int_t chan,
1794  UInt_t data)
1795 {
1796  Bool_t local_debug = false;
1797  Int_t tdcindex = 0;
1798 
1799  tdcindex = GetModuleIndex(bank_index,slot_num);
1800 
1801 
1802  // I think, it is not necessary, but is just "safe" double check routine.
1803  if (tdcindex not_eq -1) {
1804 
1805  Int_t hitcnt = 0;
1806 
1807  EQwDirectionID direction = kDirectionNull;
1808  TString name = "";
1809 
1810 
1811  Int_t plane = fDetectorIDs.at(tdcindex).at(chan).fPlane;
1812  Int_t element = fDetectorIDs.at(tdcindex).at(chan).fElement;
1813  EQwDetectorPackage package = fDetectorIDs.at(tdcindex).at(chan).fPackage;
1814  Int_t octant = fDetectorIDs.at(tdcindex).at(chan).fOctant;
1815 
1816 
1817  if(local_debug) {
1818  printf("tdcindx %d bank_idx %d, slot %d, plane %d, element %d, package %d\n",
1819  tdcindex,
1820  bank_index, slot_num, (Int_t) plane, (Int_t) element, (Int_t) package);
1821  }
1822 
1823  if (plane == -1 or element == -1){
1824  // This channel is not connected to anything. Do nothing.
1825  }
1826  else if (plane == kF1ReferenceChannelNumber){
1827  fReferenceData.at(element).push_back(data);
1828  // we assign the reference time into fReferenceData according the module index
1829  // See LocalChannelMap
1830  // if(local_debug) {
1831  // std::cout << "At QwMainDetector::FillRawTDCWord "
1832  // << " bank index " << bank_index
1833  // << " slot num " << slot_num
1834  // << " chan num " << chan
1835  // << " hitcnt " << 0
1836  // << " plane " << plane
1837  // << " wire " << element
1838  // << " package " << package
1839  // << " diection " << direction
1840  // << " data " << data
1841  // << " fTDCHits.size() " << 0
1842  // << std::endl;
1843  // }
1844  }
1845  else {
1846  direction = fDetectorIDs.at(tdcindex).at(chan).fDirection;
1847 
1848  hitcnt = std::count_if(fTDCHits.begin(), fTDCHits.end(),
1849  boost::bind(
1850  &QwHit::WireMatches, _1, kRegionIDScanner, boost::ref(package), boost::ref(plane), boost::ref(element)
1851  )
1852  );
1853 
1854  if(local_debug) {
1855  std::cout << "At QwMainDetector::FillRawTDCWord "
1856  << " bank index " << bank_index
1857  << " slot num " << slot_num
1858  << " chan num " << chan
1859  << " hitcnt " << hitcnt
1860  << " plane " << plane
1861  << " wire " << element
1862  << " package " << package
1863  << " diection " << direction
1864  << " data " << data
1865  << " fTDCHits.size() " << fTDCHits.size()
1866  << std::endl;
1867  }
1868 
1869  fTDCHits.push_back(
1870  QwHit(
1871  bank_index,
1872  slot_num,
1873  chan,
1874  hitcnt,
1876  package,
1877  octant,
1878  plane,
1879  direction,
1880  element,
1881  data
1882  )
1883  );
1884 
1885 
1886  }
1887 
1888  // }
1889  } // (tdcindex not_eq -1) {
1890 
1891  return;
1892 }
1893 
1894 
1895 
1897 {
1898 
1899  std::vector<Double_t> reftimes;
1900  std::vector<Bool_t> refchecked;
1901  std::vector<Bool_t> refokay;
1902  Bool_t allrefsokay;
1903 
1904 
1905  std::size_t ref_size = 0;
1906  std::size_t i = 0;
1907  std::size_t j = 0;
1908 
1909  ref_size = fReferenceData.size();
1910 
1911  reftimes.resize ( ref_size );
1912  refchecked.resize( ref_size );
1913  refokay.resize ( ref_size );
1914 
1915  for ( i=0; i<ref_size; i++ ) {
1916  reftimes.at(i) = 0.0;
1917  refchecked.at(i) = kFALSE;
1918  refokay.at(i) = kFALSE;
1919  }
1920 
1921  allrefsokay = kTRUE;
1922 
1923 
1924 
1925  UInt_t bank_index = 0;
1926  Double_t raw_time_arb_unit = 0.0;
1927  Double_t ref_time_arb_unit = 0.0;
1928  Double_t time_arb_unit = 0.0;
1929 
1930  Bool_t local_debug = false;
1931 
1932  for ( std::vector<QwHit>::iterator hit=fTDCHits.begin(); hit!=fTDCHits.end(); hit++ )
1933  {
1934  // Only try to check the reference time for a bank if there is at least one
1935  // non-reference hit in the bank.
1936  bank_index = hit->GetSubbankID();
1937 
1938  // if(local_debug) printf("QwHit :: bank index %d\n", bank_index);
1939 
1940  if ( not refchecked.at(bank_index) ) {
1941 
1942  if ( fReferenceData.at(bank_index).empty() ) {
1943  std::cout << "QwScanner::SubtractReferenceTimes: Subbank ID "
1944  << bank_index << " is missing a reference time." << std::endl;
1945  refokay.at(bank_index) = kFALSE;
1946  allrefsokay = kFALSE;
1947  }
1948  else {
1949  if(fReferenceData.at(bank_index).size() not_eq 1) {
1950  std::cout << "Multiple hits are recorded in the reference channel, we use the first hit signal as the refererence signal." << std::endl;
1951  }
1952  reftimes.at(bank_index) = fReferenceData.at(bank_index).at(0);
1953  refokay.at(bank_index) = kTRUE;
1954  }
1955 
1956  if (refokay.at(bank_index)){
1957  for ( j=0; j<fReferenceData.at(bank_index).size(); j++ )
1958  {
1959  // printf("Reference time %f fReferenceData.at(%d).at(%d) %f\n",
1960  // reftimes.at(bank_index), (Int_t) bank_index, (Int_t) j, fReferenceData.at(bank_index).at(j));
1961  fReferenceData.at(bank_index).at(j) -= reftimes.at(bank_index);
1962  // printf("Reference time %f fReferenceData.at(%d).at(%d) %f\n",
1963  // reftimes.at(bank_index), (Int_t) bank_index, (Int_t) j, fReferenceData.at(bank_index).at(j));
1964  }
1965  }
1966 
1967  refchecked.at(bank_index) = kTRUE;
1968  }
1969 
1970  if ( refokay.at(bank_index) ) {
1971  Int_t slot_num = hit -> GetModule();
1972  raw_time_arb_unit = (Double_t) hit -> GetRawTime();
1973  ref_time_arb_unit = (Double_t) reftimes.at(bank_index);
1974 
1975  time_arb_unit = fF1TDContainer->ReferenceSignalCorrection(raw_time_arb_unit, ref_time_arb_unit, bank_index, slot_num);
1976 
1977  hit -> SetTime(time_arb_unit);
1978  hit -> SetRawRefTime((UInt_t) ref_time_arb_unit);
1979 
1980  if(local_debug) {
1981  QwMessage << this->GetSubsystemName()
1982  << " BankIndex " << std::setw(2) << bank_index
1983  << " Slot " << std::setw(2) << slot_num
1984  << " RawTime : " << std::setw(6) << raw_time_arb_unit
1985  << " RefTime : " << std::setw(6) << ref_time_arb_unit
1986  << " time : " << std::setw(6) << time_arb_unit
1987  << std::endl;
1988 
1989  }
1990  }
1991  }
1992 
1993  // bank_index = 0;
1994 
1995  if ( not allrefsokay ) {
1996  std::vector<QwHit> tmp_hits;
1997  tmp_hits.clear();
1998  for ( std::vector<QwHit>::iterator hit=fTDCHits.begin(); hit!=fTDCHits.end(); hit++ )
1999  {
2000  bank_index = hit->GetSubbankID();
2001  if ( refokay.at(bank_index) ) tmp_hits.push_back(*hit);
2002  }
2003  // std::cout << "FTDC size " << fTDCHits.size() << "tmp hit size " << tmp_hits.size() << std::endl;
2004  fTDCHits.clear();
2005  fTDCHits = tmp_hits;
2006  // std::cout << "FTDC size " << fTDCHits.size() << "tmp hit size " << tmp_hits.size() << std::endl;
2007  }
2008 
2009  return;
2010 }
2011 
2012 
2013 
2014 
2016 {
2017 
2018  // std::vector... is weird
2019  // I use a plane number to assign a f1tdc channel. Channel 99 is the F1TDC reference channel
2020  // , becaue I see plan is 0 in qweak_new.geo file and I think, nowhere plane is used in analyzer
2021  // But, I am wrong. This double std::vector fDetectorInfo uses plane number as second index,
2022  // So I had the notorious following error
2023  // Terminate called after throwing an instance of 'std::out_of_range'
2024  // what(): vector::_M_range_check
2025  // Abort
2026  //
2027  //
2028  // I don't care about QwDetectorInfo for other tracking subsystems except VDC/HDC,
2029  // I disable to fill QwDetectorInfo into QwHit
2030 
2031  // Thursday, January 26 10:30:09 EST 2012, jhlee
2032 
2033 
2034  // EQwDetectorPackage package = kPackageNull;
2035  // // Int_t plane = 0;
2036 
2037  // QwDetectorID local_id;
2038  // QwDetectorInfo *local_info;
2039 
2040  for(std::vector<QwHit>::iterator iter=fTDCHits.begin(); iter!=fTDCHits.end(); ++iter)
2041  {
2042  // local_id = iter->GetDetectorID();
2043  // package = local_id.fPackage;
2044  // // plane = local_id.fPlane;
2045 
2046 
2047  // local_info = fDetectorInfo.in(package).at(0);
2048  // // local_info = fDetectorInfo.in(package).at(plane);
2049 
2050  // iter->SetDetectorInfo(local_info);
2051  iter->ApplyTimeCalibration(fF1TDCResolutionNS); // Fill fTimeRes and fTimeNs in QwHit
2052 
2053  }
2054 
2055  return;
2056 }
2057 
2058 
2059 
2060 
2061 
2062 Int_t QwScanner::GetModuleIndex(size_t bank_index, size_t slot_num) const
2063  {
2064  Int_t modindex = -1;
2065 
2066  if ( bank_index < fModuleIndex.size())
2067  {
2068  if ( slot_num < fModuleIndex.at(bank_index).size())
2069  {
2070  modindex = fModuleIndex.at(bank_index).at(slot_num);
2071  }
2072  }
2073  return modindex;
2074  }
2075 
2076 
2077 Int_t QwScanner::FindSignalIndex(const EQwModuleType modtype, const TString &name) const
2078 {
2079  Int_t chanindex = -1;
2080  if (modtype < (Int_t) fPMTs.size())
2081  {
2082  for (size_t chan = 0; chan < fPMTs.at(modtype).size(); chan++)
2083  {
2084  if (name == fPMTs.at(modtype).at(chan).GetElementName())
2085  {
2086  chanindex = chan;
2087  break;
2088  }
2089  }
2090  }
2091  return chanindex;
2092 }
2093 
2094 
2095 void QwScanner::SetPedestal(Double_t pedestal)
2096 {
2097  for (size_t i=0; i<fADCs.size(); i++)
2098  fADCs.at(i).SetPedestal(pedestal);
2099 }
2100 
2102 {
2103  for (size_t i=0; i<fADCs.size(); i++)
2104  fADCs.at(i).SetCalibrationFactor(calib);
2105 }
2106 
2107 /********************************************************/
2108 void QwScanner::InitializeChannel(TString name, TString datatosave)
2109 {
2110  SetPedestal(0.);
2112 
2113  for (size_t i=0; i<fADCs.size(); i++)
2114  fADCs.at(i).InitializeChannel(name,datatosave);
2115 }
2116 
2117 
2119 {
2120  std::cout << "QwScanner: " << fSystemName << std::endl;
2121 
2122  for (size_t i=0; i<fADCs.size(); i++)
2123  fADCs.at(i).PrintInfo();
2124 
2125  for (size_t i=0; i<fPMTs.size(); i++)
2126  for (size_t j=0; j<fPMTs.at(i).size(); j++)
2127  fPMTs.at(i).at(j).PrintInfo();
2128 }
2129 
2130 // //scanner analysis utilities
2131 // Double_t QwScanner::get_value( TH2* h, Double_t x, Double_t y, Int_t& checkvalidity)
2132 // {
2133 // if (checkvalidity)
2134 // {
2135 // bool x_ok = ( h->GetXaxis()->GetXmin() < x && x < h->GetXaxis()->GetXmax() );
2136 // bool y_ok = ( h->GetYaxis()->GetXmin() < y && y < h->GetYaxis()->GetXmax() );
2137 //
2138 // if (! ( x_ok && y_ok))
2139 // {
2140 // // if (!x_ok){
2141 // // std::cerr << "x value " << x << " out of range ["<< h->GetXaxis()->GetXmin()
2142 // // <<","<< h->GetXaxis()->GetXmax() << "]" << std::endl;
2143 // // }
2144 // // if (!y_ok){
2145 // // std::cerr << "y value " << y << " out of range ["<< h->GetYaxis()->GetXmin()
2146 // // <<","<< h->GetYaxis()->GetXmax() << "]" << std::endl;
2147 // // }
2148 // checkvalidity=0;
2149 // return -1e20;
2150 // }
2151 // }
2152 //
2153 // const int xbin = h->GetXaxis()->FindBin( x );
2154 // const int ybin = h->GetYaxis()->FindBin( y );
2155 //
2156 // return h->GetBinContent( h->GetBin( xbin, ybin ));
2157 // }
2158 
2159 
2160 
2161 
2163 {
2166  return;
2167 };
2168 
2169 
2170 
2171 // void QwScanner::ReportConfiguration(Bool_t verbose)
2172 // {
2173 
2174 // if(verbose) {
2175 // std::size_t i = 0;
2176 // std::size_t j = 0;
2177 
2178 // Int_t roc_num = 0;
2179 // Int_t bank_flag = 0;
2180 // Int_t bank_index = 0;
2181 // Int_t module_index = 0;
2182 
2183 // UInt_t slot_id = 0;
2184 // UInt_t vme_slot_num = 0;
2185 
2186 // std::cout << " QwMainDetector : "
2187 // << this->GetSubsystemName()
2188 // << "::ReportConfiguration fDetectorIDs.size() "
2189 // << fDetectorIDs.size() << std::endl;
2190 
2191 
2192 // for ( i=0; i<fROC_IDs.size(); i++ )
2193 // {
2194 
2195 // roc_num = fROC_IDs.at(i);
2196 
2197 // for ( j=0; j<fBank_IDs.at(i).size(); j++ )
2198 // {
2199 // bank_flag = fBank_IDs.at(i).at(j);
2200 // if(bank_flag == 0) continue;
2201 // // must be uncommented if one doesn't define "bank_flag" in a CRL file
2202 // // but, now we use "bank_flag" in our crl files, thus skip to print
2203 // // unnecessary things on a screen
2204 // // Monday, August 30 14:45:34 EDT 2010, jhlee
2205 
2206 // bank_index = GetSubbankIndex(roc_num, bank_flag);
2207 
2208 // std::cout << "ROC [index, Num]["
2209 // << i
2210 // << ","
2211 // << std::setw(2) << roc_num
2212 // << "]"
2213 // << " Bank [index,id]["
2214 // << bank_index
2215 // << ","
2216 // << bank_flag
2217 // << "]"
2218 // << std::endl;
2219 
2220 // for ( slot_id=2; slot_id<kMaxNumberOfModulesPerROC; slot_id++ )
2221 // {
2222 // // slot id starts from 2, because 0 and 1 are used for CPU and TI.
2223 // // Tuesday, August 31 10:57:07 EDT 2010, jhlee
2224 
2225 // module_index = GetModuleIndex(bank_index, slot_id);
2226 
2227 // vme_slot_num = slot_id;
2228 
2229 // std::cout << " "
2230 // << "Slot [id, VME num] ["
2231 // << std::setw(2) << slot_id
2232 // << ","
2233 // << std::setw(2) << vme_slot_num
2234 // << "]";
2235 // if ( module_index == -1 ) {
2236 // std::cout << " "
2237 // << "Unused in "
2238 // << GetSubsystemName()
2239 // << std::endl;
2240 // }
2241 // else {
2242 // std::cout << " "
2243 // << "Module index "
2244 // << module_index << std::endl;
2245 // }
2246 // }
2247 // }
2248 // }
2249 
2250 // for( size_t midx = 0; midx < fDetectorIDs.size(); midx++ )
2251 // {
2252 // for (size_t chan = 0 ; chan< fDetectorIDs.at(midx).size(); chan++)
2253 // {
2254 // std::cout << "[" << midx <<","<< chan << "] "
2255 // << " detectorID " << fDetectorIDs.at(midx).at(chan)
2256 // << std::endl;
2257 // }
2258 // }
2259 // }
2260 // return;
2261 // }
2262 
2263 
2264 
Int_t fRefTime_ChanNum
Definition: QwScanner.h:209
Int_t GetSubbankIndex() const
Definition: VQwSubsystem.h:303
Int_t RegisterROCNumber(const UInt_t roc_id)
Definition: QwScanner.cc:1621
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
Int_t RegisterSubbank(const UInt_t bank_id)
Definition: QwScanner.cc:1630
void AddQwF1TDC(QwF1TDC *in)
std::map< TString, TString > fDetectorMaps
Definition: VQwSubsystem.h:322
Int_t ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
Definition: QwScanner.cc:593
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Construct the branch and tree vector.
Definition: QwScanner.cc:1325
std::vector< QwHit > fTDCHits
Definition: QwScanner.h:195
Double_t fRefTime
Definition: QwScanner.h:210
Int_t fRefTime_SlotNum
Definition: QwScanner.h:208
F1TDCs configuration and reference siganls container.
Double_t fCal_Factor_VQWK_X
Definition: QwScanner.h:292
UInt_t GetTDCChannelNumber()
Definition: MQwV775TDC.h:43
Bool_t Compare(VQwSubsystem *value)
Definition: QwScanner.cc:1489
void FillHistograms()
Fill the histograms for this subsystem.
Definition: QwScanner.cc:1240
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
Double_t fHelicityFrequency
variables for calibrating and calculating scanner positions
Definition: QwScanner.h:283
void ClearEventData()
Definition: QwScanner.cc:429
void SubtractReferenceTimes()
Definition: QwScanner.cc:1896
Double_t fBackSCA
Definition: QwScanner.h:301
An options class.
Definition: QwOptions.h:133
Int_t RegisterSlotNumber(const UInt_t slot_id)
Definition: QwScanner.cc:1663
static UInt_t GetUInt(const TString &varvalue)
void UpdateHits()
Definition: QwScanner.cc:2015
VQwSubsystem & operator+=(VQwSubsystem *value)
Definition: QwScanner.cc:1557
std::vector< std::vector< std::pair< EQwModuleType, Int_t > > > fModulePtrs
Definition: QwScanner.h:251
TString fRegion
Definition: QwScanner.h:174
Double_t fHomePositionX
Definition: QwScanner.h:285
std::vector< QwVQWK_Channel > fADCs
Definition: QwScanner.h:224
Int_t LinkChannelToSignal(const UInt_t chan, const TString &name)
Definition: QwScanner.cc:1743
std::vector< Int_t > fADCs_offset
Definition: QwScanner.h:226
Int_t fCurrentBankIndex
Name of this subsystem (the region).
Definition: QwScanner.h:175
Double_t fPowSupply_VQWK
Definition: QwScanner.h:297
const UInt_t & GetTDCData() const
Definition: MQwF1TDC.h:49
Int_t LoadInputParameters(TString parameterfile)
Mandatory parameter file definition.
Definition: QwScanner.cc:340
Double_t fCal_Factor_QDC_Y
Definition: QwScanner.h:295
std::vector< TH1_ptr > fHistograms
Histograms associated with this data element.
Definition: MQwHistograms.h:46
Double_t fCoincidenceSCA
Definition: QwScanner.h:302
virtual ~QwScanner()
Virtual destructor.
Definition: QwScanner.cc:71
Bool_t HasDataLoaded() const
Definition: VQwSubsystem.h:94
TProfile2D * fRateMapEM
Definition: QwScanner.h:268
one F1TDC configuration and reference signal(s) holder
static const double e
Definition: QwUnits.h:91
Virtual base class for the parity subsystems.
static const Bool_t bStoreRawData
Definition: QwScanner.h:278
Bool_t CheckDataIntegrity(const UInt_t roc_id, UInt_t *buffer, UInt_t num_words)
std::vector< std::vector< Double_t > > fReferenceData
Definition: QwScanner.h:202
EQwDetectorPackage
Definition: QwTypes.h:70
static const Int_t kF1ReferenceChannelNumber
Definition: QwScanner.h:180
void ReportConfiguration(Bool_t verbose)
Definition: QwScanner.cc:1446
EQwModuleType RegisterModuleType(TString moduletype)
Definition: QwScanner.cc:1697
std::vector< std::pair< Int_t, Int_t > > fReferenceChannels
Definition: QwScanner.h:199
Bool_t IsSlotRegistered(Int_t bank_index, Int_t slot_num) const
Definition: QwScanner.h:241
void FillTreeVector(std::vector< Double_t > &values) const
Fill the tree vector.
Definition: QwScanner.cc:1394
void InitializeChannel(TString name, TString datatosave)
Definition: QwScanner.cc:2108
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Definition: VQwSubsystem.h:209
void SetPedestal(Double_t ped)
Definition: QwScanner.cc:2095
void WriteErrorSummary(Bool_t hist_flag=true)
Double_t fPositionY_VQWK
Definition: QwScanner.h:299
const UInt_t & GetTDCSlotNumber() const
Definition: MQwF1TDC.h:44
UInt_t fEventTypeMask
Mask of event types.
Definition: VQwSubsystem.h:317
MQwF1TDC fF1TDCDecoder
Definition: QwScanner.h:186
void FillRawWord(Int_t bank_index, Int_t slot_num, Int_t chan, UInt_t data)
Definition: QwScanner.cc:1761
Bool_t MatchDeviceParamsFromList(const std::string &devicename)
UInt_t fBankID[4]
Definition: QwScanner.h:314
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
Definition: QwScanner.cc:464
std::vector< Int_t > fSCAs_offset
Definition: QwScanner.h:222
Double_t fBackTDC
Definition: QwScanner.h:306
virtual VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Double_t fPositionY_ADC
Definition: QwScanner.h:309
Double_t fCal_Factor_QDC_X
Definition: QwScanner.h:294
void ProcessEvent()
Definition: QwScanner.cc:929
Double_t fPositionX_VQWK
Definition: QwScanner.h:298
const UInt_t & GetTDCChannelNumber() const
Definition: MQwF1TDC.h:45
void ClearAllBankRegistrations()
Definition: QwScanner.cc:1607
Double_t fVoltage_Offset_X
Definition: QwScanner.h:287
Double_t fMeanPositionY_ADC
Definition: QwScanner.h:312
void ProcessOptions(QwOptions &options)
Process the command line options.
Definition: QwScanner.cc:80
Int_t fNumberOfModules
Definition: QwScanner.h:183
void DecodeTDCWord(UInt_t &word, const UInt_t roc_id=0)
Definition: MQwV775TDC.cc:53
TString fSystemName
Name of this subsystem.
Definition: VQwSubsystem.h:315
size_t fTreeArrayIndex
Tree indices.
std::map< TString, size_t > fADCs_map
Definition: QwScanner.h:225
Double_t fHomePositionY
Definition: QwScanner.h:286
Double_t fFrontSCA
Definition: QwScanner.h:300
Double_t ReferenceSignalCorrection(Double_t raw_time, Double_t ref_time, Int_t bank_index, Int_t slot)
void FillHardwareErrorSummary()
Hardware error summary.
Definition: QwScanner.cc:2162
UInt_t GetTDCSlotNumber()
Definition: MQwV775TDC.h:42
VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Definition: QwScanner.cc:1514
Int_t fCurrentSlot
Definition: QwScanner.h:176
std::vector< std::vector< QwPMT_Channel > > fPMTs
Definition: QwScanner.h:214
Double_t DoneF1TDCsConfiguration()
Double_t fChannel_Offset_X
Definition: QwScanner.h:289
Bool_t WireMatches(EQwRegionID region, EQwDetectorPackage package, Int_t plane, Int_t wire)
Definition: QwHit.cc:357
Int_t GetModuleIndex(size_t bank_index, size_t slot_num) const
Definition: QwScanner.cc:2062
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
Bool_t IsValidDataword() const
Definition: MQwF1TDC.cc:328
Double_t fChannel_Offset_Y
Definition: QwScanner.h:290
The pure virtual base class of all subsystems.
Definition: VQwSubsystem.h:59
EQwModuleType
Definition: QwTypes.h:148
TProfile2D * fRateMapCM
Definition: QwScanner.h:263
UInt_t kMaxNumberOfChannelsPerModule
Definition: QwScanner.h:182
Double_t fFrontTDC
Definition: QwScanner.h:304
Double_t fFrontADC
Definition: QwScanner.h:303
void SetF1BankIndex(const Int_t bank_index)
Double_t fCal_Factor_VQWK_Y
Definition: QwScanner.h:293
EQwModuleType fCurrentType
Definition: QwScanner.h:171
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
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...
Int_t fCurrentModuleIndex
Definition: QwScanner.h:177
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.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void PrintInfo() const
Print some information about the subsystem.
Definition: QwScanner.cc:2118
std::vector< UInt_t > fROC_IDs
Vector of ROC IDs associated with this subsystem.
Definition: VQwSubsystem.h:329
UInt_t fScaEventCounter
Definition: QwScanner.h:280
void SetF1TDCIndex(const Int_t tdc_index)
EQwDirectionID
Definition: QwTypes.h:41
std::vector< std::vector< QwDetectorID > > fDetectorIDs
Definition: QwScanner.h:197
Double_t fBackADC
Definition: QwScanner.h:305
static const UInt_t kMaxNumberOfModulesPerROC
Definition: QwScanner.h:179
Double_t fMeanPositionX_ADC
Definition: QwScanner.h:311
Bool_t IsF1ReferenceChannel(Int_t slot, Int_t chan)
Definition: QwScanner.h:212
Hit structure uniquely defining each hit.
Definition: QwHit.h:43
Int_t LoadChannelMap(TString mapfile)
Mandatory map file definition.
Definition: QwScanner.cc:85
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
Bool_t fDEBUG
Definition: QwScanner.h:172
Double_t fPositionX_ADC
Definition: QwScanner.h:308
Double_t ReturnTimeCalibration(Double_t time_arb_unit)
void Print(const Option_t *options=0) const
std::vector< std::vector< Int_t > > fModuleIndex
Definition: QwScanner.h:249
Int_t FindSignalIndex(const EQwModuleType modtype, const TString &name) const
Definition: QwScanner.cc:2077
std::vector< QwSIS3801D24_Channel > fSCAs
Definition: QwScanner.h:220
QwF1TDContainer * fF1TDContainer
Definition: QwScanner.h:187
VQwSubsystem & operator-=(VQwSubsystem *value)
Definition: QwScanner.cc:1582
Double_t fVoltage_Offset_Y
Definition: QwScanner.h:288
void FillRawTDCWord(Int_t bank_index, Int_t slot_num, Int_t chan, UInt_t data)
Definition: QwScanner.cc:1791
void DecodeTDCWord(UInt_t &word, const UInt_t roc_id)
Definition: MQwF1TDC.cc:84
TH1F * Construct1DHist(const TString &inputfile, const TString &name_title)
void ClearAllBankRegistrations()
Clear all registration of ROC and Bank IDs for this subsystem.
std::map< TString, size_t > fSCAs_map
Definition: QwScanner.h:221
QwScanner()
Private default constructor (not implemented, will throw linker error on use)
Bool_t IsValidDataword()
Definition: MQwV775TDC.h:39
#define RegisterSubsystemFactory(A)
Definition: QwFactory.h:230
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40
TString GetSubsystemName() const
Definition: VQwSubsystem.h:93
std::vector< EQwModuleType > fModuleTypes
Module index, indexed by bank_index and slot_number.
Definition: QwScanner.h:250
MQwV775TDC fQDCTDC
Definition: QwScanner.h:185
void SetDataLoaded(Bool_t flag)
Definition: VQwSubsystem.h:305
void SetCalibrationFactor(Double_t calib)
Definition: QwScanner.cc:2101