8 #include "art/Utilities/ToolMacros.h"
9 #include "art_root_io/TFileService.h"
10 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "cetlib_except/exception.h"
18 #include "art/Utilities/make_tool.h"
19 #include "icarus_signal_processing/WaveformTools.h"
26 #include "icarus_signal_processing/Filters/ICARUSFFT.h"
37 explicit Response(
const fhicl::ParameterSet& pset);
41 void configure(
const fhicl::ParameterSet& pset)
override;
75 using IFilterPtr = std::unique_ptr<icarus_tool::IFilter>;
91 std::unique_ptr<icarus_signal_processing::ICARUSFFT<double>>
fFFT;
112 fFieldResponse = art::make_tool<icarus_tool::IFieldResponse>(pset.get<fhicl::ParameterSet>(
"FieldResponse"));
113 fElectronicsResponse = art::make_tool<icarus_tool::IElectronicsResponse>(pset.get<fhicl::ParameterSet>(
"ElectronicsResponse"));
114 fFilter = art::make_tool<icarus_tool::IFilter>(pset.get<fhicl::ParameterSet>(
"Filter"));
116 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
202 std::transform(fieldResponseFFTVec.begin(), fieldResponseFFTVec.begin() + fieldResponseFFTVec.size()/2, electronicsResponseFFTVec.begin(), curResponseFFTVec.begin(), std::multiplies<icarusutil::ComplexVal>());
209 icarus_signal_processing::ICARUSFFT<double> locFFT(curResponseVec.size());
211 locFFT.inverseFFT(curResponseFFTVec, curResponseVec);
222 double respIntegral = std::accumulate(curResponseVec.begin(),curResponseVec.end(),0.);
224 mf::LogInfo(
"Response_tool") <<
"***** Response for plane: " <<
fThisPlane <<
" ******" <<
"\n"
225 <<
" initial response integral: " << respIntegral << std::endl;
230 double rateRatio = samplingRate / responseRate;
242 size_t responseLowIdx = std::floor(sampleIdx * binScaleFactor);
244 if (responseLowIdx < curResponseVec.size())
247 size_t responseHiIdx = std::floor((sampleIdx + 1) * binScaleFactor);
250 if (responseHiIdx == responseLowIdx) responseHiIdx += 1;
252 if (responseHiIdx >= curResponseVec.size())
break;
254 icarusutil::TimeVec::const_iterator curResponseItr = curResponseVec.begin();
256 std::advance(curResponseItr,responseLowIdx);
258 int nBins = responseHiIdx - responseLowIdx;
261 double aveResponse = std::accumulate(curResponseItr,curResponseItr+nBins,0.)/double(nBins);
277 std::pair<icarusutil::TimeVec::iterator,icarusutil::TimeVec::iterator> minMaxPair = std::minmax_element(
fResponse.begin(),
fResponse.end());
286 double weightSum =
abs(*minMaxPair.first) +
abs(*minMaxPair.second);
289 timeBin = std::round(sum/weightSum);
292 std::cout <<
"*** Response tool is setting timeBin = " << timeBin << std::endl;
316 mf::LogInfo(
"Response_tool") <<
" final response integral: " << respIntegral <<
", T0Offset: " <<
fT0Offset << std::endl;
322 art::TFileDirectory& histDir)
const
327 art::TFileDirectory
dir = histDir.mkdir(thisResponse.c_str());
332 fFilter->outputHistograms(dir);
337 art::TFileDirectory responesDir = dir.mkdir(dirName.c_str());
339 double numBins = responseVec.size();
341 double maxFreq = 1. / samplingRate;
342 double minFreq = maxFreq / numBins;
344 TProfile* hist = dir.make<TProfile>(histName.c_str(),
"Response;Time(us)", numBins, 0., numBins * sampling_rate * 1.e-3);
348 hist->Fill((
double(
bin) + 0.5) * sampling_rate * 1.
e-3, responseVec.at(
bin), 1.);
353 fFFT->getFFTPower(responseVec, powerVec);
356 TProfile* freqHist = dir.make<TProfile>(freqName.c_str(),
"Response;Frequency(kHz)", numBins/2, minFreq, 0.5*maxFreq);
358 for(
size_t idx = 0; idx < numBins/2; idx++)
360 double freq = minFreq * (idx + 0.5);
362 freqHist->Fill(freq, powerVec.at(idx), 1.);
368 TProfile* fullResponseHist = dir.make<TProfile>(convKernelName.c_str(),
"Convolution Kernel;Frequency(kHz)", numBins/2, minFreq, 0.5*maxFreq);
370 for(
size_t idx = 0; idx < numBins/2; idx++)
372 double freq = minFreq * (idx + 0.5);
374 fullResponseHist->Fill(freq,
std::abs(convKernel[idx]), 1.);
380 TProfile* deconHist = dir.make<TProfile>(deconName.c_str(),
"Deconvolution Kernel;Frequency(kHz)", numBins/2, minFreq, 0.5*maxFreq);
382 for(
size_t idx = 0; idx < numBins/2; idx++)
384 double freq = minFreq * (idx + 0.5);
386 deconHist->Fill(freq,
std::abs(deconKernel[idx]), 1.);
394 std::ostringstream string;
396 string << std::setfill(
'0') << std::setw(2) << number;
Utilities related to art service access.
This is the interface class for a tool to handle the field response It is assumed that the field resp...
std::vector< ComplexVal > FrequencyVec
pure virtual base interface for detector clocks
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
std::vector< SigProcPrecision > TimeVec
This is the interface class for a tool to handle a filter for the overall response.
Definition of data types for geometry description.
std::string to_string(WindowPattern const &pattern)
This is the interface class for a tool to handle the field response It is assumed that the field resp...
This is the interface class for a tool to handle the electronics response.
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