Geant4  10.03
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<G4StatDouble>* hitMapToStore
111  = new G4THitsMap<G4StatDouble>("GammaKnifeController", hitMapName);
112  storedScoreMap[ hitMapName ] = hitMapToStore;
113  }
114  }
115  }
116 }
117 
119 {
121  if (scm)
122  {
123  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
124  {
125  G4VScoringMesh* mesh = scm->GetMesh(i);
126 
127 
128  MeshScoreMap scoreMap = mesh->GetScoreMap();
129  MeshScoreMap& storedScoreMap = scoreMaps[i];
130 
131  MeshScoreMap::iterator it = scoreMap.begin();
132  for( ; it != scoreMap.end(); it++)
133  {
134  std::string hitMapName = it->first;
135  //*storedScoreMap[hitMapName] += *(it->second);
136  auto storedMap = storedScoreMap[hitMapName]->GetMap();
137  auto mapItr = it->second->GetMap()->begin();
138  for(;mapItr!=it->second->GetMap()->end();mapItr++)
139  {
140  auto key = mapItr->first;
141  auto val = mapItr->second;
142  if(storedMap->find(key)==storedMap->end())
143  { (*storedMap)[key] = new G4StatDouble(); }
144  (*storedMap)[key]->add(val);
145  }
146  }
147  }
148  }
149 }
150 
152 {
154  if (scm)
155  {
156  for (size_t i = 0; i < scm->GetNumberOfMesh(); i++)
157  {
158  G4VScoringMesh* mesh = scm->GetMesh(i);
159  MeshScoreMap& storedScoreMap = scoreMaps[i];
160  MeshScoreMap::iterator it = storedScoreMap.begin();
161  for( ; it != storedScoreMap.end(); it++)
162  {
163  mesh->Accumulate( it->second );
164  }
165  }
166  }
167 }
168 
169 void GammaKnifeController::ReadFile( std::string fileName )
170 {
171  //G4cout << "Enter ReadFile()...";
172  const int SZ = 100;
173  char buf[SZ];
174 
175  phiAngles.clear(); // If called for the second time
176  thetaAngles.clear(); // we won't have 402 positions...
177 
178  std::ifstream ifs;
179  ifs.open( fileName.c_str() );
180 
181  for (G4int i = 0; i < GAMMAKNIFE_SOURCES; i++)
182  {
183  G4double phi, theta;
184 
185  /* Skip the "Axx" at the beginning of the line */
186  for (G4int c = 0; c < 4; c++) ifs.get();
187 
188  ifs >> phi >> theta;
189  ifs.getline(buf, SZ); // Next line
190 
191  phiAngles.push_back( phi * degree );
192  thetaAngles.push_back( theta * degree );
193  }
194  ifs.close();
195  //G4cout << "... done " << G4endl;
196 }
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 *)
#define position
Definition: xmlparse.cc:622
static G4ScoringManager * GetScoringManagerIfExist()
static constexpr double degree
Definition: G4SIunits.hh:144
GammaKnifeMessenger * messenger
void RotateZ(G4double delta)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
#define GAMMAKNIFE_SOURCES
MeshScoreMap GetScoreMap() const
size_t GetNumberOfMesh() const
double G4double
Definition: G4Types.hh:76
G4VScoringMesh * GetMesh(G4int i) const
std::map< G4String, RunScore * > MeshScoreMap