ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analysis.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Analysis.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 //
26 //
29 
30 #include "G4AutoDelete.hh"
31 #include "G4SystemOfUnits.hh"
32 #include "Analysis.hh"
33 
34 //Select format of output here
35 //Note: ntuple merging is supported only with Root format
36 #include "g4root.hh"
37 #include "G4RootAnalysisManager.hh"
38 
39 
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 Analysis*
46 {
47  if (!the_analysis)
48  {
49  the_analysis = new Analysis();
51  }
52  return the_analysis;
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57  fUseNtuple(true),
58  fMergeNtuple(true),
59  fincident_x_hist(0), fincident_map(0), fdose_hist(0), fdose_map(0),
60  fdose_prof(0), fdose_map_prof(0), fdose_map3d(0)
61 {
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 void
67 {
68  G4cout << "Analysis::Book start, fUseNtuple: " << fUseNtuple << G4endl;
69 
71  mgr->SetVerboseLevel(1);
72 #ifdef G4MULTITHREADED
73  // MT ntuple merging
75 #endif
76 
77  fincident_x_hist = mgr->CreateH1("incident_x", "Incident X", 100, -5 * cm,
78  5 * cm, "cm");
79  fincident_map = mgr->CreateH2("incident_map", "Incident Map", 50, -5 * cm,
80  5 * cm, 50, -5 * cm, 5 * cm, "cm", "cm");
82  = mgr->CreateH1("dose", "Dose distribution", 500, 0, 50 * cm, "cm");
83  fdose_map = mgr->CreateH2("dose_map", "Dose distribution", 500, 0, 50 * cm,
84  200, -10 * cm, 10 * cm, "cm", "cm");
85  fdose_map3d = mgr->CreateH3("dose_map_3d", "Dose distribution", 30, 0,
86  50 * cm, 20, -10 * cm, 10 * cm, 20, -10 * cm, 10 * cm, "cm", "cm", "cm");
87  fdose_prof = mgr->CreateP1("dose_prof", "Dose distribution", 300, 0, 30 * cm,
88  0, 100 * MeV, "cm", "MeV");
89  fdose_map_prof = mgr->CreateP2("dose_map_prof", "Dose distribution", 300, 0,
90  30 * cm, 80, -4 * cm, 4 * cm, 0, 100 * MeV, "cm", "cm", "MeV");
91 
92  if ( fUseNtuple) {
93  mgr->CreateNtuple("Dose", "Dose distribution"); // ntuple Id = 0
94  mgr->CreateNtupleDColumn("pz");
95  mgr->CreateNtupleDColumn("px");
96  mgr->CreateNtupleDColumn("dose");
97  mgr->FinishNtuple();
98  }
99 
100  G4cout << "Analysis::Book finished " << G4endl;
101 }
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 {
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 void
111 {
113  mgr->OpenFile(fname.c_str());
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 void
119 {
121  mgr->Write();
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125 void
126 Analysis::Close(G4bool reset)
127 {
129  mgr->CloseFile(reset);
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133 void
135 {
136  if (!fincidentFlag)
137  {
139  mgr->FillH2(fincident_map, p.x(), p.y());
140  mgr->FillH1(fincident_x_hist, p.x());
141  fincidentFlag = true;
142  }
143 }
144 
145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
146 void
148 {
149  const G4double dxy = 10. * mm;
150  if (std::abs(p.y()) < dxy)
151  {
153  const G4double Z0 = 25. * cm;
154 
155  mgr->FillH2(fdose_map, p.z() + Z0, p.x(), dedx / GeV);
156  mgr->FillP2(fdose_map_prof, p.z() + Z0, p.x(), dedx);
157  mgr->FillH3(fdose_map3d, p.z() + Z0, p.x(), p.y(), dedx / GeV);
158  if (std::abs(p.x()) < dxy)
159  {
160  mgr->FillH1(fdose_hist, p.z() + Z0, dedx / GeV);
161  mgr->FillP1(fdose_prof, p.z() + Z0, dedx);
162  }
163 
164  if ( fUseNtuple ) {
165  // the same fill frequency as H2 "dose_map"
166  mgr->FillNtupleDColumn(0, p.z() + Z0);
167  mgr->FillNtupleDColumn(1, p.x());
168  mgr->FillNtupleDColumn(2, dedx / GeV);
169  mgr->AddNtupleRow();
170  }
171  }
172 
173 }