Geant4  10.00.p01
GammaKnifeController.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 
27 
28 #include "GammaKnifeController.hh"
29 #include "G4UImanager.hh"
30 #include "G4RunManager.hh"
31 #include <fstream>
32 
33 #include "G4SystemOfUnits.hh"
34 
36 {
37  detector = det;
38 
39  messenger = new GammaKnifeMessenger( this );
40 }
41 
43 {
44  delete messenger;
45 }
46 
48 {
50  for (G4int i = 0; i < GAMMAKNIFE_SOURCES; i++)
51  {
52  RotateForward(i);
54 
55  if (i != (GAMMAKNIFE_SOURCES - 1))
56  StoreHits();
57 
58  RotateBack(i);
59  }
61 }
62 
64 {
65  // Rotate all scoring meshes to the right position
67  if (scm)
68  {
69  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
70  {
71  G4VScoringMesh * mesh = scm->GetMesh(i);
72  mesh->RotateX( thetaAngles[position] );
73  mesh->RotateZ( phiAngles[position] );
74  }
75  }
76 }
77 
79 {
81  if (scm)
82  {
83  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
84  {
85  G4VScoringMesh * mesh = scm->GetMesh(i);
86  mesh->RotateZ( - phiAngles[position] );
87  mesh->RotateX( - thetaAngles[position] );
88  }
89  }
90 }
91 
93 {
95  if (scm)
96  {
97  size_t size = scm->GetNumberOfMesh();
98  scoreMaps = new MeshScoreMap[size];
99  for (size_t i = 0; i < size; i++)
100  {
101  G4VScoringMesh * mesh = scm->GetMesh(i);
102 
103  MeshScoreMap scoreMap = mesh->GetScoreMap();
104  MeshScoreMap& storedScoreMap = scoreMaps[i];
105 
106  MeshScoreMap::iterator it = scoreMap.begin();
107  for( ; it != scoreMap.end(); it++)
108  {
109  std::string hitMapName = it->first;
110  G4THitsMap<G4double>* hitMapToStore = new G4THitsMap<G4double>("GammaKnifeController", hitMapName);
111  storedScoreMap[ hitMapName ] = hitMapToStore;
112  }
113  }
114  }
115 }
116 
118 {
120  if (scm)
121  {
122  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
123  {
124  G4VScoringMesh* mesh = scm->GetMesh(i);
125 
126 
127  MeshScoreMap scoreMap = mesh->GetScoreMap();
128  MeshScoreMap& storedScoreMap = scoreMaps[i];
129 
130  MeshScoreMap::iterator it = scoreMap.begin();
131  for( ; it != scoreMap.end(); it++)
132  {
133  std::string hitMapName = it->first;
134  *storedScoreMap[hitMapName] += *(it->second);
135  }
136  }
137  }
138 }
139 
141 {
143  if (scm)
144  {
145  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
146  {
147  G4VScoringMesh* mesh = scm->GetMesh(i);
148  MeshScoreMap& storedScoreMap = scoreMaps[i];
149  MeshScoreMap::iterator it = storedScoreMap.begin();
150  for( ; it != storedScoreMap.end(); it++)
151  {
152  mesh->Accumulate( it->second );
153  }
154  }
155  }
156 }
157 
158 void GammaKnifeController::ReadFile( std::string fileName )
159 {
160  //G4cout << "Enter ReadFile()...";
161  const int SZ = 100;
162  char buf[SZ];
163 
164  phiAngles.clear(); // If called for the second time
165  thetaAngles.clear(); // we won't have 402 positions...
166 
167  std::ifstream ifs;
168  ifs.open( fileName.c_str() );
169 
170  for (G4int i = 0; i < GAMMAKNIFE_SOURCES; i++)
171  {
172  G4double phi, theta;
173 
174  /* Skip the "Axx" at the beginning of the line */
175  for (G4int c = 0; c < 4; c++) ifs.get();
176 
177  ifs >> phi >> theta;
178  ifs.getline(buf, SZ); // Next line
179 
180  phiAngles.push_back( phi * degree );
181  thetaAngles.push_back( theta * degree );
182  }
183  ifs.close();
184  //G4cout << "... done " << G4endl;
185 }
std::map< G4String, G4THitsMap< G4double > * > MeshScoreMap
GammaKnifeDetectorConstruction * detector
void ReadFile(std::string fileName)
std::vector< G4double > phiAngles
void Accumulate(G4THitsMap< G4double > *map)
std::vector< G4double > thetaAngles
void RotateX(G4double delta)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
int G4int
Definition: G4Types.hh:78
GammaKnifeController(GammaKnifeDetectorConstruction *)
static G4ScoringManager * GetScoringManagerIfExist()
GammaKnifeMessenger * messenger
void RotateZ(G4double delta)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
#define GAMMAKNIFE_SOURCES
int position
Definition: filter.cc:7
static const double degree
Definition: G4SIunits.hh:125
MeshScoreMap GetScoreMap() const
size_t GetNumberOfMesh() const
double G4double
Definition: G4Types.hh:76
G4VScoringMesh * GetMesh(G4int i) const