All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
icarus_tool::NoiseFromHist Class Reference
Inheritance diagram for icarus_tool::NoiseFromHist:
icarus_tool::IGenNoise

Public Member Functions

 NoiseFromHist (const fhicl::ParameterSet &pset)
 
 ~NoiseFromHist ()
 
void configure (const fhicl::ParameterSet &pset) override
 
void nextEvent () override
 
void generateNoise (CLHEP::HepRandomEngine &, CLHEP::HepRandomEngine &, icarusutil::TimeVec &, detinfo::DetectorPropertiesData const &, double, const geo::PlaneID &, unsigned int) override
 

Private Attributes

double fNoiseRand
 
std::string fInputNoiseHistFileName
 
std::string fHistogramName
 
double fHistNormFactor
 
std::vector< double > fNoiseHistVec
 
std::unique_ptr
< icarus_signal_processing::ICARUSFFT
< double > > 
fFFT
 

Additional Inherited Members

- Private Member Functions inherited from icarus_tool::IGenNoise
virtual ~IGenNoise () noexcept=default
 

Detailed Description

Definition at line 36 of file NoiseFromHist_tool.cc.

Constructor & Destructor Documentation

icarus_tool::NoiseFromHist::NoiseFromHist ( const fhicl::ParameterSet &  pset)
explicit

Definition at line 72 of file NoiseFromHist_tool.cc.

73 {
74  configure(pset);
75 }
void configure(const fhicl::ParameterSet &pset) override
icarus_tool::NoiseFromHist::~NoiseFromHist ( )

Definition at line 77 of file NoiseFromHist_tool.cc.

78 {
79 }

Member Function Documentation

void icarus_tool::NoiseFromHist::configure ( const fhicl::ParameterSet &  pset)
overridevirtual

Implements icarus_tool::IGenNoise.

Definition at line 81 of file NoiseFromHist_tool.cc.

82 {
83  // Recover the histogram used for noise generation
84  fNoiseRand = pset.get< double>("NoiseRand");
85  fInputNoiseHistFileName = pset.get<std::string>("NoiseHistFileName");
86  fHistogramName = pset.get<std::string>("HistogramName");
87  fHistNormFactor = pset.get<double>("HistNormFactor");
88 
89  std::string fullFileName;
90  cet::search_path searchPath("FW_SEARCH_PATH");
91  searchPath.find_file(fInputNoiseHistFileName, fullFileName);
92 
93  TFile inputFile(fullFileName.c_str(), "READ");
94 
95  if (!inputFile.IsOpen())
96  throw cet::exception("NoiseFromHist::configure") << "Unable to open input file: " << fInputNoiseHistFileName << std::endl;
97 
98  TH1D* histPtr = (TH1D*)inputFile.Get(fHistogramName.c_str());
99 
100  if (!histPtr)
101  throw cet::exception("NoiseFromHist::configure") << "Unable to recover desired histogram: " << fHistogramName << std::endl;
102 
103  fNoiseHistVec.resize(histPtr->GetNbinsX(), 0.);
104 
105  for(size_t histIdx = 0; histIdx < size_t(histPtr->GetNbinsX()); histIdx++)
106  fNoiseHistVec[histIdx] = histPtr->GetBinContent(histIdx+1);
107 
108  // Close the input file
109  inputFile.Close();
110 
111  // Now set up our plans for doing the convolution
112  auto const clockData = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
113  int numberTimeSamples = clockData.NumberTimeSamples();
114 
115  fFFT = std::make_unique<icarus_signal_processing::ICARUSFFT<double>>(numberTimeSamples);
116 
117  return;
118 }
std::vector< double > fNoiseHistVec
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
void icarus_tool::NoiseFromHist::generateNoise ( CLHEP::HepRandomEngine &  engine,
CLHEP::HepRandomEngine &  ,
icarusutil::TimeVec noise,
detinfo::DetectorPropertiesData const &  detProp,
double  noise_factor,
const geo::PlaneID planeID,
unsigned int  board 
)
overridevirtual

Implements icarus_tool::IGenNoise.

Definition at line 120 of file NoiseFromHist_tool.cc.

127 {
128  CLHEP::RandFlat flat(engine,-1,1);
129 
130  size_t nFFTTicks = detProp.NumberTimeSamples();
131 
132  if(noise.size() != nFFTTicks)
133  throw cet::exception("SimWireICARUS")
134  << "\033[93m"
135  << "Frequency noise vector length must match FFT Ticks (FFT size)"
136  << " ... " << noise.size() << " != " << nFFTTicks
137  << "\033[00m"
138  << std::endl;
139 
140  // noise in frequency space
141  std::vector<std::complex<double>> noiseFrequency(nFFTTicks/2+1, 0.);
142 
143  double pval = 0.;
144  double phase = 0.;
145  double rnd[2] = {0.};
146  double scaleFactor = fHistNormFactor * noise_factor;
147 
148  // width of frequencyBin in kHz
149 
150  for(size_t i=0; i< nFFTTicks/2 + 1; ++i)
151  {
152  // exponential noise spectrum
153  flat.fireArray(2,rnd,0,1);
154 
155  pval = fNoiseHistVec[i] * ((1-fNoiseRand) + 2 * fNoiseRand*rnd[0]) * scaleFactor;
156 
157  phase = rnd[1] * 2. * M_PI;
158 
159  std::complex<double> tc(pval*cos(phase),pval*sin(phase));
160 
161  noiseFrequency.at(i) += tc;
162  }
163 
164  // inverse FFT MCSignal
165  fFFT->inverseFFT(noiseFrequency, noise);
166 
167  noiseFrequency.clear();
168 
169  return;
170 }
std::vector< double > fNoiseHistVec
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
auto const detProp
void icarus_tool::NoiseFromHist::nextEvent ( )
inlineoverridevirtual

Implements icarus_tool::IGenNoise.

Definition at line 45 of file NoiseFromHist_tool.cc.

45 {return;};

Member Data Documentation

std::unique_ptr<icarus_signal_processing::ICARUSFFT<double> > icarus_tool::NoiseFromHist::fFFT
private

Definition at line 67 of file NoiseFromHist_tool.cc.

double icarus_tool::NoiseFromHist::fHistNormFactor
private

Definition at line 61 of file NoiseFromHist_tool.cc.

std::string icarus_tool::NoiseFromHist::fHistogramName
private

Definition at line 59 of file NoiseFromHist_tool.cc.

std::string icarus_tool::NoiseFromHist::fInputNoiseHistFileName
private

Definition at line 58 of file NoiseFromHist_tool.cc.

std::vector<double> icarus_tool::NoiseFromHist::fNoiseHistVec
private

Definition at line 65 of file NoiseFromHist_tool.cc.

double icarus_tool::NoiseFromHist::fNoiseRand
private

Definition at line 57 of file NoiseFromHist_tool.cc.


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