source: trunk/source/processes/electromagnetic/lowenergy/test/G4BremsstrahlungTest.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: 14.9 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: G4BremsstrahlungTest.cc,v 1.14 2006/06/29 19:43:41 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30// -------------------------------------------------------------------
31//      GEANT 4 class file --- Copyright CERN 1998
32//      CERN Geneva Switzerland
33//
34//
35//      File name:     G4BremsstrahlungTest
36//
37//      Author:        Maria Grazia Pia
38//
39//      Creation date: 20 June 2000
40//
41//      Modifications:
42//
43// -------------------------------------------------------------------
44
45#include "globals.hh"
46#include "G4ios.hh"
47#include <fstream>
48#include <iomanip>
49
50#include "G4Material.hh"
51#include "G4VContinuousDiscreteProcess.hh"
52#include "G4ProcessManager.hh"
53#include "G4LowEnergyBremsstrahlung.hh"
54#include "G4eBremsstrahlung.hh"
55#include "G4EnergyLossTables.hh"
56#include "G4VParticleChange.hh"
57#include "G4ParticleChange.hh"
58#include "G4DynamicParticle.hh"
59#include "G4Electron.hh"
60#include "G4Positron.hh"
61#include "G4Gamma.hh"
62
63#include "G4Box.hh"
64#include "G4PVPlacement.hh"
65
66#include "G4Step.hh"
67#include "G4GRSVolume.hh"
68
69#include "G4UnitsTable.hh"
70#include "CLHEP/Hist/TupleManager.h"
71#include "CLHEP/Hist/HBookFile.h"
72#include "CLHEP/Hist/Histogram.h"
73#include "CLHEP/Hist/Tuple.h"
74
75HepTupleManager* hbookManager;
76
77int main()
78{
79
80  // Setup
81
82  G4int nIterations = 100000;
83  G4int materialId = 3;
84  G4int test = 0;
85
86  G4cout.setf( ios::scientific, ios::floatfield );
87
88  // -------------------------------------------------------------------
89
90  // ---- HBOOK initialization
91
92
93  hbookManager = new HBookFile("bremtest.hbook", 58);
94  assert (hbookManager != 0);
95 
96  // ---- Book a histogram and ntuples
97  G4cout<<"Hbook file name: "<<((HBookFile*) hbookManager)->filename()<<endl;
98 
99  // ---- primary ntuple ------
100  HepTuple* ntuple1 = hbookManager->ntuple("Primary Ntuple");
101  assert (ntuple1 != 0);
102 
103  // ---- secondary ntuple ------
104  HepTuple* ntuple2 = hbookManager->ntuple("Secondary Ntuple");
105  assert (ntuple2 != 0);
106   
107  // ---- secondaries histos ----
108  HepHistogram* hEKin;
109  hEKin = hbookManager->histogram("Kinetic Energy", 100,0.,200.);
110  assert (hEKin != 0); 
111 
112  HepHistogram* hP;
113  hP = hbookManager->histogram("Momentum", 100,0.,1000.);
114  assert (hP != 0); 
115 
116  HepHistogram* hNSec;
117  hNSec = hbookManager->histogram("Number of secondaries", 40,0.,40.);
118  assert (hNSec != 0); 
119 
120  HepHistogram* hDebug;
121  hDebug = hbookManager->histogram("Debug", 100,0.,200.);
122  assert (hDebug != 0); 
123 
124
125  //--------- Materials definition ---------
126
127  G4Material* Be = new G4Material("Beryllium",    4.,  9.01*g/mole, 1.848*g/cm3);
128  G4Material* Graphite = new G4Material("Graphite",6., 12.00*g/mole, 2.265*g/cm3 );
129  G4Material* Al  = new G4Material("Aluminium", 13., 26.98*g/mole, 2.7 *g/cm3);
130  G4Material* Si  = new G4Material("Silicon",   14., 28.055*g/mole, 2.33*g/cm3);
131  G4Material* LAr = new G4Material("LArgon",   18., 39.95*g/mole, 1.393*g/cm3);
132  G4Material* Fe  = new G4Material("Iron",      26., 55.85*g/mole, 7.87*g/cm3);
133  G4Material* Cu  = new G4Material("Copper",    29., 63.55*g/mole, 8.96*g/cm3);
134  G4Material*  W  = new G4Material("Tungsten", 74., 183.85*g/mole, 19.30*g/cm3);
135  G4Material* Pb  = new G4Material("Lead",      82., 207.19*g/mole, 11.35*g/cm3);
136  G4Material*  U  = new G4Material("Uranium", 92., 238.03*g/mole, 18.95*g/cm3);
137
138  G4Element*   H  = new G4Element ("Hydrogen", "H", 1. ,  1.01*g/mole);
139  G4Element*   O  = new G4Element ("Oxygen"  , "O", 8. , 16.00*g/mole);
140  G4Element*   C  = new G4Element ("Carbon"  , "C", 6. , 12.00*g/mole);
141  G4Element*  Cs  = new G4Element ("Cesium"  , "Cs", 55. , 132.905*g/mole);
142  G4Element*   I  = new G4Element ("Iodide"  , "I", 53. , 126.9044*g/mole);
143
144  G4Material*  maO = new G4Material("Oxygen", 8., 16.00*g/mole, 1.1*g/cm3);
145
146  G4Material* water = new G4Material ("Water" , 1.*g/cm3, 2);
147  water->AddElement(H,2);
148  water->AddElement(O,1);
149
150  G4Material* ethane = new G4Material ("Ethane" , 0.4241*g/cm3, 2);
151  ethane->AddElement(H,6);
152  ethane->AddElement(C,2);
153 
154  G4Material* csi = new G4Material ("CsI" , 4.53*g/cm3, 2);
155  csi->AddElement(Cs,1);
156  csi->AddElement(I,1);
157
158
159  // Interactive set-up
160
161  G4cout << "Test AlongStepDoIt [1] or PostStepDoIt [2] ?" << G4endl;
162  cin >> test;
163  if ( !(test == 1 || test == 2)) G4Exception("Wrong input");
164
165  G4cout << "How many interactions? " << G4endl;
166  G4cin >> nIterations;
167
168  if (nIterations <= 0) G4Exception("Wrong input");
169
170  G4double initEnergy = 1*MeV; 
171  G4double initX = 0.; 
172  G4double initY = 0.; 
173  G4double initZ = 1.;
174
175  G4cout << "Enter the initial particle energy E (MeV)" << G4endl; 
176  G4cin >> initEnergy ;
177
178  initEnergy = initEnergy * MeV;
179
180  if (initEnergy  <= 0.) G4Exception("Wrong input");
181
182  static const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
183
184 G4int nMaterials = G4Material::GetNumberOfMaterials();
185
186  G4cout << "Available materials are: " << G4endl;
187  for (G4int mat = 0; mat < nMaterials; mat++)
188    {
189      G4cout << mat << ") "
190             << (*theMaterialTable)[mat]->GetName()
191             << G4endl;
192    }
193
194  G4cout << "Which material? " << G4endl;
195  G4cin >> materialId;
196
197  G4Material* material = (*theMaterialTable)[materialId] ;
198
199  G4cout << "The selected material is: "
200         << material->GetName()
201         << G4endl;
202
203  G4double dimX = 1*mm;
204  G4double dimY = 1*mm;
205  G4double dimZ = 1*mm;
206 
207  // Geometry
208
209  G4Box* theFrame = new G4Box ("Frame",dimX, dimY, dimZ);
210 
211  G4LogicalVolume* logicalFrame = new G4LogicalVolume(theFrame,
212                                                      (*theMaterialTable)[materialId],
213                                                      "LFrame", 0, 0, 0);
214  logicalFrame->SetMaterial(material); 
215 
216  G4PVPlacement* physicalFrame = new G4PVPlacement(0,G4ThreeVector(),
217                                                   "PFrame",logicalFrame,0,false,0);
218 
219  // Particle definitions
220
221  G4ParticleDefinition* gamma = G4Gamma::GammaDefinition();
222  G4ParticleDefinition* electron = G4Electron::ElectronDefinition();
223  G4ParticleDefinition* positron = G4Positron::PositronDefinition();
224 
225  gamma->SetCuts(1e-3*mm);
226  electron->SetCuts(1e-3*mm);
227  positron->SetCuts(1e-3*mm);
228 
229  // Processes
230
231  G4int processType;
232  G4cout << "LowEnergy [1] or Standard [2] Bremsstrahlung?" << G4endl;
233  cin >> processType;
234  if ( !(processType == 1 || processType == 2))
235    {
236      G4Exception("Wrong input");
237    }
238
239  G4VContinuousDiscreteProcess* bremProcess;
240
241  if (processType == 1)
242    {
243      bremProcess = new G4LowEnergyBremsstrahlung;
244    }
245    else
246      {
247        bremProcess = new G4eBremsstrahlung;
248      }
249
250  G4ProcessManager* eProcessManager = new G4ProcessManager(electron);
251  electron->SetProcessManager(eProcessManager);
252  eProcessManager->AddProcess(bremProcess);
253 
254  // Create a DynamicParticle 
255 
256  G4double eEnergy = initEnergy*MeV;
257  G4ParticleMomentum eDirection(initX,initY,initZ);
258  G4DynamicParticle dynamicElectron(G4Electron::Electron(),eDirection,eEnergy);
259
260  // Track
261
262  G4ThreeVector aPosition(0.,0.,0.);
263  G4ThreeVector newPosition(0.,0.,1.*mm);
264  G4double aTime = 0. ;
265
266  G4Track* eTrack = new G4Track(&dynamicElectron,aTime,aPosition);
267
268  // do I really need this?
269
270  G4GRSVolume* touche = new G4GRSVolume(physicalFrame, 0, aPosition);   
271  eTrack->SetTouchable(touche);
272 
273 // Step
274
275  G4Step* step = new G4Step(); 
276  step->SetTrack(eTrack);
277
278  G4StepPoint* aPoint = new G4StepPoint();
279  aPoint->SetPosition(aPosition);
280  aPoint->SetMaterial(material);
281  G4double safety = 10000.*cm;
282  aPoint->SetSafety(safety);
283  step->SetPreStepPoint(aPoint);
284  G4StepPoint* newPoint = new G4StepPoint();
285  newPoint->SetPosition(newPosition);
286  newPoint->SetMaterial(material);
287  step->SetPostStepPoint(newPoint);
288 
289  // Check applicability
290 
291  if (! (bremProcess->IsApplicable(*electron)))
292    {
293      G4Exception("Not Applicable");
294    }
295
296  // Initialize the physics tables
297
298  bremProcess->BuildPhysicsTable(*electron);
299       
300  // --------- Test the DoIt
301
302  G4cout << "DoIt in material " << material->GetName() << G4endl;
303
304  G4int iteration = 0;   
305 
306
307  for (G4int iter=0; iter<nIterations; iter++)
308    {
309      step->SetStepLength(1*micrometer);
310
311      G4cout  <<  "Iteration = "  <<  iter
312              << "  -  Step Length = " 
313              << step->GetStepLength()/mm << " mm "
314              << G4endl;
315
316      eTrack->SetStep(step); 
317 
318      G4cout  <<  "Iteration = "  <<  iter
319              << "  -  Step Length = " 
320              << step->GetStepLength()/mm << " mm "
321              << G4endl;
322
323      //     G4cout << eTrack->GetStep()->GetStepLength()/mm
324      //             << G4endl;
325
326      G4VParticleChange* dummy;
327      if (test == 1) dummy = bremProcess->AlongStepDoIt(*eTrack, *step);
328      if (test == 2) dummy = bremProcess->PostStepDoIt(*eTrack, *step);
329
330      G4ParticleChange* particleChange = (G4ParticleChange*) dummy;
331     
332      // Primary physical quantities
333
334      G4double energyChange = particleChange->GetEnergyChange();
335      G4double dedx = initEnergy - energyChange ;
336      G4double dedxNow = dedx / (step->GetStepLength());
337     
338      G4ThreeVector eChange = particleChange->CalcMomentum(energyChange,
339                                                           (*particleChange->GetMomentumChange()),
340                                                           particleChange->GetMassChange());
341
342      G4double pxChange  = eChange.x();
343      G4double pyChange  = eChange.y();
344      G4double pzChange  = eChange.z();
345      G4double pChange   = std::sqrt(pxChange*pxChange + pyChange*pyChange + pzChange*pzChange);
346     
347      G4double xChange = particleChange->GetPositionChange()->x();
348      G4double yChange = particleChange->GetPositionChange()->y();
349      G4double zChange = particleChange->GetPositionChange()->z();
350      G4double thetaChange = particleChange->GetPositionChange()->theta();
351
352      G4cout << "---- Primary after the step ---- " << G4endl;
353 
354      //      G4cout << "Position (x,y,z) = "
355      //             << xChange << "  "
356      //             << yChange << "   "
357      //             << zChange << "   "
358      //             << G4endl;
359
360      G4cout << "---- Energy: " << energyChange/MeV << " MeV,  " 
361             << "(px,py,pz): ("
362             << pxChange/MeV << ","
363             << pyChange/MeV << "," 
364             << pzChange/MeV << ") MeV"
365             << G4endl;
366
367      G4cout << "---- Energy loss (dE) = " << dedx/keV << " keV" << G4endl;
368      //      G4cout << "Stopping power (dE/dx)=" << dedxNow << G4endl;
369     
370      // Secondaries
371
372      ntuple1->column("eprimary", initEnergy);
373      ntuple1->column("energyf", energyChange);
374      ntuple1->column("de", dedx);
375      ntuple1->column("dedx", dedxNow);
376      ntuple1->column("pxch", xChange);
377      ntuple1->column("pych", pyChange);
378      ntuple1->column("pzch", pzChange);
379      ntuple1->column("pch", zChange); 
380      ntuple1->column("thetach", thetaChange); 
381      ntuple1->dumpData(); 
382
383      // Secondaries physical quantities
384     
385      hNSec->accumulate(particleChange->GetNumberOfSecondaries());
386      hDebug->accumulate(particleChange->GetLocalEnergyDeposit());
387     
388      for (G4int i = 0; i < (particleChange->GetNumberOfSecondaries()); i++) 
389        {
390          // The following two items should be filled per event, not
391          // per secondary; filled here just for convenience, to avoid
392          // complicated logic to dump ntuple when there are no secondaries
393         
394          G4Track* finalParticle = particleChange->GetSecondary(i) ;
395         
396          G4double e    = finalParticle->GetTotalEnergy();
397          G4double eKin = finalParticle->GetKineticEnergy();
398          G4double px   = (finalParticle->GetMomentum()).x();
399          G4double py   = (finalParticle->GetMomentum()).y();
400          G4double pz   = (finalParticle->GetMomentum()).z();
401          G4double theta   = (finalParticle->GetMomentum()).theta();
402          G4double p   = std::sqrt(px*px+py*py+pz*pz);
403
404          if (e > initEnergy)
405            {
406              G4cout << "WARNING: eFinal > eInit " << G4endl;
407                //           << e
408                //                   << " > " initEnergy
409                 
410            }
411
412          G4String particleName = finalParticle->GetDefinition()->GetParticleName();
413          G4cout  << "==== Final " 
414                  <<  particleName  <<  " " 
415                  << "energy: " <<  e/MeV  <<  " MeV,  " 
416                  << "eKin: " <<  eKin/MeV  <<  " MeV, " 
417                  << "(px,py,pz): ("
418                  <<  px/MeV  <<  "," 
419                  <<  py/MeV  <<  ","
420                  <<  pz/MeV  << ") MeV "
421                  <<  G4endl;   
422         
423          hEKin->accumulate(eKin);
424          hP->accumulate(p);
425         
426          G4int partType = 0;
427          if (particleName == "e-") partType = 1;
428          else if (particleName == "e+") partType = 2;
429          else if (particleName == "gamma") partType = 3;
430         
431          // Fill the secondaries ntuple
432          ntuple2->column("eprimary",initEnergy);
433          ntuple2->column("px", px);
434          ntuple2->column("py", py);
435          ntuple2->column("pz", pz);
436          ntuple2->column("p", p);
437          ntuple2->column("e", e);
438          ntuple2->column("theta", theta);
439          ntuple2->column("ekin", eKin);
440          ntuple2->column("type", partType);
441         
442          ntuple2->dumpData(); 
443         
444          delete particleChange->GetSecondary(i);
445        }
446     
447      particleChange->Clear();
448     
449    } 
450 
451 
452  cout  << "Iteration number: "  <<  G4endl;
453  hbookManager->write();
454  delete hbookManager;
455 
456  // delete materials and elements
457  //  delete Be;
458  //  delete Graphite;
459  //  delete Al;
460  //  delete Si;
461  //  delete LAr;
462  //  delete Fe;
463  //  delete Cu;
464  //  delete W;
465  //  delete Pb;
466  //  delete U;
467  //  delete H;
468  //  delete maO;
469  //  delete C;
470  //  delete Cs;
471  //  delete I;
472  //  delete O;
473  //  delete water;
474  //  delete ethane;
475  //  delete csi;
476  //  delete step;
477  //  delete touche;
478  //  delete Be;
479  //  delete Graphite;
480  //  delete Al;
481  //  delete Si;
482  //  delete LAr;
483  //  delete Fe;
484  //  delete Cu;
485  //  delete W;
486  //  delete Pb;
487  //  delete U;
488  //  delete H;
489  //  delete maO;
490  //  delete C;
491  //  delete Cs;
492  //  delete I;
493  //  delete O;
494  //  delete water;
495  //  delete ethane;
496  //  delete csi;
497  delete step;
498  //  delete touche;
499
500  cout << "END OF THE MAIN PROGRAM" << G4endl;
501}
502
503
504
505
506
507
508
509
510
511
512
513
Note: See TracBrowser for help on using the repository browser.