7 #include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
13 using std::ostringstream;
14 using rndm::NuRandomService;
15 using CLHEP::HepJamesRandom;
21 : fRandomSeed(0), fLogLevel(1), m_pran(nullptr), fNoiseEngine(nullptr)
23 const string myname =
"SBNDNoiseServiceFromHist::ctor: ";
25 bool haveSeed = pset.get_if_present<
int>(
"RandomSeed",
fRandomSeed);
28 fShapingTimeOrder = { {0.5, 0 }, {1.0, 1}, {2.0, 2}, {3.0, 3} };
29 fNoiseWidth = pset.get<
double >(
"NoiseWidth");
30 fNoiseRand = pset.get<
double >(
"NoiseRand");
31 fLowCutoff = pset.get<
double >(
"LowCutoff");
34 fNoiseHistoName =
p.get< std::string >(
"NoiseHistoName");
36 cet::search_path sp(
"FW_SEARCH_PATH");
37 sp.find_file(
p.get<std::string>(
"NoiseFileFname"), fNoiseFileFname);
39 TFile
in(fNoiseFileFname.c_str(),
"READ");
41 throw art::Exception(art::errors::FileOpenError)
42 <<
"Could not find Root file '" << fNoiseHistoName
43 <<
"' for noise histogram\n";
45 fNoiseHist = (TH1D*)
in.Get(fNoiseHistoName.c_str());
48 throw art::Exception(art::errors::NotFound)
49 <<
"Could not find noise histogram '" << fNoiseHistoName
50 <<
"' in Root file '" <<
in.GetPath() <<
"'\n";
53 fNoiseHist->SetDirectory(
nullptr);
58 pset.get_if_present<
int>(
"LogLevel",
fLogLevel);
61 string rname =
"SBNDNoiseServiceFromHist";
63 if (
fLogLevel > 0 )
cout << myname <<
"WARNING: Using hardwired seed." << endl;
64 m_pran =
new HepJamesRandom(seed);
66 if (
fLogLevel > 0 )
cout << myname <<
"Using NuRandomService." << endl;
67 art::ServiceHandle<NuRandomService> seedSvc;
68 m_pran =
new HepJamesRandom;
70 seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(
m_pran), rname);
86 const string myname =
"SBNDNoiseServiceFromHist::dtor: ";
88 cout << myname <<
"Deleting random engine with seed " <<
m_pran->getSeed() << endl;
98 art::ServiceHandle<geo::Geometry> geo;
99 art::ServiceHandle<util::SignalShapingServiceSBND> sss;
100 art::ServiceHandle<util::LArFFT> fFFT;
103 size_t view = (size_t)geo->View(chan);
106 auto tempNoiseVec = sss->GetNoiseFactVec();
107 double shapingTime = 2.0;
108 double asicGain = sss->GetASICGain(chan);
110 size_t fNTicks = fFFT->FFTSize();
113 if (fShapingTimeOrder.find( shapingTime ) != fShapingTimeOrder.end() ) {
114 noise_factor = tempNoiseVec[view].at( fShapingTimeOrder.find( shapingTime )->second );
115 noise_factor *= asicGain/4.7;
118 throw cet::exception(
"SBNDNoiseServiceFromHist_service.cc")
120 <<
"Shaping Time recieved from signalshapingservices_sbnd.fcl is not one of the allowed values"
122 <<
"Allowed values: 0.5, 1.0, 2.0, 3.0 us"
128 CLHEP::RandFlat flat(*fNoiseEngine, -1, 1);
131 if (sigs.size() != fNTicks)
132 throw cet::exception(
"SBNDNoiseServiceFromHist_service.cc")
134 <<
"Frequency noise vector length must match fNTicks (FFT size)"
135 <<
" ... " << sigs.size() <<
" != " << fNTicks
140 std::vector<TComplex> noiseFrequency(fNTicks / 2 + 1, 0.);
143 double lofilter = 0.;
145 double rnd[2] = {0.};
148 double binWidth = 1.0 / (fNTicks *
fSampleRate * 1.0e-6);
150 for (
size_t i = 0; i < fNTicks / 2 + 1; ++i) {
152 flat.fireArray(2, rnd, 0, 1);
153 pval = fNoiseHist->GetBinContent(i) * ((1 - fNoiseRand) + 2 * fNoiseRand * rnd[0]) * noise_factor;
154 phase = rnd[1] * 2.*TMath::Pi();
155 TComplex tc(pval * cos(phase), pval * sin(phase));
156 noiseFrequency.at(i) += tc;
161 fFFT->DoInvFFT(noiseFrequency, sigs);
163 noiseFrequency.clear();
168 for (
unsigned int i = 0; i < sigs.size(); ++i) {
169 sigs.at(i) *= 1.*fNTicks;
179 out << prefix <<
"SBNDNoiseServiceFromHist: " << endl;
181 out << prefix <<
" LogLevel: " <<
fLogLevel << endl;
182 out << prefix <<
" RandomSeed: " <<
fRandomSeed << endl;
SBNDNoiseServiceFromHist(fhicl::ParameterSet const &pset)
CLHEP::HepRandomEngine * m_pran
int addNoise(Channel chan, AdcSignalVector &sigs) const
int fRandomSeed
Seed for random number service. If absent or zero, use SeedSvc.
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
int fLogLevel
Log message level: 0=quiet, 1=init only, 2+=every event.
std::vector< AdcSignal > AdcSignalVector
~SBNDNoiseServiceFromHist()
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
virtual void generateNoise(detinfo::DetectorClocksData const &)
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
BEGIN_PROLOG could also be cout