46 #include "art_root_io/TFileService.h" 47 #include "cetlib_except/exception.h" 54 #include "CLHEP/Random/RandFlat.h" 82 void GenNoise(std::vector<float>&
array, CLHEP::HepRandomEngine& engine);
164 MF_LOG_WARNING(
"SimWire") <<
"SimWire is an example module that works for the " 165 <<
"MicroBooNE detector. Each experiment should implement " 166 <<
"its own version of this module to simulate electronics " 169 produces<std::vector<raw::RawDigit>>();
178 fNoiseDist = tfs->make<TH1D>(
"Noise",
";Noise (ADC);", 1000, -10., 10.);
187 fNoiseFluct =
new TF1(
"_poisson",
"[0]**(x) * exp(-[0]) / ROOT::Math::tgamma(x)", 0, 5.);
195 "_poisson",
"[0]*pow([1]/[2], x/[2])*exp(-[1]/[2])/ROOT::Math::tgamma(x/[2]+1.)", 0, 5.);
213 <<
fNoiseNchToSim <<
" noise channels requested exceeds 10000" << std::endl;
216 for (
unsigned int p = 0; p <
fNoise.size(); ++p) {
218 for (
int i = 0; i <
fNTicks; ++i) {
240 for (
unsigned int p = 0; p < geo->
Nchannels(); ++p) {
249 std::vector<const sim::SimChannel*> chanHandle;
252 std::vector<const sim::SimChannel*> channels(geo->
Nchannels());
253 for (
size_t c = 0; c < chanHandle.size(); ++c) {
254 channels[chanHandle[c]->Channel()] = chanHandle[c];
259 auto digcol = std::make_unique<std::vector<raw::RawDigit>>();
267 for (
unsigned int chan = 0; chan < geo->
Nchannels(); chan++) {
269 std::vector<short> adcvec(
fNTicks, 0);
270 std::vector<double> fChargeWork(
fNTicks, 0.);
272 if (channels[chan]) {
278 for (
int t = 0; t <
fNTicks; ++t)
279 fChargeWork[t] = sc->
Charge(t);
294 std::vector<int> temp;
295 if (time_offset <= 0) {
296 temp.assign(fChargeWork.begin(), fChargeWork.begin() - time_offset);
297 fChargeWork.erase(fChargeWork.begin(), fChargeWork.begin() - time_offset);
298 fChargeWork.insert(fChargeWork.end(), temp.begin(), temp.end());
301 temp.assign(fChargeWork.end() - time_offset, fChargeWork.end());
302 fChargeWork.erase(fChargeWork.end() - time_offset, fChargeWork.end());
303 fChargeWork.insert(fChargeWork.begin(), temp.begin(), temp.end());
309 int noisechan = chan;
311 noisechan = TMath::Nint(flat.fire() * (1. * (
fNoise.size() - 1) + 0.1));
313 for (
int i = 0; i <
fNTicks; ++i) {
314 adcvec[i] = (short)TMath::Nint(
fNoise[noisechan][i] + fChargeWork[i]);
318 for (
int i = 0; i <
fNTicks; ++i) {
319 adcvec[i] = (short)TMath::Nint(fChargeWork[i]);
335 evt.
put(std::move(digcol));
346 std::vector<double> ind(
fNTicks, 0.);
347 std::vector<TComplex> kern(
fNTicks / 2 + 1);
348 std::vector<double> delta(
fNTicks, 0.);
357 for (
unsigned int i = 0; i < kern.size(); ++i)
376 for (
unsigned int i = 0; i < kern.size(); ++i)
393 "ConvolutedCollection",
";ticks; Electronics#timesCollection",
fNTicks, 0,
fNTicks);
395 "ConvolutedInduction",
";ticks; Electronics#timesInduction",
fNTicks, 0,
fNTicks);
398 for (
unsigned int i = 0; i < ind.size(); ++i) {
400 fIndTimeShape->Fill(i, ind[i]);
404 fIndTimeShape->Write();
410 CLHEP::RandFlat flat(engine);
414 std::vector<TComplex> noiseFrequency(
fNTicks / 2 + 1, 0.);
418 double rnd[2] = {0.};
423 for (
int i = 0; i <
fNTicks / 2 + 1; ++i) {
425 double x = (i + 0.5) * binWidth;
432 double lofilter = 1.0 / (1.0 + exp(-(i -
fNoiseModelPar[2] / binWidth) / 0.5));
433 flat.fireArray(1, rnd, 0, 1);
434 pval *= lofilter * (0.9 + 0.2 * rnd[0]);
445 pval = pval * randomizer /
fNTicks;
456 pval = pval * randomizer /
fNTicks;
460 <<
fNoiseModelChoice <<
" is an unknown choice for the noise model" << std::endl;
463 flat.fireArray(1, rnd, 0, 1);
464 phase = rnd[0] * 2. * TMath::Pi();
466 TComplex tc(pval * cos(phase), pval * sin(phase));
467 noiseFrequency[i] += tc;
472 fFFT->
DoInvFFT(noiseFrequency, noise);
474 noiseFrequency.clear();
479 for (
unsigned int i = 0; i < noise.size(); ++i)
490 tfs->make<TH1D>(
"InductionFieldResponse",
";t (ns);Induction Response",
fNTicks, 0,
fNTicks);
492 "CollectionFieldResponse",
";t (ns);Collection Response",
fNTicks, 0,
fNTicks);
500 double integral = 0.;
501 for (
int i = 1; i < nbinc; ++i) {
506 for (
int i = 0; i < nbinc; ++i) {
513 unsigned short lastbini = 2 * nbini;
516 for (
unsigned short i = 0; i < lastbini; ++i) {
517 double ang = i * TMath::Pi() / nbini;
527 for (
unsigned short i = 0; i < lastbini; ++i) {
533 fColFieldResp->Write();
541 std::vector<double> time(
fNTicks, 0.);
550 <<
"Check number of samples: " <<
fNTicks;
568 4.31054 * exp(-2.94809 * time[i] / To) * Ao -
569 2.6202 * exp(-2.82833 * time[i] / To) * cos(1.19361 * time[i] / To) * Ao -
570 2.6202 * exp(-2.82833 * time[i] / To) * cos(1.19361 * time[i] / To) *
571 cos(2.38722 * time[i] / To) * Ao +
572 0.464924 * exp(-2.40318 * time[i] / To) * cos(2.5928 * time[i] / To) * Ao +
573 0.464924 * exp(-2.40318 * time[i] / To) * cos(2.5928 * time[i] / To) *
574 cos(5.18561 * time[i] / To) * Ao +
575 0.762456 * exp(-2.82833 * time[i] / To) * sin(1.19361 * time[i] / To) * Ao -
576 0.762456 * exp(-2.82833 * time[i] / To) * cos(2.38722 * time[i] / To) *
577 sin(1.19361 * time[i] / To) * Ao +
578 0.762456 * exp(-2.82833 * time[i] / To) * cos(1.19361 * time[i] / To) *
579 sin(2.38722 * time[i] / To) * Ao -
580 2.6202 * exp(-2.82833 * time[i] / To) * sin(1.19361 * time[i] / To) *
581 sin(2.38722 * time[i] / To) * Ao -
582 0.327684 * exp(-2.40318 * time[i] / To) * sin(2.5928 * time[i] / To) * Ao +
583 +0.327684 * exp(-2.40318 * time[i] / To) * cos(5.18561 * time[i] / To) *
584 sin(2.5928 * time[i] / To) * Ao -
585 0.327684 * exp(-2.40318 * time[i] / To) * cos(2.5928 * time[i] / To) *
586 sin(5.18561 * time[i] / To) * Ao +
587 0.464924 * exp(-2.40318 * time[i] / To) * sin(2.5928 * time[i] / To) *
588 sin(5.18561 * time[i] / To) * Ao;
base_engine_t & createEngine(seed_t seed)
unsigned int fNSamplesReadout
number of ADC readout samples in 1 readout frame
std::string fNoiseModelChoice
choice for noise model
std::vector< TComplex > fColShape
response function for the field @ collection plane
enum raw::_compress Compress_t
std::vector< float > fIndFieldParams
induction plane field function parameterization
Energy deposited on a readout channel by simulated tracks.
std::vector< double > fElectResponse
response function for the electronics
TF1 * fNoiseFluct
Poisson dist for fluctuations in magnitude of noise freq components.
TH1D * fColTimeShape
convoluted shape for field x electronics @ col plane
std::string fDriftEModuleLabel
module making the ionization electrons
int fNoiseNchToSim
number of noise channels to generate
void SetElectResponse()
response of electronics
void ShiftData(std::vector< TComplex > &input, double shift)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
double fADCPerPCAtLowestASICGain
ADCs/pC at lowest gain setting of 4.7 mV/fC.
EDProducer(fhicl::ParameterSet const &pset)
unsigned int fNElectResp
number of entries from response to use
TH1D * fNoiseDist
distribution of noise counts
Detector simulation of raw signals on wires.
std::string fNoiseFluctChoice
choice for noise freq component mag fluctuations
Definition of basic raw digits.
raw::Compress_t fCompression
compression type to use
double fShapeTimeConst
time constants for exponential shaping
void DoFFT(std::vector< T > &input, std::vector< TComplex > &output)
std::vector< std::vector< float > > fNoise
noise on each channel for each time
T PeakCorrelation(std::vector< T > &shape1, std::vector< T > &shape2)
double fInputFieldRespSamplingPeriod
Sampling period in the input field response.
tick ticks
Alias for common language habits.
std::vector< float > fColFieldParams
collection plane field function parameterization
void DoInvFFT(std::vector< TComplex > &input, std::vector< T > &output)
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::vector< int > fCalibRespTOffset
calib response time offset in ticks
std::vector< double > fIndFieldResponse
response function for the field @ induction plane
void GenNoise(std::vector< float > &array, CLHEP::HepRandomEngine &engine)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
#define DEFINE_ART_MODULE(klass)
Signal from induction planes.
std::vector< double > fColFieldResponse
response function for the field @ collection plane
double Charge(TDC_t tdc) const
Returns the total number of ionization electrons on this channel in the specified TDC...
std::vector< TComplex > fIndShape
response function for the field @ induction plane
std::vector< double > fNoiseFluctPar
Poisson noise fluctuations params.
void produce(art::Event &evt) override
Collect all the RawData header files together.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
void ConvoluteResponseFunctions()
convolute electronics and field response
double fSampleRate
sampling rate in ns
void SetFieldResponse()
response of wires to field
SimWire(fhicl::ParameterSet const &pset)
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
TH1D * fIndFieldResp
response function for the field @ induction plane
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
int fNTicks
number of ticks of the clock
SigType_t SignalType(PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
TH1D * fIndTimeShape
convoluted shape for field x electronics @ ind plane
std::vector< int > fFieldRespTOffset
field response time offset in ticks
Encapsulate the construction of a single detector plane.
double fASICGainInMVPerFC
actual gain setting used in mV/fC
object containing MC truth information necessary for making RawDigits and doing back tracking ...
TH1D * fElectResp
response function for the electronics
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
#define MF_LOG_WARNING(category)
CLHEP::HepRandomEngine & fEngine
Random-number engine owned by art.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
Namespace collecting geometry-related classes utilities.
TH1D * fColFieldResp
response function for the field @ collection plane
std::vector< double > fNoiseModelPar
noise model params
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception