19 #include <sys/types.h> 28 #include "art_root_io/TFileService.h" 29 #include "art_root_io/TFileDirectory.h" 34 #include "nurandom/RandomUtils/NuRandomService.h" 55 #include "CLHEP/Random/RandFlat.h" 56 #include "CLHEP/Random/RandGaussQ.h" 200 produces< std::vector<raw::RawDigit> >();
203 TString compression(pset.get<
std::string >(
"CompressionType"));
204 if(compression.Contains(
"Huffman",TString::kIgnoreCase)) fCompression =
raw::kHuffman;
205 if(compression.Contains(
"ZeroSuppression",TString::kIgnoreCase)) fCompression =
raw::kZeroSuppression;
284 fNoiseDist = tfs->make<TH1D>(
"Noise",
";Noise (ADC);", 1000, -10., 10.);
291 MF_LOG_DEBUG(
"SimWireDUNE35t") <<
"Warning: FFTSize not a power of 2. " 292 <<
"May cause issues in (de)convolution.\n";
295 mf::LogError(
"SimWireDUNE35t") <<
"Cannot have number of readout samples " 296 <<
"greater than FFTSize!";
301 bool foundfirstcollectionchannel =
false;
303 unsigned int currentPlaneNumber = geo->
ChannelToWire(0).at(0).Plane;
304 unsigned int currentTPCNumber = geo->
ChannelToWire(0).at(0).TPC;
306 for (uint32_t ichan=0;ichan<geo->
Nchannels();ichan++)
309 if(!foundfirstcollectionchannel)
314 foundfirstcollectionchannel =
true;
320 const unsigned int thisPlaneNumber = geo->
ChannelToWire(ichan).at(0).Plane;
321 const unsigned int thisTPCNumber = geo->
ChannelToWire(ichan).at(0).TPC;
323 if(thisPlaneNumber != currentPlaneNumber || (thisPlaneNumber ==
geo::kZ && thisTPCNumber != currentTPCNumber))
327 currentPlaneNumber = thisPlaneNumber;
328 currentTPCNumber = thisTPCNumber;
332 if (!foundfirstcollectionchannel)
334 throw cet::exception(
"SimWireDUNE35t BeginJob") <<
" Could not find any collection channels\n";
367 for(
int i = 0; i <
fNTicks; ++i)
375 for(
int i = 0; i <
fNTicks; ++i)
385 for(
int i = 0; i <
fNTicks; ++i)
403 double xyzbeg[3],xyzend[3];
414 lastwire = geo->
Nwires(0,0,0)-1;
423 lastwire = geo->
Nwires(1,0,0)-1;
447 lastwire = geo->
Nwires(0,2,0)-1;
456 lastwire = geo->
Nwires(1,2,0)-1;
478 lastwire = geo->
Nwires(0,4,0)-1;
487 lastwire = geo->
Nwires(1,4,0)-1;
510 lastwire = geo->
Nwires(0,6,0)-1;
519 lastwire = geo->
Nwires(1,6,0)-1;
539 mf::LogInfo(
"SimWireDUNE35t") <<
" using ADC stuck code probabilities from .root file " ;
546 std::unique_ptr<TFile> fin(
new TFile(fname.c_str(),
"READ"));
550 TProfile *overflowtemp = (TProfile*) fin->Get( iOverflowHistoName );
556 TProfile *underflowtemp = (TProfile*) fin->Get( iUnderflowHistoName );
562 for(
unsigned int cellnumber=0; cellnumber < 64; ++cellnumber){
563 fOverflowProbs[cellnumber] = overflowtemp->GetBinContent(cellnumber+1);
564 fUnderflowProbs[cellnumber] = underflowtemp->GetBinContent(cellnumber+1);
583 unsigned int signalSize =
fNTicks;
586 std::vector<short> adcvec(signalSize, 0);
587 std::vector<const sim::SimChannel*> chanHandle;
598 for(
size_t c = 0;
c < chanHandle.size(); ++
c){
599 channels[chanHandle[
c]->Channel()] = chanHandle[
c];
604 std::unique_ptr< std::vector<raw::RawDigit> > digcol(
new std::vector<raw::RawDigit>);
606 unsigned int chan = 0;
611 std::vector<double> fChargeWorkCollInd;
627 std::vector<std::vector<short>> adcvec_inductionplanestart;
629 unsigned int plane_number = 0;
635 for(chan = 0; chan < geo->
Nchannels(); chan++) {
643 fChargeWorkCollInd.clear();
658 for (
auto const &ide : ides)
660 GapType_t gaptype =
combtest35t(ide.x,ide.y,ide.z);
692 throw cet::exception(
"SimWireDUNE35t") <<
"ILLEGAL VIEW Type: " << view <<
"\n";
721 throw cet::exception(
"SimWireDUNE35t") <<
"ILLEGAL VIEW Type: " << view <<
"\n";
750 throw cet::exception(
"SimWireDUNE35t") <<
"ILLEGAL VIEW Type: " << view <<
"\n";
779 throw cet::exception(
"SimWireDUNE35t") <<
"ILLEGAL VIEW Type: " << view <<
"\n";
809 fChargeWorkCollInd.resize(
fNTicks,0);
834 double *fChargeWork_a=0;
835 double *fChargeWorkCollInd_a=0;
843 fChargeWorkCollInd_a = fChargeWorkCollInd.data();
844 adcvec_a = adcvec.data();
856 mf::LogError(
"SimWireDUNE35t") <<
"ERROR: CHANNEL NUMBER " << chan <<
" OUTSIDE OF PLANE";
860 for(
unsigned int i = 0; i < signalSize; ++i){
861 if(view==
geo::kU) { tnoise = noise_a_U[i]; }
862 else if (view==
geo::kV) { tnoise = noise_a_V[i]; }
863 else { tnoise = noise_a_Z[i]; }
864 tmpfv = tnoise + fChargeWork_a[i] ;
865 if (
fSimCombs) tmpfv += fChargeWorkCollInd_a[i];
870 if ( tmpfv < 0 - ped_mean)
873 adcvec_a[i] = (tmpfv >=0) ? (
short) (tmpfv+0.5) : (short) (tmpfv-0.5);
880 std::map< double, int > fShapingTimeOrder;
881 fShapingTimeOrder = { {0.5, 0}, {1.0, 1}, {2.0, 2}, {3.0, 3} };
888 if ( fShapingTimeOrder.find( fShapingTime ) != fShapingTimeOrder.end() ){
890 fNoiseFactVec.resize(2);
891 for (
auto& item : tempNoiseVec) {
892 fNoiseFactVec[i] = item.at( fShapingTimeOrder.find( fShapingTime )->second );
893 fNoiseFactVec[i] *= fASICGain/4.7;
900 <<
"Shaping Time received from signalservices_dune.fcl is not one of allowed values" 902 <<
"Allowed values: 0.5, 1.0, 2.0, 3.0 usec" 908 CLHEP::RandGaussQ rGauss_Ind(
fEngine, 0.0, fNoiseFactVec[0]);
909 CLHEP::RandGaussQ rGauss_Col(
fEngine, 0.0, fNoiseFactVec[1]);
912 for(
unsigned int i = 0; i < signalSize; ++i){
913 if(view==
geo::kU) { tnoise = rGauss_Ind.fire(); }
914 else if (view==
geo::kV) { tnoise = rGauss_Ind.fire(); }
915 else { tnoise = rGauss_Col.fire(); }
916 tmpfv = tnoise + fChargeWork_a[i] ;
917 if (
fSimCombs) tmpfv += fChargeWorkCollInd_a[i];
922 if ( tmpfv < 0 - ped_mean)
924 adcvec_a[i] = (tmpfv >=0) ? (
short) (tmpfv+0.5) : (short) (tmpfv-0.5);
927 for(
unsigned int i = 0; i < signalSize; ++i){
928 tmpfv = fChargeWork_a[i];
929 if (
fSimCombs) tmpfv += fChargeWorkCollInd_a[i] ;
934 if ( tmpfv < 0 - ped_mean)
936 adcvec_a[i] = (tmpfv >=0) ? (
short) (tmpfv+0.5) : (short) (tmpfv-0.5);
946 float calibrated_pedestal_value = 0;
947 float calibrated_pedestal_rms_value = 0;
948 int calibrated_integer_pedestal_value = 0;
954 CLHEP::RandGaussQ rGauss_Ped(
fEngine, 0.0, ped_rms);
955 for(
unsigned int i = 0; i < signalSize; ++i){
956 float ped_variation = rGauss_Ped.fire();
957 tmpfv = adcvec_a[i] + ped_mean + ped_variation;
959 adcvec_a[i] = (short) tmpfv;
964 for(
unsigned int i = 0; i < signalSize; ++i){
965 tmpfv = adcvec_a[i] + ped_mean;
966 adcvec_a[i] = (short) tmpfv;
984 calibrated_pedestal_value = 0;
985 calibrated_pedestal_rms_value = 0;
989 calibrated_integer_pedestal_value = (
int) calibrated_pedestal_value;
995 for(
size_t i = 0; i < adcvec.size(); ++i){
999 double rnd = flat.fire(0,1);
1002 unsigned int zeromask = 0xffc0;
1003 unsigned int onemask = 0x003f;
1005 unsigned int sixlsbs = adcvec_a[i] &
onemask;
1007 int probability_index = (
int)sixlsbs;
1010 adcvec_a[i] = adcvec_a[i] |
onemask;
1014 adcvec_a[i] = adcvec_a[i] & zeromask;
1039 rd.
SetPedestal(calibrated_pedestal_value,calibrated_pedestal_rms_value);
1042 adcvec.resize(signalSize);
1044 digcol->push_back(rd);
1057 adcvec_neighbors.push_back(adcvec);
1060 if(!(adcvec_neighbors.full()))
1074 rd.
SetPedestal(calibrated_pedestal_value,calibrated_pedestal_rms_value);
1077 digcol->push_back(rd);
1096 rd.
SetPedestal(calibrated_pedestal_value,calibrated_pedestal_rms_value);
1099 digcol->push_back(rd);
1111 adcvec_neighbors.pop_front();
1113 adcvec = adcvec_neighbors.at(fNeighboringChannels);
1122 rd2.
SetPedestal(calibrated_pedestal_value,calibrated_pedestal_rms_value);
1125 digcol->push_back(rd2);
1129 adcvec_neighbors.clear();
1139 adcvec_neighbors.push_back(adcvec);
1140 if(!(adcvec_neighbors.full()))
1142 adcvec_inductionplanestart.push_back(adcvec);
1162 rd.
SetPedestal(calibrated_pedestal_value,calibrated_pedestal_rms_value);
1165 digcol->push_back(rd);
1182 adcvec_neighbors.push_back(adcvec_inductionplanestart.at(lastentries));
1184 adcvec = adcvec_neighbors.at(fNeighboringChannels);
1194 rd2.
SetPedestal(calibrated_pedestal_value,calibrated_pedestal_rms_value);
1197 digcol->push_back(rd2);
1201 adcvec_neighbors.clear();
1202 adcvec_inductionplanestart.clear();
1209 adcvec.resize(signalSize);
1229 std::vector<TComplex> noiseFrequency(
fNTicks/2+1, 0.);
1232 double lofilter = 0.;
1234 double rnd[2] = {0.};
1238 for(
int i=0; i<
fNTicks/2+1; ++i){
1242 lofilter = 1.0/(1.0+exp(-(i-
fLowCutoff/binWidth)/0.5));
1244 flat.fireArray(2,rnd,0,1);
1245 pval *= lofilter*(0.9+0.2*rnd[0]);
1247 phase = rnd[1]*2.*TMath::Pi();
1249 TComplex tc(pval*cos(phase),pval*sin(phase));
1250 noiseFrequency[i] += tc;
1256 fFFT->
DoInvFFT(noiseFrequency, noise);
1258 noiseFrequency.clear();
1263 for(
unsigned int i = 0; i < noise.size(); ++i) noise[i] *= 1.*
fNTicks;
1339 if ( y < ycomb12 && y >
ycomb7 && x > 0 && z < zcomb9 && z >
zcomb4 )
return 1;
void GenNoise(std::vector< float > &array)
float fInductionCalibPedRMS
Assumed measured value for ind plane pedestal RMS.
base_engine_t & createEngine(seed_t seed)
int fNTicks
number of ticks of the clock
std::vector< float > fFractUVCollect
std::vector< std::vector< float > > fNoiseU
noise on each channel for each time for U plane
double GetShapingTime(Channel channel) const override
enum raw::_compress Compress_t
std::vector< float > fFractVUCollect
float fNoiseWidthZ
exponential noise width (kHz) for Z (collection) plane
float fInductionPed
ADC value of baseline for induction plane.
float fNoiseWidth
exponential noise width (kHz)
Collection of charge vs time digitized from a single readout channel.
Energy deposited on a readout channel by simulated tracks.
bool fSimCombs
switch for simulation of the combs
float fLowCutoffZ
low frequency filter cutoff (kHz) for Z (collection) plane
std::vector< float > fFractHorizGapVMiss
void reconfigure(fhicl::ParameterSet const &p)
std::vector< float > fFractHorizGapZMiss
std::vector< uint32_t > fFirstChannelsInPlane
std::vector< float > fFractUUMiss
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
float fNoiseWidthU
exponential noise width (kHz) for U plane
std::vector< DoubleVec > GetNoiseFactVec() const override
EDProducer(fhicl::ParameterSet const &pset)
TH1D * fNoiseDist
distribution of noise counts
std::vector< float > fFractUVMiss
Detector simulation of raw signals on wires.
SimWireDUNE35t(fhicl::ParameterSet const &pset)
const unsigned int onemask
std::vector< float > fFractUUCollect
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector< float > fFractVUMiss
Planes which measure Z direction.
unsigned int fNoiseModel
noise model>
int GapHasDeflector(double x, double y, double z)
float fInductionCalibPed
Assumed measured value for ind plane pedestal.
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
float fInductionPedRMS
ADC value of baseline RMS for induction plane.
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
unsigned int fNSamplesReadout
number of ADC readout samples in 1 readout frame
float fNoiseFact
noise scale factor
float fLowCutoffU
low frequency filter cutoff (kHz) for U plane
std::vector< float > fFractHorizGapVCollect
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
art framework interface to geometry description
void DoInvFFT(std::vector< TComplex > &input, std::vector< T > &output)
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
std::vector< float > fFractHorizGapUMiss
GapType_t combtest35t(double x, double y, double z)
float fCollectionPed
ADC value of baseline for collection plane.
Zero Suppression algorithm.
int fNearestNeighbor
Maximum distance between hits above threshold before they are separated into different blocks...
std::string fStuckBitsUnderflowProbHistoName
Name of histogram holding ADC stuck code underflow probabilities.
std::vector< float > fFractVVMiss
float fNoiseFactU
noise scale factor for U plane
#define DEFINE_ART_MODULE(klass)
unsigned int fNoiseOn
noise turned on or off for debugging; default is on
Signal from induction planes.
double Charge(TDC_t tdc) const
Returns the total number of ionization electrons on this channel in the specified TDC...
enum geo::_plane_sigtype SigType_t
bool fPedestalOn
switch for simulation of nonzero pedestals
T get(std::string const &key) const
double fUnderflowProbs[64]
array of probabilities of 6 LSF bits getting stuck at 111111
float fCollectionPedRMS
ADC value of baseline RMS for collection plane.
raw::Compress_t fCompression
compression type to use
std::vector< double > fChargeWork
std::vector< float > fFractZVMiss
float fNoiseWidthV
exponential noise width (kHz) for V plane
float fNoiseFactZ
noise scale factor for Z (collection) plane
float fCollectionCalibPed
Assumed measured value for coll plane pedestal.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
void produce(art::Event &evt)
unsigned int fNTimeSamples
number of ADC readout samples in all readout frames (per event)
float fCollectionCalibPedRMS
Assumed measured value for coll plane pedestal RMS.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::vector< float > fFractVertGapVMiss
auto array(Array const &a)
Returns a manipulator which will print the specified array.
std::string fDriftEModuleLabel
module making the ionization electrons
void Convolute(detinfo::DetectorClocksData const &clockData, Channel channel, std::vector< T > &func) const
std::vector< float > fFractVertGapVCollect
std::vector< std::vector< float > > fNoiseZ
noise on each channel for each time for Z (collection) plane
std::vector< sim::IDE > TrackIDsAndEnergies(TDC_t startTDC, TDC_t endTDC) const
Return all the recorded energy deposition within a time interval.
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
CLHEP::HepRandomEngine & fEngine
std::vector< float > fFractVVCollect
std::string fStuckBitsProbabilitiesFname
file holding ADC stuck code overflow and underflow probabilities
double fSampleRate
sampling rate in ns
std::vector< float > fFractVertGapUMiss
std::string find_file(std::string const &filename) const
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
bool fSimStuckBits
switch for simulation of stuck bits
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
double fOverflowProbs[64]
array of probabilities of 6 LSF bits getting stuck at 000000
std::vector< std::vector< float > > fNoiseV
noise on each channel for each time for V plane
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Tools and modules for checking out the basics of the Monte Carlo.
float fLowCutoffV
low frequency filter cutoff (kHz) for V plane
double GetASICGain(Channel channel) const override
std::vector< uint32_t > fLastChannelsInPlane
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
unsigned int fZeroThreshold
Zero suppression threshold.
uint32_t fFirstCollectionChannel
float fNoiseFactV
noise scale factor for V plane
LArSoft geometry interface.
std::vector< float > fFractHorizGapUCollect
float fLowCutoff
low frequency filter cutoff (kHz)
std::string fStuckBitsOverflowProbHistoName
Name of histogram holding ADC stuck code overflow probabilities.
std::vector< float > fFractZUMiss
unsigned int fNeighboringChannels
Number of neighboring channels on either side allowed to influence zero suppression.
std::vector< float > fFractVertGapZMiss
std::vector< float > fFractVertGapUCollect
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Signal from collection planes.
std::vector< double > DoubleVec
const float adcsaturation