Public Member Functions | Private Member Functions | Private Attributes | List of all members
novaddt::WaveformProcessor Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-05-06/DDTCore/WaveformProcessor.h"

Public Member Functions

 WaveformProcessor (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
 ~WaveformProcessor ()
 
void postBeginRun (art::Run const &run)
 
void reconfigure (const fhicl::ParameterSet &pset)
 
void setup (daqdataformats::RawMicroSlice *theMicro, daqdataformats::RawNanoSlice *theNano)
 
void setup (uint32_t const &t0, uint64_t const &high_time, int16_t const &adc1, int16_t const &adc2, int16_t const &adc3, int16_t const &dcs)
 
TDC getTDC ()
 
ADC getADC ()
 

Private Member Functions

void process (uint32_t const &t0, uint64_t const &high_time, int16_t const &adc1, int16_t const &adc2, int16_t const &adc3, ADC &adcpeak, bool &goodTime, TDC &retval)
 
void initmulti ()
 
void initdcs ()
 

Private Attributes

bool fTableLoaded = false
 
std::array< uint8_t, kNumTableEntriesfTable
 
std::array< uint16_t, kNumTableEntriesfADCTable
 
std::bitset< kNumTableEntriesfGood
 
std::string fShapeTableFilename
 
const double fSampleTime
 
const double fRiseTime
 
const double fFallTime
 
daqdataformats::RawMicroSlicefMicro
 
daqdataformats::RawNanoSlicefNano
 
const bool fUseMulti
 
const bool fUseMulti4ADC
 
const bool fDoHighADCFits
 
TDC fTDC
 
ADC fADC
 

Detailed Description

Definition at line 68 of file WaveformProcessor.h.

Constructor & Destructor Documentation

novaddt::WaveformProcessor::WaveformProcessor ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry reg 
)

Definition at line 274 of file WaveformProcessor_service.cc.

References postBeginRun(), reconfigure(), and art::ActivityRegistry::sPostBeginRun.

276  : fSampleTime (pset.get< double > ("SampleTime"))
277  , fRiseTime (pset.get< double > ("RiseTime"))
278  , fFallTime (pset.get< double > ("FallTime"))
279  , fUseMulti (pset.get< bool > ("UseMulti"))
280  , fUseMulti4ADC(pset.get< bool > ("UseMulti4ADC"))
281  , fDoHighADCFits(pset.get< bool > ("DoHighADCFits"))
282  {
283  this->reconfigure(pset);
285  }
GlobalSignal< detail::SignalResponseType::LIFO, void(Run const &)> sPostBeginRun
void reconfigure(const fhicl::ParameterSet &pset)
void postBeginRun(art::Run const &run)
novaddt::WaveformProcessor::~WaveformProcessor ( )

Definition at line 287 of file WaveformProcessor_service.cc.

288  {
289  }

Member Function Documentation

ADC novaddt::WaveformProcessor::getADC ( )
inline
TDC novaddt::WaveformProcessor::getTDC ( )
inline
void novaddt::WaveformProcessor::initdcs ( )
private

Definition at line 482 of file WaveformProcessor_service.cc.

References DEFINE_ART_SERVICE, fADC, fMicro, fNano, novaddt::TDC::frac, fTDC, daqdataformats::RawMicroSlice::getHighWord(), and novaddt::TDC::val.

Referenced by getADC(), initmulti(), and setup().

482  { // initialize TDC and ADC members
483  //using dcs
484 
485  //auto trash = fMicro->getFloatingMicroSlice();
486  fTDC.val = ((uint64_t)fMicro->getHighWord() << 32)
487  | fNano->getTimeStamp();
488 
489  fTDC.frac = 0;
490  int16_t adc3 = (int16_t)fNano->getValue(3) - (int16_t)fNano->getValue(0);
491  if(adc3 > 0)
492  fADC = (ADC)adc3;
493  else
494  fADC = (ADC)0;
495 
496  }
fraction_type frac
Definition: BaseProducts.h:35
value_type val
Definition: BaseProducts.h:34
daqdataformats::RawNanoSlice * fNano
daqdataformats::RawMicroSlice * fMicro
uint32_t getHighWord() const
Get method for lower half of timing word.
void novaddt::WaveformProcessor::initmulti ( )
private

Definition at line 418 of file WaveformProcessor_service.cc.

References fADC, fMicro, fNano, fTDC, fUseMulti4ADC, daqdataformats::RawNanoSlice::getHeader(), daqdataformats::RawMicroSlice::getHighWord(), daqdataformats::NanoSliceVersionConvention::getNPretriggeredSamples(), daqdataformats::NanoSliceVersionConvention::getNSamples(), initdcs(), process(), getGoodRuns4SAM::t0, and novaddt::ADC::val.

Referenced by getADC(), and setup().

418  { // initialize TDC and ADC members
419  //using multipoint
420  //check that multipoint can be used
421  const uint32_t version = fNano->getHeader()->getVersion();
422 
424 
425  const unsigned int nSamples = conv.getNSamples(version);
426  const unsigned int nPretrig = conv.getNPretriggeredSamples(version);
427 
428  if ( (nSamples < 3) || // too few samples
429  (nSamples <= nPretrig) || //missing peak
430  (version == 0) ) //non-multipoint
431  { initdcs(); return; }
432 
433 
434  TDC tempTDC;
435  ADC tempADC;
436  uint32_t t0 = fNano->getTimeStamp();
437  uint64_t high_time = (uint64_t) fMicro->getHighWord();
438  int16_t adc1 = (int16_t)fNano->getValue(1) - (int16_t)fNano->getValue(0);
439  int16_t adc2 = (int16_t)fNano->getValue(2) - (int16_t)fNano->getValue(0);
440  int16_t adc3 = (int16_t)fNano->getValue(3) - (int16_t)fNano->getValue(0);
441  bool goodTime = true;
442  process(t0, high_time, adc1, adc2, adc3, tempADC, goodTime, tempTDC);
443 
444  if(adc3 < 0) adc3 = 0; // Check if adc3 is negative, ADC is unsigned
445  if(tempADC.val < 0) tempADC = (ADC)0; // Check if adc3 is negative, ADC is unsigned
446  if(!fUseMulti4ADC) tempADC = (ADC)adc3;
447 
448  fTDC = tempTDC;
449  fADC = tempADC;
450  }
IMPLEMENT_MAIN_STANDARD IMPLEMENT_MAIN_setBufferSource daqdataformats::RawNanoSliceHeader * getHeader() const
Get the NanoSlice header pointer.
Definition: RawNanoSlice.h:57
void process(uint32_t const &t0, uint64_t const &high_time, int16_t const &adc1, int16_t const &adc2, int16_t const &adc3, ADC &adcpeak, bool &goodTime, TDC &retval)
daqdataformats::RawNanoSlice * fNano
uint32_t getNSamples(const version_t ver) const
Get the number of samples.
uint32_t getNPretriggeredSamples(const version_t ver) const
Get number of pretriggered samples.
const XML_Char * version
Definition: expat.h:187
daqdataformats::RawMicroSlice * fMicro
uint32_t getHighWord() const
Get method for lower half of timing word.
void novaddt::WaveformProcessor::postBeginRun ( art::Run const &  run)

Definition at line 301 of file WaveformProcessor_service.cc.

References ana::assert(), om::cout, allTimeWatchdog::endl, MakeMiniprodValidationCuts::f, fADCTable, fGood, fShapeTableFilename, fTable, fTableLoaded, fUseMulti, fUseMulti4ADC, update_sam_good_runs_metadata::good, novaddt::kNumTableEntries, novaddt::nTableLoads, PandAna.reco_validation.add_data::offset, and make_root_from_grid_output::tr.

Referenced by WaveformProcessor().

302  {
303  if (fUseMulti && !fTableLoaded) { //load the table if it doesn't already exist
304  nTableLoads++;
305  std::cout << "Loading table from file for " << nTableLoads << " time." << std::endl;
306  TFile f(fShapeTableFilename.c_str());
307  assert(!f.IsZombie());
308 
309  TTree* tr = (TTree*)f.Get("shape_lookup");
310  assert(tr);
311 
312  const unsigned int N = tr->GetEntries();
313  assert(N == kNumTableEntries);
314 
315  uint8_t offset;
316  bool good;
317  uint16_t adc;
318  tr->SetBranchAddress("offset", &offset);
319  tr->SetBranchAddress("good", &good);
320  if (fUseMulti4ADC)
321  tr->SetBranchAddress("adc", &adc);
322 
323  for (unsigned int n=0; n<N; n++){
324  tr->GetEntry(n);
325  fTable[n] = offset;
326  fGood[n] = good;
327  if (fUseMulti4ADC)
328  fADCTable[n] = adc;
329  }
330 
331  fTableLoaded = true;
332  } // end if (!fTableLoaded)
333  }
std::bitset< kNumTableEntries > fGood
static const unsigned int kNumTableEntries
std::void_t< T > n
std::array< uint16_t, kNumTableEntries > fADCTable
std::array< uint8_t, kNumTableEntries > fTable
OStream cout
Definition: OStream.cxx:6
unsigned int nTableLoads
assert(nhit_max >=nhit_nbins)
void novaddt::WaveformProcessor::process ( uint32_t const &  t0,
uint64_t const &  high_time,
int16_t const &  adc1,
int16_t const &  adc2,
int16_t const &  adc3,
ADC adcpeak,
bool &  goodTime,
TDC retval 
)
private

Definition at line 336 of file WaveformProcessor_service.cc.

References novaddt::ADCShapeFit(), ana::assert(), fADCTable, fDoHighADCFits, fFallTime, fGood, novaddt::TDC::frac, fRiseTime, fTable, fUseMulti4ADC, novaddt::kADC1Min, novaddt::kADC1RelMax, novaddt::kADC2Max, novaddt::kADC2Min, novaddt::kADC3Max, novaddt::kADC3Min, novaddt::kNumTableEntries, novaddt::NBitInt2Float(), PandAna.reco_validation.add_data::offset, and novaddt::TDC::val.

Referenced by getADC(), initmulti(), and setup().

340  {
341  uint8_t offset=0;
342 
343 
344  int16_t _adc1 = NBitInt2Float(adc1, 12, 5, 3);
345  int16_t _adc2 = NBitInt2Float(adc2, 12, 5, 3);
346  int16_t _adc3 = NBitInt2Float(adc3, 12, 5, 3);
347 
348  if(_adc3 >= kADC3Min && _adc3 < kADC3Max &&
349  _adc1 >= kADC1Min && _adc1 < _adc3+kADC1RelMax &&
350  _adc2 >= kADC2Min && _adc2 < kADC2Max){
351 
352  // And this is the offset it'll be at, based on aforementioned geometry
353  const int tableIdx = ((kADC2Max-kADC2Min)* // Wedge thickness
354  ((kADC3Min-kADC1Min)*(_adc3-kADC3Min+1) + // Rectangular part
355  kADC1RelMax*(_adc3-kADC3Min)+
356  ((_adc3-kADC3Min)*(_adc3-kADC3Min-1))/2+(_adc1-kADC3Min))+ // Triangular part
357  (_adc2-kADC2Min)); // Distance through wedge
358 
359  assert(tableIdx >= 0 && tableIdx < int(kNumTableEntries));
360  offset = fTable[tableIdx];
361  goodTime = fGood[tableIdx];
362 
363  }
364  else{
365  // It's not in our table, perform the fit if fDoHighADCFits is true
366  if(fDoHighADCFits)
367  offset = ADCShapeFit(adc1, adc2, adc3, fRiseTime, fFallTime, goodTime);
368  else{
369  offset = 0;
370  goodTime = false;
371  }
372  }
373 
374  // We need to extract the best normalization, so repeat the relevant part
375  // of the inner loop at that offset.
376  // --- For speed the normalization has been saved in a different table,
377  // --- the use of which is set as a fhicl parameter.
378  if(goodTime){
379  //Perform the normalization:
380  // The observations, in chronological order
381  //const int16_t obs[kNumFineTimingADCPoints] = {0, adc1, adc2, adc3};
382  //const double t0 = (double(offset)*kSamplesPerOffset+kZeroOffsetSamples);
383  //double junk[kNumFineTimingADCPoints]; // Expectations
384  //const double norm = GetExpectations(t0, fRiseTime, fFallTime, obs, junk);
385 
386  // The value the peak of the curve would have before scaling by norm
387  // Analytic calculation from the functional form in ReadoutSim
388  //static const double peak = pow(fRiseTime/(fRiseTime+fFallTime),
389  // fRiseTime/fFallTime)-pow(fRiseTime/(fRiseTime+fFallTime),
390  // 1+fRiseTime/fFallTime);
391  //adcpeak = norm*peak;
392 
393  if (fUseMulti4ADC) { //Extract from lookup table for speed:
394  // And this is the offset it'll be at, based on aforementioned geometry
395  const int tableIdx = ((kADC2Max-kADC2Min)* // Wedge thickness
396  ((kADC3Min-kADC1Min)*(_adc3-kADC3Min+1) + // Rectangular part
397  kADC1RelMax*(_adc3-kADC3Min)+
398  ((_adc3-kADC3Min)*(_adc3-kADC3Min-1))/2+(_adc1-kADC3Min))+ // Triangular part
399  (_adc2-kADC2Min)); // Distance through wedge
400 
401 
402 
403  adcpeak = fADCTable[tableIdx];
404  } // else case handled in initmulti()
405 
406  }
407  else{
408  // Unless the fit failed, in which case we're probably safest just doing
409  // this.
410  adcpeak = ADC(adc3);
411  }
412 
413  retval.val = (high_time<<32 | (t0 + (uint64_t)(offset *
415  retval.frac = (uint8_t)(offset%2 * 50);
416  }
static const int kADC1Min
static const int kADC2Min
static const int kADC3Min
const double kSamplesPerOffset
std::bitset< kNumTableEntries > fGood
static const int kADC1RelMax
static const unsigned int kNumTableEntries
std::array< uint16_t, kNumTableEntries > fADCTable
static const int kADC2Max
std::array< uint8_t, kNumTableEntries > fTable
unsigned int NBitInt2Float(float _input, int inputBits, int outputBitsMantisa, int outputBitsExpo)
assert(nhit_max >=nhit_nbins)
const unsigned int kNumTDCPerSample
static const int kADC3Max
uint8_t ADCShapeFit(int16_t adc1, int16_t adc2, int16_t adc3, double riseTime, double fallTime, bool &goodTime)
void novaddt::WaveformProcessor::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 292 of file WaveformProcessor_service.cc.

References ana::assert(), om::cout, allTimeWatchdog::endl, cet::search_path::find_file(), fShapeTableFilename, fhicl::ParameterSet::get(), and string.

Referenced by WaveformProcessor().

293  {
294  cet::search_path sp("FW_SEARCH_PATH");
295  sp.find_file(pset.get< std::string >("ShapeTableFilename"), fShapeTableFilename);
296  std::cout << pset.get< std::string > ("ShapeTableFilename") << std::endl;
297  assert(!fShapeTableFilename.empty());
298  }
T get(std::string const &key) const
Definition: ParameterSet.h:231
OStream cout
Definition: OStream.cxx:6
assert(nhit_max >=nhit_nbins)
enum BeamMode string
void novaddt::WaveformProcessor::setup ( daqdataformats::RawMicroSlice theMicro,
daqdataformats::RawNanoSlice theNano 
)
inline
void novaddt::WaveformProcessor::setup ( uint32_t const &  t0,
uint64_t const &  high_time,
int16_t const &  adc1,
int16_t const &  adc2,
int16_t const &  adc3,
int16_t const &  dcs 
)

Definition at line 452 of file WaveformProcessor_service.cc.

References fADC, fTDC, fUseMulti, fUseMulti4ADC, process(), getGoodRuns4SAM::t0, and novaddt::TDC::val.

455  {
456  // For use by RawDigit2DAQHit in the offline.
457  // dcs is identical to adc3 for 4-point readout
458  if (!fUseMulti) {
459  fTDC.val = high_time<<32 | t0;
460  fADC = ADC(dcs);
461  return;
462  }
463  bool goodTime = true;
464  TDC tempTDC;
465  ADC tempADC;
466  process(t0, high_time, adc1, adc2, adc3, tempADC, goodTime, tempTDC);
467  if (!goodTime) { // something's gone wrong with the fit, use DCS
468  fTDC.val = high_time<<32 | t0;
469  fADC = ADC(adc3);
470  return;
471  }
472  else {
473  fTDC = tempTDC;
474  if (fUseMulti4ADC)
475  fADC = tempADC;
476  else
477  fADC = ADC(adc3);
478 
479  }
480  }
value_type val
Definition: BaseProducts.h:34
void process(uint32_t const &t0, uint64_t const &high_time, int16_t const &adc1, int16_t const &adc2, int16_t const &adc3, ADC &adcpeak, bool &goodTime, TDC &retval)

Member Data Documentation

ADC novaddt::WaveformProcessor::fADC
private

Definition at line 119 of file WaveformProcessor.h.

Referenced by getADC(), initdcs(), initmulti(), and setup().

std::array<uint16_t, kNumTableEntries> novaddt::WaveformProcessor::fADCTable
private

Definition at line 106 of file WaveformProcessor.h.

Referenced by postBeginRun(), and process().

const bool novaddt::WaveformProcessor::fDoHighADCFits
private

Definition at line 117 of file WaveformProcessor.h.

Referenced by process().

const double novaddt::WaveformProcessor::fFallTime
private

Definition at line 112 of file WaveformProcessor.h.

Referenced by process().

std::bitset<kNumTableEntries> novaddt::WaveformProcessor::fGood
private

Definition at line 108 of file WaveformProcessor.h.

Referenced by postBeginRun(), and process().

daqdataformats::RawMicroSlice* novaddt::WaveformProcessor::fMicro
private

Definition at line 113 of file WaveformProcessor.h.

Referenced by initdcs(), initmulti(), and setup().

daqdataformats::RawNanoSlice* novaddt::WaveformProcessor::fNano
private

Definition at line 114 of file WaveformProcessor.h.

Referenced by initdcs(), initmulti(), and setup().

const double novaddt::WaveformProcessor::fRiseTime
private

Definition at line 111 of file WaveformProcessor.h.

Referenced by process().

const double novaddt::WaveformProcessor::fSampleTime
private

Definition at line 110 of file WaveformProcessor.h.

std::string novaddt::WaveformProcessor::fShapeTableFilename
private

Definition at line 109 of file WaveformProcessor.h.

Referenced by postBeginRun(), and reconfigure().

std::array<uint8_t, kNumTableEntries> novaddt::WaveformProcessor::fTable
private

Definition at line 102 of file WaveformProcessor.h.

Referenced by postBeginRun(), and process().

bool novaddt::WaveformProcessor::fTableLoaded = false
private

Definition at line 101 of file WaveformProcessor.h.

Referenced by postBeginRun().

TDC novaddt::WaveformProcessor::fTDC
private

Definition at line 118 of file WaveformProcessor.h.

Referenced by getTDC(), initdcs(), initmulti(), and setup().

const bool novaddt::WaveformProcessor::fUseMulti
private

Definition at line 115 of file WaveformProcessor.h.

Referenced by postBeginRun(), and setup().

const bool novaddt::WaveformProcessor::fUseMulti4ADC
private

Definition at line 116 of file WaveformProcessor.h.

Referenced by initmulti(), postBeginRun(), process(), and setup().


The documentation for this class was generated from the following files: