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

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

update to last version 4.9.4

File size: 19.3 KB
RevLine 
[1350]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: G4PenelopeRayleighTest.cc,v 1.7 2006/06/29 19:44:26 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: G4PenelopeRayleighTest.cc
36//
37// Author: Francesco Longo
38//
39// Creation date: 04 january 2001
40//
41// Modifications: Luciano Pandola (27 november 2002)
42// Adapted in order to test G4PenelopeRayleigh
43// Minor modification in n-tuple filling
44// Updated analysis to AIDA 3.0
45//
46// -------------------------------------------------------------------
47
48#include "globals.hh"
49#include "G4ios.hh"
50#include <fstream>
51#include <iomanip>
52
53#include "G4ParticleDefinition.hh"
54#include "G4ParticleTypes.hh"
55#include "G4ParticleTable.hh"
56#include "G4Material.hh"
57#include "G4MaterialTable.hh"
58#include "G4VDiscreteProcess.hh"
59#include "G4VProcess.hh"
60#include "G4ProcessManager.hh"
61#include "G4LowEnergyRayleigh.hh"
62#include "G4PenelopeRayleigh.hh"
63#include "G4EnergyLossTables.hh"
64#include "G4VParticleChange.hh"
65#include "G4ParticleChange.hh"
66#include "G4DynamicParticle.hh"
67#include "G4ForceCondition.hh"
68#include "G4RunManager.hh"
69
70#include "G4LowEnergyBremsstrahlung.hh"
71#include "G4LowEnergyIonisation.hh"
72#include "G4eIonisation.hh"
73#include "G4MultipleScattering.hh"
74#include "G4eIonisation.hh"
75#include "G4eBremsstrahlung.hh"
76#include "G4eplusAnnihilation.hh"
77
78#include "G4ComptonScattering.hh"
79#include "G4PhotoElectricEffect.hh"
80
81#include "G4Electron.hh"
82#include "G4Positron.hh"
83#include "G4Gamma.hh"
84
85#include "G4GRSVolume.hh"
86#include "G4Box.hh"
87#include "G4PVPlacement.hh"
88#include "G4Step.hh"
89#include "G4ProductionCutsTable.hh"
90#include "G4MaterialCutsCouple.hh"
91
92#include "G4UnitsTable.hh"
93#include "AIDA/IManagedObject.h"
94
95#include <memory>
96#include "AIDA/IAnalysisFactory.h"
97#include "AIDA/ITreeFactory.h"
98#include "AIDA/ITree.h"
99#include "AIDA/IHistogramFactory.h"
100#include "AIDA/IHistogram1D.h"
101#include "AIDA/IHistogram2D.h"
102#include "AIDA/IHistogram3D.h"
103#include "AIDA/ITupleFactory.h"
104#include "AIDA/ITuple.h"
105
106
107G4int main()
108{
109
110 // Setup
111
112 G4int nIterations = 100000;
113 G4int materialId = 3;
114
115 //G4cout.setf(std::ios::scientific,std::ios::floatfield );
116
117 // -------------------------------------------------------------------
118
119 // ---- HBOOK initialization
120
121 std::auto_ptr< AIDA::IAnalysisFactory > af( AIDA_createAnalysisFactory() );
122 std::auto_ptr< AIDA::ITreeFactory > tf (af->createTreeFactory());
123 std::auto_ptr< AIDA::ITree > tree (tf->create("pen_ray_test.hbook","hbook",false,true));
124 G4cout << "Tree store: " << tree->storeName() << G4endl;
125 std::auto_ptr< AIDA::ITupleFactory > tpf (af->createTupleFactory(*tree));
126 std::auto_ptr< AIDA::IHistogramFactory > hf (af->createHistogramFactory(*tree));
127
128 // ---- primary ntuple ------
129 AIDA::ITuple* ntuple1 = tpf->create("1","Primary Ntuple","double eprimary,energyf,de,dedx,pxch,pych,pzch,pch,thetach");
130
131 // ---- secondary ntuple ------
132 //AIDA::ITuple* ntuple2 = tpf->create("2","Secondary Ntuple","double
133 //eprimary,px_el,py_el,pz_el,p_el,e_el,theta_el,ekin_el,px_po,py_po,pz_po,
134 //p_po,e_po,theta_po,ekin_po");
135
136 // ---- table ntuple ------
137 AIDA::ITuple* ntuple3 = tpf->create("3","Mean Free Path Ntuple","double kinen,mfp");
138
139 //--------- Materials definition ---------
140 G4Element* SiEl = new G4Element ("SiEl","Si",14.,28.055*g/mole);
141 G4Element* FeEl = new G4Element ("FeEl","Fe",26.,55.58*g/mole);
142 G4Element* CuEl = new G4Element ("CuEl","Cu",29.,63.55*g/mole);
143 G4Element* WEl = new G4Element ("WEl","W",74.,183.85*g/mole);
144 G4Element* PbEl = new G4Element ("PbEl","Pb",82.,207.19*g/mole);
145 G4Element* UEl = new G4Element ("UEl","U",92.,238.03*g/mole);
146 G4Element* H = new G4Element ("Hydrogen", "H", 1. , 1.01*g/mole);
147 G4Element* O = new G4Element ("Oxygen" , "O", 8. , 16.00*g/mole);
148 G4Element* C = new G4Element ("Carbon" , "C", 6. , 12.00*g/mole);
149 G4Element* Cs = new G4Element ("Cesium" , "Cs", 55. , 132.905*g/mole);
150 G4Element* I = new G4Element ("Iodine" , "I", 53. , 126.9044*g/mole);
151 G4Element* N = new G4Element ("Nitrogen","N",7.,14.0*g/mole);
152
153 G4Material* Si = new G4Material("Silicon", 2.33*g/cm3,1);
154 Si->AddElement(SiEl,1);
155 G4Material* Fe = new G4Material("Iron",7.87*g/cm3,1);
156 Fe->AddElement(FeEl,1);
157 G4Material* Cu = new G4Material("Copper", 8.96*g/cm3,1);
158 Cu->AddElement(CuEl,1);
159 G4Material* W = new G4Material("Tungsten",19.30*g/cm3,1);
160 W->AddElement(WEl,1);
161 G4Material* Pb = new G4Material("Lead",11.35*g/cm3,1);
162 Pb->AddElement(PbEl,1);
163 G4Material* U = new G4Material("Uranium",18.95*g/cm3,1);
164 U->AddElement(UEl,1);
165 G4Material* maO = new G4Material("Oxygen", 1.1*g/cm3,1);
166 maO->AddElement(O,2);
167 G4Material* water = new G4Material ("Water" , 1.*g/cm3, 2);
168 water->AddElement(H,2);
169 water->AddElement(O,1);
170 G4Material* ethane = new G4Material ("Ethane" , 0.4241*g/cm3, 2);
171 ethane->AddElement(H,6);
172 ethane->AddElement(C,2);
173 G4Material* csi = new G4Material ("CsI" , 4.53*g/cm3, 2);
174 csi->AddElement(Cs,1);
175 csi->AddElement(I,1);
176 G4Material* Air = new G4Material
177 ("Air", 1.2929*kg/m3, 2, kStateGas, 300.00*kelvin, 1.0*atmosphere);
178 Air->AddElement(N,0.8);
179 Air->AddElement(O,0.2);
180
181
182
183 // Interactive set-up
184
185 G4cout << "How many interactions? " << G4endl;
186 G4cin >> nIterations;
187
188 if (nIterations <= 0) G4Exception("Wrong input");
189
190 G4double initEnergy = 10*keV;
191 G4double initX = 0.;
192 G4double initY = 0.;
193 G4double initZ = 1.;
194
195 G4cout << "Enter the initial particle energy E (MeV)" << G4endl;
196 G4cin >> initEnergy ;
197
198 initEnergy = initEnergy*MeV;
199
200 if (initEnergy <= 0.) G4Exception("Wrong input");
201
202 static const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
203
204 G4int nMaterials = G4Material::GetNumberOfMaterials();
205
206 G4cout << "Available materials are: " << G4endl;
207 for (G4int mat = 0; mat < nMaterials; mat++)
208 {
209 G4cout << mat << ") "
210 << (*theMaterialTable)[mat]->GetName()
211 << G4endl;
212 }
213
214 G4cout << "Which material? " << G4endl;
215 G4cin >> materialId;
216
217 G4Material* material = (*theMaterialTable)[materialId] ;
218
219 G4cout << "The selected material is: "
220 << material->GetName()
221 << G4endl;
222
223 G4double dimX = 1*mm;
224 G4double dimY = 1*mm;
225 G4double dimZ = 1*mm;
226
227 // Geometry
228
229 G4Box* theFrame = new G4Box ("Frame",dimX, dimY, dimZ);
230
231 G4LogicalVolume* logicalFrame = new G4LogicalVolume(theFrame,
232 (*theMaterialTable)[materialId],
233 "LFrame", 0, 0, 0);
234 logicalFrame->SetMaterial(material);
235
236 G4PVPlacement* physicalFrame = new G4PVPlacement(0,G4ThreeVector(),
237 "PFrame",logicalFrame,0,false,0);
238 G4RunManager* rm = new G4RunManager();
239 G4cout << "World is defined " << G4endl;
240 rm->GeometryHasBeenModified();
241 rm->DefineWorldVolume(physicalFrame);
242 // Particle definitions
243
244 G4ParticleDefinition* gamma = G4Gamma::GammaDefinition();
245 G4ParticleDefinition* electron = G4Electron::ElectronDefinition();
246 G4ParticleDefinition* positron = G4Positron::PositronDefinition();
247
248 G4ProductionCutsTable* cutsTable = G4ProductionCutsTable::GetProductionCutsTable();
249 G4ProductionCuts* cuts = cutsTable->GetDefaultProductionCuts();
250 G4double cutG=1*micrometer;
251 G4double cutE=1*micrometer;
252 cuts->SetProductionCut(cutG, 0); //gammas
253 cuts->SetProductionCut(cutE, 1); //electrons
254 cuts->SetProductionCut(cutE, 2); //positrons
255 G4cout << "Cuts are defined " << G4endl;
256
257 //G4Gamma::SetEnergyRange(2.5e-4*MeV,1e5*MeV);
258 //G4Electron::SetEnergyRange(2.5e-4*MeV,1e5*MeV);
259 //G4Positron::SetEnergyRange(2.5e-4*MeV,1e5*MeV);
260
261 cutsTable->UpdateCoupleTable();
262 //cutsTable->DumpCouples();
263 const G4MaterialCutsCouple* theCouple = cutsTable->GetMaterialCutsCouple(material,cuts);
264 // Processes
265
266
267 G4int processType;
268 G4cout << "LowEnergy[1] or Penelope [2] Rayleigh?" << G4endl;
269 G4cin >> processType;
270 if ( !(processType == 1 || processType == 2))
271 {
272 G4Exception("Wrong input");
273 }
274
275 G4VDiscreteProcess* gammaProcess;
276
277 if (processType == 1)
278 {
279 gammaProcess = new G4LowEnergyRayleigh();
280 G4cout << "The selected model is Low Energy" << G4endl;
281 }
282 else if (processType == 2)
283 {
284 gammaProcess = new G4PenelopeRayleigh();
285 G4cout << "The selected model is Penelope" << G4endl;
286 }
287
288 G4VProcess* theeminusMultipleScattering = new G4MultipleScattering();
289 G4VProcess* theeminusIonisation = new G4eIonisation();
290 G4VProcess* theeminusBremsstrahlung = new G4eBremsstrahlung();
291 G4VProcess* theeplusMultipleScattering = new G4MultipleScattering();
292 G4VProcess* theeplusIonisation = new G4eIonisation();
293 G4VProcess* theeplusBremsstrahlung = new G4eBremsstrahlung();
294 G4VProcess* theeplusAnnihilation = new G4eplusAnnihilation();
295
296 //----------------
297 // process manager
298 //----------------
299
300 // gamma
301
302 G4ProcessManager* gProcessManager = new G4ProcessManager(gamma);
303 gamma->SetProcessManager(gProcessManager);
304 gProcessManager->AddDiscreteProcess(gammaProcess);
305 G4ForceCondition* condition; //l'ho fissata a zero! E' onesto??
306
307 //electron
308
309 G4ProcessManager* eProcessManager = new G4ProcessManager(electron);
310 electron->SetProcessManager(eProcessManager);
311 eProcessManager->AddProcess(theeminusMultipleScattering);
312 eProcessManager->AddProcess(theeminusIonisation);
313 eProcessManager->AddProcess(theeminusBremsstrahlung);
314
315 //positron
316
317 G4ProcessManager* pProcessManager = new G4ProcessManager(positron);
318 positron->SetProcessManager(pProcessManager);
319 pProcessManager->AddProcess(theeplusMultipleScattering);
320 pProcessManager->AddProcess(theeplusIonisation);
321 pProcessManager->AddProcess(theeplusBremsstrahlung);
322 pProcessManager->AddProcess(theeplusAnnihilation);
323
324 //--------------
325 // set ordering
326 //--------------
327
328
329 eProcessManager->
330 SetProcessOrdering(theeminusMultipleScattering, idxAlongStep,1);
331 eProcessManager->
332 SetProcessOrdering(theeminusIonisation, idxAlongStep,2);
333
334 eProcessManager->
335 SetProcessOrdering(theeminusMultipleScattering, idxPostStep,1);
336 eProcessManager->
337 SetProcessOrdering(theeminusIonisation, idxPostStep,2);
338 eProcessManager->
339 SetProcessOrdering(theeminusBremsstrahlung, idxPostStep,3);
340
341
342
343 pProcessManager->SetProcessOrderingToFirst(theeplusAnnihilation, idxAtRest);
344 pProcessManager->
345 SetProcessOrdering(theeplusMultipleScattering, idxAlongStep,1);
346 pProcessManager->
347 SetProcessOrdering(theeplusIonisation, idxAlongStep,2);
348
349 pProcessManager->
350 SetProcessOrdering(theeplusMultipleScattering, idxPostStep,1);
351 pProcessManager->
352 SetProcessOrdering(theeplusIonisation, idxPostStep,2);
353 pProcessManager->
354 SetProcessOrdering(theeplusBremsstrahlung, idxPostStep,3);
355 pProcessManager->
356 SetProcessOrdering(theeplusAnnihilation, idxPostStep,4);
357
358 // G4LowEnergyIonisation IonisationProcess;
359 // eProcessManager->AddProcess(&IonisationProcess);
360 // eProcessManager->SetProcessOrdering(&IonisationProcess,idxAlongStep,1);
361 // eProcessManager->SetProcessOrdering(&IonisationProcess,idxPostStep, 1);
362
363 // G4LowEnergyBremsstrahlung BremstrahlungProcess;
364 // eProcessManager->AddProcess(&BremstrahlungProcess);
365 // eProcessManager->SetProcessOrdering(&BremstrahlungProcess,idxAlongStep,1);
366 // eProcessManager->SetProcessOrdering(&BremstrahlungProcess,idxPostStep, 1);
367
368 // G4eIonisation IonisationPlusProcess;
369 // pPositronProcessManager->AddProcess(&IonisationPlusProcess);
370 // pProcessManager->
371 // SetProcessOrdering(&IonisationPlusProcess,idxAlongStep,1);
372 // pProcessManager->SetProcessOrdering(&IonisationPlusProcess,idxPostStep,1);
373
374
375
376 // Create a DynamicParticle
377
378 G4double eEnergy = initEnergy*MeV;
379 G4ParticleMomentum eDirection(initX,initY,initZ);
380 G4DynamicParticle dynamicGamma(G4Gamma::Gamma(),eDirection,eEnergy);
381
382 dynamicGamma.DumpInfo(0);
383
384 // Track
385
386 G4ThreeVector aPosition(0.,0.,0.);
387 G4double aTime = 0. ;
388
389 G4Track* gTrack = new G4Track(&dynamicGamma,aTime,aPosition);
390
391 G4GRSVolume* touche = new G4GRSVolume(physicalFrame, NULL, aPosition);
392 gTrack->SetTouchableHandle(touche); //verificare!!!!!!!!!!!!
393
394
395 // Step
396
397 G4Step* step = new G4Step();
398 step->SetTrack(gTrack);
399
400 G4StepPoint* aPoint = new G4StepPoint();
401 aPoint->SetPosition(aPosition);
402 aPoint->SetMaterial(material);
403 aPoint->SetMaterialCutsCouple(theCouple);
404 G4double safety = 10000.*cm;
405 aPoint->SetSafety(safety);
406 step->SetPreStepPoint(aPoint);
407
408 // Check applicability
409
410 if (! (gammaProcess->IsApplicable(*gamma)))
411 {
412 G4Exception("Not Applicable");
413 }
414 else
415 {
416 G4cout<< "applicability OK" << G4endl;
417 }
418
419 // Initialize the physics tables (in which material?)
420
421 gammaProcess->BuildPhysicsTable(*gamma);
422
423
424 theeminusMultipleScattering->BuildPhysicsTable(*electron);
425 theeminusIonisation->BuildPhysicsTable(*electron);
426 theeminusBremsstrahlung->BuildPhysicsTable(*electron);
427 theeplusMultipleScattering->BuildPhysicsTable(*positron);
428 theeplusIonisation->BuildPhysicsTable(*positron);
429 theeplusBremsstrahlung->BuildPhysicsTable(*positron);
430 theeplusAnnihilation->BuildPhysicsTable(*positron) ;
431
432 G4cout<< "table OK" << G4endl;
433 G4Material* apttoMaterial ;
434 G4String MaterialName ;
435
436 G4double minArg = 100*eV,maxArg = 100*GeV, argStp;
437 const G4int pntNum = 300;
438 G4double Tkin[pntNum+1];
439 G4double meanFreePath=0. ;
440
441 argStp = (std::log10(maxArg)-std::log10(minArg))/pntNum;
442
443 for(G4int d = 0; d < pntNum+1; d++)
444 {
445 Tkin[d] = std::pow(10,(std::log10(minArg) + d*argStp));
446 }
447
448 G4double sti = 1.*mm;
449 step->SetStepLength(sti);
450
451 // for ( G4int J = 0 ; J < nMaterials ; J++ )
452 // {
453 apttoMaterial = (*theMaterialTable)[materialId] ;
454 MaterialName = apttoMaterial->GetName() ;
455 logicalFrame->SetMaterial(apttoMaterial);
456
457 gTrack->SetStep(step);
458
459
460 G4LowEnergyRayleigh* gammaLowEProcess2 = (G4LowEnergyRayleigh*) gammaProcess;
461 G4PenelopeRayleigh* gammaLowEProcess = (G4PenelopeRayleigh*) gammaProcess;
462
463 for (G4int i=0 ; i<pntNum; i++)
464 {
465 dynamicGamma.SetKineticEnergy(Tkin[i]);
466 if (processType == 1)
467 {
468 meanFreePath=gammaLowEProcess2
469 ->DumpMeanFreePath(*gTrack, sti, condition);
470 }
471 else if (processType == 2)
472 {
473 meanFreePath=gammaLowEProcess
474 ->DumpMeanFreePath(*gTrack, sti, condition);
475 }
476
477 ntuple3->fill(ntuple3->findColumn("kinen"),std::log10(Tkin[i]));
478 ntuple3->fill(ntuple3->findColumn("mfp"),std::log10(meanFreePath/cm));
479 ntuple3->addRow();
480 // if (Tkin[i]<10*MeV)
481// G4cout << "Mean free path @" << Tkin[i] << ": " << meanFreePath/cm << G4endl;
482 }
483 G4cout << "Mean Free Path OK" << G4endl;
484
485 // --------- Test the DoIt
486
487 G4cout << "DoIt in " << material->GetName() << G4endl;
488
489
490 dynamicGamma.SetKineticEnergy(eEnergy);
491 G4int iter;
492 for (iter=0; iter<nIterations; iter++)
493 {
494
495 step->SetStepLength(1*micrometer);
496
497 G4cout << "Iteration = " << iter
498 << " - Step Length = "
499 << step->GetStepLength()/mm << " mm "
500 << G4endl;
501
502
503 gTrack->SetStep(step);
504
505
506 G4VParticleChange* dummy;
507 dummy = gammaProcess->PostStepDoIt(*gTrack, *step);
508
509 G4ParticleChange* particleChange = (G4ParticleChange*) dummy;
510
511 // Primary physical quantities
512
513 G4double energyChange = particleChange->GetEnergyChange();
514
515 G4double dedx = initEnergy - energyChange ;
516 G4double dedxNow = dedx / (step->GetStepLength());
517
518 G4ThreeVector eChange =
519 particleChange->CalcMomentum(energyChange,
520 (*particleChange->GetMomentumChange()),
521 particleChange->GetMassChange());
522
523 G4double pxChange = eChange.x();
524 G4double pyChange = eChange.y();
525 G4double pzChange = eChange.z();
526 G4double pChange =
527 std::sqrt(pxChange*pxChange + pyChange*pyChange + pzChange*pzChange);
528 G4double thetaChange = eChange.theta();
529 thetaChange = thetaChange/deg; //conversion in degrees
530 G4double xChange = particleChange->GetPositionChange()->x();
531 G4double yChange = particleChange->GetPositionChange()->y();
532 G4double zChange = particleChange->GetPositionChange()->z();
533 //G4double thetaChange = particleChange->GetPositionChange()->theta();
534
535 G4cout << "---- Primary after the step ---- " << G4endl;
536
537 G4cout << "Position (x,y,z) = "
538 << xChange << " "
539 << yChange << " "
540 << zChange << " "
541 << G4endl;
542
543 G4cout << "---- Energy: " << energyChange/MeV << " MeV, "
544 << "(px,py,pz): ("
545 << pxChange/MeV << ","
546 << pyChange/MeV << ","
547 << pzChange/MeV << ") MeV"
548 << G4endl;
549
550 G4cout << "---- Energy loss (dE) = " << dedx/keV << " keV" << G4endl;
551 // G4cout << "Stopping power (dE/dx)=" << dedxNow << G4endl;
552
553 ntuple1->fill(ntuple1->findColumn("eprimary"),initEnergy/MeV);
554 ntuple1->fill(ntuple1->findColumn("energyf"),energyChange/initEnergy);
555 ntuple1->fill(ntuple1->findColumn("de"),dedx/MeV);
556 ntuple1->fill(ntuple1->findColumn("dedx"),dedxNow/(MeV/cm));
557 ntuple1->fill(ntuple1->findColumn("pxch"),pxChange/initEnergy);
558 ntuple1->fill(ntuple1->findColumn("pych"),pyChange/initEnergy);
559 ntuple1->fill(ntuple1->findColumn("pzch"),pzChange/initEnergy);
560 ntuple1->fill(ntuple1->findColumn("pch"),pChange/initEnergy);
561 ntuple1->fill(ntuple1->findColumn("thetach"),thetaChange);
562 ntuple1->addRow();
563
564 }
565
566 G4cout << "Iteration number: " << iter << G4endl;
567
568 G4cout << "Committing.............." << G4endl;
569 tree->commit();
570 G4cout << "Closing the tree........" << G4endl;
571 tree->close();
572
573 delete step;
574
575
576 G4cout << "END OF THE MAIN PROGRAM" << G4endl;
577 return 0;
578}
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
Note: See TracBrowser for help on using the repository browser.