R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
CosmicMuonDistributions.h
Go to the documentation of this file.
1#pragma once
2
3#include <Math/GenVector/Cartesian3D.h>
4#include <Math/Math.h>
5#include <TRandom.h>
6#include <cmath>
7#include <stdexcept>
8
9namespace R3B::Neuland
10{
12 {
13 public:
14 void set_mean_sigma(double mean, double sigma)
15 {
16 mean_ = mean;
17 sigma_ = sigma;
18 }
19
20 auto operator()(TRandom* rd_engine_) const -> double
21 {
22 auto energy = rd_engine_->Gaus(mean_, sigma_);
23 return energy;
24 };
25
26 private:
27 double mean_ = 0.;
28 double sigma_ = 0.;
29 };
30
32 {
33 public:
34 auto operator()(TRandom* rd_engine_) const -> double
35 {
36 const auto n_steps = 10000;
37 const auto step_size = 0.1;
38
39 auto target_distribution = [](double val) -> double { return std::pow(std::cos(val), 2.); };
40
41 auto current_angle = 0.;
42 auto new_angle = 0.;
43
44 for (int i = 0; i < n_steps; ++i)
45 {
46 new_angle = rd_engine_->Gaus(current_angle, step_size);
47
48 if (new_angle < -ROOT::Math::Pi() || new_angle > ROOT::Math::Pi())
49 {
50 continue;
51 }
52
53 const auto acceptance_ratio = target_distribution(new_angle) / target_distribution(current_angle);
54
55 if (rd_engine_->Uniform(0.0, 1.0) < acceptance_ratio)
56 {
57 current_angle = new_angle;
58 }
59 }
60
61 return current_angle;
62 }
63 };
64
66 {
67 double xmin{};
68 double xmax{};
69 double ymin{};
70 double ymax{};
71 double zmin{};
72 double zmax{};
73 };
74
76 {
77 public:
78 void set_box_size(DetectorBoxSize detector_box_size)
79 {
80 detector_box_size_.xmin = detector_box_size.xmin;
81 detector_box_size_.xmax = detector_box_size.xmax;
82 detector_box_size_.ymin = detector_box_size.ymin;
83 detector_box_size_.ymax = detector_box_size.ymax;
84 detector_box_size_.zmin = detector_box_size.zmin;
85 detector_box_size_.zmax = detector_box_size.zmax;
86 }
87
88 auto operator()(TRandom* rd_engine_) const -> ROOT::Math::Cartesian3D<double>
89 {
90 auto box_positions = ROOT::Math::Cartesian3D<double>{};
91 if (rd_engine_ != nullptr)
92 {
93 box_positions.SetX(rd_engine_->Uniform(detector_box_size_.xmin, detector_box_size_.xmax));
94 box_positions.SetY(rd_engine_->Uniform(detector_box_size_.ymin, detector_box_size_.ymax));
95 box_positions.SetZ(rd_engine_->Uniform(detector_box_size_.zmin, detector_box_size_.zmax));
96 return box_positions;
97 }
98 throw std::runtime_error("rnd engine is nullptr!");
99 }
100
101 private:
103 };
104} // namespace R3B::Neuland
auto operator()(TRandom *rd_engine_) const -> double
auto operator()(TRandom *rd_engine_) const -> double
void set_mean_sigma(double mean, double sigma)
void set_box_size(DetectorBoxSize detector_box_size)
auto operator()(TRandom *rd_engine_) const -> ROOT::Math::Cartesian3D< double >
Simulation of NeuLAND Bar/Paddle.