Facebook
From Wilk, 6 Years ago, written in C++.
This paste is a reply to Untitled from Wilk - view diff
Embed
Download Paste or View Raw
Hits: 368
  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. //                 GEANT 4 - Brachytherapy example
  28. // --------------------------------------------------------------
  29. //
  30. // Code developed currently by:
  31. //  S.Guatelli & D. Cutajar
  32.  
  33. //
  34. //    *******************************
  35. //    *                             *
  36. //    *    Brachy.cc                *
  37. //    *                             *
  38. //    *******************************
  39. //
  40. //
  41. #ifdef G4MULTITHREADED
  42.   #include "G4MTRunManager.hh"
  43. #else
  44.   #include "G4RunManager.hh"
  45. #endif
  46.  
  47. #include "G4UImanager.hh"
  48. #include "G4UIExecutive.hh"
  49.  
  50. #include "BrachyActionInitialization.hh"
  51.  
  52. #ifdef ANALYSIS_USE
  53. #include "BrachyAnalysisManager.hh"
  54. #endif
  55.  
  56. #ifdef G4VIS_USE
  57. #include "G4VisExecutive.hh"
  58. #endif
  59.  
  60. #include "BrachyDetectorConstruction.hh"
  61. #include "BrachyPhysicsList.hh"
  62. #include "BrachyPrimaryGeneratorAction.hh"
  63. #include "G4SDManager.hh"
  64. #include "Randomize.hh"  
  65. #include "G4RunManager.hh"
  66. #include "G4SDManager.hh"
  67. #include "G4UImanager.hh"
  68. #include "G4UImessenger.hh"
  69.  
  70. #include "G4ScoringManager.hh"
  71.  
  72. #ifdef G4UI_USE
  73. #include "G4UIExecutive.hh"
  74. #endif
  75.  
  76. #include "G4ScoringManager.hh"
  77. #include "BrachyUserScoreWriter.hh"
  78.  
  79. int main(int argc ,char ** argv)
  80.  
  81. {
  82. #ifdef G4MULTITHREADED
  83.   G4MTRunManager* pRunManager = new G4MTRunManager;
  84.   pRunManager->SetNumberOfThreads(4); // Is equal to 2 by default
  85. #else
  86.  G4RunManager* pRunManager = new G4RunManager;
  87. #endif
  88.  
  89.   G4int seed = 0;
  90.  
  91.   G4Random::setTheSeed(seed);
  92.  
  93.   G4cout << "***********************" << G4endl;
  94.   G4cout << "*** " << seed << " ***" << G4endl;
  95.   G4cout << "***********************" << G4endl;
  96.  // Access to the Scoring Manager pointer
  97.  
  98.   G4ScoringManager* scoringManager = G4ScoringManager::GetScoringManager();
  99.  
  100.   // Overwrite the default output file with user-defined one
  101.   scoringManager->SetScoreWriter(new BrachyUserScoreWriter());
  102.  
  103.   // Initialize the physics component
  104.   pRunManager -> SetUserInitialization(new BrachyPhysicsList);
  105.  
  106.   // Initialize the detector component
  107.   BrachyDetectorConstruction  *pDetectorConstruction = new  BrachyDetectorConstruction();
  108.   pRunManager -> SetUserInitialization(pDetectorConstruction);
  109.  
  110. //  Analysis Manager
  111. #ifdef ANALYSIS_USE
  112.   BrachyAnalysisManager* analysis = BrachyAnalysisManager::GetInstance();
  113.   analysis -> book();
  114. #endif
  115.  
  116.   // User action initialization  
  117.  
  118.   BrachyActionInitialization* actions = new BrachyActionInitialization();
  119.   pRunManager->SetUserInitialization(actions);
  120.  
  121.   //Initialize G4 kernel
  122.   pRunManager -> Initialize();
  123.  
  124. //// Initialize the Visualization component
  125. #ifdef G4VIS_USE
  126.   // Visualization manager
  127.   G4VisManager* visManager = new G4VisExecutive;
  128.   visManager->Initialize();
  129. #endif
  130.  
  131.   // get the pointer to the User Interface manager
  132.   G4UImanager* UImanager = G4UImanager::GetUIpointer();  
  133.   if (argc == 1)   // Define UI session for interactive mode.
  134.     {
  135. #ifdef G4UI_USE
  136.       G4UIExecutive* ui = new G4UIExecutive(argc, argv);
  137.       G4cout << " UI session starts ..." << G4endl;
  138.       UImanager -> ApplyCommand("/control/execute VisualisationMacro.mac");    
  139.       ui -> SessionStart();
  140.       delete ui;
  141. #endif
  142.     }
  143.   else           // Batch mode
  144.     {
  145.       G4String command = "/control/execute ";
  146.       G4String fileName = argv[1];
  147.       UImanager -> ApplyCommand(command+fileName);
  148.     }  
  149.  
  150.   // Job termination
  151. #ifdef G4VIS_USE
  152.   delete visManager;
  153. #endif
  154.  
  155. #ifdef ANALYSIS_USE
  156. // Close the output ROOT file with the results
  157.    analysis -> save();
  158.   delete analysis;
  159. #endif
  160.  
  161.   delete pRunManager;
  162.  
  163.   return 0;
  164. }
  165.