source: trunk/source/processes/electromagnetic/lowenergy/test/G4FinalStateProductTest.cc @ 1350

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

update to last version 4.9.4

File size: 5.6 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: G4FinalStateProductTest.cc,v 1.2 2007/10/12 16:39:46 pia Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30///
31// -------------------------------------------------------------------
32//      Author:        Maria Grazia Pia
33//
34//      Creation date: 6 August 2001
35//
36//      Modifications:
37//
38// -------------------------------------------------------------------
39
40#include "globals.hh"
41#include "G4ios.hh"
42#include <fstream>
43#include <iomanip>
44#include <vector>
45
46
47#include "G4ParticleDefinition.hh"
48#include "G4ParticleTypes.hh"
49//#include "G4ParticleTable.hh"
50#include "G4ParticleMomentum.hh"
51#include "G4DynamicParticle.hh"
52#include "G4ThreeVector.hh"
53#include "G4Track.hh"
54#include "G4SystemOfUnits.hh"
55
56#include "G4FinalStateProduct.hh"
57
58int main()
59{
60  //  G4cout.setf( ios::scientific, ios::floatfield );
61
62  G4FinalStateProduct* product = new G4FinalStateProduct;
63
64  // Dump initial information
65
66  G4double deposit = product->GetEnergyDeposit();
67  G4int nSecondaries = product->NumberOfSecondaries();
68
69  G4cout << "Initial product: deposit = " 
70         << deposit
71         << ", "
72         << nSecondaries
73         << " secondaries"
74         <<G4endl;
75  G4bool kill = product->PrimaryParticleIsKilled();
76
77  if (kill)
78    {
79      G4cout << "Kill incident particle" << G4endl;
80    }
81  else
82    {
83      G4cout << "Do not kill incident particle" << G4endl;   
84    }
85
86  // Particle definitions
87  //  G4ParticleDefinition* proton = G4Proton::ProtonDefinition();
88  G4ParticleDefinition* electron = G4Electron::ElectronDefinition();
89 
90  // Create a DynamicParticle 
91
92  G4cout << "Enter energy " << G4endl;
93  G4double energy;
94  G4cin >> energy;
95
96  G4double initX = 0.; 
97  G4double initY = 0.; 
98  G4double initZ = 1.;
99  G4ParticleMomentum direction(initX,initY,initZ);
100 
101  G4DynamicParticle dynamicParticle(electron,direction,energy);
102 
103  //     dynamicParticle.DumpInfo(0);
104 
105  // Reset empty final state (make sure Clear is harmless)
106  product->Clear();
107 
108  // Add secondary particle and local energy deposit (10% of particle energy)
109
110  G4double localEnergy = 0.1 * energy;
111  product->AddEnergyDeposit(localEnergy);
112  product->AddSecondary(&dynamicParticle);
113  product->KillIncidentParticle();
114
115  // Retrieve final state products
116
117  G4int nProducts = product->NumberOfSecondaries();
118  G4double productDeposit = product->GetEnergyDeposit();
119  std::vector<G4DynamicParticle*> products = product->GetSecondaries();
120
121  G4DynamicParticle* product0 = products[0]; 
122  if (!products.empty())
123    {
124      //   product0 = products[0];
125    }
126
127  if (product0 != 0)
128    {
129      G4double charge = product0->GetCharge();
130      G4double eKin = product0->GetKineticEnergy();
131      G4double mass = product0->GetMass();
132     
133      G4cout << nProducts << " secondary products - "
134             << "Charge = " << charge
135             << ", kinetic E = " << eKin
136             << ", mass = " << mass
137             << G4endl
138             << "Local energy deposit = " << productDeposit
139             << G4endl; 
140    }
141
142  kill = product->PrimaryParticleIsKilled();
143
144  if (kill)
145    {
146      G4cout << "Kill incident particle after production" << G4endl;
147    }
148  else
149    {
150      G4cout << "Do not kill incident particle after production" << G4endl;   
151    }
152
153 // Clear final state produced
154  product->Clear();
155
156  nProducts = product->NumberOfSecondaries();
157  productDeposit = product->GetEnergyDeposit();
158  G4cout << nProducts << " secondary products  after Clear - "
159         << "Local energy deposit after Clear = " << productDeposit
160         << G4endl; 
161 
162 std::vector<G4DynamicParticle*> products2 = product->GetSecondaries();
163
164 if (products2.empty())
165   {
166     G4cout << "Vector is empty after Clear" << G4endl;
167   }
168
169  if (product0 != 0)
170    {
171      G4double charge = product0->GetCharge();
172      G4double eKin = product0->GetKineticEnergy();
173      G4double mass = product0->GetMass();
174     
175      G4cout << "Old product is still alive - "
176             << "Charge = " << charge
177             << ", kinetic E = " << eKin
178             << ", mass = " << mass
179             << G4endl; 
180      delete product0;
181
182    }
183
184  delete product;
185
186  G4cout << "END OF THE MAIN PROGRAM" << G4endl;
187}
188
189
190
191
192
193
194
195
Note: See TracBrowser for help on using the repository browser.