FairShip
Loading...
Searching...
No Matches
CosmicsGenerator Class Reference

#include <CosmicsGenerator.h>

Inheritance diagram for CosmicsGenerator:
[legend]
Collaboration diagram for CosmicsGenerator:
[legend]

Public Member Functions

 CosmicsGenerator ()=default
 ~CosmicsGenerator () override
Bool_t ReadEvent (FairPrimaryGenerator *) override
virtual Bool_t Init (Bool_t largeMom)
Bool_t Init (const char *inFile) override
Bool_t Init (const char *inFile, int startEvent) override
virtual Bool_t Init (const std::vector< std::string > &inFiles, int startNumber)
virtual Bool_t Init (const std::vector< std::string > &inFiles)
Public Member Functions inherited from SHiP::Generator
 Generator ()=default
 ~Generator () override
virtual void UseExternalFile (std::string x, Int_t i)
virtual void UseExternalFile (std::vector< std::string > &inFiles, Int_t i)
void SetMaxTheta (Double_t thetaX, Double_t thetaY)
Int_t nrOfGeoRejections () const
Long64_t GetCounter (const std::string &name) const
void SetCounter (const std::string &name, Long64_t value)
void IncrementCounter (const std::string &name, Long64_t delta=1)

Public Attributes

double z0
double yBox
double xBox
double zBox
double xdist
double zdist
double minE
int n_EVENTS

Protected Member Functions

void GenerateDynamics ()
Bool_t DetectorBox ()
Protected Member Functions inherited from SHiP::Generator
bool IsInVesselAcceptance (Double_t px, Double_t py, Double_t pz) const

Protected Attributes

double P
double px
double py
double pz
double x
double y
double z
double weighttest
double weight
double mass
double FluxIntegral
double theta
int PID
int nInside
int nTest
Bool_t high
Protected Attributes inherited from SHiP::Generator
std::optional< std::string > fextFile
Int_t firstEvent = 0
Double_t fMaxThetaX = 0
Double_t fMaxThetaY = 0
bool fUseVesselAcceptance = false
Int_t fnGeoRejects = 0
std::unordered_map< std::string, int64_t > fCounters

Private Attributes

Co3Rng * fRandomEngine = nullptr

Detailed Description

Definition at line 48 of file CosmicsGenerator.h.

Constructor & Destructor Documentation

◆ CosmicsGenerator()

CosmicsGenerator::CosmicsGenerator ( )
default

constructor,destructor

◆ ~CosmicsGenerator()

CosmicsGenerator::~CosmicsGenerator ( )
inlineoverride

Definition at line 52 of file CosmicsGenerator.h.

52 {
53 delete fRandomEngine;
54 std::cout << nInside << " events have been generated." << std::endl;
55 std::cout << "There is a total of " << nInside << "/" << nTest
56 << " muons that passed close enough to the detector."
57 << std::endl;
58 std::cout << "Including the given weight this corresponds to ";
59 std::cout << weighttest / FluxIntegral / xdist / zdist * 10000
60 << " spills (1 spill = " << xdist * zdist * FluxIntegral / 10000;
61 std::cout << " real cosmic muons = " << n_EVENTS << " simulated events)."
62 << std::endl;
63 };

Member Function Documentation

◆ DetectorBox()

Bool_t CosmicsGenerator::DetectorBox ( )
protected

Definition at line 59 of file CosmicsGenerator.cxx.

59 {
60 // check, if a given staring setup x,y,z,px,py,pz will lead to a
61 // close enough to the detector
62
63 return (TMath::Abs(x - (y + yBox) * px / py) < xBox &&
64 TMath::Abs(z - z0 - (y + yBox) * pz / py) < zBox) ||
65 (TMath::Abs(x - (y - yBox) * px / py) < xBox &&
66 TMath::Abs(z - z0 - (y - yBox) * pz / py) < zBox) ||
67 (TMath::Abs(y - (x + xBox) * py / px) < yBox &&
68 TMath::Abs(z - z0 - (x + xBox) * pz / px) < zBox) ||
69 (TMath::Abs(y - (x - xBox) * py / px) < yBox &&
70 TMath::Abs(z - z0 - (x - xBox) * pz / px) < zBox);
71}

◆ GenerateDynamics()

void CosmicsGenerator::GenerateDynamics ( )
protected

Definition at line 73 of file CosmicsGenerator.cxx.

73 {
74 // generate starting conditions for CM until the DetectorBox is hit
75 do {
77 nTest++; // book keeping
78 // momentum components
79 double phi = fRandomEngine->Uniform(0, 2 * TMath::Pi());
80 theta = fRandomEngine->fTheta->GetRandom();
81 px = TMath::Sin(phi) * TMath::Sin(theta);
82 pz = TMath::Cos(phi) * TMath::Sin(theta);
83 py = -TMath::Cos(theta);
84 // staring location
85 x = fRandomEngine->Uniform(-xdist / 2, xdist / 2);
86 z = fRandomEngine->Uniform(z0 - zdist / 2, z0 + zdist / 2);
87 } while (!DetectorBox());
88 nInside++;
89}

◆ Init() [1/5]

Bool_t CosmicsGenerator::Init ( Bool_t largeMom)
virtual

Definition at line 91 of file CosmicsGenerator.cxx.

91 {
92 // general
93 fRandomEngine = new Co3Rng();
94 TDatabasePDG* pdgBase = TDatabasePDG::Instance();
95 mass = pdgBase->GetParticle(13)->Mass(); // muons!
96 cout << "--------------------------------------------------------------------"
97 "--"
98 << endl;
99 cout << "configuration for the CMBG as defined in "
100 "$FAIRSHIP/python/CMBG_conf.py: "
101 << endl;
102 cout << "x_dist: " << xdist << endl;
103 cout << "z_dist: " << zdist << endl;
104 cout << "x_box: " << xBox << endl;
105 cout << "y_box: " << yBox << endl;
106 cout << "z_box: " << zBox << endl;
107 cout << "n_EVENTS:" << n_EVENTS << endl;
108 cout << "minE: " << minE << endl << endl;
109 if (xdist * zdist * n_EVENTS == 0) {
110 LOG(error) << "CosmicsGenerator: invalid configuration "
111 << "(xdist * zdist * n_EVENTS == 0). Stopping execution.";
112 return kFALSE;
113 }
114
115 high = largeMom;
116 if (high)
117 cout << "Simulation for high momentum" << endl;
118 else
119 cout << "Simulation for low momentum" << endl;
120
121 // calculating weights for this run
122 // weight_flux: expected #muons per spill/ #simulated events per spill:
123 // FluxIntegral*xdist*zdist/EVENTS;
124 // the respective integrals are calculated from the fluxes
125 // weight_DetectorBox: only consider CM hitting the DetectorBox
126 // this is gained from a MC test of 10xEVENTS events
127 double weight_flux, weight_DetectorBox;
128 FluxIntegral = 0;
129 if (!high) { // momentum range 1 GeV - 100 GeV
130 if (minE > 100) {
131 LOG(error)
132 << "CosmicsGenerator: invalid configuration, choose minE < 100";
133 return kFALSE;
134 }
135 constexpr int kIntegrationSteps = 100;
136 const double dt = TMath::Pi() / 2 / kIntegrationSteps;
137 for (int i = 0; i < kIntegrationSteps; ++i) {
138 const double t = (i + 0.5) * dt; // midpoint rule
139 FluxIntegral += fRandomEngine->fSpectrumL(t, minE, 0);
140 }
141 FluxIntegral = 2 * TMath::Pi() / 3 * FluxIntegral * dt * 10000;
142 cout << "LowE CM flux with P < minE = " << minE << " : " << FluxIntegral
143 << "m-2s-1" << endl;
144 } else { // momentum range 100 GeV - 1000 GeV
146 2 * TMath::Pi() / 3 * fRandomEngine->fSpectrumH->Integral(100, 1000);
147 cout << "High E CM flux: " << FluxIntegral << "m-2s-1" << endl;
148 }
149 weight_flux = FluxIntegral * xdist * zdist / n_EVENTS / 10000;
150 nInside = 0;
151 nTest = 0;
152 weighttest = 0; // book keeping
153 y = 1900; // all muons start 19m over beam axis
154 for (; nInside < 10 * n_EVENTS;) {
156 }
157 weight_DetectorBox = 0.10 * nTest / n_EVENTS;
158 weight = weight_flux / weight_DetectorBox;
159 cout << "weight_DetectorBox: " << weight_DetectorBox << ", weight: " << weight
160 << endl;
161 cout << "--------------------------------------------------------------------"
162 "--"
163 << endl
164 << endl;
165 nInside = 0;
166 nTest = 0;
167 weighttest = 0; // book keeping
168
169 return kTRUE;
170}
int i
Definition ShipAna.py:108

◆ Init() [2/5]

Bool_t CosmicsGenerator::Init ( const char * inFile)
inlineoverridevirtual

Implements SHiP::Generator.

Definition at line 70 of file CosmicsGenerator.h.

70{ return Init(inFile, 0); };
virtual Bool_t Init(Bool_t largeMom)

◆ Init() [3/5]

Bool_t CosmicsGenerator::Init ( const char * inFile,
int startEvent )
inlineoverridevirtual

Implements SHiP::Generator.

Definition at line 72 of file CosmicsGenerator.h.

72 {
73 LOG(warning) << "Init with files not implemented for CosmicsGenerator.";
74 return false;
75 };

◆ Init() [4/5]

virtual Bool_t SHiP::Generator::Init ( const std::vector< std::string > & inFiles)
inlinevirtual

public method ReadEvent

Reimplemented from SHiP::Generator.

Definition at line 33 of file Generator.h.

33 {
34 LOG(warning) << "Multiple input files not implemented for this generator "
35 "- only taking the first!";
36 return Init(inFiles.at(0).c_str(), 0);
37 };

◆ Init() [5/5]

virtual Bool_t SHiP::Generator::Init ( const std::vector< std::string > & inFiles,
int startNumber )
inlinevirtual

public method ReadEvent

Reimplemented from SHiP::Generator.

Definition at line 27 of file Generator.h.

28 {
29 LOG(warning) << "Multiple input files not implemented for this generator "
30 "- only taking the first!";
31 return Init(inFiles.at(0).c_str(), startNumber);
32 };

◆ ReadEvent()

Bool_t CosmicsGenerator::ReadEvent ( FairPrimaryGenerator * cpg)
override

Definition at line 172 of file CosmicsGenerator.cxx.

172 {
173 // muon or anti-muon
174 PID = 26 * (fRandomEngine->Uniform(0, 1) < 1.0 / 2.278) - 13;
175 // starting conditions
177 // momentum in the two regions, < or > 100 GeV
178 if (!high)
179 P = fRandomEngine->fSpectrumL(theta, minE);
180 else
181 P = fRandomEngine->fSpectrumH->GetRandom();
182 px = px * P;
183 py = py * P;
184 pz = pz * P;
185 // transfer to Geant4
186 cpg->AddTrack(
187 PID, px, py, pz, x, y, z, -1, true, TMath::Sqrt(P * P + mass * mass), 0,
188 weight); // -1 = Mother ID, true = tracking, SQRT(x) = Energy, 0 = t
189 if (nInside % 10000 == 0) {
190 cout << nInside / 10000 << "10k events have been simulated" << endl;
191 }
192 return kTRUE;
193}

Member Data Documentation

◆ FluxIntegral

double CosmicsGenerator::FluxIntegral
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ fRandomEngine

Co3Rng* CosmicsGenerator::fRandomEngine = nullptr
private

Definition at line 81 of file CosmicsGenerator.h.

◆ high

Bool_t CosmicsGenerator::high
protected

Definition at line 86 of file CosmicsGenerator.h.

◆ mass

double CosmicsGenerator::mass
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ minE

double CosmicsGenerator::minE

Definition at line 77 of file CosmicsGenerator.h.

◆ n_EVENTS

int CosmicsGenerator::n_EVENTS

Definition at line 78 of file CosmicsGenerator.h.

◆ nInside

int CosmicsGenerator::nInside
protected

Definition at line 85 of file CosmicsGenerator.h.

◆ nTest

int CosmicsGenerator::nTest
protected

Definition at line 85 of file CosmicsGenerator.h.

◆ P

double CosmicsGenerator::P
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ PID

int CosmicsGenerator::PID
protected

Definition at line 85 of file CosmicsGenerator.h.

◆ px

double CosmicsGenerator::px
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ py

double CosmicsGenerator::py
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ pz

double CosmicsGenerator::pz
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ theta

double CosmicsGenerator::theta
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ weight

double CosmicsGenerator::weight
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ weighttest

double CosmicsGenerator::weighttest
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ x

double CosmicsGenerator::x
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ xBox

double CosmicsGenerator::xBox

Definition at line 77 of file CosmicsGenerator.h.

◆ xdist

double CosmicsGenerator::xdist

Definition at line 77 of file CosmicsGenerator.h.

◆ y

double CosmicsGenerator::y
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ yBox

double CosmicsGenerator::yBox

Definition at line 77 of file CosmicsGenerator.h.

◆ z

double CosmicsGenerator::z
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ z0

double CosmicsGenerator::z0

Definition at line 77 of file CosmicsGenerator.h.

◆ zBox

double CosmicsGenerator::zBox

Definition at line 77 of file CosmicsGenerator.h.

◆ zdist

double CosmicsGenerator::zdist

Definition at line 77 of file CosmicsGenerator.h.


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