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

Public Member Functions

 SBNDataNoiseBoard (const fhicl::ParameterSet &pset)
 
 ~SBNDataNoiseBoard ()
 
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 Types

using WaveformTools = icarus_signal_processing::WaveformTools< icarusutil::SigProcPrecision >
 
using BoardToNoiseVecMap = std::unordered_map< unsigned int, icarusutil::TimeVec >
 
using BoardToHistMap = std::unordered_map< unsigned int, TH1D * >
 

Private Member Functions

void GenerateCorrelatedNoise (CLHEP::HepRandomEngine &, icarusutil::TimeVec &, double, unsigned int)
 
void GenerateUncorrelatedNoise (CLHEP::HepRandomEngine &, icarusutil::TimeVec &, double, unsigned int)
 
void GenNoise (std::function< void(double[])> &, const icarusutil::TimeVec &, icarusutil::TimeVec &, float)
 
void ComputeRMSs ()
 
void makeHistograms ()
 
void SampleCorrelatedRMSs ()
 
void ExtractUncorrelatedRMS (float &, int, int) const
 
void makeBoardHistos (unsigned int)
 
- Private Member Functions inherited from icarus_tool::IGenNoise
virtual ~IGenNoise () noexcept=default
 

Private Attributes

size_t fPlane
 
int fMedianNumBins
 
float fNoiseRand
 
long fCorrelatedSeed
 
long fUncorrelatedSeed
 
std::vector< float > fIncoherentNoiseFrac
 
bool fStoreHistograms
 
std::string fInputNoiseHistFileName
 
std::string fHistogramName
 
std::string fCorrelatedHistogramName
 
std::string fUncorrelatedHistogramName
 
std::string fCorrelatedRMSHistoName
 
std::string fUncorrelatedRMSHistoName
 
std::string fTotalRMSHistoName
 
WaveformTools fWaveformTool
 
BoardToNoiseVecMap fCoherentBoardToNoiseVecMap
 
BoardToNoiseVecMap fIncoherentBoardToNoiseVecMap
 
std::vector< icarusutil::TimeVecfCoherentNoiseVec
 
std::vector< icarusutil::TimeVecfIncoherentNoiseVec
 
icarusutil::FrequencyVec fNoiseFrequencyVec
 
bool fNeedFirstSeed =true
 
TProfile * fInputNoiseHist
 
TH1D * fMediaNoiseHist
 
TProfile * fPeakNoiseHist
 
TFile * fHistogramFile
 
std::vector< float > totalRMS
 
std::vector< float > rmsUnc
 
std::vector< float > rmsCorr
 
Eigen::FFT< double > fEigenFFT
 

Detailed Description

Definition at line 41 of file SBNDataNoiseBoard_tool.cc.

Member Typedef Documentation

using icarus_tool::SBNDataNoiseBoard::BoardToHistMap = std::unordered_map<unsigned int, TH1D*>
private

Definition at line 100 of file SBNDataNoiseBoard_tool.cc.

using icarus_tool::SBNDataNoiseBoard::BoardToNoiseVecMap = std::unordered_map<unsigned int, icarusutil::TimeVec>
private

Definition at line 92 of file SBNDataNoiseBoard_tool.cc.

using icarus_tool::SBNDataNoiseBoard::WaveformTools = icarus_signal_processing::WaveformTools<icarusutil::SigProcPrecision>
private

Definition at line 86 of file SBNDataNoiseBoard_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 126 of file SBNDataNoiseBoard_tool.cc.

127 {
128  // Recover the configuration of the tool from the input fhicl file and set up
129  configure(pset);
130  ComputeRMSs();
131 
132  // Output some histograms to catalogue what's been done
133  makeHistograms();
134  std::cout << " after making histos " << std::endl;
135 }
void configure(const fhicl::ParameterSet &pset) override
BEGIN_PROLOG could also be cout
icarus_tool::SBNDataNoiseBoard::~SBNDataNoiseBoard ( )

Definition at line 137 of file SBNDataNoiseBoard_tool.cc.

138 {
139  // Close the input file
140  fHistogramFile->Close();
141 }

Member Function Documentation

void icarus_tool::SBNDataNoiseBoard::ComputeRMSs ( )
private

Definition at line 360 of file SBNDataNoiseBoard_tool.cc.

361 {
362 
363 
364 }
void icarus_tool::SBNDataNoiseBoard::configure ( const fhicl::ParameterSet &  pset)
overridevirtual

Implements icarus_tool::IGenNoise.

Definition at line 143 of file SBNDataNoiseBoard_tool.cc.

144 {
145 std::cout << " configuring tool " << std::endl;
146  // Recover the histogram used for noise generation
147  fPlane = pset.get< size_t >("Plane");
148  fMedianNumBins = pset.get< int >("MedianNumBins");
149  fNoiseRand = pset.get< float >("NoiseRand");
150  fCorrelatedSeed = pset.get< long >("CorrelatedSeed",1000);
151  fUncorrelatedSeed = pset.get< long >("UncorrelatedSeed",5000);
152  std::vector<float> noiseFracVec = pset.get< std::vector<float> >("IncoherentNoiseFraction", std::vector<float>());
153  fStoreHistograms = pset.get< bool >("StoreHistograms");
154  fInputNoiseHistFileName = pset.get< std::string >("NoiseHistFileName");
155  fCorrelatedHistogramName = pset.get< std::string >("CorrelatedHistogramName");
156  fUncorrelatedHistogramName = pset.get< std::string >("UncorrelatedHistogramName");
157  fCorrelatedRMSHistoName = pset.get< std::string >("CorrelatedRMSHistoName");
158  fUncorrelatedRMSHistoName = pset.get< std::string >("UncorrelatedRMSHistoName");
159  fTotalRMSHistoName = pset.get< std::string >("TotalRMSHistoName");
160 
161  for(auto& noiseFrac : noiseFracVec) {
162  fIncoherentNoiseFrac.push_back(float(noiseFrac));
163  }
164 
165  std::string fullFileName;
166 
167  cet::search_path searchPath("FW_SEARCH_PATH");
168 
169  searchPath.find_file(fInputNoiseHistFileName, fullFileName);
170 
171  fHistogramFile = TFile::Open(fullFileName.c_str(), "READ");
172 
173  if (!fHistogramFile->IsOpen())
174  throw cet::exception("NoiseFromHist::configure") << "Unable to open input file: " << fInputNoiseHistFileName << std::endl;
175 
176  std::cout << " end configuring tool " << std::endl;
177  return;
178 }
BEGIN_PROLOG could also be cout
void icarus_tool::SBNDataNoiseBoard::ExtractUncorrelatedRMS ( float &  cf,
int  channel,
int  index 
) const
private

Definition at line 369 of file SBNDataNoiseBoard_tool.cc.

370 {
371 }
void icarus_tool::SBNDataNoiseBoard::GenerateCorrelatedNoise ( CLHEP::HepRandomEngine &  engine,
icarusutil::TimeVec noise,
double  noise_factor,
unsigned int  board 
)
private

Definition at line 310 of file SBNDataNoiseBoard_tool.cc.

311 {
312 
313  // Set the engine seed to the board being considered
314  engine.setSeed(fCorrelatedSeed+board,0);
315 
316  CLHEP::RandFlat noiseGen(engine,0,1);
317 
318  std::function<void (double[])> randGenFunc = [&noiseGen](double randArray[]){noiseGen.fireArray(2,randArray);};
319 
320  GenNoise(randGenFunc, fCoherentBoardToNoiseVecMap[board], noise, noise_factor);
321 
322  return;
323 }
void GenNoise(std::function< void(double[])> &, const icarusutil::TimeVec &, icarusutil::TimeVec &, float)
BoardToNoiseVecMap fCoherentBoardToNoiseVecMap
void icarus_tool::SBNDataNoiseBoard::generateNoise ( CLHEP::HepRandomEngine &  engine_unc,
CLHEP::HepRandomEngine &  engine_corr,
icarusutil::TimeVec noise,
detinfo::DetectorPropertiesData const &  ,
double  noise_factor,
const geo::PlaneID planeID,
unsigned int  board 
)
overridevirtual

Implements icarus_tool::IGenNoise.

Definition at line 243 of file SBNDataNoiseBoard_tool.cc.

250 {
251  makeBoardHistos(board);
252 
253  //std::cout << " generating noise channel " << channel << std::endl;
254  //GET THE GEOMETRY.
255  art::ServiceHandle<geo::Geometry> geom;
256 
257  // We need to know the plane to look up parameters
258 // size_t cryostat=planeID.Cryostat;
259 // size_t tpc=planeID.TPC;
260 
261  //std::cout << " index " << index << " generating noise totalRMS " << totalRMS[index] << std::endl;
262  // Define a couple of vectors to hold intermediate work
263  icarusutil::TimeVec noise_unc(noise.size(),0.);
264  icarusutil::TimeVec noise_corr(noise.size(),0.);
265 
266  // Make sure the work vector is size right with the output
267  if (fNoiseFrequencyVec.size() != noise.size()) fNoiseFrequencyVec.resize(noise.size(),std::complex<float>(0.,0.));
268 
269  // If applying incoherent noise call the generator
270  GenerateUncorrelatedNoise(engine_unc,noise_unc,noise_factor, board);
271 
272  GenerateCorrelatedNoise(engine_corr, noise_corr, noise_factor, board);
273 
274  // std::cout << " summing noise " << std::endl;
275  // Take the noise as the simple sum of the two contributions
276  std::transform(noise_unc.begin(),noise_unc.end(),noise_corr.begin(),noise.begin(),std::plus<float>());
277 
278 // float mediaNoise=0;
279 // for(unsigned int jn=0;jn<noise.size();jn++) mediaNoise+=noise.at(jn);
280 
281 // mediaNoise/=(noise.size());
282 
283  //std::cout << " media noise size " << noise.size() << std::endl;
284  //fMediaNoiseHist->Fill(mediaNoise);
285  //std::cout << " media noise " << mediaNoise << std::endl;
286  return;
287 }
static constexpr Sample_t transform(Sample_t sample)
void GenerateUncorrelatedNoise(CLHEP::HepRandomEngine &, icarusutil::TimeVec &, double, unsigned int)
std::vector< SigProcPrecision > TimeVec
icarusutil::FrequencyVec fNoiseFrequencyVec
void GenerateCorrelatedNoise(CLHEP::HepRandomEngine &, icarusutil::TimeVec &, double, unsigned int)
void icarus_tool::SBNDataNoiseBoard::GenerateUncorrelatedNoise ( CLHEP::HepRandomEngine &  engine,
icarusutil::TimeVec noise,
double  noise_factor,
unsigned int  board 
)
private

Definition at line 289 of file SBNDataNoiseBoard_tool.cc.

290 {
291  // Here we aim to produce a waveform consisting of incoherent noise
292  // Note that this is expected to be the dominate noise contribution
293  // Check for seed initialization
294  if (fNeedFirstSeed)
295  {
296  engine.setSeed(fUncorrelatedSeed,0);
297  fNeedFirstSeed = false;
298  }
299 
300  // Get the generator
301  CLHEP::RandFlat noiseGen(engine,0,1);
302 
303  std::function<void (double[])> randGenFunc = [&noiseGen](double randArray[]){noiseGen.fireArray(2,randArray);};
304 
305  GenNoise(randGenFunc, fIncoherentBoardToNoiseVecMap[board], noise, noise_factor);
306 
307  return;
308 }
BoardToNoiseVecMap fIncoherentBoardToNoiseVecMap
void GenNoise(std::function< void(double[])> &, const icarusutil::TimeVec &, icarusutil::TimeVec &, float)
void icarus_tool::SBNDataNoiseBoard::GenNoise ( std::function< void(double[])> &  gen,
const icarusutil::TimeVec freqDist,
icarusutil::TimeVec noise,
float  scaleFactor 
)
private

Definition at line 325 of file SBNDataNoiseBoard_tool.cc.

326 {
327  double rnd_corr[2] = {0.,0.};
328  // std::cout << " noise size " << noise.size() << std::endl;
329  // Build out the frequency vector
330  for(size_t i=0; i< noise.size()/2; ++i)
331  {
332  //std::cout << " i " << i << " freqdist " << freqDist[i] << std::endl;
333  // exponential noise spectrum
334  gen(rnd_corr);
335  // if(i!=10) continue;
336  float pval = freqDist[i] * ((1-fNoiseRand) + 2 * fNoiseRand*rnd_corr[0]) * scaleFactor;
337  float phase = rnd_corr[1] * 2. * M_PI;
338  // float pval = freqDist[i]*scaleFactor ;
339  // float phase = 0;
340  std::complex<float> tc(pval*cos(phase),pval*sin(phase));
341 
342  fNoiseFrequencyVec[i] = tc;
343  //std::cout << " i " << i << " noise freqvec " << fNoiseFrequencyVec[i] << std::endl;
344  }
345 
346  // inverse FFT MCSignal
347  fEigenFFT.inv(noise, fNoiseFrequencyVec);
348  // for(unsigned int jn=0;jn<noise.size();jn++) std::cout << " jn " << jn << " noise sum " << noise.at(jn) << std::endl;
349  //exit(22);
350  //std::cout << " end gen noise " << std::endl;
351  return;
352 }
icarusutil::FrequencyVec fNoiseFrequencyVec
void icarus_tool::SBNDataNoiseBoard::makeBoardHistos ( unsigned int  board)
private

Definition at line 180 of file SBNDataNoiseBoard_tool.cc.

181 {
183  {
184 
185  TH1D* corrHistPtr = (TH1D*)fHistogramFile->Get((fCorrelatedHistogramName+std::to_string(board)).c_str());
186  if (!corrHistPtr)
187  throw cet::exception("NoiseFromHist::configure") << "Unable to recover desired histogram: " << fCorrelatedHistogramName+std::to_string(board) << std::endl;
188 
190 
191  noiseVec.resize(corrHistPtr->GetNbinsX(),0.);
192  for(size_t histIdx = 0; histIdx < size_t(corrHistPtr->GetNbinsX()); histIdx++) noiseVec[histIdx] = corrHistPtr->GetBinContent(histIdx+1);
193  }
194 
196  {
197  TH1D* uncorrHistPtr = (TH1D*)fHistogramFile->Get((fUncorrelatedHistogramName+std::to_string(board)).c_str());
198  if (!uncorrHistPtr)
199  throw cet::exception("NoiseFromHist::configure") << "Unable to recover desired histogram: " << fUncorrelatedHistogramName << std::endl;
200 
202 
203  noiseVec.resize(uncorrHistPtr->GetNbinsX(),0.);
204  for(size_t histIdx = 0; histIdx < size_t(uncorrHistPtr->GetNbinsX()); histIdx++) noiseVec[histIdx] = uncorrHistPtr->GetBinContent(histIdx+1);
205  }
206 
207  // Should we store hists?
208  if (fStoreHistograms)
209  {
210  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
211  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
212 
213  // Define histograms
214  art::ServiceHandle<art::TFileService> tfs;
215 
216  art::TFileDirectory* histDirectory = tfs.get();
217 
218  // Make a directory for these histograms
219  art::TFileDirectory dir = histDirectory->mkdir(Form("CorNoisePlane%1zu",fPlane));
220 
221  float sampleRate = sampling_rate(clockData);
222  float readOutSize = detProp.ReadOutWindowSize();
223  float maxFreq = 1.e6 / (2. * sampleRate);
224  float minFreq = 1.e6 / (2. * sampleRate * readOutSize);
225  int numSamples = readOutSize / 2;
226 
227  fInputNoiseHist = dir.make<TProfile>("InNoise", ";freq(kHz)", numSamples, minFreq, maxFreq);
228  fMediaNoiseHist = dir.make<TH1D>("MedNoise", ";ADC", 100, -10., -10.);;
229  fPeakNoiseHist = dir.make<TProfile>("PeakNoise", ";freq(kHz)", numSamples, minFreq, maxFreq);;
230  }
231  //SampleCorrelatedRMSs();
232 }
BoardToNoiseVecMap fIncoherentBoardToNoiseVecMap
std::vector< SigProcPrecision > TimeVec
tuple dir
Definition: dropbox.py:28
BoardToNoiseVecMap fCoherentBoardToNoiseVecMap
std::string to_string(WindowPattern const &pattern)
art::ServiceHandle< art::TFileService > tfs
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
auto const detProp
void icarus_tool::SBNDataNoiseBoard::makeHistograms ( )
private

Definition at line 354 of file SBNDataNoiseBoard_tool.cc.

355 {
356 
357  return;
358 }
void icarus_tool::SBNDataNoiseBoard::nextEvent ( )
overridevirtual

Implements icarus_tool::IGenNoise.

Definition at line 234 of file SBNDataNoiseBoard_tool.cc.

235 {
236  // We update the correlated seed because we want to see different noise event-by-event
237  fCorrelatedSeed = (333 * fCorrelatedSeed) % 900000000;
239 
240  return;
241 }
void icarus_tool::SBNDataNoiseBoard::SampleCorrelatedRMSs ( )
private

Definition at line 365 of file SBNDataNoiseBoard_tool.cc.

366 {
367 
368 }

Member Data Documentation

BoardToNoiseVecMap icarus_tool::SBNDataNoiseBoard::fCoherentBoardToNoiseVecMap
private

Definition at line 94 of file SBNDataNoiseBoard_tool.cc.

std::vector<icarusutil::TimeVec> icarus_tool::SBNDataNoiseBoard::fCoherentNoiseVec
private

Definition at line 97 of file SBNDataNoiseBoard_tool.cc.

std::string icarus_tool::SBNDataNoiseBoard::fCorrelatedHistogramName
private

Definition at line 80 of file SBNDataNoiseBoard_tool.cc.

std::string icarus_tool::SBNDataNoiseBoard::fCorrelatedRMSHistoName
private

Definition at line 82 of file SBNDataNoiseBoard_tool.cc.

long icarus_tool::SBNDataNoiseBoard::fCorrelatedSeed
private

Definition at line 74 of file SBNDataNoiseBoard_tool.cc.

Eigen::FFT<double> icarus_tool::SBNDataNoiseBoard::fEigenFFT
private

Definition at line 120 of file SBNDataNoiseBoard_tool.cc.

TFile* icarus_tool::SBNDataNoiseBoard::fHistogramFile
private

Definition at line 113 of file SBNDataNoiseBoard_tool.cc.

std::string icarus_tool::SBNDataNoiseBoard::fHistogramName
private

Definition at line 79 of file SBNDataNoiseBoard_tool.cc.

BoardToNoiseVecMap icarus_tool::SBNDataNoiseBoard::fIncoherentBoardToNoiseVecMap
private

Definition at line 95 of file SBNDataNoiseBoard_tool.cc.

std::vector<float> icarus_tool::SBNDataNoiseBoard::fIncoherentNoiseFrac
private

Definition at line 76 of file SBNDataNoiseBoard_tool.cc.

std::vector<icarusutil::TimeVec> icarus_tool::SBNDataNoiseBoard::fIncoherentNoiseVec
private

Definition at line 98 of file SBNDataNoiseBoard_tool.cc.

TProfile* icarus_tool::SBNDataNoiseBoard::fInputNoiseHist
private

Definition at line 109 of file SBNDataNoiseBoard_tool.cc.

std::string icarus_tool::SBNDataNoiseBoard::fInputNoiseHistFileName
private

Definition at line 78 of file SBNDataNoiseBoard_tool.cc.

int icarus_tool::SBNDataNoiseBoard::fMedianNumBins
private

Definition at line 72 of file SBNDataNoiseBoard_tool.cc.

TH1D* icarus_tool::SBNDataNoiseBoard::fMediaNoiseHist
private

Definition at line 110 of file SBNDataNoiseBoard_tool.cc.

bool icarus_tool::SBNDataNoiseBoard::fNeedFirstSeed =true
private

Definition at line 106 of file SBNDataNoiseBoard_tool.cc.

icarusutil::FrequencyVec icarus_tool::SBNDataNoiseBoard::fNoiseFrequencyVec
private

Definition at line 103 of file SBNDataNoiseBoard_tool.cc.

float icarus_tool::SBNDataNoiseBoard::fNoiseRand
private

Definition at line 73 of file SBNDataNoiseBoard_tool.cc.

TProfile* icarus_tool::SBNDataNoiseBoard::fPeakNoiseHist
private

Definition at line 111 of file SBNDataNoiseBoard_tool.cc.

size_t icarus_tool::SBNDataNoiseBoard::fPlane
private

Definition at line 71 of file SBNDataNoiseBoard_tool.cc.

bool icarus_tool::SBNDataNoiseBoard::fStoreHistograms
private

Definition at line 77 of file SBNDataNoiseBoard_tool.cc.

std::string icarus_tool::SBNDataNoiseBoard::fTotalRMSHistoName
private

Definition at line 84 of file SBNDataNoiseBoard_tool.cc.

std::string icarus_tool::SBNDataNoiseBoard::fUncorrelatedHistogramName
private

Definition at line 81 of file SBNDataNoiseBoard_tool.cc.

std::string icarus_tool::SBNDataNoiseBoard::fUncorrelatedRMSHistoName
private

Definition at line 83 of file SBNDataNoiseBoard_tool.cc.

long icarus_tool::SBNDataNoiseBoard::fUncorrelatedSeed
private

Definition at line 75 of file SBNDataNoiseBoard_tool.cc.

WaveformTools icarus_tool::SBNDataNoiseBoard::fWaveformTool
private

Definition at line 88 of file SBNDataNoiseBoard_tool.cc.

std::vector<float> icarus_tool::SBNDataNoiseBoard::rmsCorr
private

Definition at line 117 of file SBNDataNoiseBoard_tool.cc.

std::vector<float> icarus_tool::SBNDataNoiseBoard::rmsUnc
private

Definition at line 116 of file SBNDataNoiseBoard_tool.cc.

std::vector<float> icarus_tool::SBNDataNoiseBoard::totalRMS
private

Definition at line 115 of file SBNDataNoiseBoard_tool.cc.


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