Geant4  10.03
HadrontherapyAnalysisFileMessenger.cc
Go to the documentation of this file.
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 // Hadrontherapy advanced example for Geant4
27 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
28 
31 #include "G4UIcmdWithAString.hh"
32 #include "G4UIcmdWithABool.hh"
33 #include "G4UIdirectory.hh"
34 #include "G4SystemOfUnits.hh"
35 
36 #include "HadrontherapyMatrix.hh"
37 #include "HadrontherapyLet.hh"
38 
41 :AnalysisManager(amgr)
42 {
43  secondaryCmd = new G4UIcmdWithABool("/analysis/secondary",this);
44  secondaryCmd -> SetParameterName("secondary", true);
45  secondaryCmd -> SetDefaultValue("true");
46  secondaryCmd -> SetGuidance("Set if dose/fluence for the secondary particles will be written"
47  "\n[usage]: /analysis/secondary [true/false]");
48  secondaryCmd -> AvailableForStates(G4State_Idle, G4State_PreInit);
49 
50  DoseMatrixCmd = new G4UIcmdWithAString("/analysis/writeDoseFile",this);
51  DoseMatrixCmd->SetGuidance("Write the dose/fluence to an ASCII file");
52  DoseMatrixCmd->SetDefaultValue("Dose.out");
53  DoseMatrixCmd->SetParameterName("choice",true);
54 
55  // With this messenger you can:
56  // give a name to the generated .root file
57  // One can use this messenger to define a different .root file name other then the default one
58 #ifdef G4ANALYSIS_USE_ROOT
59  FileNameCmd = new G4UIcmdWithAString("/analysis/setAnalysisFile",this);
60  FileNameCmd->SetGuidance("Set the .root filename for the root-output");
61  FileNameCmd->SetDefaultValue("default.root");
62  FileNameCmd->SetParameterName("choice",true);
63  FileNameCmd->AvailableForStates(G4State_Idle,G4State_PreInit);
64 #endif
65 
66 
67 LetCmd = new G4UIcmdWithABool("/analysis/computeLet",this);
68  LetCmd -> SetParameterName("choice",true);
69  LetCmd -> SetDefaultValue(true);
70  LetCmd -> SetGuidance("Set if Let must be computed and write the ASCII filename for the Let");
71  LetCmd -> AvailableForStates(G4State_Idle, G4State_PreInit);
72 
73 
74 
75 }
76 
79 {
80  delete secondaryCmd;
81  delete DoseMatrixCmd;
82  delete LetCmd;
83 
84 #ifdef G4ANALYSIS_USE_ROOT
85  delete FileNameCmd;
86 #endif
87 }
88 
91 {
92  if (command == secondaryCmd)
93  {
95  {
96  HadrontherapyMatrix::GetInstance() -> secondary = secondaryCmd -> GetNewBoolValue(newValue);
97  }
98  }
99 
100  else if (command == DoseMatrixCmd) // Filename can be passed here TODO
101  {
103  {
104  pMatrix -> TotalEnergyDeposit();
105  pMatrix -> StoreDoseFluenceAscii(newValue);
106 #ifdef G4ANALYSIS_USE_ROOT
107  pMatrix -> StoreDoseFluenceRoot();
108  HadrontherapyAnalysisManager::GetInstance() -> flush(); // Finalize & write the root file
109 #endif
110  }
111  }
112 
113  else if (command == LetCmd)
114  {
116  HadrontherapyLet::GetInstance() -> doCalculation = LetCmd -> GetNewBoolValue(newValue);
117  }
118 
119 #ifdef G4ANALYSIS_USE_ROOT
120  else if (command == FileNameCmd)
121  {
122  AnalysisManager->SetAnalysisFileName(newValue);
123  HadrontherapyAnalysisManager::GetInstance() -> book(); // Book for a new ROOT TFile
124  }
125 #endif
126 }
127 
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static HadrontherapyAnalysisManager * GetInstance()
Get the pointer to the analysis manager.
void SetNewValue(G4UIcommand *command, G4String newValue)
Called when new command given.
static HadrontherapyLet * GetInstance()
static HadrontherapyMatrix * GetInstance()
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetDefaultValue(const char *defVal)
A class for connecting the simulation to an analysis package.
G4UIcmdWithABool * LetCmd
G4 user interface command (that takes a string argument) object Constructor requires command name and...
HadrontherapyAnalysisFileMessenger(HadrontherapyAnalysisManager *)