Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
extended/medical/GammaTherapy/src/HistoManager.cc
이 파일의 문서화 페이지로 가기
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 //
28 //
29 //
30 // $Id: HistoManager.cc 102694 2017-02-17 09:07:55Z maire $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "HistoManager.hh"
36 #include "G4SystemOfUnits.hh"
37 #include "DetectorConstruction.hh"
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40 
42 {
43 
44  fNBinsZ = 60;
45  fNBinsR = 80;
46  fNBinsE = 200;
47 
48  fAbsorberZ = 300.*mm;
49  fAbsorberR = 200.*mm;
50  fScoreZ = 100.*mm;
51  fMaxEnergy = 50.*MeV;
52 
53  fStepZ = fStepR = fStepE = 0.0;
54 
55  Book();
56 
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  delete G4AnalysisManager::Instance();
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
68 void HistoManager::Book()
69 {
70 
71  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
72 
73  // Create or get analysis manager
74  // The choice of analysis technology is done via selection of a namespace
75  // in HistoManager.hh
76  analysisManager->SetVerboseLevel(1);
77  analysisManager->SetActivation(true); // enable inactivation of histograms
78 
79  // Creating an 1-dimensional histograms in the root directory of the tree
80  fHisto.assign(10,0);
81  int iHisto=0;
82  fHisto[iHisto] = analysisManager->CreateH1("10",
83  "Energy deposit at radius (mm) normalised on 1st channel",
84  fNBinsR, 0., fAbsorberR/mm);
85 
86  iHisto++;
87  fHisto[iHisto] = analysisManager->CreateH1("11",
88  "Energy deposit at radius (mm) normalised to integral",
89  fNBinsR, 0., fAbsorberR/mm);
90 
91  iHisto++;
92  fHisto[iHisto] = analysisManager->CreateH1("12",
93  "Energy deposit (MeV/kg/electron) at radius (mm)",
94  fNBinsR, 0., fAbsorberR/mm);
95 
96  iHisto++;
97  fHisto[iHisto] = analysisManager->CreateH1("13",
98  "Energy profile (MeV/kg/electron) over Z (mm)",fNBinsZ,0.,fAbsorberZ/mm);
99 
100  iHisto++;
101  fHisto[iHisto] = analysisManager->CreateH1("14",
102  "Energy profile (MeV/kg/electron) over Z (mm) at Central Voxel",
103  fNBinsZ, 0., fAbsorberZ/mm);
104 
105  iHisto++;
106  fHisto[iHisto] = analysisManager->CreateH1("15",
107  "Energy (MeV) of fGamma produced in the target",
108  fNBinsE, 0., fMaxEnergy/MeV);
109 
110  iHisto++;
111  fHisto[iHisto] = analysisManager->CreateH1("16",
112  "Energy (MeV) of fGamma before phantom",fNBinsE,0.,fMaxEnergy/MeV);
113 
114  iHisto++;
115  fHisto[iHisto] = analysisManager->CreateH1("17",
116  "Energy (MeV) of electrons produced in phantom",fNBinsE,0.,fMaxEnergy/MeV);
117 
118  iHisto++;
119  fHisto[iHisto] = analysisManager->CreateH1("18",
120  "Energy (MeV) of electrons produced in target",fNBinsE,0.,fMaxEnergy/MeV);
121 
122  iHisto++;
123  fHisto[iHisto] = analysisManager->CreateH1("19",
124  "Gamma Energy Fluence (MeV/cm2) at radius(mm) in front of phantom",
125  fNBinsR, 0., fAbsorberR/mm);
126 
127  // Create all histograms as inactivated
128  // as we have not yet set nbins, vmin, vmax
129  for(int i=0; i<iHisto+1; i++) analysisManager->SetH1Activation(i, false);
130 
131 }
132 
133 
134 void HistoManager::Update(DetectorConstruction* det, bool bForceActivation)
135 {
136 
137  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
138 
139  if(bForceActivation) {
140  for(int i=0; i<(int)fHisto.size(); i++)
141  analysisManager->SetH1Activation(fHisto[i], true);
142  analysisManager->SetActivation(true);
143  }
144 
145  if(analysisManager->IsActive()) {
146 
147  // Check nBinsR / fAbsorberR histograms
148  if(det->GetNumberDivR()!=fNBinsR||
149  std::fabs(det->GetAbsorberR()-fAbsorberR)>0.01*mm)
150  {
151  fNBinsR = det->GetNumberDivR();
152  fAbsorberR = det->GetAbsorberR();
153  std::vector<G4int> histoId { 0, 1, 2, 9 };
154  for(auto v : histoId)
155  {
156  analysisManager->SetH1(fHisto[v], fNBinsR, 0., fAbsorberR/mm);
157  }
158 
159  }
160 
161  // Check nBinsZ / fAbsorberZ histograms
162  if(det->GetNumberDivZ()!=fNBinsZ||
163  std::fabs(det->GetAbsorberZ()-fAbsorberZ)>0.01*mm)
164  {
165  fNBinsZ = det->GetNumberDivZ();
166  fAbsorberZ = det->GetAbsorberZ();
167  std::vector<G4int> histoId { 3, 4 };
168  for(auto v : histoId)
169  {
170  analysisManager->SetH1(fHisto[v], fNBinsZ, 0., fAbsorberZ/mm);
171  }
172  }
173 
174  // Check nBinsE / fAbsorberE histograms
175  if(det->GetNumberDivE()!=fNBinsE||
176  std::fabs(det->GetMaxEnergy()-fMaxEnergy)>0.01)
177  {
178  fNBinsE = det->GetNumberDivE();
179  fMaxEnergy = det->GetMaxEnergy();
180  std::vector<G4int> histoId { 5, 6, 7 ,8 };
181  for(auto v : histoId)
182  {
183  analysisManager->SetH1(fHisto[v], fNBinsE, 0., fMaxEnergy/MeV);
184  }
185  }
186  }
187 
188 }
189 
190 
191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192 
194 {
195  if(!G4AnalysisManager::Instance()->IsActive()) return;
196 
197  for(int i=0; i<(int)fHisto.size(); i++)
198  {
199  G4int histoId=fHisto[i];
200  G4String title = G4AnalysisManager::Instance()->GetH1Title(histoId);
201  G4int nbins = G4AnalysisManager::Instance()->GetH1Nbins(histoId);
202  G4double xmin = G4AnalysisManager::Instance()->GetH1Xmin(histoId);
203  G4double xmax = G4AnalysisManager::Instance()->GetH1Xmax(histoId);
204  G4double width = G4AnalysisManager::Instance()->GetH1Width(histoId);
205  G4cout<<"Histogram parameters : "<<i<<" "<<histoId<<" : "<<nbins<<" ";
206  G4cout<<xmin<<"/"<<xmax<<" "<<width<<G4endl;
207 
208  }
209 
210 }
211 
212 
213 
214 
static constexpr double MeV
Definition: G4SIunits.hh:214
static constexpr double mm
Definition: G4SIunits.hh:115
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
#define width
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
void Update(DetectorConstruction *det, bool bForceActivation=false)
Simple detector construction with a box volume placed in a world.