6 #include "nurandom/RandomUtils/NuRandomService.h" 9 #include "CLHEP/Random/JamesRandom.h" 10 #include "CLHEP/Random/RandFlat.h" 19 using rndm::NuRandomService;
20 using CLHEP::HepJamesRandom;
26 : m_RandomSeed(0), m_LogLevel(1),
28 const string myname =
"StuckBitAdcDistortionService::ctor: ";
38 if (
m_LogLevel > 0 ) cout << myname <<
"WARNING: Using hardwired seed." <<
endl;
41 string rname =
"StuckBitAdcDistortionService";
42 if (
m_LogLevel > 0 ) cout << myname <<
"Using NuRandomService." <<
endl;
44 m_pran =
new HepJamesRandom;
46 seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(
m_pran), rname);
50 mf::LogInfo(
"SimWireDUNE") <<
" using ADC stuck code probabilities from .root file " ;
54 std::unique_ptr<TFile> fin(
new TFile(fname.c_str(),
"READ"));
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 );
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);
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);
86 const string myname =
"StuckBitAdcDistortionService:dtor: ";
88 cout << myname <<
"Deleting random engine with seed " <<
m_pran->getSeed() <<
endl;
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;
104 adcvec[itck] = adcvec[itck] |
onemask;
108 adcvec[itck] = adcvec[itck] & zeromask;
118 out << prefix <<
"StuckBitAdcDistortionService:" <<
endl;
std::vector< AdcCount > AdcCountVector
int modify(Channel chan, AdcCountVector &adcvec) const
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const unsigned int onemask
double fOverflowProbs[64]
array of probs for LSF bits getting stuck at 000000
std::ostream & print(std::ostream &out=std::cout, std::string prefix=" ") const
StuckBitAdcDistortionService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
~StuckBitAdcDistortionService()
CLHEP::HepRandomEngine * m_pran
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
T get(std::string const &key) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string fStuckBitsProbabilitiesFname
file holding ADC stuck code probabilities
std::optional< T > get_if_present(std::string const &key) const
std::string find_file(std::string const &filename) const
std::string fStuckBitsUnderflowProbHistoName
Name of hist with ADC stuck code underflow probs.
QTextStream & endl(QTextStream &s)
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)