Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMCEx01/src/HepMCG4Interface.cc
Go to the documentation of this file.
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 /// \file eventgenerator/HepMC/HepMCEx01/src/HepMCG4Interface.cc
27 /// \brief Implementation of the HepMCG4Interface class
28 //
29 // $Id: HepMCG4Interface.cc 77801 2013-11-28 13:33:20Z gcosmo $
30 //
31 
32 #include "HepMCG4Interface.hh"
33 
34 #include "G4RunManager.hh"
35 #include "G4LorentzVector.hh"
36 #include "G4Event.hh"
37 #include "G4PrimaryParticle.hh"
38 #include "G4PrimaryVertex.hh"
40 #include "G4PhysicalConstants.hh"
41 #include "G4SystemOfUnits.hh"
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45  : hepmcEvent(0)
46 {
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 {
52  delete hepmcEvent;
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57  (const G4ThreeVector& pos) const
58 {
60  -> GetNavigatorForTracking();
61 
62  G4VPhysicalVolume* world= navigator-> GetWorldVolume();
63  G4VSolid* solid= world-> GetLogicalVolume()-> GetSolid();
64  EInside qinside= solid-> Inside(pos);
65 
66  if( qinside != kInside) return false;
67  else return true;
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 void HepMCG4Interface::HepMC2G4(const HepMC::GenEvent* hepmcevt,
72  G4Event* g4event)
73 {
74  for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
75  vitr != hepmcevt->vertices_end(); ++vitr ) { // loop for vertex ...
76 
77  // real vertex?
78  G4bool qvtx=false;
79  for (HepMC::GenVertex::particle_iterator
80  pitr= (*vitr)->particles_begin(HepMC::children);
81  pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
82 
83  if (!(*pitr)->end_vertex() && (*pitr)->status()==1) {
84  qvtx=true;
85  break;
86  }
87  }
88  if (!qvtx) continue;
89 
90  // check world boundary
91  HepMC::FourVector pos= (*vitr)-> position();
92  G4LorentzVector xvtx(pos.x(), pos.y(), pos.z(), pos.t());
93  if (! CheckVertexInsideWorld(xvtx.vect()*mm)) continue;
94 
95  // create G4PrimaryVertex and associated G4PrimaryParticles
96  G4PrimaryVertex* g4vtx=
97  new G4PrimaryVertex(xvtx.x()*mm, xvtx.y()*mm, xvtx.z()*mm,
98  xvtx.t()*mm/c_light);
99 
100  for (HepMC::GenVertex::particle_iterator
101  vpitr= (*vitr)->particles_begin(HepMC::children);
102  vpitr != (*vitr)->particles_end(HepMC::children); ++vpitr) {
103 
104  if( (*vpitr)->status() != 1 ) continue;
105 
106  G4int pdgcode= (*vpitr)-> pdg_id();
107  pos= (*vpitr)-> momentum();
108  G4LorentzVector p(pos.px(), pos.py(), pos.pz(), pos.e());
109  G4PrimaryParticle* g4prim=
110  new G4PrimaryParticle(pdgcode, p.x()*GeV, p.y()*GeV, p.z()*GeV);
111 
112  g4vtx-> SetPrimary(g4prim);
113  }
114  g4event-> AddPrimaryVertex(g4vtx);
115  }
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
120 {
121  HepMC::GenEvent* aevent= new HepMC::GenEvent();
122  return aevent;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127 {
128  // delete previous event object
129  delete hepmcEvent;
130 
131  // generate next event
133  if(! hepmcEvent) {
134  G4cout << "HepMCInterface: no generated particles. run terminated..."
135  << G4endl;
136  G4RunManager::GetRunManager()-> AbortRun();
137  return;
138  }
139  HepMC2G4(hepmcEvent, anEvent);
140 }
const char * p
Definition: xmltok.h:285
virtual HepMC::GenEvent * GenerateHepMCEvent()
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
void HepMC2G4(const HepMC::GenEvent *hepmcevt, G4Event *g4event)
bool G4bool
Definition: G4Types.hh:79
virtual G4bool CheckVertexInsideWorld(const G4ThreeVector &pos) const
static G4TransportationManager * GetTransportationManager()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
EInside
Definition: geomdefs.hh:58
int position
Definition: filter.cc:7
#define G4endl
Definition: G4ios.hh:61
virtual void GeneratePrimaryVertex(G4Event *anEvent)
float c_light
Definition: hepunit.py:257