ATLAS Offline Software
Loading...
Searching...
No Matches
CosmicGun.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include <iostream>
7#include <iomanip>
8#include <math.h>
10
11//--------------------------------------------------------
12//
13// These are the fortran subroutines
14//
15extern "C"{
16 void cosmic2_(void);
17 void cosipr_(void);
18 void cosgin_(void);
19 void cosgen_(float* emin, float* emax, int* iacc);
20}
21//--------------------------------------------------------
22//
23// and the common blocks
24//
25struct genpar {
27 int NBIN;
28 float PROBE[100];
29};
30alignas(32) genpar genpar_;
31
32struct coscut {
33 float ctcut;
34};
35extern coscut coscut_;
36
37struct cosevt{
38 float ENER, COSTH, PHI, CHRG;
39};
40extern cosevt cosevt_;
41
42struct flxout{
43 float FLUX, FLUX2;
44};
45extern flxout flxout_;
46
47//--------------------------------------------------------
48//
49// singleton pattern
50//
52
57
58
59//--------------------------------------------------------
60//
61// constructor with some default settings
62//
63// 9 August 2005, RMcP: remove initialization from constructor.
65 m_event = 0;
66 m_emin = 50;
67 m_emax = 500;
68 m_coscut = 0.35;
69 m_printevt = 20;
70 m_printmod = 50;
71
72 coscut_.ctcut = m_coscut;
73 genpar_.LEMIN = std::log10(m_emin);
74 genpar_.LEMAX = std::log10(m_emax);
75 genpar_.NBIN = 100;
76 genpar_.LBINWID = (genpar_.LEMAX-genpar_.LEMIN)/genpar_.NBIN;
77
78 // cosipr_();
79 // cosgin_();
80
81}
82
83// Add separate generator initialization routine
84// to avoid forced default initialization, RMcP 9 Aug 05.
86 std::cout << " CosmicGun::InitializeGenerator: E(min,max)=(" << m_emin << "," << m_emax
87 << ") GeV, and cos(ThetaCut)="<< m_coscut << std::endl;
88 cosipr_();
89 cosgin_();
90 cosmic2_();
91 return flxout_.FLUX2;
92}
93
94void CosmicGun::PrintLevel(int printevt,int printmod){
95 if (printevt >= 0)
96 {
97 m_printevt = printevt;
98 }
99 else
100 {
101 std::cerr << "CosmicGun::PrintLevel - warning ignored input printevt = " << printevt << std::endl;
102 }
103 if (printmod >= 1)
104 {
105 m_printmod = printmod;
106 }
107 else
108 {
109 std::cerr << "CosmicGun::PrintLevel - warning ignored input printmod = " << printmod << std::endl;
110 }
111}
112
113CLHEP::HepLorentzVector CosmicGun::GenerateEvent(void){
114 int iacc = 0;
115
116 while(iacc == 0){
117 cosgen_(&m_emin, &m_emax, &iacc);
118 }
119 m_event++;
120
121 float sinth = std::sqrt( 1-std::pow(cosevt_.COSTH,2) );
122 float e = cosevt_.ENER;
123 float px = cosevt_.ENER * sinth * std::sin( cosevt_.PHI);
124 float py = cosevt_.ENER * sinth * std::cos( cosevt_.PHI);
125 float pz = cosevt_.ENER * cosevt_.COSTH;
126 CLHEP::HepLorentzVector p(px,py,pz,e);
127
128// if(m_event < m_printevt || m_event%m_printmod == 0)
129// {
130// std::cout << "CosmicGun::GenerateEvent: " << std::setw(4) << m_event
131// << " muon charge " << std::setw(2) << cosevt_.CHRG << " with momentum : " << p << std::endl;
132// }
133
134 return p;
135}
136
138 return (int)cosevt_.CHRG;
139}
140
141void CosmicGun::SetEnergyRange(float emin, float emax){
142 if(emin >= emax || emin < 0 )
143 {
144 std::cout << "Error input energy range : (" << emin << " - " << emax << ") - ignored " << std::endl;
145 return;
146 }
147 m_emin = emin;
148 m_emax = emax;
149
150 genpar_.LEMIN = std::log10(m_emin);
151 genpar_.LEMAX = std::log10(m_emax);
152 genpar_.NBIN = 100;
153 genpar_.LBINWID = (genpar_.LEMAX-genpar_.LEMIN)/genpar_.NBIN;
154
155}
156
157void CosmicGun::SetCosCut(float ctcut){
158 m_coscut = ctcut;
159
160 coscut_.ctcut = m_coscut;
161}
162
void cosgin_(void)
genpar genpar_
Definition CosmicGun.cxx:30
void cosmic2_(void)
flxout flxout_
cosevt cosevt_
void cosgen_(float *emin, float *emax, int *iacc)
coscut coscut_
void cosipr_(void)
void PrintLevel(int printevt, int printmod)
Definition CosmicGun.cxx:94
static CosmicGun * s_mpointer
Definition CosmicGun.h:22
void SetEnergyRange(float emin, float emax)
int GetMuonCharge(void)
float m_emin
Definition CosmicGun.h:26
float InitializeGenerator()
Definition CosmicGun.cxx:85
CLHEP::HepLorentzVector GenerateEvent(void)
void SetCosCut(float ctcut)
float m_emax
Definition CosmicGun.h:26
static CosmicGun * GetCosmicGun(void)
Definition CosmicGun.cxx:53
int m_event
Definition CosmicGun.h:24
CosmicGun(void)
Definition CosmicGun.cxx:64
int m_printmod
Definition CosmicGun.h:25
float m_coscut
Definition CosmicGun.h:27
int m_printevt
Definition CosmicGun.h:25
float ctcut
Definition CosmicGun.cxx:33
float CHRG
Definition CosmicGun.cxx:38
float COSTH
Definition CosmicGun.cxx:38
float PHI
Definition CosmicGun.cxx:38
float ENER
Definition CosmicGun.cxx:38
float FLUX
Definition CosmicGun.cxx:43
float FLUX2
Definition CosmicGun.cxx:43
int NBIN
Definition CosmicGun.cxx:27
float LEMAX
Definition CosmicGun.cxx:26
float LEMIN
Definition CosmicGun.cxx:26
float PROBE[100]
Definition CosmicGun.cxx:28
float LBINWID
Definition CosmicGun.cxx:26