Ignore:
Timestamp:
Jun 14, 2010, 3:54:58 PM (14 years ago)
Author:
garnier
Message:

geant4.9.4 beta rc0

Location:
trunk/examples/advanced/hadrontherapy
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/advanced/hadrontherapy/GNUmakefile

    r1230 r1313  
    1 # $Id: GNUmakefile,v 1.12 2009/08/13 20:48:04 kaitanie Exp $
     1# $Id: GNUmakefile,v 1.17 2010/05/18 11:14:39 cirrone Exp $
    22# --------------------------------------------------------------
    33# GNUmakefile for examples module.  Gabriele Cosmo, 06/04/98.
     
    88G4EXLIB := true
    99
     10# Debug info
     11#CPPFLAGS += -g
     12
    1013ifndef G4INSTALL
    11   G4INSTALL = ../../..
     14  G4INSTALL = ../..
    1215endif
    1316
     
    1720include $(G4INSTALL)/config/architecture.gmk
    1821
    19 ifdef G4ANALYSIS_USE
    20 CPPFLAGS += -DANALYSIS_USE
    21 endif
    22 ifndef G4ANALYSIS_USE      # If we don't have AIDA
    23 ifdef G4ANALYSIS_USE_ROOT   # And we have ROOT
    24 CPPFLAGS += -DANALYSIS_USE -DG4ANALYSIS_USE_ROOT
     22ifdef G4ANALYSIS_USE_ROOT   # If we have ROOT
     23CPPFLAGS += -DG4ANALYSIS_USE_ROOT
    2524CPPFLAGS += $(shell root-config --cflags)
    2625LDFLAGS  += $(shell root-config --glibs)
    27 endif
    2826endif
    2927
    3028include $(G4INSTALL)/config/binmake.gmk
    3129
    32 ifdef G4ANALYSIS_USE
    33 endif
  • trunk/examples/advanced/hadrontherapy/Hadrontherapy.cc

    r1230 r1313  
    2424// ********************************************************************
    2525//
    26 // Hadrontherapy.cc
    27 //
    28 // Main of the Hadrontherapy example;
    29 // Released with the Geant4 9.3 version (December 2009)
    30 //
    31 // Last modified: G.A.P.Cirrone
    32 //
     26// This is the *basic* version of Hadrontherapy, a Geant4-based application
    3327// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
    3428//
     29// To obtain the full version visit the pages: http://sites.google.com/site/hadrontherapy/
     30
    3531// ----------------------------------------------------------------------------
    3632//                 GEANT 4 - Hadrontherapy example
    3733// ----------------------------------------------------------------------------
    38 // Code developed by:
     34// Main Authors:
    3935//
    4036// G.A.P. Cirrone(a)°, G.Cuttone(a), F.Di Rosa(a), E.Mazzaglia(a), F.Romano(a)
    4137//
    4238// Contributor authors:
    43 // P.Kaitaniemi(d), A.Heikkinen(d), Gillis Danielsen (d)
     39// P.Kaitaniemi(d), A.Heikkinen(d), G.Danielsen (d)
    4440//
    4541// Past authors:
     
    10197#endif
    10298
     99#ifdef G4UI_USE
     100#include "G4UIExecutive.hh"
     101#endif
    103102//////////////////////////////////////////////////////////////////////////////////////////////
     103
    104104int main(int argc ,char ** argv)
    105105{
    106   // Set the Random engine
    107   CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
    108 
    109   G4RunManager* runManager = new G4RunManager;
    110 
    111   //Initialize possible analysis needs, needs to come early in order to pick up metadata
    112 #ifdef ANALYSIS_USE
    113   HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance();
    114   analysis -> book();
    115 #endif
    116   // Geometry controller is responsible for instantiating the
    117   // geometries. All geometry specific setup tasks are now in class
    118   // HadrontherapyGeometryController.
    119   HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController();
    120 
    121   // Connect the geometry controller to the G4 user interface
    122   HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
    123 
    124   G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager();
    125   scoringManager->SetVerboseLevel(1);
    126   scoringManager->SetScoreWriter(new IAEAScoreWriter());
    127 
    128   // Initialize the default Hadrontherapy geometry
    129   geometryController->SetGeometry("default");
    130 
    131   // Initialize command based scoring
    132   G4ScoringManager::GetScoringManager();
    133 
    134   // Initialize the physics
    135   runManager -> SetUserInitialization(new HadrontherapyPhysicsList());
    136 
    137   // Initialize the primary particles
    138   HadrontherapyPrimaryGeneratorAction *pPrimaryGenerator = new HadrontherapyPrimaryGeneratorAction();
    139   runManager -> SetUserAction(pPrimaryGenerator);
    140  
    141   // Optional UserActions: run, event, stepping
    142   HadrontherapyRunAction* pRunAction = new HadrontherapyRunAction();
    143   runManager -> SetUserAction(pRunAction);
    144 
    145   HadrontherapyEventAction* pEventAction = new HadrontherapyEventAction();
    146   runManager -> SetUserAction(pEventAction);
    147 
    148   HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction);
    149   runManager -> SetUserAction(steppingAction);   
    150 
    151   // Interaction data: stopping powers
    152   HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters();
    153 
     106                // Set the Random engine
     107        CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
     108       
     109        // Only if an initial random seed is needed
     110        // G4int seed = time(0);
     111        // CLHEP::HepRandom::setTheSeed(seed);
     112       
     113        G4RunManager* runManager = new G4RunManager;
     114        // Geometry controller is responsible for instantiating the
     115        // geometries. All geometry specific setup tasks are now in class
     116        // HadrontherapyGeometryController.
     117        HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController();
     118       
     119        // Connect the geometry controller to the G4 user interface
     120        HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
     121       
     122        G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager();
     123        scoringManager->SetVerboseLevel(1);
     124        scoringManager->SetScoreWriter(new IAEAScoreWriter());
     125       
     126                // Initialize the default Hadrontherapy geometry
     127        geometryController->SetGeometry("default");
     128       
     129                // Initialize command based scoring
     130        G4ScoringManager::GetScoringManager();
     131       
     132                // Initialize the physics
     133        runManager -> SetUserInitialization(new HadrontherapyPhysicsList());
     134       
     135                // Initialize the primary particles
     136        HadrontherapyPrimaryGeneratorAction *pPrimaryGenerator = new HadrontherapyPrimaryGeneratorAction();
     137        runManager -> SetUserAction(pPrimaryGenerator);
     138       
     139                // Optional UserActions: run, event, stepping
     140        HadrontherapyRunAction* pRunAction = new HadrontherapyRunAction();
     141        runManager -> SetUserAction(pRunAction);
     142       
     143        HadrontherapyEventAction* pEventAction = new HadrontherapyEventAction();
     144        runManager -> SetUserAction(pEventAction);
     145       
     146        HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction);
     147        runManager -> SetUserAction(steppingAction);   
     148       
     149                // Interaction data: stopping powers
     150        HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true);
     151       
    154152#ifdef G4VIS_USE
    155   // Visualization manager
    156   G4VisManager* visManager = new G4VisExecutive;
    157   visManager -> Initialize();
     153                // Visualization manager
     154        G4VisManager* visManager = new G4VisExecutive;
     155        visManager -> Initialize();
    158156#endif
    159 
    160 G4UImanager* UI = G4UImanager::GetUIpointer();     
    161  
    162  if (argc!=1)   // batch mode
    163    {
    164      G4String command = "/control/execute ";
    165      G4String fileName = argv[1];
    166      UI->ApplyCommand(command+fileName);   
    167    }
    168  
    169  else  // interactive mode : define visualization UI terminal
    170    {
    171      G4UIsession* session = 0;
    172      
    173      // If the enviroment variable for the TCSH terminal is active, it is used and the
    174      // defaultMacro.mac file is executed
     157       
     158        G4UImanager* UI = G4UImanager::GetUIpointer();
     159       
     160        // Batch mode: in this configuration, i.e. when the User explicitly call a macro file,
     161        // the program run and, at the end, authomatically call the exit state.
     162        // With a such configuration, it is possible to send in background a simulation
     163        // and correctly get the output file.
     164        if (argc!=1)   
     165        {
     166                G4UIsession* session = 0;
     167                G4String command = "/control/execute ";
     168                G4String fileName = argv[1];
     169                UI -> ApplyCommand(command+fileName);
    175170#if defined(G4UI_USE_TCSH)
    176      session = new G4UIterminal(new G4UItcsh);     
    177      UI->ApplyCommand("/control/execute defaultMacro.mac"); 
    178 
    179      // Alternatively (if G4UI_USE_TCSH is not defined)  the program search for the
    180      // G$UI_USE_QT variable. It starts a graphical user interface based on the QT libraries
    181      // In the following case the GUI.mac file is also executed
    182      //
     171                session = new G4UIterminal(new G4UItcsh);
     172#else
     173                session = new G4UIterminal();
     174#endif
     175                // Only if the User Interface is needed!
     176                //session -> SessionStart();
     177                //delete session;
     178        }
     179        else  // interactive mode : define visualization UI terminal
     180        {
     181                G4UIsession* session = 0;
     182               
     183                        // If the enviroment variable for the TCSH terminal is active, it is used and the
     184                        // defaultMacro.mac file is executed
     185#if defined(G4UI_USE_TCSH)
     186                session = new G4UIterminal(new G4UItcsh);
     187                UI->ApplyCommand("/control/execute defaultMacro.mac");
     188                session -> SessionStart();
     189               
     190                // Alternatively (if G4UI_USE_TCSH is not defined)  the program search for the
     191                // G4UI_USE_QT variable. It starts a graphical user interface based on the QT libraries
     192                // In the following case the GUI.mac file is also executed
    183193#elif defined(G4UI_USE_QT)
    184      session = new G4UIQt(argc,argv);
    185      UI->ApplyCommand("/control/execute macro/GUI.mac");     
    186      
    187      // As final option, the simpler user interface terminal is opened
     194                session = new G4UIQt(argc,argv);
     195                UI->ApplyCommand("/control/execute macro/GUI.mac");     
     196                session -> SessionStart();
     197                // As final option, the basic user interface terminal is opened
    188198#else
    189     session = new G4UIterminal();
    190     UI->ApplyCommand("/control/execute defaultMacro.mac");
    191 #endif
    192     session->SessionStart();
    193     delete session;
    194    }
    195     HadrontherapyMatrix* matrix = HadrontherapyMatrix::getInstance();
    196     if (matrix) matrix -> TotalEnergyDeposit();
    197  
    198 #ifdef ANALYSIS_USE
    199  analysis -> finish();
    200 #endif
    201 
    202  // Job termination
    203 #ifdef G4VIS_USE
    204  delete visManager;
     199                session = new G4UIterminal();
     200               
     201                UI -> ApplyCommand("/control/execute defaultMacro.mac");
     202                session -> SessionStart();
     203#endif
     204                delete session;
     205        }
     206       
     207                // Job termination
     208#ifdef G4ANALYSIS_USE_ROOT
     209    HadrontherapyAnalysisManager::GetInstance() -> flush();     // Finalize the root file
     210#endif
     211
     212#ifdef G4UI_USE
     213      G4UIExecutive * ui = new G4UIExecutive(argc,argv);     
     214      ui->SessionStart();
     215      delete ui;
    205216#endif
    206217 
     
    210221  delete runManager;
    211222  return 0;
     223 
    212224}
  • trunk/examples/advanced/hadrontherapy/History

    r1230 r1313  
    88             History file of the Hadrontherapy application
    99         ====================================================
    10 
    11 25.11.2009 S.E.Mazzaglia & F.Romano; Tag:Hadrontherapy-V09-02-40
     1003.06.2010 J.Perl; Tag: Hadrontherapy-V09-03-04
     11           - Updated vis usage
     12
     1301.06.2010: G.A.P.Cirrone; Tag: harontherapy-V09-03-03
     14           - Added G4UIExecutive
     15           - Main file updated
     16
     1722.05.2010 S.E.Mazzaglia; Tag: hadrontherapy-V09-03-02
     18           - Updated ROOT scripts in folder RootScripts/proton/BraggPeak
     19
     2021.05.2010 S.E.Mazzaglia; Tag: hadrontherapy-V09-03-01
     21           - Solved some bugs related to the preprocessor variable G4ANALYSIS_USE_ROOT.
     22
     2318.05.2010 S.E.Mazzaglia; Tag: hadrontherapy-V09-03-00
     24           - Removed the possibility to calculate Let.
     25           - Removed AIDA and variables: G4_ANALYSIS_USE and ANALYSIS_USE.
     26           - Improved the commands to modify phantom/detector geometry
     27           - Added a command to set cuts just only in the detector: /physic/setDetectorCuts
     28           - Added the possibility to store dose & fluence for all secondaries
     29             produced in the same ASCII file. This feature can be switched on by the macro
     30             command: /analysis/secondaries true.
     31             
     32
     3316.12.2009 S.E.Mazzaglia; Tag: hadrontherapy-V09-02-42
     34           - Added the possibility to calculate the Let too, using an ASCII file to store it.
     35           - Added the new class HadrontherapyLet.
     36           - Minor revisions of the code.
     37
     3827.11.2009 S.E.Mazzaglia; Tag: hadrontherapy-V09-02-41
     39           - Added the possibility to store dose and fluence for every particle/ion
     40             produced during the simulation
     41
     4225.11.2009 S.E.Mazzaglia & F.Romano; Tag: hadrontherapy-V09-02-40
    1243           - Corrected a bug in HadrontherapyDetectorConstruction class
    13            - Added G4RadiactiveDecayPhysics class to the Physics List.
    14 
    15 22.11.2009 S.E.Mazzaglia; Tag: Hadrontherapy-V09-02-39
     44           - Added G4RadiactivedecayPhysics class to the Physics List.
     45
     4622.11.2009 S.E.Mazzaglia; Tag: hadrontherapy-V09-02-39
    1647           - Correction in the initialization of the passiveProtonBeamLine class.
    1748
  • trunk/examples/advanced/hadrontherapy/README

    r807 r1313  
    11
    2      =========================================================
    3                   Geant4 - Hadrontherapy example
    4      =========================================================
    5 
    6                                 README file
    7                           ----------------------
    8 
    9                                    AUTHORS
    10 
    11 G.A.P. CIRRONE(a *), G.CUTTONE(a), F. DI ROSA(a), G.RUSSO(a)
    12 a. Laboratori Nazionali del Sud - Istituto Nazionale di Fisica Nucleare
    13    95123 Catania, Italy
    14 * e-mail:cirrone@lns.infn.it
    15 
    16 M.G. PIA(b)
    17 b. Istituto Nazionale di Fisica Nucleare, Sezione di Genova Via Dodecaneso, 33
    18    16146, Genova, Italy
    19 
    20 A. LECHNER (c)
    21 c. CERN, Switzerland
    22 
    23 More informations on the Hadrontherapy example can be found in the
    24 Hadrontherapy Documentation available at http://www.ge.infn.it/geant4/examples/
    25 
    26 Alternatevely send an e-mail to cirrone@lns.infn.it.
    27 
    28 
    29 ---->0. INTRODUCTION.                                                   
    30                                                                        
    31 The hadrontherapy example simulates a hadron therapy beam line.
    32 In particular the example models the specific proton therapy beam line
    33 installed at Laboratori Nazionali del Sud (INFN) in Catania, Sicily (Italy).
    34 For more information on the proton therapy center of Catania
    35 or/and proton/hadron therapy in general, please visit the
    36 pages:
    37 http://www.lns.infn.it/catanaweb/catana/
    38 
    39 ---->1. GEOMETRY SET-UP.
     2             =========================================================
     3                     Text version of the Hadrontherapy README file
     4             =========================================================
     5
     6Last revsion: G.A.P.Cirrone, November 2009;
     7Released with the Geant4 9.3 version (December 2009)
     8
     9------------------------------------------------------------------------------------------------
     10ADVERTISEMENT: this is the text version of the README file of the hadrontherapy application,
     11as it has been released in the official Geant4 9.3 release
     12
     13A more complete and updated version of this file is published inside the web pages of Hadrontherapy:
     14http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
     15
     16Please refer to the web-published version to know the last and future developments of hadrontherapy
     17-------------------------------------------------------------------------------------------------
     18
     19             =========================================================
     20                                HADRONTHERAPY
     21             =========================================================
     22
     23 Code developed by:
     24 G.A.P. Cirrone(a)°, G.Cuttone(a), F.Di Rosa(a), S.E.Mazzaglia(a), F.Romano(a)
    4025 
    41 The elements simulated are:
     26 Contributor authors:
     27 P.Kaitaniemi(d), A.Heikkinen(d), G.Danielsen (d)
     28
     29 Past authors:
     30 M.G.Pia(b), S.Guatelli(c), G.Russo(a), M.Russo(a), A.Lechner(e)
     31
     32 (a) Laboratori Nazionali del Sud
     33     of the INFN, Catania, Italy
     34
     35 (b) INFN Section of Genova, Italy
     36 
     37 (c) University of Wallongong, Australia
     38
     39 (d) Helsinki Institute of Physics, Helsinki, Finland
     40
     41 (e) CERN, (CH)
     42
     43  *Corresponding author, email to cirrone@lns.infn.it
     44-------------------------------------------------------------------------------------------------
     45
     46HADRONTHERAPY:
     47WHAT IT IS, WHAT IT DOES AND WHAT IT WILL PROVIDE          
     48Hadrontherapy is a Geant4-based application specifically developed to address typical needs related to the proton and ion therapy. 
     49It first release was in 2004. At that time Hadrontherapy was only capable to simulate a well specified proton therapy facility: the passive transport beam line installed at  Laboratori Nazionali del Sud (INFN) in Catania, Italy.
     50
     51Today Hadrontontherapy, except that it is in continuous development, is more flexible and show many additional capabilities as respect the past.
     52Its geometrical set-up, for example, is now completely interchangeable permitting a simple switch between different geometrical configurations.
     53In the actual version two geometrical configuration are available: the 'passive beam line'
     54and the 'IAEA Benchmark' geometry. See the paragraph Geometry set-up for more information.
     55Folder structure of Hadrontherapy
     56Hadrontherapy distribution contain different sub-folders:
     57
     58\src: where source .cc files are stored
     59\include: where header .hh files are stored
     60\macro: where a set of ready-to-use macro files are provided
     61\experimentalData: in this director a set of reference (both experimental and analithycal) data are stored. These data are then used to perform a direct comparison with simulation results that are stored in the simulationResults folder. Data stored are better described in the README file contained inside.
     62\SimulationOutputs: when one of the .mac file contained in the macro folder is used, simulation results are directly stored in this directory.
     63\RootScripts: if the ROOT program is installed the User can use the scripts contained in this directory to compare directly results from the his/her simulation with reference data provided inside the experimentalData folder.
     64
     65Currently this folders structure is in development and reference data as well as ROOT scripts will be added in the meanwhile new features and capabilities will be added. Moreover some ROOT script can be missed. Apologize for this and contact author if you need more information, clarification or useful discussion.
     66Description of the \macro folder
     67In the example directory, inside the "macro" folder two macro files are actually provided for the use of hadrontherapy with proton and carbon beams: proton_therapy.mac and ion_therapy.mac.
     68The proton_therapy.mac permits to run a simulation with the whole passive beam line installed in Catania.
     69The carbon_therapy.mac excludes all the elements (moving the origin of the ion beam close to the water phantom) and reproduce a simple passive beam line for the use with carbon beams.
     70The macro iaea.mac uses an alternative geometry that was created for the IAEA benchmark. It features a geometry with water target, aluminum beam window, and a particle detector behind the target.
     71
     72
     73DOWNLOAD AND INSTALLATION
     74Hadrontherapy source code is actually released inside the official distribution of the Geant4 toolkit in the $G4INSTALL/examples/AdvancedExamples folder.
     75
     76To run Hadrontherapy you must first install the Geant4 package. Once Geant4 is installed the example must be first compiled (with the command gmake inside the
     77../Hadrontherapy folder). When compilation is completed the program can be executed.
     78
     79A complete guide for the Geant4 installation in different operating systems can be found inside the official installation Geant4 pages.
     80
     81If you have troubles with the Geant4 installation please send an e-mail to us.
     82
     83
     84SISTEM SET-UP: enviroment variables
     85A standard Geant4 example GNUmakefile is provided                                                         
     86
     87The following section reports the environment variables that are necessary for the run of Hadrontherapy.
     88#-------------------------------------
     89#    SET UP LINUX  GCC
     90#-------------------------------------
     91
     92VERSION="geant4-09-03"
     93
     94# Path to the directory in wich you have put data files and CLHEP
     95LIBPATH=$HOME/Geant4Library
     96
     97export G4SYSTEM=Linux-g++
     98
     99# Path to the directory in wich you put your Geant4 installation
     100export G4INSTALL=$HOME/${VERSION}
     101
     102export G4LIB=$G4INSTALL/lib
     103export G4WORKDIR=$G4INSTALL/workdir
     104export G4EXE=$G4WORKDIR/bin/$G4SYSTEM
     105
     106export CLHEP_BASE_DIR=$LIBPATH/CLHEP2.0.4.5
     107export G4LEDATA=$LIBPATH/G4EMLOW6.9
     108export G4LEVELGAMMADATA=$LIBPATH/PhotonEvaporation2.0
     109export G4NEUTRONHPDATA=$LIBPATH/G4NDL3.13
     110export G4RADIOACTIVEDATA=$LIBPATH/RadioactiveDecay3.2
     111export G4ABLADATA=$LIBPATH/G4ABLA3.0
     112
     113export LD_LIBRARY_PATH=$CLHEP_BASE_DIR/lib:$LD_LIBRARY_PATH
     114
     115# For the generation .root file directly using the ROOT (if ROOT is
     116# instaled in you machine)
     117export G4ANALYSIS_USE_ROOT=1
     118export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH
     119
     120#-------------------------------------
     121#    SET UP    VRML VIEW
     122#-------------------------------------
     123export G4VIS_BUILD_VRML_DRIVER=1
     124export G4VIS_USE_VRML=1
     125export G4VIS_USE_VRMLFILE=1
     126export G4VRMLFILE_MAX_FILE_NUM=100
     127export G4VRMLFILE_VIEWER=vrmlview    #if installed
     128
     129# Add path to your VRML installation
     130export PATH=$PATH:~/VRML
     131
     132#-------------------------------------
     133#    SET UP    OpenGL o Mesa
     134#-------------------------------------
     135export G4VIS_BUILD_OPENGLX_DRIVER=1
     136export G4VIS_USE_OPENGLX=1
     137    
     138# Add path to your OpenGL installation
     139#export OGLHOME=/usr/lib
     140
     141
     142#-------------------------------------
     143#    SET UP    DAWN (if installed)
     144#-------------------------------------
     145export G4VIS_BUILD_DAWN_DRIVER=1
     146export G4VIS_BUILD_DOWNFILE_DRIVER=1
     147export G4VIS_USE_DAWN=1
     148export G4VIS_USE_DAWNFILE=1
     149# Add path to your DAWN installation
     150# export PATH=$PATH:~/dawn_3_86a
     151
     152# VARIOUS USER INTERFACES
     153export G4UI_USE_XM=1
     154export G4UI_USE_TCSH=1
     155export G4UI_BUILD_QT_SESSION=1
     156export G4UI_USE_QT=1
     157
     158# VARIOUS GRPHICAL USER INTERFACES
     159export G4VIS_BUILD_QT_SESSION=1
     160export G4VIS_BUILD_OPENGLQT_DRIVER=1
     161export G4VIS_USE_OPENGLQT=1
     162
     163# If the QT libraries want be used for the User interfaces than the
     164# correct path must be addressed
     165export QTHOME=/usr/lib/qt-3.3
     166export PATH=$PATH:/usr/lib/qt-3.3/include/
     167export PATH=$PATH:/usr/lib/qt-3.3/
     168
     169GEOMETRICAL SET-UP
     170The idea of Hadrontherapy is to provide a tool useful for Users interested in the field of proton and ion therapy. These can include the simple calculation of dose distribution curves in water or other materials, the derivation of important transport parameters (stopping powers, ranges, etc.) in different geometrical set-ups and for different materials, up to the complete simulation of a real transport beam line for therapy.
     171
     172The main component of the simulation is the phantom, a box that can be filled with different material and where the score of different information (at moment  the dose deposited and fluence in voxels) can be performed. A more complete description of the phantom is given in the next subsection.
     173
     174At moment the Hadrontherapy include the simulation of the proton beam line for eye-treatments installed at the INFN-LNS facility in Catania. This is a passive beam line and it is simulated in the file PassiveProtonBeamLine.cc.
     175
     176In the next future an ActiveProtonBeamLine.cc will be provided for the simulation of the active scanning treatment modality.
     177Moreover the possibility to add a very simple set-up (a beam, a phantom where collect the informations and some simple component) will be also provided.
     178
     179All these configuration will be setted by macro commands.
     180
     181There is also a facility that allows the user to make a choice between alternative geometry set-ups. This can be done by using command:
     182/geometrySetup/selectGeometry <name>
     183where <name> is either "default" for the standard hadrontherapy geometry or "IAEA" for the IAEA benchmark geometry. Both geometries are described below. By default the standard "default" geometry is used.
     184The water phantom to collect informations
     185At the end of the beam line a phantom (a box of uniform material) is reproduced. Inside it, a user-defined region is divided (via the ROGeomtry classes of Geant4) in cubic and identical voxels. The voxels size can be varied as well as the voxelized region.
     186At the end of a simulation run the dose deposited by primaries and secondaries in each voxel is collected. This information is available as an .out file or as a .root (if the G4ANALYSIS_USE variable is defined and the AIDA interface is activated).  
     187
     188The default sizes of the active voxelized region are 40x40x40 mm and actually the default voxel configuration is 200 x 1 x 1, which means 200 slices with 0.2 mm of thickness.
     189Of course this default can be modified in order to obtain, for example, a matrix of 80x80x80 cubic voxels each with a lateral dimension of 0.5 mm.
     190
     191As concern the cut and stepMax values, the default configuration implies a cut value of 0.01 mm in the whole  world (use the command /physic/setCuts <length>  in order to set the cut for all, and the command /physic/setDetectorCuts <length> to set the cut for the detector only)  and a stepMax of 0.01 mm just in the phantom (use the command /Step/waterPhantomStepMax 0.01 mm).
     192In any case it is strongly recommended to use a stepMax value not bigger than 5% of the dose slice thickness.
     193The Proton passive beam line class file
     194The following is the description of the elements of the passive proton beam line of the Laboratori Nazionali del Sud in Catania (I). This line is completely simulated inside this class.
     195
     196The main elements are:
     197* The SCATTERING SYSTEM: to transversally enlarge the original beam
     198* The COLLIMATORS: placed along the beam line to collimate the beam;
     199* The RANGE SHIFTERS: to decrease the energy of the primary proton beam to a specific value;
     200* The MODULATOR WHEEL: to modulate the energy of the primary and mono-energetic beam in to a wide spectrum. The energy modulation is necessary to homogeneously irradiate a tumour volume that can extends in depth up to 20 mm;
     201* The MONITOR CHAMBERS: very thin ionisation chamber that permit the dose monitoring during the patient irradiation;
     202* The MOPI detector: microstrips, air free detector utilised for the check of the beam symmetry during the treatment;
     203* The PATIENT COLLIMATOR: a brass, tumour-shaped collimator able to  confine the proton irradiation field in order to irradiate just the tumour mass in the transverse direction;
     204
     205The user has the possibility to vary, via messenger, almost all the geometrical characteristics of the beam line elements (i.e. their position along the beam line, their thickness, etc.).
     206
     207The elements simulated in the PassiveBeamLine.cc file are:
    42208
    432091. A scattering system, to spread geometrically the beam;
     
    452112. A system of collimators, to avoid the scattering radiation;
    46212
    47 3. A modulation system that spreads the beam in energy and
    48    produces the so-called spread out bragg peak;
    49    It is constituted by a rotating wheel of different thichnesses.
    50    The wheel rotates around is axis (parallel to the proton
    51    beam axis) and its movement can be obtained by means of a
    52    messenger between runs.
    53 
    54 4. A set of monitor chambers (special transmission ionisation
    55    chambers used to control hadron flux during the irradiation);
    56 
    57 5. A "nozzle" and a final collimator defining the final shape
    58    of the beam before reaching the patient.
    59 
    60 6. A water phantom: it is a box of water where the energy deposit is
    61    calculated.
    62    The use of  the water phantom is required by the international protocol
    63    on the measure of dose in the case of proton and ion beams (IAEA 398, 2000).
    64 
    65 ---->2. EXPERIMENTAL SET-UP.     
    66                                      
    67 The application simulates the proton therapy beam line
    68 installed at Laboratori Nazionali del Sud.
    69 The default beam line is a typical treatment line composed by several elements all
    70 devoted to create the so-called "terapeutical beam", i.e. a beam ideal
    71 for a radiotherapeutic treatment.
    72 
    73    The main elements are:
    74 ** The COLLIMATORS: placed along the beam line to collimate the beam;
    75 
    76 ** The RANGE SHIFTERS: to decrease the energy of the primary proton beam
    77    to a specific value;
    78 
    79 ** The MODULATOR WHEEL: to modulate the energy of the primary and monoenergetic
    80    beam in to a wide spectrum. The energy modulation is necessary to
    81    homogeneusly irradiate a tumour volume that can extends in depth
    82    up to 20 mm;
    83 
    84 ** The MONITOR CHAMBERS: very thin ionisation chamber that permit the
    85    dose monitoring during the patient irradiation;
    86 
    87 ** The PATIENT COLLIMATOR: a brass, tumour-shaped collimator able to
    88    confine the proton irradiation field in order to irradiate just the tumour mass
    89    in the trasverse direction;
    90 
    91 The user has the possibility to vary, via messenger, almost all the geometrical
    92 characteristics of the beam line elements (i.e. their position along the beam line,
    93 their thickness, etc.). More details on the available user messengers can be
    94 found in the Hadronterapy Documentation (http://www.ge.infn.it/geant4/examples/).
    95 
    96 At the end of the beam line, a typical water phantom is reproduced.
    97 A user-defined region of the phantom is divided (via the ROGeomtry class) in
    98 cubic and identical voxels. The voxels size can be varied. At the end of the simulation
    99 the energy deposited by primary protons, and secondaries in each voxel
    100 is collected. This information is available as an .hbk file (if the
    101 G4ANALYSIS_USE variable is defined). 
    102 
    103 The default sizes of the active voxelized region are 40x40x40 mm corresponding
    104 to a matric of 80x80x80 cubic voxels each with a lateral dimension of 0.5 mm.
    105 
    106 ---->3. SET-UP
    107                                                                        
    108 - a standard Geant4 example GNUmakefile is provided                     
    109 
    110 setup with:                                                             
    111 compiler = gcc-3.2.3
    112 G4SYSTEM = linux-g++                                                   
    113 
    114 The following section reports the necessary environment variables
    115 necessary for the run of Hadrontherapy.                     
    116 
    117 ---->3.1  ENVIROMENT VARIABLES
    118 
    119  - G4SYSTEM = Linux-g++
    120 
    121  - G4INSTALL              points to the installation directory of GEANT4;
    122 
    123  - G4LIB                  point to the compiled libraries of GEANT4;
    124 
    125  - G4WORKDIR              points to the work directory;
    126 
    127  - CLHEP_BASE_DIR         points to the installation directory of CHLEP;
    128 
    129  - G4LEVELGAMMADATA       points to the photoevaporation library;
    130 
    131  - NeutronHPCrossSections points to the neutron data files;
    132 
    133  - G4RADIOACTIVEDATA      points to the libraries for radio-active decay
    134                           hadronic processes;
    135  
    136  - G4LEDATA               points to the low energy electromagnetic libraries
    137 
    138  - LD_LIBRARY_PATH = $CLHEP_BASE_DIR/lib
    139 
    140 ---->3.2  VISUALISATION
    141 
    142 The user can visualise the experimental set-up with OpenGL, DAWN and vrml
    143 
    144 ---->4. HOW TO RUN THE EXAMPLE                                         
    145 
    146 In interactive mode:
     2133. A modulation system that spreads the beam in energy and produces the so-called spread out Bragg peak; It is constituted by a rotating wheel of different thicknesses. The wheel  rotates around its axis (parallel to the proton beam axis) and its movement can be obtained by means of a messenger between runs.
     214
     2154. A set of monitor chambers (special transmission ionisation chambers used to control the particle flux during the irradiation);
     216
     2175. A final long collimator and a patient collimator defining the final shape of the beam before reaching the patient.
     218
     2196. A water phantom: it is a box of water where the dose deposit is calculated. The use of  the water phantom is required by the international protocol on the measure of dose in the case of proton and ion beams (IAEA 398, 2000).         
     220Geometry for the IAEA benchmark
     221Simple geometry for benchmark purposes contains water phantom (thickness can be set using a macro command), an aluminum beam window and Plexi-glass. Behind the phantom we have a detector that records outcoming particles. The IAEA geometry can be activated by using the command:
     222/geometrySetup/selectGeometry IAEA
     223
     224Example IAEA benchmark run can be done as follows:
     225run:        Hadrontherapy macro/iaea.mac
     226analysis: root RootScripts/iaeaBenchmark/fragmentEnergy.C
     227
     228PHYSICS PROCESSES AND PHYSICS MODELS IMPLEMENTATION
     229A particular care is addressed to the simulation of the physic processes.
     230Three different approaches can be used for the choose of the physic models.
     231Approach 1:
     232Using the macro command:
     233/physic/addPhysics/<physics List name>.
     234
     235In this case the models (for electromagnetic, hadronic elastic and hadronic inelastic) can be activated directly calling the name of the Physics Lists that are available inside the
     236Geant4 kernel in the directory:
     237
     238$G4INSTALL/source/physics_lists/builders/include
     239
     240An example of the use of the Physics List can be found in the macro files:
     241proton_therapy.mac and ion_therapy.mac
     242Approach 2:
     243A set of built-in physic models are also contained inside the Hadrontherapy directory. These are called Local*.cc and Local*.hh and can be activated using the macro command:
     244/physic/addPhysics/<name>.
     245Approach 3:
     246We developed this approach in order to simplify the choice of the physic models to
     247be used in the application.
     248With this approach the user must only insert a command line in his/her .mac file using the: /physics/addPackage <PACKAGE_NAME>
     249    
     250This permits to switch-on an already build physic package.
     251Various packages are already present in the Geant4 tree: they are in the directory: geant4/source/physics_lists/lists/include
     252
     253In this case hadronic inelastic models are directly activated for every particle.
     254
     255NOTE: we do not recommend the use of local physics lists while we recommend the use of the Physics Lists or of the Reference Physics Lists (Approach 1 or 3)
     256
     257--------------------------------------------------------------------------------
     258SUGGESTED PHYSIC FOR ION BEAMS IN THE RANGE 0 - 400 MeV
     259--------------------------------------------------------------------------------
     260Two macro files (proton_therapy.mac and ion_therapy.mac) can be used for proton and ion
     261simulations.
     262
     263Also the QGSP_BIC_EMY package can be used if the *Approach 3* is preferred.
     264
     265INTERACTIVE COMMANDS
     266How to change Phantom and Detector geometries
     267In order to let the end user to change phantom and detector geometries and voxelization, some interactive commands have been provided. All parameters are mandatory, except those inside square brackets.
     268
     269Detector geometry
     270
     271The user can change:
     272
     273(1) The detector (box) size.
     274 
     275(2) The voxels sizes. Changing this parameters, and/or the detector sizes, user should choose values in order to be divisors of the detector correspondent sizes.
     276For both above commands, zero or negative values mean << don't change it >>
     277
     278(3) The displacement between the phantom and the detector.  Displacement parameters refer to the lower left corner of the detector respect to that of the phantom, by the point of view of the beam. In this case zero or positive values are allowed, while the negatives ones mean: << don't change it>>.
     279
     280Command synopsis: the <default values> follow "#"
     281
     282
     2831. /changeDetector/size <dimX> <dimY> <dimZ> <[unit]> # 4 4 4 cm
     2842. /changeDetector/voxelSize <dimX> <dimY> <dimZ> <[unit]> # 0.2 40 40 mm
     2853. /changeDetector/displacement <dispX> <dispY> <dispZ> <[unit]> # 0 18 18 cm
     286
     287where the X dimension is that along the beam direction
     288
     289Phantom geometry
     290
     291(1) The phantom size. As usually, zero or negatives values mean: <<don't change it>>.
     292(2) The phantom position respect to the world. In this case specified values refer to the three components of the position of the phantom's center respect to the world's.
     293
     294Command synopsis:
     295
     2961. /changePhantom/size <dimX> <dimY> <dimZ> <[unit]> # 40 40 40 cm
     2972. /changePhantom/position <posX> <posY> <posZ> <[unit]> # 20 0 0 cm
     298
     299All these commands must be followed by the command /changePhantom/update
     300in order to check and apply them to the real geometry.
     301Moreover must be issued between runs (so where you want but after the /run/initialize initialization command, or the G4State_Idle Geant4 state machine).
     302Obviously all the previous sizes must be set in order to maintain the detector inside the phantom, otherwise system complains.
     303
     304 Some examples follow:
     305
     306/changeDetector/size 40 0 0 cm
     307# Will extend detector X size to cover in full the phantom X size  
     308
     309/changeDetector/size 0 4.5 0 cm
     310# Will extend the Y size to 4.5 cm (note that voxel size Y is automatically
     311#  rounded to 4.5 cm because the default value along Y is 4 cm)
     312/changePhantom/update
     313# Remember to always update the geometry before the beamOn command!!
     314
     315/changeDetector/size 0 8 0 cm
     316# Will extend the Y size to 8 cm. In this case voxel size Y doesn't change, but
     317# the number of voxel along Y doubles.
     318/changePhantom/update
     319
     320
     321/changeDetector/voxelSize 100 0 0 um
     322# 100 um should be a divisor of detector size X
     323# Will change only slabs X size to 100 um, without affecting the other.
     324/changePhantom/update
     325
     326/changeDetector/displacement 0 0 0 # default unit mm
     327# Will place the detector in the left lower corner (from the point of view of the beam) of #the  phantom.
     328/changePhantom/update
     329Stopping powers calculation
     330It is possible for the end-user to calculate, via macro command, stopping powers only for those materials inserted into G4NistMaterialBuilder class (about 300).
     331To get stopping powers user must provide this command line on the idle interactive terminal (or into a macro file) :
     332
     333/parameter/getstopping <G4_material> <Emin> <Emax> <nPoints> <[particle]> <[output_filename]>
     334
     335All parameters are mandatory except those inside square brackets [].
     336Default values for parameters inside square brackets are respectively proton and standard output (usually the user console terminal).
     337
     338Parameters are respectively:
     339
     340* The material (NIST) name (something like G4_..., the complete list of elements and materials is available into the G4NistMaterialBuilder class and can be printed  to the terminal screen via the macro command: /parameter/nist )
     341* Kinetic energy range in MeV and the number of data points to be retrieved (in a logarithmically uniform space)
     342* The particle name (proton, e+, e-, He3, neutron,... a full list can be gotten via the macro command: /particle/list).
     343         Only for ions, user must firstly give them to the particle gun, for example issuing the  macro commands:
     344a. /gun/particle ion
     345b. /gun/ion <Z> <A> <[charge]>
     346* The output filename: if users leave this blank then the standard output is used.
     347
     348Below is an example in order to calculate the stopping power for alphas into Hydrogen between 1 keV to 150 MeV for 15 points:
     349
     350/parameter/getstopping G4_H 0.001 150 15 alpha
     351
     352# and for C12 ion:
     353
     354/gun/particle ion
     355/gun/ion 6 12 6
     356/parameter/getstopping G4_H 0.001 150 15 C12[0.0]
     357
     358# Value inside square brackets is the excitation energy of the ion (ground state).
     359
     360HOW RUN HADRONTHERAPY
     361Run the example in interactive mode                                      
    147362> $G4WORDIR/bin/Linux-g++/Hadrontherapy
    148 The defaultMacro.mac is executed
    149 
    150 The primary particle beam parameter are:
    151 Radiation:                proton beam;
    152 Energy distribution:      gaussian;
    153 Mean energy:              63.4 MeV;
    154 Energy spread:            300 keV;
    155 Beam spot size:           1 mm;
    156 Beam angular spread:      0.057 deg;
    157 
    158 The modulator wheel can be rotated via the messenger:
    159 
    160 Idle>/modulator/angle/xx deg
    161 
    162 To produce a Spread Out Bragg Peak using the modulator a macro
    163 (modulatorMacro.mac) is provided. With this macro the modulator is
    164 rotated of 360 degree at 1 deg steps. In each run 1000 protons are
    165 generated as primary particles. Obviously a bigger resolution can be obtained
    166 with smaller angles or increasing the protons number in each run.
    167 
    168 Modulator wheel can be omitted setting its material air.
    169 
    170 run $G4WORKDIR/bin/Linux-g++/Hadrontherapy visualisationMacro.mac
    171 to visualise the experimental set-up with OpenGL
    172 
    173 ---->5. PHYSICS
    174 
    175 Both electromagnetic and hadronic physic processes are activated for
    176 the particles of the experimental set-up.
    177 Different physics models can be activated by the user interactively.
    178 
    179 Examples of activation are provided in the macro files starting
    180 with the string "physics":
    181 
    182 All possible physics options are summarized in the file
    183 physicsAllOptions.mac.
    184 
    185 Different options concerning electromagnetic interactions of protons
    186 and neutrons can be tested with the files:
    187 physicsElectromagneticICRU49.mac
    188 physicsElectromagneticZiegler77.mac
    189 physicsElectromagneticZiegler85.mac
    190 
    191 Different options concerning hadronic interactions of protons and
    192 neutrons can be tested with the files:
    193 physicsHadronicBertini.mac
    194 physicsHadronicBinary.mac
    195 physicsHadronicLEP.mac
    196 physicsHadronicPrecompound.mac
    197 
    198 NOTE: Apart from the different models for protons and neutrons, a user
    199 can also select among several interaction models for particles like
    200 electrons or photons. All possible options are listed in the file
    201 physicsAllOptions.mac.
    202 
    203 ---->6. SIMULATION OUTPUT                                   
    204 
    205 The output is an .hbk file (hadrontherapy.hbk) produced
    206 if the variable G4ANALYSIS_USE is set to 1 and the analysis tool (AIDA
    207 interface) correctly installed.
    208 The file contains an histogram and an n-tuple.
    209 The histogram contains the Bragg curve: energy deposited
    210 by the proton beam (in MeV) versus the depth in water (in mm).
    211 The n-tuple contains the total 3D energy deposit in the phantom; the information
    212 is energy deposit in each voxel with respect to the position of the voxel.
    213 
    214 Setup for analysis: AIDA 3.2.1 
    215 
    216 Users can download the analysis tools from: 
    217 http://aida.freehep.org/
    218 
    219 Note that the same information can be stored in any different format.
    220 Please contact cirrone@lns.infn.it if you want store the information in
    221 a different format.
    222 
    223 ---------------------------------------------------------------------------
    224 
    225 for comments, advices, doubts and questions please contact:
    226 cirrone@lns.infn.it, giorgiorusso@lns.infn.it
    227 
    228 last modified: A. Lechner, 16/11/2007
    229 
     363
     364In this case the main file (Hadrontherapy.cc) performs different operations depending on which environment variable is activated;
     365For example, if the environment variable G4UI_USE_TCSH is activated, Hadrontherapy will start with the TCSH User Interface that has many useful functionalities. On the other hand, if this first variables is not defined, the program will continue searching for the G4UI_USE_QT variable and, finally, will open the standard G4UITerminal.
     366Run the example using macro files          
     367Hadrontherapy can be launched using a macro file:
     368
     369> $G4WORDIR/bin/Linux-g++/Hadrontherapy macroFile.mac
     370
     371The defaultMacro.mac file is contained in the main directory of Hadrontherapy and is automatically readed in case the user launch the executable without a parameter. A big number of other macro are inside the /macro folder.
     372
     373Example use of command based scoring
     374In the IAEA geometry it is possible to collect the energy deposition data using the Geant4 command based scoring feature. This allows the users to define scorers interactively in the user interface without writing a single line of C++. Below is listed an example usage of command based scoring:
     375 
     376/score/create/boxMesh boxMesh_1
     377#Box size is the radius of the box ie 20x20x20 gives 40x40x40 outer dimensions
     378/score/mesh/boxSize 13.95 16. 16. cm
     379/score/mesh/translate/xyz 69 0.0 0.0 cm
     380/score/mesh/nBin 400 1 1      # 400 bins in x-direction, 1 in y and z directions
     381
     382SIMULATION OUTPUT
     383ASCII file
     384A .out file is generated at the end of each run, Dose.out is its default name that can be changed in the HadrontherapyMatrix.cc file.
     385The file can contain four columns; the first three columns represent the voxel indexes (that univocally identify the voxel volume), while the last column represent the dose deposited in the given voxel.
     386Alternatively, if the macro command /analysis/secondaries true is given, ordinated dose and fluence, for every secondary produced, is added to the file.
     387Setting the name of the ROOT output file
     388By default the name of the ROOT output file is DoseDistribution.root. The name of the file can be set by using command:
     389/analysis/setAnalysisFile <filename>
     390
     391It is also possible to create multiple new output files in the same simulation session. For example:
     392/beam/energy/meanEnergy 4800 MeV
     393/analysis/setAnalysisFile firstRun.root
     394/run/beamOn 1000
     395/beam/energy/meanEnergy 3000 MeV
     396/analysis/setAnalysisFile secondRun.root
     397/run/beamOn 1000
     398Use of the ROOT analysis
     399It is possible to use ROOT data analysis package directly for the production of output files.
     400In the last version, anyway, this functionality must be implemented by User. This can be accomplished by setting an ad-hoc environment variable (i.e. G4ANALYSIS_USE_ROOT) to 1, adding in the code lines to create outputs with the ROOT libraries and recompiling the application.
     401In this case you must have the ROOT framework installed in your machine.
     402
     403
     404FUTURE CHALLENGES AND USERS' REQUESTS
     405This is a list of future components that will be added in Hadrontherapy and of main Users requests that we hope to fulfill in the next future.
     406What is in progress
     4071. A module for the simulation of an active beam line will be provided.
     408The Korean Group of the Proton therapy center, National Cancer Center is developing this.
     4092. Modules for LET and RBE (Relative Biological Effectiveness) calculation. The Catania Group in Collaboration with the Turin one is working on this.
     4103. Hadrontherapy will permit the simulation of a 'basic' experiment usefull in hadrontherapy applications. User will be able to simulate thin/thick target configuration to calculate quantities like double differential cross sections of secondaries produces, or fluence and yelds of primary and secondaries in a thick block. This work is maily discussed with P. Kaitaniemi and the Group from the Helsinki Institute of Physics.
     411What is requested from Users
     4121. Dicom interface
     413
     414Please contact cirrone@lns.infn.it for more details or suggestions and feedbacks on this document
     415
     416
  • trunk/examples/advanced/hadrontherapy/defaultMacro.mac

    r1230 r1313  
    1 # G.A.P.Cirrone
     1 # G.A.P.Cirrone
    22#
    33# Default macro file. It is called if no argument is provided at run
     
    1919# Set of the physic models
    2020#
    21 /physic/addPhysics emstandard_opt3                     # Electromagnetic model
     21/physic/addPhysics standard_opt3                       # Electromagnetic model
    2222/physic/addPhysics elastic                             # Hadronic elastic model
    2323/physic/addPhysics binary                              # Hadronic inelastic model
    2424/physic/addPhysics local_ion_ion_inelastic             # Hadronic inelastic model for ions (local physic list)
     25
     26
    2527
    2628##########################
     
    3234# Visualisation
    3335#
    34 /vis/scene/create
    35 #/vis/open OGLIQt # only if QT library are installed
    36 /vis/open OGLIX
     36/vis/open OGL
    3737/vis/viewer/flush
    3838/vis/viewer/set/viewpointThetaPhi 30 140 deg
    3939/vis/viewer/zoom 1
    4040/vis/viewer/pan -10  0 cm
    41 /tracking/storeTrajectory 1
    42 #/vis/scene/endOfEventAction accumulate
    43 /vis/scene/endOfEventAction accumulate -1
    44 /vis/viewer/update
     41/vis/scene/add/trajectories
     42/vis/scene/endOfEventAction accumulate
    4543
    4644##########################
     
    6967# Start of the run
    7068#
    71 /run/beamOn 10
     69# If secondaries dose/fluence are needed
     70#/analysis/secondaries true
     71
     72/run/beamOn 100
     73
     74
  • trunk/examples/advanced/hadrontherapy/include/CVS/Entries

    r1230 r1313  
    1 /Decay.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    2 /HadrontherapyAnalysisFileMessenger.hh/1.4/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
    3 /HadrontherapyAnalysisManager.hh/1.16/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    4 /HadrontherapyDetectorConstruction.hh/1.24/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
    5 /HadrontherapyDetectorHit.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    6 /HadrontherapyDetectorMessenger.hh/1.15/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
    7 /HadrontherapyDetectorROGeometry.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    8 /HadrontherapyDetectorSD.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    9 /HadrontherapyDummySD.hh/1.6/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    10 /HadrontherapyEventAction.hh/1.15/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    11 /HadrontherapyEventActionMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    12 /HadrontherapyGeometryController.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    13 /HadrontherapyGeometryMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    14 /HadrontherapyInteractionParameters.hh/1.5/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
    15 /HadrontherapyMatrix.hh/1.6/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
    16 /HadrontherapyModulator.hh/1.5/Thu Jun 29 15:58:08 2006//Tgeant4-09-03
    17 /HadrontherapyParameterMessenger.hh/1.5/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
    18 /HadrontherapyParticles.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    19 /HadrontherapyPhysicsList.hh/1.21/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
    20 /HadrontherapyPhysicsListMessenger.hh/1.9/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    21 /HadrontherapyPrimaryGeneratorAction.hh/1.17/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    22 /HadrontherapyPrimaryGeneratorMessenger.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    23 /HadrontherapyRunAction.hh/1.14/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    24 /HadrontherapyStepMax.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    25 /HadrontherapyStepMaxMessenger.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    26 /HadrontherapySteppingAction.hh/1.16/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    27 /IAEADetectorConstruction.hh/1.5/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    28 /IAEADetectorMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    29 /IAEAScoreWriter.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    30 /LocalINCLIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    31 /LocalIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    32 /PassiveProtonBeamLine.hh/1.5/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
    33 /PassiveProtonBeamLineMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
     1/Decay.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     2/HadrontherapyAnalysisFileMessenger.hh/1.6/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     3/HadrontherapyAnalysisManager.hh/1.20/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     4/HadrontherapyDetectorConstruction.hh/1.28/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     5/HadrontherapyDetectorHit.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     6/HadrontherapyDetectorMessenger.hh/1.18/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     7/HadrontherapyDetectorROGeometry.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     8/HadrontherapyDetectorSD.hh/1.3/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     9/HadrontherapyDummySD.hh/1.6/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     10/HadrontherapyEventAction.hh/1.16/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     11/HadrontherapyEventActionMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     12/HadrontherapyGeometryController.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     13/HadrontherapyGeometryMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     14/HadrontherapyInteractionParameters.hh/1.8/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     15/HadrontherapyMatrix.hh/1.12/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     16/HadrontherapyModulator.hh/1.5/Thu Jun 29 15:58:08 2006//Tgeant4-09-04-beta-cand-00
     17/HadrontherapyParameterMessenger.hh/1.5/Fri Jan  8 13:32:05 2010//Tgeant4-09-04-beta-cand-00
     18/HadrontherapyParticles.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     19/HadrontherapyPhysicsList.hh/1.22/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     20/HadrontherapyPhysicsListMessenger.hh/1.10/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     21/HadrontherapyPrimaryGeneratorAction.hh/1.18/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     22/HadrontherapyPrimaryGeneratorMessenger.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     23/HadrontherapyRunAction.hh/1.16/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     24/HadrontherapyStepMax.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     25/HadrontherapyStepMaxMessenger.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     26/HadrontherapySteppingAction.hh/1.16/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     27/IAEADetectorConstruction.hh/1.5/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     28/IAEADetectorMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     29/IAEAScoreWriter.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     30/LocalINCLIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     31/LocalIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00
     32/PassiveProtonBeamLine.hh/1.6/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
     33/PassiveProtonBeamLineMessenger.hh/1.3/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00
    3434D
  • trunk/examples/advanced/hadrontherapy/include/CVS/Tag

    r1230 r1313  
    1 Ngeant4-09-03
     1Ngeant4-09-04-beta-cand-00
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisFileMessenger.hh

    r1230 r1313  
    3030#define HadrontherapyAnalysisFileMessenger_h 1
    3131
    32 #ifdef ANALYSIS_USE
    3332
    3433#include "G4UImessenger.hh"
     
    3635
    3736class HadrontherapyAnalysisManager; ///< Provides SetanalysisFileName()
    38 class G4UIcmdWithAString; ///< Provides possibility to add commands
     37class G4UIcmdWithAString;
     38class G4UIcmdWithABool;
    3939
    4040/**
     
    6868        * Constructor requires command name and messenger class(this).
    6969        */
    70     G4UIcmdWithAString* FileNameCmd;
     70    G4UIcmdWithABool *secondariesCmd;
     71#ifdef G4ANALYSIS_USE_ROOT
     72    G4UIcmdWithAString *FileNameCmd;
     73#endif
    7174};
    7275
    7376#endif
    74 #endif
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisManager.hh

    r1230 r1313  
    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 // HadrontherapyAnalysisManager.hh; May 2005
    27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
     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        // HadrontherapyAnalysisManager.hh; May 2005
     27        // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
    2828
    2929#ifndef HADRONTHERAPYANALYSISMANAGER_HH
     
    3232#include "globals.hh"
    3333
    34 #ifdef ANALYSIS_USE ///< If we use analysis
    35 
    36 #ifdef G4ANALYSIS_USE ///< If analysis is done via AIDA
    37 #include <AIDA/AIDA.h>
    38 
    39 namespace AIDA{
    40   class ITree;
    41   class IAnalysisFactory;
    42   class ITreeFactory;
    43 }
    44 #endif
    4534
    4635#ifdef G4ANALYSIS_USE_ROOT ///< If analysis is done directly with ROOT
     
    5039#include "TH1F.h"
    5140#endif
    52 
    5341/**
    5442 * Messenger class for analysis-settings for HadronTherapyAnalysisManager
     
    6452        /**
    6553         * Analysis manager is a singleton object (there is only one instance).
    66          * The pointer to this object is available through the use of the method getInstance();
     54         * The pointer to this object is available through the use of the method GetInstance();
    6755         *
    68          * @see getInstance
    69          */
    70   HadrontherapyAnalysisManager();
    71  
     56         * @see GetInstance
     57         */
     58        HadrontherapyAnalysisManager();
     59       
    7260public:
    73   ~HadrontherapyAnalysisManager();
    74 
    75   /**
    76    * Get the pointer to the analysis manager.
    77    */
    78   static HadrontherapyAnalysisManager* getInstance();
    79 
    80   /**
    81   * Book the histograms and ntuples in an AIDA or ROOT file.
    82   */
    83   void book();
    84   /**
    85    * Set name for the analysis file .root (used by macro)
    86    */
    87   void SetAnalysisFileName(G4String);
    88  
    89   /**
    90   * Fill the ntuple with the energy deposit in the phantom
    91   */
    92   void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId,
    93                          G4double energyDeposit);
    94 
    95   void BraggPeak(G4int, G4double); ///< Fill 1D histogram with the Bragg peak in the phantom
    96 
    97   void SecondaryProtonEnergyDeposit(G4int slice, G4double energy);
    98   ///< Fill 1D histogram with the energy deposit of secondary protons
    99 
    100    void SecondaryNeutronEnergyDeposit(G4int slice, G4double energy);
    101   ///< Fill 1D histogram with the energy deposit of secondary neutrons
    102 
    103   void SecondaryAlphaEnergyDeposit(G4int slice, G4double energy);
    104   ///< Fill 1D histogram with the energy deposit of secondary alpha particles
    105 
    106   void SecondaryGammaEnergyDeposit(G4int slice, G4double energy);
    107   ///< Fill 1D histogram with the energy deposit of secondary gamma
    108 
    109   void SecondaryElectronEnergyDeposit(G4int slice, G4double energy);
    110   ///< Fill 1D histogram with the energy deposit of secondary electrons
    111 
    112   void SecondaryTritonEnergyDeposit(G4int slice, G4double energy);
    113   ///< Fill 1D histogram with the energy deposit of secondary tritons
    114 
    115   void SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy);
    116   ///< Fill 1D histogram with the energy deposit of secondary deuterons
    117 
    118   void SecondaryPionEnergyDeposit(G4int slice, G4double energy);
    119   ///< Fill 1D histogram with the energy deposit of secondary pions
    120 
    121   void electronEnergyDistribution(G4double secondaryParticleKineticEnergy);
    122   ///< Energy distribution of secondary electrons originated in the phantom
    123 
    124   void gammaEnergyDistribution(G4double secondaryParticleKineticEnergy);
    125   ///< Energy distribution of secondary gamma originated in the phantom
    126 
    127   void deuteronEnergyDistribution(G4double secondaryParticleKineticEnergy);
    128   ///< Energy distribution of secondary deuterons originated in the phantom
    129 
    130   void tritonEnergyDistribution(G4double secondaryParticleKineticEnergy);
    131   ///< Energy distribution of secondary tritons originated in the phantom
    132 
    133   void alphaEnergyDistribution(G4double secondaryParticleKineticEnergy);
    134   ///< Energy distribution of secondary alpha originated in the phantom
    135 
    136   void heliumEnergy(G4double secondaryParticleKineticEnergy);
    137   ///< Energy distribution of the helium (He3 and alpha) particles after the phantom
    138 
    139   void hydrogenEnergy(G4double secondaryParticleKineticEnergy);
    140   ///< Energy distribution of the hydrogen (proton, d, t) particles after the phantom
    141 
    142   void fillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ);
    143   ///< Energy ntuple
    144 
    145   void genericIonInformation(G4int, G4double, G4int, G4double);
    146 
    147   void ThintargetBeamDisp(G4double,G4double);
    148 
    149   void startNewEvent();
    150   ///< Tell the analysis manager that a new event is starting
    151 
    152   void setGeometryMetaData(G4double, G4double, G4double);
    153   ///< from the detector construction information about the geometry can be written as metadata
    154 
    155   void setBeamMetaData(G4double, G4double);
    156   ///< metadata about the beam can be written this way
    157 
    158   void finish();
    159   ///< Close the .hbk file with the histograms and the ntuples
    160 
    161 void flush();
    162 
    163 #ifdef G4ANALYSIS_USE_ROOT
     61        ~HadrontherapyAnalysisManager();
     62       
     63        /**
     64         * Get the pointer to the analysis manager.
     65         */
     66        static HadrontherapyAnalysisManager* GetInstance();
     67
     68#ifdef G4ANALYSIS_USE_ROOT
     69         /**
     70         * Clear analysis manager heap.
     71         */
     72        void Clear();
     73
     74        /**
     75         * Book the histograms and ntuples in an AIDA or ROOT file.
     76         */
     77        void book();
     78        /**
     79         * Set name for the analysis file .root (used by macro)
     80         */
     81        void SetAnalysisFileName(G4String);
     82       
     83        /**
     84         * Fill the ntuple with the energy deposit in the phantom
     85         */
     86        void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId,
     87                                                   G4double energyDeposit);
     88       
     89        void BraggPeak(G4int, G4double); ///< Fill 1D histogram with the Bragg peak in the phantom
     90       
     91        void SecondaryProtonEnergyDeposit(G4int slice, G4double energy);
     92                ///< Fill 1D histogram with the energy deposit of secondary protons
     93       
     94        void SecondaryNeutronEnergyDeposit(G4int slice, G4double energy);
     95                ///< Fill 1D histogram with the energy deposit of secondary neutrons
     96       
     97        void SecondaryAlphaEnergyDeposit(G4int slice, G4double energy);
     98                ///< Fill 1D histogram with the energy deposit of secondary alpha particles
     99       
     100        void SecondaryGammaEnergyDeposit(G4int slice, G4double energy);
     101                ///< Fill 1D histogram with the energy deposit of secondary gamma
     102       
     103        void SecondaryElectronEnergyDeposit(G4int slice, G4double energy);
     104                ///< Fill 1D histogram with the energy deposit of secondary electrons
     105       
     106        void SecondaryTritonEnergyDeposit(G4int slice, G4double energy);
     107                ///< Fill 1D histogram with the energy deposit of secondary tritons
     108       
     109        void SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy);
     110                ///< Fill 1D histogram with the energy deposit of secondary deuterons
     111       
     112        void SecondaryPionEnergyDeposit(G4int slice, G4double energy);
     113                ///< Fill 1D histogram with the energy deposit of secondary pions
     114       
     115        void electronEnergyDistribution(G4double secondaryParticleKineticEnergy);
     116                ///< Energy distribution of secondary electrons originated in the phantom
     117       
     118        void gammaEnergyDistribution(G4double secondaryParticleKineticEnergy);
     119                ///< Energy distribution of secondary gamma originated in the phantom
     120       
     121        void deuteronEnergyDistribution(G4double secondaryParticleKineticEnergy);
     122                ///< Energy distribution of secondary deuterons originated in the phantom
     123       
     124        void tritonEnergyDistribution(G4double secondaryParticleKineticEnergy);
     125                ///< Energy distribution of secondary tritons originated in the phantom
     126       
     127        void alphaEnergyDistribution(G4double secondaryParticleKineticEnergy);
     128                ///< Energy distribution of secondary alpha originated in the phantom
     129       
     130        void heliumEnergy(G4double secondaryParticleKineticEnergy);
     131                ///< Energy distribution of the helium (He3 and alpha) particles after the phantom
     132       
     133        void hydrogenEnergy(G4double secondaryParticleKineticEnergy);
     134                ///< Energy distribution of the hydrogen (proton, d, t) particles after the phantom
     135       
     136                //Kinetic energy by voxel, mass number A and atomic number Z.
     137        void FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy);
     138       
     139                //Kinetic energy by voxel, mass number A and atomic number Z of only primary particles
     140        void FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy);
     141       
     142                ///< Energy by voxel, mass number A and atomic number Z.
     143        void FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence);
     144       
     145        void FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ);
     146                ///< Energy ntuple
     147       
     148        void FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD);
     149                ///< let ntuple
     150
     151        void genericIonInformation(G4int, G4double, G4int, G4double);
     152       
     153        void ThintargetBeamDisp(G4double,G4double);
     154       
     155        void startNewEvent();
     156                ///< Tell the analysis manager that a new event is starting
     157       
     158        void setGeometryMetaData(G4double, G4double, G4double);
     159                ///< from the detector construction information about the geometry can be written as metadata
     160       
     161        void setBeamMetaData(G4double, G4double);
     162                ///< metadata about the beam can be written this way
     163       
     164        void flush();
     165                ///< Close the .hbk file with the histograms and the ntuples
    164166private:
    165   TH1F *createHistogram1D(const TString name, const TString title, int bins, double xmin, double xmax) {
    166     TH1F *histo = new TH1F(name, title, bins, xmin, xmax);
    167     histo->SetLineWidth(2);
    168     return histo;
    169   }
    170 #endif
    171 
     167        TH1F *createHistogram1D(const TString name, const TString title, int bins, double xmin, double xmax) {
     168                TH1F *histo = new TH1F(name, title, bins, xmin, xmax);
     169                histo->SetLineWidth(2);
     170                return histo;
     171        }
     172       
    172173private:
    173   static HadrontherapyAnalysisManager* instance;
    174   HadrontherapyAnalysisFileMessenger* fMess;
    175   G4String analysisFileName;
    176 #ifdef G4ANALYSIS_USE
    177   AIDA::IAnalysisFactory* aFact;
    178   AIDA::ITree* theTree;
    179   AIDA::IHistogramFactory *histFact;
    180   AIDA::ITupleFactory *tupFact;
    181   AIDA::IHistogram1D *h1;
    182   AIDA::IHistogram1D *h2;
    183   AIDA::IHistogram1D *h3;
    184   AIDA::IHistogram1D *h4;
    185   AIDA::IHistogram1D *h5;
    186   AIDA::IHistogram1D *h6;
    187   AIDA::IHistogram1D *h7;
    188   AIDA::IHistogram1D *h8;
    189   AIDA::IHistogram1D *h9;
    190   AIDA::IHistogram1D *h10;
    191   AIDA::IHistogram1D *h11;
    192   AIDA::IHistogram1D *h12;
    193   AIDA::IHistogram1D *h13;
    194   AIDA::IHistogram1D *h14;
    195   AIDA::IHistogram1D *h15;
    196   AIDA::IHistogram1D *h16;
    197   AIDA::ITuple *ntuple;
    198   AIDA::ITuple *ionTuple;
    199   AIDA::ITuple *fragmentTuple;
    200 #endif
    201 #ifdef G4ANALYSIS_USE_ROOT
    202   TFile *theTFile;
    203   TH1F *histo1;
    204   TH1F *histo2;
    205   TH1F *histo3;
    206   TH1F *histo4;
    207   TH1F *histo5;
    208   TH1F *histo6;
    209   TH1F *histo7;
    210   TH1F *histo8;
    211   TH1F *histo9;
    212   TH1F *histo10;
    213   TH1F *histo11;
    214   TH1F *histo12;
    215   TH1F *histo13;
    216   TH1F *histo14;
    217   TH1F *histo15;
    218   TH1F *histo16;
    219  
    220   TNtuple *theROOTNtuple;
    221   TNtuple *theROOTIonTuple;
    222   TNtuple *fragmentNtuple; // fragments
    223   TNtuple *metaData;
    224 #endif
    225   G4long eventCounter;      // Simulation metadata
    226   G4double detectorDistance;
    227   G4double phantomDepth;
    228   G4double beamEnergy;
    229   G4double energyError;
    230   G4double phantomCenterDistance;
     174#endif
     175        static HadrontherapyAnalysisManager* instance;
     176        HadrontherapyAnalysisFileMessenger* fMess;
     177#ifdef G4ANALYSIS_USE_ROOT
     178        G4String analysisFileName;
     179        TFile *theTFile;
     180        TH1F *histo1;
     181        TH1F *histo2;
     182        TH1F *histo3;
     183        TH1F *histo4;
     184        TH1F *histo5;
     185        TH1F *histo6;
     186        TH1F *histo7;
     187        TH1F *histo8;
     188        TH1F *histo9;
     189        TH1F *histo10;
     190        TH1F *histo11;
     191        TH1F *histo12;
     192        TH1F *histo13;
     193        TH1F *histo14;
     194        TH1F *histo15;
     195        TH1F *histo16;
     196       
     197        TNtuple *kinFragNtuple;
     198        TNtuple *kineticEnergyPrimaryNtuple;
     199
     200        // ntuple containing the fluence of all the particle in any voxel
     201        TNtuple *doseFragNtuple;
     202
     203        // ntuple containing the fluence of all the particle in any voxel
     204        TNtuple *fluenceFragNtuple;
     205       
     206        // ntuple containing the fluence of all the particle in any voxel
     207        TNtuple *letFragNtuple;
     208
     209        TNtuple *theROOTNtuple;
     210        TNtuple *theROOTIonTuple;
     211        TNtuple *fragmentNtuple; // fragments
     212        TNtuple *metaData;
     213        G4long eventCounter;      // Simulation metadata
     214        G4double detectorDistance;
     215        G4double phantomDepth;
     216        G4double beamEnergy;
     217        G4double energyError;
     218        G4double phantomCenterDistance;
     219#endif
    231220};
    232221#endif
    233222
    234 #endif
    235 
     223
     224
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorConstruction.hh

    r1230 r1313  
    5656  void ConstructPhantom();
    5757  void ConstructDetector();
    58   void ConstructSensitiveDetector(G4ThreeVector position_respect_to_WORLD);
    59  
     58  void ConstructSensitiveDetector(G4ThreeVector positionToWORLD);
     59  void ParametersCheck();
     60
    6061public:
    6162// Get detector position relative to WORLD
     
    6566  }
    6667/////////////////////////////////////////////////////////////////////////////
    67 // Get displacement between phantom and detector by detector position, phantom and detector sizes
     68// Get displacement between phantom and detector by detector position (center of), phantom (center of) and detector sizes
    6869inline G4ThreeVector GetDetectorToPhantomPosition()
    6970{
    70     return G4ThreeVector(phantomSizeX - detectorSizeX + detectorPosition.getX(),
    71                          phantomSizeY - detectorSizeY + detectorPosition.getY(),
    72                          phantomSizeZ - detectorSizeZ + detectorPosition.getZ()
     71    return G4ThreeVector(phantomSizeX/2 - detectorSizeX/2 + detectorPosition.getX(),
     72                         phantomSizeY/2 - detectorSizeY/2 + detectorPosition.getY(),
     73                         phantomSizeZ/2 - detectorSizeZ/2 + detectorPosition.getZ()
    7374                          );
    7475}
     
    7980  {
    8081          // Adjust detector position
    81           detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX + detectorSizeX);
    82           detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY + detectorSizeY);
    83           detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ + detectorSizeZ);
     82          detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX/2 + detectorSizeX/2);
     83          detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY/2 + detectorSizeY/2);
     84          detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ/2 + detectorSizeZ/2);
    8485     
    85       if (detectorPhysicalVolume) detectorPhysicalVolume -> SetTranslation(detectorPosition);
     86    //G4cout << "*************** DetectorToPhantomPosition " << detectorToPhantomPosition/cm << "\n";
     87    //G4cout << "*************** DetectorPosition " << detectorPosition/cm << "\n";
    8688  }
    8789/////////////////////////////////////////////////////////////////////////////
    8890// Check whether detector is inside phantom
    89 inline bool IsInside(G4double detectorHalfX,
    90                      G4double detectorHalfY,
    91                      G4double detectorHalfZ,
    92                      G4double phantomHalfX,
    93                      G4double phantomHalfY,
    94                      G4double phantomHalfZ,
     91inline bool IsInside(G4double detectorX,
     92                     G4double detectorY,
     93                     G4double detectorZ,
     94                     G4double phantomX,
     95                     G4double phantomY,
     96                     G4double phantomZ,
    9597                     G4ThreeVector detectorToPhantomPosition)
    9698{
    9799// Dimensions check... X Y and Z
    98100// Firstly check what dimension we are modifying
    99         if (detectorHalfX > 0. && phantomHalfX > 0. && detectorToPhantomPosition.getX() >=0.)
    100101        {
    101             if (detectorHalfX > phantomHalfX)
     102            if (detectorX > phantomX)
    102103                 {
    103104                    G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
    104105                    return false;
    105106                 }
    106             if ( 2*(phantomHalfX - detectorHalfX) < detectorToPhantomPosition.getX())
     107            if ( (phantomX - detectorX) < detectorToPhantomPosition.getX())
    107108                 {
    108109                    G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl;
     
    111112        }
    112113
    113         if (detectorHalfY > 0. && phantomHalfY > 0.&& detectorToPhantomPosition.getY() >=0.)
    114114        {
    115             if (detectorHalfY > phantomHalfY)
     115            if (detectorY > phantomY)
    116116                 {
    117117                    G4cout << "Error: Detector Y dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
    118118                    return false;
    119119                 }
    120             if ( 2*(phantomHalfY - detectorHalfY) < detectorToPhantomPosition.getY())
     120            if ( (phantomY - detectorY) < detectorToPhantomPosition.getY())
    121121             {
    122122                   G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl;
     
    125125        }                       
    126126
    127         if (detectorHalfZ > 0. && phantomHalfZ > 0.&& detectorToPhantomPosition.getZ() >=0.)
    128127        {
    129             if (detectorHalfZ > phantomHalfZ)
     128            if (detectorZ > phantomZ)
    130129                 {
    131130                    G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
    132131                    return false;
    133132                 }
    134             if ( 2*(phantomHalfZ - detectorHalfZ) < detectorToPhantomPosition.getZ())
     133            if ( (phantomZ - detectorZ) < detectorToPhantomPosition.getZ())
    135134             {
    136135                   G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl;
     
    138137             }
    139138        }
    140 /*
    141     G4cout << "Displacement between Phantom and Detector is: ";
    142     G4cout << "DX= "<< G4BestUnit(detectorToPhantomPosition.getX(),"Length") <<
    143               "DY= "<< G4BestUnit(detectorToPhantomPosition.getY(),"Length") <<
    144               "DZ= "<< G4BestUnit(detectorToPhantomPosition.getZ(),"Length") << G4endl;
    145 */
     139
    146140        return true;
    147141}
    148142/////////////////////////////////////////////////////////////////////////////
    149143
    150   G4bool SetNumberOfVoxelBySize(G4double sizeX, G4double sizeY, G4double sizeZ);
    151   G4bool SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ);
    152   G4bool SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ);
    153   G4bool SetPhantomPosition(G4ThreeVector);
    154   G4bool SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition);
     144  G4bool  SetPhantomMaterial(G4String material);
     145  void SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ);
     146  void SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ);
     147  void SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ);
     148  void SetPhantomPosition(G4ThreeVector);
     149  void SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition);
     150  void UpdateGeometry();
     151  void PrintParameters();
    155152  G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;}
    156153
     
    169166  HadrontherapyMatrix*             matrix;
    170167
    171   G4VPhysicalVolume* phantomPhysicalVolume;
    172   G4LogicalVolume*   phantomLogicalVolume;
    173   G4LogicalVolume*   detectorLogicalVolume;
    174   G4VPhysicalVolume* detectorPhysicalVolume;
     168  G4Box *phantom , *detector;
     169  G4LogicalVolume *phantomLogicalVolume, *detectorLogicalVolume;
     170  G4VPhysicalVolume *phantomPhysicalVolume, *detectorPhysicalVolume;
    175171 
    176172  G4double phantomSizeX;
     
    192188  G4int numberOfVoxelsAlongZ; 
    193189
    194   G4Box* phantom;
    195   G4Box* detector;
     190  G4double volumeOfVoxel, massOfVoxel;
    196191
     192  G4Material *phantomMaterial, *detectorMaterial;
     193  G4Region* aRegion;
    197194};
    198195#endif
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorMessenger.hh

    r1230 r1313  
    3535class HadrontherapyDetectorConstruction;
    3636class G4UIdirectory;
    37 class G4UIcmdWithADoubleAndUnit;
    38 class G4UIcmdWithAString;
    3937class G4UIcmdWith3VectorAndUnit;
     38class G4UIcmdWithoutParameter;
     39class G4UIcmdWithAString;       
    4040
    4141class HadrontherapyDetectorMessenger: public G4UImessenger
     
    5454  G4UIdirectory *changeThePhantomDir,  *changeTheDetectorDir;
    5555
     56  G4UIcmdWithoutParameter   *updateCmd;
     57  G4UIcmdWithAString        *changeThePhantomMaterialCmd;
    5658  G4UIcmdWith3VectorAndUnit *changeThePhantomSizeCmd,
    5759                            *changeThePhantomPositionCmd,
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorSD.hh

    r1230 r1313  
    4343  ~HadrontherapyDetectorSD();
    4444
     45    std::ofstream ofs;
    4546  void Initialize(G4HCofThisEvent*);
    4647 
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventAction.hh

    r1230 r1313  
    5959  G4String drawFlag; //Visualisation flag
    6060  G4int hitsCollectionID;
    61   HadrontherapyMatrix *matrix;
     61  //HadrontherapyMatrix *matrix;
    6262  G4int printModulo; 
    6363  HadrontherapyEventActionMessenger* pointerEventMessenger;
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyInteractionParameters.hh

    r1230 r1313  
    3434#include "G4NistElementBuilder.hh"
    3535
     36#ifdef G4ANALYSIS_USE_ROOT
     37#include "TROOT.h"
     38#include "TCanvas.h"
     39#include "TFile.h"
     40#include "TH1F.h"
     41#include "TH2F.h"
     42#include "TGraph.h"
     43#include "TLegend.h"
     44#include "TLegendEntry.h"
     45#include "TStyle.h"
     46#endif
     47
    3648class HadrontherapyDetectorConstruction;
    3749class HadrontherapyParameterMessenger;
     50class G4ParticleDefinition;
     51class G4Material;
     52
    3853class HadrontherapyInteractionParameters : public G4EmCalculator
    3954{
    4055public:
    4156
    42     HadrontherapyInteractionParameters();
    43         ~HadrontherapyInteractionParameters();
     57    HadrontherapyInteractionParameters(G4bool);
     58    ~HadrontherapyInteractionParameters();
    4459
    45 // Get data for Mass SP (MeV*cm2/g)   
     60// Get data for Mass SP    
    4661// G4NistMaterialBuilder class materials
    4762// User must provide: material kinetic energy lower limit, kinetic energy upper limit, number of points to retrieve,
    4863// [particle], [output filename].
    4964
    50     bool GetStoppingTable (const G4String& vararg);
     65    G4bool GetStoppingTable (const G4String& vararg);
     66    G4double GetStopping (G4double energy,
     67                          const G4ParticleDefinition*,
     68                          const G4Material*,
     69                          G4double density = 0.);
     70#ifdef G4ANALYSIS_USE_ROOT
     71    void PlotStopping(const G4String&);
     72#endif
    5173    void ListOfNistMaterials (const G4String& vararg);
    5274    void BeamOn();
     
    5577private:
    5678    G4Material* GetNistMaterial(G4String material);
    57 
    5879    G4NistElementBuilder* nistEle;
    5980    G4NistMaterialBuilder* nistMat;
    60     G4double kinEmin, kinEmax, npoints;
    61     G4String particle, material, filename;
    6281    std::ofstream outfile;
    6382    std::ostream data;
    6483    G4Material* Pmaterial;
    65     G4double density;
    66     G4EmCalculator* emCal;
    6784    HadrontherapyParameterMessenger* pMessenger;
    6885    bool beamFlag;
     86
     87#ifdef G4ANALYSIS_USE_ROOT
     88    TCanvas *theRootCanvas;
     89    TGraph *theRootGraph;
     90    TAxis *axisX, *axisY;
     91#endif
     92    G4double kinEmin, kinEmax, npoints;
     93    G4String particle, material, filename;
     94    G4double dedxtot, density;
     95    std::vector<G4double> energy;
     96    std::vector<G4double> massDedx;
     97
    6998};
    7099#endif
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyMatrix.hh

    r1230 r1313  
    2929#ifndef HadrontherapyMatrix_H
    3030#define HadrontherapyMatrix_H 1
    31 
     31#include <G4ParticleDefinition.hh>
    3232#include "globals.hh"
    3333#include <vector>
     34#include <fstream>
    3435
    3536// The information: energy deposit and position in the phantom
    3637// is stored in a matrix
    3738
     39// type struct useful to store nucludes data
     40struct ion
     41 {
     42     G4bool isPrimary;   // true if particle is primary
     43     G4int PDGencoding;  // Particle data group id for the particle
     44     //G4String extName; //  AZ[excitation energy]: like He3[1277.4], He4[0.0], Li7[231.4], ...
     45     G4String name;      // simple name without excitation energy: He3, He4, Li7, ...
     46     G4int len;          // name length
     47     G4int Z;            // atomic number
     48     G4int A;            // mass number
     49     G4double *dose;     // pointer to dose matrix
     50     unsigned int    *fluence;  // pointer to fluence matrix
     51     //friend bool operator<(const ion& a, const ion& b) {return (a.Z == b.Z) ? b.A < a.A : b.Z < a.Z ;}
     52     G4bool operator<(const ion& a) const{return (this->Z == a.Z) ? this-> A < a.A : this->Z < a.Z ;}
     53 };
     54
    3855class HadrontherapyMatrix
    3956{
    4057private:
    41   HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ); //<--- this is supposed to be a singleton
     58  HadrontherapyMatrix(G4int numberOfVoxelAlongX,
     59                      G4int numberOfVoxelAlongY,
     60                      G4int numberOfVoxelAlongZ,
     61                      G4double massOfVoxel); //< this is supposed to be a singleton
     62
    4263
    4364public:
    4465
    4566  ~HadrontherapyMatrix();
    46 // Get object instance only
    47   static HadrontherapyMatrix* getInstance();
    48 // Make & Get instance
    49   static HadrontherapyMatrix* getInstance(G4int nX, G4int nY, G4int nZ);
    50  
    51   void flush();
    52  
     67  // Get object instance only
     68  static HadrontherapyMatrix* GetInstance();
     69  // Make & Get instance
     70  static HadrontherapyMatrix* GetInstance(G4int nX, G4int nY, G4int nZ, G4double mass);
     71
     72  static G4bool secondaries;
     73  // Full list of generated nuclides
     74  void PrintNuclides();
     75  // Hit array marker (useful to avoid multiple counts of fluence)
     76  void ClearHitTrack();
     77  G4int* GetHitTrack(G4int i, G4int j, G4int k);
     78
     79  // All the elements of the matrix are initialised to zero
    5380  void Initialize();
    54   // All the elements of the matrix are initialised to zero
    55    
     81  void Clear();
     82  // Fill DOSE/fluence matrix for particle:
     83  // if fluence parameter is true then fluence at voxel (i, j, k) is increased
     84  // else energyDeposit fill the dose matrix for voxel (i,j,k)
     85  G4bool Fill(G4int, G4ParticleDefinition* particleDef, G4int i, G4int j, G4int k, G4double energyDeposit, G4bool fluence=false);
     86
     87  // Fill TOTAL DOSE matrix for primary particles only
    5688  void Fill(G4int i, G4int j, G4int k, G4double energyDeposit);
    5789  // The matrix is filled with the energy deposit
    5890  // in the element corresponding to the voxel of the phantom where
    5991  // the energy deposit was registered
    60  
    61   void TotalEnergyDeposit();
     92 
    6293  // Store the information of the matrix in a ntuple and in
    6394  // a 1D Histogram
    64  
    65   inline G4int Index(G4int i, G4int j, G4int k){ return (i * numberVoxelY + j) * numberVoxelZ + k; }
    66   // Get a unique index from a three dimensional voxel information
     95  void TotalEnergyDeposit();
     96   
     97  // Store single matrix data to filename
     98  void StoreMatrix(G4String file, void* data,size_t psize);
     99  // Store all fluence data to filenames
     100  void StoreFluenceData();
     101  // Store all dose data to filenames
     102  void StoreDoseData();
    67103
     104  // Store all data (except the total dose) to ONE filename
     105  void StoreDoseFluenceAscii();
     106
     107#ifdef G4ANALYSIS_USE_ROOT
     108  void StoreDoseFluenceRoot();
     109#endif
     110
     111  inline G4int Index(G4int i, G4int j, G4int k) { return (i * numberOfVoxelAlongY + j) * numberOfVoxelAlongZ + k; }
     112  // Get a unique index from  a three dimensional one
     113
     114  G4double * GetMatrix(){return matrix;}
     115
     116  G4int GetNvoxel(){return numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;}
     117  // Total number of voxels read only access 
     118  G4int GetNumberOfVoxelAlongX(){return numberOfVoxelAlongX;}
     119  G4int GetNumberOfVoxelAlongY(){return numberOfVoxelAlongY;}
     120  G4int GetNumberOfVoxelAlongZ(){return numberOfVoxelAlongZ;}
    68121private:
    69122
    70123  static HadrontherapyMatrix* instance;
    71   G4int numberVoxelX;
    72   G4int numberVoxelY;
    73   G4int numberVoxelZ;
     124  G4int numberOfVoxelAlongX;
     125  G4int numberOfVoxelAlongY;
     126  G4int numberOfVoxelAlongZ;
     127  G4double massOfVoxel;
     128
    74129  G4double* matrix;
     130  G4int* hitTrack;
     131  G4String filename;
     132  std::ofstream ofs;
     133
     134  // Dose&fluence data store
     135  std::vector <ion> ionStore;
     136  // want secondaries?
     137  G4double doseUnit;
    75138};
    76139#endif
     140
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsList.hh

    r1230 r1313  
    5151  void SetCutForElectron(G4double);
    5252  void SetCutForPositron(G4double);
    53 
     53  void SetDetectorCut(G4double cut);
    5454  void AddPhysicsList(const G4String& name);
    5555  void ConstructProcess();
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsListMessenger.hh

    r1230 r1313  
    5858  G4UIcmdWithADoubleAndUnit* protoCutCmd;   
    5959  G4UIcmdWithADoubleAndUnit* allCutCmd;   
     60  G4UIcmdWithADoubleAndUnit* allDetectorCmd;   
    6061  G4UIcmdWithAString*        pListCmd;
    6162  G4UIcmdWithAString* packageListCmd;   
  • trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorAction.hh

    r1230 r1313  
    5757  void SetsigmaMomentumZ(G4double);
    5858  G4double GetmeanKineticEnergy(void);
     59  G4ParticleGun *GetParticleGun(void){return particleGun;}
    5960   
    6061private:
     
    7172
    7273private:
    73   G4ParticleGun*                particleGun;
     74  G4ParticleGun*                          particleGun;
    7475  HadrontherapyPrimaryGeneratorMessenger* gunMessenger;
    75   G4double sigmaX;
     76  G4double                                sigmaX;
    7677};
    7778
  • trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLine.hh

    r1230 r1313  
    116116
    117117private:
    118 
    119   void SetDimensions(); //passive proton line dimensions
     118//passive proton line dimensions
     119  void SetDefaultDimensions();
    120120  void ConstructPassiveProtonBeamLine();
    121121
  • trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLineMessenger.hh

    r1230 r1313  
    2424// ********************************************************************
    2525//
    26 // HadrontherapyDetectorMessenger.hh;
     26// PassiveProtonBeamLineMessenger.hh;
    2727// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
    2828
    29 #ifndef HadrontherapyDetectorMessenger_h
    30 #define HadrontherapyDetectorMessenger_h 1
     29#ifndef PassiveProtonBeamLineMessenger_h
     30#define PassiveProtonBeamLineMessenger_h 1
    3131
    3232#include "globals.hh"
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyAnalysisManager.cc

    r1230 r1313  
    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 // $Id: HadrontherapyAnalisysManager.cc;
    27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
     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        // $Id: HadrontherapyAnalisysManager.cc;
     27        // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
    2828
    2929#include "HadrontherapyAnalysisManager.hh"
     
    3131#include "HadrontherapyAnalysisFileMessenger.hh"
    3232#include <time.h>
    33 #ifdef ANALYSIS_USE
     33
    3434HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::instance = 0;
    3535
    36 #ifdef G4ANALYSIS_USE_ROOT
    37 #undef G4ANALYSIS_USE
    38 #endif
    39 
    40 /////////////////////////////////////////////////////////////////////////////
    41 
    42 #ifdef G4ANALYSIS_USE
    43 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() :
    44   analysisFileName("DoseDistribution.root"), aFact(0), theTree(0), histFact(0), tupFact(0), h1(0), h2(0), h3(0),
    45   h4(0), h5(0), h6(0), h7(0), h8(0), h9(0), h10(0), h11(0), h12(0), h13(0), h14(0), h15(0), h16(0), ntuple(0),
    46   ionTuple(0),
    47   fragmentTuple(0),
    48   eventCounter(0)
    49 {
    50         fMess = new HadrontherapyAnalysisFileMessenger(this);
    51 }
    52 #endif
    53 #ifdef G4ANALYSIS_USE_ROOT
    54 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() :
    55   analysisFileName("DoseDistribution.root"),theTFile(0), histo1(0), histo2(0), histo3(0),
    56   histo4(0), histo5(0), histo6(0), histo7(0), histo8(0), histo9(0), histo10(0), histo11(0), histo12(0), histo13(0), histo14(0), histo15(0), histo16(0),
    57   theROOTNtuple(0),
    58   theROOTIonTuple(0),
    59   fragmentNtuple(0),
    60   metaData(0),
    61   eventCounter(0)
    62 {
    63   fMess = new HadrontherapyAnalysisFileMessenger(this);
     36HadrontherapyAnalysisManager::HadrontherapyAnalysisManager():
     37#ifdef G4ANALYSIS_USE_ROOT
     38analysisFileName("DoseDistribution.root"),theTFile(0), histo1(0), histo2(0), histo3(0),
     39histo4(0), histo5(0), histo6(0), histo7(0), histo8(0), histo9(0), histo10(0), histo11(0), histo12(0), histo13(0), histo14(0), histo15(0), histo16(0),
     40kinFragNtuple(0),
     41kineticEnergyPrimaryNtuple(0),
     42doseFragNtuple(0),
     43fluenceFragNtuple(0),
     44letFragNtuple(0),
     45theROOTNtuple(0),
     46theROOTIonTuple(0),
     47fragmentNtuple(0),
     48metaData(0),
     49eventCounter(0)
     50{
     51    fMess = new HadrontherapyAnalysisFileMessenger(this);
    6452}
    6553#endif
    6654/////////////////////////////////////////////////////////////////////////////
     55
    6756HadrontherapyAnalysisManager::~HadrontherapyAnalysisManager()
    6857{
    69 delete(fMess); //kill the messenger
    70 #ifdef G4ANALYSIS_USE
    71   delete fragmentTuple;
    72   fragmentTuple = 0;
    73 
    74   delete ionTuple;
    75   ionTuple = 0;
    76 
    77   delete ntuple;
    78   ntuple = 0;
    79 
    80   delete h16;
    81   h16 = 0;
    82 
    83   delete h15;
    84   h15 = 0;
    85 
    86   delete h14;
    87   h14 = 0;
    88 
    89   delete h13;
    90   h13 = 0;
    91 
    92   delete h12;
    93   h12 = 0;
    94 
    95   delete h11;
    96   h11 = 0;
    97 
    98   delete h10;
    99   h10 = 0;
    100 
    101   delete h9;
    102   h9 = 0;
    103 
    104   delete h8;
    105   h8 = 0;
    106 
    107   delete h7;
    108   h7 = 0;
    109 
    110   delete h6;
    111   h6 = 0;
    112 
    113   delete h5;
    114   h5 = 0;
    115 
    116   delete h4;
    117   h4 = 0;
    118 
    119   delete h3;
    120   h3 = 0;
    121 
    122   delete h2;
    123   h2 = 0;
    124 
    125   delete h1;
    126   h1 = 0;
    127 
    128   delete tupFact;
    129   tupFact = 0;
    130 
    131   delete histFact;
    132   histFact = 0;
    133 
    134   delete theTree;
    135   theTree = 0;
    136 
    137   delete aFact;
    138   aFact = 0;
     58    delete(fMess);
     59#ifdef G4ANALYSIS_USE_ROOT
     60    Clear();   
    13961#endif
     62}
     63
     64HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::GetInstance()
     65{
     66        if (instance == 0) instance = new HadrontherapyAnalysisManager;
     67        return instance;
     68}
    14069#ifdef G4ANALYSIS_USE_ROOT
    141   delete metaData;
    142   metaData = 0;
    143 
    144   delete fragmentNtuple;
    145   fragmentNtuple = 0;
    146 
    147   delete theROOTIonTuple;
    148   theROOTIonTuple = 0;
    149 
    150   delete theROOTNtuple;
    151   theROOTNtuple = 0;
    152  
    153   delete histo16;
    154   histo14 = 0;
    155 
    156   delete histo15;
    157   histo14 = 0;
    158 
    159   delete histo14;
    160   histo14 = 0;
    161 
    162   delete histo13;
    163   histo13 = 0;
    164 
    165   delete histo12;
    166   histo12 = 0;
    167 
    168   delete histo11;
    169   histo11 = 0;
    170 
    171   delete histo10;
    172   histo10 = 0;
    173 
    174   delete histo9;
    175   histo9 = 0;
    176 
    177   delete histo8;
    178   histo8 = 0;
    179 
    180   delete histo7;
    181   histo7 = 0;
    182 
    183   delete histo6;
    184   histo6 = 0;
    185 
    186   delete histo5;
    187   histo5 = 0;
    188 
    189   delete histo4;
    190   histo4 = 0;
    191 
    192   delete histo3;
    193   histo3 = 0;
    194 
    195   delete histo2;
    196   histo2 = 0;
    197 
    198   delete histo1;
    199   histo1 = 0;
     70void HadrontherapyAnalysisManager::Clear()
     71{
     72    // XXX delete ALL variables!!
     73    // but this seems to be automatically done by
     74    // theTFile->Close() command!
     75    // so we get a *double free or corruption*
     76
     77    delete metaData;
     78    metaData = 0;
     79
     80    delete fragmentNtuple;
     81    fragmentNtuple = 0;
     82
     83    delete theROOTIonTuple;
     84    theROOTIonTuple = 0;
     85
     86    delete theROOTNtuple;
     87    theROOTNtuple = 0;
     88
     89    delete histo16;
     90    histo16 = 0;
     91
     92    delete histo15;
     93    histo15 = 0;
     94
     95    delete histo14;
     96    histo14 = 0;
     97
     98    delete histo13;
     99    histo13 = 0;
     100
     101    delete histo12;
     102    histo12 = 0;
     103
     104    delete histo11;
     105    histo11 = 0;
     106
     107    delete histo10;
     108    histo10 = 0;
     109
     110    delete histo9;
     111    histo9 = 0;
     112
     113    delete histo8;
     114    histo8 = 0;
     115
     116    delete histo7;
     117    histo7 = 0;
     118
     119    delete histo6;
     120    histo6 = 0;
     121
     122    delete histo5;
     123    histo5 = 0;
     124
     125    delete histo4;
     126    histo4 = 0;
     127
     128    delete histo3;
     129    histo3 = 0;
     130
     131    delete histo2;
     132    histo2 = 0;
     133
     134    delete histo1;
     135    histo1 = 0;
     136}
     137/////////////////////////////////////////////////////////////////////////////
     138
     139void HadrontherapyAnalysisManager::SetAnalysisFileName(G4String aFileName)
     140{
     141        this->analysisFileName = aFileName;
     142}
     143
     144        /////////////////////////////////////////////////////////////////////////////
     145void HadrontherapyAnalysisManager::book()
     146{
     147        delete theTFile; // this is similar to theTFile->Close() => delete all associated variables created via new, moreover it delete itself. 
     148
     149        theTFile = new TFile(analysisFileName, "RECREATE");
     150
     151        // Create the histograms with the energy deposit along the X axis
     152        histo1 = createHistogram1D("braggPeak","slice, energy", 400, 0., 80); //<different waterthicknesses are accoutned for in ROOT-analysis stage
     153        histo2 = createHistogram1D("h20","Secondary protons - slice, energy", 400, 0., 400.);
     154        histo3 = createHistogram1D("h30","Secondary neutrons - slice, energy", 400, 0., 400.);
     155        histo4 = createHistogram1D("h40","Secondary alpha - slice, energy", 400, 0., 400.);
     156        histo5 = createHistogram1D("h50","Secondary gamma - slice, energy", 400, 0., 400.);
     157        histo6 = createHistogram1D("h60","Secondary electron - slice, energy", 400, 0., 400.);
     158        histo7 = createHistogram1D("h70","Secondary triton - slice, energy", 400, 0., 400.);
     159        histo8 = createHistogram1D("h80","Secondary deuteron - slice, energy", 400, 0., 400.);
     160        histo9 = createHistogram1D("h90","Secondary pion - slice, energy", 400, 0., 400.);
     161        histo10 = createHistogram1D("h100","Energy distribution of secondary electrons", 70, 0., 70.);
     162        histo11 = createHistogram1D("h110","Energy distribution of secondary photons", 70, 0., 70.);
     163        histo12 = createHistogram1D("h120","Energy distribution of secondary deuterons", 70, 0., 70.);
     164        histo13 = createHistogram1D("h130","Energy distribution of secondary tritons", 70, 0., 70.);
     165        histo14 = createHistogram1D("h140","Energy distribution of secondary alpha particles", 70, 0., 70.);
     166        histo15 = createHistogram1D("heliumEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
     167                70, 0., 500.);
     168        histo16 = createHistogram1D("hydrogenEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
     169                70, 0., 500.);
     170
     171        kinFragNtuple  = new TNtuple("kinFragNtuple",
     172                "Kinetic energy by voxel & fragment",
     173                "i:j:k:A:Z:kineticEnergy");
     174        kineticEnergyPrimaryNtuple= new TNtuple("kineticEnergyPrimaryNtuple",
     175                "Kinetic energy by voxel of primary",
     176                "i:j:k:kineticEnergy");
     177        doseFragNtuple = new TNtuple("doseFragNtuple",
     178                "Energy deposit by voxel & fragment",
     179                "i:j:k:A:Z:energy");
     180
     181        fluenceFragNtuple = new TNtuple("fluenceFragNtuple",
     182                "Fluence by voxel & fragment",
     183                "i:j:k:A:Z:fluence");
     184
     185        letFragNtuple = new TNtuple("letFragNtuple",
     186                "Let by voxel & fragment",
     187                "i:j:k:A:Z:letT:letD");
     188
     189        theROOTNtuple =   new TNtuple("theROOTNtuple",
     190                "Energy deposit by slice",
     191                "i:j:k:energy");
     192
     193        theROOTIonTuple = new TNtuple("theROOTIonTuple",
     194                "Generic ion information",
     195                "a:z:occupancy:energy");
     196
     197        fragmentNtuple =  new TNtuple("fragmentNtuple",
     198                "Fragments",
     199                "A:Z:energy:posX:posY:posZ");
     200
     201        metaData =        new TNtuple("metaData",
     202                "Metadata",
     203                "events:detectorDistance:waterThickness:beamEnergy:energyError:phantomCenterDistance");
     204}
     205
     206        /////////////////////////////////////////////////////////////////////////////
     207void HadrontherapyAnalysisManager::FillEnergyDeposit(G4int i,
     208                                                                                                         G4int j,
     209                                                                                                         G4int k,
     210                                                                                                         G4double energy)
     211{
     212        if (theROOTNtuple) {
     213                theROOTNtuple->Fill(i, j, k, energy);
     214        }
     215}
     216
     217        /////////////////////////////////////////////////////////////////////////////
     218void HadrontherapyAnalysisManager::BraggPeak(G4int slice, G4double energy)
     219{
     220        histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct
     221}
     222
     223        /////////////////////////////////////////////////////////////////////////////
     224void HadrontherapyAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy)
     225{
     226        histo2->Fill(slice, energy);
     227}
     228
     229        /////////////////////////////////////////////////////////////////////////////
     230void HadrontherapyAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy)
     231{
     232        histo3->Fill(slice, energy);
     233}
     234
     235        /////////////////////////////////////////////////////////////////////////////
     236void HadrontherapyAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy)
     237{
     238        histo4->Fill(slice, energy);
     239}
     240
     241        /////////////////////////////////////////////////////////////////////////////
     242void HadrontherapyAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy)
     243{
     244        histo5->Fill(slice, energy);
     245}
     246
     247        /////////////////////////////////////////////////////////////////////////////
     248void HadrontherapyAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy)
     249{
     250        histo6->Fill(slice, energy);
     251}
     252
     253        /////////////////////////////////////////////////////////////////////////////
     254void HadrontherapyAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy)
     255{
     256        histo7->Fill(slice, energy);
     257}
     258
     259        /////////////////////////////////////////////////////////////////////////////
     260void HadrontherapyAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy)
     261{
     262        histo8->Fill(slice, energy);
     263}
     264
     265        /////////////////////////////////////////////////////////////////////////////
     266void HadrontherapyAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy)
     267{
     268        histo9->Fill(slice, energy);
     269}
     270
     271        /////////////////////////////////////////////////////////////////////////////
     272void HadrontherapyAnalysisManager::electronEnergyDistribution(G4double energy)
     273{
     274        histo10->Fill(energy);
     275}
     276
     277        /////////////////////////////////////////////////////////////////////////////
     278void HadrontherapyAnalysisManager::gammaEnergyDistribution(G4double energy)
     279{
     280        histo11->Fill(energy);
     281}
     282
     283        /////////////////////////////////////////////////////////////////////////////
     284void HadrontherapyAnalysisManager::deuteronEnergyDistribution(G4double energy)
     285{
     286        histo12->Fill(energy);
     287}
     288
     289        /////////////////////////////////////////////////////////////////////////////
     290void HadrontherapyAnalysisManager::tritonEnergyDistribution(G4double energy)
     291{
     292        histo13->Fill(energy);
     293}
     294
     295        /////////////////////////////////////////////////////////////////////////////
     296void HadrontherapyAnalysisManager::alphaEnergyDistribution(G4double energy)
     297{
     298        histo14->Fill(energy);
     299}
     300        /////////////////////////////////////////////////////////////////////////////
     301void HadrontherapyAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy)
     302{
     303        histo15->Fill(secondaryParticleKineticEnergy);
     304}
     305
     306        /////////////////////////////////////////////////////////////////////////////
     307void HadrontherapyAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy)
     308{
     309        histo16->Fill(secondaryParticleKineticEnergy);
     310}
     311
     312        /////////////////////////////////////////////////////////////////////////////
     313        // FillKineticFragmentTuple create an ntuple where the voxel indexs, the atomic number and mass and the kinetic
     314        // energy of all the particles interacting with the phantom, are stored
     315void HadrontherapyAnalysisManager::FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy)
     316{
     317    kinFragNtuple -> Fill(i, j, k, A, Z, kinEnergy);
     318}
     319
     320        /////////////////////////////////////////////////////////////////////////////
     321        // FillKineticEnergyPrimaryNTuple creates a ntuple where the voxel indexs and the kinetic
     322        // energies of ONLY primary particles interacting with the phantom, are stored
     323void HadrontherapyAnalysisManager::FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy)
     324{
     325    kineticEnergyPrimaryNtuple -> Fill(i, j, k, kinEnergy);
     326}
     327
     328        /////////////////////////////////////////////////////////////////////////////
     329        // This function is called only if ROOT is activated.
     330        // It is called by the HadrontherapyMatric.cc class file and it is used to create two ntuples containing
     331        // the total energy deposited and the fluence values, in each voxel and per any particle (primary beam
     332        // and secondaries )
     333void HadrontherapyAnalysisManager::FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence)
     334{
     335                // Fill the ntuple containing the voxel, mass and atomic number and the energy deposited
     336    doseFragNtuple ->    Fill( i, j, k, A, Z, energy );
     337       
     338                // Fill the ntuple containing the voxel, mass and atomic number and the fluence
     339        if (i==1 && Z==1) {
     340                fluenceFragNtuple -> Fill( i, j, k, A, Z, fluence );
     341
     342        }
     343}
     344
     345void HadrontherapyAnalysisManager::FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD)
     346{
     347        letFragNtuple -> Fill( i, j, k, A, Z, letT, letD);
     348
     349}
     350        /////////////////////////////////////////////////////////////////////////////
     351void HadrontherapyAnalysisManager::FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ)
     352{
     353        fragmentNtuple->Fill(A, Z, energy, posX, posY, posZ);
     354}
     355
     356        /////////////////////////////////////////////////////////////////////////////
     357void HadrontherapyAnalysisManager::genericIonInformation(G4int a,
     358                                                                                                                 G4double z,
     359                                                                                                                 G4int electronOccupancy,
     360                                                                                                                 G4double energy)
     361{
     362        if (theROOTIonTuple) {
     363                theROOTIonTuple->Fill(a, z, electronOccupancy, energy);
     364        }
     365}
     366
     367        /////////////////////////////////////////////////////////////////////////////
     368void HadrontherapyAnalysisManager::startNewEvent()
     369{
     370        eventCounter++;
     371}
     372        /////////////////////////////////////////////////////////////////////////////
     373void HadrontherapyAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness, G4double phantomCenter)
     374{
     375        this->detectorDistance = endDetectorPosition;
     376        this->phantomDepth = waterThickness;
     377        this->phantomCenterDistance = phantomCenter;
     378}
     379void HadrontherapyAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy)
     380{
     381        this->beamEnergy = meanKineticEnergy;
     382        this->energyError = sigmaEnergy;
     383}
     384/////////////////////////////////////////////////////////////////////////////
     385// Flush data & close the file
     386void HadrontherapyAnalysisManager::flush()
     387{
     388    if (theTFile)
     389    {
     390        theTFile -> Write();
     391        theTFile -> Close();
     392    }
     393    eventCounter = 0;
     394}
     395
    200396#endif
    201 }
    202 /////////////////////////////////////////////////////////////////////////////
    203 HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::getInstance()
    204 {
    205   if (instance == 0) instance = new HadrontherapyAnalysisManager;
    206   return instance;
    207 }
    208 
    209 /////////////////////////////////////////////////////////////////////////////
    210 void HadrontherapyAnalysisManager::SetAnalysisFileName(G4String aFileName)
    211 {
    212   this->analysisFileName = aFileName;
    213 }
    214 
    215 /////////////////////////////////////////////////////////////////////////////
    216 void HadrontherapyAnalysisManager::book()
    217 {
    218 #ifdef G4ANALYSIS_USE
    219   // Build up  the  analysis factory
    220   aFact = AIDA_createAnalysisFactory();
    221   AIDA::ITreeFactory* treeFact = aFact -> createTreeFactory();
    222 
    223   // Create the .hbk or the .root file
    224   G4String fileName = "DoseDistribution.hbk";
    225 
    226   std::string opts = "export=root";
    227 
    228   theTree = treeFact -> create(fileName,"hbook",false,true);
    229   theTree = treeFact -> create(analysisFileName,"ROOT",false,true,opts);
    230 
    231   // Factories are not "managed" by an AIDA analysis system.
    232   // They must be deleted by the AIDA user code.
    233   delete treeFact;
    234 
    235   // Create the histogram and the ntuple factory
    236   histFact = aFact -> createHistogramFactory(*theTree);
    237   tupFact = aFact -> createTupleFactory(*theTree);
    238 
    239   // Create the histograms with the enrgy deposit along the X axis
    240   h1 = histFact -> createHistogram1D("10","slice, energy", 400, 0., 400. );
    241 
    242   h2 = histFact -> createHistogram1D("20","Secondary protons - slice, energy", 400, 0., 400. );
    243 
    244   h3 = histFact -> createHistogram1D("30","Secondary neutrons - slice, energy", 400, 0., 400. );
    245 
    246   h4 = histFact -> createHistogram1D("40","Secondary alpha - slice, energy", 400, 0., 400. );
    247 
    248   h5 = histFact -> createHistogram1D("50","Secondary gamma - slice, energy", 400, 0., 400. );
    249 
    250   h6 = histFact -> createHistogram1D("60","Secondary electron - slice, energy", 400, 0., 400. );
    251 
    252   h7 = histFact -> createHistogram1D("70","Secondary triton - slice, energy", 400, 0., 400. );
    253 
    254   h8 = histFact -> createHistogram1D("80","Secondary deuteron - slice, energy", 400, 0., 400. );
    255 
    256   h9 = histFact -> createHistogram1D("90","Secondary pion - slice, energy", 400, 0., 400. );
    257 
    258   h10 = histFact -> createHistogram1D("100","Energy distribution of secondary electrons", 70, 0., 70. );
    259 
    260   h11 = histFact -> createHistogram1D("110","Energy distribution of secondary photons", 70, 0., 70. );
    261 
    262   h12 = histFact -> createHistogram1D("120","Energy distribution of secondary deuterons", 70, 0., 70. );
    263 
    264   h13 = histFact -> createHistogram1D("130","Energy distribution of secondary tritons", 70, 0., 70. );
    265 
    266   h14 = histFact -> createHistogram1D("140","Energy distribution of secondary alpha particles", 70, 0., 70. );
    267 
    268   h15 = histFact -> createHistogram1D("150","Energy distribution of helium fragments after the phantom", 70, 0., 500.);
    269 
    270   h16 = histFact -> createHistogram1D("160","Energy distribution of hydrogen fragments after the phantom", 70, 0., 500.);
    271 
    272   // Create the ntuple
    273   G4String columnNames = "int i; int j; int k; double energy;";
    274   G4String options = "";
    275   if (tupFact) ntuple = tupFact -> create("1","1",columnNames, options);
    276 
    277   // Create the ntuple
    278   G4String columnNames2 = "int a; double z;  int occupancy; double energy;";
    279   G4String options2 = "";
    280   if (tupFact) ionTuple = tupFact -> create("2","2", columnNames2, options2);
    281 
    282   // Create the fragment ntuple
    283   G4String columnNames3 = "int a; double z; double energy; double posX; double posY; double posZ;";
    284   G4String options3 = "";
    285   if (tupFact) fragmentTuple = tupFact -> create("3","3", columnNames3, options3);
    286 #endif
    287 #ifdef G4ANALYSIS_USE_ROOT
    288   // Use ROOT
    289   theTFile = new TFile(analysisFileName, "RECREATE");
    290 
    291   // Create the histograms with the energy deposit along the X axis
    292   histo1 = createHistogram1D("braggPeak","slice, energy", 400, 0., 27.9); //<different waterthicknesses are accoutned for in ROOT-analysis stage
    293   histo2 = createHistogram1D("h20","Secondary protons - slice, energy", 400, 0., 400.);
    294   histo3 = createHistogram1D("h30","Secondary neutrons - slice, energy", 400, 0., 400.);
    295   histo4 = createHistogram1D("h40","Secondary alpha - slice, energy", 400, 0., 400.);
    296   histo5 = createHistogram1D("h50","Secondary gamma - slice, energy", 400, 0., 400.);
    297   histo6 = createHistogram1D("h60","Secondary electron - slice, energy", 400, 0., 400.);
    298   histo7 = createHistogram1D("h70","Secondary triton - slice, energy", 400, 0., 400.);
    299   histo8 = createHistogram1D("h80","Secondary deuteron - slice, energy", 400, 0., 400.);
    300   histo9 = createHistogram1D("h90","Secondary pion - slice, energy", 400, 0., 400.);
    301   histo10 = createHistogram1D("h100","Energy distribution of secondary electrons", 70, 0., 70.);
    302   histo11 = createHistogram1D("h110","Energy distribution of secondary photons", 70, 0., 70.);
    303   histo12 = createHistogram1D("h120","Energy distribution of secondary deuterons", 70, 0., 70.);
    304   histo13 = createHistogram1D("h130","Energy distribution of secondary tritons", 70, 0., 70.);
    305   histo14 = createHistogram1D("h140","Energy distribution of secondary alpha particles", 70, 0., 70.);
    306   histo15 = createHistogram1D("heliumEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
    307                            70, 0., 500.);
    308   histo16 = createHistogram1D("hydrogenEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
    309                            70, 0., 500.);
    310 
    311   theROOTNtuple = new TNtuple("theROOTNtuple", "Energy deposit by slice", "i:j:k:energy");
    312   theROOTIonTuple = new TNtuple("theROOTIonTuple", "Generic ion information", "a:z:occupancy:energy");
    313   fragmentNtuple = new TNtuple("fragmentNtuple", "Fragments", "A:Z:energy:posX:posY:posZ");
    314   metaData = new TNtuple("metaData", "Metadata", "events:detectorDistance:waterThickness:beamEnergy:energyError:phantomCenterDistance");
    315 #endif
    316 }
    317 
    318 /////////////////////////////////////////////////////////////////////////////
    319 void HadrontherapyAnalysisManager::FillEnergyDeposit(G4int i,
    320                                                      G4int j,
    321                                                      G4int k,
    322                                                      G4double energy)
    323 {
    324 #ifdef G4ANALYSIS_USE
    325  if (ntuple)     {
    326        G4int iSlice = ntuple -> findColumn("i");
    327        G4int jSlice = ntuple -> findColumn("j");
    328        G4int kSlice = ntuple -> findColumn("k");
    329        G4int iEnergy = ntuple -> findColumn("energy");
    330 
    331        ntuple -> fill(iSlice,i);
    332        ntuple -> fill(jSlice,j);
    333        ntuple -> fill(kSlice,k);
    334        ntuple -> fill(iEnergy, energy);     }
    335 
    336   ntuple -> addRow();
    337 #endif
    338 #ifdef G4ANALYSIS_USE_ROOT
    339   if (theROOTNtuple) {
    340     theROOTNtuple->Fill(i, j, k, energy);
    341   }
    342 #endif
    343 }
    344 
    345 /////////////////////////////////////////////////////////////////////////////
    346 void HadrontherapyAnalysisManager::BraggPeak(G4int slice, G4double energy)
    347 {
    348 #ifdef G4ANALYSIS_USE
    349   h1 -> fill(slice,energy);
    350 #endif
    351 #ifdef G4ANALYSIS_USE_ROOT
    352   histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct
    353 #endif
    354 }
    355 
    356 /////////////////////////////////////////////////////////////////////////////
    357 void HadrontherapyAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy)
    358 {
    359 #ifdef G4ANALYSIS_USE
    360   h2 -> fill(slice,energy);
    361 #endif
    362 #ifdef G4ANALYSIS_USE_ROOT
    363   histo2->Fill(slice, energy);
    364 #endif
    365 }
    366 
    367 /////////////////////////////////////////////////////////////////////////////
    368 void HadrontherapyAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy)
    369 {
    370 #ifdef G4ANALYSIS_USE
    371   h3 -> fill(slice,energy);
    372 #endif
    373 #ifdef G4ANALYSIS_USE_ROOT
    374   histo3->Fill(slice, energy);
    375 #endif
    376 }
    377 
    378 /////////////////////////////////////////////////////////////////////////////
    379 void HadrontherapyAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy)
    380 {
    381 #ifdef G4ANALYSIS_USE
    382   h4 -> fill(slice,energy);
    383 #endif
    384 #ifdef G4ANALYSIS_USE_ROOT
    385   histo4->Fill(slice, energy);
    386 #endif
    387 }
    388 
    389 /////////////////////////////////////////////////////////////////////////////
    390 void HadrontherapyAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy)
    391 {
    392 #ifdef G4ANALYSIS_USE
    393   h5 -> fill(slice,energy);
    394 #endif
    395 #ifdef G4ANALYSIS_USE_ROOT
    396   histo5->Fill(slice, energy);
    397 #endif
    398 }
    399 
    400 /////////////////////////////////////////////////////////////////////////////
    401 void HadrontherapyAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy)
    402 {
    403 #ifdef G4ANALYSIS_USE
    404   h6 -> fill(slice,energy);
    405 #endif
    406 #ifdef G4ANALYSIS_USE_ROOT
    407   histo6->Fill(slice, energy);
    408 #endif
    409 }
    410 
    411 /////////////////////////////////////////////////////////////////////////////
    412 void HadrontherapyAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy)
    413 {
    414 #ifdef G4ANALYSIS_USE
    415   h7 -> fill(slice,energy);
    416 #endif
    417 #ifdef G4ANALYSIS_USE_ROOT
    418   histo7->Fill(slice, energy);
    419 #endif
    420 }
    421 
    422 /////////////////////////////////////////////////////////////////////////////
    423 void HadrontherapyAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy)
    424 {
    425 #ifdef G4ANALYSIS_USE
    426   h8 -> fill(slice,energy);
    427 #endif
    428 #ifdef G4ANALYSIS_USE_ROOT
    429   histo8->Fill(slice, energy);
    430 #endif
    431 }
    432 
    433 /////////////////////////////////////////////////////////////////////////////
    434 void HadrontherapyAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy)
    435 {
    436 #ifdef G4ANALYSIS_USE
    437   h9 -> fill(slice,energy);
    438 #endif
    439 #ifdef G4ANALYSIS_USE_ROOT
    440   histo9->Fill(slice, energy);
    441 #endif
    442 }
    443 
    444 /////////////////////////////////////////////////////////////////////////////
    445 void HadrontherapyAnalysisManager::electronEnergyDistribution(G4double energy)
    446 {
    447 #ifdef G4ANALYSIS_USE
    448   h10 -> fill(energy);
    449 #endif
    450 #ifdef G4ANALYSIS_USE_ROOT
    451   histo10->Fill(energy);
    452 #endif
    453 }
    454 
    455 /////////////////////////////////////////////////////////////////////////////
    456 void HadrontherapyAnalysisManager::gammaEnergyDistribution(G4double energy)
    457 {
    458 #ifdef G4ANALYSIS_USE
    459   h11 -> fill(energy);
    460 #endif
    461 #ifdef G4ANALYSIS_USE_ROOT
    462   histo11->Fill(energy);
    463 #endif
    464 }
    465 
    466 /////////////////////////////////////////////////////////////////////////////
    467 void HadrontherapyAnalysisManager::deuteronEnergyDistribution(G4double energy)
    468 {
    469 #ifdef G4ANALYSIS_USE
    470   h12 -> fill(energy);
    471 #endif
    472 #ifdef G4ANALYSIS_USE_ROOT
    473   histo12->Fill(energy);
    474 #endif
    475 }
    476 
    477 /////////////////////////////////////////////////////////////////////////////
    478 void HadrontherapyAnalysisManager::tritonEnergyDistribution(G4double energy)
    479 {
    480 #ifdef G4ANALYSIS_USE
    481   h13 -> fill(energy);
    482 #endif
    483 #ifdef G4ANALYSIS_USE_ROOT
    484   histo13->Fill(energy);
    485 #endif
    486 }
    487 
    488 /////////////////////////////////////////////////////////////////////////////
    489 void HadrontherapyAnalysisManager::alphaEnergyDistribution(G4double energy)
    490 {
    491 #ifdef G4ANALYSIS_USE
    492   h14 -> fill(energy);
    493 #endif
    494 #ifdef G4ANALYSIS_USE_ROOT
    495   histo14->Fill(energy);
    496 #endif
    497 }
    498 /////////////////////////////////////////////////////////////////////////////
    499 void HadrontherapyAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy)
    500 {
    501 #ifdef G4ANALYSIS_USE
    502   h15->fill(secondaryParticleKineticEnergy);
    503 #endif
    504 #ifdef G4ANALYSIS_USE_ROOT
    505   histo15->Fill(secondaryParticleKineticEnergy);
    506 #endif
    507 }
    508 
    509 /////////////////////////////////////////////////////////////////////////////
    510 void HadrontherapyAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy)
    511 {
    512 #ifdef G4ANALYSIS_USE
    513   h16->fill(secondaryParticleKineticEnergy);
    514 #endif
    515 #ifdef G4ANALYSIS_USE_ROOT
    516   histo16->Fill(secondaryParticleKineticEnergy);
    517 #endif
    518 }
    519 
    520 
    521 
    522 void HadrontherapyAnalysisManager::fillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ)
    523 {
    524 #ifdef G4ANALYSIS_USE
    525   if (fragmentTuple)    {
    526        G4int aIndex = fragmentTuple -> findColumn("a");
    527        G4int zIndex = fragmentTuple -> findColumn("z");
    528        G4int energyIndex = fragmentTuple -> findColumn("energy");
    529        G4int posXIndex = fragmentTuple -> findColumn("posX");
    530        G4int posYIndex = fragmentTuple -> findColumn("posY");
    531        G4int posZIndex = fragmentTuple -> findColumn("posZ");
    532 
    533        fragmentTuple -> fill(aIndex,A);
    534        fragmentTuple -> fill(zIndex,Z);
    535        fragmentTuple -> fill(energyIndex, energy);
    536        fragmentTuple -> fill(posXIndex, posX);
    537        fragmentTuple -> fill(posYIndex, posY);
    538        fragmentTuple -> fill(posZIndex, posZ);
    539        fragmentTuple -> addRow();
    540   }
    541 #endif
    542 #ifdef G4ANALYSIS_USE_ROOT
    543   //G4cout <<" A = " << A << "  Z = " << Z << " energy = " << energy << G4endl;
    544   fragmentNtuple->Fill(A, Z, energy, posX, posY, posZ);
    545 #endif
    546 }
    547 
    548 /////////////////////////////////////////////////////////////////////////////
    549 void HadrontherapyAnalysisManager::genericIonInformation(G4int a,
    550                                                          G4double z,
    551                                                          G4int electronOccupancy,
    552                                                          G4double energy)
    553 {
    554 #ifdef G4ANALYSIS_USE
    555   if (ionTuple)    {
    556        G4int aIndex = ionTuple -> findColumn("a");
    557        G4int zIndex = ionTuple -> findColumn("z");
    558        G4int electronIndex = ionTuple -> findColumn("occupancy");
    559        G4int energyIndex = ionTuple -> findColumn("energy");
    560 
    561        ionTuple -> fill(aIndex,a);
    562       ionTuple -> fill(zIndex,z);
    563       ionTuple -> fill(electronIndex, electronOccupancy);
    564        ionTuple -> fill(energyIndex, energy);
    565      }
    566    ionTuple -> addRow();
    567 #endif
    568 #ifdef G4ANALYSIS_USE_ROOT
    569    if (theROOTIonTuple) {
    570      theROOTIonTuple->Fill(a, z, electronOccupancy, energy);
    571    }
    572 #endif
    573 }
    574 
    575 /////////////////////////////////////////////////////////////////////////////
    576 void HadrontherapyAnalysisManager::startNewEvent()
    577 {
    578   eventCounter++;
    579 }
    580 /////////////////////////////////////////////////////////////////////////////
    581 void HadrontherapyAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness, G4double phantomCenter)
    582 {
    583   this->detectorDistance = endDetectorPosition;
    584   this->phantomDepth = waterThickness;
    585   this->phantomCenterDistance = phantomCenter;
    586 }
    587 void HadrontherapyAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy)
    588 {
    589   this->beamEnergy = meanKineticEnergy;
    590   this->energyError = sigmaEnergy;
    591 }
    592 /////////////////////////////////////////////////////////////////////////////
    593 void HadrontherapyAnalysisManager::flush()
    594 {
    595   HadrontherapyMatrix* matrix = HadrontherapyMatrix::getInstance();
    596 
    597   matrix->TotalEnergyDeposit();
    598 #ifdef G4ANALYSIS_USE
    599   theTree -> commit();
    600   theTree ->close();
    601 #endif
    602 #ifdef G4ANALYSIS_USE_ROOT
    603   metaData->Fill((Float_t) eventCounter,(Float_t) detectorDistance, (Float_t) phantomDepth, (Float_t) beamEnergy,(Float_t) energyError, (Float_t) phantomCenterDistance);
    604   metaData->Write();
    605   theROOTNtuple->Write();
    606   theROOTIonTuple->Write();
    607   fragmentNtuple->Write();
    608   theTFile->Write();
    609   //  theTFile->Clear();
    610   theTFile->Close();
    611 #endif
    612   eventCounter = 0;
    613   matrix->flush();
    614 }
    615 /////////////////////////////////////////////////////////////////////////////
    616 void HadrontherapyAnalysisManager::finish()
    617 {
    618 #ifdef G4ANALYSIS_USE
    619   // Write all histograms to file
    620   theTree -> commit();
    621   // Close (will again commit)
    622   theTree ->close();
    623 #endif
    624 #ifdef G4ANALYSIS_USE_ROOT
    625   metaData->Fill((Float_t) eventCounter,(Float_t) detectorDistance, (Float_t) phantomDepth, (Float_t) beamEnergy,(Float_t) energyError, (Float_t) phantomCenterDistance);
    626   metaData->Write();
    627   theROOTNtuple->Write();
    628   theROOTIonTuple->Write();
    629   fragmentNtuple->Write();
    630   theTFile->Write();
    631   theTFile->Close();
    632 #endif
    633   eventCounter = 0;
    634 }
    635 
    636 #endif
    637 
    638 
    639 
    640 
    641 
    642 
    643 
    644 
    645 
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyDetectorConstruction.cc

    r1230 r1313  
    2828// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
    2929
     30
    3031#include "G4SDManager.hh"
    3132#include "G4RunManager.hh"
     33#include "G4GeometryManager.hh"
     34#include "G4SolidStore.hh"
     35#include "G4PhysicalVolumeStore.hh"
     36#include "G4LogicalVolumeStore.hh"
    3237#include "G4Box.hh"
    3338#include "G4LogicalVolume.hh"
     
    4247#include "G4VisAttributes.hh"
    4348#include "G4NistManager.hh"
     49
     50#include "HadrontherapyDetectorConstruction.hh"
    4451#include "HadrontherapyDetectorROGeometry.hh"
    4552#include "HadrontherapyDetectorMessenger.hh"
    4653#include "HadrontherapyDetectorSD.hh"
    47 #include "HadrontherapyDetectorConstruction.hh"
    4854#include "HadrontherapyMatrix.hh"
     55#include "HadrontherapyAnalysisManager.hh"
     56
     57#include <cmath>
    4958
    5059/////////////////////////////////////////////////////////////////////////////
    5160HadrontherapyDetectorConstruction::HadrontherapyDetectorConstruction(G4VPhysicalVolume* physicalTreatmentRoom)
    52   : motherPhys(physicalTreatmentRoom),
     61  : motherPhys(physicalTreatmentRoom), // pointer to WORLD volume
    5362    detectorSD(0), detectorROGeometry(0), matrix(0),
    54     phantomPhysicalVolume(0),
    55     detectorLogicalVolume(0), detectorPhysicalVolume(0),
    56     phantomSizeX(20.*cm), phantomSizeY(20.*cm), phantomSizeZ(20.*cm), // Default half dimensions
    57     detectorSizeX(2.*cm), detectorSizeY(2.*cm), detectorSizeZ(2.*cm),
    58     phantomPosition(20.*cm, 0.*cm, 0.*cm),
    59     detectorToPhantomPosition(0.*cm,18.*cm,18.*cm)// Default displacement of the detector respect to the phantom
    60 {
     63    phantom(0), detector(0),
     64    phantomLogicalVolume(0), detectorLogicalVolume(0),
     65    phantomPhysicalVolume(0), detectorPhysicalVolume(0),
     66    aRegion(0)
     67{
     68  HadrontherapyAnalysisManager::GetInstance();
     69
    6170  // NOTE! that the HadrontherapyDetectorConstruction class
    6271  // does NOT inherit from G4VUserDetectorConstruction G4 class
     
    6978  // Default detector voxels size
    7079  // 200 slabs along the beam direction (X)
    71   sizeOfVoxelAlongX = 200 *um; 
    72   sizeOfVoxelAlongY = 2 * detectorSizeY;
    73   sizeOfVoxelAlongZ = 2 * detectorSizeZ;
    74 
    75   // Calculate (and eventually set) detector position by displacement, phantom size and detector size
    76   SetDetectorPosition();
    77 
    78   // Build phantom and associated detector
    79   ConstructPhantom();
    80   ConstructDetector();
    81   // Set number of the detector voxels along X Y and Z directions. 
    82   // This will construct also the sensitive detector, the ROGeometry
    83   // and the matrix where the energy deposited is collected!
    84   SetNumberOfVoxelBySize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ);
     80  sizeOfVoxelAlongX = 200 *um;
     81  sizeOfVoxelAlongY = 4 *cm;
     82  sizeOfVoxelAlongZ = 4 *cm;
     83
     84  // Define here the material of the water phantom and of the detector
     85  SetPhantomMaterial("G4_WATER");
     86  // Construct geometry (messenger commands)
     87  SetDetectorSize(4.*cm, 4.*cm, 4.*cm);
     88  SetPhantomSize(40. *cm, 40. *cm, 40. *cm);
     89  SetPhantomPosition(G4ThreeVector(20. *cm, 0. *cm, 0. *cm));
     90  SetDetectorToPhantomPosition(G4ThreeVector(0. *cm, 18. *cm, 18. *cm));
     91
     92
     93  // Write virtual parameters to the real ones and check for consistency     
     94  UpdateGeometry();
    8595}
    8696
     
    8898HadrontherapyDetectorConstruction::~HadrontherapyDetectorConstruction()
    8999{
    90     delete detectorROGeometry;// This should be safe in C++ even if the argument is a NULL pointer 
     100    delete detectorROGeometry; 
    91101    delete matrix; 
    92102    delete detectorMessenger;
    93103}
    94104
     105/////////////////////////////////////////////////////////////////////////////
     106// ConstructPhantom() is the method that reconstuct a water box (called phantom
     107// (or water phantom) in the usual Medical physicists slang).
     108// A water phantom can be considered a good
     109// approximation of a an human body.
    95110void HadrontherapyDetectorConstruction::ConstructPhantom()
    96111{
    97   //----------------------------------------
    98   // Phantom:
    99   // A box used to approximate tissues
    100   //----------------------------------------
    101 
    102     G4bool isotopes =  false;
    103     G4Material* waterNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER", isotopes);
    104     phantom = new G4Box("Phantom",phantomSizeX, phantomSizeY, phantomSizeZ);
     112    // Definition of the solid volume of the Phantom
     113    phantom = new G4Box("Phantom",
     114                        phantomSizeX/2,
     115                        phantomSizeY/2,
     116                        phantomSizeZ/2);
     117   
     118// Definition of the logical volume of the Phantom
    105119    phantomLogicalVolume = new G4LogicalVolume(phantom,
    106                                              waterNist,
     120                                             phantomMaterial,
    107121                                             "phantomLog", 0, 0, 0);
    108122 
     123    // Definition of the physics volume of the Phantom
    109124    phantomPhysicalVolume = new G4PVPlacement(0,
    110125                                            phantomPosition,
     
    119134    red -> SetVisibility(true);
    120135    red -> SetForceSolid(true);
    121 //red -> SetForceWireframe(true);
     136    //red -> SetForceWireframe(true);
    122137    phantomLogicalVolume -> SetVisAttributes(red);
    123138}
    124139
    125140/////////////////////////////////////////////////////////////////////////////
     141// ConstructDetector() it the method the reconstruct a detector region
     142// inside the water phantom. It is a volume, located inside the water phantom
     143// and with two coincident faces:
     144//
     145//           **************************
     146//           *   water phantom        *
     147//           *                        *
     148//           *                        *
     149//           *---------------         *
     150//  Beam     *              -         *
     151//  ----->   * detector     -         *
     152//           *              -         *
     153//           *---------------         *
     154//           *                        *
     155//           *                        *
     156//           *                        *
     157//           **************************
     158//
     159// The detector is the volume that can be dived in slices or voxelized
     160// and in it we can collect a number of usefull information:
     161// dose distribution, fluence distribution, LET and so on
    126162void HadrontherapyDetectorConstruction::ConstructDetector()
    127163{
    128   //-----------
    129   // Detector
    130   //-----------
    131     G4bool isotopes =  false;
    132     G4Material* waterNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER", isotopes);
    133     detector = new G4Box("Detector",detectorSizeX,detectorSizeY,detectorSizeZ);
     164
     165    // Definition of the solid volume of the Detector
     166    detector = new G4Box("Detector",
     167                         detectorSizeX/2,
     168                         detectorSizeY/2,
     169                         detectorSizeZ/2);
     170   
     171    // Definition of the logic volume of the Phantom
    134172    detectorLogicalVolume = new G4LogicalVolume(detector,
    135                                                 waterNist,
     173                                                detectorMaterial,
    136174                                                "DetectorLog",
    137175                                                0,0,0);
    138 // Detector is attached by default to the phantom face directly exposed to the beam
    139     detectorPhysicalVolume = new G4PVPlacement(0,
    140                                              detectorPosition, // Setted by displacement
    141                                             "DetectorPhys",
    142                                              detectorLogicalVolume,
    143                                              phantomPhysicalVolume,
    144                                              false,0);
    145  
     176// Definition of the physical volume of the Phantom
     177    detectorPhysicalVolume = new G4PVPlacement(0, 
     178                                               detectorPosition, // Setted by displacement
     179                                               "DetectorPhys",
     180                                               detectorLogicalVolume,
     181                                               phantomPhysicalVolume,
     182                                               false,0);
     183
    146184// Visualisation attributes of the detector
    147185    skyBlue = new G4VisAttributes( G4Colour(135/255. , 206/255. ,  235/255. ));
    148186    skyBlue -> SetVisibility(true);
    149187    skyBlue -> SetForceSolid(true);
    150 //skyBlue -> SetForceWireframe(true);
     188    //skyBlue -> SetForceWireframe(true);
    151189    detectorLogicalVolume -> SetVisAttributes(skyBlue);
     190
     191  // **************
     192  // Cut per Region
     193  // **************
    152194 
    153 }
    154 /////////////////////////////////////////////////////////////////////////////
     195  // A smaller cut is fixed in the phantom to calculate the energy deposit with the
     196  // required accuracy
     197    if (!aRegion)
     198    {
     199        aRegion = new G4Region("DetectorLog");
     200        detectorLogicalVolume -> SetRegion(aRegion);
     201        aRegion -> AddRootLogicalVolume(detectorLogicalVolume);
     202    }
     203
     204}
     205
     206/////////////////////////////////////////////////////////////////////////////
     207
    155208void  HadrontherapyDetectorConstruction::ConstructSensitiveDetector(G4ThreeVector detectorToWorldPosition)
    156209
    157210    // Install new Sensitive Detector and ROGeometry
    158211    delete detectorROGeometry; // this should be safe in C++ also if we have a NULL pointer
    159 
     212    //if (detectorSD) detectorSD->PrintAll();
     213    //delete detectorSD;
    160214    // Sensitive Detector and ReadOut geometry definition
    161215    G4SDManager* sensitiveDetectorManager = G4SDManager::GetSDMpointer();
    162216
    163     G4String sensitiveDetectorName = "Detector";
     217    static G4String sensitiveDetectorName = "Detector";
    164218    if (!detectorSD)
    165219        {
     
    168222        }
    169223    // The Read Out Geometry is instantiated
    170     G4String ROGeometryName = "DetectorROGeometry";
     224    static G4String ROGeometryName = "DetectorROGeometry";
    171225    detectorROGeometry = new HadrontherapyDetectorROGeometry(ROGeometryName,
    172226                                                            detectorToWorldPosition,
    173                                                             detectorSizeX,
    174                                                             detectorSizeY,
    175                                                             detectorSizeZ,
     227                                                            detectorSizeX/2,
     228                                                            detectorSizeY/2,
     229                                                            detectorSizeZ/2,
    176230                                                            numberOfVoxelsAlongX,
    177231                                                            numberOfVoxelsAlongY,
     
    193247        }
    194248}
    195 
     249void  HadrontherapyDetectorConstruction::ParametersCheck()
     250{
     251    // Check phantom/detector sizes & relative position
     252    if (!IsInside(detectorSizeX,
     253                detectorSizeY,
     254                detectorSizeZ,
     255                phantomSizeX,
     256                phantomSizeY,
     257                phantomSizeZ,
     258                detectorToPhantomPosition
     259                ))
     260        G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector is not fully inside Phantom!");
     261
     262    // Check Detector sizes respect to the voxel ones
     263
     264    if ( detectorSizeX < sizeOfVoxelAlongX) {
     265        G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector X size must be bigger or equal than that of Voxel X");
     266    }
     267    if ( detectorSizeY < sizeOfVoxelAlongY) {
     268        G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector Y size must be bigger or equal than that of Voxel Y");
     269    }
     270    if ( detectorSizeZ < sizeOfVoxelAlongZ) {
     271        G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector Z size must be bigger or equal than that of Voxel Z");
     272    }
     273
     274}
    196275/////////////////
    197276// MESSENGERS //
    198277////////////////
    199 G4bool HadrontherapyDetectorConstruction::SetNumberOfVoxelBySize(G4double sizeX, G4double sizeY, G4double sizeZ)
    200 {
    201     // Only change positive dimensions
    202     // XXX numberOfVoxels must be an integer, warn the user
    203 
    204     if (sizeX > 0)
     278
     279G4bool HadrontherapyDetectorConstruction::SetPhantomMaterial(G4String material)
     280{
     281
     282    if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
    205283    {
    206         if (sizeX > 2*detectorSizeX)
     284        phantomMaterial  = pMat;
     285        detectorMaterial = pMat;
     286        if (detectorLogicalVolume && phantomLogicalVolume)
    207287        {
    208             G4cout << "WARNING: Voxel X size must be smaller or equal than that of detector X" << G4endl;
    209             return false;
     288            detectorLogicalVolume -> SetMaterial(pMat);
     289            phantomLogicalVolume ->  SetMaterial(pMat);
     290
     291            G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
     292            G4RunManager::GetRunManager() -> GeometryHasBeenModified();
     293            G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
    210294        }
    211         // Round to the nearest integer
    212         numberOfVoxelsAlongX = lrint(2 * detectorSizeX / sizeX);
    213         sizeOfVoxelAlongX = (2 * detectorSizeX / numberOfVoxelsAlongX );
    214         if(sizeOfVoxelAlongX!=sizeX) G4cout << "Rounding " <<
    215                                                 G4BestUnit(sizeX, "Length") << " to " <<
    216                                                 G4BestUnit(sizeOfVoxelAlongX, "Length") << G4endl;
    217     }
    218 
    219     if (sizeY > 0)
     295    }
     296    else
    220297    {
    221         if (sizeY > 2*detectorSizeY)
    222         {
    223             G4cout << "WARNING: Voxel Y size must be smaller or equal than that of detector Y" << G4endl;
    224             return false;
    225         }
    226         numberOfVoxelsAlongY = lrint(2 * detectorSizeY / sizeY);
    227         sizeOfVoxelAlongY = (2 * detectorSizeY / numberOfVoxelsAlongY );
    228         if(sizeOfVoxelAlongY!=sizeY) G4cout << "Rounding " <<
    229                                                 G4BestUnit(sizeY, "Length") << " to " <<
    230                                                 G4BestUnit(sizeOfVoxelAlongY, "Length") << G4endl;
    231     }
    232     if (sizeZ > 0)
     298        G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
     299            " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl;
     300        G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl;
     301        return false;
     302    }
     303
     304    return true;
     305}
     306/////////////////////////////////////////////////////////////////////////////
     307void HadrontherapyDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ)
     308{
     309    if (sizeX > 0.) phantomSizeX = sizeX;
     310    if (sizeY > 0.) phantomSizeY = sizeY;
     311    if (sizeZ > 0.) phantomSizeZ = sizeZ;
     312}
     313/////////////////////////////////////////////////////////////////////////////
     314/////////////////////////////////////////////////////////////////////////////
     315void HadrontherapyDetectorConstruction::SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ)
     316{
     317    if (sizeX > 0.) {detectorSizeX = sizeX;}
     318    if (sizeY > 0.) {detectorSizeY = sizeY;}
     319    if (sizeZ > 0.) {detectorSizeZ = sizeZ;}
     320    SetVoxelSize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ);
     321}
     322/////////////////////////////////////////////////////////////////////////////
     323
     324void HadrontherapyDetectorConstruction::SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ)
     325{
     326    if (sizeX > 0.) {sizeOfVoxelAlongX = sizeX;}
     327    if (sizeY > 0.) {sizeOfVoxelAlongY = sizeY;}
     328    if (sizeZ > 0.) {sizeOfVoxelAlongZ = sizeZ;}
     329}
     330void HadrontherapyDetectorConstruction::SetPhantomPosition(G4ThreeVector pos)
     331{
     332    phantomPosition = pos;
     333}
     334
     335/////////////////////////////////////////////////////////////////////////////
     336void HadrontherapyDetectorConstruction::SetDetectorToPhantomPosition(G4ThreeVector displ)
     337{
     338    detectorToPhantomPosition = displ;
     339}
     340/////////////////////////////////////////////////////////////////////////////
     341void HadrontherapyDetectorConstruction::UpdateGeometry()
     342{
     343    ParametersCheck();
     344
     345    //G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
     346    G4GeometryManager::GetInstance() -> OpenGeometry();
     347    if (phantom)
    233348    {
    234         if (sizeZ > 2*detectorSizeZ)
    235         {
    236             G4cout << "WARNING: Voxel Z size must be smaller or equal than that of detector Z" << G4endl;
    237             return false;
    238         }
    239         numberOfVoxelsAlongZ = lrint(2 * detectorSizeZ / sizeZ);
    240         sizeOfVoxelAlongZ = (2 * detectorSizeZ / numberOfVoxelsAlongZ );
    241         if(sizeOfVoxelAlongZ!=sizeZ) G4cout << "Rounding " <<
    242                                                 G4BestUnit(sizeZ, "Length") << " to " <<
    243                                                 G4BestUnit(sizeOfVoxelAlongZ, "Length") << G4endl;
    244     }
    245 
    246     G4cout << "The (X, Y, Z) sizes of the Voxels are: (" <<
    247                 G4BestUnit(sizeOfVoxelAlongX, "Length")  << ", " <<
    248                 G4BestUnit(sizeOfVoxelAlongY, "Length")  << ", " <<
    249                 G4BestUnit(sizeOfVoxelAlongZ, "Length") << ')' << G4endl;
     349            phantom -> SetXHalfLength(phantomSizeX/2);
     350            phantom -> SetYHalfLength(phantomSizeY/2);
     351            phantom -> SetZHalfLength(phantomSizeZ/2);
     352            phantomPhysicalVolume -> SetTranslation(phantomPosition);
     353    }
     354    else   ConstructPhantom();
     355
     356    // Get the center of the detector
     357    SetDetectorPosition();
     358    if (detector)
     359    {
     360                        detector -> SetXHalfLength(detectorSizeX/2);
     361                        detector -> SetYHalfLength(detectorSizeY/2);
     362                        detector -> SetZHalfLength(detectorSizeZ/2);
     363                        detectorPhysicalVolume -> SetTranslation(detectorPosition);
     364    }
     365    else    ConstructDetector();
     366   
     367// Round to nearest integer number of voxel
     368        numberOfVoxelsAlongX = lrint(detectorSizeX / sizeOfVoxelAlongX);
     369        sizeOfVoxelAlongX = ( detectorSizeX / numberOfVoxelsAlongX );
     370
     371        numberOfVoxelsAlongY = lrint(detectorSizeY / sizeOfVoxelAlongY);
     372        sizeOfVoxelAlongY = ( detectorSizeY / numberOfVoxelsAlongY );
     373
     374        numberOfVoxelsAlongZ = lrint(detectorSizeZ / sizeOfVoxelAlongZ);
     375        sizeOfVoxelAlongZ = ( detectorSizeZ / numberOfVoxelsAlongZ );
     376
     377    //G4cout << "*************** DetectorToWorldPosition " << GetDetectorToWorldPosition()/cm << "\n";
     378    ConstructSensitiveDetector(GetDetectorToWorldPosition());
     379
     380    volumeOfVoxel = sizeOfVoxelAlongX * sizeOfVoxelAlongY * sizeOfVoxelAlongZ;
     381    massOfVoxel = detectorMaterial -> GetDensity() * volumeOfVoxel;
     382    //  This will clear the existing matrix (together with all data inside it)!
     383    matrix = HadrontherapyMatrix::GetInstance(numberOfVoxelsAlongX,
     384                                              numberOfVoxelsAlongY,
     385                                              numberOfVoxelsAlongZ,
     386                                              massOfVoxel);
     387
     388    // Inform the kernel about the new geometry
     389    G4RunManager::GetRunManager() -> GeometryHasBeenModified();
     390    G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
     391
     392    PrintParameters();
     393}
     394
     395void HadrontherapyDetectorConstruction::PrintParameters()
     396{
     397
     398    G4cout << "The (X,Y,Z) dimensions of the phantom are : (" <<
     399        G4BestUnit( phantom -> GetXHalfLength()*2., "Length") << ',' <<
     400        G4BestUnit( phantom -> GetYHalfLength()*2., "Length") << ',' <<
     401        G4BestUnit( phantom -> GetZHalfLength()*2., "Length") << ')' << G4endl;
     402   
     403    G4cout << "The (X,Y,Z) dimensions of the detector are : (" <<
     404        G4BestUnit( detector -> GetXHalfLength()*2., "Length") << ',' <<
     405        G4BestUnit( detector -> GetYHalfLength()*2., "Length") << ',' <<
     406        G4BestUnit( detector -> GetZHalfLength()*2., "Length") << ')' << G4endl;
     407
     408    G4cout << "Displacement between Phantom and World is: ";
     409    G4cout << "DX= "<< G4BestUnit(phantomPosition.getX(),"Length") <<
     410        "DY= "<< G4BestUnit(phantomPosition.getY(),"Length") <<
     411        "DZ= "<< G4BestUnit(phantomPosition.getZ(),"Length") << G4endl;
     412
     413    G4cout << "The (X,Y,Z) sizes of the Voxels are: (" <<
     414        G4BestUnit(sizeOfVoxelAlongX, "Length")  << ',' <<
     415        G4BestUnit(sizeOfVoxelAlongY, "Length")  << ',' <<
     416        G4BestUnit(sizeOfVoxelAlongZ, "Length") << ')' << G4endl;
    250417
    251418    G4cout << "The number of Voxels along (X,Y,Z) is: (" <<
    252                 numberOfVoxelsAlongX  << ", " <<
    253                 numberOfVoxelsAlongY  << ", "  <<
    254                 numberOfVoxelsAlongZ  << ')' << G4endl;
    255 
    256     //  This will clear the existing matrix (together with data inside it)!
    257     matrix = HadrontherapyMatrix::getInstance(numberOfVoxelsAlongX,
    258                                               numberOfVoxelsAlongY,
    259                                               numberOfVoxelsAlongZ);
    260 
    261     // Here construct the Sensitive Detector and Read Out Geometry
    262     ConstructSensitiveDetector(GetDetectorToWorldPosition());
    263     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
    264     return true;
    265 }
    266 /////////////////////////////////////////////////////////////////////////////
    267 G4bool HadrontherapyDetectorConstruction::SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ)
    268 {
    269 // Check that the detector stay inside the phantom
    270         if (sizeX > 0 && sizeX < sizeOfVoxelAlongX) {G4cout << "WARNING: Detector X size must be bigger than that of Voxel X" << G4endl; return false;}
    271         if (sizeY > 0 && sizeY < sizeOfVoxelAlongY) {G4cout << "WARNING: Detector Y size must be bigger than that of Voxel Y" << G4endl; return false;}
    272         if (sizeZ > 0 && sizeZ < sizeOfVoxelAlongZ) {G4cout << "WARNING: Detector Z size must be bigger than that of Voxel Z" << G4endl; return false;}
    273 
    274         if (!IsInside(sizeX/2,
    275                       sizeY/2,
    276                       sizeZ/2,
    277                       phantomSizeX,
    278                       phantomSizeY,
    279                       phantomSizeZ,
    280                       detectorToPhantomPosition))
    281         {return false;}
    282 // Negative or null values mean don't change it!
    283     if (sizeX > 0) {
    284                         detectorSizeX = sizeX/2;
    285                         detector -> SetXHalfLength(detectorSizeX);
    286                    }
    287 
    288     if (sizeY > 0) {
    289                         detectorSizeY = sizeY/2;
    290                         detector -> SetYHalfLength(detectorSizeY);
    291                    }
    292 
    293     if (sizeZ > 0) {
    294                         detectorSizeZ = sizeZ/2;
    295                         detector -> SetZHalfLength(detectorSizeZ);
    296                     }
    297 
    298 
    299     G4cout << "The (X, Y, Z) dimensions of the detector are : (" <<
    300                   G4BestUnit( detector -> GetXHalfLength()*2., "Length") << ", " <<
    301                   G4BestUnit( detector -> GetYHalfLength()*2., "Length") << ", " <<
    302                   G4BestUnit( detector -> GetZHalfLength()*2., "Length") << ')' << G4endl;
    303 // Adjust detector position
    304     SetDetectorPosition();
    305 // Adjust voxels number accordingly to new detector geometry
    306 // Matrix will be re-instantiated!
    307 // Voxels and ROGeometry must follow the detector!
    308     SetNumberOfVoxelBySize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ);
    309     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
    310     return true;
    311 }
    312 
    313 /////////////////////////////////////////////////////////////////////////////
    314 G4bool HadrontherapyDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ)
    315 {
    316 
    317         if (!IsInside(detectorSizeX,
    318                                   detectorSizeY,
    319                                   detectorSizeZ,
    320                                   sizeX/2,//method parameters
    321                                   sizeY/2,
    322                                   sizeZ/2,
    323                                   detectorToPhantomPosition
    324                                   ))
    325         return false;
    326 
    327 // Only change positive dimensions
    328     if (sizeX > 0) {
    329                      phantomSizeX = sizeX/2;
    330                      phantom -> SetXHalfLength(phantomSizeX);
    331                    }
    332     if (sizeY > 0) {
    333                      phantomSizeY = sizeY/2;
    334                      phantom -> SetYHalfLength(phantomSizeY);
    335                    }
    336 
    337     if (sizeZ > 0) {
    338                      phantomSizeZ = sizeZ/2;
    339                      phantom -> SetZHalfLength(phantomSizeZ);
    340                    }
    341  
    342 
    343     G4cout << "The (X, Y, Z) dimensions of the phantom are : (" <<
    344                   G4BestUnit( phantom -> GetXHalfLength()*2., "Length") << ", " <<
    345                   G4BestUnit( phantom -> GetYHalfLength()*2., "Length") << ", " <<
    346                   G4BestUnit( phantom -> GetZHalfLength()*2., "Length") << ')' << G4endl;
    347 //G4cout << '\n' << "Coordinate volume: " << phantomPhysicalVolume -> GetTranslation() << G4endl;
    348 // Adjust detector position inside phantom
    349     SetDetectorPosition();
    350 
    351     ConstructSensitiveDetector(GetDetectorToWorldPosition());
    352     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
    353     return true;
    354 }
    355 /////////////////////////////////////////////////////////////////////////////
    356 G4bool HadrontherapyDetectorConstruction::SetPhantomPosition(G4ThreeVector displacement)
    357 {
    358 // Set Phantom position respect to the World
    359 // TODO check for overlap!
    360     phantomPosition = displacement;
    361     if (phantomPhysicalVolume)
    362         {
    363             phantomPhysicalVolume -> SetTranslation(phantomPosition);
    364             G4cout << "Displacement between Phantom and World is: ";
    365             G4cout << "DX= "<< G4BestUnit(phantomPosition.getX(),"Length") << ", " <<
    366                       "DY= "<< G4BestUnit(phantomPosition.getY(),"Length") << ", " <<
    367                       "DZ= "<< G4BestUnit(phantomPosition.getZ(),"Length") << G4endl;
    368 
    369 // Redraw ROGeometry!
    370             ConstructSensitiveDetector(GetDetectorToWorldPosition());
    371             G4RunManager::GetRunManager() -> GeometryHasBeenModified();
    372         }
    373     return true;
    374 }
    375 
    376 /////////////////////////////////////////////////////////////////////////////
    377 G4bool HadrontherapyDetectorConstruction::SetDetectorToPhantomPosition(G4ThreeVector displacement)
    378 {
    379 // Ignore negative values
    380     if (displacement[0] < 0.) displacement[0] = detectorToPhantomPosition[0];
    381     if (displacement[1] < 0.) displacement[1] = detectorToPhantomPosition[1];
    382     if (displacement[2] < 0.) displacement[2] = detectorToPhantomPosition[2];
    383 
    384     if (!IsInside(detectorSizeX,
    385                   detectorSizeY,
    386                   detectorSizeZ,
    387                   phantomSizeX,
    388                   phantomSizeY,
    389                   phantomSizeZ,
    390                   displacement // method parameter!
    391                   ))
    392     {return false;}
    393     detectorToPhantomPosition = displacement;
    394 
    395 // Adjust detector position inside phantom
    396     SetDetectorPosition();
    397 
    398     ConstructSensitiveDetector(GetDetectorToWorldPosition());
    399     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
    400     return true;
    401 }
     419        numberOfVoxelsAlongX  << ',' <<
     420        numberOfVoxelsAlongY  <<','  <<
     421        numberOfVoxelsAlongZ  << ')' << G4endl;
     422
     423}
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyDetectorMessenger.cc

    r1230 r1313  
    3131#include "HadrontherapyDetectorConstruction.hh"
    3232#include "G4UIdirectory.hh"
    33 #include "G4UIcmdWithADoubleAndUnit.hh"
     33#include "G4UIcmdWith3VectorAndUnit.hh"
     34#include "G4UIcmdWithoutParameter.hh"
    3435#include "G4UIcmdWithAString.hh"
    35 #include "G4UIcmdWith3VectorAndUnit.hh"
    3636
    3737/////////////////////////////////////////////////////////////////////////////
     
    4949                                                "PhantomSizeAlongZ", false);
    5050    changeThePhantomSizeCmd -> SetDefaultUnit("mm");
    51     changeThePhantomSizeCmd -> SetUnitCandidates("um mm cm");
     51    changeThePhantomSizeCmd -> SetUnitCandidates("nm um mm cm");
    5252    changeThePhantomSizeCmd -> AvailableForStates(G4State_Idle);
    5353
     54
     55    // Change Phantom material
     56    changeThePhantomMaterialCmd = new G4UIcmdWithAString("/changePhantom/material", this);
     57    changeThePhantomMaterialCmd -> SetGuidance("Change the Phantom and the detector material");
     58    changeThePhantomMaterialCmd -> SetParameterName("PhantomMaterial", false);
     59    changeThePhantomMaterialCmd -> SetDefaultValue("G4_WATER");
     60    changeThePhantomMaterialCmd -> AvailableForStates(G4State_Idle);
    5461
    5562    // Change Phantom position
     
    6168                                                    "PositionAlongZ", false);
    6269    changeThePhantomPositionCmd -> SetDefaultUnit("mm");
    63     changeThePhantomPositionCmd -> SetUnitCandidates("mm cm m");
     70    changeThePhantomPositionCmd -> SetUnitCandidates("um mm cm m");
    6471    changeThePhantomPositionCmd -> AvailableForStates(G4State_Idle);
    6572
     73
     74    updateCmd = new G4UIcmdWithoutParameter("/changePhantom/update",this);
     75    updateCmd->SetGuidance("Update Phantom/Detector geometry.");
     76    updateCmd->SetGuidance("This command MUST be applied before \"beamOn\" ");
     77    updateCmd->SetGuidance("if you changed geometrical value(s).");
     78    updateCmd->AvailableForStates(G4State_Idle);
    6679
    6780    //  Change detector size
     
    7487    changeTheDetectorSizeCmd -> SetParameterName("DetectorSizeAlongX", "DetectorSizeAlongY", "DetectorSizeAlongZ", false);
    7588    changeTheDetectorSizeCmd -> SetDefaultUnit("mm");
    76     changeTheDetectorSizeCmd -> SetUnitCandidates("um mm cm");
     89    changeTheDetectorSizeCmd -> SetUnitCandidates("nm um mm cm");
    7790    changeTheDetectorSizeCmd -> AvailableForStates(G4State_Idle);
    7891
     
    8598                                                              "DisplacementAlongZ", false);
    8699    changeTheDetectorToPhantomPositionCmd -> SetDefaultUnit("mm");
    87     changeTheDetectorToPhantomPositionCmd -> SetUnitCandidates("um mm cm");
     100    changeTheDetectorToPhantomPositionCmd -> SetUnitCandidates("nm um mm cm");
    88101    changeTheDetectorToPhantomPositionCmd -> AvailableForStates(G4State_Idle);
    89102   
     
    94107    changeTheDetectorVoxelCmd -> SetParameterName("VoxelSizeAlongX", "VoxelSizeAlongY", "VoxelSizeAlongZ", false);
    95108    changeTheDetectorVoxelCmd -> SetDefaultUnit("mm");
    96     changeTheDetectorVoxelCmd -> SetUnitCandidates("um mm cm");
     109    changeTheDetectorVoxelCmd -> SetUnitCandidates("nm um mm cm");
    97110    changeTheDetectorVoxelCmd -> AvailableForStates(G4State_Idle);
    98111   }
     
    104117    delete changeThePhantomSizeCmd;
    105118    delete changeThePhantomPositionCmd;
     119    delete changeThePhantomMaterialCmd;
     120    delete updateCmd;
    106121    delete changeTheDetectorDir;
    107122    delete changeTheDetectorSizeCmd;
     
    124139         hadrontherapyDetector -> SetPhantomPosition(size);
    125140  }
     141  else if (command == changeThePhantomMaterialCmd)
     142  {
     143      hadrontherapyDetector -> SetPhantomMaterial(newValue);
     144  }
    126145  else if (command == changeTheDetectorSizeCmd)
    127146  {
     
    137156  {
    138157        G4ThreeVector size = changeTheDetectorVoxelCmd  -> GetNew3VectorValue(newValue);
    139         hadrontherapyDetector -> SetNumberOfVoxelBySize(size.getX(),size.getY(),size.getZ());
     158        hadrontherapyDetector -> SetVoxelSize(size.getX(),size.getY(),size.getZ());
     159  }
     160  else if (command == updateCmd)
     161  {
     162      hadrontherapyDetector -> UpdateGeometry();
    140163  }
    141164}
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyEventAction.cc

    r1230 r1313  
    2424// ********************************************************************
    2525//
    26 // $Id: HadrontherapyEventAction.cc;
    27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
    28 
     26// $Id: HadrontherapyEventAction.cc;
     27//
     28// See more at: http://workgroup.lngs.infn.it/geant4lns
     29//
     30// ----------------------------------------------------------------------------
     31//                 GEANT 4 - Hadrontherapy example
     32// ----------------------------------------------------------------------------
     33// Code developed by:
     34//
     35// G.A.P. Cirrone(a)*, G. Candiano, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
     36//
     37// (a) Laboratori Nazionali del Sud
     38//     of the National Institute for Nuclear Physics, Catania, Italy
     39// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
     40//
     41// * cirrone@lns.infn.it
     42// --------------------------------------------------------------
    2943#include "G4Event.hh"
    3044#include "G4EventManager.hh"
    3145#include "G4HCofThisEvent.hh"
    3246#include "G4VHitsCollection.hh"
    33 #include "G4TrajectoryContainer.hh"
    34 #include "G4Trajectory.hh"
    35 #include "G4VVisManager.hh"
    3647#include "G4SDManager.hh"
    3748#include "G4VVisManager.hh"
     49
    3850#include "HadrontherapyEventAction.hh"
    3951#include "HadrontherapyDetectorHit.hh"
     
    6476  //printing survey
    6577  if (evtNb%printModulo == 0)
    66     G4cout << "\n---> Begin of Event: " << evtNb << G4endl;
     78     G4cout << "\n---> Begin of Event: " << evtNb << G4endl;
    6779   
    6880  G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
    6981  if(hitsCollectionID == -1)
    7082    hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyDetectorHitsCollection");
     83 
    7184}
    7285
    7386/////////////////////////////////////////////////////////////////////////////
    7487void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt)
    75 {  
     88{
    7689  if(hitsCollectionID < 0)
    7790  return;
    7891  G4HCofThisEvent* HCE = evt -> GetHCofThisEvent();
    79  
     92
     93  // Clear voxels hit list
     94  HadrontherapyMatrix* matrix = HadrontherapyMatrix::GetInstance();
     95  if (matrix) matrix -> ClearHitTrack();
     96
    8097  if(HCE)
    8198  {
     
    83100    if(CHC)
    84101     {
    85            matrix = HadrontherapyMatrix::getInstance(); 
    86102       if(matrix)
    87103          {
     
    101117    }
    102118  }
    103   // Extract the trajectories and draw them in the visualisation
    104 
    105   if (G4VVisManager::GetConcreteInstance())
    106     {
    107       G4TrajectoryContainer * trajectoryContainer = evt -> GetTrajectoryContainer();
    108       G4int n_trajectories = 0;
    109       if (trajectoryContainer) n_trajectories = trajectoryContainer -> entries();
    110      
    111       for (G4int i = 0; i < n_trajectories; i++)
    112         {
    113           G4Trajectory* trj = (G4Trajectory*)
    114             ((*(evt -> GetTrajectoryContainer()))[i]);
    115           if(drawFlag == "all") trj -> DrawTrajectory(50);
    116           else if((drawFlag == "charged")&&(trj -> GetCharge() != 0.))
    117             trj -> DrawTrajectory(50);
    118           else if ((drawFlag == "neutral")&&(trj -> GetCharge() == 0.))
    119             trj -> DrawTrajectory(50);               
    120         }
    121     }
    122119}
    123120
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyMatrix.cc

    r1230 r1313  
    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 // $Id: HadrontherapyMatrix.cc;
    27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy//
     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        // $Id: HadrontherapyMatrix.cc;
     27        // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy//
    2828
    2929#include "HadrontherapyMatrix.hh"
    3030#include "HadrontherapyAnalysisManager.hh"
     31#include "G4RunManager.hh"
     32#include "HadrontherapyPrimaryGeneratorAction.hh"
     33#include "G4ParticleGun.hh"
     34
     35#include <fstream>
     36#include <unistd.h>
     37#include <iostream>
     38#include <sstream>
     39#include <iomanip>
    3140#include "globals.hh"
    32 #include <fstream>
    33 
     41
     42// Units definition: CLHEP/Units/SystemOfUnits.h
     43//
    3444HadrontherapyMatrix* HadrontherapyMatrix::instance = NULL;
    35 // Static method that only return a pointer to the matrix object
    36 HadrontherapyMatrix* HadrontherapyMatrix::getInstance()
    37 {
    38   return instance;
    39 }
    40 // This STATIC method delete (!) the old matrix and rewrite a new object returning a pointer to it
    41 HadrontherapyMatrix* HadrontherapyMatrix::getInstance(G4int voxelX, G4int voxelY, G4int voxelZ) 
    42 {
    43     if (instance) delete instance;
    44     instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ);
    45     instance -> Initialize();   
    46     return instance;
    47 }
    48 
    49 HadrontherapyMatrix::HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ):
    50     matrix(0)
     45G4bool HadrontherapyMatrix::secondaries = false;
     46        // Only return a pointer to matrix
     47HadrontherapyMatrix* HadrontherapyMatrix::GetInstance()
     48{
     49        return instance;
     50}
     51        // This STATIC method delete (!) the old matrix and rewrite a new object returning a pointer to it
     52        // TODO A check on the parameters is required!
     53HadrontherapyMatrix* HadrontherapyMatrix::GetInstance(G4int voxelX, G4int voxelY, G4int voxelZ, G4double mass) 
     54{
     55        if (instance) delete instance;
     56        instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ, mass);
     57        instance -> Initialize();// XXX
     58        return instance;
     59}
     60HadrontherapyMatrix::HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ, G4double mass):
     61    filename("Dose.out"),
     62    doseUnit(MeV/g)
    5163
    52 // Number of the voxels of the phantom
    53 // For Y = Z = 1 the phantom is divided in slices (and not in voxels)
    54 // orthogonal to the beam axis
    55   numberVoxelX = voxelX;
    56   numberVoxelY = voxelY;
    57   numberVoxelZ = voxelZ;
    58   // Create the dose matrix
    59   matrix = new G4double[numberVoxelX*numberVoxelY*numberVoxelZ];
    60   if (matrix) G4cout << "Matrix: Memory space to store physical dose into " << 
    61                         numberVoxelX*numberVoxelY*numberVoxelZ <<
    62                         " voxels has been allocated " << G4endl;
    63   else G4Exception("Can't allocate memory to store physical dose!");
    64 }
    65 
     64        // Number of the voxels of the phantom
     65        // For Y = Z = 1 the phantom is divided in slices (and not in voxels)
     66        // orthogonal to the beam axis
     67        numberOfVoxelAlongX = voxelX;
     68        numberOfVoxelAlongY = voxelY;
     69        numberOfVoxelAlongZ = voxelZ;
     70        massOfVoxel = mass;
     71        // Create the dose matrix
     72        matrix = new G4double[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ];
     73        if (matrix)
     74        {
     75                G4cout << "HadrontherapyMatrix: Memory space to store physical dose into " << 
     76                numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ <<
     77                " voxels has been allocated " << G4endl;
     78        }
     79        else G4Exception(" HadrontherapyMatrix::HadrontherapyMatrix. Can't allocate memory to store physical dose!");
     80                // Hit voxel (TrackID) marker
     81                // This array mark the status of voxel, if a hit occur, with the trackID of the particle
     82                // Must be initialized
     83        hitTrack = new G4int[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ];
     84        ClearHitTrack();
     85}
     86
     87/////////////////////////////////////////////////////////////////////////////
    6688HadrontherapyMatrix::~HadrontherapyMatrix()
    6789{
    6890    delete[] matrix;
    69 }
    70 
    71 void HadrontherapyMatrix::flush()
    72 {
    73         if(matrix)
    74         for(int i=0; i<numberVoxelX*numberVoxelY*numberVoxelZ; i++)
    75         {
    76           matrix[i] = 0;
    77         }
    78 }
     91    delete[] hitTrack;
     92                // clear fluences/dose data
     93    Clear();
     94}
     95
     96/////////////////////////////////////////////////////////////////////////////
     97void HadrontherapyMatrix::Clear()
     98{
     99    for (size_t i=0; i<ionStore.size(); i++)
     100    {
     101        delete[] ionStore[i].dose;
     102        delete[] ionStore[i].fluence;
     103    }
     104    ionStore.clear();
     105}
     106
     107/////////////////////////////////////////////////////////////////////////////
     108// Initialise the elements of the matrix to zero
    79109void HadrontherapyMatrix::Initialize()
    80110{
    81 // Initialise the elements of the matrix to zero
    82   for(G4int i = 0; i < numberVoxelX; i++)
    83     {
    84       for(G4int j = 0; j < numberVoxelY; j++)
    85            {
    86               for(G4int k = 0; k < numberVoxelZ; k++)
    87 
    88               matrix[Index(i,j,k)] = 0.;
    89            }
    90     }
    91 }
     111    Clear();
     112    for(int i=0;i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;i++)
     113    {
     114                matrix[i] = 0;
     115    }
     116}
     117        /////////////////////////////////////////////////////////////////////////////
     118        /////////////////////////////////////////////////////////////////////////////
     119        // Print generated nuclides list
     120void HadrontherapyMatrix::PrintNuclides()
     121{
     122    for (size_t i=0; i<ionStore.size(); i++)
     123    {
     124                G4cout << ionStore[i].name << G4endl;
     125    }
     126}
     127        /////////////////////////////////////////////////////////////////////////////
     128        // Clear Hit voxel (TrackID) markers
     129void HadrontherapyMatrix::ClearHitTrack()
     130{
     131        for(G4int i=0; i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; i++) hitTrack[i] = 0;
     132}
     133        // Return Hit status
     134G4int* HadrontherapyMatrix::GetHitTrack(G4int i, G4int j, G4int k)
     135{
     136        return &(hitTrack[Index(i,j,k)]);
     137}
     138/////////////////////////////////////////////////////////////////////////////
     139// Dose methods...
     140// Fill DOSE/fluence matrix for particle/ion:
     141// If fluence parameter is true (default value is FALSE) then fluence at voxel (i, j, k) is increased.
     142// The energyDeposit parameter fill the dose matrix for voxel (i,j,k)
     143/////////////////////////////////////////////////////////////////////////////
     144
     145G4bool HadrontherapyMatrix::Fill(G4int trackID,
     146                                 G4ParticleDefinition* particleDef,
     147                                 G4int i, G4int j, G4int k,
     148                                 G4double energyDeposit,
     149                                 G4bool fluence)
     150{
     151    if (energyDeposit <=0. && !fluence || !secondaries) return false;
     152    // Get Particle Data Group particle ID
     153    G4int PDGencoding = particleDef -> GetPDGEncoding();
     154    PDGencoding -= PDGencoding%10;
     155       
     156    // Search for already allocated data...
     157    for (size_t l=0; l < ionStore.size(); l++)
     158    {
     159                if (ionStore[l].PDGencoding == PDGencoding )
     160                {   // Is it a primary or a secondary particle?
     161                        if ( trackID ==1 && ionStore[l].isPrimary || trackID !=1 && !ionStore[l].isPrimary)
     162                        {
     163                                if (energyDeposit > 0.) ionStore[l].dose[Index(i, j, k)] += energyDeposit/massOfVoxel;
     164                               
     165                                        // Fill a matrix per each ion with the fluence
     166                                if (fluence) ionStore[l].fluence[Index(i, j, k)]++;
     167                                return true;
     168                        }
     169                }
     170    }
     171       
     172    G4int Z = particleDef-> GetAtomicNumber();
     173    G4int A = particleDef-> GetAtomicMass();
     174
     175    G4String fullName = particleDef -> GetParticleName();
     176    G4String name = fullName.substr (0, fullName.find("[") ); // cut excitation energy 
     177  // Let's put a new particle in our store...
     178    ion newIon =
     179    {
     180                (trackID == 1) ? true:false,
     181                PDGencoding,
     182                name,
     183                name.length(),
     184                Z,
     185                A,
     186                new G4double[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ],
     187                new unsigned int[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ]
     188    };
     189                // Initialize data
     190    if (newIon.dose && newIon.fluence)
     191    {
     192                for(G4int m=0; m<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; m++)
     193                {
     194                        newIon.dose[m] = 0.;
     195                        newIon.fluence[m] = 0;
     196                }
     197                if (energyDeposit > 0.) newIon.dose[Index(i, j, k)] += energyDeposit/massOfVoxel;
     198                if (fluence) newIon.fluence[Index(i, j, k)]++;
     199               
     200                ionStore.push_back(newIon);
     201               
     202                // TODO Put some verbosity check
     203                /*
     204                 G4cout << "Memory space to store the DOSE/FLUENCE into " << 
     205                 numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ <<
     206                 " voxels has been allocated for the nuclide " << newIon.name <<
     207                 " (Z = " << Z << ", A = " << A << ")" << G4endl ;
     208                 */
     209                return true;
     210    }
     211    else // XXX Out of memory! XXX
     212    {
     213                return false;
     214    }
     215       
     216}
     217       
     218        /////////////////////////////////////////////////////////////////////////////
     219        /////////////////////////////////////////////////////////////////////////////
     220        // Methods to store data to filenames...
     221        ////////////////////////////////////////////////////////////////////////////
     222        ////////////////////////////////////////////////////////////////////////////
     223        //
     224        // General method to store matrix data to filename
     225void HadrontherapyMatrix::StoreMatrix(G4String file, void* data, size_t psize)
     226{
     227    if (data)
     228    {
     229                ofs.open(file, std::ios::out);
     230                if (ofs.is_open())
     231                {
     232                        for(G4int i = 0; i < numberOfVoxelAlongX; i++)
     233                                for(G4int j = 0; j < numberOfVoxelAlongY; j++)
     234                                        for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
     235                                        {
     236                                                G4int n = Index(i, j, k);
     237                                                        // Check for data type: u_int, G4double, XXX
     238                                                if (psize == sizeof(unsigned int))
     239                                                {
     240                                                        unsigned int* pdata = (unsigned int*)data;
     241                                                        if (pdata[n]) ofs << i << '\t' << j << '\t' <<
     242                                                                k << '\t' << pdata[n] << G4endl;
     243                                                }
     244                                                else if (psize == sizeof(G4double))
     245                                                {
     246                                                        G4double* pdata = (G4double*)data;
     247                                                        if (pdata[n]) ofs << i << '\t' << j << '\t' <<
     248                                                                k << '\t' << pdata[n] << G4endl;
     249                                                }
     250                                        }
     251                        ofs.close();
     252                }
     253    }
     254}
     255
     256        // Store fluence per single ion in multiple files
     257void HadrontherapyMatrix::StoreFluenceData()
     258{
     259    for (size_t i=0; i < ionStore.size(); i++){
     260                StoreMatrix(ionStore[i].name + "_Fluence.out", ionStore[i].fluence, sizeof(unsigned int));
     261    }
     262}
     263        // Store dose per single ion in multiple files
     264void HadrontherapyMatrix::StoreDoseData()
     265{
     266       
     267    for (size_t i=0; i < ionStore.size(); i++){
     268                StoreMatrix(ionStore[i].name + "_Dose.out", ionStore[i].dose, sizeof(G4double));
     269    }
     270}
     271        /////////////////////////////////////////////////////////////////////////
     272        // Store dose for all ions into a single file and into ntuples.
     273        // Please note that this function is called via messenger commands
     274        // defined in the HadrontherapyAnalysisFileMessenger.cc class file
     275void HadrontherapyMatrix::StoreDoseFluenceAscii()
     276{
     277    // Sort like periodic table
     278    std::sort(ionStore.begin(), ionStore.end());
     279#define width 15L
     280    ofs.open(filename, std::ios::out);
     281    if (ofs.is_open())
     282    {
     283
     284        //
     285        // Write the voxels index and the list of particles/ions
     286        ofs << std::setprecision(6) << std::left <<
     287            "i\tj\tk\t";
     288/*         
     289            G4RunManager *runManager = G4RunManager::GetRunManager();
     290            HadrontherapyPrimaryGeneratorAction *pPGA = (HadrontherapyPrimaryGeneratorAction*)runManager -> GetUserPrimaryGeneratorAction();
     291            G4String name = pPGA -> GetParticleGun() -> GetParticleDefinition() -> GetParticleName();
     292*/         
     293        // Total dose
     294        ofs << std::setw(width) << "Dose";
     295
     296        for (size_t l=0; l < ionStore.size(); l++)
     297        {
     298            G4String a = (ionStore[l].isPrimary) ? "_1":""; // is it a primary?
     299            ofs << std::setw(width) << ionStore[l].name + a <<
     300                std::setw(width) << ionStore[l].name  + a;
     301        }
     302        ofs << G4endl;
     303
     304/*
     305        // PDGencoding
     306        ofs << std::setprecision(6) << std::left <<
     307        "0\t0\t0\t";
     308
     309        // Total dose
     310        ofs << std::setw(width) << '0';
     311        for (size_t l=0; l < ionStore.size(); l++)
     312        {
     313        ofs << std::setw(width) << ionStore[l].PDGencoding  <<
     314        std::setw(width) << ionStore[l].PDGencoding;
     315        }
     316        ofs << G4endl;
     317*/
     318        // Write data
     319        for(G4int i = 0; i < numberOfVoxelAlongX; i++)
     320            for(G4int j = 0; j < numberOfVoxelAlongY; j++)
     321                for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
     322                {
     323                    G4int n = Index(i, j, k);
     324                    // Write only not identically null data lines
     325                    if (matrix[n])
     326                    {
     327                        ofs << G4endl;
     328                        ofs << i << '\t' << j << '\t' << k << '\t';
     329                        // Total dose
     330                        ofs << std::setw(width) << matrix[n]/(doseUnit);
     331                        {
     332                            for (size_t l=0; l < ionStore.size(); l++)
     333                            {
     334                                // Fill ASCII file rows
     335                                ofs << std::setw(width) << ionStore[l].dose[n]/(doseUnit) <<
     336                                    std::setw(width) << ionStore[l].fluence[n];
     337                            }
     338                        }
     339                    }
     340                }
     341        ofs.close();
     342    }
     343}
     344/////////////////////////////////////////////////////////////////////////////
     345
     346#ifdef G4ANALYSIS_USE_ROOT
     347void HadrontherapyMatrix::StoreDoseFluenceRoot()
     348{
     349    HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::GetInstance();
     350    for(G4int i = 0; i < numberOfVoxelAlongX; i++)
     351        for(G4int j = 0; j < numberOfVoxelAlongY; j++)
     352            for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
     353            {
     354                G4int n = Index(i, j, k);
     355                for (size_t l=0; l < ionStore.size(); l++)
     356
     357                {
     358                    // Do the same work for .root file: fill dose/fluence ntuple 
     359                    analysis -> FillVoxelFragmentTuple( i, j, k,
     360                                                        ionStore[l].A,
     361                                                        ionStore[l].Z,
     362                                                        ionStore[l].dose[n]/(doseUnit),
     363                                                        ionStore[l].fluence[n] );
     364
     365
     366                }
     367            }
     368}
     369#endif
    92370
    93371void HadrontherapyMatrix::Fill(G4int i, G4int j, G4int k,
    94372                               G4double energyDeposit)
    95373{
    96   if (matrix)
    97     matrix[Index(i,j,k)] += energyDeposit;
    98  
    99   // Store the energy deposit in the matrix element corresponding
    100   // to the phantom voxel  i, j, k
    101 }
    102 
     374    if (matrix)
     375                matrix[Index(i,j,k)] += energyDeposit;
     376       
     377    // Store the energy deposit in the matrix element corresponding
     378    // to the phantom voxel 
     379}
    103380void HadrontherapyMatrix::TotalEnergyDeposit()
    104381{
     382  // Convert energy deposited to dose.
    105383  // Store the information of the matrix in a ntuple and in
    106384  // a 1D Histogram
    107385
    108   G4int k;
    109   G4int j;
    110   G4int i;
    111  
    112   if (matrix)
     386#ifdef G4ANALYSIS_USE_ROOT
     387    HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::GetInstance();
     388#endif
     389    if (matrix)
    113390    { 
    114       std::ofstream ofs;       
    115       ofs.open("DoseDistribution.out");
    116      
    117       for(G4int l = 0; l < numberVoxelZ; l++)
    118         {
    119           k = l;
    120          
    121           for(G4int m = 0; m < numberVoxelY; m++)
    122             {
    123               j = m * numberVoxelZ + k;
    124                
    125                 for(G4int n = 0; n <  numberVoxelX; n++)
    126                   {
    127                     i =  n* numberVoxelZ * numberVoxelY + j;
    128                     if(matrix[i] != 0)
    129                       {
    130                         ofs << n << '\t' << m << '\t' <<
    131                           k << '\t' << matrix[i] << G4endl;
    132                        
    133 #ifdef ANALYSIS_USE
    134                         HadrontherapyAnalysisManager* analysis =
    135                         HadrontherapyAnalysisManager::getInstance();
    136                         analysis -> FillEnergyDeposit(n, m, k, matrix[i]);
    137                         analysis -> BraggPeak(n, matrix[i]);
     391        for(G4int i = 0; i < numberOfVoxelAlongX; i++)
     392            for(G4int j = 0; j < numberOfVoxelAlongY; j++)
     393                for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
     394                {
     395                    G4int n = Index(i,j,k);
     396                    matrix[n] = matrix[n] / massOfVoxel;
     397#ifdef G4ANALYSIS_USE_ROOT
     398                    analysis -> FillEnergyDeposit(i, j, k, matrix[n]/doseUnit);
     399                    analysis -> BraggPeak(i, matrix[n]/doseUnit);
    138400#endif
    139                       }
    140 }       
    141               }
    142           }
    143     }
    144 }
     401                }
     402    }
     403}
     404
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyPhysicsList.cc

    r1230 r1313  
    7676//                        and local physic for ion-ion enelastic processes)
    7777
     78#include "G4RunManager.hh"
     79#include "G4Region.hh"
     80#include "G4RegionStore.hh"
    7881#include "HadrontherapyPhysicsList.hh"
    7982#include "HadrontherapyPhysicsListMessenger.hh"
     
    8689#include "LocalINCLIonIonInelasticPhysic.hh"         // Physic dedicated to the ion-ion inelastic processes using INCL/ABLA
    8790
    88 // Physic lists (contained inside the Geant4 distribution)
     91// Physic lists (contained inside the Geant4 source code, in the 'physicslists folder')
    8992#include "G4EmStandardPhysics_option3.hh"
    9093#include "G4EmLivermorePhysics.hh"
     
    173176{
    174177  // transportation
    175   //
    176178  AddTransportation();
    177179
    178180  // electromagnetic physics list
    179   //
    180181  emPhysicsList->ConstructProcess();
    181182  em_config.AddModels();
    182183
    183184  // decay physics list
    184   //
    185185  decPhysicsList->ConstructProcess();
    186186
     
    207207  //   ELECTROMAGNETIC MODELS
    208208  /////////////////////////////////////////////////////////////////////////////
    209 
    210   if (name == "standard_opt3") {
     209    if (name == "standard_opt3") {
    211210    emName = name;
    212211    delete emPhysicsList;
    213212    emPhysicsList = new G4EmStandardPhysics_option3();
     213    G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
    214214    G4cout << "THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmStandardPhysics_option3" << G4endl;
    215215
     
    218218    delete emPhysicsList;
    219219    emPhysicsList = new G4EmLivermorePhysics();
     220    G4RunManager::GetRunManager()-> PhysicsHasBeenModified();
    220221    G4cout << "THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmLivermorePhysics" << G4endl;
    221222
     
    308309  SetCutValue(cutForPositron, "e+");
    309310
     311  // Set cuts for detector
     312  SetDetectorCut(defaultCutValue);
    310313  if (verboseLevel>0) DumpCutValuesTable();
    311314}
     
    331334  SetParticleCuts(cutForPositron, G4Positron::Positron());
    332335}
     336
     337void HadrontherapyPhysicsList::SetDetectorCut(G4double cut)
     338{
     339
     340  G4String regionName = "DetectorLog";
     341  G4Region* region = G4RegionStore::GetInstance()->GetRegion(regionName);
     342
     343  G4ProductionCuts* cuts = new G4ProductionCuts ;
     344  cuts -> SetProductionCut(cut,G4ProductionCuts::GetIndex("gamma"));
     345  cuts -> SetProductionCut(cut,G4ProductionCuts::GetIndex("e-"));
     346  cuts -> SetProductionCut(cut,G4ProductionCuts::GetIndex("e+"));
     347  region -> SetProductionCuts(cuts);
     348}
     349
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyPhysicsListMessenger.cc

    r1230 r1313  
    6969  allCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 
    7070
     71  allDetectorCmd = new G4UIcmdWithADoubleAndUnit("/physic/setDetectorCuts",this); 
     72  allDetectorCmd->SetGuidance("Set cut for all. into Detector");
     73  allDetectorCmd->SetParameterName("cut",false);
     74  allDetectorCmd->SetUnitCategory("Length");
     75  allDetectorCmd->SetRange("cut>0.0");
     76  allDetectorCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 
     77
    7178  pListCmd = new G4UIcmdWithAString("/physic/addPhysics",this); 
    7279  pListCmd->SetGuidance("Add physics list.");
    7380  pListCmd->SetParameterName("PList",false);
    74   pListCmd->AvailableForStates(G4State_PreInit); 
     81  pListCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 
    7582
    7683  packageListCmd = new G4UIcmdWithAString("/physic/addPackage",this);
    7784  packageListCmd->SetGuidance("Add physics package.");
    7885  packageListCmd->SetParameterName("package",false);
    79   packageListCmd->AvailableForStates(G4State_PreInit);
     86  packageListCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
    8087}
    8188
     
    8794  delete protoCutCmd;
    8895  delete allCutCmd;
     96  delete allDetectorCmd;
    8997  delete pListCmd;
    9098  delete physDir;   
     
    99107   { pPhysicsList->SetCutForGamma(gammaCutCmd->GetNewDoubleValue(newValue));}
    100108     
    101   if( command == electCutCmd )
     109  else if( command == electCutCmd )
    102110   { pPhysicsList->SetCutForElectron(electCutCmd->GetNewDoubleValue(newValue));}
    103111     
    104   if( command == protoCutCmd )
     112  else if( command == protoCutCmd )
    105113   { pPhysicsList->SetCutForPositron(protoCutCmd->GetNewDoubleValue(newValue));}
    106114
    107   if( command == allCutCmd )
     115  else if( command == allCutCmd )
    108116    {
    109117      G4double cut = allCutCmd->GetNewDoubleValue(newValue);
     
    112120      pPhysicsList->SetCutForPositron(cut);
    113121    }
    114 
    115   if( command == pListCmd )
     122  else if( command == allDetectorCmd)
     123  {
     124      G4double cut = allDetectorCmd -> GetNewDoubleValue(newValue);
     125      pPhysicsList -> SetDetectorCut(cut);
     126  }
     127  else if( command == pListCmd )
    116128   { pPhysicsList->AddPhysicsList(newValue);}
    117129
    118130
    119   if( command == packageListCmd )
     131  else if( command == packageListCmd )
    120132   { pPhysicsList->AddPackage(newValue);}
    121133
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyPrimaryGeneratorAction.cc

    r1230 r1313  
    8686  sigmaEnergy = defaultsigmaEnergy;
    8787 
    88 #ifdef ANALYSIS_USE
     88#ifdef G4ANALYSIS_USE_ROOT
    8989  // Write these values into the analysis if needed. Have to be written separately on change.
    90   HadrontherapyAnalysisManager::getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
     90  HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
    9191#endif
    9292
     
    120120void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
    121121{
    122 #ifdef ANALYSIS_USE
     122#ifdef G4ANALYSIS_USE_ROOT
    123123  // Increment the event counter
    124   HadrontherapyAnalysisManager::getInstance()->startNewEvent();
     124  HadrontherapyAnalysisManager::GetInstance()->startNewEvent();
    125125#endif
    126126
     
    178178{
    179179        meanKineticEnergy = val;
    180 #ifdef ANALYSIS_USE
     180#ifdef G4ANALYSIS_USE_ROOT
    181181  // Update the beam-data in the analysis manager
    182   HadrontherapyAnalysisManager::getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
     182  HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
    183183#endif
    184184
     
    188188{
    189189        sigmaEnergy = val;
    190 #ifdef ANALYSIS_USE
     190#ifdef G4ANALYSIS_USE_ROOT
    191191  // Update the sigmaenergy in the metadata.
    192   HadrontherapyAnalysisManager::getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
     192  HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
    193193#endif
    194194}
     
    217217G4double HadrontherapyPrimaryGeneratorAction::GetmeanKineticEnergy(void)
    218218{ return meanKineticEnergy;}
     219
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapyRunAction.cc

    r1230 r1313  
    2727// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
    2828
     29
    2930#include "HadrontherapyRunAction.hh"
    3031#include "HadrontherapyEventAction.hh"
     
    3839#include "HadrontherapyRunAction.hh"
    3940
     41
     42#include "HadrontherapyAnalysisManager.hh"
     43#include "HadrontherapyMatrix.hh"
     44
    4045HadrontherapyRunAction::HadrontherapyRunAction()
    4146{
     
    4853void HadrontherapyRunAction::BeginOfRunAction(const G4Run* aRun)
    4954{       
    50    G4RunManager::GetRunManager()->SetRandomNumberStore(true);
    51    G4cout << "Run " << aRun -> GetRunID() << " starts ..." << G4endl;
     55    G4RunManager::GetRunManager()-> SetRandomNumberStore(true);
     56    G4cout << "Run " << aRun -> GetRunID() << " starts ..." << G4endl;
    5257
    53    electromagnetic = 0;
    54    hadronic = 0;
     58    // Warning! any beamOn will reset all data (dose, fluence, histograms, etc)!
     59    //
     60
     61    // Initialize matrix with energy of primaries clearing data inside
     62    if (HadrontherapyMatrix::GetInstance())
     63    {
     64        HadrontherapyMatrix::GetInstance() -> Initialize();
     65    }
     66
     67#ifdef G4ANALYSIS_USE_ROOT
     68    HadrontherapyAnalysisManager::GetInstance() -> flush();     // Finalize the root file
     69    // Initialize root analysis ----> book
     70    HadrontherapyAnalysisManager::GetInstance() -> book();
     71#endif
     72    electromagnetic = 0;
     73    hadronic = 0;
    5574}
    5675
    5776void HadrontherapyRunAction::EndOfRunAction(const G4Run*)
    5877{
    59   //   G4cout << " Summary of Run " << aRun -> GetRunID() <<" :"<< G4endl;
    60   //G4cout << "Number of electromagnetic processes of primary particles in the phantom:"
    61   //     << electromagnetic << G4endl;
    62   //G4cout << "Number of hadronic processes of primary particles in the phantom:"
    63   //     << hadronic << G4endl;
     78    // Store dose & fluence data to ASCII & ROOT files
     79    if ( HadrontherapyMatrix::GetInstance() )
     80    {
     81        HadrontherapyMatrix::GetInstance() -> TotalEnergyDeposit();
     82        HadrontherapyMatrix::GetInstance() -> StoreDoseFluenceAscii();
     83
     84#ifdef G4ANALYSIS_USE_ROOT
     85        if (HadrontherapyAnalysisManager::GetInstance())
     86        {
     87            HadrontherapyMatrix::GetInstance() -> StoreDoseFluenceRoot();
     88        }
     89#endif
     90    }
     91
     92    //G4cout << " Summary of Run " << aRun -> GetRunID() <<" :"<< G4endl;
     93    //G4cout << "Number of electromagnetic processes of primary particles in the phantom:"
     94    //     << electromagnetic << G4endl;
     95    //G4cout << "Number of hadronic processes of primary particles in the phantom:"
     96    //     << hadronic << G4endl;
    6497}
    6598void HadrontherapyRunAction::AddEMProcess()
     
    72105}
    73106
    74 
    75 
  • trunk/examples/advanced/hadrontherapy/src/HadrontherapySteppingAction.cc

    r1230 r1313  
    3939#include "G4ParticleDefinition.hh"
    4040#include "G4ParticleTypes.hh"
     41#include "G4UserEventAction.hh"
    4142
    4243#include "HadrontherapyAnalysisManager.hh"
     
    4748HadrontherapySteppingAction::HadrontherapySteppingAction( HadrontherapyRunAction *run)
    4849{
    49   runAction = run;
     50    runAction = run;
    5051}
    5152
     
    5859void HadrontherapySteppingAction::UserSteppingAction(const G4Step* aStep)
    5960{
     61    /*
     62    // USEFULL METHODS TO RETRIEVE INFORMATION DURING THE STEPS
     63    if( (aStep->GetTrack()->GetVolume()->GetName() == "DetectorPhys")
     64    && aStep->GetTrack()->GetDefinition()->GetParticleName() == "proton")
     65    //G4int evtNb = G4RunManager::GetRunManager()->GetCurrentEvent() -> GetEventID();
     66    {
     67    G4cout << "ENERGIA:   " << aStep->GetTrack()->GetKineticEnergy()
     68    << "   VOLUME  " << aStep->GetTrack()->GetVolume()->GetName()
     69    << "   MATERIALE    " <<  aStep -> GetTrack() -> GetMaterial() -> GetName()
     70    << "   EVENTO     " << G4RunManager::GetRunManager()->GetCurrentEvent() -> GetEventID()
     71    << "   POS     " << aStep->GetTrack()->GetPosition().x()
     72    << G4endl;
     73    }
     74    */
     75
    6076    if( aStep->GetTrack()->GetVolume()->GetName() == "NewDetectorPhys"){
    61 #ifdef ANALYSIS_USE
    62       G4ParticleDefinition *def = aStep->GetTrack()->GetDefinition();
    63       G4double secondaryParticleKineticEnergy =  aStep->GetTrack()->GetKineticEnergy();     
    64       G4String particleType = def->GetParticleType(); // particle type = nucleus for d, t, He3, alpha, and heavier nuclei
    65       G4String particleName = def->GetParticleName(); // e.g. for alpha: the name = "alpha" and type = "nucleus"
    66       if(particleType == "nucleus") {
    67         G4int A = def->GetBaryonNumber();
    68         G4double Z = def->GetPDGCharge();
    69         G4double posX = aStep->GetTrack()->GetPosition().x() / cm;
    70         G4double posY = aStep->GetTrack()->GetPosition().y() / cm;
    71         G4double posZ = aStep->GetTrack()->GetPosition().z() / cm;
    72         G4double energy = secondaryParticleKineticEnergy / A / MeV;
    73 
    74         HadrontherapyAnalysisManager* analysisMgr =  HadrontherapyAnalysisManager::getInstance();   
    75         analysisMgr->fillFragmentTuple(A, Z, energy, posX, posY, posZ);
    76       } else if(particleName == "proton") {   // proton (hydrogen-1) is a special case
    77         G4double posX = aStep->GetTrack()->GetPosition().x() / cm ;
    78         G4double posY = aStep->GetTrack()->GetPosition().y() / cm ;
    79         G4double posZ = aStep->GetTrack()->GetPosition().z() / cm ;
    80         G4double energy = secondaryParticleKineticEnergy * MeV;    // Hydrogen-1: A = 1, Z = 1
    81         HadrontherapyAnalysisManager::getInstance()->fillFragmentTuple(1, 1.0, energy, posX, posY, posZ);
    82       }
    83 
    84       G4String secondaryParticleName =  def -> GetParticleName(); 
    85       //G4cout <<"Particle: " << secondaryParticleName << G4endl;
    86       //G4cout <<"Energy: " << secondaryParticleKineticEnergy << G4endl;
    87         HadrontherapyAnalysisManager* analysis =  HadrontherapyAnalysisManager::getInstance();   
     77#ifdef G4ANALYSIS_USE_ROOT
     78        G4ParticleDefinition *def = aStep->GetTrack()->GetDefinition();
     79        G4double secondaryParticleKineticEnergy =  aStep->GetTrack()->GetKineticEnergy();     
     80        G4String particleType = def->GetParticleType(); // particle type = nucleus for d, t, He3, alpha, and heavier nuclei
     81        G4String particleName = def->GetParticleName(); // e.g. for alpha: the name = "alpha" and type = "nucleus"
     82        if(particleType == "nucleus") {
     83            G4int A = def->GetBaryonNumber();
     84            G4double Z = def->GetPDGCharge();
     85            G4double posX = aStep->GetTrack()->GetPosition().x() / cm;
     86            G4double posY = aStep->GetTrack()->GetPosition().y() / cm;
     87            G4double posZ = aStep->GetTrack()->GetPosition().z() / cm;
     88            G4double energy = secondaryParticleKineticEnergy / A / MeV;
     89
     90            HadrontherapyAnalysisManager* analysisMgr =  HadrontherapyAnalysisManager::GetInstance();   
     91            analysisMgr->FillFragmentTuple(A, Z, energy, posX, posY, posZ);
     92        } else if(particleName == "proton") {   // proton (hydrogen-1) is a special case
     93            G4double posX = aStep->GetTrack()->GetPosition().x() / cm ;
     94            G4double posY = aStep->GetTrack()->GetPosition().y() / cm ;
     95            G4double posZ = aStep->GetTrack()->GetPosition().z() / cm ;
     96            G4double energy = secondaryParticleKineticEnergy * MeV;    // Hydrogen-1: A = 1, Z = 1
     97            HadrontherapyAnalysisManager::GetInstance()->FillFragmentTuple(1, 1.0, energy, posX, posY, posZ);
     98        }
     99
     100        G4String secondaryParticleName =  def -> GetParticleName(); 
     101        //G4cout <<"Particle: " << secondaryParticleName << G4endl;
     102        //G4cout <<"Energy: " << secondaryParticleKineticEnergy << G4endl;
     103        HadrontherapyAnalysisManager* analysis =  HadrontherapyAnalysisManager::GetInstance();   
    88104        //There is a bunch of stuff recorded with the energy 0, something should perhaps be done about this.
    89105        if(secondaryParticleName == "proton") {
    90           analysis->hydrogenEnergy(secondaryParticleKineticEnergy / MeV);
     106            analysis->hydrogenEnergy(secondaryParticleKineticEnergy / MeV);
    91107        }
    92108        if(secondaryParticleName == "deuteron") {
    93           analysis->hydrogenEnergy((secondaryParticleKineticEnergy/2) / MeV);
     109            analysis->hydrogenEnergy((secondaryParticleKineticEnergy/2) / MeV);
    94110        }
    95111        if(secondaryParticleName == "triton") {
    96           analysis->hydrogenEnergy((secondaryParticleKineticEnergy/3) / MeV);
     112            analysis->hydrogenEnergy((secondaryParticleKineticEnergy/3) / MeV);
    97113        }
    98114        if(secondaryParticleName == "alpha") {
    99           analysis->heliumEnergy((secondaryParticleKineticEnergy/4) / MeV);
     115            analysis->heliumEnergy((secondaryParticleKineticEnergy/4) / MeV);
    100116        }
    101117        if(secondaryParticleName == "He3"){
    102           analysis->heliumEnergy((secondaryParticleKineticEnergy/3) / MeV);             
     118            analysis->heliumEnergy((secondaryParticleKineticEnergy/3) / MeV);           
    103119        }
    104120#endif
     
    107123    }
    108124
    109   // Electromagnetic and hadronic processes of primary particles in the phantom
    110   //setting phantomPhys correctly will break something here fixme
    111   if ((aStep -> GetTrack() -> GetTrackID() == 1) &&
    112     (aStep -> GetTrack() -> GetVolume() -> GetName() == "PhantomPhys") &&
    113     (aStep -> GetPostStepPoint() -> GetProcessDefinedStep() != NULL))
     125    // Electromagnetic and hadronic processes of primary particles in the phantom
     126    //setting phantomPhys correctly will break something here fixme
     127    if ((aStep -> GetTrack() -> GetTrackID() == 1) &&
     128            (aStep -> GetTrack() -> GetVolume() -> GetName() == "PhantomPhys") &&
     129            (aStep -> GetPostStepPoint() -> GetProcessDefinedStep() != NULL))
     130    {
     131        G4String process = aStep -> GetPostStepPoint() ->
     132            GetProcessDefinedStep() -> GetProcessName();
     133
     134        if ((process == "Transportation") || (process == "StepLimiter")) {;}
     135        else
     136        {
     137            if ((process == "msc") || (process == "hLowEIoni") || (process == "hIoni"))
     138            {
     139                runAction -> AddEMProcess();
     140            }
     141            else 
    114142            {
    115               G4String process = aStep -> GetPostStepPoint() ->
    116                 GetProcessDefinedStep() -> GetProcessName();
    117  
    118               if ((process == "Transportation") || (process == "StepLimiter")) {;}
    119               else {
    120                 if ((process == "msc") || (process == "hLowEIoni") || (process == "hIoni"))
    121                   {
    122                     runAction -> AddEMProcess();
    123                   }
    124                 else 
    125                  {
    126                    runAction -> AddHadronicProcess();
    127 
    128                    if ( (process != "LElastic") && (process != "ProtonInelastic") && (process != "hElastic") )
    129                      G4cout << "Warning! Unknown proton process: "<< process << G4endl;
    130                  }
    131               }         
     143                runAction -> AddHadronicProcess();
     144
     145                if ( (process != "LElastic") && (process != "ProtonInelastic") && (process != "hElastic") )
     146                    G4cout << "Warning! Unknown proton process: "<< process << G4endl;
    132147            }
    133 
    134  // Retrieve information about the secondaries originated in the phantom
    135 
    136  G4SteppingManager*  steppingManager = fpSteppingManager;
    137  
    138   // check if it is alive
    139   //if(theTrack-> GetTrackStatus() == fAlive) { return; }
    140 
    141   // Retrieve the secondary particles
    142   G4TrackVector* fSecondary = steppingManager -> GetfSecondary();
    143      
    144   for(size_t lp1=0;lp1<(*fSecondary).size(); lp1++)
     148        }         
     149    }
     150
     151    // Retrieve information about the secondaries originated in the phantom
     152
     153    G4SteppingManager*  steppingManager = fpSteppingManager;
     154
     155    // check if it is alive
     156    //if(theTrack-> GetTrackStatus() == fAlive) { return; }
     157
     158    // Retrieve the secondary particles
     159    G4TrackVector* fSecondary = steppingManager -> GetfSecondary();
     160
     161    for(size_t lp1=0;lp1<(*fSecondary).size(); lp1++)
    145162    {
    146       G4String volumeName = (*fSecondary)[lp1] -> GetVolume() -> GetName();
    147  
    148       if (volumeName == "phantomPhys")
     163        G4String volumeName = (*fSecondary)[lp1] -> GetVolume() -> GetName();
     164
     165        if (volumeName == "phantomPhys")
    149166        {
    150 #ifdef ANALYSIS_USE   
    151           G4String secondaryParticleName =  (*fSecondary)[lp1]->GetDefinition() -> GetParticleName(); 
    152           G4double secondaryParticleKineticEnergy =  (*fSecondary)[lp1] -> GetKineticEnergy();     
    153 
    154           HadrontherapyAnalysisManager* analysis =  HadrontherapyAnalysisManager::getInstance();   
    155        
    156           if (secondaryParticleName == "e-")
    157             analysis -> electronEnergyDistribution(secondaryParticleKineticEnergy/MeV);
    158                    
    159           if (secondaryParticleName == "gamma")
    160             analysis -> gammaEnergyDistribution(secondaryParticleKineticEnergy/MeV);
    161 
    162           if (secondaryParticleName == "deuteron")
    163             analysis -> deuteronEnergyDistribution(secondaryParticleKineticEnergy/MeV);
    164        
    165           if (secondaryParticleName == "triton")
    166             analysis -> tritonEnergyDistribution(secondaryParticleKineticEnergy/MeV);
    167            
    168           if (secondaryParticleName == "alpha")
    169             analysis -> alphaEnergyDistribution(secondaryParticleKineticEnergy/MeV);
    170        
    171           G4double z = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetPDGCharge();
    172           if (z > 0.)
    173             {     
    174               G4int a = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetBaryonNumber();
    175               G4int electronOccupancy = (*fSecondary)[lp1] ->  GetDynamicParticle() -> GetTotalOccupancy();
    176              
    177               // If a generic ion is originated in the detector, its baryonic number, PDG charge,
    178               // total number of electrons in the orbitals are stored in a ntuple
    179               analysis -> genericIonInformation(a, z, electronOccupancy, secondaryParticleKineticEnergy/MeV);
     167#ifdef G4ANALYSIS_USE_ROOT   
     168            G4String secondaryParticleName =  (*fSecondary)[lp1]->GetDefinition() -> GetParticleName(); 
     169            G4double secondaryParticleKineticEnergy =  (*fSecondary)[lp1] -> GetKineticEnergy();     
     170
     171            HadrontherapyAnalysisManager* analysis =  HadrontherapyAnalysisManager::GetInstance();   
     172
     173            if (secondaryParticleName == "e-")
     174                analysis -> electronEnergyDistribution(secondaryParticleKineticEnergy/MeV);
     175
     176            if (secondaryParticleName == "gamma")
     177                analysis -> gammaEnergyDistribution(secondaryParticleKineticEnergy/MeV);
     178
     179            if (secondaryParticleName == "deuteron")
     180                analysis -> deuteronEnergyDistribution(secondaryParticleKineticEnergy/MeV);
     181
     182            if (secondaryParticleName == "triton")
     183                analysis -> tritonEnergyDistribution(secondaryParticleKineticEnergy/MeV);
     184
     185            if (secondaryParticleName == "alpha")
     186                analysis -> alphaEnergyDistribution(secondaryParticleKineticEnergy/MeV);
     187
     188            G4double z = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetPDGCharge();
     189            if (z > 0.)
     190            {     
     191                G4int a = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetBaryonNumber();
     192                G4int electronOccupancy = (*fSecondary)[lp1] ->  GetDynamicParticle() -> GetTotalOccupancy();
     193
     194                // If a generic ion is originated in the detector, its baryonic number, PDG charge,
     195                // total number of electrons in the orbitals are stored in a ntuple
     196                analysis -> genericIonInformation(a, z, electronOccupancy, secondaryParticleKineticEnergy/MeV);
    180197            }
    181198#endif
Note: See TracChangeset for help on using the changeset viewer.