Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
ML2SDWithParticle.cc
이 파일의 문서화 페이지로 가기
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 // The code was written by :
27 // ^Claudio Andenna claudio.andenna@ispesl.it, claudio.andenna@iss.infn.it
28 // *Barbara Caccia barbara.caccia@iss.it
29 // with the support of Pablo Cirrone (LNS, INFN Catania Italy)
30 // with the contribute of Alessandro Occhigrossi*
31 //
32 // ^INAIL DIPIA - ex ISPESL and INFN Roma, gruppo collegato Sanità, Italy
33 // *Istituto Superiore di Sanità and INFN Roma, gruppo collegato Sanità, Italy
34 // Viale Regina Elena 299, 00161 Roma (Italy)
35 // tel (39) 06 49902246
36 // fax (39) 06 49387075
37 //
38 // more information:
39 // http://g4advancedexamples.lngs.infn.it/Examples/medical-linac
40 //
41 //*******************************************************//
42 
43 #include "ML2SDWithParticle.hh"
44 #include "ML2ExpVoxels.hh"
46 #include "G4SystemOfUnits.hh"
47 
49 : G4VSensitiveDetector("killer_plane"),particles(0)
50 {
52  bStopAtPhaseSpace=true;
54  bActive=true;
55 }
56 
58  G4int seed, G4int nMaxPart, G4String name,
59  G4String PhaseSpaceOutFile, G4bool bSave, G4bool bStop,
60  SPrimaryParticle *pData, G4double ZPos)
61 : G4VSensitiveDetector(name),particles(0)
62 {
63  accTargetZPosition=ZPos;
64  max_N_particles_in_PhSp_File=maxPartFile;
66  idType=id;
67  primaryParticleData=pData;
68  bActive=true;
69  nParticle=0;
71  bSavePhaseSpace=bSave;
72  bStopAtPhaseSpace=bStop;
73  if (bSavePhaseSpace)
74  {particles=new Sparticle[nMaxPart];}
75  G4String seedName;
76  char a[10];
77  sprintf(a,"%d", seed);
78  seedName=(G4String)a;
79 
80  fullOutFileData=PhaseSpaceOutFile+"_"+seedName+".txt";
81  fullOutFileData=PhaseSpaceOutFile+"_"+seedName+".txt";
82 }
84 {
85  if (particles!=0)
86  {
87  delete [] particles;
88  }
89 }
91 {
92  std::ofstream out;
93  out.open(fullOutFileData, std::ios::out);
94  out << "Sensitive Detector-Particles"<<G4endl;
95  out << "n Total Events,\t x [mm],\t y [mm],\t z [mm],\t dirX,\t dirY,\t dirZ,\t KinEnergy [MeV],\t part Type,\t primary part type,\t nPrimaryPart" << G4endl;
96  out.close();
97 }
99 {
100  std::ofstream out;
101  out.open(fullOutFileData, std::ios::app);
102  static G4int nTotParticles=0;
103  for (int i=0; i< nPart; i++)
104  {
105  out << nTotParticles++ << '\t';
106 // out << particles[i].volumeName << '\t';
107  out << particles[i].pos.getX()/mm << '\t';
108  out << particles[i].pos.getY()/mm << '\t';
109  out << (accTargetZPosition + particles[i].pos.getZ())/mm << '\t'; // it translates the current z value in global coordinates to the accelerator local coordinates (only z)
110  out << particles[i].dir.getX() << '\t';
111  out << particles[i].dir.getY() << '\t';
112  out << particles[i].dir.getZ() << '\t';
113  out << particles[i].kinEnergy/MeV << '\t';
114  out << particles[i].partPDGE<< '\t';
115  out << particles[i].primaryParticlePDGE<< '\t';
116  out << particles[i].nPrimaryPart<< G4endl;
117  }
118  out.close();
119 }
120 
122 {
123  if (bActive && (CML2AcceleratorConstruction::GetInstance()->getPhysicalVolume()->GetRotation()->isIdentity()))
124  {
125  G4double energyKin= aStep->GetTrack()->GetKineticEnergy();
126  static bool bFirstTime=true;
128  {
129  nTotalParticles++;
131  }
132  else
133  {
134  if (energyKin>0.)
135  {
139  particles[nParticle].kinEnergy=energyKin;
143  nParticle++;
144  nTotalParticles++;
146  {
147  if (bFirstTime)
148  {
149  bFirstTime=false;
151  }
153  nParticle=0;
154  bActive =false;// to stop the phase space creation
155  }
157  {
158  if (bFirstTime)
159  {
160  bFirstTime=false;
162  }
164  nParticle=0;
165  }
166 
167  Sparticle *particle=new Sparticle;
168  particle->dir=aStep->GetPreStepPoint()->GetMomentumDirection();
169  particle->pos=aStep->GetPreStepPoint()->GetPosition();
170  particle->kinEnergy=energyKin;
171  particle->nPrimaryPart=nTotalParticles; // to pass the id of this phase space particle
172  particle->partPDGE=aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
174  particle->volumeId=-1;
175  particle->volumeName="-1";
176  }
177  if (bStopAtPhaseSpace)
178  {aStep->GetTrack()->SetTrackStatus(fStopAndKill);}
179  }
180  }
181  else
182  {
183  if (bStopAtPhaseSpace)
184  {aStep->GetTrack()->SetTrackStatus(fStopAndKill);}
185  }
186 
187  return true;
188 }
189 
191 {
192  if ((bActive) && (nParticle>0) && (CML2AcceleratorConstruction::GetInstance()->getPhysicalVolume()->GetRotation()->isIdentity()))
194 }
G4double GetKineticEnergy() const
const XML_Char * name
Definition: expat.h:151
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
static constexpr double MeV
Definition: G4SIunits.hh:214
G4StepPoint * GetPreStepPoint() const
static constexpr double mm
Definition: G4SIunits.hh:115
double getZ() const
#define G4endl
Definition: G4ios.hh:61
G4double kinEnergy
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROHist)
G4ParticleDefinition * GetDefinition() const
G4String volumeName
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
long seed
Definition: chem4.cc:68
const G4ThreeVector & GetPosition() const
double getX() const
G4Track * GetTrack() const
const G4ThreeVector & GetMomentumDirection() const
void saveDataParticles(G4int nParticle)
Definition: G4Step.hh:76
double getY() const
SPrimaryParticle * primaryParticleData
G4int nPrimaryPart
int G4int
Definition: G4Types.hh:78
static CML2AcceleratorConstruction * GetInstance(void)
G4ThreeVector pos
G4int primaryParticlePDGE
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4int partPDGE
G4int volumeId
G4ThreeVector dir