ATLAS Offline Software
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 //
15 extern "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 //
25 struct genpar {
26  float LBINWID, LEMIN, LEMAX;
27  int NBIN;
28  float PROBE[100];
29 };
30 alignas(32) genpar genpar_;
31 
32 struct coscut {
33  float ctcut;
34 };
35 extern coscut coscut_;
36 
37 struct cosevt{
38  float ENER, COSTH, PHI, CHRG;
39 };
40 extern cosevt cosevt_;
41 
42 struct flxout{
43  float FLUX, FLUX2;
44 };
45 extern flxout flxout_;
46 
47 //--------------------------------------------------------
48 //
49 // singleton pattern
50 //
52 
54  if(!s_mpointer) s_mpointer = new CosmicGun();
55  return s_mpointer;
56 }
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 
73  genpar_.LEMIN = std::log10(m_emin);
74  genpar_.LEMAX = std::log10(m_emax);
75  genpar_.NBIN = 100;
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 
94 void 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 
113 CLHEP::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 
141 void 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;
154 
155 }
156 
157 void CosmicGun::SetCosCut(float ctcut){
158  m_coscut = ctcut;
159 
161 }
162 
flxout_
flxout flxout_
CosmicGun
Definition: CosmicGun.h:10
coscut
Definition: CosmicGun.cxx:32
test_pyathena.px
px
Definition: test_pyathena.py:18
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
genpar_
genpar genpar_
Definition: CosmicGun.cxx:30
CosmicGun::SetCosCut
void SetCosCut(float ctcut)
Definition: CosmicGun.cxx:157
CosmicGun::s_mpointer
static CosmicGun * s_mpointer
Definition: CosmicGun.h:22
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
cosevt::ENER
float ENER
Definition: CosmicGun.cxx:38
cosevt_
cosevt cosevt_
CosmicGun::m_emin
float m_emin
Definition: CosmicGun.h:26
cosevt::CHRG
float CHRG
Definition: CosmicGun.cxx:38
cosevt::PHI
float PHI
Definition: CosmicGun.cxx:38
genpar::LEMAX
float LEMAX
Definition: CosmicGun.cxx:26
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
CosmicGun::CosmicGun
CosmicGun(void)
Definition: CosmicGun.cxx:64
coscut_
coscut coscut_
cosmic2_
void cosmic2_(void)
genpar::PROBE
float PROBE[100]
Definition: CosmicGun.cxx:28
flxout::FLUX2
float FLUX2
Definition: CosmicGun.cxx:43
genpar::LBINWID
float LBINWID
Definition: CosmicGun.cxx:26
flxout::FLUX
float FLUX
Definition: CosmicGun.cxx:43
CosmicGun::GenerateEvent
CLHEP::HepLorentzVector GenerateEvent(void)
Definition: CosmicGun.cxx:113
CosmicGun::m_printmod
int m_printmod
Definition: CosmicGun.h:25
CosmicGun.h
cosevt::COSTH
float COSTH
Definition: CosmicGun.cxx:38
CosmicGun::m_event
int m_event
Definition: CosmicGun.h:24
flxout
Definition: CosmicGun.cxx:42
CosmicGun::GetCosmicGun
static CosmicGun * GetCosmicGun(void)
Definition: CosmicGun.cxx:53
CosmicGun::m_printevt
int m_printevt
Definition: CosmicGun.h:25
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
CosmicGun::GetMuonCharge
int GetMuonCharge(void)
Definition: CosmicGun.cxx:137
genpar::LEMIN
float LEMIN
Definition: CosmicGun.cxx:26
CosmicGun::InitializeGenerator
float InitializeGenerator()
Definition: CosmicGun.cxx:85
coscut::ctcut
float ctcut
Definition: CosmicGun.cxx:33
cosevt
Definition: CosmicGun.cxx:37
genpar::NBIN
int NBIN
Definition: CosmicGun.cxx:27
Amg::py
@ py
Definition: GeoPrimitives.h:39
cosgen_
void cosgen_(float *emin, float *emax, int *iacc)
CosmicGun::PrintLevel
void PrintLevel(int printevt, int printmod)
Definition: CosmicGun.cxx:94
CosmicGun::m_coscut
float m_coscut
Definition: CosmicGun.h:27
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CosmicGun::SetEnergyRange
void SetEnergyRange(float emin, float emax)
Definition: CosmicGun.cxx:141
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
cosgin_
void cosgin_(void)
genpar
Definition: CosmicGun.cxx:25
cosipr_
void cosipr_(void)
CosmicGun::m_emax
float m_emax
Definition: CosmicGun.h:26