Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
30 #include "G4RunManager.hh"
31 
32 #include "G4SystemOfUnits.hh"
33 
35 {
36  detector = det;
37 
38  messenger = new GammaKnifeMessenger( this );
39 }
40 
42 {
43  delete messenger;
44 }
45 
47 {
48  PrepareHitsAccumulation();
49  for (G4int i = 0; i < GAMMAKNIFE_SOURCES; i++)
50  {
51  RotateForward(i);
53  if (i != (GAMMAKNIFE_SOURCES - 1))
54  {
55  StoreHits();
56  }
57  RotateBack(i);
58  }
59  AccumulateAllHits();
60 }
61 
62 void GammaKnifeController::RotateForward( G4int position )
63 {
64  // Rotate all scoring meshes to the right position
66  if (scm)
67  {
68  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
69  {
70  G4VScoringMesh * mesh = scm->GetMesh(i);
71  mesh->RotateX( thetaAngles[position] );
72  mesh->RotateZ( phiAngles[position] );
73  }
74  }
75 }
76 
77 void GammaKnifeController::RotateBack( G4int position )
78 {
80  if (scm)
81  {
82  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
83  {
84  G4VScoringMesh * mesh = scm->GetMesh(i);
85  mesh->RotateZ( - phiAngles[position] );
86  mesh->RotateX( - thetaAngles[position] );
87  }
88  }
89 }
90 
91 void GammaKnifeController::PrepareHitsAccumulation()
92 {
94  if (scm)
95  {
96  size_t size = scm->GetNumberOfMesh();
97  scoreMaps = new MeshScoreMap[size];
98  for (size_t i = 0; i < size; i++)
99  {
100  G4VScoringMesh * mesh = scm->GetMesh(i);
101 
102  MeshScoreMap scoreMap = mesh->GetScoreMap();
103  MeshScoreMap& storedScoreMap = scoreMaps[i];
104 
105  MeshScoreMap::iterator it = scoreMap.begin();
106  for( ; it != scoreMap.end(); it++)
107  {
108  std::string hitMapName = it->first;
109  G4THitsMap<G4double>* hitMapToStore = new G4THitsMap<G4double>("GammaKnifeController", hitMapName);
110  storedScoreMap[ hitMapName ] = hitMapToStore;
111  }
112  }
113  }
114 }
115 
116 void GammaKnifeController::StoreHits()
117 {
119  if (scm)
120  {
121  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
122  {
123  G4VScoringMesh* mesh = scm->GetMesh(i);
124 
125 
126  MeshScoreMap scoreMap = mesh->GetScoreMap();
127  MeshScoreMap& storedScoreMap = scoreMaps[i];
128 
129  MeshScoreMap::iterator it = scoreMap.begin();
130  for( ; it != scoreMap.end(); it++)
131  {
132  std::string hitMapName = it->first;
133  *storedScoreMap[hitMapName] += *(it->second);
134  }
135  }
136  }
137 }
138 
139 void GammaKnifeController::AccumulateAllHits()
140 {
142  if (scm)
143  {
144  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
145  {
146  G4VScoringMesh* mesh = scm->GetMesh(i);
147  MeshScoreMap& storedScoreMap = scoreMaps[i];
148  MeshScoreMap::iterator it = storedScoreMap.begin();
149  for( ; it != storedScoreMap.end(); it++)
150  {
151  mesh->Accumulate( it->second );
152  }
153  }
154  }
155 }
156 
157 void GammaKnifeController::ReadFile( std::string fileName )
158 {
159  const int SZ = 100;
160  char buf[SZ];
161 
162  phiAngles.clear(); // If called for the second time
163  thetaAngles.clear(); // we won't have 402 positions...
164 
165  std::ifstream ifs;
166  ifs.open( fileName.c_str() );
167 
168  for (G4int i = 0; i < GAMMAKNIFE_SOURCES; i++)
169  {
170  G4double phi, theta;
171 
172  /* Skip the "Axx" at the beginning of the line */
173  for (G4int c = 0; c < 4; c++) ifs.get();
174 
175  ifs >> phi >> theta;
176  ifs.getline(buf, SZ); // Next line
177 
178  phiAngles.push_back( phi * degree );
179  thetaAngles.push_back( theta * degree );
180  }
181  ifs.close();
182 }