source: trunk/source/processes/electromagnetic/lowenergy/test/G4PenelopePhotoElectricTest.cc @ 1358

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

update to last version 4.9.4

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