NoisyAdcSimulator_tool.cc
Go to the documentation of this file.
1 // NoisyAdcSimulator_tool.cc
2 
3 #include "NoisyAdcSimulator.h"
4 using rndm::NuRandomService;
5 using CLHEP::HepJamesRandom;
6 
7 //**********************************************************************
8 
9 NoisyAdcSimulator::NoisyAdcSimulator(double vsen, unsigned int nbit, int noise)
10  :m_noise(noise), m_vsen(vsen), m_vmax(0.0), m_adcmax(0), m_random_engine(nullptr) {
11 
13  m_random_engine = new HepJamesRandom;
14  seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(m_random_engine), "NoisyAdcSimulator");
15 
16  if ( nbit == 0 ) return;
17  unsigned int nbitmax = 8*sizeof(Count);
18  if ( nbit > nbitmax ) return;
19  unsigned int bit = 1;
20  for ( unsigned int ibit=0; ibit<nbit; ++ibit ) {
21  m_adcmax |= bit;
22  bit = bit << 1;
23  }
25 
26 }
27 
28 //**********************************************************************
29 
31  : NoisyAdcSimulator(ps.get<double>("Vsen"), ps.get<unsigned int>("Nbit"), ps.get<int>("Noise")) {
32  std::cout << "Digitisation noise : " << m_noise << "\n";
33 
34 }
35 
36 //**********************************************************************
37 
39 NoisyAdcSimulator::count(double vin, Channel, Tick) const {
40  CLHEP::RandBinomial binom(*m_random_engine);
41 
42  //std::cout << "v_sen " << m_vsen << " m_vmax " << m_vmax << " vin " << vin << std::endl;
43  double halfsen = 0.5*m_vsen;
44  if ( m_vsen <= 0.0 ) return 0;
45  if ( vin < halfsen ) return 0;
46  if ( vin > m_vmax - halfsen ) return m_adcmax;
47  Count count = vin/m_vsen + 0.5;
48  if (m_noise>0) {
49  int n = binom.fire(m_noise,0.5)- m_noise/2;
50  count += n;
51  }
52  if ( count > m_adcmax ) return m_adcmax;
53  return count;
54 }
55 
56 //**********************************************************************
Count count(double vin, Channel chan=0, Tick tick=0) const override
std::void_t< T > n
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
CLHEP::HepRandomEngine * m_random_engine
unsigned short Count
Definition: AdcSimulator.h:24
NoisyAdcSimulator(double vsen, unsigned int nbit, int noise)