source: trunk/source/processes/hadronic/stopping/test/G4PiMinusAbsorptionAtRestTest.cc @ 1199

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

nvx fichiers dans CVS

File size: 15.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: G4PiMinusAbsorptionAtRestTest.cc,v 1.5 2008/12/18 13:02:40 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:     G4PiMinusAbsorptionAtRestTest.cc
36//
37//      Author:        Maria Grazia Pia (pia@genova.infn.it),
38//                     (from Ch. Voelcker, from M. Maire)
39//
40//      Creation date: 8 May 1998
41//
42//      Modifications:
43//      MG Pia         6 Jul 1998 Modified handling of ProcessManager
44//                                to be consistent with changes in
45//                                ParticleDefinition
46//
47// -------------------------------------------------------------------
48
49#include "G4ios.hh"
50#include <fstream>
51#include <iomanip>
52
53#include "G4Material.hh"
54#include "G4Element.hh"
55
56#include "G4ProcessManager.hh"
57#include "G4PiMinusAbsorptionAtRest.hh"
58#include "G4PionMinusAbsorptionAtRest.hh"
59
60#include "G4ParticleDefinition.hh"
61#include "G4DynamicParticle.hh"
62#include "G4PionMinus.hh"
63#include "G4ParticleMomentum.hh"
64
65#include "G4Box.hh"
66#include "G4PVPlacement.hh"
67
68#include "G4GRSVolume.hh"
69#include "G4LogicalVolume.hh"
70
71#include "G4ProcessManager.hh"
72#include "G4ForceCondition.hh"
73
74#include "G4Step.hh"
75#include "G4Track.hh"
76
77#include "CLHEP/Hist/TupleManager.h"
78#include "CLHEP/Hist/HBookFile.h"
79#include "CLHEP/Hist/Histogram.h"
80#include "CLHEP/Hist/Tuple.h"
81
82#include "G4IonTable.hh"
83#include "G4Electron.hh"
84#include "G4Proton.hh"
85#include "G4Neutron.hh"
86#include "G4ParticleTypes.hh"
87#include "G4IonTable.hh"
88#include "G4ParticleTable.hh"
89#include "G4GenericIon.hh"
90
91int main()
92{
93  G4ParticleDefinition* electron = G4Electron::ElectronDefinition();
94  G4ParticleDefinition* ion  = G4GenericIon::GenericIonDefinition();
95
96  G4ParticleDefinition* proton = G4Proton::ProtonDefinition();
97  proton->SetCuts(0.01);
98  G4ParticleDefinition* neutron  = G4Neutron::NeutronDefinition();
99  neutron->SetCuts(0.01);
100
101
102  G4ParticleTable* theTableOfParticles;
103  theTableOfParticles = G4ParticleTable::GetParticleTable();
104  G4IonTable* theTable = new G4IonTable();
105
106  // -------------------------------------------------------------------
107  // MGP ---- HBOOK initialization
108  HepTupleManager* hbookManager;
109  hbookManager = new HBookFile("mg.hbook", 58);
110  assert (hbookManager != 0);
111
112  // MGP ---- Book a histogram
113  HepHistogram* hEKin;
114  hEKin = hbookManager->histogram("Kinetic Energy", 100,0.,150.);
115  assert (hEKin != 0); 
116
117  HepHistogram* hP;
118  hP = hbookManager->histogram("Momentum", 100,0.,1000.);
119  assert (hP != 0); 
120
121  HepHistogram* hNSec;
122  hNSec = hbookManager->histogram("Number of secondaries", 25,0.,25.);
123  assert (hNSec != 0); 
124
125  HepHistogram* hDebug;
126  hDebug = hbookManager->histogram("Debug", 100,0.,140.);
127  assert (hDebug != 0); 
128
129  // MGP ---- Book a ntuple
130  HepTuple* ntuple;
131  ntuple = hbookManager->ntuple("Pion absorption at rest Ntuple");
132  assert (ntuple != 0);
133
134  G4String name, symbol;
135  G4double a, iz, z, density;
136  G4int nEl;
137
138  G4int nIter = 10;
139  G4int imat = 3;
140  G4int verboseLevel = 1;
141  G4int processId = 1;
142  G4int deexcitationIndex =0;
143
144  cout << " 0) Copper      1) Lead         2) Iron         3) Carbon" << G4endl;
145  cout << " 4) LArgon      5) Polystyrene  6) Tungsten     7) Oxygen" << G4endl;
146  cout << " 8) Beryllium   9) Aluminium   10) Uranium     11) BGO" << G4endl;
147  cout << "12) NaI        13) CsI         14) Kapton" << G4endl;
148
149  G4cout
150    << "Enter number of absorptions [10], material [3], Verbose level [1]"
151    << G4endl;
152  G4cin >> nIter >> imat >> verboseLevel;
153
154  G4cout
155    << "Enter process: 1 G4PiMinusAbsorptionAtRest, 2 G4GheishaAbsAtRest" 
156    << G4endl;
157  G4cin >> processId;
158
159  if (processId < 1 || processId >2)
160    {
161      G4cout << "Wrong process ID, set to default" << G4endl;
162      processId = 1;
163    }
164
165  G4cout << "Enter deexcitation algorithm: 0 Theo, 1 Dummy" << G4endl;
166  G4cin >> deexcitationIndex;
167 
168  G4int hnt;
169  G4cout << "Enter histo (0) or ntuple (1) " << G4endl;
170  G4cin >> hnt;
171
172  // Materials definition
173
174  // Materials definition
175
176    G4Material* Cu = new G4Material(name="Copper", density=8.96*g/cm3, nEl=1);
177    G4Element* elCu = new G4Element(name="Copper", symbol="Cu", iz=29., a=63.55*g/mole);
178    Cu->AddElement( elCu, 1 );
179   
180    G4Material* Pb = new G4Material(name="Lead", density=11.35*g/cm3, nEl=1);
181    G4Element* elPb = new G4Element(name="Lead", symbol="Pb", iz=82., a=207.19*g/mole);
182    Pb->AddElement( elPb, 1 );
183   
184    G4Material*  Fe = new G4Material(name="Iron", density=7.87*g/cm3, nEl=1);
185    G4Element* elFe = new G4Element(name="Iron", symbol="Fe", iz=26., a=55.85*g/mole);
186    Fe->AddElement( elFe, 1 );
187   
188    G4Material*  Graphite = new G4Material(name="Graphite", density=2.265*g/cm3, nEl=1);
189    G4Element* elC  = new G4Element(name="Carbon", symbol="C", iz=6., a=12.0107*g/mole);
190    Graphite->AddElement( elC, 1 );
191
192    G4Material*  LAr= new G4Material(name="LArgon", density=1.393*g/cm3, nEl=1);
193    G4Element* elAr  = new G4Element(name="Argon", symbol="Ar", iz=18., a=39.95*g/mole);
194    LAr->AddElement( elAr, 1 );
195   
196    G4Material*  PS = new G4Material(name="PolyStyrene", density=1.032*g/cm3, nEl=2);
197    //    G4Element* elC = new G4Element(name="Carbon", symbol="C", iz=6., a=12.01*g/mole);
198    G4Element* elH = new G4Element(name="Hydrogen", symbol="H", iz=1., a=1.01*g/mole);
199    PS->AddElement( elC, 8 );
200    PS->AddElement( elH, 8 );
201   
202    G4Material*  W  = new G4Material(name="Tungsten", density=19.30*g/cm3, nEl=1);
203    G4Element* elW  = new G4Element(name="Tungsten", symbol="W", iz=74., a=183.85*g/mole);
204    W->AddElement( elW, 1 );
205   
206    // approximate numbers for O
207    G4Material*  O = new G4Material(name="Oxygen", density=1.1*g/cm3, nEl=1);
208    G4Element* elO  = new G4Element(name="Oxygen", symbol="O", iz=8., a=15.9994*g/mole);
209    O->AddElement( elO,  1 );
210   
211    G4Material*  Be = new G4Material(name="Beryllium", density=1.848*g/cm3, nEl=1);
212    G4Element* elBe  = new G4Element(name="Beryllium", symbol="Be", iz=4., a=9.01*g/mole);
213    Be->AddElement( elBe, 1 );
214   
215    G4Material*  Al = new G4Material(name="Aluminium", density=2.70*g/cm3, nEl=1);
216    G4Element* elAl  = new G4Element(name="Aluminium", symbol="Al", iz=13., a=26.98*g/mole);
217    Al->AddElement( elAl, 1 );
218   
219   
220    G4Material*  U = new G4Material(name="Uranium", density=18.95*g/cm3, nEl=1);
221    G4Element* elU  = new G4Element(name="Uranium", symbol="U", iz=92., a=238.03*g/mole);
222    U->AddElement( elU, 1 );
223   
224    G4Material*  BGO = new G4Material(name="BGO", density=2.15*g/cm3, nEl=3);
225    G4Element* elBi = new G4Element(name="Bismuth", symbol="Bi", iz=83., a=208.98*g/mole);
226    G4Element* elGe = new G4Element(name="Germanium", symbol="Ge", iz=32., a=72.59*g/mole);
227    BGO->AddElement( elBi, 4 );
228    BGO->AddElement( elGe, 3 );
229    BGO->AddElement( elO, 12 );
230   
231    G4Material*  NaI = new G4Material(name="NaI", density=3.67*g/cm3, nEl=2);
232    G4Element* elNa = new G4Element(name="Sodium", symbol="Na", iz=11., a=22.990*g/mole);
233    G4Element* elI = new G4Element(name="Iodine", symbol="I", iz=53., a=126.904*g/mole);
234    NaI->AddElement( elNa, 1 );
235    NaI->AddElement( elI, 1 );
236   
237    G4Material*  CsI = new G4Material(name="CsI", density=4.53*g/cm3, nEl=2);
238    G4Element* elCs = new G4Element(name="Cesium", symbol="Cs", iz=55., a=132.905*g/mole);
239    CsI->AddElement( elCs, 1 );
240    CsI->AddElement( elI, 1 );
241
242    G4Material*  Kapton = new G4Material(name="Kapton", density=1.53*g/cm3, nEl=4); 
243    // formula: private communications, see mail.
244    Kapton->AddElement( elC, 22 );
245    Kapton->AddElement( elH, 10 );
246    Kapton->AddElement( elO,  5 );
247    G4Element* elN = new G4Element(name="Nitrogen", symbol="N", iz=7., a=14.007*g/mole);
248    Kapton->AddElement( elN, 2 );
249
250
251    //  G4Material* Al = new G4Material("Aluminium", 13., 26.98*g/mole, 2.7 *g/cm3 );
252    //  G4Material* Fe = new G4Material("Iron",      26., 55.85*g/mole, 7.87*g/cm3 );
253    //  G4Material* Pb = new G4Material("Lead",      82., 207.19*g/mole, 11.35*g/cm3 );
254    //  G4Material* Graphite = new G4Material("Graphite", 6., 12.00*g/mole, 2.265*g/cm3 );
255 
256    //  G4Element*   H = new G4Element ("Hydrogen", "H", 1. ,  1.01*g/mole);
257    //  G4Element*   O = new G4Element ("Oxygen"  , "O", 8. , 16.00*g/mole);
258    //  G4Element*   C = new G4Element ("Carbon"  , "C", 6. , 12.00*g/mole);
259    //  G4Element*  Cs = new G4Element ("Cesium"  , "Cs", 55. , 132.905*g/mole);
260    //  G4Element*   I = new G4Element ("Iodide"  , "I", 53. , 126.9044*g/mole);
261 
262    //  G4Material* water = new G4Material ("Water" , 1.*g/cm3, 2);
263    //  water->AddElement(H,2);
264    //  water->AddElement(O,1);
265    // 
266    //  G4Material* ethane = new G4Material ("Ethane" , 0.4241*g/cm3, 2);
267    //  ethane->AddElement(H,6);
268    //  ethane->AddElement(C,2);
269 
270    //  G4Material* csi = new G4Material ("CsI" , 4.53*g/cm3, 2);
271    //  csi->AddElement(Cs,1);
272    //  csi->AddElement(I,1);
273 
274  //  G4Element::DumpInfo();
275  //  G4Material::DumpInfo();
276 
277  static const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
278 
279  // Fix a material
280  // G4int imat = 0;   // graphite
281 
282  // Geometry definitions
283
284  G4Box* theFrame = new G4Box ("Frame",1*m, 1*m, 1*m);
285  G4LogicalVolume* LogicalFrame = 
286    new G4LogicalVolume (theFrame,(*theMaterialTable)(imat),"LFrame", 0,0,0);
287 
288  G4PVPlacement* PhysicalFrame = 
289    new G4PVPlacement(0,G4ThreeVector(),
290                      "PFrame",LogicalFrame,0,false,0);
291 
292  // The center-of-mass of the cube should be located at the origin!
293
294  // Particle
295  G4ParticleDefinition* pionMinus = G4PionMinus::PionMinusDefinition();
296
297  // Processes
298  G4ProcessManager* thePionProcessManager = new G4ProcessManager(pionMinus);
299  pionMinus->SetProcessManager(thePionProcessManager);
300 
301  //  thePionProcessManager->SetParticleType(pionMinus);
302
303  G4PiMinusAbsorptionAtRest* thePiAbsorptionProcess = 
304    new G4PiMinusAbsorptionAtRest("G4PiMinusAbsorptionAtRest");
305  G4PionMinusAbsorptionAtRest* gheishaAbsorptionProcess =
306    new G4PionMinusAbsorptionAtRest();
307
308  switch (processId)
309    {
310    case 1:
311      {
312        thePionProcessManager->AddProcess(thePiAbsorptionProcess,0,-1,0);
313        thePiAbsorptionProcess->SetDeexcitationAlgorithm(deexcitationIndex); 
314        break;
315      }
316    case 2:
317      {
318        thePionProcessManager->AddProcess(gheishaAbsorptionProcess,0,-1,0);
319        break;
320      }
321    default:
322      {
323        thePionProcessManager->AddProcess(thePiAbsorptionProcess,0,-1,0);
324        thePiAbsorptionProcess->SetDeexcitationAlgorithm(deexcitationIndex); 
325        break;
326      }
327    }
328
329  G4ForceCondition* condition;
330 
331  // Set cut and Build CrossSection Tables
332  pionMinus->SetCuts(1.*mm);
333 
334  // Create one Dynamic Particle 
335  G4double pionEnergy = 0.*MeV;
336  G4ParticleMomentum pionDirection(0.,0.,1.);
337  G4DynamicParticle aPionMinus(G4PionMinus::PionMinus(),pionDirection,pionEnergy);
338 
339  // Track definition (for this test ONLY!)
340  G4ThreeVector aPosition(0.,0.,0.);
341  G4double aTime = 0. ;
342  G4Track* ptrack = new G4Track(&aPionMinus,aTime,aPosition) ;
343  G4Track& aTrack = (*ptrack) ;
344 
345  //ptrack->SetVolume(PhysicalFrame);
346 
347  // Do I really need this?
348  G4GRSVolume* touche = new G4GRSVolume(PhysicalFrame, NULL, aPosition);   
349  ptrack->SetTouchable(touche);
350 
351  // Create 1 Step (for this test only)
352  G4Step* Step = new G4Step(); 
353  G4Step& aStep = (*Step);
354  Step->SetTrack(ptrack);
355 
356  // Check applicability
357  G4ParticleDefinition* PionMinusDefinition = aPionMinus.GetDefinition();
358
359  if (! thePiAbsorptionProcess->IsApplicable(*PionMinusDefinition)) 
360    {
361      G4cout
362        << PionMinusDefinition->GetParticleName() << " is not a PionMinus!" << G4endl;
363      G4Exception("FAIL: *** exit program ***\n");
364      //     return ;
365    }
366
367  // Test the DoIt for the Pion Absorption
368
369  G4Material* apttoMaterial ;
370  apttoMaterial = (*theMaterialTable)(imat) ;
371  LogicalFrame->SetMaterial(apttoMaterial); 
372  aPionMinus.SetKineticEnergy(0.*MeV);
373  aPionMinus.SetMomentumDirection(0., 0., 1.);
374  G4VParticleChange* aParticleChange;
375  G4Track* aFinalParticle;
376  G4String aParticleName; 
377 
378  thePiAbsorptionProcess->SetVerboseLevel(verboseLevel);
379 
380  G4int iteration = 0;   
381
382  do {
383   
384    if (processId == 1)
385      { aParticleChange = thePiAbsorptionProcess->AtRestDoIt(aTrack, aStep); }
386    else 
387      {
388        if (processId == 2) 
389          { aParticleChange = gheishaAbsorptionProcess->AtRestDoIt(aTrack, aStep); }
390      }
391   
392    // Loop over final particle List
393
394    G4double e = 0;
395    G4double eKin = 0;
396    G4double Px = 0;
397    G4double Py = 0;
398    G4double Pz = 0;
399
400
401    hNSec->accumulate(aParticleChange->GetNumberOfSecondaries());
402    hDebug->accumulate(aParticleChange->GetLocalEnergyDeposit());
403
404    G4int i;
405    for (i=0; i<(aParticleChange->GetNumberOfSecondaries()); i++) 
406      {
407        // The following two items should be filled per event, not
408        // per secondary; filled here just for convenience, to avoid
409        // complicated logic
410        ntuple->column("nsec",aParticleChange->GetNumberOfSecondaries());
411        ntuple->column("excitation",aParticleChange->GetLocalEnergyDeposit());
412
413        aFinalParticle = aParticleChange->GetSecondary(i) ;
414     
415        e    =  aFinalParticle->GetTotalEnergy();
416        eKin = aFinalParticle->GetKineticEnergy();
417        Px   = (aFinalParticle->GetMomentum()).x() ;
418        Py   = (aFinalParticle->GetMomentum()).y() ;
419        Pz   = (aFinalParticle->GetMomentum()).z() ;
420     
421        aParticleName = aFinalParticle->GetDefinition()->GetParticleName();
422
423        if (aFinalParticle->GetDefinition() == G4Proton::ProtonDefinition() ||
424            aFinalParticle->GetDefinition() == G4Neutron::NeutronDefinition())
425          {
426            hEKin->accumulate(eKin);
427            hP->accumulate(std::sqrt(Px*Px+Py*Py+Pz*Pz));
428
429            //  ntuple->column("px", Px);
430            //  ntuple->column("py", Py);
431            //  ntuple->column("pz", Pz);
432            //        ntuple->column("p", sqrt(Px*Px+Py*Py+Pz*Pz));
433            //        ntuple->column("e", e);
434            if (hnt == 1)
435              {
436                ntuple->column("ekin", eKin);
437                ntuple->dumpData(); 
438              }
439
440            delete aParticleChange->GetSecondary(i);
441           
442          }
443      }
444
445    G4cout << "******* Iteration = " << iteration << G4endl;
446    iteration++;
447    aParticleChange->Clear();
448   
449  }  while (iteration < nIter) ; // end of do-while
450 
451  hbookManager->write();
452
453  // Clean up
454  //  delete aFinalParticle;
455  delete Al;
456  delete Fe;
457  delete Pb;
458  delete Graphite;
459  //  delete H;
460  delete O;
461  //  delete C;
462  //  delete Cs;
463  //  delete I;
464  //  delete water;
465  //  delete ethane;
466  //  delete csi;
467
468  delete touche;
469  delete Step;
470
471 
472  return EXIT_SUCCESS;
473}
Note: See TracBrowser for help on using the repository browser.