source: trunk/source/processes/electromagnetic/lowenergy/test/processTest/src/G4TestSetup.cc @ 1199

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

nvx fichiers dans CVS

File size: 4.8 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: G4TestSetup.cc,v 1.9 2006/06/29 19:48:58 gunter Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31//
32// History:
33// -----------
34// 07 Oct 2001   MGP        Created
35//
36// -------------------------------------------------------------------
37
38#include "globals.hh"
39#include "G4TestSetup.hh"
40#include "G4VProcess.hh"
41#include "G4ios.hh"
42#include <fstream>
43#include <iomanip>
44
45#include "G4Electron.hh"
46#include "G4Positron.hh"
47#include "G4Gamma.hh"
48
49#include "G4Material.hh"
50#include "G4Box.hh"
51#include "G4LogicalVolume.hh"
52#include "G4PVPlacement.hh"
53#include "G4GRSVolume.hh"
54#include "G4Step.hh"
55#include "G4StepPoint.hh"
56#include "G4Track.hh"
57
58#include "G4DynamicParticle.hh"
59
60#include "G4UnitsTable.hh"
61#include "Randomize.hh"
62
63
64G4TestSetup::G4TestSetup(const G4Material* aMaterial,
65                         const G4ParticleDefinition* def,
66                         G4double minEnergy, G4double  maxEnergy)
67  : eMin(minEnergy), eMax(maxEnergy)
68{
69  // const_cast needed because geometry and tracking objects require
70  // non-const materials and particle definitions in their constructors (why?)
71  part = const_cast<G4ParticleDefinition*>(def);
72  material = const_cast<G4Material*>(aMaterial);
73  track = 0;
74  step = new G4Step;
75  physicalFrame = 0;
76}
77
78G4TestSetup:: ~G4TestSetup()
79{
80  delete physicalFrame;
81  physicalFrame = 0;
82  delete step;
83  step = 0;
84  delete track;
85  track = 0;
86}
87
88  void G4TestSetup::makeGeometry()
89{
90  G4double dimX = 10.*cm;
91  G4double dimY = 10.*cm;
92  G4double dimZ = 10.*cm;
93 
94  G4Box box("Box",dimX, dimY, dimZ);
95 
96  G4LogicalVolume logicalVol(&box,material,"LogicalBox", 0, 0, 0);
97  logicalVol.SetMaterial(material); 
98 
99  physicalFrame = new G4PVPlacement(0,G4ThreeVector(),
100                                    "PhysicalBox",&logicalVol,0,false,0);
101
102}
103
104const G4Track* G4TestSetup::makeTrack()
105{
106  G4double energy = eMin + (eMax - eMin) * G4UniformRand();
107
108  if (track == 0)
109    {   
110      G4double initX = 0.; 
111      G4double initY = 0.; 
112      G4double initZ = 1.;
113      G4ParticleMomentum direction(initX,initY,initZ);
114      G4DynamicParticle* dynamicPart = new G4DynamicParticle(part,direction,energy);
115      G4ThreeVector position(0.,0.,0.);
116      G4double time = 0. ;
117     
118      track = new G4Track(dynamicPart,time,position);
119     
120      // do I really need this?     
121      G4GRSVolume* touche = new G4GRSVolume(physicalFrame,0,position);   
122      track->SetTouchable(touche);
123    }
124  else
125    {
126      track->SetKineticEnergy(energy);
127    }
128
129  G4double e = track->GetKineticEnergy();
130  G4cout << "Track energy = " << e/MeV << " MeV" << G4endl;
131
132  return track;
133}
134
135const G4Step* G4TestSetup::makeStep()
136{
137  step->SetTrack(track);
138
139  G4ThreeVector aPosition(0.,0.,0.);
140  G4ThreeVector newPosition(0.,0.,1.*mm);
141 
142  G4StepPoint* aPoint = new G4StepPoint();
143  aPoint->SetPosition(aPosition);
144  aPoint->SetMaterial(material);
145  G4double safety = 10000.*cm;
146  aPoint->SetSafety(safety);
147  step->SetPreStepPoint(aPoint);
148  G4StepPoint* newPoint = new G4StepPoint();
149  newPoint->SetPosition(newPosition);
150  newPoint->SetMaterial(material);
151  newPoint->SetSafety(safety);
152  step->SetPostStepPoint(newPoint);
153  step->SetStepLength(1*mm);
154
155  track->SetStep(step); 
156 
157return step;
158}
159
Note: See TracBrowser for help on using the repository browser.