8 #include "art/Framework/Core/EDProducer.h"
9 #include "art/Utilities/ToolMacros.h"
10 #include "art/Utilities/make_tool.h"
11 #include "messagefacility/MessageLogger/MessageLogger.h"
12 #include "cetlib_except/exception.h"
16 #include "art_root_io/TFileService.h"
19 #include "nurandom/RandomUtils/NuRandomService.h"
21 #include "icarus_signal_processing/WaveformTools.h"
24 #include "CLHEP/Random/RandFlat.h"
25 #include "CLHEP/Random/RandGeneral.h"
26 #include "CLHEP/Random/RandGaussQ.h"
33 #include <unsupported/Eigen/FFT>
47 void configure(
const fhicl::ParameterSet& pset)
override;
52 CLHEP::HepRandomEngine& cornoise_engine,
57 unsigned int)
override;
81 using WaveformTools = icarus_signal_processing::WaveformTools<icarusutil::SigProcPrecision>;
132 fPlane = pset.get<
size_t >(
"Plane");
145 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
149 std::string fullFileName;
150 std::string corrAmpFileName;
152 cet::search_path searchPath(
"FW_SEARCH_PATH");
153 searchPath.find_file(fInputNoiseHistFileName, fullFileName);
155 TFile inputFile(fullFileName.c_str(),
"READ");
157 if (!inputFile.IsOpen())
158 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to open input file: " << fInputNoiseHistFileName << std::endl;
160 TH1D* histPtr = (TH1D*)inputFile.Get(fHistogramName.c_str());
163 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to recover desired histogram: " << fHistogramName << std::endl;
169 searchPath.find_file(fCorrAmpHistFileName, corrAmpFileName);
171 TFile corrAmpInputFile(corrAmpFileName.c_str(),
"READ");
173 if (!corrAmpInputFile.IsOpen())
174 throw cet::exception(
"CorrelatedNoise::configure") <<
"Unable to open input file: " << fCorrAmpHistFileName << std::endl;
176 TH1D* corrAmpHistPtr = (TH1D*)corrAmpInputFile.Get(fCorrAmpHistogramName.c_str());
179 throw cet::exception(
"CorrelatedNoise::configure") <<
"Unable to recover desired histogram: " << fCorrAmpHistogramName << std::endl;
182 corrAmpInputFile.Close();
188 for(
size_t histIdx = 0; histIdx < size_t(histPtr->GetNbinsX()); histIdx++)
191 for(
size_t histIdx = 0; histIdx < size_t(corrAmpHistPtr->GetNbinsX()); histIdx++)
198 art::ServiceHandle<art::TFileService>
tfs;
200 art::TFileDirectory* histDirectory = tfs.get();
203 art::TFileDirectory
dir = histDirectory->mkdir(Form(
"CorNoisePlane%1zu",
fPlane));
205 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
207 float readOutSize = detProp.ReadOutWindowSize();
208 float maxFreq = 1.e6 / (2. * sampleRate);
209 float minFreq = 1.e6 / (2. * sampleRate * readOutSize);
210 int numSamples = readOutSize / 2;
212 fInputNoiseHist = dir.make<TProfile>(
"InNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);
213 fMedianNoiseHist = dir.make<TProfile>(
"MedNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);;
214 fPeakNoiseHist = dir.make<TProfile>(
"PeakNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);;
231 CLHEP::HepRandomEngine& engine_corr,
254 std::transform(noise_unc.begin(),noise_unc.end(),noise_corr.begin(),noise.begin(),std::plus<float>());
271 CLHEP::RandFlat noiseGen(engine,0,1);
273 std::function<void (double[])> randGenFunc = [&noiseGen](
double randArray[]){noiseGen.fireArray(2,randArray);};
296 CLHEP::RandFlat noiseGen(engine,0,1);
298 std::function<void (double[])> randGenFunc = [&noiseGen](
double randArray[]){noiseGen.fireArray(2,randArray);};
312 double rnd_corr[2] = {0.,0.};
315 for(
size_t i=0; i< noise.size()/2; ++i)
321 double phase = rnd_corr[1] * 2. * M_PI;
323 std::complex<double> tc(pval*cos(phase),pval*sin(phase));
337 std::vector<float> dHeight;
343 for(
size_t histIdx = 1; histIdx <
fNoiseHistVec.size(); histIdx++) {
347 for(
size_t histIdx = 1; histIdx <
fNoiseHistVec.size(); histIdx++)
348 if(dHeight[histIdx]>dThr&&dHeight[histIdx+1]<dThr&&histIdx>5)
fCoherentNoiseVec[histIdx]=1;
371 icarusutil::TimeVec::iterator maxItr = std::max_element(peakVec.begin(),peakVec.end());
373 float maxPeak = *maxItr;
374 float threshold = std::min(0.1 * maxPeak, 20.);
379 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
381 for(
size_t idx = 0; idx < peakVec.size(); idx++)
398 std::function<void (double[])> randGenFunc = [](
double randArray[]){randArray[0]=0.5; randArray[1]=0.5;};
401 float scaleFactor = 1.;
412 fWaveformTool.getTruncatedMean(waveNoise, mean, nTrunc, range);
418 fWaveformTool.getTruncatedMean(waveNoise, mean, nTrunc, range);
433 amp_corr.setTheSeed(board+1);
434 double rnd_corr[1] = {0.};
436 amp_corr.fireArray(1,rnd_corr);
438 float cfmedio=0.2287;
439 corrFactor=rnd_corr[0]/cfmedio;
Utilities related to art service access.
The data type to uniquely identify a Plane.
std::vector< ComplexVal > FrequencyVec
std::vector< SigProcPrecision > TimeVec
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
This is the interface class for a tool to handle a GenNoise for the overall response.
art::ServiceHandle< art::TFileService > tfs
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.