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] [ 10.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/extended/hadronic/FlukaCern/ProcessLevel/FinalState/HadNucIneEvents.cc (Version 11.3.0) and /examples/extended/hadronic/FlukaCern/ProcessLevel/FinalState/HadNucIneEvents.cc (Version 9.2.p2)


  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 ///  \file HadNucIneEvents.cc                     
 28 ///  \brief Main program,                         
 29 ///         hadronic/FlukaCern/ProcessLevel/Fi    
 30 //                                                
 31 //  Author: A. Ribbon, 8 November 2020            
 32 //  Modified: G. Hugo, 8 December 2022            
 33 //                                                
 34 //--------------------------------------------    
 35 //                                                
 36 //     HadNucIneEvents                            
 37 //                                                
 38 /// This program is an adaptation of Hadr09 ex    
 39 /// It offers all Hadr09 features, and adds th    
 40 /// accessing hadron-nucleus inelastic interac    
 41 ///                                               
 42 /// With respect to the Hadr09 example,           
 43 /// the program also adds the possibility of p    
 44 /// all encountered secondaries spectra are au    
 45 /// as well as the residual nuclei distributio    
 46 /// All plots (created via the G4 analysis man    
 47 /// to any of the usually supported formats (e    
 48 /// but also in a Flair-compatible format.        
 49 ///                                               
 50 /// The final states (i.e. secondary particles    
 51 /// hadron-nuclear inelastic collisions are ha    
 52 ///                                               
 53 /// The use of the class Hadronic Generator is    
 54 /// the constructor needs to be invoked only o    
 55 /// of the "physics case" to consider ("CFLUKA    
 56 /// considered as default if the name is not s    
 57 /// method needs to be called at each collisio    
 58 /// collision (hadron, energy, direction, mate    
 59 /// The class HadronicGenerator is expected to    
 60 /// multi-threaded environment with "external"    
 61 /// that are not necessarily managed by Geant4    
 62 /// each thread should have its own instance o    
 63 ///                                               
 64 /// See the string "***LOOKHERE***" below for     
 65 /// of this example: the "physics case", the s    
 66 /// which to sample the projectile                
 67 /// a list of hadrons is possible from which t    
 68 /// the kinetic energy of the projectile (whic    
 69 /// an interval), whether the direction of the    
 70 /// sampled at each collision, the target mate    
 71 /// is possible, from which the target materia    
 72 /// collision, and then from this target mater    
 73 /// will be chosen randomly by Geant4 itself),    
 74 /// some information or not and how frequently    
 75 /// Once a well-defined type of hadron-nucleus    
 76 /// inelastic collision has been chosen, the m    
 77 ///   HadronicGenerator::GenerateInteraction      
 78 /// returns the secondaries produced by that i    
 79 /// of a G4VParticleChange object).               
 80 ///                                               
 81 /// Here by default, an already well-defined t    
 82 /// inelastic collision is selected               
 83 /// (specific hadron, at a given kinetic energ    
 84 /// on a specific material).                      
 85 /// The initial random seed is not set randoml    
 86 /// so that results are reproducible from one     
 87 ///                                               
 88 /// Use:  build/HadNucIneEvents                   
 89 //                                                
 90 //--------------------------------------------    
 91                                                   
 92 //....oooOO0OOooo........oooOO0OOooo........oo    
 93 //....oooOO0OOooo........oooOO0OOooo........oo    
 94                                                   
 95 #include "CLHEP/Random/Randomize.h"               
 96 #include "CLHEP/Random/Ranlux64Engine.h"          
 97 #include "FinalStateHistoManager.hh"              
 98 #include "HadronicGenerator.hh"                   
 99                                                   
100 #include "G4GenericIon.hh"                        
101 #include "G4IonTable.hh"                          
102 #include "G4Material.hh"                          
103 #include "G4NistManager.hh"                       
104 #include "G4ParticleTable.hh"                     
105 #include "G4PhysicalConstants.hh"                 
106 #include "G4ProcessManager.hh"                    
107 #include "G4SystemOfUnits.hh"                     
108 #include "G4UnitsTable.hh"                        
109 #include "G4VParticleChange.hh"                   
110 #include "G4ios.hh"                               
111 #include "globals.hh"                             
112                                                   
113 #include <chrono>                                 
114 #include <iomanip>                                
115                                                   
116 //....oooOO0OOooo........oooOO0OOooo........oo    
117                                                   
118 G4int main(G4int argc, char** argv)               
119 {                                                 
120   G4cout << "=== Test of the HadronicGenerator    
121                                                   
122   // See the HadronicGenerator class for the p    
123   // ( In short, it is the name of the Geant4     
124   //   the collision, with the possibility of     
125   //   a given energy interval, as in physics     
126                                                   
127   //***LOOKHERE***  PHYSICS CASE                  
128   G4String namePhysics = "CFLUKAHI";              
129   // const G4String namePhysics = "FTFP_BERT";    
130   // const G4String namePhysics = "FTFP_BERT_A    
131   // const G4String namePhysics = "QGSP_BERT";    
132   // const G4String namePhysics = "QGSP_BIC";     
133   // const G4String namePhysics = "FTFP_INCLXX    
134   // const G4String namePhysics = "FTFP";         
135   // const G4String namePhysics = "QGSP";         
136   // const G4String namePhysics = "BERT";         
137   // const G4String namePhysics = "BIC";          
138   // const G4String namePhysics = "IonBIC";       
139   // const G4String namePhysics = "INCL";         
140                                                   
141   // The kinetic energy of the projectile will    
142   // in the interval [minEnergy, maxEnergy].      
143   G4double minEnergy = 7. * CLHEP::TeV;  //***    
144   G4double maxEnergy = 7. * CLHEP::TeV;  //***    
145                                                   
146   G4int numCollisions = 100000;  //***LOOKHERE    
147   // const G4int numCollisions = 100;    // DE    
148                                                   
149   // IMPORTANT - TESTING ONLY:                    
150   // OVERWRITES DEFAULT PHYSICS CASE AND NUMBE    
151   std::vector<G4String> args(argv, argv + argc    
152   if (args.size() == 2 && args[1] == "--test")    
153     namePhysics = G4String("FTFP_BERT");          
154     numCollisions = 10;                           
155   }                                               
156                                                   
157   // Enable or disable the print out of this p    
158   // produced in each collisions is printed ou    
159   // collisions, the list of secondaries is pr    
160   const G4bool isPrintingEnabled = true;  //**    
161   const G4int printingGap = 100;  //***LOOKHER    
162                                                   
163   // Vector of Geant4 names of hadron projecti    
164   // (with uniform probability) for each colli    
165   // Note: comment out the corresponding line     
166   std::vector<G4String> vecProjectiles;  //***    
167   // vecProjectiles.push_back( "pi-" );           
168   // Note: vecProjectiles.push_back( "pi0" );     
169   // vecProjectiles.push_back( "pi+" );           
170   // vecProjectiles.push_back( "kaon-" );         
171   // vecProjectiles.push_back( "kaon+" );         
172   // vecProjectiles.push_back( "kaon0L" );        
173   // vecProjectiles.push_back( "kaon0S" );        
174   // Note: vecProjectiles.push_back( "eta" );     
175   // Note: vecProjectiles.push_back( "eta_prim    
176   vecProjectiles.push_back("proton");             
177   // vecProjectiles.push_back( "neutron" );       
178   // vecProjectiles.push_back( "deuteron" );      
179   // vecProjectiles.push_back( "triton" );        
180   // vecProjectiles.push_back( "He3" );           
181   // vecProjectiles.push_back( "alpha" );         
182   // vecProjectiles.push_back( "lambda" );        
183   // vecProjectiles.push_back( "sigma-" );        
184   // Note: vecProjectiles.push_back( "sigma0"     
185   // vecProjectiles.push_back( "sigma+" );        
186   // vecProjectiles.push_back( "xi-" );           
187   // vecProjectiles.push_back( "xi0" );           
188   // vecProjectiles.push_back( "omega-" );        
189   // vecProjectiles.push_back( "anti_proton" )    
190   // vecProjectiles.push_back( "anti_neutron"     
191   // vecProjectiles.push_back( "anti_lambda" )    
192   // vecProjectiles.push_back( "anti_sigma-" )    
193   // Note: vecProjectiles.push_back( "anti_sig    
194   // vecProjectiles.push_back( "anti_sigma+" )    
195   // vecProjectiles.push_back( "anti_xi-" );      
196   // vecProjectiles.push_back( "anti_xi0" );      
197   // vecProjectiles.push_back( "anti_omega-" )    
198   // vecProjectiles.push_back( "anti_deuteron"    
199   // vecProjectiles.push_back( "anti_triton" )    
200   // vecProjectiles.push_back( "anti_He3" );      
201   // vecProjectiles.push_back( "anti_alpha" );    
202   //  Charm and bottom hadrons                    
203   // vecProjectiles.push_back( "D+" );            
204   // vecProjectiles.push_back( "D-" );            
205   // vecProjectiles.push_back( "D0" );            
206   // vecProjectiles.push_back( "anti_D0" );       
207   // vecProjectiles.push_back( "Ds+" );           
208   // vecProjectiles.push_back( "Ds-" );           
209   // Note: vecProjectiles.push_back( "etac" );    
210   // Note: vecProjectiles.push_back( "J/psi" )    
211   // vecProjectiles.push_back( "B+" );            
212   // vecProjectiles.push_back( "B-" );            
213   // vecProjectiles.push_back( "B0" );            
214   // vecProjectiles.push_back( "anti_B0" );       
215   // vecProjectiles.push_back( "Bs0" );           
216   // vecProjectiles.push_back( "anti_Bs0" );      
217   // vecProjectiles.push_back( "Bc+" );           
218   // vecProjectiles.push_back( "Bc-" );           
219   // Note: vecProjectiles.push_back( "Upsilon"    
220   // vecProjectiles.push_back( "lambda_c+" );     
221   // vecProjectiles.push_back( "anti_lambda_c+    
222   // Note: vecProjectiles.push_back( "sigma_c+    
223   // Note: vecProjectiles.push_back( "anti_sig    
224   // Note: vecProjectiles.push_back( "sigma_c0    
225   // Note: vecProjectiles.push_back( "anti_sig    
226   // Note: vecProjectiles.push_back( "sigma_c+    
227   // Note: vecProjectiles.push_back( "anti_sig    
228   // vecProjectiles.push_back( "xi_c+" );         
229   // vecProjectiles.push_back( "anti_xi_c+" );    
230   // vecProjectiles.push_back( "xi_c0" );         
231   // vecProjectiles.push_back( "anti_xi_c0" );    
232   // vecProjectiles.push_back( "omega_c0" );      
233   // vecProjectiles.push_back( "anti_omega_c0"    
234   // vecProjectiles.push_back( "lambda_b" );      
235   // vecProjectiles.push_back( "anti_lambda_b"    
236   // Note: vecProjectiles.push_back( "sigma_b+    
237   // Note: vecProjectiles.push_back( "anti_sig    
238   // Note: vecProjectiles.push_back( "sigma_b0    
239   // Note: vecProjectiles.push_back( "sigma_b0    
240   // Note: vecProjectiles.push_back( "sigma_b-    
241   // Note: vecProjectiles.push_back( "anti_sig    
242   // vecProjectiles.push_back( "xi_b0" );         
243   // vecProjectiles.push_back( "anti_xi_b0" );    
244   // vecProjectiles.push_back( "xi_b-" );         
245   // vecProjectiles.push_back( "anti_xi_b-" );    
246   // vecProjectiles.push_back( "omega_b-" );      
247   // vecProjectiles.push_back( "anti_omega_b-"    
248                                                   
249   G4ParticleDefinition* projectileNucleus = nu    
250   G4GenericIon* gion = G4GenericIon::GenericIo    
251   gion->SetProcessManager(new G4ProcessManager    
252   G4ParticleTable* partTable = G4ParticleTable    
253   G4IonTable* ions = partTable->GetIonTable();    
254   partTable->SetReadiness();                      
255   ions->CreateAllIon();                           
256   ions->CreateAllIsomer();                        
257                                                   
258   //***LOOKHERE***  HADRON (false) OR ION (tru    
259   const G4bool isProjectileIon = false;           
260   if (isProjectileIon) {                          
261     minEnergy = 40.0 * 13.0 * CLHEP::GeV;  //*    
262     maxEnergy = 40.0 * 13.0 * CLHEP::GeV;  //*    
263     G4int ionZ = 18, ionA = 40;  //***LOOKHERE    
264     projectileNucleus = partTable->GetIonTable    
265   }                                               
266                                                   
267   // Vector of Geant4 NIST names of materials:    
268   // (with uniform probability) for each colli    
269   // Note: comment out the corresponding line     
270   //       or, vice versa, add a new line to e    
271   std::vector<G4String> vecMaterials;  //***LO    
272   // vecMaterials.push_back( "G4_H" );            
273   // vecMaterials.push_back( "G4_He" );           
274   // vecMaterials.push_back( "G4_Be" );           
275   vecMaterials.push_back("G4_C");                 
276   // vecMaterials.push_back( "G4_Al" );           
277   // vecMaterials.push_back( "G4_Si" );           
278   // vecMaterials.push_back( "G4_Sc" );           
279   // vecMaterials.push_back( "G4_Ar" );           
280   // vecMaterials.push_back( "G4_Fe" );           
281   // vecMaterials.push_back( "G4_Cu" );           
282   // vecMaterials.push_back( "G4_W" );            
283   // vecMaterials.push_back( "G4_Pb" );           
284                                                   
285   const G4int numProjectiles = vecProjectiles.    
286   const G4int numMaterials = vecMaterials.size    
287                                                   
288   G4cout << G4endl << "=================  Conf    
289          << "Model: " << namePhysics << G4endl    
290          << maxEnergy / CLHEP::GeV << " ] GeV"    
291          << "Number of collisions:  " << numCo    
292          << "Number of hadron projectiles: " <    
293          << "Number of materials:   " << numMa    
294          << "IsIonProjectile: " << (projectile    
295          << (projectileNucleus != nullptr ? pr    
296          << G4endl << "=======================    
297                                                   
298   CLHEP::Ranlux64Engine defaultEngine(1234567,    
299   CLHEP::HepRandom::setTheEngine(&defaultEngin    
300   //***LOOKHERE***  RANDOM ENGINE START SEED      
301   // G4int seed = time( NULL );                   
302   // CLHEP::HepRandom::setTheSeed( seed );        
303   // G4cout << G4endl << " Initial seed = " <<    
304                                                   
305   // Set up histo manager.                        
306   auto histoManager = FinalStateHistoManager()    
307   histoManager.Book();                            
308                                                   
309   // Instanciate the HadronicGenerator providi    
310   HadronicGenerator* theHadronicGenerator = ne    
311   //******************************************    
312                                                   
313   if (theHadronicGenerator == nullptr) {          
314     G4cerr << "ERROR: theHadronicGenerator is     
315     return 1;                                     
316   }                                               
317   else if (!theHadronicGenerator->IsPhysicsCas    
318     G4cerr << "ERROR: this physics case is NOT    
319     return 2;                                     
320   }                                               
321                                                   
322   // Start timing                                 
323   auto start = std::chrono::high_resolution_cl    
324                                                   
325   // Loop over the collisions                     
326   G4double rnd1, rnd2, rnd3, rnd4, rnd5, rnd6,    
327   G4VParticleChange* aChange = nullptr;           
328   for (G4int i = 0; i < numCollisions; ++i) {     
329     histoManager.BeginOfEvent();                  
330                                                   
331     // Draw some random numbers to select the     
332     // projectile hadron, projectile kinetic e    
333     rnd1 = CLHEP::HepRandom::getTheEngine()->f    
334     rnd2 = CLHEP::HepRandom::getTheEngine()->f    
335     rnd3 = CLHEP::HepRandom::getTheEngine()->f    
336     rnd4 = CLHEP::HepRandom::getTheEngine()->f    
337     rnd5 = CLHEP::HepRandom::getTheEngine()->f    
338     rnd6 = CLHEP::HepRandom::getTheEngine()->f    
339     // Sample the projectile kinetic energy       
340     projectileEnergy = minEnergy + rnd1 * (max    
341     if (projectileEnergy <= 0.0) projectileEne    
342     // Sample the projectile direction            
343     normalization = 1.0 / std::sqrt(rnd2 * rnd    
344     //***LOOKHERE***  IF true THEN SMEAR DIREC    
345     const G4bool isOnSmearingDirection = false    
346     //***LOOKHERE***  ELSE USE THIS FIXED DIRE    
347     G4ThreeVector aDirection = G4ThreeVector(0    
348     if (isOnSmearingDirection) {                  
349       aDirection = G4ThreeVector(normalization    
350     }                                             
351     // Sample the projectile hadron from the v    
352     G4int index_projectile = std::trunc(rnd5 *    
353     G4String nameProjectile = vecProjectiles[i    
354     G4ParticleDefinition* projectile = partTab    
355     if (projectileNucleus) {                      
356       nameProjectile = projectileNucleus->GetP    
357       projectile = projectileNucleus;             
358     }                                             
359     // Sample the target material from the vec    
360     // (Note: the target nucleus will be sampl    
361     G4int index_material = std::trunc(rnd6 * n    
362     G4String nameMaterial = vecMaterials[index    
363     G4Material* material = G4NistManager::Inst    
364     if (material == nullptr) {                    
365       G4cerr << "ERROR: Material " << nameMate    
366       return 3;                                   
367     }                                             
368     if (isPrintingEnabled) {                      
369       G4cout << "\t Collision " << i << " ; pr    
370       if (projectileNucleus) {                    
371         G4cout << " ; Ekin[MeV]/nucleon="         
372                << projectileEnergy                
373                     / static_cast<G4double>(st    
374       }                                           
375       else {                                      
376         G4cout << " ; Ekin[MeV]=" << projectil    
377       }                                           
378       G4cout << " ; direction=" << aDirection     
379     }                                             
380                                                   
381     // Call here the "hadronic generator" to g    
382     aChange = theHadronicGenerator->GenerateIn    
383       projectile, projectileEnergy,               
384       /* *************************************    
385                                                   
386     G4int nsec = aChange ? aChange->GetNumberO    
387     G4bool isPrintingOfSecondariesEnabled = fa    
388     if (isPrintingEnabled) {                      
389       G4cout << G4endl << "\t --> #secondaries    
390              << " ; impactParameter[fm]=" << t    
391              << " ; #projectileSpectatorNucleo    
392              << theHadronicGenerator->GetNumbe    
393              << " ; #targetSpectatorNucleons="    
394              << theHadronicGenerator->GetNumbe    
395              << " ; #NNcollisions=" << theHadr    
396       if (i % printingGap == 0) {                 
397         isPrintingOfSecondariesEnabled = true;    
398         G4cout << "\t \t List of produced seco    
399       }                                           
400     }                                             
401     // Loop over produced secondaries and even    
402     for (G4int j = 0; j < nsec; ++j) {            
403       const G4DynamicParticle* sec = aChange->    
404       if (isPrintingOfSecondariesEnabled) {       
405         G4cout << "\t \t \t j=" << j << "\t" <    
406                << "\t p=" << sec->Get4Momentum    
407       }                                           
408                                                   
409       // Store each secondary.                    
410       histoManager.ScoreSecondary(sec);           
411                                                   
412       delete aChange->GetSecondary(j);            
413     }                                             
414     if (aChange) aChange->Clear();                
415     histoManager.EndOfEvent();                    
416   }                                               
417                                                   
418   histoManager.EndOfRun();                        
419                                                   
420   G4cout << G4endl << " Final random number =     
421          << G4endl;                               
422                                                   
423   const auto stop = std::chrono::high_resoluti    
424   const auto diff = stop - start;                 
425   const auto time =                               
426     static_cast<G4double>(std::chrono::duratio    
427     / 1e6;                                        
428   G4cout << G4endl;                               
429   G4cout << "Processed " << numCollisions << "    
430          << " seconds."                           
431          << " Average: " << std::defaultfloat     
432          << G4endl;                               
433   G4cout << G4endl;                               
434                                                   
435   G4cout << "=== End of test ===" << G4endl;      
436 }                                                 
437                                                   
438 //....oooOO0OOooo........oooOO0OOooo........oo    
439