23 #include "art/Framework/Core/EDProducer.h"
24 #include "art/Framework/Services/Registry/ServiceHandle.h"
25 #include "art_root_io/TFileService.h"
26 #include "art/Framework/Principal/Event.h"
27 #include "art/Framework/Core/ModuleMacros.h"
28 #include "art/Utilities/make_tool.h"
29 #include "canvas/Persistency/Common/Ptr.h"
30 #include "messagefacility/MessageLogger/MessageLogger.h"
52 virtual void configure(fhicl::ParameterSet
const & pset);
53 virtual void produce(art::Event &
e);
61 using WireTuple = std::tuple<raw::ChannelID_t,float,float,caldata::RawDigitVector>;
105 fCharacterizationAlg(pset.get<fhicl::ParameterSet>(
"CharacterizationAlg")),
106 fPedestalRetrievalAlg(*lar::providerFrom<lariov::DetPedestalService>())
109 fGeometry = lar::providerFrom<geo::Geometry>();
112 produces<std::vector<raw::RawDigit>>(
"erosion");
113 produces<std::vector<raw::RawDigit>>(
"dilation");
114 produces<std::vector<raw::RawDigit>>(
"edge");
115 produces<std::vector<raw::RawDigit>>(
"average");
116 produces<std::vector<raw::RawDigit>>(
"difference");
117 produces<std::vector<raw::RawDigit>>(
"median");
120 mf::LogInfo(
"RawDigitSmoother") <<
"RawDigitSmoother configured\n";
149 if (fOutputHistograms)
153 art::ServiceHandle<art::TFileService>
tfs;
168 art::ServiceHandle<art::TFileService>
tfs;
191 std::unique_ptr<std::vector<raw::RawDigit> > erosionRawDigit(
new std::vector<raw::RawDigit>);
192 std::unique_ptr<std::vector<raw::RawDigit> > dilationRawDigit(
new std::vector<raw::RawDigit>);
193 std::unique_ptr<std::vector<raw::RawDigit> > edgeRawDigit(
new std::vector<raw::RawDigit>);
194 std::unique_ptr<std::vector<raw::RawDigit> > differenceRawDigit(
new std::vector<raw::RawDigit>);
195 std::unique_ptr<std::vector<raw::RawDigit> > averageRawDigit(
new std::vector<raw::RawDigit>);
196 std::unique_ptr<std::vector<raw::RawDigit> > medianRawDigit(
new std::vector<raw::RawDigit>);
198 erosionRawDigit->clear();
199 dilationRawDigit->clear();
200 edgeRawDigit->clear();
201 differenceRawDigit->clear();
202 averageRawDigit->clear();
203 medianRawDigit->clear();
206 art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
210 if (digitVecHandle.isValid() && digitVecHandle->size() > 0)
212 erosionRawDigit->reserve(digitVecHandle->size());
213 dilationRawDigit->reserve(digitVecHandle->size());
214 edgeRawDigit->reserve(digitVecHandle->size());
215 differenceRawDigit->reserve(digitVecHandle->size());
216 averageRawDigit->reserve(digitVecHandle->size());
217 medianRawDigit->reserve(digitVecHandle->size());
223 std::vector<const raw::RawDigit*> rawDigitVec;
226 for(
size_t idx = 0; idx < digitVecHandle->size(); idx++) rawDigitVec.push_back(&digitVecHandle->at(idx));
232 size_t rawDataSize = rawDigitVec.front()->Samples();
260 size_t validIndex = 0;
263 size_t maxAdcBinSize(0);
267 for(
const auto& structElemVal : rowVec)
268 if (structElemVal) maxAdcBinSize++;
271 std::vector<short> adcBinValVec(maxAdcBinSize, 0);
279 for(
const auto& rawDigit : rawDigitVec)
283 if (channel >= maxChannels)
continue;
289 if (lastWireID.
asPlaneID().
cmp(wids[0].asPlaneID()) != 0)
292 WaveformList::iterator inputWaveItr = inputWaveformList.begin();
294 std::advance(inputWaveItr, fStructuringElementWireSize/2);
296 while(++inputWaveItr != inputWaveformList.end())
311 lastWireID = wids[0];
314 unsigned int plane = wids[0].Plane;
315 unsigned int wire = wids[0].Wire;
317 if (rawDigit->Samples() < 1)
319 std::cout <<
"****>> Found zero length raw digit buffer, channel: " << channel <<
", plane: " << plane <<
", wire: " << wire << std::endl;
324 if (validIndex == inputWaveformList.size())
326 inputWaveformList.push_back(inputWaveformList.front());
327 inputWaveformList.pop_front();
332 WaveformList::iterator inputWaveItr = inputWaveformList.begin();
333 WaveformList::iterator midWaveItr = inputWaveItr;
335 std::advance(inputWaveItr, validIndex - 1);
336 std::advance(midWaveItr, validIndex / 2);
341 raw::Uncompress(rawDigit->ADCs(), inputAdcVector, rawDigit->Compression());
353 std::transform(inputAdcVector.begin(),inputAdcVector.end(),rawadc.begin(),std::bind(std::minus<short>(),std::placeholders::_1,pedCorVal));
355 std::get<0>(**inputWaveItr) = channel;
356 std::get<1>(**inputWaveItr) = pedestal;
357 std::get<2>(**inputWaveItr) = rmsVal;
360 if (validIndex == inputWaveformList.size())
364 float midPedestal = std::get<1>(**midWaveItr);
365 float midRmsVal = std::get<2>(**midWaveItr);
371 for(
size_t adcBinIdx = 0; adcBinIdx < halfStructuringElementTickSize; adcBinIdx++)
373 size_t adcLastBinIdx = rawDataSize - adcBinIdx - 1;
375 erosionVec[adcBinIdx] = midPedestal;
376 erosionVec[adcLastBinIdx] = midPedestal;
377 dilationVec[adcBinIdx] = midPedestal;
378 dilationVec[adcLastBinIdx] = midPedestal;
379 edgeVec[adcBinIdx] = midPedestal;
380 edgeVec[adcLastBinIdx] = midPedestal;
381 differenceVec[adcBinIdx] = midPedestal;
382 differenceVec[adcLastBinIdx] = midPedestal;
383 averageVec[adcBinIdx] = midPedestal;
384 averageVec[adcLastBinIdx] = midPedestal;
385 medianVec[adcBinIdx] = midPedestal;
386 medianVec[adcLastBinIdx] = midPedestal;
391 for(
size_t adcBinIdx = halfStructuringElementTickSize; adcBinIdx < erosionVec.size() - halfStructuringElementTickSize; adcBinIdx++)
394 size_t adcBinVecIdx(0);
397 for(
const auto& curTuple : inputWaveformList)
403 if (fStructuringElement[rowIdx][colIdx]) adcBinValVec[adcBinVecIdx++] = curAdcVec[colIdx + adcBinIdx - halfStructuringElementTickSize];
409 std::sort(adcBinValVec.begin(),adcBinValVec.end());
411 erosionVec[adcBinIdx] = adcBinValVec.front();
412 dilationVec[adcBinIdx] = adcBinValVec.back();
413 edgeVec[adcBinIdx] = (dilationVec[adcBinIdx] - currentVec[adcBinIdx]) + midPedestal;
414 differenceVec[adcBinIdx] = (dilationVec[adcBinIdx] - erosionVec[adcBinIdx]) + midPedestal;
415 averageVec[adcBinIdx] = (dilationVec[adcBinIdx] + erosionVec[adcBinIdx]) / 2;
416 medianVec[adcBinIdx] = adcBinValVec[adcBinValVec.size()/2];
419 saveRawDigits(erosionRawDigit, midChannel, midPedestal, midRmsVal, std::get<3>(erosionTuple));
420 saveRawDigits(dilationRawDigit, midChannel, midPedestal, midRmsVal, std::get<3>(dilationTuple));
421 saveRawDigits(edgeRawDigit, midChannel, midPedestal, midRmsVal, std::get<3>(edgeTuple));
422 saveRawDigits(differenceRawDigit, midChannel, midPedestal, midRmsVal, std::get<3>(differenceTuple));
423 saveRawDigits(averageRawDigit, midChannel, midPedestal, midRmsVal, std::get<3>(averageTuple));
424 saveRawDigits(medianRawDigit, midChannel, midPedestal, midRmsVal, std::get<3>(medianTuple));
426 else if (validIndex <= fStructuringElementWireSize / 2)
479 event.put(std::move(erosionRawDigit),
"erosion");
480 event.put(std::move(dilationRawDigit),
"dilation");
481 event.put(std::move(edgeRawDigit),
"edge");
482 event.put(std::move(differenceRawDigit),
"difference");
483 event.put(std::move(averageRawDigit),
"average");
484 event.put(std::move(medianRawDigit),
"median");
493 float pedestal = std::get<1>(wireTuple);
494 float rms = std::get<2>(wireTuple);
497 filteredRawDigit->emplace_back(channel, rawDigitVec.size(), rawDigitVec,
raw::kNone);
498 filteredRawDigit->back().SetPedestal(pedestal,rms);
503 void RawDigitSmoother::RawDigitSmoother::saveRawDigits(std::unique_ptr<std::vector<raw::RawDigit> >& filteredRawDigit,
509 filteredRawDigit->emplace_back(channel, rawDigitVec.size(), rawDigitVec,
raw::kNone);
510 filteredRawDigit->back().SetPedestal(pedestal,rms);
519 mf::LogInfo(
"RawDigitSmoother") <<
"Looked at " <<
fNumEvent <<
" events" << std::endl;
virtual void configure(fhicl::ParameterSet const &pset)
Collection of charge vs time digitized from a single readout channel.
virtual ~RawDigitSmoother()
Destructor.
void getMeanRmsAndPedCor(const RawDigitVector &rawWaveform, unsigned int channel, unsigned int view, unsigned int wire, float &aveVal, float &rmsVal, float &pedCorVal) const
virtual void endJob()
End job method.
geo::GeometryCore const * fGeometry
pointer to Geometry service
virtual void produce(art::Event &e)
RawDigitSmoother(fhicl::ParameterSet const &pset)
ChannelID_t Channel() const
DAQ channel this raw data was read from.
const lariov::DetPedestalProvider & fPedestalRetrievalAlg
Keep track of an instance to the pedestal retrieval alg.
raw::RawDigit::ADCvector_t RawDigitVector
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
Definition of basic raw digits.
std::vector< std::vector< short >> StructuringElement
size_t fStructuringElementWireSize
art::TFileDirectory * fHistDirectory
void saveRawDigits(std::unique_ptr< std::vector< raw::RawDigit > > &, WireTuple &)
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
Collect all the RawData header files together.
std::list< WireTuple * > WaveformList
virtual void beginJob()
Begin job method.
constexpr PlaneID const & asPlaneID() const
Conversion to PlaneID (for convenience of notation).
std::string fDigitModuleLabel
The full collection of hits.
Description of geometry of one entire detector.
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
size_t fStructuringElementTickSize
std::vector< WireTuple > WaveformVec
caldata::RawDigitCharacterizationAlg fCharacterizationAlg
art::ServiceHandle< art::TFileService > tfs
std::tuple< raw::ChannelID_t, float, float, caldata::RawDigitVector > WireTuple
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.
int fNumEvent
Number of events seen.
void initializeHists(art::ServiceHandle< art::TFileService > &)
Begin job method.
bool fOutputWaveforms
Output waveforms?
constexpr int cmp(PlaneID const &other) const
Returns < 0 if this is smaller than other, 0 if equal, > 0 if larger.
bool fOutputHistograms
Output histograms?
art framework interface to geometry description
BEGIN_PROLOG could also be cout
StructuringElement fStructuringElement