Geant4  10.02
Analysis.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 // $Id: Analysis.cc 88353 2015-02-16 08:54:08Z gcosmo $
27 //
30 
31 #include "TFile.h"
32 #include "TH1.h"
33 #include "TH2.h"
34 #include "TROOT.h"
35 #include "G4SystemOfUnits.hh"
36 #include "Analysis.hh"
37 #include "G4AutoLock.hh"
38 
41 
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 {
47  if ( ! the_analysis ) the_analysis = new Analysis;
48  return the_analysis;
49 }
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 {
54  G4AutoLock l(&rootm);
55  // define histograms
56  fincident_map = new TH2D("incident map", "Incident Distributuon",
57  50, -5., 5.,
58  50, -5., 5.);
59  fincident_map-> GetXaxis()-> SetTitle("X (cm)");
60  fincident_map-> GetYaxis()-> SetTitle("Y (cm)");
61  fincident_map-> SetStats(0);
62 
63  fincident_x_hist = new TH1D("incident x", "Incident X", 100, -5., 5.);
64  fincident_x_hist-> GetXaxis()-> SetTitle("X (cm)");
65  fincident_x_hist-> SetFillColor(kRed);
66 
67  fdose_map = new TH2D("dose map", "Dose Distribution",
68  500, 0., 50.,
69  200, -10., 10.);
70  fdose_map-> GetXaxis()-> SetTitle("Z (cm)");
71  fdose_map-> GetYaxis()-> SetTitle("X (cm)");
72  fdose_map-> SetStats(0);
73 
74  fdose_hist = new TH1D("dose", "Dose Distribution", 500, 0., 50.);
75  fdose_hist-> GetXaxis()-> SetTitle("Z (cm)");
76  fdose_hist-> GetYaxis()-> SetTitle("Dose (GeV)");
77  fdose_hist-> SetFillColor(kBlue);
78  fdose_hist-> SetStats(0);
79 }
80 
81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 {
84  delete fincident_map;
85  delete fincident_x_hist;
86  delete fdose_map;
87  delete fdose_hist;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 {
93  return;
94 }
95 
96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 {
99  fincident_map-> Reset();
100  fincident_x_hist-> Reset();
101  fdose_map-> Reset();
102  fdose_hist-> Reset();
103 
104  return;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
108 void Analysis::Save(const G4String& fname)
109 {
110  G4AutoLock l(&rootm);
111  TFile* file = new TFile(fname.c_str(), "RECREATE", "Geant4 ROOT analysis");
112 
113  fincident_map-> Write();
114  fincident_x_hist-> Write();
115  fdose_map-> Write();
116  fdose_hist-> Write();
117 
118  file-> Close();
119 
120  delete file;
121 
122  return;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127 {
128  if ( ! fincidentFlag ) {
129  fincident_map-> Fill(p.x()/cm, p.y()/cm);
130  fincident_x_hist-> Fill(p.x()/cm);
131 
132  fincidentFlag = true;
133  }
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
138 {
139  const G4double Z0 = 25.*cm;
140  const G4double dxy = 10.*mm;
141 
142  if ( std::abs(p.y()) < dxy ) {
143  fdose_map-> Fill((p.z()+Z0)/cm, p.x()/cm, dedx/GeV);
144 
145  if ( std::abs(p.x()) < dxy ) {
146  fdose_hist-> Fill((p.z()+Z0)/cm, dedx/GeV);
147  }
148  }
149 }
static const double cm
Definition: G4SIunits.hh:118
void Update()
Definition: Analysis.cc:91
CLHEP::Hep3Vector G4ThreeVector
void FillDose(const G4ThreeVector &p, G4double dedx)
Definition: Analysis.cc:137
#define G4ThreadLocal
Definition: tls.hh:89
void Close()
Definition: Analysis.cc:117
int G4int
Definition: G4Types.hh:78
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
G4Mutex rootm
Definition: Analysis.cc:42
TH1D * fdose_hist
Definition: Analysis.hh:66
TH2D * fincident_map
Definition: Analysis.hh:62
static Analysis * GetAnalysis()
Definition: Analysis.cc:45
void Save(const G4String &fname)
Definition: Analysis.cc:108
static const double GeV
Definition: G4SIunits.hh:214
Analysis()
Definition: Analysis.cc:52
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
void Clear()
Definition: Analysis.cc:97
TH1D * fincident_x_hist
Definition: Analysis.hh:63
TH2D * fdose_map
Definition: Analysis.hh:65
G4int G4Mutex
Definition: G4Threading.hh:173
static G4ThreadLocal G4int fincidentFlag
Definition: Analysis.hh:68
void FillIncident(const G4ThreeVector &p)
Definition: Analysis.cc:126
G4ThreadLocal Analysis * the_analysis
Definition: Analysis.cc:40
double G4double
Definition: G4Types.hh:76
static const double mm
Definition: G4SIunits.hh:114
~Analysis()
Definition: Analysis.cc:82