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4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/ChargeExchangeMC/src/CexmcReimplementedGenbod.cc (Version 11.3.0) and /examples/advanced/ChargeExchangeMC/src/CexmcReimplementedGenbod.cc (Version 5.1.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 /*                                                
 27  * ===========================================    
 28  *                                                
 29  *       Filename:  CexmcReimplementedGenbod.c    
 30  *                                                
 31  *    Description:  reimplemented GENBOD          
 32  *                  (mostly adopted from ROOT     
 33  *                                                
 34  *        Version:  1.0                           
 35  *        Created:  08.09.2010 18:52:39           
 36  *       Revision:  none                          
 37  *       Compiler:  gcc                           
 38  *                                                
 39  *         Author:  Alexey Radkov (),             
 40  *        Company:  PNPI                          
 41  *                                                
 42  * ===========================================    
 43  */                                               
 44                                                   
 45 #include <cmath>                                  
 46 #include <Randomize.hh>                           
 47 #include <G4PhysicalConstants.hh>                 
 48 #include <G4SystemOfUnits.hh>                     
 49 #include "CexmcReimplementedGenbod.hh"            
 50 #include "CexmcException.hh"                      
 51                                                   
 52                                                   
 53 namespace                                         
 54 {                                                 
 55     G4int  DoubleMax( const void *  a, const v    
 56     {                                             
 57        G4double  aa( *( ( G4double * )a ) );      
 58        G4double  bb( *( ( G4double * )b ) );      
 59                                                   
 60        if ( aa > bb )                             
 61            return  1;                             
 62                                                   
 63        if ( aa < bb )                             
 64            return -1;                             
 65                                                   
 66        return 0;                                  
 67     }                                             
 68                                                   
 69                                                   
 70     G4double  PDK( G4double  a, G4double  b, G    
 71     {                                             
 72         G4double  x( ( a - b - c ) * ( a + b +    
 73                      ( a + b - c ) );             
 74         x = std::sqrt( x ) / ( 2 * a );           
 75                                                   
 76         return x;                                 
 77     }                                             
 78 }                                                 
 79                                                   
 80                                                   
 81 CexmcReimplementedGenbod::CexmcReimplementedGe    
 82     nmbOfOutputParticles( 0 )                     
 83 {                                                 
 84 }                                                 
 85                                                   
 86                                                   
 87 G4double  CexmcReimplementedGenbod::Generate(     
 88 {                                                 
 89     // Generate a random final state.             
 90     // The function returns the weigth of the     
 91     // Note that Momentum, Energy units are Ge    
 92                                                   
 93     G4double  te_minus_tm( totalEnergy - total    
 94     G4double  rno[ maxParticles ];                
 95     rno[ 0 ] = 0;                                 
 96                                                   
 97     if ( nmbOfOutputParticles > 2 )               
 98     {                                             
 99         for ( G4int  i( 1 ); i < nmbOfOutputPa    
100         {                                         
101             rno[ i ] = G4UniformRand();           
102         }                                         
103         qsort( rno + 1, nmbOfOutputParticles -    
104                DoubleMax );                       
105     }                                             
106     rno[ nmbOfOutputParticles - 1 ] = 1;          
107                                                   
108     G4double  invMas[ maxParticles ];             
109     G4double  sum( 0 );                           
110                                                   
111     for ( int  i( 0 ); i < nmbOfOutputParticle    
112     {                                             
113         sum += outVec[ i ].mass / GeV;            
114         invMas[ i ] = rno[ i ] * te_minus_tm /    
115     }                                             
116                                                   
117     //                                            
118     //-----> compute the weight of the current    
119     //                                            
120     G4double  wt( maxWeight );                    
121     G4double  pd[ maxParticles ];                 
122                                                   
123     for ( int  i( 0 ); i < nmbOfOutputParticle    
124     {                                             
125         pd[ i ] = PDK( invMas[ i + 1 ], invMas    
126                        outVec[ i + 1 ].mass /     
127         wt *= pd[ i ];                            
128     }                                             
129                                                   
130     //                                            
131     //-----> complete specification of event (    
132     //                                            
133     outVec[ 0 ].lVec->setPx( 0. );                
134     outVec[ 0 ].lVec->setPy( pd[ 0 ] );           
135     outVec[ 0 ].lVec->setPz( 0. );                
136     outVec[ 0 ].lVec->setE( std::sqrt( pd[ 0 ]    
137                                        outVec[    
138                                        outVec[    
139                                                   
140     G4int  i( 1 );                                
141                                                   
142     while ( true )                                
143     {                                             
144         outVec[ i ].lVec->setPx( 0. );            
145         outVec[ i ].lVec->setPy( -pd[ i - 1 ]     
146         outVec[ i ].lVec->setPz( 0. );            
147         outVec[ i ].lVec->setE( std::sqrt( pd[    
148                                            out    
149                                            out    
150                                                   
151         G4double  cZ( 2 * G4UniformRand() - 1     
152         G4double  sZ( std::sqrt( 1 - cZ * cZ )    
153         G4double  angY( 2 * pi * G4UniformRand    
154         G4double  cY( std::cos( angY ) );         
155         G4double  sY( std::sin( angY ) );         
156                                                   
157         for ( int  j( 0 ); j <= i; ++j )          
158         {                                         
159             G4LorentzVector *  v( outVec[ j ].    
160             G4double           x( v->px() );      
161             G4double           y( v->py() );      
162             v->setPx( cZ * x - sZ * y );          
163             v->setPy( sZ * x + cZ * y );   //     
164             x = v->px();                          
165             G4double           z( v->pz() );      
166             v->setPx( cY * x - sY * z );          
167             v->setPz( sY * x + cY * z );   //     
168         }                                         
169                                                   
170         if ( i == nmbOfOutputParticles - 1 )      
171             break;                                
172                                                   
173         G4double  beta( pd[ i ] / std::sqrt( p    
174                                              i    
175         for ( int  j( 0 ); j <= i; ++j )          
176             outVec[ j ].lVec->boost( 0, beta,     
177                                                   
178         ++i;                                      
179     }                                             
180                                                   
181     for ( int  j( 0 ); j < nmbOfOutputParticle    
182         *outVec[ j ].lVec *= GeV;                 
183                                                   
184     //                                            
185     //---> return the weigth of event             
186     //                                            
187     return wt;                                    
188 }                                                 
189                                                   
190                                                   
191 void  CexmcReimplementedGenbod::ParticleChange    
192 {                                                 
193     nmbOfOutputParticles = outVec.size();         
194                                                   
195     if ( nmbOfOutputParticles < 2 || nmbOfOutp    
196         throw CexmcException( CexmcKinematicsE    
197                                                   
198     SetMaxWeight();                               
199 }                                                 
200                                                   
201                                                   
202 void  CexmcReimplementedGenbod::FermiEnergyDep    
203 {                                                 
204     SetMaxWeight();                               
205 }                                                 
206                                                   
207                                                   
208 void  CexmcReimplementedGenbod::SetMaxWeight(     
209 {                                                 
210     G4double  te_minus_tm( totalEnergy - total    
211                                                   
212     if ( fermiEnergyDepIsOn )                     
213     {                                             
214         // ffq[] = pi * (2*pi)**(N-2) / (N-2)!    
215         G4double  ffq[] = { 0                     
216                      ,3.141592, 19.73921, 62.0    
217                      ,256.3704, 268.4705, 240.    
218                      ,132.1308,  83.0202,  47.    
219                      ,12.0006,   5.3858,   2.2    
220         maxWeight =                               
221                 std::pow( te_minus_tm / GeV, n    
222                 ffq[ nmbOfOutputParticles - 1     
223     }                                             
224     else                                          
225     {                                             
226         G4double  emmax( ( te_minus_tm + outVe    
227         G4double  emmin( 0. );                    
228         G4double  wtmax( 1. );                    
229                                                   
230         for ( G4int  i( 1 ); i < nmbOfOutputPa    
231         {                                         
232             emmin += outVec[ i - 1 ].mass / Ge    
233             emmax += outVec[ i ].mass / GeV;      
234             wtmax *= PDK( emmax, emmin, outVec    
235         }                                         
236         maxWeight = 1 / wtmax;                    
237     }                                             
238 }                                                 
239                                                   
240