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

#include <CosmicsGenerator.h>

Inheritance diagram for CosmicsGenerator:
Collaboration diagram for CosmicsGenerator:

Public Member Functions

 CosmicsGenerator ()
 
 ~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
 
- Public Member Functions inherited from SHiP::Generator
 Generator ()
 
virtual ~Generator ()
 
virtual Bool_t Init (const char *, int)=0
 
virtual Bool_t Init (const char *)=0
 
virtual Bool_t Init (const std::vector< std::string > &inFiles, int startNumber)
 
virtual Bool_t Init (const std::vector< std::string > &inFiles)
 
virtual void UseExternalFile (std::string x, Int_t i)
 
virtual void UseExternalFile (std::vector< std::string > &inFiles, Int_t i)
 

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 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
 

Private Attributes

Co3RngfRandomEngine
 

Detailed Description

Definition at line 47 of file CosmicsGenerator.h.

Constructor & Destructor Documentation

◆ CosmicsGenerator()

CosmicsGenerator::CosmicsGenerator ( )
inline

constructor,destructor

Definition at line 50 of file CosmicsGenerator.h.

50{};

◆ ~CosmicsGenerator()

CosmicsGenerator::~CosmicsGenerator ( )
inlineoverride

Definition at line 51 of file CosmicsGenerator.h.

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

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}
TF1 * fTheta
double Uniform(Float_t min, Float_t max)

◆ Init() [1/3]

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 cout << "check the configuration for unphysical behavior." << endl
111 << "We stop the execution." << endl
112 << endl;
113 return kFALSE;
114 }
115
116 high = largeMom;
117 if (high)
118 cout << "Simulation for high momentum" << endl;
119 else
120 cout << "Simulation for low momentum" << endl;
121
122 // calculating weights for this run
123 // weight_flux: expected #muons per spill/ #simulated events per spill:
124 // FluxIntegral*xdist*zdist/EVENTS;
125 // the respective integrals are calculated from the fluxes
126 // weight_DetectorBox: only consider CM hitting the DetectorBox
127 // this is gained from a MC test of 10xEVENTS events
128 double weight_flux, weight_DetectorBox;
129 FluxIntegral = 0;
130 if (!high) { // momentum range 1 GeV - 100 GeV
131 if (minE > 100) {
132 cout << "choose minE < 100 !" << endl;
133 return kFALSE;
134 }
135 double dt = TMath::Pi() / 2 / 100;
136 for (double t = dt / 2; t < TMath::Pi() / 2; t += dt) {
138 }
139 FluxIntegral = 2 * TMath::Pi() / 3 * FluxIntegral * dt * 10000;
140 cout << "LowE CM flux with P < minE = " << minE << " : " << FluxIntegral
141 << "m-2s-1" << endl;
142 } else { // momentum range 100 GeV - 1000 GeV
144 2 * TMath::Pi() / 3 * fRandomEngine->fSpectrumH->Integral(100, 1000);
145 cout << "High E CM flux: " << FluxIntegral << "m-2s-1" << endl;
146 }
147 weight_flux = FluxIntegral * xdist * zdist / n_EVENTS / 10000;
148 nInside = 0;
149 nTest = 0;
150 weighttest = 0; // book keeping
151 y = 1900; // all muons start 19m over beam axis
152 for (; nInside < 10 * n_EVENTS;) {
154 }
155 weight_DetectorBox = 0.10 * nTest / n_EVENTS;
156 weight = weight_flux / weight_DetectorBox;
157 cout << "weight_DetectorBox: " << weight_DetectorBox << ", weight: " << weight
158 << endl;
159 cout << "--------------------------------------------------------------------"
160 "--"
161 << endl
162 << endl;
163 nInside = 0;
164 nTest = 0;
165 weighttest = 0; // book keeping
166
167 return kTRUE;
168}
double fSpectrumL(double theta, double minE, Bool_t generateP)
TF1 * fSpectrumH

◆ Init() [2/3]

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

Implements SHiP::Generator.

Definition at line 69 of file CosmicsGenerator.h.

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

◆ Init() [3/3]

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

Implements SHiP::Generator.

Definition at line 71 of file CosmicsGenerator.h.

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

◆ ReadEvent()

Bool_t CosmicsGenerator::ReadEvent ( FairPrimaryGenerator *  cpg)
override

Definition at line 170 of file CosmicsGenerator.cxx.

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

Member Data Documentation

◆ FluxIntegral

double CosmicsGenerator::FluxIntegral
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ fRandomEngine

Co3Rng* CosmicsGenerator::fRandomEngine
private

Definition at line 80 of file CosmicsGenerator.h.

◆ high

Bool_t CosmicsGenerator::high
protected

Definition at line 85 of file CosmicsGenerator.h.

◆ mass

double CosmicsGenerator::mass
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ minE

double CosmicsGenerator::minE

Definition at line 76 of file CosmicsGenerator.h.

◆ n_EVENTS

int CosmicsGenerator::n_EVENTS

Definition at line 77 of file CosmicsGenerator.h.

◆ nInside

int CosmicsGenerator::nInside
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ nTest

int CosmicsGenerator::nTest
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ P

double CosmicsGenerator::P
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ PID

int CosmicsGenerator::PID
protected

Definition at line 84 of file CosmicsGenerator.h.

◆ px

double CosmicsGenerator::px
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ py

double CosmicsGenerator::py
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ pz

double CosmicsGenerator::pz
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ theta

double CosmicsGenerator::theta
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ weight

double CosmicsGenerator::weight
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ weighttest

double CosmicsGenerator::weighttest
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ x

double CosmicsGenerator::x
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ xBox

double CosmicsGenerator::xBox

Definition at line 76 of file CosmicsGenerator.h.

◆ xdist

double CosmicsGenerator::xdist

Definition at line 76 of file CosmicsGenerator.h.

◆ y

double CosmicsGenerator::y
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ yBox

double CosmicsGenerator::yBox

Definition at line 76 of file CosmicsGenerator.h.

◆ z

double CosmicsGenerator::z
protected

Definition at line 83 of file CosmicsGenerator.h.

◆ z0

double CosmicsGenerator::z0

Definition at line 76 of file CosmicsGenerator.h.

◆ zBox

double CosmicsGenerator::zBox

Definition at line 76 of file CosmicsGenerator.h.

◆ zdist

double CosmicsGenerator::zdist

Definition at line 76 of file CosmicsGenerator.h.


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