Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunAction.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 // Please cite the following paper if you use this software
27 // Nucl.Instrum.Meth.B260:20-27, 2007
28 
29 // #define MATRIX_BOUND_CHECK
30 
31 #include "RunAction.hh"
32 #include "Analysis.hh"
33 #include "G4AutoLock.hh"
34 
35 namespace
36 {
38 }
39 
40 using namespace std;
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
43 
45 :fDetector(det),fPrimary(pri)
46 {;}
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
49 
51 {}
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
54 
55 void RunAction::BeginOfRunAction(const G4Run* /*aRun*/)
56 {
57  // Vector initialization
58 
59  fRow=0;
60 
61  fXVector = CLHEP::HepVector(32);
62  fYVector = CLHEP::HepVector(32);
63  fThetaVector = CLHEP::HepVector(32);
64  fPhiVector = CLHEP::HepVector(32);
65 
66  // Histograms
67 
68  // Get/create analysis manager
69  G4cout << "##### Create analysis manager " << " " << this << G4endl;
70 
71  G4AnalysisManager* man = G4AnalysisManager::Instance();
72 
73  G4cout << "Using " << man->GetType() << " analysis manager" << G4endl;
74 
75 
76  // Open an output file
77  man->OpenFile("nanobeam");
78  man->SetFirstHistoId(1);
79  man->SetFirstNtupleId(1);
80 
81  // Create 1st ntuple (id = 1)
82  //
83  man->CreateNtuple("ntuple0", "BeamProfile");
84  man->CreateNtupleDColumn("xIn");
85  man->CreateNtupleDColumn("yIn");
86  man->CreateNtupleDColumn("zIn");
87  man->FinishNtuple();
88  G4cout << "Ntuple-1 created" << G4endl;
89 
90  // Create 2nd htuple (id = 2)
91  //
92  man->CreateNtuple("ntuple1","Grid");
93  man->CreateNtupleDColumn("xIn");
94  man->CreateNtupleDColumn("yIn");
95  man->CreateNtupleDColumn("e");
96  man->FinishNtuple();
97  G4cout << "Ntuple-2 created" << G4endl;
98 
99  // Create 3rd ntuple (id = 3)
100  man->CreateNtuple("ntuple2","Coef");
101  man->CreateNtupleDColumn("xIn");
102  man->CreateNtupleDColumn("yIn");
103  man->CreateNtupleDColumn("thetaIn");
104  man->CreateNtupleDColumn("phiIn");
105  man->FinishNtuple();
106  G4cout << "Ntuple-3 created" << G4endl;
107 
108  return;
109 
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
113 
114 void RunAction::EndOfRunAction(const G4Run* /*aRun*/)
115 {
116 
117 if (fDetector->GetCoef()==1)
118 {
119  // 17/12/2013 - thanks to A. Dotti
120  // CLHEP Matrix inversion (as for CLHEP version 2.1.4.1)
121  // is not thread safe, we need to protect this code.
122  // Since this is not performance critical we simply lock
123  // all this part.
124  G4AutoLock l(&aMutex);
125  //
126 
127  CLHEP::HepMatrix m;
128 
129  // VECTOR READING
130  // VECTOR READING
131 
132  m = CLHEP::HepMatrix(32,32);
133  m = fPrimary->GetMatrix();
134 
135  G4cout << G4endl;
136  G4cout << "===> NANOBEAM LINE INTRINSIC ABERRATION COEFFICIENTS (units of micrometer and mrad) :" << G4endl;
137  G4cout << G4endl;
138 
139  int inv;
140 
141  m.invert(inv);
142  CLHEP::HepVector tmp(32,0);
143  tmp=m*fXVector;
144  CLHEP::HepVector b;
145  b=tmp.sub(2,2); G4cout << "<x|theta>=" << b << G4endl;
146  b=tmp.sub(8,8); G4cout << "<x|theta*delta>=" << b << G4endl;
147  b=tmp.sub(10,10); G4cout << "<x|theta^3>=" << b << G4endl;
148  b=tmp.sub(12,12); G4cout << "<x|theta*phi^2>=" << b << G4endl;
149  m.invert(inv);
150 
151  m.invert(inv);
152  tmp = m*fThetaVector;
153  m.invert(inv);
154  b=tmp.sub(2,2); G4cout << "<x|x>=" << b << G4endl;
155 
156  m.invert(inv);
157  tmp=m*fYVector;
158  b=tmp.sub(3,3); G4cout << "<y|phi>=" << b << G4endl;
159  b=tmp.sub(9,9); G4cout << "<y|phi*delta>=" << b << G4endl;
160  b=tmp.sub(11,11); G4cout << "<y|theta^2*phi>=" << b << G4endl;
161  b=tmp.sub(13,13); G4cout << "<y|phi^3>=" << b << G4endl;
162  m.invert(inv);
163 
164  m.invert(inv);
165  tmp = m*fPhiVector;
166  m.invert(inv);
167  b=tmp.sub(3,3); G4cout << "<y|y>=" << b << G4endl;
168 
169 }
170 
171  // Save histograms
172 
173  G4AnalysisManager* man = G4AnalysisManager::Instance();
174  man->Write();
175  man->CloseFile();
176 
177  // Complete clean-up
178 
179  delete G4AnalysisManager::Instance();
180 
181 }
The primary generator action class with particle gun.
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
tuple b
Definition: test.py:12
G4GLOB_DLL std::ostream G4cout
static constexpr double m
Definition: G4SIunits.hh:129
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4Mutex aMutex
Definition: G4Run.hh:46
~RunAction()
Definition: RunAction.cc:52
G4int G4Mutex
Definition: G4Threading.hh:173
Detector construction class to define materials and geometry.
#define G4endl
Definition: G4ios.hh:61
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77