Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | Friends | List of all members
JDETECTOR::JK40DefaultSimulator Class Reference

Default implementation of the simulation of K40 background. More...

#include <JK40DefaultSimulator.hh>

Inheritance diagram for JDETECTOR::JK40DefaultSimulator:
JDETECTOR::JK40DefaultSimulatorInterface JPHYSICS::JK40Rates JDETECTOR::JK40Simulator JTRIGGER::JK40RunByRunSimulator

Public Member Functions

 JK40DefaultSimulator ()
 Default constructor. More...
 
 JK40DefaultSimulator (const JK40Rates &rates)
 Constructor. More...
 
virtual double getSinglesRate (const JPMTIdentifier &pmt) const override
 Get singles rate as a function of PMT. More...
 
virtual double getMultiplesRate (const JModuleIdentifier &module, const int M) const override
 Get multiples rate as a function of optical module. More...
 
virtual double getProbability (const double ct) const override
 Get probability of coincidence. More...
 
virtual void generateHits (const JModule &module, const JTimeRange &period, JModuleData &output) const
 Generate hits. More...
 
double getSinglesRate () const
 Get singles rate. More...
 
const JRateL1_tgetMultiplesRates () const
 Get multiples rate. More...
 
double getMultiplesRate (const multiplicity_type M) const
 Get multiples rate at given multiplicity. More...
 
multiplicity_type getLowerL1Multiplicity () const
 Get lower multiplicty. More...
 
multiplicity_type getUpperL1Multiplicity () const
 Get upper multiplicty. More...
 
void correct (const double QE)
 Correct rates for global efficiency,. More...
 

Static Public Member Functions

static JK40DefaultSimulatorgetInstance ()
 Get reference to unique instance of this class object. More...
 
static double getSigma ()
 Get intrinsic time smearing of K40 coincidences. More...
 
static void setSigma (const double sigma)
 Set intrinsic time smearing of K40 coincidences. More...
 

Static Public Attributes

static const multiplicity_type LOWER_L1_MULTIPLICITY = 2
 Lower L1 multiplicity. More...
 

Static Protected Member Functions

static double p1 ()
 Parameters for probability of coincidence as a function of the cosine of space angle between PMT axes. More...
 
static double p2 ()
 
static double p3 ()
 
static double p4 ()
 

Protected Attributes

JRateL0_t rateL0
 singles rate [Hz] More...
 
JRateL1_t rateL1
 multiples rates [Hz] More...
 

Static Private Member Functions

static double & get_sigma ()
 Get intrinsic time smearing of K40 coincidences. More...
 

Private Attributes

 probabilityL1
 
std::vector< double > rateL1_Hz
 Multiples rate as a function of the multiplicity. More...
 

Friends

std::istream & operator>> (std::istream &in, JK40DefaultSimulator &object)
 Read K40 simulator from input. More...
 
std::ostream & operator<< (std::ostream &out, const JK40DefaultSimulator &object)
 Write K40 simulator to output. More...
 

Detailed Description

Default implementation of the simulation of K40 background.

This class implements the JK40Simulator interface.

Definition at line 30 of file JK40DefaultSimulator.hh.

Constructor & Destructor Documentation

◆ JK40DefaultSimulator() [1/2]

JDETECTOR::JK40DefaultSimulator::JK40DefaultSimulator ( )
inline

Default constructor.

Definition at line 38 of file JK40DefaultSimulator.hh.

38  :
39  JK40Rates()
40  {}
JK40Rates()
Default constructor.
Definition: JK40Rates.hh:45

◆ JK40DefaultSimulator() [2/2]

JDETECTOR::JK40DefaultSimulator::JK40DefaultSimulator ( const JK40Rates rates)
inline

Constructor.

Parameters
ratesK40 rates [Hz]

Definition at line 48 of file JK40DefaultSimulator.hh.

48  :
49  JK40Rates(rates)
50  {}

Member Function Documentation

◆ getInstance()

static JK40DefaultSimulator& JDETECTOR::JK40DefaultSimulator::getInstance ( )
inlinestatic

Get reference to unique instance of this class object.

This method returns an object with default values. The singles and multiples rates are taken from KM3NeT internal note "Detector simulations for KM3NeT".

Returns
reference to this class object

Definition at line 62 of file JK40DefaultSimulator.hh.

63  {
64  static JK40DefaultSimulator k40Simulator(KM3NET::getK40Rates());
65 
66  return k40Simulator;
67  }
Default implementation of the simulation of K40 background.
const JK40Rates & getK40Rates()
Get K40 rates.
Definition: KM3NeT.hh:36

◆ getSinglesRate() [1/2]

virtual double JDETECTOR::JK40DefaultSimulator::getSinglesRate ( const JPMTIdentifier pmt) const
inlineoverridevirtual

Get singles rate as a function of PMT.

Parameters
pmtPMT identifier
Returns
rate [Hz]

Implements JDETECTOR::JK40DefaultSimulatorInterface.

Reimplemented in JTRIGGER::JK40RunByRunSimulator.

Definition at line 76 of file JK40DefaultSimulator.hh.

77  {
79  }
double getSinglesRate() const
Get singles rate.
Definition: JK40Rates.hh:71

◆ getMultiplesRate() [1/2]

virtual double JDETECTOR::JK40DefaultSimulator::getMultiplesRate ( const JModuleIdentifier module,
const int  M 
) const
inlineoverridevirtual

Get multiples rate as a function of optical module.

Parameters
moduleoptical module identifier
Mmultiplicity (M >= 2)
Returns
rate [Hz]

Implements JDETECTOR::JK40DefaultSimulatorInterface.

Definition at line 89 of file JK40DefaultSimulator.hh.

90  {
92  }
double getMultiplesRate(const multiplicity_type M) const
Get multiples rate at given multiplicity.
Definition: JK40Rates.hh:94

◆ getProbability()

virtual double JDETECTOR::JK40DefaultSimulator::getProbability ( const double  ct) const
inlineoverridevirtual

Get probability of coincidence.

Parameters
ctcosine space angle between PMT axes
Returns
probability

Implements JDETECTOR::JK40DefaultSimulatorInterface.

Definition at line 101 of file JK40DefaultSimulator.hh.

102  {
103  return exp(ct * (p1() + ct * (p2() + ct * (p3() + ct*p4()))));
104  }
static double p1()
Parameters for probability of coincidence as a function of the cosine of space angle between PMT axes...

◆ p1()

static double JDETECTOR::JK40DefaultSimulator::p1 ( )
inlinestaticprotected

Parameters for probability of coincidence as a function of the cosine of space angle between PMT axes.

Values are provided by V.Kulikovski.

Definition at line 160 of file JK40DefaultSimulator.hh.

160 { return 3.0767; }

◆ p2()

static double JDETECTOR::JK40DefaultSimulator::p2 ( )
inlinestaticprotected

Definition at line 161 of file JK40DefaultSimulator.hh.

161 { return -1.2078; }

◆ p3()

static double JDETECTOR::JK40DefaultSimulator::p3 ( )
inlinestaticprotected

Definition at line 162 of file JK40DefaultSimulator.hh.

162 { return 0.9905; }

◆ p4()

static double JDETECTOR::JK40DefaultSimulator::p4 ( )
inlinestaticprotected

Definition at line 163 of file JK40DefaultSimulator.hh.

163 { return 0.9379; }

◆ generateHits()

virtual void JDETECTOR::JK40DefaultSimulatorInterface::generateHits ( const JModule module,
const JTimeRange period,
JModuleData output 
) const
inlinevirtualinherited

Generate hits.

Parameters
modulemodule
periodtime window [ns]
outputbackground data

Implements JDETECTOR::JK40Simulator.

Definition at line 134 of file JK40DefaultSimulatorInterface.hh.

137  {
138  using namespace std;
139  using namespace JPP;
140 
141 
142  // resize internal buffers
143 
144  const size_t N = module.size();
145  const size_t M = (N * (N - 1)) / 2;
146 
147  rateL1_Hz .resize(N);
148  probabilityL1.resize(M + 1);
149 
150 
151  // generate singles
152 
153  for (size_t pmt = 0; pmt != N; ++pmt) {
154 
155  const double rateL0_Hz = getSinglesRate(JPMTIdentifier(module.getID(), pmt));
156 
157  if (rateL0_Hz > 0.0) {
158 
159  const double t_ns = 1.0e9 / rateL0_Hz; // [ns]
160 
161  for (double t1 = period.getLowerLimit() + gRandom->Exp(t_ns); t1 < period.getUpperLimit(); t1 += gRandom->Exp(t_ns)) {
162  output[pmt].push_back(JPMTSignal(t1, 1));
163  }
164  }
165  }
166 
167 
168  // generate coincidences
169 
170  double totalRateL1_Hz = 0.0;
171 
172  for (size_t i = 0; i != N; ++i) {
173  totalRateL1_Hz += rateL1_Hz[i] = getMultiplesRate(module.getID(), i + 2);
174  }
175 
176  if (totalRateL1_Hz > 0.0) {
177 
178  const double t_ns = 1.0e9 / totalRateL1_Hz; // [ns]
179 
180  double t1 = period.getLowerLimit() + gRandom->Exp(t_ns);
181 
182  if (t1 < period.getUpperLimit()) {
183 
184  // configure pair-wise propabilities
185 
186  probabilityL1[0] = { N, N, 0.0};
187 
188  size_t i = 0;
189  double P = 0.0;
190 
191  for (size_t pmt1 = 0; pmt1 != N; ++pmt1) {
192  for (size_t pmt2 = 0; pmt2 != pmt1; ++pmt2) {
193 
194  const double ct = getDot(module[pmt1].getDirection(), module[pmt2].getDirection());
195  const double p = getProbability(ct);
196 
197  i += 1;
198  P += p;
199 
200  probabilityL1[i] = { pmt1, pmt2, P};
201  }
202  }
203 
204  for ( ; t1 < period.getUpperLimit(); t1 += gRandom->Exp(t_ns)) {
205 
206  try {
207 
208  // generate two-fold coincidence
209 
210  const pair_type& pair = probabilityL1(gRandom->Rndm());
211 
212  output[pair.pmt1].insert(JPMTSignal(gRandom->Gaus(t1, getSigma()), 1));
213  output[pair.pmt2].insert(JPMTSignal(gRandom->Gaus(t1, getSigma()), 1));
214 
215  // generate larger than two-fold coincidences, if any
216 
217  size_t M = 0;
218 
219  for (double R = totalRateL1_Hz * gRandom->Rndm(); M != N && (R -= rateL1_Hz[M]) > 0.0; ++M) {}
220 
221  if (M != 0) {
222 
223  set<size_t> buffer = { pair.pmt1, pair.pmt2 }; // hit PMTs
224 
225  for ( ; M != 0; --M) {
226 
227  vector<double> probability1D(N, 1.0);
228 
229  double P = 0.0;
230 
231  for (size_t i = 0; i != N; ++i) {
232 
233  if (buffer.count(i) == 0) {
234 
235  for (set<size_t>::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
236 
237  const double ct = getDot(module[i].getDirection(), module[*pmt].getDirection());
238 
239  probability1D[i] *= getProbability(ct);
240  }
241 
242  P += probability1D[i];
243 
244  } else {
245 
246  probability1D[i] = 0.0;
247  }
248  }
249 
250  if (P > 0.0) {
251 
252  size_t pmt = 0;
253 
254  for (P *= gRandom->Rndm(); pmt != N && (P -= probability1D[pmt]) > 0.0; ++pmt) {}
255 
256  if (pmt != N) {
257 
258  output[pmt].insert(JPMTSignal(gRandom->Gaus(t1, getSigma()), 1));
259 
260  buffer.insert(pmt);
261  }
262 
263  } else {
264 
265  break;
266  }
267  }
268  }
269  }
270  catch (const JNumericalPrecision&) {}
271  }
272  }
273  }
274  }
static double getSigma()
Get intrinsic time smearing of K40 coincidences.
std::vector< double > rateL1_Hz
Multiples rate as a function of the multiplicity.
virtual double getSinglesRate(const JPMTIdentifier &pmt) const =0
Get singles rate as a function of PMT.
virtual double getMultiplesRate(const JModuleIdentifier &module, const int M) const =0
Get multiples rate as a function of optical module.
virtual double getProbability(const double ct) const =0
Get probability of coincidence.
Exception for numerical precision error.
Definition: JException.hh:270
int getID() const
Get identifier.
Definition: JObjectID.hh:50
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
JDirection3D getDirection(const Vec &dir)
Get direction.
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:676
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Data structure for PMT analogue signal.
Data structure for a pair of indices.

◆ getSigma()

static double JDETECTOR::JK40DefaultSimulatorInterface::getSigma ( )
inlinestaticinherited

Get intrinsic time smearing of K40 coincidences.

Returns
sigma [ns]

Definition at line 282 of file JK40DefaultSimulatorInterface.hh.

283  {
284  return get_sigma();
285  }
static double & get_sigma()
Get intrinsic time smearing of K40 coincidences.

◆ setSigma()

static void JDETECTOR::JK40DefaultSimulatorInterface::setSigma ( const double  sigma)
inlinestaticinherited

Set intrinsic time smearing of K40 coincidences.

Parameters
sigmasigma [ns]

Definition at line 293 of file JK40DefaultSimulatorInterface.hh.

294  {
295  get_sigma() = sigma;
296  }
const double sigma[]
Definition: JQuadrature.cc:74

◆ get_sigma()

static double& JDETECTOR::JK40DefaultSimulatorInterface::get_sigma ( )
inlinestaticprivateinherited

Get intrinsic time smearing of K40 coincidences.

Returns
sigma [ns]

Definition at line 304 of file JK40DefaultSimulatorInterface.hh.

305  {
306  static double sigma = 0.5;
307 
308  return sigma;
309  }

◆ getSinglesRate() [2/2]

double JPHYSICS::JK40Rates::getSinglesRate ( ) const
inlineinherited

Get singles rate.

Returns
rate [Hz]

Definition at line 71 of file JK40Rates.hh.

72  {
73  return rateL0;
74  }
JRateL0_t rateL0
singles rate [Hz]
Definition: JK40Rates.hh:221

◆ getMultiplesRates()

const JRateL1_t& JPHYSICS::JK40Rates::getMultiplesRates ( ) const
inlineinherited

Get multiples rate.

Returns
rate [Hz]

Definition at line 82 of file JK40Rates.hh.

83  {
84  return rateL1;
85  }
JRateL1_t rateL1
multiples rates [Hz]
Definition: JK40Rates.hh:222

◆ getMultiplesRate() [2/2]

double JPHYSICS::JK40Rates::getMultiplesRate ( const multiplicity_type  M) const
inlineinherited

Get multiples rate at given multiplicity.

Parameters
Mmultiplicity (M >= JK40Rates::LOWER_L1_MULTIPLICITY)
Returns
rate [Hz]

Definition at line 94 of file JK40Rates.hh.

95  {
97  return rateL1[M - LOWER_L1_MULTIPLICITY];
98  else
99  return 0.0;
100  }
size_t multiplicity_type
Type definition of multiplicity.
Definition: JK40Rates.hh:33
static const multiplicity_type LOWER_L1_MULTIPLICITY
Lower L1 multiplicity.
Definition: JK40Rates.hh:217

◆ getLowerL1Multiplicity()

multiplicity_type JPHYSICS::JK40Rates::getLowerL1Multiplicity ( ) const
inlineinherited

Get lower multiplicty.

Returns
lower multiplicity

Definition at line 108 of file JK40Rates.hh.

109  {
110  return LOWER_L1_MULTIPLICITY;
111  }

◆ getUpperL1Multiplicity()

multiplicity_type JPHYSICS::JK40Rates::getUpperL1Multiplicity ( ) const
inlineinherited

Get upper multiplicty.

Returns
upper multiplicity

Definition at line 119 of file JK40Rates.hh.

120  {
121  return rateL1.size() + 1;
122  }

◆ correct()

void JPHYSICS::JK40Rates::correct ( const double  QE)
inlineinherited

Correct rates for global efficiency,.

Parameters
QEglobal efficiency

Definition at line 130 of file JK40Rates.hh.

131  {
132  if (QE > 0.0) {
133 
134  rateL0 /= QE;
135 
136  JRateL1_t buffer = rateL1;
137 
139 
140  // determine contribution from higher multiplicities
141 
142  double R = 0.0;
143 
144  for (multiplicity_type i = M + 1; i <= getUpperL1Multiplicity(); ++i) {
145  R += buffer[i - LOWER_L1_MULTIPLICITY] * JMATH::binomial(i, M) * pow(QE, M) * pow(1.0 - QE, i - M);
146  }
147 
148  if (getMultiplesRate(M) > R)
149  buffer[M - LOWER_L1_MULTIPLICITY] = (getMultiplesRate(M) - R) / pow(QE, M);
150  else
151  buffer[M - LOWER_L1_MULTIPLICITY] = 0.0;
152  }
153 
154  rateL1 = buffer;
155 
156  } else {
157 
158  rateL0 = 0.0;
159 
160  for (JRateL1_t::iterator i = rateL1.begin(); i != rateL1.end(); ++i) {
161  *i = 0.0;
162  }
163  }
164  }
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
double binomial(const size_t n, const size_t k)
Binomial function.
multiplicity_type getLowerL1Multiplicity() const
Get lower multiplicty.
Definition: JK40Rates.hh:108
multiplicity_type getUpperL1Multiplicity() const
Get upper multiplicty.
Definition: JK40Rates.hh:119

Friends And Related Function Documentation

◆ operator>>

std::istream& operator>> ( std::istream &  in,
JK40DefaultSimulator object 
)
friend

Read K40 simulator from input.

Parameters
ininput stream
objectK40 simulator
Returns
input stream

Definition at line 114 of file JK40DefaultSimulator.hh.

115  {
116  const double rateL0 = object.rateL0;
117 
118  if (in >> object.rateL0) {
119 
120  object.rateL1.clear();
121 
122  for (double x; in >> x; ) {
123  object.rateL1.push_back(x);
124  }
125 
126  } else {
127 
128  object.rateL0 = rateL0;
129  }
130 
131  return in;
132  }

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JK40DefaultSimulator object 
)
friend

Write K40 simulator to output.

Parameters
outoutput stream
objectK40 simulator
Returns
output stream

Definition at line 142 of file JK40DefaultSimulator.hh.

143  {
144  out << object.rateL0;
145 
146  for (JRateL1_t::const_iterator i = object.rateL1.begin(); i != object.rateL1.end(); ++i) {
147  out << ' ' << *i;
148  }
149 
150  return out;
151  }

Member Data Documentation

◆ probabilityL1

JDETECTOR::JK40DefaultSimulatorInterface::probabilityL1
privateinherited

◆ rateL1_Hz

std::vector<double> JDETECTOR::JK40DefaultSimulatorInterface::rateL1_Hz
mutableprivateinherited

Multiples rate as a function of the multiplicity.

The index i corresponds to multiplicity M = i + 2.

Definition at line 316 of file JK40DefaultSimulatorInterface.hh.

◆ LOWER_L1_MULTIPLICITY

const multiplicity_type JPHYSICS::JK40Rates::LOWER_L1_MULTIPLICITY = 2
staticinherited

Lower L1 multiplicity.

Definition at line 217 of file JK40Rates.hh.

◆ rateL0

JRateL0_t JPHYSICS::JK40Rates::rateL0
protectedinherited

singles rate [Hz]

Definition at line 221 of file JK40Rates.hh.

◆ rateL1

JRateL1_t JPHYSICS::JK40Rates::rateL1
protectedinherited

multiples rates [Hz]

Definition at line 222 of file JK40Rates.hh.


The documentation for this class was generated from the following file: