StandardRawDigitExtractService_service.cc
Go to the documentation of this file.
1 // StandardRawDigitExtractService_service.cc
2 
4 #include <iostream>
12 
13 using std::string;
14 using std::cout;
15 using std::endl;
16 
17 //**********************************************************************
18 
21 : m_LogLevel(1),
22  m_pDigitReadTool(nullptr),
23  m_pROIBuilderTool(nullptr),
24  m_pPedProv(nullptr) {
25  const string myname = "StandardRawDigitExtractService::ctor: ";
26  pset.get_if_present<int>("LogLevel", m_LogLevel);
27  pset.get_if_present<string>("ROIBuilderTool", m_ROIBuilderTool);
28  m_DigitReadTool = pset.get<string>("DigitReadTool");
29  m_PedestalOption = pset.get<int>("PedestalOption");
30  m_FlagStuckOff = pset.get<bool>("FlagStuckOff");
31  m_FlagStuckOn = pset.get<bool>("FlagStuckOn");
32  // Retrieve tools
34  if ( ptm == nullptr ) {
35  cout << myname << "ERROR: Unable to retrieve tool manaager." << endl;
36  } else {
39  if ( m_pDigitReadTool == nullptr ) {
40  cout << myname << "ERROR: Unable to retrieve digit reader " << m_DigitReadTool << endl;
41  } else {
42  if ( m_LogLevel ) cout << myname << "Retrieved digit read tool " << m_DigitReadTool << endl;
43  }
44  }
45  // Retrieve pedestal provider.
46  if ( m_PedestalOption == 2 ) {
47  if ( m_LogLevel ) cout << myname << "Fetching pedestal provider." << endl;
49  if ( m_LogLevel ) cout << myname << " Pedestal provider: @" << m_pPedProv << endl;
50  }
51  if ( m_PedestalOption == 3 ) {
52  if ( m_LogLevel ) cout << myname << "Fetching pedestal evaluation service." << endl;
54  if ( m_LogLevel ) cout << myname << " Pedestal evaluation service: @"
56  }
57  print(cout, myname);
58 }
59 
60 //**********************************************************************
61 
63  const string myname = "StandardRawDigitExtractService:extract: ";
64  const raw::RawDigit* pdig = acd.digit;
65  if ( pdig == nullptr ) {
66  cout << myname << "ERROR: ADC channel does not have a larsoft digit." << endl;
67  return 1;
68  }
69  const raw::RawDigit& dig = *pdig;
70  if ( m_LogLevel >= 2 ) {
71  cout << myname << "Entering..." << endl;
72  cout << myname << "Input vector size: " << dig.Samples() << endl;
73  }
74  if ( acd.samples.size() ) {
75  cout << myname << "ERROR: Channel has data." << endl;
76  return 2;
77  }
78  if ( acd.flags.size() ) {
79  cout << myname << "ERROR: Channel has flags." << endl;
80  return 3;
81  }
82  if ( m_pDigitReadTool ) {
83  m_pDigitReadTool->update(acd);
84  } else {
85  cout << myname << "ERROR: Digit read tool " << m_DigitReadTool << " was not found." << endl;
86  }
87  unsigned int nsig = acd.raw.size();
88  acd.flags.resize(nsig, AdcGood);
89  acd.samples.resize(nsig, -999);
90  // Retrieve pedestal.
91  AdcSignal ped = 0.0;
92  AdcSignal pedrms = 0.0;
93  if ( m_PedestalOption == 1 ) {
94  ped = dig.GetPedestal();
95  pedrms = dig.GetSigma();
96  } else if ( m_PedestalOption == 2 ) {
97  ped = m_pPedProv->PedMean(acd.channel());
98  }
99  acd.pedestal = ped;
100  acd.pedestalRms = pedrms;
101  // Convert int -> float, subtract pedestal and set conversion flag.
102  const AdcCount lowbits = 0x3f;
103  for ( unsigned int isig=0; isig<nsig; ++isig ) {
104  AdcCount adc = acd.raw[isig];
105  AdcCount adclow = adc & lowbits;
106  acd.samples[isig] = adc - ped;
107  if ( adc == 0 ) acd.flags[isig] = AdcUnderflow;
108  else if ( adc >= 4095 ) acd.flags[isig] = AdcOverflow;
109  else if ( m_FlagStuckOff && adclow == 0 ) acd.flags[isig] = AdcStuckOff;
110  else if ( m_FlagStuckOn && adclow == lowbits ) acd.flags[isig] = AdcStuckOn;
111  }
112  if ( m_PedestalOption == 3 ) {
113 
114  //optional: build ROI and exclude ROI from pedestal calculation
115  if( m_ROIBuilderTool.size() )
116  {
117  m_pROIBuilderTool->update(acd);
118  }
119 
121  for ( unsigned int isig=0; isig<nsig; ++isig ) {
122  acd.samples[isig] -= ped;
123  }
124  acd.pedestal += ped;
125  }
126  return 0;
127 }
128 
129 //**********************************************************************
130 
132 print(std::ostream& out, std::string prefix) const {
133  out << prefix << "StandardRawDigitExtractService:" << endl;
134  out << prefix << " LogLevel: " << m_LogLevel << endl;
135  out << prefix << " DigitReadTool: " << m_DigitReadTool << endl;
136  out << prefix << " PedestalOption: " << m_PedestalOption << endl;
137  out << prefix << " FlagStuckOff: " << m_FlagStuckOff << endl;
138  out << prefix << " FlagStuckOn: " << m_FlagStuckOn << endl;
139  return out;
140 }
141 
142 //**********************************************************************
143 
145 
146 //**********************************************************************
float GetPedestal() const
Definition: RawDigit.h:214
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
int16_t adc
Definition: CRTFragment.hh:202
const AdcFlag AdcUnderflow
Definition: AdcTypes.h:33
virtual int evaluate(const AdcChannelData &data, AdcSignal *pped=nullptr, AdcSignal *prms=nullptr, AdcSignal *ppederr=nullptr, AdcSignal *prmserr=nullptr) const =0
const raw::RawDigit * digit
StandardRawDigitExtractService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
const AdcFlag AdcGood
Definition: AdcTypes.h:32
AdcSignal pedestalRms
const AdcFlag AdcOverflow
Definition: AdcTypes.h:34
T get(std::string const &key) const
Definition: ParameterSet.h:271
const AdcFlag AdcStuckOn
Definition: AdcTypes.h:37
AdcCountVector raw
PedestalEvaluationService * m_PedestalEvaluationService
const AdcFlag AdcStuckOff
Definition: AdcTypes.h:36
Channel channel() const
AdcSignal pedestal
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
short AdcCount
Definition: AdcTypes.h:18
const lariov::DetPedestalProvider * m_pPedProv
float GetSigma() const
TODO RMS of the pedestal level?
Definition: RawDigit.h:215
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)