All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SBNDuBooNEDataDrivenNoiseService.h
Go to the documentation of this file.
1 // SBNDuBooNEDataDrivenNoiseService.h
2 // Andrew Scarff (University of Sheffield)
3 // July 2019
4 
5 // Based upon SPhaseChannelNoiseService.h created by Jingbo Wang (UC Davis) for ProtoDUNE.
6 
7 // Implementation of a general TPC channel noise model with:
8 // (1) white noise
9 // (2) Inherent Gaussian noise in frequency
10 // (3) MicroBooNE noise in frequency
11 // (4) Coherent noise (exponential + Gaussian) in frequency
12 // (Note a: phase at each frequency bin is randamized at the moment. Will be updated soon
13 // Note b: Currently, consecutive offline channels (configurable) are grouped together and
14 // the same coherent noise waveform is assigned to channels within the same group. )
15 //
16 // The default parameters are obtained from the ProtoDUNE-SP data (run 4096)
17 // fcl file: sbndcode/DetectorSim/Services/noiseservices_sbnd.fcl
18 //
19 
20 #ifndef SBNDuBooNEDataDrivenNoiseService_H
21 #define SBNDuBooNEDataDrivenNoiseService_H
22 
24 
25 #include "art_root_io/TFileService.h"
26 #include "art/Framework/Services/Registry/ServiceDeclarationMacros.h"
30 #include "nurandom/RandomUtils/NuRandomService.h"
31 
32 #include "CLHEP/Random/JamesRandom.h"
33 #include "CLHEP/Random/RandFlat.h"
34 #include "CLHEP/Random/RandGaussQ.h"
35 
36 #include "TH1F.h"
37 #include "TRandom3.h"
38 #include "TF1.h"
39 #include "TMath.h"
40 
41 #include <vector>
42 #include <iostream>
43 #include <sstream>
44 
45 class TH1;
46 namespace CLHEP {
47 class HepRandomEngine;
48 }
49 
51 
52 public:
53 
54  // Ctor.
55  SBNDuBooNEDataDrivenNoiseService(fhicl::ParameterSet const& pset);
56 
57  // Ctor.
58  SBNDuBooNEDataDrivenNoiseService(fhicl::ParameterSet const& pset, art::ActivityRegistry&);
59 
60  // Dtor.
62 
63  // Add noise to a signal array.
64  int addNoise(detinfo::DetectorClocksData const& clockData, Channel chan, AdcSignalVector& sigs) const override;
65 
66  void generateNoise(detinfo::DetectorClocksData const& clockData) override;
67 
68  // Print the configuration.
69  std::ostream& print(std::ostream& out =std::cout, std::string prefix ="") const override;
70 
71 private:
72 
73  // Fill the noise vectors.
74  //void generateNoise();
75 
76  // Fill a noise vector.
77  // Input vector contents are lost.
78  // The size of the vector is obtained from the FFT service.
79  void generateMicroBooNoise(float wirelength, float ENOB,
80  AdcSignalVector& noise, TH1* aNoiseHist) const;
82  AdcSignalVector& noise, std::vector<float> gausNorm,
83  std::vector<float> gausMean, std::vector<float> gausSigma,
84  TH1* aNoiseHist) const;
86  AdcSignalVector& noise, std::vector<float> gausNorm,
87  std::vector<float> gausMean, std::vector<float> gausSigma,
88  float cohExpNorm, float cohExpWidth, float cohExpOffset,
89  TH1* aNoiseHist) const;
90 
91  // Make coherent groups
92  void makeCoherentGroupsByOfflineChannel(unsigned int nchpergroup);
93  std::vector<unsigned int> fChannelGroupMap; ///< assign each channel a group number
94  std::vector<int> fGroupCoherentNoiseMap; ///< assign each group a noise
95  unsigned int getGroupNumberFromOfflineChannel(unsigned int offlinechan) const;
96  unsigned int getCohNoiseChanFromGroup(unsigned int cohgroup) const;
97 
98  // General parameters
99  unsigned int fNoiseArrayPoints; ///< number of points in randomly generated noise array
100  int fRandomSeed; ///< Seed for random number service. If absent or zero, use SeedSvc.
101  int fLogLevel; ///< Log message level: 0=quiet, 1=init only, 2+=every event
102 
103  // Inherent White noise parameters
105  float fWhiteNoiseZ; ///< Level (per freq bin) for white noise for Z.
106  float fWhiteNoiseU; ///< Level (per freq bin) for white noise for U.
107  float fWhiteNoiseV; ///< Level (per freq bin) for white noise for V.
108 
109  // Inherent Gaussian noise
111  std::vector<float> fGausNormU; ///< noise scale factor for the gaussian component in coherent noise
112  std::vector<float> fGausMeanU; ///< mean of the gaussian component in coherent noise
113  std::vector<float> fGausSigmaU; ///< sigma of the gaussian component in coherent noise
114  std::vector<float> fGausNormV; ///< noise scale factor for the gaussian component in coherent noise
115  std::vector<float> fGausMeanV; ///< mean of the gaussian component in coherent noise
116  std::vector<float> fGausSigmaV; ///< sigma of the gaussian component in coherent noise
117  std::vector<float> fGausNormZ; ///< noise scale factor for the gaussian component in coherent noise
118  std::vector<float> fGausMeanZ; ///< mean of the gaussian component in coherent noise
119  std::vector<float> fGausSigmaZ; ///< sigma of the gaussian component in coherent noise
120 
121  // Inherent MicroBoone noise parameters
122  bool fEnableMicroBooNoise; ///< enable MicroBooNE noise model
123  float fENOB; ///< Effective number of bits
124  bool fIncludeJumpers; ///< Include jumper term
125  float fJumperCapacitance; ///< Capacitance of jumper cables in pF. Defaults to 0 if not included.
126  float fUFirstJumper; ///< Wire number of first wire on U layer to include a jumper cable. Defaults to 0 if not included.
127  float fULastJumper; ///< Wire number of last wire on U layer to include a jumper cable. Defaults to 0 if not included.
128  float fVFirstJumper; ///< Wire number of first wire on V layer to include a jumper cable. Defaults to 0 if not included.
129  float fVLastJumper; ///< Wire number of last wire on V layer to include a jumper cable. Defaults to 0 if not included.
130  std::vector<float> fNoiseFunctionParameters; ///< Parameters in the MicroBooNE noise model
131 
132  // Coherent Noise parameters
134  std::vector<unsigned int> fNChannelsPerCoherentGroup;
135  unsigned int fExpNoiseArrayPoints; ///< number of points in randomly generated noise array
136  unsigned int fCohNoiseArrayPoints; ///< number of points in randomly generated noise array
137  float fCohExpNorm; ///< noise scale factor for the exponential component component in coherent noise
138  float fCohExpWidth; ///< width of the exponential component in coherent noise
139  float fCohExpOffset; ///< Amplitude offset of the exponential background component in coherent noise
140  std::vector<float> fCohGausNorm; ///< noise scale factor for the gaussian component in coherent noise
141  std::vector<float> fCohGausMean; ///< mean of the gaussian component in coherent noise
142  std::vector<float> fCohGausSigma; ///< sigma of the gaussian component in coherent noise
143 
144 
145  // Inherent Gausian noise arrays
149 
150  // Inherent MicroBoo noise arrays
154 
155  // Coherent Noise array.
156  AdcSignalVectorVector fCohNoiseZ; ///< noise on each channel for each time for all planes
157  AdcSignalVectorVector fCohNoiseU; ///< noise on each channel for each time for all planes
158  AdcSignalVectorVector fCohNoiseV; ///< noise on each channel for each time for all planes
159 
160 
161  // Histograms.
162 
163  TH1* fGausNoiseHistZ; ///< distribution of noise counts for Z
164  TH1* fGausNoiseHistU; ///< distribution of noise counts for U
165  TH1* fGausNoiseHistV; ///< distribution of noise counts for V
166  TH1* fGausNoiseChanHist; ///< distribution of accessed noise samples
167 
168  TH1* fMicroBooNoiseHistZ; ///< distribution of noise counts for Z
169  TH1* fMicroBooNoiseHistU; ///< distribution of noise counts for U
170  TH1* fMicroBooNoiseHistV; ///< distribution of noise counts for V
171  TH1* fMicroBooNoiseChanHist; ///< distribution of accessed noise samples
172 
173  TH1* fCohNoiseHist; ///< distribution of noise counts
174  TH1* fCohNoiseChanHist; ///< distribution of accessed noise samples
175 
176  TF1* _wld_f;
177  double wldparams[2];
178 
179  TF1* _poisson;
180 
181 
182  // Randomisation.
183  bool haveSeed;
184  CLHEP::HepRandomEngine* m_pran;
185  CLHEP::HepRandomEngine* ConstructRandomEngine(const bool haveSeed);
186  double GetRandomTF1(TF1* func) const;
187  TRandom3* fTRandom3;
188 
189 
190 };
191 
192 DECLARE_ART_SERVICE_INTERFACE_IMPL(SBNDuBooNEDataDrivenNoiseService, ChannelNoiseService, LEGACY)
193 
194 #endif
float fCohExpOffset
Amplitude offset of the exponential background component in coherent noise.
AdcSignalVectorVector fCohNoiseZ
noise on each channel for each time for all planes
TH1 * fGausNoiseHistU
distribution of noise counts for U
void generateCoherentNoise(detinfo::DetectorClocksData const &clockData, AdcSignalVector &noise, std::vector< float > gausNorm, std::vector< float > gausMean, std::vector< float > gausSigma, float cohExpNorm, float cohExpWidth, float cohExpOffset, TH1 *aNoiseHist) const
int fLogLevel
Log message level: 0=quiet, 1=init only, 2+=every event.
std::vector< float > fGausMeanU
mean of the gaussian component in coherent noise
int addNoise(detinfo::DetectorClocksData const &clockData, Channel chan, AdcSignalVector &sigs) const override
float fWhiteNoiseV
Level (per freq bin) for white noise for V.
TH1 * fMicroBooNoiseHistV
distribution of noise counts for V
void generateGaussianNoise(detinfo::DetectorClocksData const &clockData, AdcSignalVector &noise, std::vector< float > gausNorm, std::vector< float > gausMean, std::vector< float > gausSigma, TH1 *aNoiseHist) const
TH1 * fMicroBooNoiseChanHist
distribution of accessed noise samples
AdcSignalVectorVector fCohNoiseU
noise on each channel for each time for all planes
void makeCoherentGroupsByOfflineChannel(unsigned int nchpergroup)
std::vector< float > fGausMeanV
mean of the gaussian component in coherent noise
SBNDuBooNEDataDrivenNoiseService(fhicl::ParameterSet const &pset)
TH1 * fCohNoiseChanHist
distribution of accessed noise samples
std::vector< float > fGausNormV
noise scale factor for the gaussian component in coherent noise
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const override
unsigned int getGroupNumberFromOfflineChannel(unsigned int offlinechan) const
float fJumperCapacitance
Capacitance of jumper cables in pF. Defaults to 0 if not included.
std::vector< int > fGroupCoherentNoiseMap
assign each group a noise
AdcSignalVectorVector fCohNoiseV
noise on each channel for each time for all planes
std::vector< unsigned int > fChannelGroupMap
assign each channel a group number
int fRandomSeed
Seed for random number service. If absent or zero, use SeedSvc.
std::vector< float > fCohGausSigma
sigma of the gaussian component in coherent noise
std::vector< float > fNoiseFunctionParameters
Parameters in the MicroBooNE noise model.
bool fEnableMicroBooNoise
enable MicroBooNE noise model
float fCohExpNorm
noise scale factor for the exponential component component in coherent noise
unsigned int fExpNoiseArrayPoints
number of points in randomly generated noise array
float fWhiteNoiseZ
Level (per freq bin) for white noise for Z.
std::vector< float > fGausSigmaV
sigma of the gaussian component in coherent noise
void generateNoise(detinfo::DetectorClocksData const &clockData) override
std::vector< AdcSignalVector > AdcSignalVectorVector
float fWhiteNoiseU
Level (per freq bin) for white noise for U.
std::vector< float > fGausMeanZ
mean of the gaussian component in coherent noise
TH1 * fMicroBooNoiseHistU
distribution of noise counts for U
float fULastJumper
Wire number of last wire on U layer to include a jumper cable. Defaults to 0 if not included...
float fVFirstJumper
Wire number of first wire on V layer to include a jumper cable. Defaults to 0 if not included...
std::vector< float > fGausSigmaU
sigma of the gaussian component in coherent noise
std::vector< AdcSignal > AdcSignalVector
std::vector< float > fGausSigmaZ
sigma of the gaussian component in coherent noise
std::vector< float > fCohGausMean
mean of the gaussian component in coherent noise
void generateMicroBooNoise(float wirelength, float ENOB, AdcSignalVector &noise, TH1 *aNoiseHist) const
Contains all timing reference information for the detector.
TH1 * fCohNoiseHist
distribution of noise counts
std::vector< float > fGausNormZ
noise scale factor for the gaussian component in coherent noise
unsigned int fCohNoiseArrayPoints
number of points in randomly generated noise array
float fVLastJumper
Wire number of last wire on V layer to include a jumper cable. Defaults to 0 if not included...
TH1 * fMicroBooNoiseHistZ
distribution of noise counts for Z
CLHEP::HepRandomEngine * ConstructRandomEngine(const bool haveSeed)
TH1 * fGausNoiseHistV
distribution of noise counts for V
TH1 * fGausNoiseHistZ
distribution of noise counts for Z
unsigned int fNoiseArrayPoints
number of points in randomly generated noise array
float fUFirstJumper
Wire number of first wire on U layer to include a jumper cable. Defaults to 0 if not included...
float fCohExpWidth
width of the exponential component in coherent noise
std::vector< unsigned int > fNChannelsPerCoherentGroup
std::vector< float > fCohGausNorm
noise scale factor for the gaussian component in coherent noise
unsigned int getCohNoiseChanFromGroup(unsigned int cohgroup) const
TH1 * fGausNoiseChanHist
distribution of accessed noise samples
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::vector< float > fGausNormU
noise scale factor for the gaussian component in coherent noise