8 #include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
14 using std::ostringstream;
15 using rndm::NuRandomService;
16 using CLHEP::HepJamesRandom;
22 : fRandomSeed(0), fLogLevel(1), m_pran(nullptr), fNoiseEngine(nullptr)
24 const string myname =
"SBNDThermalNoiseServiceInFreq::ctor: ";
26 bool haveSeed = pset.get_if_present<
int>(
"RandomSeed",
fRandomSeed);
36 pset.get_if_present<
int>(
"LogLevel",
fLogLevel);
39 string rname =
"SBNDThermalNoiseServiceInFreq";
41 if (
fLogLevel > 0 )
cout << myname <<
"WARNING: Using hardwired seed." << endl;
42 m_pran =
new HepJamesRandom(seed);
44 if (
fLogLevel > 0 )
cout << myname <<
"Using NuRandomService." << endl;
45 art::ServiceHandle<NuRandomService> seedSvc;
46 m_pran =
new HepJamesRandom;
48 seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(
m_pran), rname);
51 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
65 const string myname =
"SBNDThermalNoiseServiceInFreq::dtor: ";
67 cout << myname <<
"Deleting random engine with seed " <<
m_pran->getSeed() << endl;
78 art::ServiceHandle<geo::Geometry> geo;
79 art::ServiceHandle<util::SignalShapingServiceSBND> sss;
80 art::ServiceHandle<util::LArFFT> fFFT;
83 size_t view = (size_t)geo->View(chan);
86 auto tempNoiseVec = sss->GetNoiseFactVec();
87 double shapingTime = 2.0;
88 double asicGain = sss->GetASICGain(chan);
90 size_t fNTicks = fFFT->FFTSize();
94 noise_factor = tempNoiseVec[view].at(
fShapingTimeOrder.find( shapingTime )->second );
95 noise_factor *= asicGain/4.7;
98 throw cet::exception(
"SBNDThermalNoiseServiceInFreq_service.cc")
100 <<
"Shaping Time recieved from signalshapingservices_sbnd.fcl is not one of the allowed values"
102 <<
"Allowed values: 0.5, 1.0, 2.0, 3.0 us"
111 if (sigs.size() != fNTicks)
112 throw cet::exception(
"SBNDThermalNoiseServiceInFreq_service.cc")
114 <<
"Frequency noise vector length must match fNTicks (FFT size)"
115 <<
" ... " << sigs.size() <<
" != " << fNTicks
120 std::vector<TComplex> noiseFrequency(fNTicks / 2 + 1, 0.);
123 double lofilter = 0.;
125 double rnd[2] = {0.};
128 double binWidth = 1.0 / (fNTicks *
fSampleRate * 1.0e-6);
130 for (
size_t i = 0; i < fNTicks / 2 + 1; ++i) {
132 flat.fireArray(2, rnd, 0, 1);
133 std::cout <<
"rnd[0]: " << rnd[0] << std::endl;
134 std::cout <<
"rnd[1]: " << rnd[1] << std::endl;
138 lofilter = 1.0 / (1.0 +
exp(-(i -
fLowCutoff / binWidth) / 0.5));
162 phase = rnd[1] * 2.*TMath::Pi();
163 TComplex tc(pval * cos(phase), pval * sin(phase));
164 noiseFrequency.at(i) += tc;
169 fFFT->DoInvFFT(noiseFrequency, sigs);
171 noiseFrequency.clear();
176 for (
unsigned int i = 0; i < sigs.size(); ++i) {
177 sigs.at(i) *= 1.*fNTicks;
187 out << prefix <<
"SBNDThermalNoiseServiceInFreq: " << endl;
189 out << prefix <<
" LogLevel: " <<
fLogLevel << endl;
190 out << prefix <<
" RandomSeed: " <<
fRandomSeed << endl;
double fNoiseRand
fraction of random "wiggle" in noise in freq. spectrum
CLHEP::HepRandomEngine * fNoiseEngine
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
double fLowCutoff
low frequency filter cutoff (kHz)
SBNDThermalNoiseServiceInFreq(fhicl::ParameterSet const &pset)
~SBNDThermalNoiseServiceInFreq()
CLHEP::HepRandomEngine * m_pran
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const override
int addNoise(detinfo::DetectorClocksData const &clockData, Channel chan, AdcSignalVector &sigs) const override
int fRandomSeed
Seed for random number service. If absent or zero, use SeedSvc.
double fNoiseWidth
exponential noise width (kHz)
std::vector< AdcSignal > AdcSignalVector
Contains all timing reference information for the detector.
std::map< double, int > fShapingTimeOrder
virtual void generateNoise(detinfo::DetectorClocksData const &)
BEGIN_PROLOG could also be cout
int fLogLevel
Log message level: 0=quiet, 1=init only, 2+=every event.