All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DigiPMTSBNDAlg.hh
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //// File: DigiPMTSBNDAlg.hh
3 ////
4 //// This algorithm is used for the electronic response of PMTs
5 //// Created by L. Paulucci, F. Marinho, and I.L. de Icaza
6 //// Based on OpDetDigitizerDUNE_module.cc
7 //////////////////////////////////////////////////////////////////////////
8 
9 #ifndef SBND_OPDETSIM_DIGIPMTSBNDALG_HH
10 #define SBND_OPDETSIM_DIGIPMTSBNDALG_HH
11 
12 #include "fhiclcpp/types/Atom.h"
13 #include "fhiclcpp/types/DelegatedParameter.h"
14 #include "fhiclcpp/types/OptionalDelegatedParameter.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
16 #include "nurandom/RandomUtils/NuRandomService.h"
17 #include "CLHEP/Random/RandFlat.h"
18 #include "CLHEP/Random/RandGaussQ.h"
19 #include "CLHEP/Random/RandGeneral.h"
20 #include "CLHEP/Random/RandPoissonQ.h"
21 #include "CLHEP/Random/RandExponential.h"
22 #include "art/Utilities/make_tool.h"
23 
24 #include <algorithm>
25 #include <memory>
26 #include <vector>
27 #include <cmath>
28 #include <string>
29 #include <map>
30 #include <unordered_map>
31 #include <set>
32 #include <sstream>
33 #include <fstream>
34 
39 
41 
42 #include "TFile.h"
43 
44 namespace opdet {
45 
47 
48  public:
49 
51  double TransitTime; //ns
52  double TTS; //ns
53  double CableTime; //ns
54  double PMTChargeToADC; //voltage to ADC conversion scale
55  double PMTBaseline; //waveform baseline in ADC
56  double PMTFallTime; //pulse decaying time constant (exponential) in ns
57  double PMTRiseTime; //pulse rising time constant (exponential) in ns
58  double PMTMeanAmplitude; //mean amplitude for single pe in pC
59  double PMTBaselineRMS; //Pedestal RMS in ADC counts
60  double PMTDarkNoiseRate; //in Hz
61  double PMTSaturation; //in number of p.e.
62  double QEDirect; //PMT quantum efficiency for direct (VUV) light
63  double QERefl; //PMT quantum efficiency for reflected (TPB converted) light
64  std::string PMTDataFile; //File containing timing emission structure for TPB, and single PE profile from data
65  bool PMTSinglePEmodel; //Model for single pe response, false for ideal, true for test bench meas
66  bool MakeGainFluctuations; //Fluctuate PMT gain
67  fhicl::ParameterSet GainFluctuationsParams;
68 
69  detinfo::LArProperties const* larProp = nullptr; //< LarProperties service provider.
70  double frequency; //wave sampling frequency (GHz)
71  CLHEP::HepRandomEngine* engine = nullptr;
72  };// ConfigurationParameters_t
73 
74  //Default constructor
76  //Default destructor
78 
79  void ConstructWaveform(
80  int ch,
81  sim::SimPhotons const& simphotons,
82  std::vector<short unsigned int>& waveform,
83  std::string pdtype,
84  double start_time,
85  unsigned n_sample);
86 
88  int ch,
89  std::vector<short unsigned int>& waveform,
90  std::unordered_map<int, sim::SimPhotons>& DirectPhotonsMap,
91  std::unordered_map<int, sim::SimPhotons>& ReflectedPhotonsMap,
92  double start_time,
93  unsigned n_sample);
94 
96  int ch,
97  sim::SimPhotonsLite const& litesimphotons,
98  std::vector<short unsigned int>& waveform,
99  std::string pdtype,
100  double start_time,
101  unsigned n_sample);
102 
104  int ch,
105  std::vector<short unsigned int>& waveform,
106  std::unordered_map<int, sim::SimPhotonsLite>& DirectPhotonsMap,
107  std::unordered_map<int, sim::SimPhotonsLite>& ReflectedPhotonsMap,
108  double start_time,
109  unsigned n_sample);
110 
111  double Baseline()
112  {
113  return fParams.PMTBaseline;
114  }
115 
116  private:
117 
119  // Declare member data here.
120  double fSampling; //wave sampling frequency (GHz)
121  double fQEDirect;
122  double fQERefl;
123  //int fSinglePEmodel;
124  double sigma1;
125  double sigma2;
126 
127  const double transitTimeSpread_frac = 2.0 * std::sqrt(2.0 * std::log(2.0));
128  double saturation;
129 
130  CLHEP::HepRandomEngine* fEngine; //!< Reference to art-managed random-number engine
131  CLHEP::RandFlat fFlatGen;
132  CLHEP::RandPoissonQ fPoissonQGen;
133  CLHEP::RandGaussQ fGaussQGen;
134  CLHEP::RandExponential fExponentialGen;
135  std::unique_ptr<CLHEP::RandGeneral> fTimeTPB; // histogram for getting the TPB emission time for coated PMTs
136 
137 
138  //PMTFluctuationsAlg
139  std::unique_ptr<opdet::PMTGainFluctuations> fPMTGainFluctuationsPtr;
140 
141  void AddSPE(size_t time_bin, std::vector<double>& wave); // add single pulse to auxiliary waveform
142  void Pulse1PE(std::vector<double>& wave);
143  double Transittimespread(double fwhm);
144 
145  std::vector<double> fSinglePEWave; // single photon pulse vector
146  int pulsesize; //size of 1PE waveform
147  std::unordered_map< raw::Channel_t, std::vector<double> > fFullWaveforms;
148 
149  void CreatePDWaveform(
150  sim::SimPhotons const& SimPhotons,
151  double t_min,
152  std::vector<double>& wave,
153  int ch,
154  std::string pdtype);
156  int ch,
157  double t_min,
158  std::vector<double>& wave,
159  std::unordered_map<int, sim::SimPhotons>& DirectPhotonsMap,
160  std::unordered_map<int, sim::SimPhotons>& ReflectedPhotonsMap);
162  sim::SimPhotonsLite const& litesimphotons,
163  double t_min,
164  std::vector<double>& wave,
165  int ch,
166  std::string pdtype);
168  int ch,
169  double t_min,
170  std::vector<double>& wave,
171  std::unordered_map<int, sim::SimPhotonsLite>& DirectPhotonsMap,
172  std::unordered_map<int, sim::SimPhotonsLite>& ReflectedPhotonsMap);
173  void CreateSaturation(std::vector<double>& wave);//Including saturation effects
174  void AddLineNoise(std::vector<double>& wave); //add noise to baseline
175  void AddDarkNoise(std::vector<double>& wave); //add dark noise
176  double FindMinimumTime(
177  sim::SimPhotons const&,
178  int ch,
179  std::string pdtype,
180  std::unordered_map<int, sim::SimPhotons>& directPhotonsOnPMTS);
181  double FindMinimumTimeLite(
182  sim::SimPhotonsLite const& litesimphotons,
183  int ch,
184  std::string pdtype,
185  std::unordered_map<int, sim::SimPhotonsLite>& directPhotonsOnPMTS);
186  };//class DigiPMTSBNDAlg
187 
189 
190  public:
191  struct Config {
192  using Name = fhicl::Name;
193  using Comment = fhicl::Comment;
194 
195  fhicl::Atom<double> transitTime {
196  Name("TransitTime"),
197  Comment("Single pe: Time of maximum amplitude in the PMT pulse in ns")
198  };
199 
200  fhicl::Atom<double> tts {
201  Name("TTS"),
202  Comment("Single pe: Transit time spread in ns")
203  };
204 
205  fhicl::Atom<double> cableTime {
206  Name("CableTime"),
207  Comment("Time delay of the 30 m long readout cable in ns")
208  };
209 
210  fhicl::Atom<double> pmtmeanAmplitude {
211  Name("PMTMeanAmplitude"),
212  Comment("Single pe: mean amplitude of PMT pulse in pC")
213  };
214 
215  fhicl::Atom<double> pmtriseTime {
216  Name("PMTRiseTime"),
217  Comment("Single pe: Pulse rise time constant (exponential), from 0.1 to 0.9 of maximum amplitude")
218  };
219 
220  fhicl::Atom<double> pmtfallTime {
221  Name("PMTFallTime"),
222  Comment("Single pe: Pulse decay time constant (exponential), from 0.1 to 0.9 of maximum amplitude")
223  };
224 
225  fhicl::Atom<double> pmtchargeToADC {
226  Name("PMTChargeToADC"),
227  Comment("Charge to ADC convertion factor")
228  };
229 
230  fhicl::Atom<double> pmtbaseline {
231  Name("PMTBaseline"),
232  Comment("Waveform baseline in ADC")
233  };
234 
235  fhicl::Atom<double> pmtbaselineRMS {
236  Name("PMTBaselineRMS"),
237  Comment("RMS of the electronics noise fluctuations in ADC counts")
238  };
239 
240  fhicl::Atom<double> pmtdarkNoiseRate {
241  Name("PMTDarkNoiseRate"),
242  Comment("Dark noise rate in Hz")
243  };
244 
245  fhicl::Atom<double> pmtsaturation {
246  Name("PMTSaturation"),
247  Comment("Saturation in number of p.e.")
248  };
249 
250  fhicl::Atom<double> qEDirect {
251  Name("QEDirect"),
252  Comment("PMT quantum efficiency for direct (VUV) light")
253  };
254 
255  fhicl::Atom<double> qERefl {
256  Name("QERefl"),
257  Comment("PMT quantum efficiency for reflected (TPB emitted)light")
258  };
259 
260  fhicl::Atom<bool> PMTsinglePEmodel {
261  Name("PMTSinglePEmodel"),
262  Comment("Model used for single PE response of PMT. =0 is ideal, =1 is testbench")
263  };
264 
265  fhicl::Atom<std::string> pmtDataFile {
266  Name("PMTDataFile"),
267  Comment("File containing timing emission distribution for TPB and single pe pulse from data")
268  };
269 
270  fhicl::Atom<bool> makeGainFluctuations {
271  Name("MakeGainFluctuations"),
272  Comment("Option to fluctuate PMT gain")
273  };
274 
275  fhicl::OptionalDelegatedParameter gainFluctuationsParams {
276  Name("GainFluctuationsParams"),
277  Comment("Parameters used for SinglePE response fluctuations")
278  };
279 
280  }; //struct Config
281 
282  DigiPMTSBNDAlgMaker(Config const& config); //Constructor
283 
284  std::unique_ptr<DigiPMTSBNDAlg> operator()(
285  detinfo::LArProperties const& larProp,
286  detinfo::DetectorClocksData const& clockData,
287  CLHEP::HepRandomEngine* engine
288  ) const;
289 
290  private:
291  // Part of the configuration learned from configuration files.
293  }; //class DigiPMTSBNDAlgMaker
294 
295 } // namespace opdet
296 
297 #endif //SBND_OPDETSIM_DIGIPMTSBNDALG_HH
std::unique_ptr< CLHEP::RandGeneral > fTimeTPB
void CreatePDWaveformLiteCoatedPMT(int ch, double t_min, std::vector< double > &wave, std::unordered_map< int, sim::SimPhotonsLite > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotonsLite > &ReflectedPhotonsMap)
void CreatePDWaveformLite(sim::SimPhotonsLite const &litesimphotons, double t_min, std::vector< double > &wave, int ch, std::string pdtype)
ConfigurationParameters_t fParams
void ConstructWaveform(int ch, sim::SimPhotons const &simphotons, std::vector< short unsigned int > &waveform, std::string pdtype, double start_time, unsigned n_sample)
CLHEP::RandExponential fExponentialGen
CLHEP::RandFlat fFlatGen
DigiPMTSBNDAlg::ConfigurationParameters_t fBaseConfig
void ConstructWaveformLiteCoatedPMT(int ch, std::vector< short unsigned int > &waveform, std::unordered_map< int, sim::SimPhotonsLite > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotonsLite > &ReflectedPhotonsMap, double start_time, unsigned n_sample)
void CreateSaturation(std::vector< double > &wave)
fhicl::Atom< double > pmtdarkNoiseRate
std::vector< double > fSinglePEWave
void ConstructWaveformLite(int ch, sim::SimPhotonsLite const &litesimphotons, std::vector< short unsigned int > &waveform, std::string pdtype, double start_time, unsigned n_sample)
const double transitTimeSpread_frac
Simulation objects for optical detectors.
void AddDarkNoise(std::vector< double > &wave)
double Transittimespread(double fwhm)
void AddLineNoise(std::vector< double > &wave)
std::unique_ptr< DigiPMTSBNDAlg > operator()(detinfo::LArProperties const &larProp, detinfo::DetectorClocksData const &clockData, CLHEP::HepRandomEngine *engine) const
fhicl::Atom< std::string > pmtDataFile
void CreatePDWaveformCoatedPMT(int ch, double t_min, std::vector< double > &wave, std::unordered_map< int, sim::SimPhotons > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotons > &ReflectedPhotonsMap)
CLHEP::RandPoissonQ fPoissonQGen
CLHEP::HepRandomEngine * fEngine
Reference to art-managed random-number engine.
void ConstructWaveformCoatedPMT(int ch, std::vector< short unsigned int > &waveform, std::unordered_map< int, sim::SimPhotons > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotons > &ReflectedPhotonsMap, double start_time, unsigned n_sample)
BEGIN_PROLOG vertical distance to the surface Name
fhicl::Atom< bool > makeGainFluctuations
fhicl::Atom< double > pmtsaturation
std::unique_ptr< opdet::PMTGainFluctuations > fPMTGainFluctuationsPtr
DigiPMTSBNDAlg(ConfigurationParameters_t const &config)
fhicl::Atom< double > pmtmeanAmplitude
fhicl::Atom< double > pmtchargeToADC
fhicl::Atom< double > pmtbaselineRMS
void CreatePDWaveform(sim::SimPhotons const &SimPhotons, double t_min, std::vector< double > &wave, int ch, std::string pdtype)
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
Contains all timing reference information for the detector.
std::unordered_map< raw::Channel_t, std::vector< double > > fFullWaveforms
void Pulse1PE(std::vector< double > &wave)
DigiPMTSBNDAlgMaker(Config const &config)
double FindMinimumTimeLite(sim::SimPhotonsLite const &litesimphotons, int ch, std::string pdtype, std::unordered_map< int, sim::SimPhotonsLite > &directPhotonsOnPMTS)
void AddSPE(size_t time_bin, std::vector< double > &wave)
fhicl::OptionalDelegatedParameter gainFluctuationsParams
CLHEP::RandGaussQ fGaussQGen
double FindMinimumTime(sim::SimPhotons const &, int ch, std::string pdtype, std::unordered_map< int, sim::SimPhotons > &directPhotonsOnPMTS)