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] [ 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/ChargeExchangeMC.cc (Version 11.3.0) and /examples/advanced/ChargeExchangeMC/ChargeExchangeMC.cc (Version 6.0)


  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:  cexmc.cc                      
 30  *                                                
 31  *    Description:  main                          
 32  *                                                
 33  *        Version:  1.0                           
 34  *        Created:  10.10.2009 23:24:39           
 35  *       Revision:  none                          
 36  *       Compiler:  gcc                           
 37  *                                                
 38  *         Author:  Alexey Radkov (),             
 39  *        Company:  PNPI                          
 40  *                                                
 41  * ===========================================    
 42  */                                               
 43                                                   
 44 #include <set>                                    
 45 #ifdef CEXMC_USE_PERSISTENCY                      
 46 #include <boost/algorithm/string.hpp>             
 47 #include <boost/archive/archive_exception.hpp>    
 48 #ifdef CEXMC_USE_CUSTOM_FILTER                    
 49 #include <boost/variant/get.hpp>                  
 50 #endif                                            
 51 #endif                                            
 52 #include <G4UImanager.hh>                         
 53 #include <G4String.hh>                            
 54 #include <G4UIsession.hh>                         
 55 #include <G4UIterminal.hh>                        
 56 #ifdef G4UI_USE_TCSH                              
 57 #include <G4UItcsh.hh>                            
 58 #endif                                            
 59 #ifdef G4UI_USE_QT                                
 60 #include <G4UIQt.hh>                              
 61 #endif                                            
 62 #include <G4VisExecutive.hh>                      
 63 #include "CexmcRunManager.hh"                     
 64 #include "CexmcHistoManager.hh"                   
 65 #include "CexmcSetup.hh"                          
 66 #include "CexmcPhysicsList.hh"                    
 67 #include "CexmcPhysicsManager.hh"                 
 68 #include "CexmcPrimaryGeneratorAction.hh"         
 69 #include "CexmcTrackingAction.hh"                 
 70 #include "CexmcSteppingAction.hh"                 
 71 #include "CexmcEventAction.hh"                    
 72 #include "CexmcRunAction.hh"                      
 73 #include "CexmcMessenger.hh"                      
 74 #include "CexmcException.hh"                      
 75 #include "CexmcBasicPhysicsSettings.hh"           
 76 #include "CexmcCommon.hh"                         
 77                                                   
 78                                                   
 79 namespace                                         
 80 {                                                 
 81     const G4String  CexmcVisManagerVerboseLeve    
 82 }                                                 
 83                                                   
 84                                                   
 85 struct  CexmcCmdLineData                          
 86 {                                                 
 87     CexmcCmdLineData() : isInteractive( false     
 88                          preinitMacro( "" ), i    
 89                          wProject( "" ), overr    
 90                          customFilter( "" )       
 91     {}                                            
 92                                                   
 93     G4bool                  isInteractive;        
 94     G4bool                  startQtSession;       
 95     G4String                preinitMacro;         
 96     G4String                initMacro;            
 97     G4String                rProject;             
 98     G4String                wProject;             
 99     G4bool                  overrideExistingPr    
100     CexmcOutputDataTypeSet  outputData;           
101     G4String                customFilter;         
102 };                                                
103                                                   
104                                                   
105 void  printUsage( void )                          
106 {                                                 
107 #ifdef CEXMC_PROG_NAME                            
108     const char *  progName( CEXMC_PROG_NAME );    
109 #else                                             
110     const char *  progName( "cexmc" );            
111 #endif                                            
112                                                   
113     G4cout << "Usage: " << progName << " [-i]     
114 #ifdef G4UI_USE_QT                                
115                            "[-g] "                
116 #endif                                            
117                            "[-p preinit_macro]    
118 #ifdef CEXMC_USE_PERSISTENCY                      
119                            "[[-y] -w project]"    
120               "             [-r project "         
121 #ifdef CEXMC_USE_CUSTOM_FILTER                    
122                            "[-f filter_script]    
123 #endif                                            
124                            "[-o list]]"           
125 #endif                                            
126            << G4endl;                             
127     G4cout << "or     " << progName << " [--he    
128     G4cout << "           -i - run in interact    
129 #ifdef G4UI_USE_QT                                
130     G4cout << "           -g - start graphical    
131                               "interactive mod    
132 #endif                                            
133     G4cout << "           -p - use specified p    
134     G4cout << "           -m - use specified i    
135 #ifdef CEXMC_USE_PERSISTENCY                      
136     G4cout << "           -w - save data in sp    
137     G4cout << "           -r - read data from     
138               G4endl;                             
139 #ifdef CEXMC_USE_CUSTOM_FILTER                    
140     G4cout << "           -f - use specified c    
141 #endif                                            
142     G4cout << "           -o - comma-separated    
143                               "possible values    
144               "                run, geom, even    
145     G4cout << "           -y - force project o    
146 #endif                                            
147     G4cout << "  --help | -h - print this mess    
148 }                                                 
149                                                   
150                                                   
151 G4bool  parseArgs( int  argc, char **  argv, C    
152 {                                                 
153     if ( argc < 2 )                               
154         return false;                             
155                                                   
156     for ( G4int  i( 1 ); i < argc; ++i )          
157     {                                             
158         do                                        
159         {                                         
160             if ( G4String( argv[ i ] ) == "--h    
161             {                                     
162                 return false;                     
163             }                                     
164             if ( G4String( argv[ i ] ) == "-h"    
165             {                                     
166                 return false;                     
167             }                                     
168             if ( G4String( argv[ i ], 2 ) == "    
169             {                                     
170                 cmdLineData.isInteractive = tr    
171                 break;                            
172             }                                     
173 #ifdef G4UI_USE_QT                                
174             if ( G4String( argv[ i ], 2 ) == "    
175             {                                     
176                 cmdLineData.isInteractive = tr    
177                 cmdLineData.startQtSession = t    
178                 break;                            
179             }                                     
180 #endif                                            
181             if ( G4String( argv[ i ], 2 ) == "    
182             {                                     
183                 cmdLineData.preinitMacro = arg    
184                 if ( cmdLineData.preinitMacro     
185                 {                                 
186                     if ( ++i >= argc )            
187                         throw CexmcException(     
188                     cmdLineData.preinitMacro =    
189                 }                                 
190                 break;                            
191             }                                     
192             if ( G4String( argv[ i ], 2 ) == "    
193             {                                     
194                 cmdLineData.initMacro = argv[     
195                 if ( cmdLineData.initMacro ==     
196                 {                                 
197                     if ( ++i >= argc )            
198                         throw CexmcException(     
199                     cmdLineData.initMacro = ar    
200                 }                                 
201                 break;                            
202             }                                     
203 #ifdef CEXMC_USE_PERSISTENCY                      
204             if ( G4String( argv[ i ], 2 ) == "    
205             {                                     
206                 cmdLineData.wProject = argv[ i    
207                 if ( cmdLineData.wProject == "    
208                 {                                 
209                     if ( ++i >= argc )            
210                         throw CexmcException(     
211                     cmdLineData.wProject = arg    
212                 }                                 
213                 break;                            
214             }                                     
215             if ( G4String( argv[ i ], 2 ) == "    
216             {                                     
217                 cmdLineData.rProject = argv[ i    
218                 if ( cmdLineData.rProject == "    
219                 {                                 
220                     if ( ++i >= argc )            
221                         throw CexmcException(     
222                     cmdLineData.rProject = arg    
223                 }                                 
224                 break;                            
225             }                                     
226             if ( G4String( argv[ i ], 2 ) == "    
227             {                                     
228                 cmdLineData.overrideExistingPr    
229                 break;                            
230             }                                     
231             if ( G4String( argv[ i ], 2 ) == "    
232             {                                     
233                 std::string  outputData( argv[    
234                 if ( outputData == "" )           
235                 {                                 
236                     if ( ++i >= argc )            
237                         throw CexmcException(     
238                     outputData = argv[ i ];       
239                 }                                 
240                 std::set< std::string >  token    
241                 boost::split( tokens, outputDa    
242                 for ( std::set< std::string >:    
243                                                   
244                 {                                 
245                     do                            
246                     {                             
247                         if ( *k == "run" )        
248                         {                         
249                             cmdLineData.output    
250                             break;                
251                         }                         
252                         if ( *k == "geom" )       
253                         {                         
254                             cmdLineData.output    
255                                                   
256                             break;                
257                         }                         
258                         if ( *k == "events" )     
259                         {                         
260                             cmdLineData.output    
261                             break;                
262                         }                         
263                         throw CexmcException(     
264                     } while ( false );            
265                 }                                 
266                 break;                            
267             }                                     
268 #ifdef CEXMC_USE_CUSTOM_FILTER                    
269             if ( G4String( argv[ i ], 2 ) == "    
270             {                                     
271                 cmdLineData.customFilter = arg    
272                 if ( cmdLineData.customFilter     
273                 {                                 
274                     if ( ++i >= argc )            
275                         throw CexmcException(     
276                     cmdLineData.customFilter =    
277                 }                                 
278                 break;                            
279             }                                     
280 #endif                                            
281 #endif                                            
282                                                   
283             throw CexmcException( CexmcCmdLine    
284                                                   
285         } while ( false );                        
286     }                                             
287                                                   
288     return true;                                  
289 }                                                 
290                                                   
291                                                   
292 int  main( int  argc, char **  argv )             
293 {                                                 
294                                                   
295     G4UIsession *     session( NULL );            
296                                                   
297                                                   
298     CexmcCmdLineData  cmdLineData;                
299 #ifdef CEXMC_USE_PERSISTENCY                      
300     G4bool            outputDataOnly( false );    
301 #endif                                            
302                                                   
303     try                                           
304     {                                             
305         if ( ! parseArgs( argc, argv, cmdLineD    
306         {                                         
307             printUsage();                         
308             return 0;                             
309         }                                         
310 #ifdef CEXMC_USE_PERSISTENCY                      
311         if ( cmdLineData.rProject != "" &&        
312              cmdLineData.rProject == cmdLineDa    
313             throw CexmcException( CexmcCmdLine    
314         if ( cmdLineData.rProject == "" && ! c    
315             throw CexmcException( CexmcCmdLine    
316 #ifdef CEXMC_USE_CUSTOM_FILTER                    
317         if ( cmdLineData.rProject == "" && ! c    
318             throw CexmcException( CexmcCmdLine    
319 #endif                                            
320         if ( cmdLineData.wProject != "" && ! c    
321             throw CexmcException( CexmcCmdLine    
322         outputDataOnly = ! cmdLineData.outputD    
323 #endif                                            
324     }                                             
325     catch ( CexmcException &  e )                 
326     {                                             
327         G4cout << e.what() << G4endl;             
328         return 1;                                 
329     }                                             
330     catch ( ... )                                 
331     {                                             
332         G4cout << "Unknown exception caught wh    
333         return 1;                                 
334     }                                             
335                                                   
336     CexmcRunManager *  runManager( NULL );        
337     CexmcMessenger::Instance();                   
338                                                   
339     G4VisManager *     visManager( NULL );        
340                                                   
341 #ifdef CEXMC_USE_ROOT                             
342     CexmcHistoManager::Instance();                
343 #endif                                            
344                                                   
345     try                                           
346     {                                             
347         runManager = new CexmcRunManager( cmdL    
348                                           cmdL    
349                                           cmdL    
350 #ifdef CEXMC_USE_PERSISTENCY                      
351 #ifdef CEXMC_USE_CUSTOM_FILTER                    
352         runManager->SetCustomFilter( cmdLineDa    
353 #endif                                            
354                                                   
355         if ( outputDataOnly )                     
356         {                                         
357             /* we will need an arbitrary physi    
358              * table if events output was orde    
359             CexmcOutputDataTypeSet::const_iter    
360                             cmdLineData.output    
361             if ( found != cmdLineData.outputDa    
362                 runManager->SetUserInitializat    
363                                 CexmcChargeExc    
364                                             Cr    
365             runManager->PrintReadData( cmdLine    
366             delete runManager;                    
367             return 0;                             
368         }                                         
369 #endif                                            
370                                                   
371         G4UImanager *  uiManager( G4UImanager:    
372                                                   
373         if ( cmdLineData.preinitMacro != "" )     
374             uiManager->ApplyCommand( "/control    
375                                      cmdLineDa    
376                                                   
377         CexmcProductionModelType  productionMo    
378                                         runMan    
379                                                   
380         if ( productionModelType == CexmcUnkno    
381             throw CexmcException( CexmcPreinit    
382                                                   
383         G4VUserPhysicsList *    physicsList( C    
384                                                   
385         CexmcPhysicsManager *   physicsManager    
386                         dynamic_cast< CexmcPhy    
387         CexmcProductionModel *  productionMode    
388                                         physic    
389                                                   
390         if ( ! productionModel )                  
391             throw CexmcException( CexmcWeirdEx    
392                                                   
393         G4cout << CEXMC_LINE_START << "Product    
394                 productionModel->GetName() <<     
395                                                   
396         runManager->SetUserInitialization( phy    
397                                                   
398         CexmcSetup *   setup( new CexmcSetup(     
399                                     runManager    
400                                                   
401         runManager->SetUserInitialization( set    
402                                                   
403         runManager->Initialize();                 
404                                                   
405         runManager->SetPhysicsManager( physics    
406                                                   
407         runManager->SetUserAction( new CexmcPr    
408                                                   
409                                                   
410         runManager->SetUserAction( new CexmcEv    
411                                                   
412         runManager->SetUserAction( new CexmcRu    
413                                                   
414         runManager->SetUserAction( new CexmcTr    
415                                                   
416         runManager->SetUserAction( new CexmcSt    
417                                                   
418 #ifdef CEXMC_USE_ROOT                             
419         CexmcHistoManager::Instance()->Initial    
420 #endif                                            
421                                                   
422                                                   
423         if ( cmdLineData.isInteractive )          
424         {                                         
425             visManager = new G4VisExecutive( C    
426             visManager->Initialize();             
427         }                                         
428                                                   
429                                                   
430 #ifdef CEXMC_USE_PERSISTENCY                      
431         if ( runManager->ProjectIsRead() )        
432         {                                         
433             runManager->ReadProject();            
434             runManager->PrintReadRunData();       
435         }                                         
436 #endif                                            
437                                                   
438         if ( cmdLineData.initMacro != "" )        
439             uiManager->ApplyCommand( "/control    
440                                      cmdLineDa    
441                                                   
442         if ( cmdLineData.isInteractive )          
443             productionModel->PrintInitialData(    
444                                                   
445                                                   
446         if ( cmdLineData.isInteractive )          
447         {                                         
448             if ( cmdLineData.startQtSession )     
449             {                                     
450 #ifdef G4UI_USE_QT                                
451                 /* no need to pass all command    
452                 session = new G4UIQt( 1, argv     
453                 const G4String &  guiMacroName    
454                 if ( guiMacroName != "" )         
455                     uiManager->ApplyCommand( "    
456                                              g    
457 #ifdef CEXMC_USE_ROOTQT                           
458                 CexmcHistoManager::Instance()-    
459 #endif                                            
460 #endif                                            
461             }                                     
462             else                                  
463             {                                     
464 #ifdef G4UI_USE_TCSH                              
465                 session = new G4UIterminal( ne    
466 #else                                             
467                 session = new G4UIterminal;       
468 #endif                                            
469             }                                     
470             if ( session )                        
471                 session->SessionStart();          
472         }                                         
473                                                   
474 #ifdef CEXMC_USE_PERSISTENCY                      
475         if ( runManager->ProjectIsSaved() )       
476             runManager->SaveProject();            
477 #endif                                            
478     }                                             
479     catch ( CexmcException &  e )                 
480     {                                             
481         G4cout << e.what() << G4endl;             
482     }                                             
483 #ifdef CEXMC_USE_PERSISTENCY                      
484     catch ( boost::archive::archive_exception     
485     {                                             
486         G4cout << CEXMC_LINE_START << "Seriali    
487                   G4endl;                         
488     }                                             
489 #ifdef CEXMC_USE_CUSTOM_FILTER                    
490     catch ( boost::bad_get &  e )                 
491     {                                             
492         G4cout << CEXMC_LINE_START << "Custom     
493                   G4endl;                         
494     }                                             
495 #endif                                            
496 #endif                                            
497     catch ( ... )                                 
498     {                                             
499         G4cout << "Unknown exception caught" <    
500     }                                             
501                                                   
502 #ifdef CEXMC_USE_ROOT                             
503     CexmcHistoManager::Destroy();                 
504 #endif                                            
505                                                   
506     CexmcMessenger::Destroy();                    
507                                                   
508     delete session;                               
509     delete visManager;                            
510     delete runManager;                            
511                                                   
512     return 0;                                     
513 }                                                 
514                                                   
515