LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
RawHitFinder_module.cc
Go to the documentation of this file.
1 //HIT FINDER THAT RUNS ON RAW SIGNALS INSTEAD OF DECONVOLUTED ONES.
3 //WRITTEN INITIALLY FOR DUNE 35T ONLINE FILTER.
4 //abooth@fnal.gov, mstancar@fnal.gov.
6 
7 // C/C++ standard libraries
8 #include <numeric> // std::accumulate
9 #include <string>
10 
11 //Framework
19 #include "fhiclcpp/ParameterSet.h"
21 
22 //LArSoft
25 #include "lardataobj/RawData/raw.h"
26 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h"
27 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
28 
29 //LArSoft From FFT
30 
33 
34 namespace hit {
35 
36  class RawHitFinder : public art::EDProducer {
37 
38  public:
39  explicit RawHitFinder(fhicl::ParameterSet const& pset);
40 
41  private:
42  void produce(art::Event& evt) override;
43 
44  unsigned int fDataSize; //SIZE OF RAW DATA ON ONE WIRE.
45  art::InputTag fDigitModuleLabel; //MODULE THAT MADE DIGITS.
46  std::string fSpillName; //NOMINAL SPILL IS AN EMPTY STRING.
47 
48  //FFT COPIED VARIABLES.
49  std::string fCalDataModuleLabel;
50  std::string fHitLabelName;
51  double fMinSigInd; //INDUCTION SIGNAL HEIGHT THRESHOLD.
52  double fMinSigCol; //COLLECTION SIGNAL HEIGHT THRESHOLD.
53  double fIndWidth; //INITIAL WIDTH FOR COLLECTION FIT.
54  double fColWidth; //INITIAL WIDTH FOR COLLECTION FIT.
55  double fIndMinWidth; //MINIMUM INDUCTION HIT WIDTH.
56  double fColMinWidth; //MINIMUM COLLECTION HIT WIDTH.
57  int fMaxMultiHit; //MAXIMUM HITS FOR MULTIFIT.
58  int fAreaMethod; //TYPE OF AREA CALCULATION.
59  std::vector<double> fAreaNorms; //FACTORS FOR CONVERTING AREA TO SAME UNIT AS PEAK HEIGHT.
60  bool fUncompressWithPed; //OPTION TO UNCOMPRESS WITH PEDESTAL.
61  bool fSkipInd; //OPTION TO SKIP INDUCTION PLANES
62  double fIncludeMoreTail; //FRACTION OF THE HIT WIDTH INCLUDED BELOW THRESHOLD IN
63  // THE CALCULATION OF CHARGE. COLLECTION PLANE ONLY
64  int fColMinWindow; // Minimum length of integration window for charge in ticks
65  int fIndCutoff; //MAX WIDTH FOR EARLY SIDE OF INDUCTION HIT IN TICKS
66 
67  }; // class RawHitFinder
68 
69  //-------------------------------------------------
71  {
72  fDigitModuleLabel = pset.get<art::InputTag>("DigitModuleLabel", "daq");
73  fCalDataModuleLabel = pset.get<std::string>("CalDataModuleLabel");
74  fMinSigInd = pset.get<double>("MinSigInd");
75  fMinSigCol = pset.get<double>("MinSigCol");
76  fIncludeMoreTail = pset.get<double>("IncludeMoreTail", 0.);
77  fIndWidth = pset.get<int>("IndWidth", 20);
78  fColWidth = pset.get<double>("ColWidth");
79  fIndMinWidth = pset.get<double>("IndMinWidth");
80  fColMinWidth = pset.get<double>("ColMinWidth", 0.);
81  fMaxMultiHit = pset.get<int>("MaxMultiHit");
82  fAreaMethod = pset.get<int>("AreaMethod");
83  fAreaNorms = pset.get<std::vector<double>>("AreaNorms");
84  fUncompressWithPed = pset.get<bool>("UncompressWithPed", true);
85  fSkipInd = pset.get<bool>("SkipInd", false);
86  fColMinWindow = pset.get<int>("ColMinWindow", 0);
87  fIndCutoff = pset.get<int>("IndCutoff", 20);
88  mf::LogInfo("RawHitFinder_module") << "fDigitModuleLabel: " << fDigitModuleLabel << std::endl;
89 
90  //LET HITCOLLECTIONCREATOR DECLARE THAT WE ARE GOING TO PRODUCE
91  //HITS AND ASSOCIATIONS TO RAW DIGITS BUT NOT ASSOCIATIONS TO WIRES
92  //(WITH NO PARTICULAR PRODUCT LABEL).
94  /*instance_name*/ "",
95  /*doWireAssns*/ false,
96  /*doRawDigitAssns*/ true);
97  }
98 
99  //-------------------------------------------------
101  {
102  //GET THE GEOMETRY.
104 
105  //READ IN THE DIGIT LIST OBJECTS(S).
107 
108  bool retVal = evt.getByLabel(fDigitModuleLabel, digitVecHandle);
109  if (retVal == true)
110  mf::LogInfo("RawHitFinder_module")
111  << "I got fDigitModuleLabel: " << fDigitModuleLabel << std::endl;
112  else
113  mf::LogWarning("RawHitFinder_module")
114  << "Could not get fDigitModuleLabel: " << fDigitModuleLabel << std::endl;
115 
116  std::vector<float> holder; //HOLDS SIGNAL DATA.
117  std::vector<short> rawadc; //UNCOMPRESSED ADC VALUES.
118 
119  // ###############################################
120  // ### Making a ptr vector to put on the event ###
121  // ###############################################
122  // THIS CONTAINS THE HIT COLLECTION AND ITS ASSOCIATIONS TO WIRES AND RAW DIGITS.
123  recob::HitCollectionCreator hcol(evt, false /* doWireAssns */, true /* doRawDigitAssns */);
124 
125  std::vector<float> startTimes; //STORES TIME OF WINDOW START.
126  std::vector<float> maxTimes; //STORES TIME OF LOCAL MAXIMUM.
127  std::vector<float> endTimes; //STORES TIME OF WINDOW END.
128  std::vector<float> peakHeight; //STORES ADC COUNT AT THE MAXIMUM.
129  std::vector<float> hitrms; //STORES CHARGE WEIGHTED RMS OF TIME ACROSS THE HIT.
130  std::vector<double> charge; //STORES THE TOTAL CHARGE ASSOCIATED WITH THE HIT.
131 
132  uint32_t channel = 0; //CHANNEL NUMBER.
133  double threshold = 0; //MINIMUM SIGNAL SIZE FOR ID'ING A HIT.
134  double totSig = 0;
135  double myrms = 0;
136  double mynorm = 0;
138  std::stringstream numConv;
139 
140  hcol.reserve(digitVecHandle->size());
141  for (size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter) {
142  holder.clear();
143 
144  //GET THE REFERENCE TO THE CURRENT raw::RawDigit.
145  art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
146  channel = digitVec->Channel();
147  fDataSize = digitVec->Samples();
148 
149  rawadc.resize(fDataSize);
150  holder.resize(fDataSize);
151 
152  //UNCOMPRESS THE DATA.
153  if (fUncompressWithPed) {
154  int pedestal = (int)digitVec->GetPedestal();
155  raw::Uncompress(digitVec->ADCs(), rawadc, pedestal, digitVec->Compression());
156  }
157  else {
158  raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->Compression());
159  }
160 
161  //GET THE LIST OF BAD CHANNELS.
162  lariov::ChannelStatusProvider const& channelStatus =
164 
165  lariov::ChannelStatusProvider::ChannelSet_t const BadChannels = channelStatus.BadChannels();
166 
167  for (unsigned int bin = 0; bin < fDataSize; ++bin) {
168  holder[bin] = (rawadc[bin] - digitVec->GetPedestal());
169  }
170 
171  sigType = geom->SignalType(channel);
172 
173  peakHeight.clear();
174  endTimes.clear();
175  startTimes.clear();
176  maxTimes.clear();
177  charge.clear();
178  hitrms.clear();
179 
180  bool channelSwitch = false;
181 
182  for (auto it = BadChannels.begin(); it != BadChannels.end(); it++) {
183  if (channel == *it) {
184  channelSwitch = true;
185  break;
186  }
187  }
188 
189  if (channelSwitch == false) {
190  // ###############################################
191  // ### Induction Planes ###
192  // ###############################################
193 
194  //THE INDUCTION PLANE METHOD HAS NOT YET BEEN MODIFIED AND TESTED FOR REAL DATA.
195  // Or for detectors without a grid plane
196  //
197  if (sigType == geo::kInduction && !fSkipInd) {
198  threshold = fMinSigInd;
199  // std::cout<< "Threshold is " << threshold << std::endl;
200  // fitWidth = fIndWidth;
201  // minWidth = fIndMinWidth;
202  // continue;
203  float negthr = -1.0 * threshold;
204  unsigned int bin = 1;
205  float minadc = 0;
206 
207  // find the dips
208  while (bin < (fDataSize - 1)) { // loop over ticks
209  float thisadc = holder[bin];
210  float nextadc = holder[bin + 1];
211  if (thisadc < negthr &&
212  nextadc < negthr) { // new region, require two ticks above threshold
213  // std::cout << "new region" << bin << " " << thisadc << std::endl;
214  // step back to find zero crossing
215  unsigned int place = bin;
216  while (thisadc <= 0 && bin > 0) {
217  // std::cout << bin << " " << thisadc << std::endl;
218  bin--;
219  thisadc = holder[bin];
220  }
221  float hittime = bin + thisadc / (thisadc - holder[bin + 1]);
222  maxTimes.push_back(hittime);
223 
224  // step back more to find the hit start time
225  uint32_t stop;
226  if (fIndCutoff < (int)bin) { stop = bin - fIndCutoff; }
227  else {
228  stop = 0;
229  }
230  while (thisadc < threshold && bin > stop) {
231  // std::cout << bin << " " << thisadc << std::endl;
232  bin--;
233  thisadc = holder[bin];
234  }
235  if (bin >= 2) bin -= 2;
236  while (thisadc > threshold && bin > stop) {
237  // std::cout << bin << " " << thisadc << std::endl;
238  bin--;
239  thisadc = holder[bin];
240  }
241  startTimes.push_back(bin + 1);
242  // now step forward from hit time to find end time, area of dip
243  bin = place;
244  thisadc = holder[bin];
245  minadc = thisadc;
246  bin++;
247  totSig = fabs(thisadc);
248  while (thisadc < negthr && bin < fDataSize) {
249  totSig += fabs(thisadc);
250  thisadc = holder[bin];
251  if (thisadc < minadc) minadc = thisadc;
252  bin++;
253  }
254  endTimes.push_back(bin - 1);
255  peakHeight.push_back(-1.0 * minadc);
256  charge.push_back(totSig);
257  hitrms.push_back(5.0);
258  // std::cout << "TOTAL SIGNAL INDUCTION " << totSig << " 5.0" << std::endl;
259  // std::cout << "filled end times " << bin-1 << "peak height vector size " << peakHeight.size() << std::endl;
260 
261  // don't look for a new hit until it returns to baseline
262  while (thisadc < 0 && bin < fDataSize) {
263  // std::cout << bin << " " << thisadc << std::endl;
264  bin++;
265  if (bin == fDataSize) break;
266  thisadc = holder[bin];
267  }
268  } // end region
269  bin++;
270  } // loop over ticks
271  }
272 
273  // ###############################################
274  // ### Collection Plane ###
275  // ###############################################
276 
277  else if (sigType == geo::kCollection) {
278  threshold = fMinSigCol;
279 
280  float madc = threshold;
281  int ibin = 0;
282  int start = 0;
283  int end = 0;
284  unsigned int bin = 0;
285 
286  while (bin < fDataSize) {
287  float thisadc = holder[bin];
288  madc = threshold;
289  ibin = 0;
290 
291  if (thisadc > madc) {
292  start = bin;
293 
294  if (thisadc > threshold && bin < fDataSize) {
295  while (thisadc > threshold && bin < fDataSize) {
296  if (thisadc > madc) {
297  ibin = bin;
298  madc = thisadc;
299  }
300  bin++;
301  if (bin == fDataSize) break;
302  thisadc = holder[bin];
303  }
304  }
305  else {
306  bin++;
307  }
308 
309  end = bin - 1;
310 
311  if (start != end) {
312  maxTimes.push_back(ibin);
313  peakHeight.push_back(madc);
314  startTimes.push_back(start);
315  endTimes.push_back(end);
316 
317  totSig = 0;
318  myrms = 0;
319  mynorm = 0;
320 
321  int moreTail = std::ceil(fIncludeMoreTail * (end - start));
322  if (moreTail < fColMinWindow) moreTail = fColMinWindow;
323 
324  for (int i = start - moreTail; i <= end + moreTail; i++) {
325  if (i < (int)(holder.size()) && i >= 0) {
326  float temp = ibin - i;
327  myrms += temp * temp * holder[i];
328 
329  totSig += holder[i];
330  }
331  }
332 
333  charge.push_back(totSig);
334  mynorm = totSig;
335  myrms /= mynorm;
336  hitrms.push_back(sqrt(myrms));
337 
338  //PRE CHANGES MADE 04/14/16. A BOOTH, DUNE 35T.
339  /*
340  int moreTail = std::ceil(fIncludeMoreTail*(end-start));
341 
342  for(int i = start-moreTail; i <= end+moreTail; i++)
343  {
344  totSig += holder[i];
345  float temp2 = holder[i]*holder[i];
346  mynorm += temp2;
347  float temp = ibin-i;
348  myrms += temp*temp*temp2;
349  }
350 
351  charge.push_back(totSig);
352  myrms/=mynorm;
353  if((end-start+2*moreTail+1)!=0)
354  {
355  myrms/=(float)(end-start+2*moreTail+1);
356  hitrms.push_back(sqrt(myrms));
357  }
358  else
359  {
360  hitrms.push_back(sqrt(myrms));
361  }*/
362  }
363  }
364  start = 0;
365  end = 0;
366  bin++;
367  }
368  }
369  }
370 
371  int numHits(0); //NUMBER OF CONSECUTIVE HITS BEING FITTED.
372  int hitIndex(0); //INDEX OF CURRENT HIT IN SEQUENCE.
373  double amplitude(0), position(0); //FIT PARAMETERS.
374  double start(0), end(0);
375  double amplitudeErr(0), positionErr(0); //FIT ERRORS.
376  double goodnessOfFit(0), chargeErr(0); //CHI2/NDF and error on charge.
377  double hrms(0);
378 
379  numHits = maxTimes.size();
380  for (int i = 0; i < numHits; ++i) {
381  amplitude = peakHeight[i];
382  position = maxTimes[i];
383  start = startTimes[i];
384  end = endTimes[i];
385  hrms = hitrms[i];
386  amplitudeErr = -1;
387  positionErr = 1.0;
388  goodnessOfFit = -1;
389  chargeErr = -1;
390  totSig = charge[i];
391 
392  std::vector<geo::WireID> wids = geom->ChannelToWire(channel);
393  geo::WireID wid = wids[0];
394 
395  if (start >= end) {
396  mf::LogWarning("RawHitFinder_module")
397  << "Hit start " << start << " is >= hit end " << end;
398  continue;
399  }
400 
401  recob::HitCreator hit(*digitVec, //RAW DIGIT REFERENCE.
402  wid, //WIRE ID.
403  start, //START TICK.
404  end, //END TICK.
405  hrms, //RMS.
406  position, //PEAK_TIME.
407  positionErr, //SIGMA_PEAK_TIME.
408  amplitude, //PEAK_AMPLITUDE.
409  amplitudeErr, //SIGMA_PEAK_AMPLITUDE.
410  totSig, //HIT_INTEGRAL.
411  chargeErr, //HIT_SIGMA_INTEGRAL.
412  std::accumulate(holder.begin() + (int)start,
413  holder.begin() + (int)end,
414  0.), //SUMMED CHARGE.
415  1, //MULTIPLICITY.
416  -1, //LOCAL_INDEX.
417  goodnessOfFit, //WIRE ID.
418  int(end - start + 1) //DEGREES OF FREEDOM.
419  );
420  hcol.emplace_back(hit.move(), digitVec);
421 
422  ++hitIndex;
423  }
424  }
425 
426  hcol.put_into(evt);
427  }
428 
430 
431 } // end namespace hit
float GetPedestal() const
Definition: RawDigit.h:221
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:209
void produce(art::Event &evt) override
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:217
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:213
std::vector< double > fAreaNorms
Definition of basic raw digits.
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.cxx:248
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
Class managing the creation of a new recob::Hit object.
Definition: HitCreator.h:87
Helper functions to create a hit.
A class handling a collection of hits and its associations.
Definition: HitCreator.h:481
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Signal from induction planes.
Definition: geo_types.h:151
void reserve(size_t new_size)
Prepares the collection to host at least new_size hits.
Definition: HitCreator.h:600
enum geo::_plane_sigtype SigType_t
Enumerate the possible plane projections.
Collect all the RawData header files together.
RawHitFinder(fhicl::ParameterSet const &pset)
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
Definition: HitCreator.cxx:286
float bin[41]
Definition: plottest35.C:14
Definition of data types for geometry description.
void put_into(art::Event &)
Moves the data into an event.
Definition: HitCreator.h:614
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:229
SigType_t SignalType(PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string fCalDataModuleLabel
art::InputTag fDigitModuleLabel
TCEvent evt
Definition: DataStructs.cxx:8
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:744
art framework interface to geometry description
Signal from collection planes.
Definition: geo_types.h:152