LArSoft  v10_06_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(pset.get<bool>("NoFastRisingTime", false))
22  , fNoSlowRisingTime(pset.get<bool>("NoSlowRisingTime", false))
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  int ncalls = 0;
57  while (1) {
58  ++ncalls;
59  double ran1 = fUniformGen->fire();
60  double ran2 = fUniformGen->fire();
61  double t = -tau2 * std::log(1 - ran1);
62  double g = d * single_exp(t, tau2);
63  if (ran2 <= bi_exp(t, tau1, tau2) / g) { return t; }
64  }
65  }
66 
67  //......................................................................
68  // Returns the time within the time distribution of the
69  // scintillation process, when the photon was created.
70  // Scintillation light has an exponential decay which is given by
71  // the decay time, tau2, and an exponential increase, which here is
72  // given by the rise time, tau1.
73  void ScintTimeLAr::GenScintTime(bool is_fast, CLHEP::HepRandomEngine& engine)
74  {
75  double tau1;
76  double tau2;
77 
78  if (is_fast) {
79  tau1 = FRTime;
80  tau2 = FDTime;
81  }
82  else {
83  tau1 = SRTime;
84  tau2 = SDTime;
85  }
86 
87  CLHEP::RandFlat randflatscinttime{engine};
88 
89  if ((tau1 < 1e-8) || (tau1 == -1.0)) {
90  timing = -tau2 * std::log(randflatscinttime());
91  return;
92  }
93 
94  //ran1, ran2 = random numbers for the algorithm
95  while (1) {
96  auto ran1 = randflatscinttime();
97  auto ran2 = randflatscinttime();
98  auto d = (tau1 + tau2) / tau2;
99  auto t = -tau2 * std::log(1 - ran1);
100  auto g = d * single_exp(t, tau2);
101  if (ran2 <= bi_exp(t, tau1, tau2) / g) {
102  timing = t;
103  return;
104  }
105  }
106  }
107 
109  {
110  if (fNoFastRisingTime) { return -FDTime * std::log(fUniformGen->fire()); }
111  return with_rising_time(FRTime, FDTime);
112  }
113 
115  {
116  if (fNoSlowRisingTime) { return -SDTime * std::log(fUniformGen->fire()); }
117  return with_rising_time(SRTime, SDTime);
118  }
119 
120 }
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:73
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