WhiteChannelNoiseService_service.cc
Go to the documentation of this file.
1 // WhiteChannelNoiseService.cxx
2 
6 #include "nurandom/RandomUtils/NuRandomService.h"
7 #include "art_root_io/TFileService.h"
9 #include "CLHEP/Random/JamesRandom.h"
10 #include "CLHEP/Random/RandGaussQ.h"
11 #include "TH1F.h"
12 
13 using std::ostream;
14 using std::cout;
15 using std::endl;
16 using std::string;
17 using rndm::NuRandomService;
18 using CLHEP::HepJamesRandom;
19 
20 //**********************************************************************
21 
24 : m_RandomSeed(0), m_LogLevel(1),
25  fNoiseHist(nullptr),
26  m_pran(nullptr) {
27  const string myname = "WhiteChannelNoiseService::ctor: ";
28  // Fetch parameters.
29  bool haveSeed = pset.get_if_present<int>("RandomSeed", m_RandomSeed);
30  pset.get_if_present<int>("LogLevel", m_LogLevel);
31  if ( m_RandomSeed == 0 ) haveSeed = false;
32  // Create random number engine.
33  if ( haveSeed ) {
34  if ( m_LogLevel > 0 ) cout << myname << "WARNING: Using hardwired seed." << endl;
35  m_pran = new HepJamesRandom(m_RandomSeed);
36  } else {
37  string rname = "WhiteChannelNoiseService";
38  if ( m_LogLevel > 0 ) cout << myname << "Using NuRandomService." << endl;
40  m_pran = new HepJamesRandom;
41  if ( m_LogLevel > 0 ) cout << myname << " Initial seed: " << m_pran->getSeed() << endl;
42  seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(m_pran), rname);
43  }
44  if ( m_LogLevel > 0 ) cout << myname << " Registered seed: " << m_pran->getSeed() << endl;
46  fNoiseHist = tfs->make<TH1F>("Noise", ";Noise (ADC);", 1000, -10., 10.);
47 }
48 
49 //**********************************************************************
50 
52  const string myname = "WhiteChannelNoiseService::dtor: ";
53  if ( m_LogLevel > 0 ) {
54  cout << myname << "Deleting random engine with seed " << m_pran->getSeed() << endl;
55  }
56  delete m_pran;
57 }
58 
59 //**********************************************************************
60 
63  Channel chan, AdcSignalVector& sigs) const {
65  float fASICGain = sss->GetASICGain(chan);
66  double fShapingTime = sss->GetShapingTime(chan);
67  std::map< double, int > fShapingTimeOrder;
68  fShapingTimeOrder = { {0.5, 0}, {1.0, 1}, {2.0, 2}, {3.0, 3} };
69  DoubleVec fNoiseFactVec;
70  auto tempNoiseVec = sss->GetNoiseFactVec();
71  if ( fShapingTimeOrder.find(fShapingTime) != fShapingTimeOrder.end() ) {
72  size_t i = 0;
73  fNoiseFactVec.resize(2);
74  for ( auto& item : tempNoiseVec ) {
75  fNoiseFactVec[i] = item.at(fShapingTimeOrder.find( fShapingTime )->second);
76  fNoiseFactVec[i] *= fASICGain/4.7;
77  ++i;
78  }
79  } else {
80  throw cet::exception("WhiteChannelNoiseService")
81  << "\033[93m"
82  << "Shaping Time received from signalservices_dune.fcl is not one of allowed values"
83  << std::endl
84  << "Allowed values: 0.5, 1.0, 2.0, 3.0 usec"
85  << "\033[00m"
86  << std::endl;
87  }
89  const geo::View_t view = geo->View(chan);
90  CLHEP::HepRandomEngine& engine = *m_pran;
91  CLHEP::RandGaussQ rGauss_Ind(engine, 0.0, fNoiseFactVec[0]);
92  CLHEP::RandGaussQ rGauss_Col(engine, 0.0, fNoiseFactVec[1]);
93  for ( AdcSignal& sig : sigs ) {
94  double tnoise = 0.0;
95  if ( view==geo::kU ) tnoise = rGauss_Ind.fire();
96  else if ( view==geo::kV ) tnoise = rGauss_Ind.fire();
97  else tnoise = rGauss_Col.fire();
98  sig += tnoise;
99  }
100  return 0;
101 }
102 
103 //**********************************************************************
104 
105 ostream& WhiteChannelNoiseService::print(ostream& out, string prefix) const {
106  string myprefix = prefix + " ";
107  out << myprefix << " Random seed: " << m_pran->getSeed() << endl;
108  return out;
109 }
110 
111 //**********************************************************************
112 
114 
115 //**********************************************************************
double GetShapingTime(Channel channel) const override
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string string
Definition: nybbler.cc:12
Planes which measure V.
Definition: geo_types.h:130
float AdcSignal
Definition: AdcTypes.h:21
std::vector< DoubleVec > GetNoiseFactVec() const override
TH1 * fNoiseHist
distribution of noise counts
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
art framework interface to geometry description
int addNoise(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, Channel chan, AdcSignalVector &sigs) const
Planes which measure U.
Definition: geo_types.h:129
WhiteChannelNoiseService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Contains all timing reference information for the detector.
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
CLHEP::HepRandomEngine * m_pran
double GetASICGain(Channel channel) const override
LArSoft geometry interface.
Definition: ChannelGeo.h:16
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
std::vector< double > DoubleVec
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)