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"
20 #include "nurandom/RandomUtils/NuRandomService.h"
22 #include "icarus_signal_processing/WaveformTools.h"
27 #include "CLHEP/Random/RandFlat.h"
28 #include "CLHEP/Random/RandGeneral.h"
29 #include "CLHEP/Random/RandGaussQ.h"
36 #include <unsupported/Eigen/FFT>
50 void configure(
const fhicl::ParameterSet& pset)
override;
55 CLHEP::HepRandomEngine& cornoise_engine,
60 unsigned int board)
override;
91 using WaveformTools = icarus_signal_processing::WaveformTools<icarusutil::SigProcPrecision>;
147 fPlane = pset.get<
size_t >(
"Plane");
152 std::vector<float> noiseFracVec = pset.get< std::vector<float> >(
"IncoherentNoiseFraction", std::vector<float>());
153 for(
auto& noiseFrac : noiseFracVec) {
159 std::vector<std::string> noiseToolParamSetVec = pset.get< std::vector<std::string> >(
"NoiseHistFileName", std::vector<std::string>());
160 for(
auto& noiseToolParams : noiseToolParamSetVec) {
170 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
171 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
176 std::string fullFileName;
178 cet::search_path searchPath(
"FW_SEARCH_PATH");
180 searchPath.find_file(
filename, fullFileName);
182 std::cout <<
" fullfilename;" << fullFileName << std::endl;
184 std::cout <<
"uncorrelated histo name: " << fUncorrelatedHistogramName << std::endl;
185 TFile inputFile(fullFileName.c_str(),
"READ");
187 if (!inputFile.IsOpen())
188 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to open input file: " <<
filename << std::endl;
192 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to recover desired histogram: " <<
fCorrelatedHistogramName << std::endl;
194 TH1D* uncorrHistPtr = (TH1D*)inputFile.Get(fUncorrelatedHistogramName.c_str());
195 if (!inputFile.Get(fUncorrelatedHistogramName.c_str()))
196 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to recover desired histogram: " << fUncorrelatedHistogramName << std::endl;
198 corrRMSHistPtr.push_back((TH1D*)inputFile.Get(fCorrelatedRMSHistoName.c_str()));
199 if (!inputFile.Get(fCorrelatedRMSHistoName.c_str()))
200 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to recover desired histogram: " << fCorrelatedRMSHistoName << std::endl;
202 uncorrRMSHistPtr.push_back((TH1D*)inputFile.Get(fUncorrelatedRMSHistoName.c_str()));
203 if (!inputFile.Get(fUncorrelatedRMSHistoName.c_str()))
204 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to recover desired histogram: " << fUncorrelatedRMSHistoName << std::endl;
206 totalRMSHistPtr.push_back((TH1D*)inputFile.Get(fTotalRMSHistoName.c_str()));
207 if (!inputFile.Get(fTotalRMSHistoName.c_str()))
208 throw cet::exception(
"NoiseFromHist::configure") <<
"Unable to recover desired histogram: " << fTotalRMSHistoName << std::endl;
213 std::cout <<
" corr hist nbins " << corrHistPtr->GetNbinsX() << std::endl;
214 std::cout <<
" uncorr hist nbins " << uncorrHistPtr->GetNbinsX() << std::endl;
216 corvec.resize(corrHistPtr->GetNbinsX(), 0.);
219 for(
size_t histIdx = 0; histIdx < size_t(corrHistPtr->GetNbinsX()); histIdx++)
220 corvec[histIdx] = corrHistPtr->GetBinContent(histIdx+1);
223 incvec.resize(uncorrHistPtr->GetNbinsX(), 0.);
226 for(
size_t histIdx = 0; histIdx < size_t(uncorrHistPtr->GetNbinsX()); histIdx++)
227 incvec[histIdx] = uncorrHistPtr->GetBinContent(histIdx+1);
232 std::cout <<
" after filling vectors " << std::endl;
236 art::ServiceHandle<art::TFileService>
tfs;
238 art::TFileDirectory* histDirectory = tfs.get();
241 art::TFileDirectory
dir = histDirectory->mkdir(Form(
"CorNoisePlane%1zu",
fPlane));
244 float readOutSize =
detProp.ReadOutWindowSize();
245 float maxFreq = 1.e6 / (2. * sampleRate);
246 float minFreq = 1.e6 / (2. * sampleRate * readOutSize);
247 int numSamples = readOutSize / 2;
249 fInputNoiseHist = dir.make<TProfile>(
"InNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);
250 fMediaNoiseHist = dir.make<TH1D>(
"MedNoise",
";ADC", 100, -10., -10.);;
251 fPeakNoiseHist = dir.make<TProfile>(
"PeakNoise",
";freq(kHz)", numSamples, minFreq, maxFreq);;
256 const auto& channelMap = art::ServiceHandle<icarusDB::IICARUSChannelMap const>{}.get();
260 for(
const auto& boardPair : readoutBoardToChannelMap)
281 CLHEP::HepRandomEngine& engine_corr,
298 size_t tpc=planeID.
TPC;
302 if(cryostat==0&&tpc<2) index=0;
303 if(cryostat==0&&tpc>1) index=1;
304 if(cryostat==1&&tpc<2) index=2;
305 if(cryostat==1&&tpc>1) index=3;
328 CorrFactorsMap::const_iterator corrFactorItr =
fCorrFactorsMap.find(board);
330 if (corrFactorItr ==
fCorrFactorsMap.end())
std::cout <<
"********************** board " << board <<
" not found in map!" << std::endl;
341 std::transform(noise_unc.begin(),noise_unc.end(),noise_corr.begin(),noise.begin(),std::plus<float>());
344 for(
unsigned int jn=0;jn<noise.size();jn++) {
351 mediaNoise+=noise.at(jn);
354 mediaNoise/=(noise.size());
374 CLHEP::RandFlat noiseGen(engine,0,1);
376 std::function<void (double[])> randGenFunc = [&noiseGen](
double randArray[]){noiseGen.fireArray(2,randArray);};
379 float scaleFactor = cf*noise_factor;
392 CLHEP::RandFlat noiseGen(engine,0,1);
394 std::function<void (double[])> randGenFunc = [&noiseGen](
double randArray[]){noiseGen.fireArray(2,randArray);};
397 float scaleFactor = noise_factor;
407 double rnd_corr[2] = {0.,0.};
410 for(
size_t i=0; i< noise.size()/2; ++i)
417 float phase = rnd_corr[1] * 2. * M_PI;
420 std::complex<float> tc(pval*cos(phase),pval*sin(phase));
444 std::function<void (double[])> randGenFunc = [](
double randArray[]){randArray[0]=0.5; randArray[1]=0.5;};
453 double mean,rmsTrunc;
473 std::cout <<
" index " <<jh <<
" uncRMS " <<
rmsUnc.back() << std::endl;
480 for(
size_t index = 0; index < 4; index++)
484 float meanVal = noiseHist->GetMean();
488 float corVal = noiseHist->GetRandom() / meanVal;
490 correction.second[index] = corVal;
502 float rndRMS=histo->GetRandom();
503 float meanRMS=histo->GetMean();
Utilities related to art service access.
virtual void resetCoherentNoiseFactors(const TH1D *)=0
BEGIN_PROLOG could also be dds filename
virtual float getCoherentNoiseFactor(unsigned int, unsigned int) const =0
The data type to uniquely identify a Plane.
CryostatID_t Cryostat
Index of cryostat.
std::vector< ComplexVal > FrequencyVec
std::vector< SigProcPrecision > TimeVec
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
std::map< unsigned int, SlotChannelVecPair > TPCReadoutBoardToChannelMap
This is the interface class for a tool to handle a GenNoise for the overall response.
art::ServiceHandle< art::TFileService > tfs
TPCID_t TPC
Index of the TPC within its cryostat.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
art framework interface to geometry description
BEGIN_PROLOG could also be cout