All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SBNDThermalNoiseServiceInFreq Class Reference

#include <SBNDThermalNoiseServiceInFreq.h>

Inheritance diagram for SBNDThermalNoiseServiceInFreq:
ChannelNoiseService

Public Member Functions

 SBNDThermalNoiseServiceInFreq (fhicl::ParameterSet const &pset)
 
 SBNDThermalNoiseServiceInFreq (fhicl::ParameterSet const &pset, art::ActivityRegistry &)
 
 ~SBNDThermalNoiseServiceInFreq ()
 
int addNoise (detinfo::DetectorClocksData const &clockData, Channel chan, AdcSignalVector &sigs) const override
 
std::ostream & print (std::ostream &out=std::cout, std::string prefix="") const override
 
- Public Member Functions inherited from ChannelNoiseService
virtual ~ChannelNoiseService ()=default
 
virtual void generateNoise (detinfo::DetectorClocksData const &)
 

Private Member Functions

void InitialiseProducerDeps (art::EDProducer *EDProdPointer, fhicl::ParameterSet const &pset) override
 

Private Attributes

unsigned int fNoiseArrayPoints
 number of points in randomly generated noise array More...
 
int fRandomSeed
 Seed for random number service. If absent or zero, use SeedSvc. More...
 
int fLogLevel
 Log message level: 0=quiet, 1=init only, 2+=every event. More...
 
std::map< double, int > fShapingTimeOrder
 
double fSampleRate
 
double fNoiseWidth
 exponential noise width (kHz) More...
 
double fNoiseRand
 fraction of random "wiggle" in noise in freq. spectrum More...
 
double fLowCutoff
 low frequency filter cutoff (kHz) More...
 
CLHEP::HepRandomEngine * m_pran
 
CLHEP::HepRandomEngine * fNoiseEngine
 

Additional Inherited Members

- Public Types inherited from ChannelNoiseService
typedef unsigned int Channel
 

Detailed Description

Definition at line 47 of file SBNDThermalNoiseServiceInFreq.h.

Constructor & Destructor Documentation

SBNDThermalNoiseServiceInFreq::SBNDThermalNoiseServiceInFreq ( fhicl::ParameterSet const &  pset)

Definition at line 21 of file SBNDThermalNoiseServiceInFreq_service.cc.

22  : fRandomSeed(0), fLogLevel(1), m_pran(nullptr), fNoiseEngine(nullptr)
23 {
24  const string myname = "SBNDThermalNoiseServiceInFreq::ctor: ";
25  fNoiseArrayPoints = pset.get<unsigned int>("NoiseArrayPoints");
26  bool haveSeed = pset.get_if_present<int>("RandomSeed", fRandomSeed);
27 
28 
29  fShapingTimeOrder = { {0.5, 0 }, {1.0, 1}, {2.0, 2}, {3.0, 3} };
30  fNoiseWidth = pset.get< double >("NoiseWidth");
31  fNoiseRand = pset.get< double >("NoiseRand");
32  fLowCutoff = pset.get< double >("LowCutoff");
33 
34 
35  if ( fRandomSeed == 0 ) haveSeed = false;
36  pset.get_if_present<int>("LogLevel", fLogLevel);
37  int seed = fRandomSeed;
38 
39  string rname = "SBNDThermalNoiseServiceInFreq";
40  if ( haveSeed ) {
41  if ( fLogLevel > 0 ) cout << myname << "WARNING: Using hardwired seed." << endl;
42  m_pran = new HepJamesRandom(seed);
43  } else {
44  if ( fLogLevel > 0 ) cout << myname << "Using NuRandomService." << endl;
45  art::ServiceHandle<NuRandomService> seedSvc;
46  m_pran = new HepJamesRandom;
47  if ( fLogLevel > 0 ) cout << myname << " Initial seed: " << m_pran->getSeed() << endl;
48  seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(m_pran), rname);
49  }
50  if ( fLogLevel > 0 ) cout << myname << " Registered seed: " << m_pran->getSeed() << endl;
51  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
52  generateNoise(clockData);
53  if ( fLogLevel > 1 ) print() << endl;
54 }
double fNoiseRand
fraction of random &quot;wiggle&quot; in noise in freq. spectrum
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
double fLowCutoff
low frequency filter cutoff (kHz)
unsigned int seed
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const override
int fRandomSeed
Seed for random number service. If absent or zero, use SeedSvc.
double fNoiseWidth
exponential noise width (kHz)
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.
SBNDThermalNoiseServiceInFreq::SBNDThermalNoiseServiceInFreq ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry &   
)

Definition at line 59 of file SBNDThermalNoiseServiceInFreq_service.cc.

SBNDThermalNoiseServiceInFreq(fhicl::ParameterSet const &pset)
SBNDThermalNoiseServiceInFreq::~SBNDThermalNoiseServiceInFreq ( )

Definition at line 64 of file SBNDThermalNoiseServiceInFreq_service.cc.

64  {
65  const string myname = "SBNDThermalNoiseServiceInFreq::dtor: ";
66  if ( fLogLevel > 0 ) {
67  cout << myname << "Deleting random engine with seed " << m_pran->getSeed() << endl;
68  }
69  delete m_pran;
70 }
BEGIN_PROLOG could also be cout
int fLogLevel
Log message level: 0=quiet, 1=init only, 2+=every event.

Member Function Documentation

int SBNDThermalNoiseServiceInFreq::addNoise ( detinfo::DetectorClocksData const &  clockData,
Channel  chan,
AdcSignalVector sigs 
) const
overridevirtual

Implements ChannelNoiseService.

Definition at line 74 of file SBNDThermalNoiseServiceInFreq_service.cc.

75  {
76 
77  //Get services.
78  art::ServiceHandle<geo::Geometry> geo;
79  art::ServiceHandle<util::SignalShapingServiceSBND> sss;
80  art::ServiceHandle<util::LArFFT> fFFT;
81 
82  //Generate Noise:
83  size_t view = (size_t)geo->View(chan);
84 
85  double noise_factor;
86  auto tempNoiseVec = sss->GetNoiseFactVec();
87  double shapingTime = 2.0; //sss->GetShapingTime(chan);
88  double asicGain = sss->GetASICGain(chan);
89 
90  size_t fNTicks = fFFT->FFTSize();
91 
92 
93  if (fShapingTimeOrder.find( shapingTime ) != fShapingTimeOrder.end() ) {
94  noise_factor = tempNoiseVec[view].at( fShapingTimeOrder.find( shapingTime )->second );
95  noise_factor *= asicGain/4.7;
96  }
97  else {
98  throw cet::exception("SBNDThermalNoiseServiceInFreq_service.cc")
99  << "\033[93m"
100  << "Shaping Time recieved from signalshapingservices_sbnd.fcl is not one of the allowed values"
101  << std::endl
102  << "Allowed values: 0.5, 1.0, 2.0, 3.0 us"
103  << "\033[00m"
104  << std::endl;
105  }
106 
107 
108  CLHEP::RandFlat flat(*fNoiseEngine, -1, 1);
109 
110 
111  if (sigs.size() != fNTicks)
112  throw cet::exception("SBNDThermalNoiseServiceInFreq_service.cc")
113  << "\033[93m"
114  << "Frequency noise vector length must match fNTicks (FFT size)"
115  << " ... " << sigs.size() << " != " << fNTicks
116  << "\033[00m"
117  << std::endl;
118 
119  // noise in frequency space
120  std::vector<TComplex> noiseFrequency(fNTicks / 2 + 1, 0.);
121 
122  double pval = 0.;
123  double lofilter = 0.;
124  double phase = 0.;
125  double rnd[2] = {0.};
126 
127  // width of frequencyBin in kHz
128  double binWidth = 1.0 / (fNTicks * fSampleRate * 1.0e-6);
129 
130  for (size_t i = 0; i < fNTicks / 2 + 1; ++i) {
131  // exponential noise spectrum
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;
135 
136  pval = noise_factor * exp(-(double)i * binWidth / fNoiseWidth);
137  // low frequency cutoff
138  lofilter = 1.0 / (1.0 + exp(-(i - fLowCutoff / binWidth) / 0.5));
139  // randomize 10%
140 
141  pval *= lofilter * ((1 - fNoiseRand) + 2 * fNoiseRand * rnd[0]);
142 
143  /*
144  //if not from histo or in time --> then hardcoded freq. spectrum
145  if ( !fGetNoiseFromHisto )
146  {
147  pval = noise_factor * exp(-(double)i * binWidth / fNoiseWidth);
148  // low frequency cutoff
149  lofilter = 1.0 / (1.0 + exp(-(i - fLowCutoff / binWidth) / 0.5));
150  // randomize 10%
151 
152  pval *= lofilter * ((1 - fNoiseRand) + 2 * fNoiseRand * rnd[0]);
153  }
154 
155 
156  else
157  {
158 
159  pval = fNoiseHist->GetBinContent(i) * ((1 - fNoiseRand) + 2 * fNoiseRand * rnd[0]) * noise_factor;
160  }
161  */
162  phase = rnd[1] * 2.*TMath::Pi();
163  TComplex tc(pval * cos(phase), pval * sin(phase));
164  noiseFrequency.at(i) += tc;
165  }
166 
167 
168  // inverse FFT MCSignal
169  fFFT->DoInvFFT(noiseFrequency, sigs);
170 
171  noiseFrequency.clear();
172 
173  // multiply each noise value by fNTicks as the InvFFT
174  // divides each bin by fNTicks assuming that a forward FFT
175  // has already been done.
176  for (unsigned int i = 0; i < sigs.size(); ++i) {
177  sigs.at(i) *= 1.*fNTicks;
178  }
179 
180  return 0;
181 }
double fNoiseRand
fraction of random &quot;wiggle&quot; in noise in freq. spectrum
double fLowCutoff
low frequency filter cutoff (kHz)
double fNoiseWidth
exponential noise width (kHz)
BEGIN_PROLOG could also be cout
void SBNDThermalNoiseServiceInFreq::InitialiseProducerDeps ( art::EDProducer *  EDProdPointer,
fhicl::ParameterSet const &  pset 
)
inlineoverrideprivatevirtual

Reimplemented from ChannelNoiseService.

Definition at line 84 of file SBNDThermalNoiseServiceInFreq.h.

84  {
85 
86  CLHEP::HepRandomEngine& NoiseEngine((art::ServiceHandle<rndm::NuRandomService>{}->createEngine(*EDProdPointer,"HepJamesRandom","noise",pset,"Seed")));
87  fNoiseEngine = &NoiseEngine;
88  return;
89  }
ostream & SBNDThermalNoiseServiceInFreq::print ( std::ostream &  out = std::cout,
std::string  prefix = "" 
) const
overridevirtual

Implements ChannelNoiseService.

Definition at line 186 of file SBNDThermalNoiseServiceInFreq_service.cc.

186  {
187  out << prefix << "SBNDThermalNoiseServiceInFreq: " << endl;
188 
189  out << prefix << " LogLevel: " << fLogLevel << endl;
190  out << prefix << " RandomSeed: " << fRandomSeed << endl;
191  out << prefix << " NoiseArrayPoints: " << fNoiseArrayPoints << endl;
192 
193  return out;
194 }
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
int fRandomSeed
Seed for random number service. If absent or zero, use SeedSvc.
int fLogLevel
Log message level: 0=quiet, 1=init only, 2+=every event.

Member Data Documentation

int SBNDThermalNoiseServiceInFreq::fLogLevel
private

Log message level: 0=quiet, 1=init only, 2+=every event.

Definition at line 72 of file SBNDThermalNoiseServiceInFreq.h.

double SBNDThermalNoiseServiceInFreq::fLowCutoff
private

low frequency filter cutoff (kHz)

Definition at line 77 of file SBNDThermalNoiseServiceInFreq.h.

unsigned int SBNDThermalNoiseServiceInFreq::fNoiseArrayPoints
private

number of points in randomly generated noise array

Definition at line 70 of file SBNDThermalNoiseServiceInFreq.h.

CLHEP::HepRandomEngine* SBNDThermalNoiseServiceInFreq::fNoiseEngine
private

Definition at line 81 of file SBNDThermalNoiseServiceInFreq.h.

double SBNDThermalNoiseServiceInFreq::fNoiseRand
private

fraction of random "wiggle" in noise in freq. spectrum

Definition at line 76 of file SBNDThermalNoiseServiceInFreq.h.

double SBNDThermalNoiseServiceInFreq::fNoiseWidth
private

exponential noise width (kHz)

Definition at line 75 of file SBNDThermalNoiseServiceInFreq.h.

int SBNDThermalNoiseServiceInFreq::fRandomSeed
private

Seed for random number service. If absent or zero, use SeedSvc.

Definition at line 71 of file SBNDThermalNoiseServiceInFreq.h.

double SBNDThermalNoiseServiceInFreq::fSampleRate
private

Definition at line 74 of file SBNDThermalNoiseServiceInFreq.h.

std::map< double, int > SBNDThermalNoiseServiceInFreq::fShapingTimeOrder
private

Definition at line 73 of file SBNDThermalNoiseServiceInFreq.h.

CLHEP::HepRandomEngine* SBNDThermalNoiseServiceInFreq::m_pran
private

Definition at line 80 of file SBNDThermalNoiseServiceInFreq.h.


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