All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DigiArapucaSBNDAlg.hh
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // File: DigiArapucaSBNDAlg.hh
3 //
4 // This algorithm is used for the electronic response of arapucas
5 // Created by L. Paulucci, F. Marinho and I.L. de Icaza
6 // Based on OpDetDigitizerDUNE_module.cc and SimPMTSBND_module.cc
7 ////////////////////////////////////////////////////////////////////////
8 
9 #ifndef SBND_OPDETSIM_DIGIARAPUCASBNDALG_HH
10 #define SBND_OPDETSIM_DIGIARAPUCASBNDALG_HH
11 
12 #include "fhiclcpp/types/Atom.h"
13 #include "messagefacility/MessageLogger/MessageLogger.h"
14 #include "nurandom/RandomUtils/NuRandomService.h"
15 #include "CLHEP/Random/RandFlat.h"
16 #include "CLHEP/Random/RandGaussQ.h"
17 #include "CLHEP/Random/RandGeneral.h"
18 #include "CLHEP/Random/RandPoissonQ.h"
19 #include "CLHEP/Random/RandExponential.h"
20 
21 #include <algorithm>
22 #include <memory>
23 #include <vector>
24 #include <cmath>
25 #include <string>
26 #include <map>
27 #include <unordered_map>
28 #include <set>
29 #include <sstream>
30 #include <fstream>
31 
36 
37 #include "TFile.h"
38 
39 namespace opdet {
40 
42 
43  public:
44 
46  double PeakTime; // maximum time of each component pulse in ns
47  double PulseLength; // in ns
48  double MeanAmplitude; // Mean amplitude for pulses in mV
49  double RiseTime; // pulse rising time constant (exponential)
50  double FallTime; // pulse decaying time constant (exponential)
51  double ADC; //voltage to ADC convertion scale
52  double Baseline; //waveform baseline
53  double BaselineRMS; //Pedestal RMS in ADC counts
54  double DarkNoiseRate; //in Hz
55  double CrossTalk; //probability for producing a signal of 2 PE in response to 1 photon
56  double Saturation; //Saturation in number of p.e.
57  double XArapucaVUVEff; //XArapucaVUV efficiency (optical window + cavity)
58  double XArapucaVISEff; //XArapucaVIS efficiency (optical window + cavity)
59  double DecayTXArapucaVIS;// Decay time of EJ280 in ns
60  std::string ArapucaDataFile; //File containing timing structure for arapucas
61  bool ArapucaSinglePEmodel; //Model for single pe response, false for ideal, true for test bench meas
62  bool MakeAmpFluctuations; //Add amplitude fluctuations to the simulation
63  double AmpFluctuation; //Model for single pe response, false for ideal, true for test bench meas
64 
65  detinfo::LArProperties const* larProp = nullptr; ///< LarProperties service provider.
66  double frequency; ///< Optical-clock frequency
67  double frequency_Daphne; ///< Optical-clock frequency for daphne readouts
68 
69  CLHEP::HepRandomEngine* engine = nullptr;
70  };// ConfigurationParameters_t
71 
72  //Default constructor
74  //Default destructor
76 
77  double Baseline()
78  {
79  return fParams.Baseline;
80  }
81 
82  void ConstructWaveform(int ch,
83  sim::SimPhotons const& simphotons,
84  std::vector<short unsigned int>& waveform,
85  std::string pdtype,
86  bool is_daphne,
87  double start_time,
88  unsigned n_samples);
89  void ConstructWaveformLite(int ch,
90  sim::SimPhotonsLite const& litesimphotons,
91  std::vector<short unsigned int>& waveform,
92  std::string pdtype,
93  bool is_daphne,
94  double start_time,
95  unsigned n_samples);
96  // double P_truth=0;
97 
98  private:
99 
100  // Declare member data here.
102 
103  const double fSampling; //wave sampling frequency (GHz)
104  const double fSampling_Daphne; //wave sampling frequency (GHz)
105  const double fXArapucaVUVEff;
106  const double fXArapucaVISEff;
107  const double fADCSaturation;
108 
109  CLHEP::HepRandomEngine* fEngine; //!< Reference to art-managed random-number engine
110  CLHEP::RandFlat fFlatGen;
111  CLHEP::RandPoissonQ fPoissonQGen;
112  CLHEP::RandGaussQ fGaussQGen;
113  CLHEP::RandExponential fExponentialGen;
114  std::unique_ptr<CLHEP::RandGeneral> fTimeXArapucaVUV;// histogram for getting the photon time distribution inside the XArapuca VUV box (considering the optical window)
115  std::unique_ptr<CLHEP::RandGeneral> fTimeTPB; // histogram for getting the TPB emission time for visible (x)arapucas
116 
117  std::vector<double> fWaveformSP; //single photon pulse vector
118  std::vector<double> fWaveformSP_Daphne; //single photon pulse vector
119  std::unordered_map< raw::Channel_t, std::vector<double> > fFullWaveforms;
120 
121  void CreatePDWaveform(sim::SimPhotons const& SimPhotons,
122  double t_min,
123  std::vector<double>& wave,
124  std::string pdtype,
125  bool is_daphne);
126  void CreatePDWaveformLite(std::map<int, int> const& photonMap,
127  double t_min,
128  std::vector<double>& wave,
129  std::string pdtype,
130  bool is_daphne);
131  void SinglePDWaveformCreatorLite(double effT,
132  std::unique_ptr<CLHEP::RandGeneral>& timeHisto,
133  std::vector<double>& wave,
134  std::map<int, int> const& photonMap,
135  double const& t_min,
136  bool is_daphne);
137  void SinglePDWaveformCreatorLite(double effT,
138  std::vector<double>& wave,
139  std::map<int, int> const& photonMap,
140  double const& t_min,
141  bool is_daphne);
142  void AddSPE(size_t time_bin, std::vector<double>& wave, const std::vector<double>& fWaveformSP, int nphotons); // add single pulse to auxiliary waveform
143  void Pulse1PE(std::vector<double>& wave,const double sampling);
144  void AddLineNoise(std::vector<double>& wave);
145  void AddDarkNoise(std::vector<double>& wave , std::vector<double>& WaveformSP);
146  double FindMinimumTime(sim::SimPhotons const& simphotons);
147  double FindMinimumTimeLite(std::map< int, int > const& photonMap);
148  void CreateSaturation(std::vector<double>& wave);//Including saturation effects
149  };//class DigiArapucaSBNDAlg
150 
152 
153  public:
154  struct Config {
155  using Name = fhicl::Name;
156  using Comment = fhicl::Comment;
157 
158  fhicl::Atom<double> peakTime {
159  Name("ArapucaPeakTime"),
160  Comment("Single pe: Time of maximum amplitude in the SiPM pulse in ns")
161  };
162 
163  fhicl::Atom<double> pulseLength {
164  Name("ArapucaPulseLength"),
165  Comment("Single pe: Time length of SiPM pulse")
166  };
167 
168  fhicl::Atom<double> meanAmplitude {
169  Name("ArapucaMeanAmplitude"),
170  Comment("Single pe: mean amplitude of SiPM pulse in mV")
171  };
172 
173  fhicl::Atom<double> riseTime {
174  Name("ArapucaRiseTime"),
175  Comment("Single pe: Pulse rise time constant (exponential), from 0.1 to 0.9 of maximum amplitude")
176  };
177 
178  fhicl::Atom<double> fallTime {
179  Name("ArapucaFallTime"),
180  Comment("Single pe: Pulse decay time constant (exponential), from 0.1 to 0.9 of maximum amplitude")
181  };
182 
183  fhicl::Atom<double> voltageToADC {
184  Name("ArapucaVoltageToADC"),
185  Comment("Voltage to ADC convertion factor")
186  };
187 
188  fhicl::Atom<double> baseline {
189  Name("ArapucaBaseline"),
190  Comment("Waveform baseline in ADC")
191  };
192 
193  fhicl::Atom<double> baselineRMS {
194  Name("ArapucaBaselineRMS"),
195  Comment("RMS of the electronics noise fluctuations in ADC counts")
196  };
197 
198  fhicl::Atom<double> darkNoiseRate {
199  Name("ArapucaDarkNoiseRate"),
200  Comment("Dark noise rate in Hz")
201  };
202 
203  fhicl::Atom<double> crossTalk {
204  Name("CrossTalk"),
205  Comment("Probability for producing a signal of 2 PE in response to 1 photon")
206  };
207 
208  fhicl::Atom<double> saturation {
209  Name("ArapucaSaturation"),
210  Comment("Saturation in number of p.e.")
211  };
212 
213  fhicl::Atom<double> arapucaVUVEff {
214  Name("ArapucaVUVEff"),
215  Comment("Arapuca VUV efficiency (optical window + cavity)")
216  };
217 
218  fhicl::Atom<double> arapucaVISEff {
219  Name("ArapucaVISEff"),
220  Comment("Arapuca VIS efficiency (optical window + cavity)")
221  };
222 
223  fhicl::Atom<double> xArapucaVUVEff {
224  Name("XArapucaVUVEff"),
225  Comment("XArapuca VUV efficiency (optical window + cavity)")
226  };
227 
228  fhicl::Atom<double> xArapucaVISEff {
229  Name("XArapucaVISEff"),
230  Comment("XArapuca VIS efficiency (optical window + cavity)")
231  };
232 
233  fhicl::Atom<double> decayTXArapucaVIS {
234  Name("DecayTXArapucaVIS"),
235  Comment("X-Arapuca VIS decay time of EJ280 in ns")
236  };
237 
238  fhicl::Atom<std::string> arapucaDataFile {
239  Name("ArapucaDataFile"),
240  Comment("File containing timing distribution for ArapucaVUV (optical window + cavity), ArapucaVIS (optical window + cavity), XArapuca VUV (optical window)")
241  };
242 
243  fhicl::Atom<bool> ArapucasinglePEmodel {
244  Name("ArapucaSinglePEmodel"),
245  Comment("Model used for single PE response of PMT. =0 is ideal, =1 is from X-TDBoard data (with overshoot)")
246  };
247 
248  fhicl::Atom<double> DaphneFrequency {
249  Name("DaphneFrequency"),
250  Comment("Sampling Frequency of the XArapucas with Daphne readouts (SBND Light detection system has 2 readout frequencies). Apsaia readouts read the frec value from LArSoft.")
251  };
252 
253  fhicl::Atom<bool> makeAmpFluctuations {
254  Name("MakeAmpFluctuations"),
255  Comment("Include amplitude fluctuations to the simulated wvfs. For each PE, roll a rand number(gaussian distributed) with std=AmpFluctuation.")
256  };
257 
258  fhicl::Atom<double> ampFluctuation {
259  Name("AmpFluctuation"),
260  Comment("Std of the gaussian fit (from data) to the 1PE distribution. Relative units i.e.: AmpFluctuation=0.1-> Amp(1PE)= 18+-1.8 ADC counts")
261  };
262 
263 
264  }; //struct Config
265 
266  DigiArapucaSBNDAlgMaker(Config const& config); //Constructor
267 
268  std::unique_ptr<DigiArapucaSBNDAlg> operator()(
269  detinfo::LArProperties const& larProp,
270  detinfo::DetectorClocksData const& clockData,
271  CLHEP::HepRandomEngine* engine
272  ) const;
273 
274  private:
275  /// Part of the configuration learned from configuration files.
277  }; //class DigiArapucaSBNDAlgMaker
278 
279 } //namespace
280 
281 #endif // SBND_OPDETSIM_DIGIARAPUCASBNDALG_HH
double FindMinimumTime(sim::SimPhotons const &simphotons)
std::vector< double > fWaveformSP_Daphne
void AddDarkNoise(std::vector< double > &wave, std::vector< double > &WaveformSP)
CLHEP::HepRandomEngine * fEngine
Reference to art-managed random-number engine.
void AddLineNoise(std::vector< double > &wave)
DigiArapucaSBNDAlg::ConfigurationParameters_t fBaseConfig
Part of the configuration learned from configuration files.
std::unique_ptr< CLHEP::RandGeneral > fTimeXArapucaVUV
Simulation objects for optical detectors.
CLHEP::RandExponential fExponentialGen
std::vector< double > fWaveformSP
void ConstructWaveformLite(int ch, sim::SimPhotonsLite const &litesimphotons, std::vector< short unsigned int > &waveform, std::string pdtype, bool is_daphne, double start_time, unsigned n_samples)
void AddSPE(size_t time_bin, std::vector< double > &wave, const std::vector< double > &fWaveformSP, int nphotons)
BEGIN_PROLOG vertical distance to the surface Name
std::unique_ptr< CLHEP::RandGeneral > fTimeTPB
detinfo::LArProperties const * larProp
LarProperties service provider.
std::unique_ptr< DigiArapucaSBNDAlg > operator()(detinfo::LArProperties const &larProp, detinfo::DetectorClocksData const &clockData, CLHEP::HepRandomEngine *engine) const
void CreateSaturation(std::vector< double > &wave)
DigiArapucaSBNDAlgMaker(Config const &config)
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
Compact representation of photons on a channel.
Definition: SimPhotons.h:103
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production start_time
void CreatePDWaveform(sim::SimPhotons const &SimPhotons, double t_min, std::vector< double > &wave, std::string pdtype, bool is_daphne)
CLHEP::RandPoissonQ fPoissonQGen
void CreatePDWaveformLite(std::map< int, int > const &photonMap, double t_min, std::vector< double > &wave, std::string pdtype, bool is_daphne)
Contains all timing reference information for the detector.
DigiArapucaSBNDAlg(ConfigurationParameters_t const &config)
void Pulse1PE(std::vector< double > &wave, const double sampling)
const ConfigurationParameters_t fParams
double frequency_Daphne
Optical-clock frequency for daphne readouts.
void ConstructWaveform(int ch, sim::SimPhotons const &simphotons, std::vector< short unsigned int > &waveform, std::string pdtype, bool is_daphne, double start_time, unsigned n_samples)
void SinglePDWaveformCreatorLite(double effT, std::unique_ptr< CLHEP::RandGeneral > &timeHisto, std::vector< double > &wave, std::map< int, int > const &photonMap, double const &t_min, bool is_daphne)
fhicl::Atom< std::string > arapucaDataFile
std::unordered_map< raw::Channel_t, std::vector< double > > fFullWaveforms
double FindMinimumTimeLite(std::map< int, int > const &photonMap)