Public Types | Public Member Functions | Private Attributes | List of all members
StuckBitAdcDistortionService Class Reference

#include <StuckBitAdcDistortionService.h>

Inheritance diagram for StuckBitAdcDistortionService:
AdcDistortionService

Public Types

typedef unsigned int Channel
 
- Public Types inherited from AdcDistortionService
typedef unsigned int Channel
 

Public Member Functions

 StuckBitAdcDistortionService (fhicl::ParameterSet const &pset, art::ActivityRegistry &)
 
 ~StuckBitAdcDistortionService ()
 
int modify (Channel chan, AdcCountVector &adcvec) const
 
std::ostream & print (std::ostream &out=std::cout, std::string prefix=" ") const
 
- Public Member Functions inherited from AdcDistortionService
virtual ~AdcDistortionService ()=default
 

Private Attributes

std::string fStuckBitsProbabilitiesFname
 file holding ADC stuck code probabilities More...
 
std::string fStuckBitsOverflowProbHistoName
 Name of hist with ADC stuck code overflow probs. More...
 
std::string fStuckBitsUnderflowProbHistoName
 Name of hist with ADC stuck code underflow probs. More...
 
int m_RandomSeed
 
int m_LogLevel
 
double fOverflowProbs [64]
 array of probs for LSF bits getting stuck at 000000 More...
 
double fUnderflowProbs [64]
 array of probs for LSF bits getting stuck at 111111 More...
 
CLHEP::HepRandomEngine * m_pran
 

Detailed Description

Definition at line 33 of file StuckBitAdcDistortionService.h.

Member Typedef Documentation

Definition at line 37 of file StuckBitAdcDistortionService.h.

Constructor & Destructor Documentation

StuckBitAdcDistortionService::StuckBitAdcDistortionService ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry  
)

Definition at line 25 of file StuckBitAdcDistortionService_service.cc.

26 : m_RandomSeed(0), m_LogLevel(1),
27  m_pran(nullptr) {
28  const string myname = "StuckBitAdcDistortionService::ctor: ";
29  // Fetch parameters.
30  fStuckBitsProbabilitiesFname = pset.get<string>("StuckBitsProbabilitiesFname");
31  fStuckBitsOverflowProbHistoName = pset.get<string>("StuckBitsOverflowProbHistoName");
32  fStuckBitsUnderflowProbHistoName = pset.get<string>("StuckBitsUnderflowProbHistoName");
33  bool haveSeed = pset.get_if_present<int>("RandomSeed", m_RandomSeed);
34  pset.get_if_present<int>("LogLevel", m_LogLevel);
35  if ( m_RandomSeed == 0 ) haveSeed = false;
36  // Create random number engine.
37  if ( haveSeed ) {
38  if ( m_LogLevel > 0 ) cout << myname << "WARNING: Using hardwired seed." << endl;
39  m_pran = new HepJamesRandom(m_RandomSeed);
40  } else {
41  string rname = "StuckBitAdcDistortionService";
42  if ( m_LogLevel > 0 ) cout << myname << "Using NuRandomService." << endl;
44  m_pran = new HepJamesRandom;
45  if ( m_LogLevel > 0 ) cout << myname << " Initial seed: " << m_pran->getSeed() << endl;
46  seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(m_pran), rname);
47  }
48  if ( m_LogLevel > 0 ) cout << myname << " Registered seed: " << m_pran->getSeed() << endl;
49  // Fetch the probabilities.
50  mf::LogInfo("SimWireDUNE") << " using ADC stuck code probabilities from .root file " ;
52  cet::search_path sp("FW_SEARCH_PATH");
53  sp.find_file(fStuckBitsProbabilitiesFname, fname);
54  std::unique_ptr<TFile> fin(new TFile(fname.c_str(), "READ"));
55  if ( !fin->IsOpen() )
57  << "Could not find the ADC stuck code probabilities file " << fname;
58  TString iOverflowHistoName = Form( "%s", fStuckBitsOverflowProbHistoName.c_str());
59  TProfile *overflowtemp = (TProfile*) fin->Get( iOverflowHistoName );
60  if ( !overflowtemp )
62  << "Could not find the ADC code overflow probabilities histogram "
64  if ( overflowtemp->GetNbinsX() != 64 )
66  << "Overflow ADC stuck code probability histograms must have 64 bins.";
67  TString iUnderflowHistoName = Form( "%s", fStuckBitsUnderflowProbHistoName.c_str());
68  TProfile *underflowtemp = (TProfile*) fin->Get(iUnderflowHistoName);
69  if ( !underflowtemp )
71  << "Could not find the ADC code underflow probabilities histogram "
73  if ( underflowtemp->GetNbinsX() != 64 )
75  << "Underflow ADC stuck code probability histograms must have 64 bins.";
76  for ( unsigned int cellnumber=0; cellnumber < 64; ++cellnumber ) {
77  fOverflowProbs[cellnumber] = overflowtemp->GetBinContent(cellnumber+1);
78  fUnderflowProbs[cellnumber] = underflowtemp->GetBinContent(cellnumber+1);
79  }
80  fin->Close();
81 }
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
double fOverflowProbs[64]
array of probs for LSF bits getting stuck at 000000
std::string fStuckBitsOverflowProbHistoName
Name of hist with ADC stuck code overflow probs.
double fUnderflowProbs[64]
array of probs for LSF bits getting stuck at 111111
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string fStuckBitsProbabilitiesFname
file holding ADC stuck code probabilities
std::string fStuckBitsUnderflowProbHistoName
Name of hist with ADC stuck code underflow probs.
QTextStream & endl(QTextStream &s)
StuckBitAdcDistortionService::~StuckBitAdcDistortionService ( )

Definition at line 85 of file StuckBitAdcDistortionService_service.cc.

85  {
86  const string myname = "StuckBitAdcDistortionService:dtor: ";
87  if ( m_LogLevel > 0 ) {
88  cout << myname << "Deleting random engine with seed " << m_pran->getSeed() << endl;
89  }
90  delete m_pran;
91 }
QTextStream & endl(QTextStream &s)

Member Function Documentation

int StuckBitAdcDistortionService::modify ( Channel  chan,
AdcCountVector adcvec 
) const
virtual

Implements AdcDistortionService.

Definition at line 95 of file StuckBitAdcDistortionService_service.cc.

95  {
96  CLHEP::RandFlat stuck_flat(*m_pran);
97  for ( size_t itck = 0; itck<adcvec.size(); ++itck ) {
98  double rnd = stuck_flat.fire(0,1);
99  const unsigned int zeromask = 0xffc0;
100  const unsigned int onemask = 0x003f;
101  unsigned int sixlsbs = adcvec[itck] & onemask;
102  int probability_index = (int)sixlsbs;
103  if ( rnd < fUnderflowProbs[probability_index] ) {
104  adcvec[itck] = adcvec[itck] | onemask; // 6 LSBs are stuck at 3F
105  adcvec[itck] -= 64; // correct 1st MSB value by subtracting 64
106  } else if ( rnd > fUnderflowProbs[probability_index] &&
107  rnd < fUnderflowProbs[probability_index] + fOverflowProbs[probability_index] ) {
108  adcvec[itck] = adcvec[itck] & zeromask; // 6 LSBs are stuck at 0
109  adcvec[itck] += 64; // correct 1st MSB value by adding 64
110  }
111  }
112  return 0;
113 }
const unsigned int onemask
Definition: raw.h:139
double fOverflowProbs[64]
array of probs for LSF bits getting stuck at 000000
double fUnderflowProbs[64]
array of probs for LSF bits getting stuck at 111111
ostream & StuckBitAdcDistortionService::print ( std::ostream &  out = std::cout,
std::string  prefix = "  " 
) const
virtual

Implements AdcDistortionService.

Definition at line 117 of file StuckBitAdcDistortionService_service.cc.

117  {
118  out << prefix << "StuckBitAdcDistortionService:" << endl;
119  out << prefix << " StuckBitsProbabilitiesFname: " << fStuckBitsProbabilitiesFname << endl;
120  out << prefix << " fStuckBitsOverflowProbHistoName: " << fStuckBitsOverflowProbHistoName << endl;
121  out << prefix << " fStuckBitsUnderflowProbHistoName: " << fStuckBitsUnderflowProbHistoName << endl;
122  return out;
123 }
std::string fStuckBitsOverflowProbHistoName
Name of hist with ADC stuck code overflow probs.
std::string fStuckBitsProbabilitiesFname
file holding ADC stuck code probabilities
std::string fStuckBitsUnderflowProbHistoName
Name of hist with ADC stuck code underflow probs.
QTextStream & endl(QTextStream &s)

Member Data Documentation

double StuckBitAdcDistortionService::fOverflowProbs[64]
private

array of probs for LSF bits getting stuck at 000000

Definition at line 60 of file StuckBitAdcDistortionService.h.

std::string StuckBitAdcDistortionService::fStuckBitsOverflowProbHistoName
private

Name of hist with ADC stuck code overflow probs.

Definition at line 55 of file StuckBitAdcDistortionService.h.

std::string StuckBitAdcDistortionService::fStuckBitsProbabilitiesFname
private

file holding ADC stuck code probabilities

Definition at line 54 of file StuckBitAdcDistortionService.h.

std::string StuckBitAdcDistortionService::fStuckBitsUnderflowProbHistoName
private

Name of hist with ADC stuck code underflow probs.

Definition at line 56 of file StuckBitAdcDistortionService.h.

double StuckBitAdcDistortionService::fUnderflowProbs[64]
private

array of probs for LSF bits getting stuck at 111111

Definition at line 61 of file StuckBitAdcDistortionService.h.

int StuckBitAdcDistortionService::m_LogLevel
private

Definition at line 58 of file StuckBitAdcDistortionService.h.

CLHEP::HepRandomEngine* StuckBitAdcDistortionService::m_pran
private

Definition at line 63 of file StuckBitAdcDistortionService.h.

int StuckBitAdcDistortionService::m_RandomSeed
private

Definition at line 57 of file StuckBitAdcDistortionService.h.


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