9 #ifndef RecoWireICARUS_H
10 #define RecoWireICARUS_H
20 #include "fhiclcpp/ParameterSet.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
22 #include "cetlib_except/exception.h"
23 #include "cetlib/search_path.h"
24 #include "canvas/Persistency/Common/Ptr.h"
25 #include "canvas/Persistency/Common/Assns.h"
26 #include "art/Framework/Principal/Event.h"
27 #include "art/Framework/Principal/Handle.h"
28 #include "art/Framework/Services/Registry/ServiceHandle.h"
29 #include "art/Framework/Core/EDProducer.h"
30 #include "art/Framework/Core/ModuleMacros.h"
42 #include "icarus_signal_processing/Filters/ICARUSFFT.h"
69 std::vector<std::vector<std::complex<double>>>
fKernelR;
71 std::vector<std::vector<std::complex<double>>>
fKernelS;
93 produces< std::vector<recob::Wire> >();
94 produces<art::Assns<raw::RawDigit, recob::Wire>>();
107 cet::search_path sp(
"FW_SEARCH_PATH");
108 sp.find_file(p.get<std::string>(
"ResponseFile"),
fResponseFile);
117 MF_LOG_DEBUG(
"RecoWireICARUS") <<
"RecoWireICARUS_plugin: Opening Electronics Response File: "
122 mf::LogWarning(
"RecoWireICARUS") <<
"Cannot open response file "
125 TH2D *respRe =
dynamic_cast<TH2D*
>(f.Get(
"real/RespRe") );
126 TH2D *respIm =
dynamic_cast<TH2D*
>(f.Get(
"real/RespIm") );
127 TH1D *decayHist =
dynamic_cast<TH1D*
>(f.Get(
"real/decayHist"));
128 unsigned int wires = decayHist->GetNbinsX();
129 unsigned int bins = respRe->GetYaxis()->GetNbins();
130 unsigned int bin = 0;
131 unsigned int wire = 0;
134 fKernelR.resize(respRe->GetXaxis()->GetNbins());
135 const TArrayD *edges = respRe->GetXaxis()->GetXbins();
136 for(
int i = 0; i < respRe->GetXaxis()->GetNbins(); ++i) {
138 for(bin = 0; bin < bins; ++
bin) {
140 const TComplex
a(respRe->GetBinContent(i+1,bin+1),
141 respIm->GetBinContent(i+1,bin+1));
144 for(; wire < (*edges)[i+1]; ++wire) {
149 respRe =
dynamic_cast<TH2D*
>(f.Get(
"sim/RespRe") );
150 respIm =
dynamic_cast<TH2D*
>(f.Get(
"sim/RespIm") );
151 decayHist =
dynamic_cast<TH1D*
>(f.Get(
"sim/decayHist"));
152 wires = decayHist->GetNbinsX();
153 bins = respRe->GetYaxis()->GetNbins();
156 fKernelS.resize(respRe->GetXaxis()->GetNbins());
157 const TArrayD *edges1 = respRe->GetXaxis()->GetXbins();
159 for(
int i = 0; i < respRe->GetXaxis()->GetNbins(); ++i) {
161 for(bin = 0; bin < bins; ++
bin) {
162 const TComplex b(respRe->GetBinContent(i+1,bin+1),
163 respIm->GetBinContent(i+1,bin+1));
166 for(; wire < (*edges1)[i+1]; ++wire) {
186 art::ServiceHandle<geo::Geometry> geom;
188 std::vector<double> decayConsts;
189 std::vector<int> kernMap;
190 std::vector<std::vector<std::complex<double>>> kernel;
192 if(evt.isRealData()) {
204 std::unique_ptr<std::vector<recob::Wire> > wirecol(
new std::vector<recob::Wire>);
206 std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire> > WireDigitAssn
207 (
new art::Assns<raw::RawDigit,recob::Wire>);
210 art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
213 if (!digitVecHandle->size())
return;
214 mf::LogInfo(
"RecoWireICARUS") <<
"RecoWireICARUS:: digitVecHandle size is " << digitVecHandle->size();
217 art::Ptr<raw::RawDigit> digitVec0(digitVecHandle, 0);
219 unsigned int dataSize = digitVec0->Samples();
221 int transformSize = dataSize;
225 icarus_signal_processing::ICARUSFFT<double> fft(transformSize);
227 double decayConst = 0.;
228 double fitAmplitude = 0.;
229 std::vector<float> holder;
230 std::vector<float> shortADC;
231 std::vector<float> longADC;
232 std::vector<short> rawadc(transformSize);
233 std::vector<std::complex<double>> freqHolder(transformSize+1);
234 wirecol->reserve(digitVecHandle->size());
236 for(
unsigned int rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter){
239 art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
240 channel = digitVec->Channel();
242 holder.resize(transformSize);
243 shortADC.resize(transformSize);
244 longADC.resize(transformSize);
249 for(bin = 0; bin < dataSize; ++
bin)
250 holder[bin]=(rawadc[bin]-digitVec->GetPedestal());
259 throw cet::exception(
"RecoWireICARUS") <<
"Bad signal type = " << sigtype <<
"\n";
260 if (k >= kernel.size())
261 throw cet::exception(
"RecoWireICARUS") <<
"kernel size < " << k <<
"!\n";
265 for(bin = 1; bin < dataSize; ++
bin)
269 for(bin = 0; bin < dataSize; ++
bin)
272 for (
int ijk=0; ijk<30; ijk++) {
273 if ((
int(bin)-ijk)>=0 && (bin+ijk)<4096) {
280 for(bin = 0; bin < dataSize; ++
bin)
282 if(shortADC[bin]==0)holder[
bin]=0;
285 for(bin = 1; bin < dataSize; ++
bin)
287 holder[
bin]+= holder[bin-1];
289 for(bin = 0; bin < dataSize; ++
bin)
291 if(shortADC[bin]==0)holder[
bin]=0;
330 TH1D expTailData(
"expTailData",
"Tail data for fit",
332 TF1 expFit(
"expFit",
"[0]*exp([1]*x)");
336 decayConst = decayConsts[channel];
338 expFit.FixParameter(1,decayConst);
339 expFit.SetParameter(0,fitAmplitude);
340 expTailData.Fit(&expFit,
"QWN",
"",dataSize-
fExpEndBins,dataSize);
341 expFit.SetRange(dataSize,transformSize);
342 for(bin = 0; bin < dataSize; ++
bin)
343 holder[dataSize+bin]= expFit.Eval(bin+dataSize);
356 std::copy(holder.begin(),holder.end(),temp.begin());
357 fft.convolute(temp,kernel[k],0);
358 std::copy(temp.begin(),temp.end(),holder.begin());
365 for(bin = 0; bin < holder.size(); ++
bin) holder[bin]-=average;
372 throw art::Exception(art::errors::ProductRegistrationFailure)
373 <<
"Can't associate wire #" << (wirecol->size() - 1)
374 <<
" with raw digit #" << digitVec.key();
378 if(wirecol->size() == 0)
379 mf::LogWarning(
"RecoWireICARUS") <<
"No wires made for this event.";
381 evt.put(std::move(wirecol));
382 evt.put(std::move(WireDigitAssn));
392 DEFINE_ART_MODULE(RecoWireICARUS)
397 #endif // RecoWireICARUS_H
std::string fResponseFile
std::vector< std::vector< std::complex< double > > > fKernelS
void reconfigure(fhicl::ParameterSet const &p)
Helper functions to create a wire.
std::vector< double > fDecayConstsR
Definition of basic raw digits.
std::vector< double > fDecayConstsS
int fExpEndBins
number of end bins to consider for tail fit
Class managing the creation of a new recob::Wire object.
RecoWireICARUS(fhicl::ParameterSet const &pset)
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::vector< int > fKernMapR
std::string fDigitModuleLabel
module that made digits
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Signal from induction planes.
enum geo::_plane_sigtype SigType_t
int fPostsample
number of postsample bins
Collect all the RawData header files together.
std::vector< SigProcPrecision > TimeVec
void produce(art::Event &evt)
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
Encapsulate the construction of a single detector plane.
std::vector< std::vector< std::complex< double > > > fKernelR
std::vector< int > fKernMapS
virtual ~RecoWireICARUS()
Declaration of basic channel signal object.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
art framework interface to geometry description
Signal from collection planes.