17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 #include "cetlib_except/exception.h"
20 #include "cetlib/search_path.h"
21 #include "canvas/Persistency/Common/Ptr.h"
22 #include "canvas/Persistency/Common/Assns.h"
23 #include "art/Framework/Principal/Event.h"
24 #include "art/Framework/Principal/Handle.h"
25 #include "art/Framework/Services/Registry/ServiceHandle.h"
26 #include "art/Framework/Core/EDProducer.h"
27 #include "art/Framework/Core/ModuleMacros.h"
48 explicit CalWire(fhicl::ParameterSet
const& pset);
86 fDigitModuleLabel = pset.get< std::string >(
"DigitModuleLabel",
"daq");
87 cet::search_path sp(
"FW_SEARCH_PATH");
88 sp.find_file(pset.get<std::string>(
"ResponseFile"), fResponseFile);
89 fExpEndBins = pset.get<
int > (
"ExponentialEndBins");
90 fPostsample = pset.get<
int > (
"PostsampleBins");
92 produces< std::vector<recob::Wire> >();
93 produces<art::Assns<raw::RawDigit, recob::Wire>>();
101 MF_LOG_DEBUG(
"CalWire") <<
"CalWire_plugin: Opening Electronics Response File: "
106 mf::LogWarning(
"CalWire") <<
"Cannot open response file "
109 TH2D *respRe =
dynamic_cast<TH2D*
>(f.Get(
"real/RespRe") );
110 TH2D *respIm =
dynamic_cast<TH2D*
>(f.Get(
"real/RespIm") );
111 TH1D *decayHist =
dynamic_cast<TH1D*
>(f.Get(
"real/decayHist"));
112 unsigned int wires = decayHist->GetNbinsX();
113 unsigned int bins = respRe->GetYaxis()->GetNbins();
114 unsigned int bin = 0;
115 unsigned int wire = 0;
118 fKernelR.resize(respRe->GetXaxis()->GetNbins());
119 const TArrayD *edges = respRe->GetXaxis()->GetXbins();
120 for(
int i = 0; i < respRe->GetXaxis()->GetNbins(); ++i) {
122 for(bin = 0; bin < bins; ++
bin) {
124 const TComplex
a(respRe->GetBinContent(i+1,bin+1),
125 respIm->GetBinContent(i+1,bin+1));
128 for(; wire < (*edges)[i+1]; ++wire) {
133 respRe =
dynamic_cast<TH2D*
>(f.Get(
"sim/RespRe") );
134 respIm =
dynamic_cast<TH2D*
>(f.Get(
"sim/RespIm") );
135 decayHist =
dynamic_cast<TH1D*
>(f.Get(
"sim/decayHist"));
136 wires = decayHist->GetNbinsX();
137 bins = respRe->GetYaxis()->GetNbins();
140 fKernelS.resize(respRe->GetXaxis()->GetNbins());
141 const TArrayD *edges1 = respRe->GetXaxis()->GetXbins();
143 for(
int i = 0; i < respRe->GetXaxis()->GetNbins(); ++i) {
145 for(bin = 0; bin < bins; ++
bin) {
146 const TComplex b(respRe->GetBinContent(i+1,bin+1),
147 respIm->GetBinContent(i+1,bin+1));
150 for(; wire < (*edges1)[i+1]; ++wire) {
165 art::ServiceHandle<geo::Geometry const> geom;
167 std::vector<double> decayConsts;
168 std::vector<int> kernMap;
169 std::vector<std::vector<TComplex> > kernel;
171 if(evt.isRealData()) {
183 art::ServiceHandle<util::LArFFT> fFFT;
186 std::unique_ptr<std::vector<recob::Wire> > wirecol(
new std::vector<recob::Wire>);
188 std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire> > WireDigitAssn
189 (
new art::Assns<raw::RawDigit,recob::Wire>);
192 art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
195 if (!digitVecHandle->size())
return;
196 mf::LogInfo(
"CalWire") <<
"CalWire:: digitVecHandle size is " << digitVecHandle->size();
199 art::Ptr<raw::RawDigit> digitVec0(digitVecHandle, 0);
201 unsigned int dataSize = digitVec0->Samples();
203 int transformSize = fFFT->FFTSize();
207 double decayConst = 0.;
208 double fitAmplitude = 0.;
209 std::vector<float> holder;
210 std::vector<short> rawadc(transformSize);
211 std::vector<TComplex> freqHolder(transformSize+1);
214 for(
unsigned int rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter){
217 art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
218 channel = digitVec->Channel();
220 holder.resize(transformSize);
225 for(bin = 0; bin < dataSize; ++
bin)
226 holder[bin]=(rawadc[bin]-digitVec->GetPedestal());
230 TH1D expTailData(
"expTailData",
"Tail data for fit",
232 TF1 expFit(
"expFit",
"[0]*exp([1]*x)");
236 decayConst = decayConsts[channel];
238 expFit.FixParameter(1,decayConst);
239 expFit.SetParameter(0,fitAmplitude);
240 expTailData.Fit(&expFit,
"QWN",
"",dataSize-
fExpEndBins,dataSize);
241 expFit.SetRange(dataSize,transformSize);
242 for(bin = 0; bin < dataSize; ++
bin)
243 holder[dataSize+bin]= expFit.Eval(bin+dataSize);
262 throw cet::exception(
"CalWire") <<
"Bad signal type = " << sigtype <<
"\n";
263 if (k >= kernel.size())
264 throw cet::exception(
"CalWire") <<
"kernel size < " << k <<
"!\n";
266 fFFT->Convolute(holder,kernel[k]);
268 holder.resize(dataSize,1
e-5);
274 for(bin = 0; bin < holder.size(); ++
bin) holder[bin]-=average;
280 throw art::Exception(art::errors::ProductRegistrationFailure)
281 <<
"Can't associate wire #" << (wirecol->size() - 1)
282 <<
" with raw digit #" << digitVec.key();
286 if(wirecol->size() == 0)
287 mf::LogWarning(
"CalWire") <<
"No wires made for this event.";
289 evt.put(std::move(wirecol));
290 evt.put(std::move(WireDigitAssn));
300 DEFINE_ART_MODULE(CalWire)
std::string fResponseFile
std::vector< int > fKernMapR
Helper functions to create a wire.
std::vector< double > fDecayConstsR
Definition of basic raw digits.
Class managing the creation of a new recob::Wire object.
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::vector< double > fDecayConstsS
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Signal from induction planes.
enum geo::_plane_sigtype SigType_t
Collect all the RawData header files together.
std::vector< std::vector< TComplex > > fKernelR
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.
std::string fDigitModuleLabel
module that made digits
std::vector< std::vector< TComplex > > fKernelS
int fExpEndBins
number of end bins to consider for tail fit
Declaration of basic channel signal object.
int fPostsample
number of postsample bins
void produce(art::Event &evt)
std::vector< int > fKernMapS
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.
process_name can override from command line with o or output caldata
CalWire(fhicl::ParameterSet const &pset)
art framework interface to geometry description
Signal from collection planes.