00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "G4Svc/AthenaHepMCtoG4EventAction.h"
00017
00018 #include "HepMC/GenEvent.h"
00019
00020 #include "G4Event.hh"
00021 #include "G4UImanager.hh"
00022 #include "globals.hh"
00023
00024 #include "G4PrimaryParticle.hh"
00025 #include "G4PrimaryVertex.hh"
00026 #include "G4LorentzVector.hh"
00027 #include "G4Geantino.hh"
00028
00029 #include "GaudiKernel/IMessageSvc.h"
00030
00031 using namespace HepMC;
00032
00033 AthenaHepMCtoG4EventAction::AthenaHepMCtoG4EventAction( int level):
00034 m_logLevel(level) {
00035 }
00036
00037 AthenaHepMCtoG4EventAction::AthenaHepMCtoG4EventAction():
00038 m_logLevel( int(MSG::INFO) ) {
00039 }
00040
00041 AthenaHepMCtoG4EventAction::~AthenaHepMCtoG4EventAction() {
00042
00043 }
00044
00045
00046
00047
00048 void AthenaHepMCtoG4EventAction::SetHepMCEvent(McEventCol::iterator p) {
00049
00050 if ( m_logLevel <= int(MSG::DEBUG) ) {
00051 std::cout << "AthenaHepMCtoG4EventAction: - Setting HepMC Event ptr"
00052 << std::endl;
00053 }
00054
00055
00056 p_evtCollItr = p;
00057
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 void AthenaHepMCtoG4EventAction::GeneratePrimaries(G4Event* anEvent)
00153 {
00154 if ( m_logLevel <= int(MSG::DEBUG) ) {
00155 std::cout << "AthenaHepMCtoG4EventAction: - Generating Primaries"
00156 << std::endl;
00157 }
00158
00159
00160 p_evt = (const HepMC::GenEvent *)(*p_evtCollItr);
00161
00162
00163 if (p_evt == 0) {
00164
00165 if ( m_logLevel <= int(MSG::WARNING) ) {
00166 std::cout << "AthenaHepMCtoG4EventAction: - HepMC ptr == null"
00167 << std::endl;
00168 }
00169
00170 return;
00171
00172 }
00173
00174 G4PrimaryVertex* vertex = new G4PrimaryVertex(0.,0.,0.,0.);
00175
00176 int n=0;
00177 for ( HepMC::GenEvent::vertex_const_iterator v = p_evt->vertices_begin();
00178 v != p_evt->vertices_end(); ++v ) {
00179 bool IsGood=false;
00180 for (HepMC::GenVertex::particle_iterator it=
00181 (*v)->particles_begin(HepMC::children);
00182 it!=(*v)->particles_end(HepMC::children);
00183 it++) {
00184
00185 if (!(*it)->end_vertex() && (*it)->status()==1 ) {
00186 IsGood=true;
00187 break;
00188 }
00189 }
00190
00191 if (IsGood) {
00192
00193
00194
00195 for (HepMC::GenVertex::particle_iterator it=
00196 (*v)->particles_begin(HepMC::children);
00197 it!=(*v)->particles_end(HepMC::children);
00198 it++) {
00199
00200 if ( (*it)->status() != 1) continue;
00201
00202 int pdgcode=(*it)->pdg_id();
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 const G4ThreeVector& p=(*it)->momentum();
00215 G4PrimaryParticle *part;
00216 if (pdgcode!=999) {
00217 part=new G4PrimaryParticle (pdgcode,p.x()*GeV,p.y()*GeV,p.z()*GeV);
00218 } else {
00219 G4ParticleDefinition *pdef = G4Geantino::GeantinoDefinition();
00220 part=new G4PrimaryParticle (pdef,p.x()*GeV,p.y()*GeV,p.z()*GeV);
00221 }
00222
00223 vertex->SetPosition((*v)->position().x(),
00224 (*v)->position().y(),
00225 (*v)->position().z());
00226 vertex->SetT0((*v)->position().t());
00227
00228 vertex->SetPrimary(part);
00229
00230 n++;
00231 }
00232 }
00233 }
00234 anEvent->AddPrimaryVertex(vertex);
00235
00236 if ( m_logLevel <= int(MSG::DEBUG) ) {
00237 std::cout << "AthenaHepMCtoG4EventAction: - done. G4Event has "
00238 << n << " particles. "
00239 << std::endl;
00240 }
00241
00242 p_evtCollItr++;
00243
00244 }