9 #include "nurandom/RandomUtils/NuRandomService.h" 10 #include "art_root_io/TFileService.h" 11 #include "CLHEP/Random/JamesRandom.h" 12 #include "CLHEP/Random/RandFlat.h" 13 #include "CLHEP/Random/RandGauss.h" 23 using std::ostringstream;
24 using rndm::NuRandomService;
25 using CLHEP::HepJamesRandom;
31 : fRandomSeed(0), fLogLevel(1),
32 fNoiseHistZ(nullptr), fNoiseHistU(nullptr), fNoiseHistV(nullptr),
33 fNoiseChanHist(nullptr),
35 const string myname =
"ProtoDUNEChannelNoiseService::ctor: ";
47 fENOB = pset.
get<
double>(
"EffectiveNBits");
51 fNoiseZ.resize(fNoiseArrayPoints);
52 fNoiseU.resize(fNoiseArrayPoints);
53 fNoiseV.resize(fNoiseArrayPoints);
56 fNoiseHistZ = tfs->make<TH1F>(
"znoise",
";Z Noise [ADC counts];", 1000, -10., 10.);
57 fNoiseHistU = tfs->make<TH1F>(
"unoise",
";U Noise [ADC counts];", 1000, -10., 10.);
58 fNoiseHistV = tfs->make<TH1F>(
"vnoise",
";V Noise [ADC counts];", 1000, -10., 10.);
62 string rname =
"ProtoDUNEChannelNoiseService";
64 if (
fLogLevel > 0 ) cout << myname <<
"WARNING: Using hardwired seed." <<
endl;
65 m_pran =
new HepJamesRandom(seed);
67 if (
fLogLevel > 0 ) cout << myname <<
"Using NuRandomService." <<
endl;
69 m_pran =
new HepJamesRandom;
71 seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(
m_pran), rname);
92 const string myname =
"ProtoDUNEChannelNoiseService::dtor: ";
94 cout << myname <<
"Deleting random engine with seed " <<
m_pran->getSeed() <<
endl;
106 unsigned int noisechan = 0;
118 for (
unsigned int itck=0; itck<sigs.size(); ++itck ) {
122 tnoise =
fNoiseU[noisechan][itck];
125 tnoise =
fNoiseV[noisechan][itck];
128 tnoise =
fNoiseZ[noisechan][itck];
131 if ( wnoise != 0.0 ) tnoise += wnoise*gaus.fire();
132 sigs[itck] += tnoise;
140 out << prefix <<
"ProtoDUNEChannelNoiseService: " <<
endl;
146 out << prefix <<
" EffectiveNBits: " <<
fENOB <<
endl;
155 out << prefix <<
" Actual random seed: " <<
m_pran->getSeed();
163 float wirelength,
float ENOB,
float aLowCutoff,
165 const string myname =
"ProtoDUNEChannelNoiseService::generateNoise: ";
167 cout << myname <<
"Generating noise." <<
endl;
169 cout << myname <<
" Cutoff: " << aLowCutoff <<
endl;
170 cout << myname <<
" Seed: " <<
m_pran->getSeed() <<
endl;
177 unsigned int ntick = pfft->
FFTSize();
180 unsigned nbin = ntick/2 + 1;
181 std::vector<TComplex> noiseFrequency(nbin, 0.);
185 double rnd[3] = {0.};
190 double fitpar[9] = {0.};
191 double wldparams[2] = {0.};
194 double baseline_noise = std::sqrt(ntick*1.0/12)*
std::pow(2, 12 -
fENOB);
196 TF1* _wld_f =
new TF1(
"_wld_f",
"[0] + [1]*x", 0.0, 1000);
198 TF1* _poisson =
new TF1(
"_poisson",
"[0]**(x) * exp(-[0]) / ROOT::Math::tgamma(x+1.)", 0, 30);
200 TF1* _pfn_f1 =
new TF1(
"_pfn_f1",
"([0]*1/(x*[8]/2 + 10) + ([1]*exp(-0.5*(((x*[8]/2)-[2])/[3])**2)*exp(-0.5*pow(x*[8]/(2*[4]),[5])))*[6])+[7]", 0.0, (
double)ntick);
206 wldparams[0] = 0.395;
207 wldparams[1] = 0.001304;
208 _wld_f->SetParameters(wldparams);
209 double wldValue = _wld_f->Eval(wirelength);
210 fitpar[0] = 9.27790e+02;
211 fitpar[1] = 1.20284e+07;
212 fitpar[2] = 4.93692e+03;
213 fitpar[3] = 1.03438e+03;
214 fitpar[4] = 2.33306e+02;
215 fitpar[5] = 1.36605e+00;
216 fitpar[6] = wldValue;
217 fitpar[7] = baseline_noise;
219 _pfn_f1->SetParameters(fitpar);
220 _poisson->SetParameters(params);
223 double binWidth = 1.0/(ntick*sampleRate*1.0e-6);
224 for (
unsigned int i=0; i<ntick/2+1; ++i ) {
226 double pfnf1val = _pfn_f1->Eval((
double)i*binWidth/1000);
228 double randomizer = _poisson->GetRandom()/params[0];
229 pval = pfnf1val * randomizer;
233 flat.fireArray(2, rnd, 0, 1);
236 phase = rnd[1]*2.*TMath::Pi();
237 TComplex tc(pval*cos(phase),pval*sin(phase));
238 noiseFrequency[i] += tc;
242 noise.resize(ntick,0.0);
243 std::vector<double> tmpnoise(noise.size());
244 pfft->
DoInvFFT(noiseFrequency, tmpnoise);
245 noiseFrequency.clear();
246 for (
unsigned int itck=0; itck<noise.size(); ++itck ) {
247 noise[itck] = tmpnoise[itck];
249 for (
unsigned int itck=0; itck<noise.size(); ++itck ) {
250 aNoiseHist->Fill(noise[itck]);
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.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
float fWhiteNoiseZ
Level (per freq bin) for white noise for Z.
AdcSignalVectorVector fNoiseZ
noise on each channel for each time for Z (collection) plane
TH1 * fNoiseHistU
distribution of noise counts for U
AdcSignalVectorVector fNoiseV
noise on each channel for each time for V plane
ProtoDUNEChannelNoiseService(fhicl::ParameterSet const &pset)
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
void generateNoise(detinfo::DetectorClocksData const &clockData, float wirelength, float ENOB, float aLowCutoff, AdcSignalVector &noise, TH1 *aNoiseHist) const
bool fOldNoiseIndex
Use old selection of noise array index.
art framework interface to geometry description
void DoInvFFT(std::vector< TComplex > &input, std::vector< T > &output)
CLHEP::HepRandomEngine * m_pran
T gaus(T x, T amplitude, T mean, T sigma)
Tests GausssianFit object with a known input.
~ProtoDUNEChannelNoiseService()
AdcSignalVectorVector fNoiseU
noise on each channel for each time for U plane
float fLowCutoffV
low frequency filter cutoff (kHz) for V plane
T get(std::string const &key) const
int fRandomSeed
Seed for random number service. If absent or zero, use SeedSvc.
TH1 * fNoiseHistV
distribution of noise counts for V
float fWhiteNoiseV
Level (per freq bin) for white noise for V.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
TH1 * fNoiseChanHist
distribution of accessed noise samples
Contains all timing reference information for the detector.
std::optional< T > get_if_present(std::string const &key) const
std::vector< AdcSignal > AdcSignalVector
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 fLogLevel
Log message level: 0=quiet, 1=init only, 2+=every event.
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
float fLowCutoffZ
low frequency filter cutoff (kHz) for Z (collection) plane
QTextStream & endl(QTextStream &s)
float fLowCutoffU
low frequency filter cutoff (kHz) for U plane
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)