source: trunk/source/processes/electromagnetic/lowenergy/test/G4PenelopeGammaConversionTest.cc@ 1201

Last change on this file since 1201 was 1199, checked in by garnier, 16 years ago

nvx fichiers dans CVS

File size: 23.2 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: G4PenelopeGammaConversionTest.cc,v 1.8 2006/06/29 19:44:20 gunter Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30// -------------------------------------------------------------------
31// GEANT 4 class file --- Copyright CERN 1998
32// CERN Geneva Switzerland
33//
34//
35// File name: G4PenelopeGammaConversionTest.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 G4PenelopeGammaConversion
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
62#include "G4PenelopeGammaConversion.hh"
63#include "G4LowEnergyGammaConversion.hh"
64#include "G4GammaConversion.hh"
65
66#include "G4EnergyLossTables.hh"
67#include "G4VParticleChange.hh"
68#include "G4ParticleChange.hh"
69#include "G4DynamicParticle.hh"
70#include "G4ForceCondition.hh"
71
72#include "G4LowEnergyBremsstrahlung.hh"
73#include "G4LowEnergyIonisation.hh"
74#include "G4eIonisation.hh"
75#include "G4MultipleScattering.hh"
76#include "G4eIonisation.hh"
77#include "G4eBremsstrahlung.hh"
78#include "G4eplusAnnihilation.hh"
79
80#include "G4ComptonScattering.hh"
81#include "G4PhotoElectricEffect.hh"
82
83#include "G4RunManager.hh"
84
85#include "G4Electron.hh"
86#include "G4Positron.hh"
87#include "G4Gamma.hh"
88
89#include "G4GRSVolume.hh"
90#include "G4Box.hh"
91#include "G4PVPlacement.hh"
92#include "G4Step.hh"
93#include "G4ProductionCutsTable.hh"
94#include "G4MaterialCutsCouple.hh"
95
96#include "G4UnitsTable.hh"
97#include "AIDA/IManagedObject.h"
98
99#include <memory>
100#include "AIDA/IAnalysisFactory.h"
101#include "AIDA/ITreeFactory.h"
102#include "AIDA/ITree.h"
103#include "AIDA/IHistogramFactory.h"
104#include "AIDA/IHistogram1D.h"
105#include "AIDA/IHistogram2D.h"
106#include "AIDA/IHistogram3D.h"
107#include "AIDA/ITupleFactory.h"
108#include "AIDA/ITuple.h"
109
110
111G4int main()
112{
113
114 // Setup
115
116 G4int nIterations = 100000;
117 G4int materialId = 3;
118
119 //G4cout.setf(std::ios::scientific,std::ios::floatfield );
120
121 // -------------------------------------------------------------------
122
123 // ---- HBOOK initialization
124
125 std::auto_ptr< AIDA::IAnalysisFactory > af( AIDA_createAnalysisFactory() );
126 std::auto_ptr< AIDA::ITreeFactory > tf (af->createTreeFactory());
127 std::auto_ptr< AIDA::ITree > tree (tf->create("Pen_pp_test.hbook","hbook",false,true));
128 G4cout << "Tree store: " << tree->storeName() << G4endl;
129 std::auto_ptr< AIDA::ITupleFactory > tpf (af->createTupleFactory(*tree));
130 std::auto_ptr< AIDA::IHistogramFactory > hf (af->createHistogramFactory(*tree));
131
132 // ---- primary ntuple ------
133 //AIDA::ITuple* ntuple1 = tpf->create("1","Primary Ntuple","double eprimary,energyf,de,dedx,pxch,pych,pzch,pch,thetach");
134
135 // ---- secondary ntuple ------
136 AIDA::ITuple* ntuple2 = tpf->create("2","Secondary Ntuple","double eprimary,px_el,py_el,pz_el,p_el,e_el,theta_el,ekin_el,px_po,py_po,pz_po,p_po,e_po,theta_po,ekin_po");
137
138 // ---- table ntuple ------
139 AIDA::ITuple* ntuple3 = tpf->create("3","Mean Free Path Ntuple","double kinen,mfp");
140
141 // ---- secondaries histos ----
142 AIDA::IHistogram1D* hEKin;
143 hEKin = hf->createHistogram1D("10","Kinetic Energy", 100,0.,10.);
144
145 AIDA::IHistogram1D* hP;
146 hP = hf->createHistogram1D("20","Momentum", 100,0.,10.);
147
148 AIDA::IHistogram1D* hNSec;
149 hNSec = hf->createHistogram1D("30","Number of secondaries", 40,0.,40.);
150
151 AIDA::IHistogram1D* hDebug;
152 hDebug = hf->createHistogram1D("40","Debug", 100,0.,200.);
153
154
155 //--------- Materials definition ---------
156
157 G4Material* Si = new G4Material("Silicon", 14., 28.055*g/mole, 2.33*g/cm3);
158 G4Material* Fe = new G4Material("Iron", 26., 55.85*g/mole, 7.87*g/cm3);
159 G4Material* Cu = new G4Material("Copper", 29., 63.55*g/mole, 8.96*g/cm3);
160 G4Material* W = new G4Material("Tungsten", 74., 183.85*g/mole, 19.30*g/cm3);
161 G4Material* Pb = new G4Material("Lead", 82., 207.19*g/mole, 11.35*g/cm3);
162 G4Material* U = new G4Material("Uranium", 92., 238.03*g/mole, 18.95*g/cm3);
163
164 G4Element* H = new G4Element ("Hydrogen", "H", 1. , 1.01*g/mole);
165 G4Element* O = new G4Element ("Oxygen" , "O", 8. , 16.00*g/mole);
166 G4Element* C = new G4Element ("Carbon" , "C", 6. , 12.00*g/mole);
167 G4Element* Cs = new G4Element ("Cesium" , "Cs", 55. , 132.905*g/mole);
168 G4Element* I = new G4Element ("Iodine" , "I", 53. , 126.9044*g/mole);
169
170 G4Material* maO = new G4Material("Oxygen", 8., 16.00*g/mole, 1.1*g/cm3);
171
172 G4Material* water = new G4Material ("Water" , 1.*g/cm3, 2);
173 water->AddElement(H,2);
174 water->AddElement(O,1);
175
176 G4Material* ethane = new G4Material ("Ethane" , 0.4241*g/cm3, 2);
177 ethane->AddElement(H,6);
178 ethane->AddElement(C,2);
179
180 G4Material* csi = new G4Material ("CsI" , 4.53*g/cm3, 2);
181 csi->AddElement(Cs,1);
182 csi->AddElement(I,1);
183
184
185 // Interactive set-up
186
187 G4cout << "How many interactions? " << G4endl;
188 G4cin >> nIterations;
189
190 if (nIterations <= 0) G4Exception("Wrong input");
191
192 G4double initEnergy = 1*MeV;
193 G4double initX = 0.;
194 G4double initY = 0.;
195 G4double initZ = 1.;
196
197 G4cout << "Enter the initial particle energy E (MeV)" << G4endl;
198 G4cin >> initEnergy ;
199
200 initEnergy = initEnergy*MeV;
201
202 if (initEnergy <= 0.) G4Exception("Wrong input");
203
204 static const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
205
206 G4int nMaterials = G4Material::GetNumberOfMaterials();
207
208 G4cout << "Available materials are: " << G4endl;
209 for (G4int mat = 0; mat < nMaterials; mat++)
210 {
211 G4cout << mat << ") "
212 << (*theMaterialTable)[mat]->GetName()
213 << G4endl;
214 }
215
216 G4cout << "Which material? " << G4endl;
217 G4cin >> materialId;
218
219 G4Material* material = (*theMaterialTable)[materialId] ;
220
221 G4cout << "The selected material is: "
222 << material->GetName()
223 << G4endl;
224
225 G4double dimX = 1*mm;
226 G4double dimY = 1*mm;
227 G4double dimZ = 1*mm;
228
229 // Geometry
230
231 G4Box* theFrame = new G4Box ("Frame",dimX, dimY, dimZ);
232
233 G4LogicalVolume* logicalFrame = new G4LogicalVolume(theFrame,
234 (*theMaterialTable)[materialId],
235 "LFrame", 0, 0, 0);
236 logicalFrame->SetMaterial(material);
237
238 G4PVPlacement* physicalFrame = new G4PVPlacement(0,G4ThreeVector(),
239 "PFrame",logicalFrame,0,false,0);
240
241 G4RunManager* rm = new G4RunManager();
242 G4cout << "World is defined " << G4endl;
243 rm->GeometryHasBeenModified();
244 rm->DefineWorldVolume(physicalFrame);
245
246 // Particle definitions
247
248 G4ParticleDefinition* gamma = G4Gamma::GammaDefinition();
249 G4ParticleDefinition* electron = G4Electron::ElectronDefinition();
250 G4ParticleDefinition* positron = G4Positron::PositronDefinition();
251
252 G4ProductionCutsTable* cutsTable = G4ProductionCutsTable::GetProductionCutsTable();
253 G4ProductionCuts* cuts = cutsTable->GetDefaultProductionCuts();
254 G4double cutG=1*micrometer;
255 G4double cutE=1*micrometer;
256 cuts->SetProductionCut(cutG, 0); //gammas
257 cuts->SetProductionCut(cutE, 1); //electrons
258 cuts->SetProductionCut(cutE, 2); //positrons
259 G4cout << "Cuts are defined " << G4endl;
260
261 //G4Gamma::SetEnergyRange(2.5e-4*MeV,1e5*MeV);
262 //G4Electron::SetEnergyRange(2.5e-4*MeV,1e5*MeV);
263 //G4Positron::SetEnergyRange(2.5e-4*MeV,1e5*MeV);
264
265 cutsTable->UpdateCoupleTable();
266 //cutsTable->DumpCouples();
267 const G4MaterialCutsCouple* theCouple = cutsTable->GetMaterialCutsCouple(material,cuts);
268 G4int indx=theCouple->GetIndex();
269
270 // Processes
271
272
273 G4int processType;
274 G4cout << "Standard [1] or LowEnergy[2] or Penelope [3] Gamma Conversion?" << G4endl;
275 G4cin >> processType;
276 if ( !(processType == 1 || processType == 2 || processType == 3))
277 {
278 G4Exception("Wrong input");
279 }
280
281 G4VDiscreteProcess* gammaProcess;
282
283 if (processType == 1)
284 {
285 gammaProcess = new G4GammaConversion();
286 G4cout << "The selected model is Standard" << G4endl;
287 }
288 else if (processType == 2)
289 {
290 gammaProcess = new G4LowEnergyGammaConversion();
291 G4cout << "The selected model is Low Energy" << G4endl;
292 }
293 else if (processType == 3)
294 {
295
296 gammaProcess = new G4PenelopeGammaConversion();
297 G4cout << "The selected model is Penelope" << G4endl;
298 }
299
300 G4VProcess* theeminusMultipleScattering = new G4MultipleScattering();
301 G4VProcess* theeminusIonisation = new G4eIonisation();
302 G4VProcess* theeminusBremsstrahlung = new G4eBremsstrahlung();
303 G4VProcess* theeplusMultipleScattering = new G4MultipleScattering();
304 G4VProcess* theeplusIonisation = new G4eIonisation();
305 G4VProcess* theeplusBremsstrahlung = new G4eBremsstrahlung();
306 G4VProcess* theeplusAnnihilation = new G4eplusAnnihilation();
307
308 //----------------
309 // process manager
310 //----------------
311
312 // gamma
313
314 G4ProcessManager* gProcessManager = new G4ProcessManager(gamma);
315 gamma->SetProcessManager(gProcessManager);
316 gProcessManager->AddDiscreteProcess(gammaProcess);
317 G4ForceCondition* condition;
318
319 //electron
320
321 G4ProcessManager* eProcessManager = new G4ProcessManager(electron);
322 electron->SetProcessManager(eProcessManager);
323 eProcessManager->AddProcess(theeminusMultipleScattering);
324 eProcessManager->AddProcess(theeminusIonisation);
325 eProcessManager->AddProcess(theeminusBremsstrahlung);
326
327 //positron
328
329 G4ProcessManager* pProcessManager = new G4ProcessManager(positron);
330 positron->SetProcessManager(pProcessManager);
331 pProcessManager->AddProcess(theeplusMultipleScattering);
332 pProcessManager->AddProcess(theeplusIonisation);
333 pProcessManager->AddProcess(theeplusBremsstrahlung);
334 pProcessManager->AddProcess(theeplusAnnihilation);
335
336 //--------------
337 // set ordering
338 //--------------
339
340
341 eProcessManager->
342 SetProcessOrdering(theeminusMultipleScattering, idxAlongStep,1);
343 eProcessManager->
344 SetProcessOrdering(theeminusIonisation, idxAlongStep,2);
345
346 eProcessManager->
347 SetProcessOrdering(theeminusMultipleScattering, idxPostStep,1);
348 eProcessManager->
349 SetProcessOrdering(theeminusIonisation, idxPostStep,2);
350 eProcessManager->
351 SetProcessOrdering(theeminusBremsstrahlung, idxPostStep,3);
352
353
354
355 pProcessManager->SetProcessOrderingToFirst(theeplusAnnihilation, idxAtRest);
356 pProcessManager->
357 SetProcessOrdering(theeplusMultipleScattering, idxAlongStep,1);
358 pProcessManager->
359 SetProcessOrdering(theeplusIonisation, idxAlongStep,2);
360
361 pProcessManager->
362 SetProcessOrdering(theeplusMultipleScattering, idxPostStep,1);
363 pProcessManager->
364 SetProcessOrdering(theeplusIonisation, idxPostStep,2);
365 pProcessManager->
366 SetProcessOrdering(theeplusBremsstrahlung, idxPostStep,3);
367 pProcessManager->
368 SetProcessOrdering(theeplusAnnihilation, idxPostStep,4);
369
370 // G4LowEnergyIonisation IonisationProcess;
371 // eProcessManager->AddProcess(&IonisationProcess);
372 // eProcessManager->SetProcessOrdering(&IonisationProcess,idxAlongStep,1);
373 // eProcessManager->SetProcessOrdering(&IonisationProcess,idxPostStep, 1);
374
375 // G4LowEnergyBremsstrahlung BremstrahlungProcess;
376 // eProcessManager->AddProcess(&BremstrahlungProcess);
377 // eProcessManager->SetProcessOrdering(&BremstrahlungProcess,idxAlongStep,1);
378 // eProcessManager->SetProcessOrdering(&BremstrahlungProcess,idxPostStep, 1);
379
380 // G4eIonisation IonisationPlusProcess;
381 // pPositronProcessManager->AddProcess(&IonisationPlusProcess);
382 // pProcessManager->
383 // SetProcessOrdering(&IonisationPlusProcess,idxAlongStep,1);
384 // pProcessManager->SetProcessOrdering(&IonisationPlusProcess,idxPostStep,1);
385
386
387
388 // Create a DynamicParticle
389
390 G4double eEnergy = initEnergy*MeV;
391 G4ParticleMomentum eDirection(initX,initY,initZ);
392 G4DynamicParticle dynamicGamma(G4Gamma::Gamma(),eDirection,eEnergy);
393
394 dynamicGamma.DumpInfo(0);
395
396 // Track
397
398 G4ThreeVector aPosition(0.,0.,0.);
399 G4double aTime = 0. ;
400
401 G4Track* gTrack = new G4Track(&dynamicGamma,aTime,aPosition);
402
403 G4GRSVolume* touche = new G4GRSVolume(physicalFrame, NULL, aPosition);
404 gTrack->SetTouchableHandle(touche); //verificare!!!!!!!!!!!!
405
406
407 // Step
408
409 G4Step* step = new G4Step();
410 step->SetTrack(gTrack);
411
412 G4StepPoint* aPoint = new G4StepPoint();
413 aPoint->SetPosition(aPosition);
414 aPoint->SetMaterial(material);
415 aPoint->SetMaterialCutsCouple(theCouple);
416 G4double safety = 10000.*cm;
417 aPoint->SetSafety(safety);
418 step->SetPreStepPoint(aPoint);
419
420 // Check applicability
421
422 if (! (gammaProcess->IsApplicable(*gamma)))
423 {
424 G4Exception("Not Applicable");
425 }
426 else
427 {
428 G4cout<< "applicability OK" << G4endl;
429 }
430
431 // Initialize the physics tables (in which material?)
432 //G4cout << "Prima del build" << G4endl;
433 gammaProcess->BuildPhysicsTable(*gamma);
434 //G4cout << "Dopo il buildt" << G4endl;
435
436 theeminusMultipleScattering->BuildPhysicsTable(*electron);
437 theeminusIonisation->BuildPhysicsTable(*electron);
438 theeminusBremsstrahlung->BuildPhysicsTable(*electron);
439 theeplusMultipleScattering->BuildPhysicsTable(*positron);
440 theeplusIonisation->BuildPhysicsTable(*positron);
441 theeplusBremsstrahlung->BuildPhysicsTable(*positron);
442 theeplusAnnihilation->BuildPhysicsTable(*positron) ;
443
444 G4cout<< "table OK" << G4endl;
445
446 // Test GetMeanFreePath()
447 // E' protected! Il membro accessibile e' DumpMeanFreePath()
448
449 G4Material* apttoMaterial ;
450 G4String MaterialName ;
451
452 G4double minArg = 100*eV,maxArg = 100*GeV, argStp;
453 const G4int pntNum = 300;
454 G4double Tkin[pntNum+1];
455 G4double meanFreePath=0. ;
456
457 argStp = (std::log10(maxArg)-std::log10(minArg))/pntNum;
458
459 for(G4int d = 0; d < pntNum+1; d++)
460 {
461 Tkin[d] = std::pow(10,(std::log10(minArg) + d*argStp));
462 }
463
464 G4double sti = 1.*mm;
465 step->SetStepLength(sti);
466
467 // for ( G4int J = 0 ; J < nMaterials ; J++ )
468 // {
469 apttoMaterial = (*theMaterialTable)[materialId] ;
470 MaterialName = apttoMaterial->GetName() ;
471 logicalFrame->SetMaterial(apttoMaterial);
472
473 gTrack->SetStep(step);
474
475 G4PenelopeGammaConversion* gammaLowEProcess =
476 (G4PenelopeGammaConversion*) gammaProcess;
477 G4LowEnergyGammaConversion* gammaLowEProcess2 =
478 (G4LowEnergyGammaConversion*) gammaProcess;
479 G4GammaConversion* gammaStdProcess =
480 (G4GammaConversion*) gammaProcess;
481
482
483 for (G4int i=0 ; i<pntNum; i++)
484 {
485 dynamicGamma.SetKineticEnergy(Tkin[i]);
486 if (processType == 1)
487 {
488 meanFreePath=gammaLowEProcess
489 ->DumpMeanFreePath(*gTrack, sti, condition);
490 }
491 else if (processType == 2)
492 {
493 meanFreePath=gammaLowEProcess2
494 ->DumpMeanFreePath(*gTrack, sti, condition);
495 }
496 else if (processType == 3)
497 {
498 meanFreePath=gammaStdProcess
499 ->GetMeanFreePath(*gTrack, sti, condition);
500 }
501
502 ntuple3->fill(ntuple3->findColumn("kinen"),std::log10(Tkin[i]));
503 ntuple3->fill(ntuple3->findColumn("mfp"),std::log10(meanFreePath/cm));
504 ntuple3->addRow();
505
506
507 // G4cout << meanFreePath/cm << G4endl;
508
509 }
510 G4cout << "Mean Free Path OK" << G4endl;
511
512 // --------- Test the DoIt
513
514 G4cout << "DoIt in " << material->GetName() << G4endl;
515
516
517 dynamicGamma.SetKineticEnergy(eEnergy);
518 G4int iter;
519 for (iter=0; iter<nIterations; iter++)
520 {
521
522 step->SetStepLength(1*micrometer);
523
524 G4cout << "Iteration = " << iter
525 << " - Step Length = "
526 << step->GetStepLength()/mm << " mm "
527 << G4endl;
528
529
530 gTrack->SetStep(step);
531
532
533 // G4cout << "Iteration = " << iter
534 // << " - Step Length = "
535 // << step->GetStepLength()/mm << " mm "
536 // << G4endl;
537
538 //G4cout << gTrack->GetStep()->GetStepLength()/mm
539 // << G4endl;
540
541 G4VParticleChange* dummy;
542 G4cout << "Prima" << G4endl;
543 dummy = gammaProcess->PostStepDoIt(*gTrack, *step);
544 G4cout << "Dopo" << G4endl;
545
546 G4ParticleChange* particleChange = (G4ParticleChange*) dummy;
547
548 // Primary physical quantities
549
550 G4double energyChange = particleChange->GetEnergy();
551
552 G4double dedx = initEnergy - energyChange ;
553 G4double dedxNow = dedx / (step->GetStepLength());
554
555 G4ThreeVector eChange =
556 particleChange->CalcMomentum(energyChange,
557 (*particleChange->GetMomentumDirection()),
558 particleChange->GetMass());
559
560 G4double pxChange = eChange.x();
561 G4double pyChange = eChange.y();
562 G4double pzChange = eChange.z();
563 G4double pChange =
564 std::sqrt(pxChange*pxChange + pyChange*pyChange + pzChange*pzChange);
565
566 G4double xChange = particleChange->GetPosition()->x();
567 G4double yChange = particleChange->GetPosition()->y();
568 G4double zChange = particleChange->GetPosition()->z();
569 G4double thetaChange = particleChange->GetPosition()->theta();
570
571 G4cout << "---- Primary after the step ---- " << G4endl;
572
573 // G4cout << "Position (x,y,z) = "
574 // << xChange << " "
575 // << yChange << " "
576 // << zChange << " "
577 // << G4endl;
578
579 G4cout << "---- Energy: " << energyChange/MeV << " MeV, "
580 << "(px,py,pz): ("
581 << pxChange/MeV << ","
582 << pyChange/MeV << ","
583 << pzChange/MeV << ") MeV"
584 << G4endl;
585
586 G4cout << "---- Energy loss (dE) = " << dedx/keV << " keV" << G4endl;
587 // G4cout << "Stopping power (dE/dx)=" << dedxNow << G4endl;
588
589 // ntuple1->fill(ntuple1->findColumn("eprimary"),initEnergy/MeV);
590// ntuple1->fill(ntuple1->findColumn("energyf"),energyChange/MeV);
591// ntuple1->fill(ntuple1->findColumn("de"),dedx/MeV);
592// ntuple1->fill(ntuple1->findColumn("dedx"),dedxNow/(MeV/cm));
593// ntuple1->fill(ntuple1->findColumn("pxch"),pxChange/MeV);
594// ntuple1->fill(ntuple1->findColumn("pych"),pyChange/MeV);
595// ntuple1->fill(ntuple1->findColumn("pzch"),pzChange/MeV);
596// ntuple1->fill(ntuple1->findColumn("pch"),pChange/MeV);
597// ntuple1->fill(ntuple1->findColumn("thetach"),thetaChange);
598// ntuple1->addRow();
599
600 // Secondaries physical quantities
601
602 // Secondaries
603 hNSec->fill(particleChange->GetNumberOfSecondaries());
604 hDebug->fill(particleChange->GetLocalEnergyDeposit());
605
606 G4cout << " secondaries " <<
607 particleChange->GetNumberOfSecondaries() << G4endl;
608 G4double px_el,py_el,pz_el,p_el,e_el,theta_el,eKin_el;
609 G4double px_po,py_po,pz_po,p_po,e_po,theta_po,eKin_po;
610
611 for (G4int i = 0; i < (particleChange->GetNumberOfSecondaries()); i++)
612 {
613 // The following two items should be filled per event, not
614 // per secondary; filled here just for convenience, to avoid
615 // complicated logic to dump ntuple when there are no secondaries
616
617 G4Track* finalParticle = particleChange->GetSecondary(i) ;
618
619 G4double e = finalParticle->GetTotalEnergy();
620 G4double eKin = finalParticle->GetKineticEnergy();
621 G4double px = (finalParticle->GetMomentum()).x();
622 G4double py = (finalParticle->GetMomentum()).y();
623 G4double pz = (finalParticle->GetMomentum()).z();
624 G4double theta = (finalParticle->GetMomentum()).theta();
625 G4double p = std::sqrt(px*px+py*py+pz*pz);
626 theta = theta/deg; //conversion in degrees
627 if (e > initEnergy)
628 {
629 G4cout << "WARNING: eFinal > eInit " << G4endl;
630 // << e
631 // << " > " initEnergy
632
633 }
634
635 G4String particleName =
636 finalParticle->GetDefinition()->GetParticleName();
637 G4cout << "==== Final "
638 << particleName << " "
639 << "energy: " << e/MeV << " MeV, "
640 << "eKin: " << eKin/MeV << " MeV, "
641 << "(px,py,pz): ("
642 << px/MeV << ","
643 << py/MeV << ","
644 << pz/MeV << ") MeV "
645 << G4endl;
646
647 hEKin->fill(eKin);
648 hP->fill(p);
649
650 G4int partType;
651 if (particleName == "e-") {
652 partType = 1;
653 px_el=px;
654 py_el=py;
655 pz_el=pz;
656 p_el=p;
657 e_el=e;
658 theta_el=theta;
659 eKin_el=eKin;
660 }
661 else if (particleName == "e+")
662 {
663 partType = 2;
664 px_po=px;
665 py_po=py;
666 pz_po=pz;
667 p_po=p;
668 e_po=e;
669 theta_po=theta;
670 eKin_po=eKin;
671 }
672 else if (particleName == "gamma") partType = 3;
673
674
675 delete particleChange->GetSecondary(i);
676 }
677
678 // Fill the secondaries ntuple
679
680 // Normalize all to the energy of primary
681 // for gammas initEnergy=initP
682 ntuple2->fill(ntuple2->findColumn("eprimary"),initEnergy);
683 ntuple2->fill(ntuple2->findColumn("px_el"),px_el/initEnergy);
684 ntuple2->fill(ntuple2->findColumn("py_el"),py_el/initEnergy);
685 ntuple2->fill(ntuple2->findColumn("pz_el"),pz_el/initEnergy);
686 ntuple2->fill(ntuple2->findColumn("p_el"),p_el/initEnergy);
687 ntuple2->fill(ntuple2->findColumn("e_el"),e_el/initEnergy);
688 ntuple2->fill(ntuple2->findColumn("theta_el"),theta_el);
689 ntuple2->fill(ntuple2->findColumn("ekin_el"),eKin_el/initEnergy);
690 ntuple2->fill(ntuple2->findColumn("px_po"),px_po/initEnergy);
691 ntuple2->fill(ntuple2->findColumn("py_po"),py_po/initEnergy);
692 ntuple2->fill(ntuple2->findColumn("pz_po"),pz_po/initEnergy);
693 ntuple2->fill(ntuple2->findColumn("p_po"),p_po/initEnergy);
694 ntuple2->fill(ntuple2->findColumn("e_po"),e_po/initEnergy);
695 ntuple2->fill(ntuple2->findColumn("theta_po"),theta_po);
696 ntuple2->fill(ntuple2->findColumn("ekin_po"),eKin_po/initEnergy);
697 ntuple2->addRow();
698 particleChange->Clear();
699
700 }
701
702
703 G4cout << "Iteration number: " << iter << G4endl;
704
705 G4cout << "Committing.............." << G4endl;
706 tree->commit();
707 G4cout << "Closing the tree........" << G4endl;
708 tree->close();
709
710 delete step;
711
712
713 G4cout << "END OF THE MAIN PROGRAM" << G4endl;
714 return 0;
715}
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
Note: See TracBrowser for help on using the repository browser.