Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
39 G4ThreadLocal G4int Analysis::fincidentFlag = false;
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......
52 Analysis::Analysis()
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......
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 }
void Update()
Definition: Analysis.cc:91
static constexpr double mm
Definition: G4SIunits.hh:115
double x() const
const char * p
Definition: xmltok.h:285
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
double z() const
G4Mutex rootm
Definition: Analysis.cc:42
static Analysis * GetAnalysis()
Definition: Analysis.cc:45
static constexpr double cm
Definition: G4SIunits.hh:119
void Save(const G4String &fname)
Definition: Analysis.cc:108
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
void Clear()
Definition: Analysis.cc:97
G4int G4Mutex
Definition: G4Threading.hh:173
double y() const
void FillIncident(const G4ThreeVector &p)
Definition: Analysis.cc:126
static constexpr double GeV
Definition: G4SIunits.hh:217
string fname
Definition: test.py:308
G4ThreadLocal Analysis * the_analysis
Definition: Analysis.cc:40
double G4double
Definition: G4Types.hh:76
~Analysis()
Definition: Analysis.cc:82