10 #include "nurandom/RandomUtils/NuRandomService.h" 11 #include "art_root_io/TFileService.h" 12 #include "CLHEP/Random/JamesRandom.h" 13 #include "CLHEP/Random/RandFlat.h" 14 #include "CLHEP/Random/RandGauss.h" 22 using std::ostringstream;
23 using rndm::NuRandomService;
24 using CLHEP::HepJamesRandom;
30 : fRandomSeed(0), fLogLevel(1),
31 fNoiseHistZ(nullptr), fNoiseHistU(nullptr), fNoiseHistV(nullptr),
32 fNoiseChanHist(nullptr),
34 const string myname =
"ExponentialChannelNoiseService::ctor: ";
52 fNoiseZ.resize(fNoiseArrayPoints);
53 fNoiseU.resize(fNoiseArrayPoints);
54 fNoiseV.resize(fNoiseArrayPoints);
57 fNoiseHistZ = tfs->make<TH1F>(
"znoise",
";Z Noise [ADC counts];", 1000, -10., 10.);
58 fNoiseHistU = tfs->make<TH1F>(
"unoise",
";U Noise [ADC counts];", 1000, -10., 10.);
59 fNoiseHistV = tfs->make<TH1F>(
"vnoise",
";V Noise [ADC counts];", 1000, -10., 10.);
63 string rname =
"ExponentialChannelNoiseService";
65 if (
fLogLevel > 0 ) cout << myname <<
"WARNING: Using hardwired seed." <<
endl;
66 m_pran =
new HepJamesRandom(seed);
68 if (
fLogLevel > 0 ) cout << myname <<
"Using NuRandomService." <<
endl;
70 m_pran =
new HepJamesRandom;
72 seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(
m_pran), rname);
94 const string myname =
"ExponentialChannelNoiseService::dtor: ";
96 cout << myname <<
"Deleting random engine with seed " <<
m_pran->getSeed() <<
endl;
108 unsigned int noisechan = 0;
120 for (
unsigned int itck=0; itck<sigs.size(); ++itck ) {
124 tnoise =
fNoiseU[noisechan][itck];
127 tnoise =
fNoiseV[noisechan][itck];
130 tnoise =
fNoiseZ[noisechan][itck];
133 if ( wnoise != 0.0 ) tnoise += wnoise*gaus.fire();
134 sigs[itck] += tnoise;
142 out << prefix <<
"ExponentialChannelNoiseService: " <<
endl;
159 out << prefix <<
" Actual random seed: " <<
m_pran->getSeed();
167 float aNoiseNorm,
float aNoiseWidth,
float aLowCutoff,
169 const string myname =
"ExponentialChannelNoiseService::generateNoise: ";
171 cout << myname <<
"Generating noise." <<
endl;
173 cout << myname <<
" Norm: " << aNoiseNorm <<
endl;
174 cout << myname <<
" Width: " << aNoiseWidth <<
endl;
175 cout << myname <<
" Cutoff: " << aLowCutoff <<
endl;
176 cout << myname <<
" Seed: " <<
m_pran->getSeed() <<
endl;
183 unsigned int ntick = pfft->
FFTSize();
186 unsigned nbin = ntick/2 + 1;
187 std::vector<TComplex> noiseFrequency(nbin, 0.);
189 double lofilter = 0.;
191 double rnd[2] = {0.};
193 double binWidth = 1.0/(ntick*sampleRate*1.0e-6);
194 bool flatAtLowFreq = aLowCutoff < 0.0;
195 double frqCutoff = flatAtLowFreq ? -aLowCutoff : 0.0;
196 for (
unsigned int i=0; i<ntick/2+1; ++i ) {
197 double frq = double(i)*binWidth;
200 if ( flatAtLowFreq ) {
202 if ( frq < frqCutoff ) frq = frqCutoff;
204 lofilter = 1.0/(1.0+exp(-(i-aLowCutoff/binWidth)/0.5));
207 pval = aNoiseNorm*exp(-frq/aNoiseWidth);
210 flat.fireArray(2, rnd, 0, 1);
211 pval *= lofilter*(0.9 + 0.2*rnd[0]);
213 phase = rnd[1]*2.*TMath::Pi();
214 TComplex tc(pval*cos(phase),pval*sin(phase));
215 noiseFrequency[i] += tc;
219 noise.resize(ntick,0.0);
220 std::vector<double> tmpnoise(noise.size());
221 pfft->
DoInvFFT(noiseFrequency, tmpnoise);
222 noiseFrequency.clear();
228 for (
unsigned int itck=0; itck<noise.size(); ++itck ) {
229 noise[itck] = sqrt(ntick)*tmpnoise[itck];
231 for (
unsigned int itck=0; itck<noise.size(); ++itck ) {
232 aNoiseHist->Fill(noise[itck]);
float fNoiseWidthV
exponential noise width (kHz) for V plane
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
float fNoiseNormV
noise scale factor for V plane
~ExponentialChannelNoiseService()
AdcSignalVectorVector fNoiseV
noise on each channel for each time for V plane
float fNoiseNormZ
noise scale factor for Z (collection) plane
void generateNoise(detinfo::DetectorClocksData const &clockData, float aNoiseNorm, float aNoiseWidth, float aLowCutoff, AdcSignalVector &noise, TH1 *aNoiseHist) const
float fLowCutoffV
low frequency filter cutoff (kHz) for V plane
float fLowCutoffZ
low frequency filter cutoff (kHz) for Z (collection) plane
float fNoiseWidthZ
exponential noise width (kHz) for Z (collection) plane
art framework interface to geometry description
void DoInvFFT(std::vector< TComplex > &input, std::vector< T > &output)
int addNoise(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, Channel chan, AdcSignalVector &sigs) const
float fWhiteNoiseU
Level (per freq bin) for white noise for U.
float fWhiteNoiseV
Level (per freq bin) for white noise for V.
T gaus(T x, T amplitude, T mean, T sigma)
Tests GausssianFit object with a known input.
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
AdcSignalVectorVector fNoiseZ
noise on each channel for each time for Z (collection) plane
T get(std::string const &key) const
TH1 * fNoiseHistU
distribution of noise counts for U
float fLowCutoffU
low frequency filter cutoff (kHz) for U plane
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
float fNoiseWidthU
exponential noise width (kHz) for U plane
float fWhiteNoiseZ
Level (per freq bin) for white noise for Z.
bool fOldNoiseIndex
Use old selection of noise array index.
TH1 * fNoiseHistV
distribution of noise counts for V
ExponentialChannelNoiseService(fhicl::ParameterSet const &pset)
Contains all timing reference information for the detector.
CLHEP::HepRandomEngine * m_pran
int fLogLevel
Log message level: 0=quiet, 1=init only, 2+=every event.
std::optional< T > get_if_present(std::string const &key) const
float fNoiseNormU
noise scale factor for U plane
std::vector< AdcSignal > AdcSignalVector
TH1 * fNoiseChanHist
distribution of accessed noise samples
AdcSignalVectorVector fNoiseU
noise on each channel for each time for U plane
TH1 * fNoiseHistZ
distribution of noise counts for Z
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
LArSoft geometry interface.
int fRandomSeed
Seed for random number service. If absent or zero, use SeedSvc.
QTextStream & endl(QTextStream &s)
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)