IdealAdcSimulator_tool.cc
Go to the documentation of this file.
1 // IdealAdcSimulator_tool.cc
2 
3 #include "IdealAdcSimulator.h"
4 
5 //**********************************************************************
6 
7 IdealAdcSimulator::IdealAdcSimulator(double vsen, unsigned int nbit)
8 : m_vsen(vsen), m_vmax(0.0), m_adcmax(0) {
9  if ( nbit == 0 ) return;
10  unsigned int nbitmax = 8*sizeof(Count);
11  if ( nbit > nbitmax ) return;
12  unsigned int bit = 1;
13  for ( unsigned int ibit=0; ibit<nbit; ++ibit ) {
14  m_adcmax |= bit;
15  bit = bit << 1;
16  }
18 }
19 
20 //**********************************************************************
21 
23 : IdealAdcSimulator(ps.get<double>("Vsen"), ps.get<unsigned int>("Nbit")) { }
24 
25 //**********************************************************************
26 
28 IdealAdcSimulator::count(double vin, Channel, Tick) const {
29  //std::cout << "v_sen " << m_vsen << " m_vmax " << m_vmax << " vin " << vin << std::endl;
30  double halfsen = 0.5*m_vsen;
31  if ( m_vsen <= 0.0 ) return 0;
32  if ( vin < halfsen ) return 0;
33  if ( vin > m_vmax - halfsen ) return m_adcmax;
34  Count count = vin/m_vsen + 0.5;
35  assert( count <= m_adcmax );
36  //std::cout << " count " << count << " m_adcmax " << m_adcmax << std::endl;
37  if ( count > m_adcmax ) return m_adcmax;//
38  return count;
39 }
40 
41 //**********************************************************************
42 
Count count(double vin, Channel chan=0, Tick tick=0) const override
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
IdealAdcSimulator(double vsen, unsigned int nbit=12)
T get(std::string const &key) const
Definition: ParameterSet.h:271
unsigned int Tick
Definition: AdcSimulator.h:25
static constexpr double ps
Definition: Units.h:99
unsigned int Channel
Definition: AdcSimulator.h:23
unsigned short Count
Definition: AdcSimulator.h:24