43 #include "art_root_io/TFileService.h" 49 #include "nurandom/RandomUtils/NuRandomService.h" 51 #include "CLHEP/Random/RandFlat.h" 79 void GenNoise(std::vector<float>&
array, CLHEP::HepRandomEngine& engine);
159 MF_LOG_WARNING(
"SimWire") <<
"SimWire is an example module that works for the " 160 <<
"MicroBooNE detector. Each experiment should implement " 161 <<
"its own version of this module to simulate electronics " 164 produces<std::vector<raw::RawDigit>>();
174 fNoiseDist = tfs->make<TH1D>(
"Noise",
";Noise (ADC);", 1000, -10., 10.);
183 fNoiseFluct =
new TF1(
"_poisson",
"[0]**(x) * exp(-[0]) / ROOT::Math::tgamma(x)", 0, 5.);
189 fNoiseFluct =
new TF1(
"_poisson",
"[0]*pow([1]/[2], x/[2])*exp(-[1]/[2])/ROOT::Math::tgamma(x/[2]+1.)", 0, 5.);
196 <<
" is an unknown noise fluctuation choice" <<
std::endl;
206 <<
" noise channels requested exceeds 10000" <<
std::endl;
209 for (
unsigned int p = 0;
p <
fNoise.size(); ++
p) {
211 for (
int i = 0; i <
fNTicks; ++i) {
244 std::vector<const sim::SimChannel*> chanHandle;
248 for(
size_t c = 0;
c < chanHandle.size(); ++
c){
249 channels[chanHandle[
c]->Channel()] = chanHandle[
c];
254 auto digcol = std::make_unique<std::vector<raw::RawDigit>>();
262 for(
unsigned int chan = 0; chan < geo->
Nchannels(); chan++) {
264 std::vector<short> adcvec(
fNTicks, 0);
265 std::vector<double> fChargeWork(
fNTicks, 0.);
288 std::vector<int>
temp;
289 if (time_offset <=0){
290 temp.assign(fChargeWork.begin(),fChargeWork.begin()-time_offset);
291 fChargeWork.erase(fChargeWork.begin(),fChargeWork.begin()-time_offset);
292 fChargeWork.insert(fChargeWork.end(),temp.begin(),temp.end());
294 temp.assign(fChargeWork.end()-time_offset,fChargeWork.end());
295 fChargeWork.erase(fChargeWork.end()-time_offset,fChargeWork.end());
296 fChargeWork.insert(fChargeWork.begin(),temp.begin(),temp.end());
303 int noisechan = chan;
305 noisechan = TMath::Nint(flat.fire()*(1.*(
fNoise.size()-1)+0.1));
307 for(
int i = 0; i <
fNTicks; ++i){
308 adcvec[i] = (short)TMath::Nint(
fNoise[noisechan][i] + fChargeWork[i]);
311 for(
int i = 0; i <
fNTicks; ++i){
312 adcvec[i] = (short)TMath::Nint(fChargeWork[i]);
339 std::vector<double> col(
fNTicks, 0.);
340 std::vector<double> ind(
fNTicks, 0.);
341 std::vector<TComplex> kern(
fNTicks/2 + 1);
342 std::vector<double> delta(
fNTicks, 0.);
351 for(
unsigned int i=0; i<kern.size(); ++i)
370 for(
unsigned int i=0; i<kern.size(); ++i)
387 "ConvolutedCollection",
";ticks; Electronics#timesCollection",
fNTicks,0,
fNTicks);
389 "ConvolutedInduction",
";ticks; Electronics#timesInduction",
fNTicks,0,
fNTicks);
392 for(
unsigned int i = 0; i < ind.size(); ++i){
394 fIndTimeShape->Fill(i, ind[i]);
398 fIndTimeShape->Write();
406 CLHEP::RandFlat
flat(engine);
410 std::vector<TComplex> noiseFrequency(
fNTicks/2+1, 0.);
414 double rnd[2] = {0.};
419 for (
int i=0; i<
fNTicks/2+1; ++i) {
421 double x=(i+0.5)*binWidth;
428 double lofilter = 1.0 / (1.0 + exp(-(i -
fNoiseModelPar[2] / binWidth) / 0.5));
429 flat.fireArray(1, rnd, 0, 1);
430 pval *= lofilter * (0.9 + 0.2 * rnd[0]);
440 pval = pval * randomizer/
fNTicks;
450 pval = pval * randomizer/
fNTicks;
453 <<
" is an unknown choice for the noise model" <<
std::endl;
456 flat.fireArray(1,rnd,0,1);
457 phase = rnd[0]*2.*TMath::Pi();
459 TComplex tc(pval*cos(phase),pval*sin(phase));
460 noiseFrequency[i] += tc;
465 fFFT->
DoInvFFT(noiseFrequency, noise);
467 noiseFrequency.clear();
472 for (
unsigned int i = 0; i < noise.size(); ++i)
493 for (
int i = 1; i < nbinc; ++i) {
498 for (
int i = 0; i < nbinc; ++i) {
505 unsigned short lastbini = 2 * nbini;
508 for (
unsigned short i = 0; i < lastbini; ++i) {
509 double ang = i * TMath::Pi() / nbini;
519 for (
unsigned short i = 0; i < lastbini; ++i) {
525 fColFieldResp->Write();
541 mf::LogInfo(
"SimWire::SetElectResponse") <<
"Check sampling intervals: " 543 <<
"Check number of samples: " <<
fNTicks;
561 4.31054*exp(-2.94809*time[i]/To)*Ao - 2.6202*exp(-2.82833*time[i]/To)*cos(1.19361*time[i]/To)*Ao
562 -2.6202*exp(-2.82833*time[i]/To)*cos(1.19361*time[i]/To)*cos(2.38722*time[i]/To)*Ao
563 +0.464924*exp(-2.40318*time[i]/To)*cos(2.5928*time[i]/To)*Ao
564 +0.464924*exp(-2.40318*time[i]/To)*cos(2.5928*time[i]/To)*cos(5.18561*time[i]/To)*Ao
565 +0.762456*exp(-2.82833*time[i]/To)*sin(1.19361*time[i]/To)*Ao
566 -0.762456*exp(-2.82833*time[i]/To)*cos(2.38722*time[i]/To)*sin(1.19361*time[i]/To)*Ao
567 +0.762456*exp(-2.82833*time[i]/To)*cos(1.19361*time[i]/To)*sin(2.38722*time[i]/To)*Ao
568 -2.6202*exp(-2.82833*time[i]/To)*sin(1.19361*time[i]/To)*sin(2.38722*time[i]/To)*Ao
569 -0.327684*exp(-2.40318*time[i]/To)*sin(2.5928*time[i]/To)*Ao +
570 +0.327684*exp(-2.40318*time[i]/To)*cos(5.18561*time[i]/To)*sin(2.5928*time[i]/To)*Ao
571 -0.327684*exp(-2.40318*time[i]/To)*cos(2.5928*time[i]/To)*sin(5.18561*time[i]/To)*Ao
572 +0.464924*exp(-2.40318*time[i]/To)*sin(2.5928*time[i]/To)*sin(5.18561*time[i]/To)*Ao;
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
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)
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
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.
art framework interface to geometry description
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.
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)
#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
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
void ConvoluteResponseFunctions()
convolute electronics and field response
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
double fSampleRate
sampling rate in ns
void SetFieldResponse()
response of wires to field
static int max(int a, int b)
SimWire(fhicl::ParameterSet const &pset)
TH1D * fIndFieldResp
response function for the field @ induction plane
int fNTicks
number of ticks of the clock
auto array(Array const &a)
Returns a manipulator which will print the specified array.
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
TH1D * fElectResp
response function for the electronics
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
#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.
LArSoft geometry interface.
TH1D * fColFieldResp
response function for the field @ collection plane
std::vector< double > fNoiseModelPar
noise model params
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)