[807] | 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 | // |
---|
| 28 | // HepMCG4Interface.cc |
---|
| 29 | // $Id: HepMCG4Interface.cc,v 1.4 2006/06/29 17:12:24 gunter Exp $ |
---|
| 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" |
---|
| 39 | #include "G4TransportationManager.hh" |
---|
| 40 | |
---|
| 41 | //////////////////////////////////// |
---|
| 42 | HepMCG4Interface::HepMCG4Interface() |
---|
| 43 | : hepmcEvent(0) |
---|
| 44 | //////////////////////////////////// |
---|
| 45 | { |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | ///////////////////////////////////// |
---|
| 49 | HepMCG4Interface::~HepMCG4Interface() |
---|
| 50 | ///////////////////////////////////// |
---|
| 51 | { |
---|
| 52 | delete hepmcEvent; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | ///////////////////////////////////////////////////////// |
---|
| 56 | G4bool HepMCG4Interface::CheckVertexInsideWorld |
---|
| 57 | (const G4ThreeVector& pos) const |
---|
| 58 | ///////////////////////////////////////////////////////// |
---|
| 59 | { |
---|
| 60 | G4Navigator* navigator= G4TransportationManager::GetTransportationManager() |
---|
| 61 | -> GetNavigatorForTracking(); |
---|
| 62 | |
---|
| 63 | G4VPhysicalVolume* world= navigator-> GetWorldVolume(); |
---|
| 64 | G4VSolid* solid= world-> GetLogicalVolume()-> GetSolid(); |
---|
| 65 | EInside qinside= solid-> Inside(pos); |
---|
| 66 | |
---|
| 67 | if( qinside != kInside) return false; |
---|
| 68 | else return true; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | //////////////////////////////////////////////////////////////// |
---|
| 72 | void HepMCG4Interface::HepMC2G4(const HepMC::GenEvent* hepmcevt, |
---|
| 73 | G4Event* g4event) |
---|
| 74 | //////////////////////////////////////////////////////////////// |
---|
| 75 | { |
---|
| 76 | for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin(); |
---|
| 77 | vitr != hepmcevt->vertices_end(); ++vitr ) { // loop for vertex ... |
---|
| 78 | |
---|
| 79 | // real vertex? |
---|
| 80 | G4bool qvtx=false; |
---|
| 81 | for (HepMC::GenVertex::particle_iterator |
---|
| 82 | pitr= (*vitr)->particles_begin(HepMC::children); |
---|
| 83 | pitr != (*vitr)->particles_end(HepMC::children); ++pitr) { |
---|
| 84 | |
---|
| 85 | if (!(*pitr)->end_vertex() && (*pitr)->status()==1) { |
---|
| 86 | qvtx=true; |
---|
| 87 | break; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | if (!qvtx) continue; |
---|
| 91 | |
---|
| 92 | // check world boundary |
---|
| 93 | G4LorentzVector xvtx= (*vitr)-> position(); |
---|
| 94 | if (! CheckVertexInsideWorld(xvtx.vect()*mm)) continue; |
---|
| 95 | |
---|
| 96 | // create G4PrimaryVertex and associated G4PrimaryParticles |
---|
| 97 | G4PrimaryVertex* g4vtx= |
---|
| 98 | new G4PrimaryVertex(xvtx.x()*mm, xvtx.y()*mm, xvtx.z()*mm, |
---|
| 99 | xvtx.t()*mm/c_light); |
---|
| 100 | |
---|
| 101 | for (HepMC::GenVertex::particle_iterator |
---|
| 102 | vpitr= (*vitr)->particles_begin(HepMC::children); |
---|
| 103 | vpitr != (*vitr)->particles_end(HepMC::children); ++vpitr) { |
---|
| 104 | |
---|
| 105 | if( (*vpitr)->status() != 1 ) continue; |
---|
| 106 | |
---|
| 107 | G4int pdgcode= (*vpitr)-> pdg_id(); |
---|
| 108 | G4LorentzVector p= (*vpitr)-> momentum(); |
---|
| 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 | |
---|
| 119 | /////////////////////////////////////////////////////// |
---|
| 120 | HepMC::GenEvent* HepMCG4Interface::GenerateHepMCEvent() |
---|
| 121 | /////////////////////////////////////////////////////// |
---|
| 122 | { |
---|
| 123 | HepMC::GenEvent* aevent= new HepMC::GenEvent(); |
---|
| 124 | return aevent; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | ////////////////////////////////////////////////////////////// |
---|
| 128 | void HepMCG4Interface::GeneratePrimaryVertex(G4Event* anEvent) |
---|
| 129 | ////////////////////////////////////////////////////////////// |
---|
| 130 | { |
---|
| 131 | // delete previous event object |
---|
| 132 | delete hepmcEvent; |
---|
| 133 | |
---|
| 134 | // generate next event |
---|
| 135 | hepmcEvent= GenerateHepMCEvent(); |
---|
| 136 | if(! hepmcEvent) { |
---|
| 137 | G4cout << "HepMCInterface: no generated particles. run terminated..." |
---|
| 138 | << G4endl; |
---|
| 139 | G4RunManager::GetRunManager()-> AbortRun(); |
---|
| 140 | return; |
---|
| 141 | } |
---|
| 142 | HepMC2G4(hepmcEvent, anEvent); |
---|
| 143 | } |
---|
| 144 | |
---|