Geant4  10.00.p01
BrachyAnalysisManager.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 Author: Susanna Guatelli
27 */
28 // The class BrachyAnalysisManager creates and manages histograms and ntuples
29 
30 // The analysis was included in this application following the extended Geant4
31 // example analysis/AnaEx01
32 
33 #include <stdlib.h>
34 #include "BrachyAnalysisManager.hh"
35 #include "G4UnitsTable.hh"
36 #include "G4SystemOfUnits.hh"
37 
39 {
40 
41 factoryOn = false;
42 
43 // Initialization
44 // histograms
45 for (G4int k=0; k<MaxHisto; k++) fHistId[k] = 0;
46 
47 // Initialization ntuple
48  for (G4int k=0; k<MaxNtCol; k++) {
49  fNtColId[k] = 0;
50  }
51 
53 
54 }
55 
57 {
58 }
59 
61 {
62  G4AnalysisManager* AnalysisManager = G4AnalysisManager::Instance();
63 
64  AnalysisManager->SetVerboseLevel(2);
65 
66  // Create a root file
67  G4String fileName = "brachytherapy.root";
68 
69  // Create directories
70  AnalysisManager->SetHistoDirectoryName("brachy_histo");
71  AnalysisManager->SetNtupleDirectoryName("brachy_ntuple");
72 
73 
74  G4bool fileOpen = AnalysisManager->OpenFile(fileName);
75  if (!fileOpen) {
76  G4cout << "\n---> HistoManager::book(): cannot open "
77  << fileName[1]
78  << G4endl;
79  return;
80  }
81 
82 //creating a 1D histograms
83  AnalysisManager->SetFirstHistoId(1);
84 
85  // Histogram containing the primary particle energy (MeV)
86  fHistId[1] = AnalysisManager -> CreateH1("1",
87  "Initial energy",
88  1000, 0., 1000.);
89 
90  //Parameters of CreateH1: histoID, histo name, bins' number, xmin, xmax
91 
92  primaryParticleSpectrum = AnalysisManager-> GetH1(fHistId[1]);
93 
94  //creating a ntuple, containg 3D energy deposition in the phantom
95  AnalysisManager -> CreateNtuple("1", "3Dedep");
96  fNtColId[0] = AnalysisManager->CreateNtupleDColumn("xx");
97  fNtColId[1] = AnalysisManager->CreateNtupleDColumn("yy");
98  fNtColId[2] = AnalysisManager->CreateNtupleDColumn("zz");
99  fNtColId[3] = AnalysisManager->CreateNtupleDColumn("edep");
100  AnalysisManager->FinishNtuple();
101 
102  factoryOn = true;
103 }
104 
106 {
107  // 1DHistogram: energy spectrum of primary particles
108  primaryParticleSpectrum -> fill(primaryParticleEnergy);
109 }
110 
112  G4double yy,
113  G4double zz,
114  G4double energyDep)
115 {
116  G4AnalysisManager* AnalysisManager = G4AnalysisManager::Instance();
117  AnalysisManager->FillNtupleDColumn(fNtColId[0], xx);
118  AnalysisManager->FillNtupleDColumn(fNtColId[1], yy);
119  AnalysisManager->FillNtupleDColumn(fNtColId[2], zz);
120  AnalysisManager->FillNtupleDColumn(fNtColId[3], energyDep);
121  AnalysisManager->AddNtupleRow();
122 }
123 
125 {
126  if (factoryOn)
127  {
128  G4AnalysisManager* AnalysisManager = G4AnalysisManager::Instance();
129  AnalysisManager->Write();
130  AnalysisManager->CloseFile();
131 
132  delete G4AnalysisManager::Instance();
133  factoryOn = false;
134  }
135 }
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
G4bool SetHistoDirectoryName(const G4String &dirName)
G4bool SetFirstHistoId(G4int firstId)
void SetVerboseLevel(G4int verboseLevel)
void FillPrimaryParticleHistogram(G4double)
G4bool SetNtupleDirectoryName(const G4String &dirName)
int G4int
Definition: G4Types.hh:78
void FillNtupleWithEnergyDeposition(G4double, G4double, G4double, G4double)
G4GLOB_DLL std::ostream G4cout
G4bool FillNtupleDColumn(G4int id, G4double value)
bool G4bool
Definition: G4Types.hh:79
const G4int MaxHisto
Definition: HistoManager.hh:47
const G4int MaxNtCol
#define G4endl
Definition: G4ios.hh:61
G4int CreateNtupleDColumn(const G4String &name)
double G4double
Definition: G4Types.hh:76