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"
15 #include "art_root_io/TFileService.h"
18 #include "nurandom/RandomUtils/NuRandomService.h"
20 #include "icarus_signal_processing/WaveformTools.h"
23 #include "CLHEP/Random/RandFlat.h"
24 #include "CLHEP/Random/RandGeneral.h"
25 #include "CLHEP/Random/RandGaussQ.h"
32 #include <unsupported/Eigen/FFT>
42 explicit Overlay1D(
const fhicl::ParameterSet& pset);
46 void configure(
const fhicl::ParameterSet& pset)
override;
51 CLHEP::HepRandomEngine& cornoise_engine,
54 unsigned int wire)
override;
77 using WaveformTools = icarus_signal_processing::WaveformTools<icarusutil::SigProcPrecision>;
129 fPlane = pset.get<
size_t >(
"Plane");
142 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataForJob();
143 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataForJob(clockData);
147 std::string fullFileName;
148 std::string corrAmpFileName;
150 cet::search_path searchPath(
"FW_SEARCH_PATH");
151 searchPath.find_file(fInputNoiseHistFileName, fullFileName);
153 TFile inputFile(fullFileName.c_str(),
"READ");
155 if (!inputFile.IsOpen())
156 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to open input file: " << fInputNoiseHistFileName << std::endl;
158 TH1D* histPtr = (TH1D*)inputFile.Get(fHistogramName.c_str());
161 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to recover desired histogram: " << fHistogramName << std::endl;
167 searchPath.find_file(fCorrAmpHistFileName, corrAmpFileName);
169 TFile corrAmpInputFile(corrAmpFileName.c_str(),
"READ");
171 if (!corrAmpInputFile.IsOpen())
172 throw cet::exception(
"Overlay1D::configure") <<
"Unable to open input file: " << fCorrAmpHistFileName << std::endl;
174 TH1D* corrAmpHistPtr = (TH1D*)corrAmpInputFile.Get(fCorrAmpHistogramName.c_str());
177 throw cet::exception(
"Overlay1D::configure") <<
"Unable to recover desired histogram: " << fCorrAmpHistogramName << std::endl;
180 corrAmpInputFile.Close();
186 for(
size_t histIdx = 0; histIdx < size_t(histPtr->GetNbinsX()); histIdx++)
189 for(
size_t histIdx = 0; histIdx < size_t(corrAmpHistPtr->GetNbinsX()); histIdx++)
196 art::ServiceHandle<art::TFileService>
tfs;
198 art::TFileDirectory* histDirectory = tfs.get();
201 art::TFileDirectory
dir = histDirectory->mkdir(Form(
"CorNoisePlane%1zu",
fPlane));
204 float readOutSize =
detProp.ReadOutWindowSize();
205 float maxFreq = 1.e6 / (2. * sampleRate);
206 float minFreq = 1.e6 / (2. * sampleRate * readOutSize);
207 int numSamples = readOutSize / 2;
209 fInputNoiseHist = dir.make<TProfile>(
"InNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);
210 fMedianNoiseHist = dir.make<TProfile>(
"MedNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);;
211 fPeakNoiseHist = dir.make<TProfile>(
"PeakNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);;
228 CLHEP::HepRandomEngine& engine_corr,
231 unsigned int channel)
243 int board=channel/32;
249 std::transform(noise_unc.begin(),noise_unc.end(),noise_corr.begin(),noise.begin(),std::plus<float>());
266 CLHEP::RandFlat noiseGen(engine,0,1);
268 std::function<void (double[])> randGenFunc = [&noiseGen](
double randArray[]){noiseGen.fireArray(2,randArray);};
279 double rnd_corr[2] = {0.,0.};
282 for(
size_t i=0; i< noise.size()/2; ++i)
288 double phase = rnd_corr[1] * 2. * M_PI;
290 std::complex<double> tc(pval*cos(phase),pval*sin(phase));
304 std::vector<float> dHeight;
310 for(
size_t histIdx = 1; histIdx <
fNoiseHistVec.size(); histIdx++) {
314 for(
size_t histIdx = 1; histIdx <
fNoiseHistVec.size(); histIdx++)
315 if(dHeight[histIdx]>dThr&&dHeight[histIdx+1]<dThr&&histIdx>5)
fCoherentNoiseVec[histIdx]=1;
338 icarusutil::TimeVec::iterator maxItr = std::max_element(peakVec.begin(),peakVec.end());
340 float maxPeak = *maxItr;
341 float threshold = std::min(0.1 * maxPeak, 20.);
346 auto const samplingRate =
sampling_rate(art::ServiceHandle<detinfo::DetectorClocksService>()->DataForJob());
347 for(
size_t idx = 0; idx < peakVec.size(); idx++)
364 std::function<void (double[])> randGenFunc = [](
double randArray[]){randArray[0]=0.5; randArray[1]=0.5;};
367 float scaleFactor = 1.;
378 fWaveformTool.getTruncatedMean(waveNoise, mean, nTrunc, range);
384 fWaveformTool.getTruncatedMean(waveNoise, mean, nTrunc, range);
399 amp_corr.setTheSeed(board+1);
400 double rnd_corr[1] = {0.};
402 amp_corr.fireArray(1,rnd_corr);
404 float cfmedio=0.2287;
405 corrFactor=rnd_corr[0]/cfmedio;
Utilities related to art service access.
std::vector< ComplexVal > FrequencyVec
This is the interface class for a tool to handle a GenNoise for the overall response.
std::vector< SigProcPrecision > TimeVec
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
art::ServiceHandle< art::TFileService > tfs
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.