Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CexmcGenbod.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 /*
27  * =============================================================================
28  *
29  * Filename: CexmcGenbod.cc
30  *
31  * Description: original fortran routine GENBOD wrapper
32  *
33  * Version: 1.0
34  * Created: 08.09.2010 14:36:23
35  * Revision: none
36  * Compiler: gcc
37  *
38  * Author: Alexey Radkov (),
39  * Company: PNPI
40  *
41  * =============================================================================
42  */
43 
44 #ifdef CEXMC_USE_GENBOD
45 
46 #include "CexmcGenbod.hh"
47 #include "CexmcException.hh"
48 
49 
50 extern "C"
51 {
52  extern int genbod_( void );
53 }
54 
55 
56 extern struct genbod_in_data
57 {
58  int np;
59  float tecm;
60  float amass[ 18 ];
61  int kgenev;
62 } genin_;
63 
64 
65 extern struct genbod_out_data
66 {
67  float pcm[ 18 ][ 5 ];
68  float wt;
69 } genout_;
70 
71 
72 CexmcGenbod::CexmcGenbod()
73 {
74  genin_.np = 0;
75  genin_.kgenev = 1;
76 }
77 
78 
79 G4bool CexmcGenbod::CheckKinematics( void )
80 {
81  totalEnergy = 0.;
82  for ( CexmcPhaseSpaceInVector::const_iterator k( inVec.begin() );
83  k != inVec.end(); ++k )
84  {
85  totalEnergy += ( *k )->e();
86  }
87 
88  /* epsilon is needed to compensate float to fortran real cast accuracy,
89  * the value 3E-6 was found experimentally, maybe has to be made bigger,
90  * but not smaller */
91  const float epsilon( 3E-6 );
92 
93  return totalEnergy - totalMass > 0.0f + epsilon;
94 }
95 
96 
97 G4double CexmcGenbod::Generate( void )
98 {
99  genin_.tecm = totalEnergy / GeV;
100 
101  genbod_();
102 
103  float ( *pcm )[ 5 ]( &genout_.pcm[ 0 ] );
104 
105  for ( CexmcPhaseSpaceOutVector::iterator k( outVec.begin() );
106  k != outVec.end(); ++k )
107  {
108  k->lVec->setPx( ( *pcm )[ 0 ] * GeV );
109  k->lVec->setPy( ( *pcm )[ 1 ] * GeV );
110  k->lVec->setPz( ( *pcm )[ 2 ] * GeV );
111  k->lVec->setE( ( *pcm++ )[ 3 ] * GeV );
112  }
113 
114  return genout_.wt;
115 }
116 
117 
118 void CexmcGenbod::ParticleChangeHook( void )
119 {
120  size_t nmbOfOutputParticles( outVec.size() );
121 
122  if ( nmbOfOutputParticles < 2 || nmbOfOutputParticles > 18 )
124 
125  genin_.np = nmbOfOutputParticles;
126 
127  float * amass( genin_.amass );
128 
129  for ( CexmcPhaseSpaceOutVector::const_iterator k( outVec.begin() );
130  k != outVec.end(); ++k )
131  {
132  *amass++ = k->mass / GeV;
133  }
134 }
135 
136 
137 void CexmcGenbod::FermiEnergyDepStatusChangeHook( void )
138 {
139  genin_.kgenev = fermiEnergyDepIsOn ? 2 : 1;
140 }
141 
142 #endif
143