10 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "fhiclcpp/ParameterSet.h"
12 #include "cetlib_except/exception.h"
13 #include "cetlib/search_path.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Core/EDProducer.h"
17 #include "art/Framework/Principal/Handle.h"
18 #include "canvas/Persistency/Common/Ptr.h"
19 #include "canvas/Persistency/Common/Assns.h"
20 #include "art/Framework/Services/Registry/ServiceHandle.h"
49 explicit CalWireT962(fhicl::ParameterSet
const& pset);
87 fDigitModuleLabel = pset.get< std::string >(
"DigitModuleLabel",
"daq");
88 fExpEndBins = pset.get<
int > (
"ExponentialEndBins");
89 fPostsample = pset.get<
int > (
"PostsampleBins");
91 cet::search_path sp(
"FW_SEARCH_PATH");
92 sp.find_file(pset.get<std::string>(
"ResponseFile"), fResponseFile);
94 produces< std::vector<recob::Wire> >();
95 produces<art::Assns<raw::RawDigit, recob::Wire>>();
103 MF_LOG_DEBUG(
"CalWireT962") <<
"CalWireT962_module: Opening Electronics Response File: "
108 mf::LogWarning(
"CalWireT962") <<
"Cannot open response file "
111 TH2D *respRe =
dynamic_cast<TH2D*
>(f.Get(
"real/RespRe") );
112 TH2D *respIm =
dynamic_cast<TH2D*
>(f.Get(
"real/RespIm") );
113 TH1D *decayHist =
dynamic_cast<TH1D*
>(f.Get(
"real/decayHist"));
114 unsigned int wires = decayHist->GetNbinsX();
115 unsigned int bins = respRe->GetYaxis()->GetNbins();
116 unsigned int bin = 0;
117 unsigned int wire = 0;
120 fKernelR.resize(respRe->GetXaxis()->GetNbins());
121 const TArrayD *edges = respRe->GetXaxis()->GetXbins();
122 for(
int i = 0; i < respRe->GetXaxis()->GetNbins(); ++i) {
124 for(bin = 0; bin < bins; ++
bin) {
126 const TComplex
a(respRe->GetBinContent(i+1,bin+1),
127 respIm->GetBinContent(i+1,bin+1));
130 for(; wire < (*edges)[i+1]; ++wire) {
135 respRe =
dynamic_cast<TH2D*
>(f.Get(
"sim/RespRe") );
136 respIm =
dynamic_cast<TH2D*
>(f.Get(
"sim/RespIm") );
137 decayHist =
dynamic_cast<TH1D*
>(f.Get(
"sim/decayHist"));
138 wires = decayHist->GetNbinsX();
139 bins = respRe->GetYaxis()->GetNbins();
142 fKernelS.resize(respRe->GetXaxis()->GetNbins());
143 const TArrayD *edges1 = respRe->GetXaxis()->GetXbins();
145 for(
int i = 0; i < respRe->GetXaxis()->GetNbins(); ++i) {
147 for(bin = 0; bin < bins; ++
bin) {
148 const TComplex b(respRe->GetBinContent(i+1,bin+1),
149 respIm->GetBinContent(i+1,bin+1));
152 for(; wire < (*edges1)[i+1]; ++wire) {
167 art::ServiceHandle<geo::Geometry const> geom;
169 std::vector<double> decayConsts;
170 std::vector<int> kernMap;
171 std::vector<std::vector<TComplex> > kernel;
173 if(evt.isRealData()) {
185 art::ServiceHandle<util::LArFFT> fFFT;
188 std::unique_ptr<std::vector<recob::Wire> > wirecol(
new std::vector<recob::Wire>);
190 std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire> > WireDigitAssn
191 (
new art::Assns<raw::RawDigit,recob::Wire>);
194 art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
197 if (!digitVecHandle->size())
return;
198 mf::LogInfo(
"CalWireT962") <<
"CalWireT962:: digitVecHandle size is " << digitVecHandle->size();
201 art::Ptr<raw::RawDigit> digitVec0(digitVecHandle, 0);
203 unsigned int dataSize = digitVec0->Samples();
205 int transformSize = fFFT->FFTSize();
210 = art::ServiceHandle<lariov::ChannelStatusService const>()->GetProvider();
212 double decayConst = 0.;
213 double fitAmplitude = 0.;
214 std::vector<float> holder;
215 std::vector<TComplex> freqHolder(transformSize+1);
218 for(
unsigned int rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter){
221 art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
224 channel = digitVec->Channel();
227 if(!channelStatus.
IsBad(channel)) {
228 holder.resize(transformSize);
230 for(bin = 0; bin < dataSize; ++
bin)
231 holder[bin]=(rawadc[bin]-digitVec->GetPedestal());
233 if(fExpEndBins &&
std::abs(decayConsts[channel]) > 0.0){
235 TH1D expTailData(
"expTailData",
"Tail data for fit",
236 fExpEndBins,dataSize-fExpEndBins,dataSize);
237 TF1 expFit(
"expFit",
"[0]*exp([1]*x)");
239 for(bin = 0; bin < (
unsigned int)fExpEndBins; ++
bin)
240 expTailData.Fill(dataSize-fExpEndBins+bin,holder[dataSize-fExpEndBins+bin]);
241 decayConst = decayConsts[channel];
242 fitAmplitude = holder[dataSize-
fExpEndBins]/
exp(decayConst*(dataSize-fExpEndBins));
243 expFit.FixParameter(1,decayConst);
244 expFit.SetParameter(0,fitAmplitude);
245 expTailData.Fit(&expFit,
"QWN",
"",dataSize-fExpEndBins,dataSize);
246 expFit.SetRange(dataSize,transformSize);
247 for(bin = 0; bin < dataSize; ++
bin)
248 holder[dataSize+bin]= expFit.Eval(bin+dataSize);
256 fFFT->Convolute(holder,kernel[kernMap[channel]]);
259 holder.resize(dataSize,1
e-5);
263 for(bin=0; bin < (
unsigned int)fPostsample; ++
bin)
264 average+=holder[holder.size()-1-
bin]/(double)fPostsample;
265 for(bin = 0; bin < holder.size(); ++
bin) holder[bin]-=average;
274 throw art::Exception(art::errors::ProductRegistrationFailure)
275 <<
"Can't associate wire #" << (wirecol->size() - 1)
276 <<
" with raw digit #" << digitVec.key();
280 if(wirecol->size() == 0)
281 mf::LogWarning(
"CalWireT962") <<
"No wires made for this event.";
283 evt.put(std::move(wirecol));
284 evt.put(std::move(WireDigitAssn));
293 DEFINE_ART_MODULE(CalWireT962)
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
int fPostsample
number of postsample bins
Helper functions to create a wire.
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition of basic raw digits.
Class managing the creation of a new recob::Wire object.
std::vector< std::vector< TComplex > > fKernelR
std::vector< double > fDecayConstsS
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
std::string fDigitModuleLabel
module that made digits
Collect all the RawData header files together.
std::vector< int > fKernMapS
Class providing information about the quality of channels.
std::string fResponseFile
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::vector< double > fDecayConstsR
Interface for experiment-specific channel quality info provider.
Declaration of basic channel signal object.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Interface for experiment-specific service for channel quality info.
void produce(art::Event &evt)
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
CalWireT962(fhicl::ParameterSet const &pset)
std::vector< std::vector< TComplex > > fKernelS
process_name can override from command line with o or output caldata
art framework interface to geometry description
std::vector< int > fKernMapR
int fExpEndBins
number of end bins to consider for tail fit