Public Member Functions | Private Member Functions | Private Attributes | List of all members
gar::rosim::TPCReadoutSimStandardAlg Class Reference

#include <TPCReadoutSimStandardAlg.h>

Inheritance diagram for gar::rosim::TPCReadoutSimStandardAlg:
gar::rosim::TPCReadoutSimAlg

Public Member Functions

 TPCReadoutSimStandardAlg (CLHEP::HepRandomEngine &engine, fhicl::ParameterSet const &pset)
 
virtual ~TPCReadoutSimStandardAlg ()
 
raw::RawDigit CreateRawDigit (unsigned int channel, std::vector< float > const &electrons, bool &todrop)
 
void CreateNoiseDigits (std::vector< raw::RawDigit > &digits)
 
void reconfigure (fhicl::ParameterSet const &pset)
 
- Public Member Functions inherited from gar::rosim::TPCReadoutSimAlg
 TPCReadoutSimAlg (CLHEP::HepRandomEngine &engine, fhicl::ParameterSet const &pset)
 
virtual ~TPCReadoutSimAlg ()
 

Private Member Functions

void AddNoiseToADCs (std::vector< short > &adcs)
 
short ElectronsToADCs (float electrons)
 

Private Attributes

std::vector< short > fNoiseVec
 

Additional Inherited Members

- Protected Attributes inherited from gar::rosim::TPCReadoutSimAlg
CLHEP::HepRandomEngine & fEngine
 random number engine More...
 
bool fAddNoise
 flag to add noise or not More...
 
int fNoiseSpectrum
 0: Gaussian white noise; more to come More...
 
float fNoiseAmplitude
 noise amplitdue More...
 
int fNoiseVecSize
 how much noise to pre-generate More...
 
int fCompressType
 Switch to compress raw digits. More...
 
int fZSThreshold
 for ZS Compression, threshold (upwards) More...
 
unsigned int fZSTicksBefore
 for ZS Compression, # samples before More...
 
unsigned int fZSTicksAfter
 for ZS Compression, # samples after More...
 
int fPedestal
 Raw Digit Pedestal. More...
 
const detinfo::DetectorPropertiesfDetProp
 detector properties More...
 
int fADCSaturation
 limit of the ADC More...
 

Detailed Description

Definition at line 19 of file TPCReadoutSimStandardAlg.h.

Constructor & Destructor Documentation

gar::rosim::TPCReadoutSimStandardAlg::TPCReadoutSimStandardAlg ( CLHEP::HepRandomEngine &  engine,
fhicl::ParameterSet const &  pset 
)

Definition at line 18 of file TPCReadoutSimStandardAlg.cxx.

20  : TPCReadoutSimAlg(engine, pset)
21  {
22  this->reconfigure(pset);
23 
24  fDetProp = gar::providerFrom<detinfo::DetectorPropertiesService>();
25 
26  fNoiseVec.clear();
27  std::vector<double> noisevecdbl(fNoiseVecSize,0);
28  if (fNoiseSpectrum == 0)
29  {
30  CLHEP::RandGauss GaussRand(fEngine);
31  //std::cout << "noise amplitude: " << fNoiseAmplitude << std::endl;
32  GaussRand.fireArray(fNoiseVecSize, &noisevecdbl[0],0.0,fNoiseAmplitude);
33  for (int i=0; i<fNoiseVecSize; ++i)
34  {
35  long inoise = lrint(noisevecdbl[i]);
36  if (inoise > 32767) inoise = 32767; // to be stored in a signed short.
37  if (inoise < -32767) inoise = -32767; // to be stored in a signed short.
38  fNoiseVec.push_back( (short) inoise );
39  //std::cout << "inoise: " << i << " " << inoise << std::endl;
40  }
41  }
42 
43 
44  return;
45  }
const detinfo::DetectorProperties * fDetProp
detector properties
float fNoiseAmplitude
noise amplitdue
int fNoiseVecSize
how much noise to pre-generate
TPCReadoutSimAlg(CLHEP::HepRandomEngine &engine, fhicl::ParameterSet const &pset)
int fNoiseSpectrum
0: Gaussian white noise; more to come
CLHEP::HepRandomEngine & fEngine
random number engine
void reconfigure(fhicl::ParameterSet const &pset)
gar::rosim::TPCReadoutSimStandardAlg::~TPCReadoutSimStandardAlg ( )
virtual

Definition at line 48 of file TPCReadoutSimStandardAlg.cxx.

49  {
50  return;
51  }

Member Function Documentation

void gar::rosim::TPCReadoutSimStandardAlg::AddNoiseToADCs ( std::vector< short > &  adcs)
privatevirtual

Implements gar::rosim::TPCReadoutSimAlg.

Definition at line 160 of file TPCReadoutSimStandardAlg.cxx.

161  {
162  // start sampling the pregenerated noise vector from a random spot
163  CLHEP::RandFlat FlatRand(fEngine);
164  double xnvi = ((double) fNoiseVec.size() - 1) * FlatRand.fire();
165  if (xnvi < 0) xnvi = 0; // just to be extra sure
166  size_t i = (size_t ) xnvi;
167  if (i >= fNoiseVec.size())
168  {
169  i = fNoiseVec.size() - 1;
170  }
171  //std::cout << "In AddNoiseToADCs: " << i << " " << fNoiseVec.size() << " " << adcs.size() << std::endl;
172  for (size_t j=0; j<adcs.size(); ++j)
173  {
174  adcs[j] += fNoiseVec[i]; // we check the bounds of i already
175  ++i;
176  if (i>=fNoiseVec.size()) i=0;
177  if (adcs[j]>fADCSaturation) adcs[j] = fADCSaturation;
178  }
179 
180  return;
181  }
CLHEP::HepRandomEngine & fEngine
random number engine
int fADCSaturation
limit of the ADC
void gar::rosim::TPCReadoutSimStandardAlg::CreateNoiseDigits ( std::vector< raw::RawDigit > &  digits)
virtual

Implements gar::rosim::TPCReadoutSimAlg.

Definition at line 116 of file TPCReadoutSimStandardAlg.cxx.

117  {
118  if(!fAddNoise) return;
119 
120  // we'll need the geometry
121  auto geo = gar::providerFrom<geo::GeometryGAr>();
122 
123  // figure out which channels we need to make pure noise
124  std::set<unsigned int> channels;
125  for(auto const& dig : digits) channels.insert(dig.Channel());
126 
127  // now loop over the channels in the detector and make a noise digit
128  // for any channel that does not already have a rawdigit
129  for(unsigned int c = 0; c < geo->NChannels(); ++c){
130 
131  // do nothing if we already have a digit for this channel
132  if(channels.count(c) > 0) continue;
133 
134  //std::cout << "Making noise digit for channel: " << c << std::endl;
135  //std::cout << "ZS Threshold: " << fZSThreshold << std::endl;
136  std::vector<short> adcs(fDetProp->NumberTimeSamples(), 0);
137  this->AddNoiseToADCs(adcs);
138  // check for zero suppression
140  int retblocks = 1;
141  if (fCompressType == 1)
142  {
145  }
146  //std::cout << "retblocks: " << retblocks << std::endl;
147  auto numTicks = fDetProp->NumberTimeSamples();
148  if (retblocks) digits.emplace_back(c, numTicks, adcs, cflag, 0);
149 
150  } // end make noise digits
151 
152 
153  return;
154  }
void AddNoiseToADCs(std::vector< short > &adcs)
const detinfo::DetectorProperties * fDetProp
detector properties
enum gar::raw::_compress Compress_t
unsigned int fZSTicksBefore
for ZS Compression, # samples before
unsigned int fZSTicksAfter
for ZS Compression, # samples after
Zero Suppression algorithm.
Definition: RawTypes.h:18
int fZSThreshold
for ZS Compression, threshold (upwards)
no compression
Definition: RawTypes.h:16
bool fAddNoise
flag to add noise or not
int fCompressType
Switch to compress raw digits.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void Compress(gar::raw::ADCvector_t &adc, gar::raw::Compress_t compress)
In-place compression of raw data buffer.
Definition: raw.cxx:23
virtual unsigned int NumberTimeSamples() const =0
raw::RawDigit gar::rosim::TPCReadoutSimStandardAlg::CreateRawDigit ( unsigned int  channel,
std::vector< float > const &  electrons,
bool todrop 
)
virtual

Implements gar::rosim::TPCReadoutSimAlg.

Definition at line 54 of file TPCReadoutSimStandardAlg.cxx.

57  {
58  // make a vector to store the adc information
59  auto numTicks = fDetProp->NumberTimeSamples();
60  std::vector< short> adcs(numTicks, 0);
61 
62 
63  // check that the size of the electrons vector is the same as the
64  // adc vector, they better be
65  if(adcs.size() != electrons.size()){
66  throw cet::exception("TPCReadoutSimStandardAlg")
67  << "The vectors for adc and electrons have different sizes, no idea "
68  << "how to handle that, bail";
69  }
70 
71  for(size_t e = 0; e < electrons.size(); ++e){
72  adcs[e] = this->ElectronsToADCs(electrons[e]);
73 // if(electrons[e] > 0)
74 // LOG_VERBATIM("TPCReadoutSim")
75 // << "ADC: "
76 // << adcs[e]
77 // << " electrons "
78 // << electrons[e]
79 // << " tdc "
80 // << e;
81  }
82 
83  // add noise to the adc vector if we want that
84  if(fAddNoise) this->AddNoiseToADCs(adcs);
85 
86  // check for zero suppression
87  int retblocks = 1;
89  if (fCompressType == 1)
90  {
93  }
94 
95  todrop = (retblocks == 0);
96  return raw::RawDigit(channel, numTicks, adcs, cflag, 0);
97  }
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
void AddNoiseToADCs(std::vector< short > &adcs)
const detinfo::DetectorProperties * fDetProp
detector properties
enum gar::raw::_compress Compress_t
uint8_t channel
Definition: CRTFragment.hh:201
unsigned int fZSTicksBefore
for ZS Compression, # samples before
unsigned int fZSTicksAfter
for ZS Compression, # samples after
const double e
Zero Suppression algorithm.
Definition: RawTypes.h:18
int fZSThreshold
for ZS Compression, threshold (upwards)
no compression
Definition: RawTypes.h:16
bool fAddNoise
flag to add noise or not
int fCompressType
Switch to compress raw digits.
void Compress(gar::raw::ADCvector_t &adc, gar::raw::Compress_t compress)
In-place compression of raw data buffer.
Definition: raw.cxx:23
virtual unsigned int NumberTimeSamples() const =0
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
short gar::rosim::TPCReadoutSimStandardAlg::ElectronsToADCs ( float  electrons)
privatevirtual

Implements gar::rosim::TPCReadoutSimAlg.

Definition at line 184 of file TPCReadoutSimStandardAlg.cxx.

185  {
186  //LOG_DEBUG("TPCReadoutSimStandard")
187  //<< "Electrons to ADC: "
188  //<< fDetProp->ElectronsToADC()
189  //<< " electrons: "
190  //<< electrons
191  //<< " product: "
192  //<< fDetProp->ElectronsToADC() * electrons;
193 
194  int tmpadc = (int) (fDetProp->ElectronsToADC() * electrons);
195  if (tmpadc > fADCSaturation) tmpadc = fADCSaturation;
196  return (short)(tmpadc);
197  }
const detinfo::DetectorProperties * fDetProp
detector properties
virtual double ElectronsToADC() const =0
int fADCSaturation
limit of the ADC
void gar::rosim::TPCReadoutSimStandardAlg::reconfigure ( fhicl::ParameterSet const &  pset)
virtual

Implements gar::rosim::TPCReadoutSimAlg.

Definition at line 100 of file TPCReadoutSimStandardAlg.cxx.

101  {
102  fAddNoise = pset.get<bool>("AddNoise", false);
103  fNoiseSpectrum = pset.get<int>("NoiseSpectrum", 0);
104  fNoiseVecSize = pset.get<int>("NoiseVecSize",500000);
105  fNoiseAmplitude = pset.get<float>("NoiseAmplitude", 0);
106  fCompressType = pset.get<int>("CompressType",0);
107  fZSThreshold = pset.get<int>("ZSThreshold",5);
108  fZSTicksBefore = pset.get<unsigned int>("ZSTicksBefore",5);
109  fZSTicksAfter = pset.get<unsigned int>("ZSTicksAfter",5);
110  fPedestal = pset.get<int>("Pedestal",0);
111  fADCSaturation = pset.get<int>("ADCSaturation",4095); // default to 12-bit ADC's
112  return;
113  }
float fNoiseAmplitude
noise amplitdue
unsigned int fZSTicksBefore
for ZS Compression, # samples before
unsigned int fZSTicksAfter
for ZS Compression, # samples after
int fZSThreshold
for ZS Compression, threshold (upwards)
int fNoiseVecSize
how much noise to pre-generate
bool fAddNoise
flag to add noise or not
int fCompressType
Switch to compress raw digits.
int fNoiseSpectrum
0: Gaussian white noise; more to come
int fADCSaturation
limit of the ADC
int fPedestal
Raw Digit Pedestal.

Member Data Documentation

std::vector<short> gar::rosim::TPCReadoutSimStandardAlg::fNoiseVec
private

Definition at line 42 of file TPCReadoutSimStandardAlg.h.


The documentation for this class was generated from the following files: