LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ScintTimeLAr.cc
Go to the documentation of this file.
1 // Class: ScintTimeLAr
3 // Plugin Type: tool
4 // File: ScintTimeLAr_tool.cc ScintTimeLAr.h
5 // Description:
6 // Generate a random number for timing of LAr scintillation
7 // Oct. 8 by Mu Wei
10 
11 #include "fhiclcpp/ParameterSet.h"
12 
13 namespace phot {
14  //......................................................................
16  : LogLevel{pset.get<int>("LogLevel")}
17  , SRTime{pset.get<double>("SlowRisingTime", 0.)}
18  , SDTime{pset.get<double>("SlowDecayTime", 0.)}
19  , FRTime{pset.get<double>("FastRisingTime", 0.)}
20  , FDTime{pset.get<double>("FastDecayTime", 0.)}
21  , fNoFastRisingTime((FRTime >= 1.e-8) && (FRTime != -1.))
22  , fNoSlowRisingTime((SRTime >= 1.e-8) && (SRTime != -1.))
23  {
24  if (LogLevel >= 1) {
25  std::cout << "ScintTimeLAr Tool configure:" << std::endl;
26  std::cout << "Fast rising time: " << FRTime << ", Fast decay time: " << FDTime
27  << ", Slow rising time: " << SRTime << ", Slow decay time: " << SDTime << std::endl;
28  }
29  }
30 
31  void ScintTimeLAr::initRand(CLHEP::HepRandomEngine& engine)
32  {
33  fUniformGen = std::make_unique<CLHEP::RandFlat>(engine);
34  }
35 
36  //......................................................................
37  double ScintTimeLAr::single_exp(double t, double tau2) const
38  {
39  return std::exp((-1.0 * t) / tau2) / tau2;
40  }
41 
42  //......................................................................
43  double ScintTimeLAr::bi_exp(double t, double tau1, double tau2) const
44  {
45  return (((std::exp((-1.0 * t) / tau2) * (1.0 - std::exp((-1.0 * t) / tau1))) / tau2) / tau2) *
46  (tau1 + tau2);
47  }
48 
49  //......................................................................
50  double ScintTimeLAr::with_rising_time(double tau1, double tau2)
51  {
52  // TODO: This method is very inefficient.
53  // If we care about simulating the rising time, it would be better
54  // to simulate random numbers according a general distribution
55  double d = (tau1 + tau2) / tau2;
56  while (1) {
57  double ran1 = fUniformGen->fire();
58  double ran2 = fUniformGen->fire();
59  double t = -tau2 * std::log(1 - ran1);
60  double g = d * single_exp(t, tau2);
61  if (ran2 <= bi_exp(t, tau1, tau2) / g) { return t; }
62  }
63  }
64 
65  //......................................................................
66  // Returns the time within the time distribution of the
67  // scintillation process, when the photon was created.
68  // Scintillation light has an exponential decay which is given by
69  // the decay time, tau2, and an exponential increase, which here is
70  // given by the rise time, tau1.
71  void ScintTimeLAr::GenScintTime(bool is_fast, CLHEP::HepRandomEngine& engine)
72  {
73  double tau1;
74  double tau2;
75 
76  if (is_fast) {
77  tau1 = FRTime;
78  tau2 = FDTime;
79  }
80  else {
81  tau1 = SRTime;
82  tau2 = SDTime;
83  }
84 
85  CLHEP::RandFlat randflatscinttime{engine};
86 
87  if ((tau1 < 1e-8) || (tau1 == -1.0)) {
88  timing = -tau2 * std::log(randflatscinttime());
89  return;
90  }
91 
92  //ran1, ran2 = random numbers for the algorithm
93  while (1) {
94  auto ran1 = randflatscinttime();
95  auto ran2 = randflatscinttime();
96  auto d = (tau1 + tau2) / tau2;
97  auto t = -tau2 * std::log(1 - ran1);
98  auto g = d * single_exp(t, tau2);
99  if (ran2 <= bi_exp(t, tau1, tau2) / g) {
100  timing = t;
101  return;
102  }
103  }
104  }
105 
107  {
108  if (fNoFastRisingTime) { return -FDTime * std::log(fUniformGen->fire()); }
109  return with_rising_time(FRTime, FDTime);
110  }
111 
113  {
114  if (fNoSlowRisingTime) { return -SDTime * std::log(fUniformGen->fire()); }
115  return with_rising_time(SRTime, SDTime);
116  }
117 
118 }
double bi_exp(double t, double tau1, double tau2) const
Definition: ScintTimeLAr.cc:43
void GenScintTime(bool is_fast, CLHEP::HepRandomEngine &engine)
Definition: ScintTimeLAr.cc:71
ScintTimeLAr(fhicl::ParameterSet const &pset)
Definition: ScintTimeLAr.cc:15
const bool fNoSlowRisingTime
Definition: ScintTimeLAr.h:40
T get(std::string const &key) const
Definition: ParameterSet.h:314
Float_t d
Definition: plot.C:235
std::unique_ptr< CLHEP::RandFlat > fUniformGen
Definition: ScintTimeLAr.h:34
void initRand(CLHEP::HepRandomEngine &engine)
Definition: ScintTimeLAr.cc:31
const double SRTime
Definition: ScintTimeLAr.h:36
General LArSoft Utilities.
const double FDTime
Definition: ScintTimeLAr.h:39
double single_exp(double t, double tau2) const
Definition: ScintTimeLAr.cc:37
const double FRTime
Definition: ScintTimeLAr.h:38
const bool fNoFastRisingTime
Definition: ScintTimeLAr.h:40
const double SDTime
Definition: ScintTimeLAr.h:37
Float_t e
Definition: plot.C:35
double with_rising_time(double tau1, double tau2)
Definition: ScintTimeLAr.cc:50
double timing
Definition: ScintTime.h:29