Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4BlineTracer.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 //
28 //
29 //
30 // $Id: G4BlineTracer.cc 109623 2018-05-03 13:05:02Z gcosmo $
31 //
32 //
33 // --------------------------------------------------------------------
34 //
35 // G4BlineTracer implementation
36 //
37 // --------------------------------------------------------------------
38 // Author: Laurent Desorgher (desorgher@phim.unibe.ch)
39 // Created - 2003-10-06
40 // --------------------------------------------------------------------
41 
42 #include "G4BlineTracer.hh"
45 #include "G4BlineEventAction.hh"
46 #include "G4BlineSteppingAction.hh"
47 #include "G4BlineEquation.hh"
48 
49 #include "G4RunManager.hh"
51 #include "G4FieldManager.hh"
52 #include "G4PropagatorInField.hh"
53 #include "G4MagIntegratorDriver.hh"
54 #include "G4CashKarpRKF45.hh"
55 #include "G4LogicalVolumeStore.hh"
56 #include "G4ChordFinder.hh"
57 #include "G4SystemOfUnits.hh"
58 
60 
62 {
65  fEventAction = new G4BlineEventAction(this);
67  fMaxTrackingStep =1000.*m;
69 }
70 
72 
74 {
75  delete fMessenger;
76  delete fSteppingAction;
77  delete fEventAction;
79  for (size_t i=0; i< fVecEquationOfMotion.size();i++)
80  {
82  if (fVecChordFinders[i]) delete fVecChordFinders[i];
83  }
84 }
85 
87 
89 {
90 }
91 
93 
95 {
96 }
97 
99 
101 {
102  //the first time ResetChordFinders should be called
103  //
105  {
108  }
109 
110  // Replace the user action by the ad-hoc actions for Blines
111 
112  G4RunManager* theRunManager = G4RunManager::GetRunManager();
113  G4UserRunAction* user_run_action =
114  (G4UserRunAction*)theRunManager->GetUserRunAction();
115  theRunManager->SetUserAction(this);
116 
117  G4UserSteppingAction* user_stepping_action =
118  (G4UserSteppingAction*)theRunManager->GetUserSteppingAction();
119  theRunManager->SetUserAction(fSteppingAction);
120 
121  G4VUserPrimaryGeneratorAction* userPrimaryAction =
123  if (userPrimaryAction)
124  fPrimaryGeneratorAction->SetUserPrimaryAction(userPrimaryAction);
125  theRunManager->SetUserAction(fPrimaryGeneratorAction);
126 
127  G4UserEventAction* user_event_action =
128  (G4UserEventAction*)theRunManager->GetUserEventAction();
129  theRunManager->SetUserAction(fEventAction);
130 
131  G4UserTrackingAction* user_tracking_action =
132  (G4UserTrackingAction*)theRunManager->GetUserTrackingAction();
133  G4UserTrackingAction* aNullTrackingAction = 0;
134  theRunManager->SetUserAction(aNullTrackingAction);
135 
136  G4UserStackingAction* user_stacking_action =
137  (G4UserStackingAction*)theRunManager->GetUserStackingAction();
138  G4UserStackingAction* aNullStackingAction = 0;
139  theRunManager->SetUserAction(aNullStackingAction);
140 
141  // replace the user defined chordfinder by the element of fVecChordFinders
142 
143  std::vector<G4ChordFinder*> user_chord_finders;
144  std::vector<G4double> user_largest_acceptable_step;
145  for (size_t i=0;i<fVecChordFinders.size();i++)
146  {
147  user_largest_acceptable_step.push_back(-1.);
148  if (fVecChordFinders[i])
149  {
150  user_chord_finders.push_back(fVecFieldManagers[i]->GetChordFinder());
151  fVecChordFinders[i]->SetDeltaChord(user_chord_finders[i]->GetDeltaChord());
152  fVecFieldManagers[i]->SetChordFinder(fVecChordFinders[i]);
153  }
154  else user_chord_finders.push_back(0);
155  }
156 
157  // I have tried to use the smooth line filter ability but I could not obtain
158  // a smooth trajectory in the G4TrajectoryContainer after an event
159  // Another solution for obtaining a smooth trajectory is to limit
160  // the LargestAcceptableStep in the G4PropagatorInField object.
161  // This is the solution I used.
162 
163  // Old solution:
164  // G4TransportationManager::GetTransportationManager()
165  // ->GetPropagatorInField()->SetTrajectoryFilter(fTrajectoryFilter);
166 
167  // New solution:
168  // set the largest_acceptable_step to max_step:length
169 
170  G4TransportationManager* tmanager =
172  G4double previous_largest_acceptable_step =
174 
175  tmanager->GetPropagatorInField()
177 
178  // Start the integration of n_of_lines different magnetic field lines
179 
180  for (G4int il=0; il<n_of_lines;il++)
181  {
182  // for each magnetic field line we integrate once backward and once
183  // forward from the same starting point
184 
185  // backward integration
186 
187  for (size_t i=0; i< fVecEquationOfMotion.size();i++)
188  {
189  if (fVecEquationOfMotion[i])
190  fVecEquationOfMotion[i]->SetBackwardDirectionOfIntegration(true);
191  }
192  theRunManager->BeamOn(1);
193 
194  // forward integration
195 
196  for (size_t i=0; i < fVecEquationOfMotion.size();i++)
197  {
198  if (fVecEquationOfMotion[i])
199  fVecEquationOfMotion[i]->SetBackwardDirectionOfIntegration(false);
200  }
201  theRunManager->BeamOn(1);
202  }
203 
204  // Remove trajectory filter to PropagatorInField
205  // It was for old solution when using smooth trajectory filter
206 
207  // tmanager->GetPropagatorInField()->SetTrajectoryFilter(0);
208 
209  // back to User defined actions and other parameters
210  // -------------------------------------------------
211 
212  tmanager->GetPropagatorInField()
213  ->SetLargestAcceptableStep(previous_largest_acceptable_step);
214 
215  // return to User actions
216 
217  theRunManager->SetUserAction(user_run_action);
218  theRunManager->SetUserAction(user_event_action);
219  theRunManager->SetUserAction(userPrimaryAction);
220  theRunManager->SetUserAction(user_stepping_action);
221  theRunManager->SetUserAction(user_tracking_action);
222  theRunManager->SetUserAction(user_stacking_action);
223 
224  // set user defined chord finders and largest acceptable step
225 
226  for (size_t i=0;i<fVecFieldManagers.size();i++)
227  {
228  if (user_chord_finders[i])
229  fVecFieldManagers[i]->SetChordFinder(user_chord_finders[i]);
230  }
231 }
232 
234 
235 /*
236 G4bool G4BlineTracer::CheckMagneticFields()
237 {
238  // Check FieldManagers
239 
240  G4TransportationManager* tmanager =
241  G4TransportationManager::GetTransportationManager();
242 
243  if (fVecFieldManagers[0] != tmanager->GetFieldManager())
244  return false;
245  if (fVecMagneticFields[0] != tmanager->GetFieldManager()->GetDetectorField())
246  return false;
247  G4LogicalVolumeStore* theVolumeStore = G4LogicalVolumeStore::GetInstance();
248 
249  std::vector<G4FieldManagers*> LogicalVolumeFields;
250  size_t j=0;
251  for (size_t i=0; i<theVolumeStore.size();i++)
252  {
253  if (theVolumeStore[i]->GetFieldManager())
254  {
255  j++;
256  if (j >= fVecFieldManagers.size()) return false;
257  if (fVecFieldManagers[j] != theVolumeStore[i]->GetFieldManager())
258  return false;
259  if (fVecMagneticFields[j] !=
260  theVolumeStore[i]->GetFieldManager()->GetDetectorField())
261  return false;
262  }
263  }
264  if (j<fVecFieldManagers.size()) return false;
265 
266  return true;
267 }
268 */
269 
271 
273 {
274  for (size_t i=0; i<fVecEquationOfMotion.size();i++)
275  {
276  delete fVecEquationOfMotion[i];
277  delete fVecChordFinders[i];
278  }
279 
280  fVecChordFinders.clear();
281  fVecFieldManagers.clear();
282  fVecMagneticFields.clear();
283  fVecEquationOfMotion.clear();
284 
285  // global field
286 
287  fVecChordFinders.push_back(0);
288  fVecMagneticFields.push_back(0);
289  fVecEquationOfMotion.push_back(0);
291  ->GetFieldManager());
292  if (fVecFieldManagers[0])
293  {
294  fVecMagneticFields[0] =
295  (G4MagneticField*) fVecFieldManagers[0]->GetDetectorField();
296  if (fVecMagneticFields[0])
297  {
300  G4MagInt_Driver* pIntgrDriver =
301  new G4MagInt_Driver(0.01*mm,pStepper,pStepper->GetNumberOfVariables());
302  fVecChordFinders[0] = new G4ChordFinder(pIntgrDriver);
303  }
304  }
305 
306  // local fields
307 
309 
310  size_t j=0;
311  for (size_t i=0; i<theVolumeStore->size();i++)
312  {
313  if ((*theVolumeStore)[i]->GetFieldManager())
314  {
315  j++;
316  fVecFieldManagers.push_back(((*theVolumeStore)[i])->GetFieldManager());
318  fVecFieldManagers[j]->GetDetectorField());
319  fVecEquationOfMotion.push_back(0);
320  fVecChordFinders.push_back(0);
321  if (fVecMagneticFields[j])
322  {
325  G4MagInt_Driver* pIntgrDriver =
326  new G4MagInt_Driver(.01*mm,pStepper,pStepper->GetNumberOfVariables());
327  fVecChordFinders[j] = new G4ChordFinder(pIntgrDriver);
328  }
329  }
330  }
331 }
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
void SetUserPrimaryAction(G4VUserPrimaryGeneratorAction *anAction)
std::vector< G4ChordFinder * > fVecChordFinders
const G4UserRunAction * GetUserRunAction() const
const G4UserEventAction * GetUserEventAction() const
const G4UserStackingAction * GetUserStackingAction() const
G4BlineEventAction * fEventAction
static constexpr double mm
Definition: G4SIunits.hh:115
const G4UserTrackingAction * GetUserTrackingAction() const
std::vector< G4FieldManager * > fVecFieldManagers
G4bool fWas_ResetChordFinders_already_called
virtual void SetUserAction(G4UserRunAction *userAction)
void SetLargestAcceptableStep(G4double newBigDist)
virtual ~G4BlineTracer()
void ResetChordFinders()
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
Definition of the G4BlineTracerMessenger class.
static constexpr double m
Definition: G4SIunits.hh:129
void ComputeBlines(G4int nlines)
double G4double
Definition: G4Types.hh:76
const G4UserSteppingAction * GetUserSteppingAction() const
G4BlineSteppingAction * fSteppingAction
Definition of the G4BlineTracer class.
std::vector< G4BlineEquation * > fVecEquationOfMotion
Definition: G4Run.hh:46
G4double GetLargestAcceptableStep()
static G4TransportationManager * GetTransportationManager()
virtual void BeginOfRunAction(const G4Run *aRun)
int G4int
Definition: G4Types.hh:78
G4BlineTracerMessenger * fMessenger
Definition of the G4BlineEquation class.
Definition of the G4BlineSteppingAction class.
Definition of the G4BlinePrimaryGeneratorAction class.
G4PropagatorInField * GetPropagatorInField() const
G4double fMaxTrackingStep
G4int GetNumberOfVariables() const
Definition of the G4BlineEventAction class.
static G4LogicalVolumeStore * GetInstance()
const G4VUserPrimaryGeneratorAction * GetUserPrimaryGeneratorAction() const
virtual void EndOfRunAction(const G4Run *aRun)
G4BlinePrimaryGeneratorAction * fPrimaryGeneratorAction
std::vector< G4MagneticField * > fVecMagneticFields