CalGausHFDUNE10kt_module.cc
Go to the documentation of this file.
1 #ifndef CALGAUSHFDUNE10KT_H
2 #define CALGAUSHFDUNE10KT_H
3 
4 ////////////////////////////////////////////////////////////////////////
5 //
6 // CalGausHFDUNE10kt class
7 //
8 // jti3@fnal.gov
9 //
10 // 06-21-13 Branched from CalWire_module and added GausHitFinder_module code
11 //
12 // brebel@fnal.gov
13 //
14 // 11-3-09 Pulled all FFT code out and put into Utilitiess/LArFFT
15 //
16 ////////////////////////////////////////////////////////////////////////
17 
18 #include <string>
19 #include <vector>
20 #include <algorithm> // std::accumulate
21 #include <utility> // std::move
22 
29 #include "fhiclcpp/ParameterSet.h"
31 #include "cetlib_except/exception.h"
32 
34 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
38 #include "lardataobj/RawData/raw.h"
42 
43 // ROOT Includes
44 #include "TH1D.h"
45 #include "TDecompSVD.h"
46 #include "TMath.h"
47 #include "TComplex.h"
48 #include "TFile.h"
49 #include "TH2D.h"
50 #include "TF1.h"
51 #include "TTree.h"
52 
53 /* unused function
54 namespace{
55  // Fill histogram from vector (set underflow/overflow bins to zero).
56 
57  void vector_to_hist(const std::vector<double>& v, TH1D* h)
58  {
59  if (!h) throw cet::exception("vector_to_hist") << "no histogram specified\n";
60  int nvec = v.size();
61  int nbins = h->GetNbinsX();
62  int nfill = std::min(nvec, nbins);
63  h->SetBinContent(0, 0.);
64  int zerobin = h->GetXaxis()->FindBin(0.);
65  for(int i=1; i<=nfill; ++i) {
66  if(i >= zerobin)
67  h->SetBinContent(i, v[i - zerobin]);
68  else
69  h->SetBinContent(i, v[i - zerobin + nvec]);
70  }
71  for(int i=nfill+1; i<=nbins+1; ++i)
72  h->SetBinContent(i, 0.);
73  }
74 
75 }
76 */
77 
78 ///creation of calibrated signals on wires
79 namespace calgaushf {
80 
82 
83  public:
84 
85  // create calibrated signals on wires. this class runs
86  // an fft to remove the electronics shaping.
87  explicit CalGausHFDUNE10kt(fhicl::ParameterSet const& pset);
88  virtual ~CalGausHFDUNE10kt();
89 
90  void produce(art::Event& evt);
91  void beginJob();
92  void endJob();
93  void reconfigure(fhicl::ParameterSet const& p);
94 
95  private:
96  int fDeconvKernSize; //< Length of truncated deconvolution kernel
97  //int fDataSize; ///< size of raw data on one wire // unused
98  int fPostsample; ///< number of postsample bins
99  std::string fDigitModuleLabel; ///< module that made digits
100  ///< constants
101  std::string fSpillName; ///< nominal spill is an empty string
102  ///< it is set by the DigitModuleLabel
103  ///< ex.: "daq:preSpill" for prespill data
105  double fMinSigInd; ///<Induction signal height threshold
106  double fMinSigCol; ///<Collection signal height threshold
107  double fIndWidth; ///<Initial width for induction fit
108  double fColWidth; ///<Initial width for collection fit
109  double fIndMinWidth; ///<Minimum induction hit width
110  double fColMinWidth; ///<Minimum collection hit width
111  int fMaxMultiHit; ///<maximum hits for multi fit
112  int fAreaMethod; ///<Type of area calculation
113  std::vector<double> fAreaNorms; ///<factors for converting area to same units as peak height
114  double fChi2NDF; ///maximum Chisquared / NDF allowed for a hit to be saved
115 
116  //double WireNumber[100000];
117  //double TotalSignal[100000];
118  double StartIime;
120  double EndTime;
121  double EndTimeError;
122  double RMS;
124  double MeanPosition;
125  double MeanPosError;
126  double Amp;
127  double AmpError;
128  double Charge;
129  double ChargeError;
130  double FitGoodnes;
131  int FitNDF;
132 
133  protected:
134 
135  }; // class CalGausHFDUNE10kt
136 
138 
139  //-------------------------------------------------
141  {
142  fSpillName="";
143  this->reconfigure(pset);
144 
145  // let HitCollectionCreator declare that we are going to produce
146  // hits and associations with wires and raw digits
148  (producesCollector(), fSpillName, false /* doWireAssns */, true /* doRawDigitAssns */);
149 
150  }
151 
152  //-------------------------------------------------
154  {
155  }
156 
157  //////////////////////////////////////////////////////
159  {
160  fDigitModuleLabel = p.get< std::string >("DigitModuleLabel", "daq");
161  fPostsample = p.get< int > ("PostsampleBins");
162  fDeconvKernSize = p.get< int > ("DeconvKernSize");
163 
164  fSpillName="";
165 
166  size_t pos = fDigitModuleLabel.find(":");
167  if( pos!=std::string::npos ) {
168  fSpillName = fDigitModuleLabel.substr( pos+1 );
169  fDigitModuleLabel = fDigitModuleLabel.substr( 0, pos );
170  }
171 
172  // Implementation of optional member function here.
173  //fCalDataModuleLabel = p.get< std::string >("CalDataModuleLabel");
174  fMinSigInd = p.get< double >("MinSigInd");
175  fMinSigCol = p.get< double >("MinSigCol");
176  fIndWidth = p.get< double >("IndWidth");
177  fColWidth = p.get< double >("ColWidth");
178  fIndMinWidth = p.get< double >("IndMinWidth");
179  fColMinWidth = p.get< double >("ColMinWidth");
180  fMaxMultiHit = p.get< int >("MaxMultiHit");
181  fAreaMethod = p.get< int >("AreaMethod");
182  fAreaNorms = p.get< std::vector< double > >("AreaNorms");
183  fChi2NDF = p.get< double >("Chi2NDF");
184 
185 
186  }
187 
188  //-------------------------------------------------
190  {
191  }
192 
193  //////////////////////////////////////////////////////
195  {
196  }
197 
198  //////////////////////////////////////////////////////
200  {
201  // get the geometry
203 
204  // Get signal shaping service.
206 
207 
208  //Gaussian hit finder initializations etc.
209  TH1::AddDirectory(kFALSE);
210 
211 
212  // ---------------------------
213  // --- Seed Fit Functions --- (This function used to "seed" the mean peak position)
214  // ---------------------------
215  TF1 *hit = new TF1("hit","gaus",0,3200); // FIXME use DetectorProperties
216 
217  // ###############################################
218  // ### Making a ptr vector to put on the event ###
219  // ###############################################
220  // this contains the hit collection
221  // and its associations to raw digits (not to wires)
223  evt, fSpillName, false /* doWireAssns */, true /* doRawDigitAssns */
224  );
225 
226 
227  // ##########################################
228  // ### Reading in the Wire List object(s) ###
229  // ##########################################
230  //auto wireVecHandle = evt.getHandle< std::vector<recob::Wire> >(fCalDataModuleLabel);
231  //art::ServiceHandle<geo::Geometry> geom;
232 
233  // #########################################################
234  // ### List of useful variables used throughout the code ###
235  // #########################################################
236  double threshold = 0.; // minimum signal size for id'ing a hit
237  double fitWidth = 0.; //hit fit width initial value
238  double minWidth = 0.; //minimum hit width
239  //channel = 0; // channel number
240  geo::SigType_t sigType; // Signal Type (Collection or Induction)
241  geo::View_t view; // view
242  std::vector<int> startTimes; // stores time of 1st local minimum
243  std::vector<int> maxTimes; // stores time of local maximum
244  std::vector<int> endTimes; // stores time of 2nd local minimum
245  int time = 0; // current time bin
246  int minTimeHolder = 0; // current start time
247 
248  std::string eqn = "gaus(0)"; // string for equation for gaus fit
249  //std::string seed = "gaus(0)"; // string for equation seed gaus fit
250 
251 
252  bool maxFound = false; // Flag for whether a peak > threshold has been found
253  std::stringstream numConv;
254 
255 
256  // Read in the digit List object(s).
258 
260  if (fSpillName.size()>0) digitVecHandle = evt.getHandle< std::vector<raw::RawDigit> >(itag1);
261  else digitVecHandle = evt.getHandle< std::vector<raw::RawDigit> >(fDigitModuleLabel);
262 
263  if (!digitVecHandle->size()) return;
264  mf::LogInfo("CalGausHFDUNE10kt") << "CalGausHFDUNE10kt:: digitVecHandle size is " << digitVecHandle->size();
265 
266  // Use the handle to get a particular (0th) element of collection.
267  art::Ptr<raw::RawDigit> digitVec0(digitVecHandle, 0);
268 
269  if (digitVec0->Compression() != raw::kZeroSuppression) {
271  << "CalGausHFDUNE only supports zero-suppressed raw digit input!";
272  } // if
273 
274 
275  raw::ChannelID_t channel = raw::InvalidChannelID; // channel number
276  unsigned int bin(0); // time bin loop variable
277 
278  filter::ChannelFilter *chanFilt = new filter::ChannelFilter();
279 
280  std::vector<float> holder; // holds signal data
281  std::vector<float> rawadc_conv; // holds signal data before time domain deconvolution
282  std::vector<short> rawadc; // vector holding uncompressed adc values
283 
284  // loop over all wires
285  for(size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter){ // ++ move
286  holder.clear();
287 
288  // get the reference to the current raw::RawDigit
289  art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
290  channel = digitVec->Channel();
291 
292  // skip bad channels
293  if(!chanFilt->BadChannel(channel)) {
294 
295 
296  const int numberofblocks = digitVec->ADC(1);
297 
298  int zerosuppressedindex = numberofblocks*2 + 2;
299 
300  //loop over all nonzero blocks
301  for(int i=0; i<numberofblocks; i++){
302 
303  const int lengthofblock = digitVec->ADC(2+numberofblocks+i);
304  rawadc.resize(lengthofblock);
305  holder.resize(lengthofblock);
306  rawadc_conv.resize(lengthofblock);
307 
308  for (int j=0;j<lengthofblock;j++)
309  {
310  rawadc[j] = digitVec->ADC(zerosuppressedindex);
311  zerosuppressedindex++;
312  }
313 
314 
315 
316  // loop over all adc values and subtract the pedestal
317  for(bin = 0; bin < rawadc.size(); ++bin)
318  rawadc_conv[bin]=(rawadc[bin]-digitVec->GetPedestal());
319 
320 
321  sigType = geom->SignalType(channel);
322  view = geom->View(channel);
323 
324  if(sigType == geo::kCollection){
325 
326  //Leave collection plane signals as is
327  for(bin = 0; bin < rawadc_conv.size(); ++bin)
328  holder[bin] = rawadc_conv[bin];
329  }
330  else if(sigType == geo::kInduction){
331 
332  //Integrate over signal in induction planes
333  for(bin = 0; bin < rawadc_conv.size(); ++bin)
334  holder[bin] = (bin>0) ? rawadc_conv[bin] + holder[bin-1] : rawadc_conv[bin];
335  }
336 
337 
338 
339  //Beginning of Gaussian hit finder loop over signal blocks
340 
341 
342  //##############################
343  //### Looping over the wires ###
344  //##############################
345 
346  //for(size_t wireIter = 0; wireIter < wirecol->size(); wireIter++){
347 
348  //art::Ptr<recob::Wire> wire(wirecol, wireIter);
349 
350  //std::vector<recob::Wire>::iterator wire;
351  //for(wire=wirecol->begin(); wire != wirecol->end(); wire++){
352  // --- Setting Channel Number and Wire Number as well as signal type ---
353  //channel = wire->RawDigit()->Channel();
354 
355 
356  // -----------------------------------------------------------
357  // -- Clearing variables at the start of looping over wires --
358  // -----------------------------------------------------------
359  startTimes.clear();
360  maxTimes.clear();
361  endTimes.clear();
362  //std::vector<float> signal(wire->Signal());
363  std::vector<float> signal(holder);
364  std::vector<float>::iterator timeIter; // iterator for time bins
365  time = 0;
366  minTimeHolder = 0;
367  maxFound = false;
368  // -- Setting the appropriate signal widths and thresholds --
369  // -- for either the collection or induction plane --
370  if(sigType == geo::kInduction){
371  threshold = fMinSigInd;
372  fitWidth = fIndWidth;
373  minWidth = fIndMinWidth;
374  }//<-- End if Induction Plane
375  else if(sigType == geo::kCollection){
376  threshold = fMinSigCol;
377  fitWidth = fColWidth;
378  minWidth = fColMinWidth;
379  }//<-- End if Collection Plane
380 
381 
382  // ##################################
383  // ### Looping over Signal Vector ###
384  // ##################################
385  for(timeIter = signal.begin();timeIter+2<signal.end();timeIter++){
386  // ##########################################################
387  // ### LOOK FOR A MINIMUM ###
388  // ### Testing if the point timeIter+1 is at a minimum by ###
389  // ### checking if timeIter and timeIter+1 and if it is ###
390  // ### then we add this to the endTimes ###
391  // ##########################################################
392  if(*timeIter > *(timeIter+1) && *(timeIter+1) < *(timeIter+2)){
393  //--- Note: We only keep the a minimum if we've already ---
394  //--- found a point above threshold ---
395  if(maxFound){
396  endTimes.push_back(time+1);
397  maxFound = false;
398  //keep these in case new hit starts right away
399  minTimeHolder = time+2;
400  }
401  else minTimeHolder = time+1;
402 
403  }//<---End Checking if this is a minimum
404 
405 
406  // ########################################################
407  // ### Testing if the point timeIter+1 is a maximum and ###
408  // ### if it and is above threshold then we add it to ###
409  // ### the startTime ###
410  // ########################################################
411  //if not a minimum, test if we are at a local maximum
412  //if so, and the max value is above threshold, add it and proceed.
413  else if(*timeIter < *(timeIter+1) && *(timeIter+1) > *(timeIter+2) && *(timeIter+1) > threshold){
414  maxFound = true;
415  maxTimes.push_back(time+1);
416  startTimes.push_back(minTimeHolder);
417  }
418 
419  time++;
420 
421  }//end loop over signal vec
422 
423  // ###########################################################
424  // ### If there was no minimum found before the end, but a ###
425  // ### maximum was found then add an end point to the end ###
426  // ###########################################################
427  while( maxTimes.size() > endTimes.size() ){
428  endTimes.push_back(signal.size()-1);
429 
430  }//<---End maxTimes.size > endTimes.size
431 
432  // ####################################################
433  // ### If no startTime hit was found skip this wire ###
434  // ####################################################
435  if( startTimes.size() == 0 ){
436  continue;
437  }
438 
439  /////////////////////////////////////////////////////////////////////////////
440  /////////////////////////////////////////////////////////////////////////////
441 
442  // ##########################################################
443  // ### PERFORM THE FITTING, ADDING HITS TO THE HIT VECTOR ###
444  // ##########################################################
445 
446  //All code below does the fitting, adding of hits
447  //to the hit vector and when all wires are complete
448  //saving them
449 
450  double totSig(0); //stores the total hit signal
451  double startT(0); //stores the start time
452  double endT(0); //stores the end time
453  int numHits(0); //number of consecutive hits being fitted
454  int size(0); //size of data vector for fit
455  int hitIndex(0); //index of current hit in sequence
456  double amplitude(0); //fit parameters
457  double minPeakHeight(0); //lowest peak height in multi-hit fit
458 
459 
460  StartIime = 0; // stores the start time of the hit
461  StartTimeError = 0; // stores the error assoc. with the start time of the hit
462  EndTime = 0; // stores the end time of the hit
463  EndTimeError = 0; // stores the error assoc. with the end time of the hit
464  RMS = 0; // stores the RMS from the gaussian fit
465  MeanPosition = 0; // stores the peak time position of the hit
466  MeanPosError = 0; // stores the error assoc. with thte peak time of the hit
467  Charge = 0; // stores the total charge assoc. with the hit
468  ChargeError = 0; // stores the error on the charge
469  Amp = 0; // stores the amplitude of the hit
470  AmpError = 0; // stores the error assoc. with the amplitude
471  NumOfHits = 0; // stores the multiplicity of the hit
472  FitGoodnes = 0; // stores the Chi2/NDF of the hit
473  FitNDF = -1; // stores the NDF of the hit
474 
475 
476 
477  //stores gaussian paramters first index is the hit number
478  //the second refers to height, position, and width respectively
479  std::vector<double> hitSig;
480 
481  // ########################################
482  // ### Looping over the hitIndex Vector ###
483  // ########################################
484  while( hitIndex < (signed)startTimes.size() ) {
485  // --- Zeroing Start Times and End Times ---
486  startT = 0;
487  endT = 0;
488  // Note: numHits is hardcoded to one here (Need to fix!)
489  numHits=1;
490 
491  minPeakHeight = signal[maxTimes[hitIndex]];
492 
493  // consider adding pulse to group of consecutive hits if:
494  // 1 less than max consecutive hits
495  // 2 we are not at the last point in the signal vector
496  // 3 the height of the dip between the two is greater than threshold/2
497  // 4 and there is no gap between them
498  while(numHits < fMaxMultiHit && numHits+hitIndex < (signed)endTimes.size() &&
499  signal[endTimes[hitIndex+numHits-1]] >threshold/2.0 &&
500  startTimes[hitIndex+numHits] - endTimes[hitIndex+numHits-1] < 2){
501  if(signal[maxTimes[hitIndex+numHits]] < minPeakHeight){
502  minPeakHeight=signal[maxTimes[hitIndex+numHits]];
503 
504  }//<---Only move the mean peakHeight in this hit
505 
506  numHits++;//<---Interate the multihit function
507 
508  }//<---End multihit while loop
509 
510 
511 
512  // ###########################################################
513  // ### Finding the first point from the beginning (startT) ###
514  // ### which is greater then 1/2 the smallest peak ###
515  // ###########################################################
516  startT=startTimes[hitIndex];
517  while(signal[(int)startT] < minPeakHeight/2.0) {startT++;}
518 
519  // #########################################################
520  // ### Finding the first point from the end (endT) which ###
521  // ### is greater then 1/2 the smallest peak ###
522  // #########################################################
523  endT=endTimes[hitIndex+numHits-1];
524  while(signal[(int)endT] <minPeakHeight/2.0) {endT--;}
525 
526 
527  // ###############################################################
528  // ### Putting the current considered hit into a 1-D Histogram ###
529  // ###############################################################
530  //--- Size of hit = endT - startT ---
531  size = (int)(endT-startT);
532 
533  // ###########################################################################
534  // ### Bug Fix: For ADC counts occuring at the end of the ticks range ###
535  // ### the hitfinder incorrectly assigns the size of the hit as a negative ###
536  // ### number...so we fix this to be 0 so that this hit is skipped ###
537  // ###########################################################################
538  if(size < 0){size = 0;}
539 
540 
541  // --- TH1D HitSignal ---
542  TH1D hitSignal("hitSignal","",size,startT,endT);
543 
544  for(int i = (int)startT; i < (int)endT; i++){
545  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
546  // ~~~ Filling the pulse signals into TH1D histograms ~~~
547  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
548  hitSignal.Fill(i,signal[i]);
549 
550  //std::cout<<"i = "<<i<<" , signal[i] = "<<signal[i]<<std::endl;
551  }//<---End for looping over startT and endT
552 
553 
554  // ##################################################################################################
555  // ### Trying to utilize the old approach of builing my TF1 and then implementing this new method ###
556  // ##################################################################################################
557 
558  // ########################################################
559  // ### Building TFormula for seedHit and basic Gaussian ###
560  // ########################################################
561  eqn = "gaus(0)";
562  for(int i = 3; i < numHits*3; i+=3){
563  eqn.append("+gaus(");
564  numConv.str("");
565  numConv << i;
566  eqn.append(numConv.str());
567  eqn.append(")");
568  }
569 
570 
571 
572  // --- TF1 function for GausHit ---
573  TF1 Gaus("Gaus",eqn.c_str(),0,size);
574 
575  // ##############################################################################
576  // ### For multi-pulse hits we loop over all the hits and fit N Gaus function ###
577  // ##############################################################################
578  if(numHits > 1) {
579  // --- Loop over numHits ---
580  for(int i = 0; i < numHits; ++i){
581 
582  // ###################################################################
583  // ### Set the parameters of the Gaus hit based on the seedHit fit ###
584  // ###################################################################
585  //amplitude = 0.5*(threshold+signal[maxTimes[hitIndex+i]]);
586 
587  amplitude = signal[maxTimes[hitIndex+i]];
588  Gaus.SetParameter(3*i,amplitude);
589  Gaus.SetParameter(1+3*i, maxTimes[hitIndex+i]);
590  Gaus.SetParameter(2+3*i, fitWidth);
591  Gaus.SetParLimits(3*i, 0.0, 3.0*amplitude);
592  Gaus.SetParLimits(1+3*i, startT , endT);
593  Gaus.SetParLimits(2+3*i, 0.0, 10.0*fitWidth);
594  }//end loop over hits
595  }//end if numHits > 1
596 
597  // ######################################################################
598  // ### For single pulse hits we perform a fit using a single Gaussian ###
599  // ######################################################################
600  else{
601 
602  Gaus.SetParameters(signal[maxTimes[hitIndex]],maxTimes[hitIndex],fitWidth);
603  Gaus.SetParLimits(0,0.0,1.5*signal[maxTimes[hitIndex]]);
604  Gaus.SetParLimits(1, startT , endT);
605  Gaus.SetParLimits(2,0.0,10.0*fitWidth);
606  }
607 
608  // ####################################################
609  // ### PERFORMING THE TOTAL GAUSSIAN FIT OF THE HIT ###
610  // ####################################################
611  hitSignal.Sumw2();
612 
613  hitSignal.Fit(&Gaus,"QNRW","", startT, endT);
614  //hitSignal.Fit(&Gaus,"QR0LLi","", startT, endT);
615 
616 
617  for(int hitNumber = 0; hitNumber < numHits; ++hitNumber){
618  totSig = 0;
619 
620 
621  // ###########################################################
622  // ### Record this hit if the amplitude is > threshold/2.0 ###
623  // ### and the width is > minWidth ###
624  // ###########################################################
625  if(Gaus.GetParameter(3*hitNumber) > threshold/2.0 &&
626  Gaus.GetParameter(3*hitNumber+2) > minWidth){
627  StartIime = Gaus.GetParameter(3*hitNumber+1) - Gaus.GetParameter(3*hitNumber+2); // position - width
628 
629  EndTime = Gaus.GetParameter(3*hitNumber+1) + Gaus.GetParameter(3*hitNumber+2); // position + width
630 
631  MeanPosition = Gaus.GetParameter(3*hitNumber+1);
632  StartIime = Gaus.GetParameter(3*hitNumber+2); // width
633 
634  //StartTimeError = TMath::Sqrt( (Gaus.GetParError(3*hitNumber+1)*Gaus.GetParError(3*hitNumber+1)) +
635  // (Gaus.GetParError(3*hitNumber+2)*Gaus.GetParError(3*hitNumber+2)));
636 
637  //EndTimeError = TMath::Sqrt( (Gaus.GetParError(3*hitNumber+1)*Gaus.GetParError(3*hitNumber+1)) +
638  // (Gaus.GetParError(3*hitNumber+2)*Gaus.GetParError(3*hitNumber+2)));
639 
640 
641  //MeanPosError = Gaus.GetParError(3*hitNumber+1);
642 
643 
644 
645 
646  hitSig.resize(size);
647  for(int sigPos = 0; sigPos<size; sigPos++){ //<---Loop over the size (endT - startT)
648 
649  hitSig[sigPos] = Gaus.GetParameter(3*hitNumber)*TMath::Gaus(sigPos+startT,Gaus.GetParameter(3*hitNumber+1), Gaus.GetParameter(3*hitNumber+2));
650  totSig+=hitSig[(int)sigPos];
651 
652  }//<---End Signal postion loop
653 
654  // --- Getting the total charge using the area method ---
655  if(fAreaMethod) {
656  totSig = std::sqrt(2*TMath::Pi())*Gaus.GetParameter(3*hitNumber)*Gaus.GetParameter(3*hitNumber+2)/fAreaNorms[(size_t)sigType];
657 
658  }//<---End Area Method
659  Charge = totSig;
660  // ---------------------------------------------------------------------------------
661  // --- chargeErr=TMath::Sqrt(TMath::Pi())*(amplitudeErr*width+widthErr*amplitude); ---
662  // -----------------------------------------------------------------------------------
663  ChargeError = TMath::Sqrt(TMath::Pi())*(Gaus.GetParError(3*hitNumber+0)*Gaus.GetParameter(3*hitNumber+2)+
664  Gaus.GetParError(3*hitNumber+2)*Gaus.GetParameter(3*hitNumber+0)); //estimate from area of Gaussian
665  Amp = Gaus.GetParameter(3*hitNumber);
666  AmpError = Gaus.GetParError(3*hitNumber);
667  NumOfHits = numHits;
668 
669  // #######################################################
670  // ### Using seeded values to get a better estimate of ###
671  // ### the errors associated with the fit ###
672  // #######################################################
673  // -----------------------------------------
674  // --- Determing the goodness of the fit ---
675  // -----------------------------------------
676  hit->SetParameters(Amp,MeanPosition, Gaus.GetParameter(3*hitNumber+2));
677  hit->FixParameter(0,Amp);
678  //hit->SetParLimits(0,Amp/2, Amp*2);
679  //hit->FixParameter(1,MeanPosition);
680  hit->SetParLimits(1,MeanPosition - 3, MeanPosition + 3);
681  //hit->FixParameter(2,Gaus.GetParameter(3*hitNumber+2));//<---Should I be setting the fitWidth initally
682  // #############################
683  // ### Perform Hit on Signal ###
684  // #############################
685 
686 
687  float TempStartTime = MeanPosition - 4;
688  float TempEndTime = MeanPosition + 4;
689 
690  hitSignal.Fit(hit,"QNRLLi","", TempStartTime, TempEndTime);
691 
692 
693  FitGoodnes = hit->GetChisquare() / hit->GetNDF();
694  FitNDF = hit->GetNDF();
695 
696  StartTimeError = TMath::Sqrt( (hit->GetParError(1)*hit->GetParError(1)) +
697  (hit->GetParError(2)*hit->GetParError(2)));
698 
699  EndTimeError = TMath::Sqrt( (hit->GetParError(1)*hit->GetParError(1)) +
700  (hit->GetParError(2)*hit->GetParError(2)));
701 
702 
703  MeanPosError = hit->GetParError(1);
704 
705  // ####################################################################################
706  // ### Skipping hits with a chi2/NDF larger than the value defined in the .fcl file ###
707  // ####################################################################################
708  if(FitGoodnes > fChi2NDF){continue;}
709 
710  // get the WireID for this hit
711  std::vector<geo::WireID> wids = geom->ChannelToWire(channel);
712  ///\todo need to have a disambiguation algorithm somewhere in here
713  // for now, just take the first option returned from ChannelToWire
714  geo::WireID wid = wids[0];
715 
716  recob::Hit hit(
717  channel, // channel
718  (raw::TDCtick_t) startT, // start_tick
719  (raw::TDCtick_t) endT, // end_tick
720  MeanPosition, // peak_time
721  MeanPosError, // sigma_peak_time
722  RMS, // rms,
723  Amp, // peak_amplitude,
724  AmpError, // sigma_peak_amplitude
725  std::accumulate // summedADC
726  (signal.begin() + TempStartTime, signal.begin() + TempEndTime, 0.),
727  Charge, // hit_integral
728  ChargeError, // hit_sigma_integral
729  NumOfHits, // multiplicity
730  hitNumber, // local_index
731  FitGoodnes, // goodness_of_fit
732  FitNDF, // dof
733  view, // view
734  sigType, // signal_type
735  wid // wireID
736  );
737  hcol.emplace_back(std::move(hit), digitVec);
738 
739  }//<---End looking at hits over threshold
740 
741  }//<---End Looping over numHits
742 
743 
744  hitIndex+=numHits;
745  }//<---End while hitIndex < startTimes.size()
746 
747 
748 
749  //}//<---End looping over wireIter
750 
751 
752  //std::cout << "Test1" << std::endl;
753 
754 
755  } // end loop over nonzero blocks
756 
757 
758  } // end if not a bad channel
759 
760 
761  } // end loop over wires
762 
763  // move the hit collection and the associations into the event
764  hcol.put_into(evt);
765 
766  delete chanFilt;
767 
768 
769  return;
770  }
771 
772 } // end namespace calgaushf
773 
774 
775 #endif // CALGAUSHFDUNE10KT_H
float GetPedestal() const
Definition: RawDigit.h:214
intermediate_table::iterator iterator
double fIndWidth
Initial width for induction fit.
short ADC(int i) const
ADC vector element number i; no decompression is applied.
Definition: RawDigit.h:208
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool BadChannel(uint32_t channel) const
double fColMinWidth
Minimum collection hit width.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
double fColWidth
Initial width for collection fit.
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
uint8_t channel
Definition: CRTFragment.hh:201
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
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
art framework interface to geometry description
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
double fIndMinWidth
Minimum induction hit width.
Zero Suppression algorithm.
Definition: RawTypes.h:11
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Helper functions to create a hit.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
A class handling a collection of hits and its associations.
Definition: HitCreator.h:508
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
Signal from induction planes.
Definition: geo_types.h:145
enum geo::_plane_sigtype SigType_t
def move(depos, offset)
Definition: depos.py:107
T get(std::string const &key) const
Definition: ParameterSet.h:271
int fPostsample
number of postsample bins
p
Definition: test.py:223
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:290
CalGausHFDUNE10kt(fhicl::ParameterSet const &pset)
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
void put_into(art::Event &)
Moves the data into an event.
Definition: HitCreator.h:652
double fMinSigCol
Collection signal height threshold.
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
int fMaxMultiHit
maximum hits for multi fit
void reconfigure(fhicl::ParameterSet const &p)
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Declaration of signal hit object.
double fMinSigInd
Induction signal height threshold.
QTextStream & bin(QTextStream &s)
double StartIime
maximum Chisquared / NDF allowed for a hit to be saved
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
int fAreaMethod
Type of area calculation.
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< double > fAreaNorms
factors for converting area to same units as peak height
creation of calibrated signals on wires
Signal from collection planes.
Definition: geo_types.h:146