TPCReadoutSimAlg.h
Go to the documentation of this file.
1 //
2 // TPCReadoutSimAlg.h
3 //
4 // Created by Brian Rebel on 2/14/17.
5 //
6 
7 #ifndef GAR_READOUTSIMULATION_TPCReadoutSimAlg_hpp
8 #define GAR_READOUTSIMULATION_TPCReadoutSimAlg_hpp
9 
10 #include <vector>
11 
13 
14 #include "CLHEP/Random/RandGauss.h"
15 #include "CLHEP/Random/RandFlat.h"
16 
18 #include "DetectorInfo/DetectorProperties.h"
19 
20 namespace fhicl {
21  class ParameterSet;
22 }
23 
24 namespace gar {
25 
26  namespace rosim {
27 
28  // helper struct for tracking the information needed to make raw digits
29  struct edepIDE {
30 
31  edepIDE();
32  edepIDE(float numE,
33  unsigned int chan,
34  unsigned short tdc,
35  size_t edepIdx,
36  float edepWeight)
37  : NumElect(numE)
38  , Channel (chan)
39  , TDC (tdc)
40  {
41  edepLocs.insert(edepIdx);
42  edepWeights.push_front(edepWeight);
43  }
44 
45  //------------------------------------------------------------------------
46  bool operator <(edepIDE const& b) const
47  {
48  if(Channel < b.Channel) return true;
49  else if(Channel == b.Channel){
50  if(TDC < b.TDC) return true;
51  }
52 
53  return false;
54  }
55 
56  //------------------------------------------------------------------------
57  bool operator ==(edepIDE const& b) const
58  {
59  if(Channel == b.Channel &&
60  TDC == b.TDC ) return true;
61 
62  return false;
63  }
64 
65  //------------------------------------------------------------------------
66  bool operator !=(edepIDE const& b) const
67  {
68  return !(*this == b);
69  }
70 
71  //------------------------------------------------------------------------
72  void operator +=(edepIDE const& b)
73  {
74  if(Channel != b.Channel ||
75  TDC != b.TDC ){
76  MF_LOG_WARNING("IonizationReadout")
77  << "Attempting to add edepIDE with different "
78  << "Channels: "
79  << Channel
80  << " / "
81  << b.Channel
82  << " or TDCs: "
83  << TDC
84  << " / "
85  << b.TDC
86  << " bail";
87  return;
88  }
89 
90  NumElect += b.NumElect;
91 
92  for(auto const e : b.edepLocs)
93  edepLocs.insert(e);
94  for(auto const w : b.edepWeights)
95  edepWeights.push_front(w);
96 
97  return;
98  }
99 
100  float NumElect;
101  unsigned int Channel;
102  unsigned short TDC;
103  std::unordered_set<size_t> edepLocs; // keeps insert order, loads from front
104  std::deque<float> edepWeights; // fraction of parent edep associated to digit, use deque for efficient front loading
105  };
106 
108 
109  public:
110 
111  TPCReadoutSimAlg(CLHEP::HepRandomEngine & engine,
112  fhicl::ParameterSet const& pset);
113 
114  virtual ~TPCReadoutSimAlg();
115 
116  // Method to take IDEs and turn them into RawDigits
117  virtual raw::RawDigit CreateRawDigit(unsigned int channel,
118  std::vector<float> const& electrons,
119  bool &todrop) = 0;
120  virtual void CreateNoiseDigits(std::vector<raw::RawDigit> & digits) = 0;
121 
122 
123  virtual void reconfigure(fhicl::ParameterSet const& pset) = 0;
124 
125  protected:
126 
127  CLHEP::HepRandomEngine & fEngine; ///< random number engine
128  bool fAddNoise; ///< flag to add noise or not
129  int fNoiseSpectrum; ///< 0: Gaussian white noise; more to come
130  float fNoiseAmplitude; ///< noise amplitdue
131  int fNoiseVecSize; ///< how much noise to pre-generate
132  int fCompressType; ///< Switch to compress raw digits
133  int fZSThreshold; ///< for ZS Compression, threshold (upwards)
134  unsigned int fZSTicksBefore; ///< for ZS Compression, # samples before
135  unsigned int fZSTicksAfter; ///< for ZS Compression, # samples after
136  int fPedestal; ///< Raw Digit Pedestal
137  const detinfo::DetectorProperties* fDetProp; ///< detector properties
138  int fADCSaturation; ///< limit of the ADC
139 
140  // AddNoiseToADCs is foradding noise to recorded signal. Assume that the
141  // noise level is dependent on the amount of signal recorded
142  virtual void AddNoiseToADCs(std::vector<short> & adcs) = 0;
143  virtual short ElectronsToADCs(float electrons) = 0;
144 
145  };
146 
147  } // end rosim
148 
149 } // end gar
150 
151 
152 #endif /* GAR_READOUTSIMULATION_TPCReadoutSimAlg_hpp */
const detinfo::DetectorProperties * fDetProp
detector properties
float fNoiseAmplitude
noise amplitdue
std::deque< float > edepWeights
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Definition: ToyProducts.h:103
uint8_t channel
Definition: CRTFragment.hh:201
unsigned int fZSTicksBefore
for ZS Compression, # samples before
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.cc:51
unsigned int fZSTicksAfter
for ZS Compression, # samples after
const double e
virtual void reconfigure(fhicl::ParameterSet const &pset)
int fZSThreshold
for ZS Compression, threshold (upwards)
std::unordered_set< size_t > edepLocs
General GArSoft Utilities.
int fNoiseVecSize
how much noise to pre-generate
edepIDE(float numE, unsigned int chan, unsigned short tdc, size_t edepIdx, float edepWeight)
bool fAddNoise
flag to add noise or not
int fCompressType
Switch to compress raw digits.
int fNoiseSpectrum
0: Gaussian white noise; more to come
static bool * b
Definition: config.cpp:1043
CLHEP::HepRandomEngine & fEngine
random number engine
int fADCSaturation
limit of the ADC
#define MF_LOG_WARNING(category)
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:67
int fPedestal
Raw Digit Pedestal.
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept