ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleChangeForGamma.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParticleChangeForGamma.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 //
26 //
27 //
28 //
29 // --------------------------------------------------------------
30 // GEANT 4 class implementation file
31 //
32 // ------------------------------------------------------------
33 // 15 April 2005 V.Ivanchenko for gamma EM processes
34 // --------------------------------------------------------------
35 //
36 // Modified::
37 // 28.08.06 V.Ivanchenko Add access to current track and polarizaion
38 //
39 // ------------------------------------------------------------
40 //
42 #include "G4SystemOfUnits.hh"
43 #include "G4Track.hh"
44 #include "G4Step.hh"
45 #include "G4DynamicParticle.hh"
46 #include "G4ExceptionSeverity.hh"
47 
49  : G4VParticleChange(), currentTrack(0), proposedKinEnergy(0.)
50 {
52  debugFlag = false;
53 #ifdef G4VERBOSE
54  if (verboseLevel>2) {
55  G4cout << "G4ParticleChangeForGamma::G4ParticleChangeForGamma() " << G4endl;
56  }
57 #endif
58 }
59 
61 {
62 #ifdef G4VERBOSE
63  if (verboseLevel>2) {
64  G4cout << "G4ParticleChangeForGamma::~G4ParticleChangeForGamma() " << G4endl;
65  }
66 #endif
67 }
68 
71 {
72  if (verboseLevel>1)
73  G4cout << "G4ParticleChangeForGamma:: copy constructor is called " << G4endl;
74 
75  currentTrack = right.currentTrack;
79 }
80 
81 // assignment operator
84 {
85 #ifdef G4VERBOSE
86  if (verboseLevel>1)
87  G4cout << "G4ParticleChangeForGamma:: assignment operator is called " << G4endl;
88 #endif
89 
90  if (this != &right) {
91  if (theNumberOfSecondaries>0) {
92 #ifdef G4VERBOSE
93  if (verboseLevel>0) {
94  G4cout << "G4ParticleChangeForGamma: assignment operator Warning ";
95  G4cout << "theListOfSecondaries is not empty ";
96  }
97 #endif
98  for (G4int index= 0; index<theNumberOfSecondaries; index++){
99  if ( (*theListOfSecondaries)[index] ) delete (*theListOfSecondaries)[index] ;
100  }
101  }
102  delete theListOfSecondaries;
105  for (G4int index = 0; index<theNumberOfSecondaries; index++){
106  G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index] ));
107  theListOfSecondaries->SetElement(index, newTrack); }
108 
113 
114  currentTrack = right.currentTrack;
118  }
119  return *this;
120 }
121 
123 {
124  // create track
125  G4Track* aTrack = new G4Track(aParticle, currentTrack->GetGlobalTime(),
127 
128  // Touchable handle is copied to keep the pointer
130 
131  // add a secondary
133 }
134 
135 //----------------------------------------------------------------
136 // method for updating G4Step
137 //
138 
140 {
142  pStep->SetStepLength( 0.0 );
143 
146  }
147 
148  return pStep;
149 }
150 
152 {
153  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
154  G4Track* pTrack = pStep->GetTrack();
155 
156  pPostStepPoint->SetKineticEnergy( proposedKinEnergy );
158  pPostStepPoint->SetPolarization( proposedPolarization );
159 
160  // update velocity for scattering process and particles with mass
161  if(proposedKinEnergy > 0.0) {
162  if(pTrack->GetParticleDefinition()->GetPDGMass() > 0.0) {
163  pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
164  }
165  }
166 
168  pPostStepPoint->SetWeight( theParentWeight );
169  }
170 
173  return pStep;
174 }
175 
176 //----------------------------------------------------------------
177 // methods for printing messages
178 //
179 
181 {
182 // use base-class DumpInfo
184 
185  G4int oldprc = G4cout.precision(3);
186  G4cout << " Kinetic Energy (MeV): "
187  << std::setw(20) << proposedKinEnergy/MeV
188  << G4endl;
189  G4cout << " Momentum Direction: "
190  << std::setw(20) << proposedMomentumDirection
191  << G4endl;
192  G4cout << " Polarization: "
193  << std::setw(20) << proposedPolarization
194  << G4endl;
195  G4cout.precision(oldprc);
196 }
197 
199 {
200  G4bool itsOK = true;
201  G4bool exitWithError = false;
202 
203  G4double accuracy;
204 
205  // Energy should not be lager than initial value
206  accuracy = ( proposedKinEnergy - aTrack.GetKineticEnergy())/MeV;
207  if (accuracy > accuracyForWarning) {
208  itsOK = false;
209  exitWithError = (accuracy > accuracyForException);
210 #ifdef G4VERBOSE
211  G4cout << "G4ParticleChangeForGamma::CheckIt: ";
212  G4cout << "KinEnergy become larger than the initial value!"
213  << " Difference: " << accuracy << "[MeV] " <<G4endl;
214  G4cout << aTrack.GetDefinition()->GetParticleName()
215  << " E=" << aTrack.GetKineticEnergy()/MeV
216  << " pos=" << aTrack.GetPosition().x()/m
217  << ", " << aTrack.GetPosition().y()/m
218  << ", " << aTrack.GetPosition().z()/m
219  << G4endl;
220 #endif
221  }
222 
223  // dump out information of this particle change
224 #ifdef G4VERBOSE
225  if (!itsOK) DumpInfo();
226 #endif
227 
228  // Exit with error
229  if (exitWithError) {
230  G4Exception("G4ParticleChangeForGamma::CheckIt",
231  "TRACK004",EventMustBeAborted,
232  "energy was illegal");
233  }
234 
235  //correction
236  if (!itsOK) {
238  }
239 
240  itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
241  return itsOK;
242 }