SND@LHC Software
Loading...
Searching...
No Matches
CosmicsGenerator Class Reference

#include <CosmicsGenerator.h>

Inheritance diagram for CosmicsGenerator:
Collaboration diagram for CosmicsGenerator:

Public Member Functions

 CosmicsGenerator ()
 
virtual ~CosmicsGenerator ()
 
Bool_t ReadEvent (FairPrimaryGenerator *)
 
virtual Bool_t Init (Bool_t largeMom)
 

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 ()
 
 ClassDef (CosmicsGenerator, 4)
 

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
 

Private Attributes

Co3RngfRandomEngine
 

Detailed Description

Definition at line 38 of file CosmicsGenerator.h.

Constructor & Destructor Documentation

◆ CosmicsGenerator()

CosmicsGenerator::CosmicsGenerator ( )
inline

constructor,destructor

Definition at line 41 of file CosmicsGenerator.h.

41{};

◆ ~CosmicsGenerator()

virtual CosmicsGenerator::~CosmicsGenerator ( )
inlinevirtual

Definition at line 42 of file CosmicsGenerator.h.

42 {
43 delete fRandomEngine;
44 cout<<nInside<<" events have been generated."<<endl;
45 cout<<"There is a total of "<<nInside<<"/"<<nTest<<" muons that passed close enough to the detector."<<endl;
46 cout<<"Including the given weight this corresponds to ";
47 cout<<weighttest/FluxIntegral/xdist/zdist*10000<<" spills (1 spill = "<<xdist*zdist*FluxIntegral/10000;
48 cout<<" real cosmic muons = "<<n_EVENTS<<" simulated events)."<<endl;
49 };

Member Function Documentation

◆ ClassDef()

CosmicsGenerator::ClassDef ( CosmicsGenerator  ,
 
)
protected

◆ DetectorBox()

Bool_t CosmicsGenerator::DetectorBox ( )
protected

Definition at line 45 of file CosmicsGenerator.cxx.

45 {
46 // check, if a given staring setup x,y,z,px,py,pz will lead to a
47 // close enough to the detector
48
49 if ((TMath::Abs(x-(y+yBox)*px/py) < xBox && TMath::Abs(z-z0-(y+yBox)*pz/py) < zBox) ||
50 (TMath::Abs(x-(y-yBox)*px/py) < xBox && TMath::Abs(z-z0-(y-yBox)*pz/py) < zBox) ||
51 (TMath::Abs(y-(x+xBox)*py/px) < yBox && TMath::Abs(z-z0-(x+xBox)*pz/px) < zBox) ||
52 (TMath::Abs(y-(x-xBox)*py/px) < yBox && TMath::Abs(z-z0-(x-xBox)*pz/px) < zBox)) {
53 return true;
54 }
55 return false;
56}

◆ GenerateDynamics()

void CosmicsGenerator::GenerateDynamics ( )
protected

Definition at line 58 of file CosmicsGenerator.cxx.

58 {
59 // generate starting conditions for CM until the DetectorBox is hit
60 do{
61 weighttest += weight; nTest++; //book keeping
62 //momentum components
63 double phi = fRandomEngine->Uniform(0,2*TMath::Pi());
64 theta = fRandomEngine->fTheta->GetRandom();
65 px = TMath::Sin(phi)*TMath::Sin(theta);
66 pz = TMath::Cos(phi)*TMath::Sin(theta);
67 py = -TMath::Cos(theta);
68 //staring location
70 z = fRandomEngine->Uniform(z0 - zdist/2, z0 + zdist/2);
71 }while(!DetectorBox());
72 nInside++;
73}
double Uniform(Float_t min, Float_t max)

◆ Init()

Bool_t CosmicsGenerator::Init ( Bool_t  largeMom)
virtual

Definition at line 75 of file CosmicsGenerator.cxx.

75 {
76 //general
77 fRandomEngine = new Co3Rng();
78 TDatabasePDG* pdgBase = TDatabasePDG::Instance();
79 mass = pdgBase->GetParticle(13)->Mass(); // muons!
80 cout<<"----------------------------------------------------------------------"<<endl;
81 cout<<"configuration for the CMBG as defined in $FAIRSHIP/python/CMBG_conf.py: "<<endl;
82 cout<<"x_dist: "<<xdist<<endl;
83 cout<<"z_dist: "<<zdist<<endl;
84 cout<<"x_box: "<<xBox<<endl;
85 cout<<"y_box: "<<yBox<<endl;
86 cout<<"z_box: "<<zBox<<endl;
87 cout<<"n_EVENTS:"<<n_EVENTS<<endl;
88 cout<<"minE: "<<minE<<endl<<endl;
89 if (xdist*zdist*n_EVENTS == 0){cout<<"check the configuration for unphysical behavior."<<endl<<"We stop the execution."<<endl<<endl; return kFALSE;}
90
91 high = largeMom;
92 if (high) cout<<"Simulation for high momentum"<<endl;
93 else cout<<"Simulation for low momentum"<<endl;
94
95 // calculating weights for this run
96 // weight_flux: expected #muons per spill/ #simulated events per spill: FluxIntegral*xdist*zdist/EVENTS;
97 // the respective integrals are calculated from the fluxes
98 // weight_DetectorBox: only consider CM hitting the DetectorBox
99 // this is gained from a MC test of 10xEVENTS events
100 double weight_flux, weight_DetectorBox;
101 FluxIntegral = 0;
102 if (!high) { // momentum range 1 GeV - 100 GeV
103 if (minE > 100) {cout<<"choose minE < 100 !"<<endl; return kFALSE;}
104 double dt = TMath::Pi()/2/100;
105 for (double t= dt/2; t< TMath::Pi()/2; t += dt){
107 }
108 FluxIntegral = 2*TMath::Pi()/3*FluxIntegral*dt*10000;
109 cout<< "LowE CM flux with P < minE = "<<minE<<" : "<<FluxIntegral<< "m-2s-1"<<endl;
110 }
111 else { // momentum range 100 GeV - 1000 GeV
112 FluxIntegral = 2*TMath::Pi()/3*fRandomEngine->fSpectrumH->Integral(100,1000);
113 cout<< "HighE CM flux: "<<FluxIntegral<< "m-2s-1"<<endl;
114 }
115 weight_flux = FluxIntegral*xdist*zdist/n_EVENTS/10000;
116 nInside = 0; nTest = 0; weighttest = 0; // book keeping
117 y = 1900; //all muons start 19m over beam axis
118 for (; nInside < 10*n_EVENTS;){
120 }
121 weight_DetectorBox = 0.10 * nTest/n_EVENTS;
122 weight = weight_flux / weight_DetectorBox;
123 cout<<"weight_DetectorBox: "<< weight_DetectorBox<<", weight: "<< weight<<endl;
124 cout<<"----------------------------------------------------------------------"<<endl<<endl;
125 nInside = 0; nTest = 0; weighttest = 0; // book keeping
126
127 return kTRUE;
128}
double fSpectrumL(double theta, double minE, Bool_t generateP)
TF1 * fSpectrumH

◆ ReadEvent()

Bool_t CosmicsGenerator::ReadEvent ( FairPrimaryGenerator *  cpg)

public method ReadEvent

Definition at line 130 of file CosmicsGenerator.cxx.

130 {
131 // muon or anti-muon
132 PID = 26*(fRandomEngine->Uniform(0,1) < 1.0/2.278) - 13;
133 // starting conditions
135 //momentum in the two regions, < or > 100 GeV
137 else P = fRandomEngine->fSpectrumH->GetRandom();
138 px = px*P;
139 py = py*P;
140 pz = pz*P;
141 // transfer to Geant4
142 cpg->AddTrack(PID,px,py,pz,x,y,z,-1,true,TMath::Sqrt(P*P+mass*mass),0,weight); // -1 = Mother ID, true = tracking, SQRT(x) = Energy, 0 = t
143 if (!nInside%10000){cout<<nInside/10000<<"10k events have been simulated"<<endl;}
144 return kTRUE;
145}

Member Data Documentation

◆ FluxIntegral

double CosmicsGenerator::FluxIntegral
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ fRandomEngine

Co3Rng* CosmicsGenerator::fRandomEngine
private

Definition at line 60 of file CosmicsGenerator.h.

◆ high

Bool_t CosmicsGenerator::high
protected

Definition at line 65 of file CosmicsGenerator.h.

◆ mass

double CosmicsGenerator::mass
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ minE

double CosmicsGenerator::minE

Definition at line 56 of file CosmicsGenerator.h.

◆ n_EVENTS

int CosmicsGenerator::n_EVENTS

Definition at line 57 of file CosmicsGenerator.h.

◆ nInside

int CosmicsGenerator::nInside
protected

Definition at line 64 of file CosmicsGenerator.h.

◆ nTest

int CosmicsGenerator::nTest
protected

Definition at line 64 of file CosmicsGenerator.h.

◆ P

double CosmicsGenerator::P
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ PID

int CosmicsGenerator::PID
protected

Definition at line 64 of file CosmicsGenerator.h.

◆ px

double CosmicsGenerator::px
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ py

double CosmicsGenerator::py
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ pz

double CosmicsGenerator::pz
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ theta

double CosmicsGenerator::theta
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ weight

double CosmicsGenerator::weight
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ weighttest

double CosmicsGenerator::weighttest
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ x

double CosmicsGenerator::x
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ xBox

double CosmicsGenerator::xBox

Definition at line 56 of file CosmicsGenerator.h.

◆ xdist

double CosmicsGenerator::xdist

Definition at line 56 of file CosmicsGenerator.h.

◆ y

double CosmicsGenerator::y
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ yBox

double CosmicsGenerator::yBox

Definition at line 56 of file CosmicsGenerator.h.

◆ z

double CosmicsGenerator::z
protected

Definition at line 63 of file CosmicsGenerator.h.

◆ z0

double CosmicsGenerator::z0

Definition at line 56 of file CosmicsGenerator.h.

◆ zBox

double CosmicsGenerator::zBox

Definition at line 56 of file CosmicsGenerator.h.

◆ zdist

double CosmicsGenerator::zdist

Definition at line 56 of file CosmicsGenerator.h.


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