source: trunk/source/geometry/benchmarks/Shoot.hh@ 1350

Last change on this file since 1350 was 1347, checked in by garnier, 15 years ago

geant4 tag 9.4

File size: 7.7 KB
Line 
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// $Id: Shoot.hh,v 1.9 2006/06/29 18:15:29 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30#ifndef SHOOT_HH
31#define SHOOT_HH
32
33#include "G4Timer.hh"
34#include "G4VPhysicalVolume.hh"
35#include "G4Navigator.hh"
36#include "G4ThreeVector.hh"
37#include "G4ios.hh"
38
39void Shoot(const G4int numShoot,
40 G4VPhysicalVolume *pTopNode,
41 const G4ThreeVector& pSource,
42 const G4ThreeVector& pVec)
43{
44 G4double physStep=kInfinity;
45 G4int i;
46 G4double safety;
47 G4double Step;
48 G4Navigator myNav;
49 G4Timer timer;
50 G4ThreeVector partLoc;
51 G4VPhysicalVolume *located=0;
52
53 myNav.SetWorldVolume(pTopNode);
54
55 timer.Start();
56
57 for (i=numShoot;i>0;i--)
58 {
59 // G4cout << "#Loop " << i << G4endl ;
60
61 partLoc=pSource;
62 located=myNav.LocateGlobalPointAndSetup(partLoc,0,false,true);
63 while (located)
64 {
65 /*
66 G4cout << "Loc = " << partLoc << " Vec = " << pVec << G4endl ;
67 G4cout << "Safety = " << safety << G4endl ;
68 */
69 Step=myNav.ComputeStep(partLoc,pVec,physStep,safety);
70
71 partLoc+=Step*pVec;
72 myNav.SetGeometricallyLimitedStep();
73 located=myNav.LocateGlobalPointAndSetup(partLoc);
74 };
75 }
76 timer.Stop();
77 // G4cout << "Shots = " << numShoot << " " << timer << G4endl;
78}
79
80#include "G4TransportationManager.hh"
81#include "G4MagneticField.hh"
82#include "G4UniformMagField.hh"
83#include "G4ChordFinder.hh"
84#include "G4PropagatorInField.hh"
85#include "G4FieldManager.hh"
86#include "G4HelixExplicitEuler.hh"
87#include "G4HelixSimpleRunge.hh"
88#include "G4HelixImplicitEuler.hh"
89#include "G4ExplicitEuler.hh"
90#include "G4ImplicitEuler.hh"
91#include "G4SimpleRunge.hh"
92#include "G4SimpleHeum.hh"
93#include "G4ClassicalRK4.hh"
94#include "G4Mag_UsualEqRhs.hh"
95#include "G4CashKarpRKF45.hh"
96#include "G4RKG3_Stepper.hh"
97
98void MagneticShoot(const G4int numShoot,
99 G4VPhysicalVolume *pTopNode,
100 const G4ThreeVector& pSource,
101 const G4ThreeVector& pVec,
102 const G4double fieldValue, // ** already in tesla **
103 const G4double DeltaChord) // ** already in mm **
104{
105 /** Setting up the Magnetic field **/
106
107 G4UniformMagField magField (0.,0.,fieldValue);
108 G4Navigator *myNav = G4TransportationManager::
109 GetTransportationManager()-> GetNavigatorForTracking();
110 myNav->SetWorldVolume(pTopNode);
111
112 G4double momentum = 0.05*proton_mass_c2;
113 G4double kineticEnergy = momentum*momentum /
114 (std::sqrt(momentum*momentum+proton_mass_c2*proton_mass_c2)+proton_mass_c2);
115 G4double velocity = momentum / (proton_mass_c2+kineticEnergy);
116 G4double labTof= 10.*ns;
117 G4double properTof= 0.1*ns;
118
119 /* Field Properties */
120
121 G4Mag_UsualEqRhs *fEquation = new G4Mag_UsualEqRhs(&magField);
122
123 /* Choose your stepper here */
124 /* G4ClassicalRK4 is the default one */
125 G4MagIntegratorStepper* pStepper = new G4ClassicalRK4( fEquation );
126
127 /*
128 pStepper = new G4ExplicitEuler( fEquation );
129 pStepper = new G4ImplicitEuler( fEquation );
130 pStepper = new G4SimpleRunge( fEquation );
131 pStepper = new G4SimpleHeum( fEquation );
132 pStepper = new G4ClassicalRK4( fEquation );
133 pStepper = new G4HelixExplicitEuler( fEquation );
134 pStepper = new G4HelixImplicitEuler( fEquation );
135 pStepper = new G4HelixSimpleRunge( fEquation );
136 pStepper = new G4RKG3_Stepper( fEquation );
137 */
138
139 G4FieldManager* pFieldMgr = G4TransportationManager::
140 GetTransportationManager()->GetFieldManager();
141 pFieldMgr->SetDetectorField( &magField );
142
143 G4ChordFinder* pChordFinder = new G4ChordFinder( &magField,DeltaChord,pStepper);
144 pFieldMgr->SetChordFinder( pChordFinder );
145
146 G4PropagatorInField *pMagFieldPropagator= G4TransportationManager::
147 GetTransportationManager()-> GetPropagatorInField ();
148
149 pChordFinder->SetChargeMomentumMass(1., // charge in e+ units
150 momentum, // Momentum in Mev/c ?
151 proton_mass_c2 );
152 G4Timer timer;
153 timer.Start();
154
155 for (G4int i=numShoot;i>0;i--)
156 {
157 G4VPhysicalVolume *located;
158 G4ThreeVector Vec = pVec ;
159 G4ThreeVector partLoc = pSource ;
160 /*
161 G4cout << "#Loop " << i << G4endl ;
162 G4cout << "Loc = " << partLoc << " Vec = " << Vec << G4endl << G4endl ;
163 */
164 momentum = (0.5+i*0.1) * proton_mass_c2;
165 kineticEnergy = momentum*momentum /
166 (std::sqrt(momentum*momentum+proton_mass_c2*proton_mass_c2)+proton_mass_c2);
167 velocity = momentum / (proton_mass_c2+kineticEnergy);
168
169 pFieldMgr->GetChordFinder()
170 ->SetChargeMomentumMass(1, // charge in e+ units
171 momentum, // Momentum in Mev/c
172 proton_mass_c2); // Mass
173
174 located=myNav->LocateGlobalPointAndSetup(partLoc);
175 while (located)
176 {
177 G4double physStep= kInfinity; // 2.5*mm ;
178 G4double safety = 1.0*m;
179 G4double Step = 0.0*m;
180 /*
181 G4cout << "Loc = " << partLoc << " Vec = " << Vec << G4endl ;
182 G4cout << "Safety = " << safety << G4endl ;
183 */
184
185 G4FieldTrack initTrack(partLoc,pVec,0.,kineticEnergy,
186 proton_mass_c2,velocity,labTof,properTof,0);
187 Step=pMagFieldPropagator->ComputeStep(initTrack,physStep,safety);
188
189 myNav->SetGeometricallyLimitedStep();
190
191 partLoc = pMagFieldPropagator->EndPosition();
192 Vec = pMagFieldPropagator->EndMomentumDir();
193
194 located=myNav->LocateGlobalPointAndSetup(partLoc);
195 };
196 }
197 timer.Stop();
198 // G4cout << "Shots = " << numShoot << " " << timer << G4endl;
199}
200
201
202void ShootVerbose(G4VPhysicalVolume *pTopNode,
203 const G4ThreeVector& pSource,
204 const G4ThreeVector& pVec)
205{
206 const G4double physStep=kInfinity;
207 G4double safety,Step;
208 G4Navigator myNav;
209 G4ThreeVector partLoc;
210 G4VPhysicalVolume *located=0;
211
212 myNav.SetWorldVolume(pTopNode);
213
214 partLoc=pSource;
215 located=myNav.LocateGlobalPointAndSetup(partLoc);
216 while (located)
217 {
218 Step=myNav.ComputeStep(partLoc,pVec,physStep,safety);
219 G4cout << "Physical Location=" << located->GetName()
220 << " #" << located->GetCopyNo() << G4endl
221 << " Step=" << Step << " Safety=" << safety
222 << " ---->" << G4endl;
223
224 partLoc+=Step*pVec;
225 myNav.SetGeometricallyLimitedStep();
226 located=myNav.LocateGlobalPointAndSetup(partLoc);
227 };
228}
229
230#endif
231
Note: See TracBrowser for help on using the repository browser.