source: trunk/examples/novice/N05/src/ExN05PiModel.cc @ 1287

Last change on this file since 1287 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 5.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: ExN05PiModel.cc,v 1.7 2006/06/29 17:53:34 gunter Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30#include "ExN05PiModel.hh"
31
32#include "G4PionMinus.hh"
33#include "G4PionPlus.hh"
34#include "G4Gamma.hh"
35
36ExN05PiModel::ExN05PiModel(G4Region *anEnvelope) :
37  G4VFastSimulationModel("ExN05PiModel",anEnvelope)
38{;}
39
40ExN05PiModel::~ExN05PiModel()
41{;}
42
43G4bool ExN05PiModel::IsApplicable(const G4ParticleDefinition& particleType)
44{
45  return
46    &particleType == G4PionMinus::PionMinusDefinition() ||
47    &particleType == G4PionPlus::PionPlusDefinition();
48}
49
50G4bool ExN05PiModel::ModelTrigger(const G4FastTrack& fastTrack) {
51  //-------------------------------------------------------------
52  // UserTrigger() method: method which has to decide if
53  // the parameterisation has to be applied.
54  // Here ModelTrigger() asks the user (ie you) a 0/1 answer.
55  //
56  // Note that quantities like the local/global position/direction etc..
57  // are available at this level via the fastTrack parameter (allowing
58  // to check distance from boundaries, see below  to allow the decision)
59  //--------------------------------------------------------------
60  G4cout << "\nExN05PiModel::ModelTrigger() called:" << G4endl;
61  G4cout <<   "--------------------------------" << G4endl;
62  G4cout << "(particle is a " << fastTrack.GetPrimaryTrack()->
63    GetDefinition()->GetParticleName() << " )\n" << G4endl;
64
65  // -- Examples of available informations:
66
67  // -- position:
68  G4cout << "         Track position: " <<
69    fastTrack.GetPrimaryTrack()->GetPosition()  << "(global coord.)"   <<
70    fastTrack.GetPrimaryTrackLocalPosition()  << "(in envelope coord.)" 
71       << G4endl;
72
73  // -- direction:
74  G4cout << "         Track direction:"       <<
75    fastTrack.GetPrimaryTrack()->GetMomentum().unit() << 
76    "(global coord.)"      <<
77    fastTrack.GetPrimaryTrackLocalDirection() << "(in envelope coord.)" << 
78    G4endl;
79
80  return true;
81}
82
83void ExN05PiModel::DoIt(const G4FastTrack& fastTrack, 
84                     G4FastStep& fastStep)
85  //--------------------------------------------------
86  //
87  // User method to code the parameterisation properly
88  // said.
89  //
90  //--------------------------------------------------
91{
92
93  //------------------------------------------------
94  // The primary track continues along its direction.
95  // One secondary (a photon) is added:
96  //------------------------------------------------
97  G4cout << "      Pion `model' applied\n" << G4endl;
98
99  //------------------------------
100  // Primary:
101  //    idem as in "DefaultModel":
102  //
103  //------------------------------
104  G4ThreeVector position;
105  G4double distance;
106  distance = fastTrack.GetEnvelopeSolid()->
107    DistanceToOut(fastTrack.GetPrimaryTrackLocalPosition(),
108                  fastTrack.GetPrimaryTrackLocalDirection());
109  position = fastTrack.GetPrimaryTrackLocalPosition() + 
110    distance*fastTrack.GetPrimaryTrackLocalDirection();
111
112  // -- set final position:
113  fastStep.ProposePrimaryTrackFinalPosition(position);
114
115  //---------------------------
116  // Secondary:
117  //   Adds one "secondary":
118  //
119  //---------------------------
120  // -- First, user has to say how many secondaries will be created:
121  fastStep.SetNumberOfSecondaryTracks(1);
122
123  //------------------------
124  // -- Build the secondary:
125  //------------------------
126  // -- direction:
127  G4ParticleMomentum direction(fastTrack.GetPrimaryTrackLocalDirection());
128  direction.setZ(direction.z()*0.5);
129  direction.setY(direction.y()+direction.z()*0.1);
130  direction = direction.unit(); // necessary ?
131
132  // -- dynamics (Note that many constructors exists for G4DynamicParticle
133  // -- see prototype/particle+matter/particles/management/include/G4DynamicParticle.hh)
134  G4DynamicParticle dynamique(G4Gamma::GammaDefinition(),
135                              direction,
136                              fastTrack.GetPrimaryTrack()->
137                              GetKineticEnergy()/2.);
138  // -- position:
139  G4double Dist;
140  Dist = fastTrack.GetEnvelopeSolid()->
141    DistanceToOut(fastTrack.GetPrimaryTrackLocalPosition(),
142                  direction);
143  G4ThreeVector posi;
144  posi = fastTrack.GetPrimaryTrackLocalPosition() + Dist*direction;
145 
146  //------------------------------------
147  //-- Creation of the secondary Track:
148  //------------------------------------
149  fastStep.CreateSecondaryTrack(dynamique, posi, 
150                       fastTrack.GetPrimaryTrack()->GetGlobalTime());
151
152}
Note: See TracBrowser for help on using the repository browser.