CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
AthenaHepMCtoG4EventAction.cpp
Go to the documentation of this file.
1//------------------------------------------------------------------
2//
3// ClassName: AthenaHepMCtoG4EventAction
4//
5// Description: PrimaryGeneratorAction to convert HepMC event to G4Event
6//
7// Author: Charles Leggett
8//
9// Date: 3-8-2001
10//
11// $Id: AthenaHepMCtoG4EventAction.cpp,v 1.1.1.1 2013/11/22 02:11:07 juxd Exp $
12// Simulation/G4Sim/G4Svc tag $Name: G4Svc-00-04-01 $
13//
14//------------------------------------------------------------------
15
16#include "G4Svc/AthenaHepMCtoG4EventAction.h"
17
18#include "HepMC/GenEvent.h"
19
20#include "G4Event.hh"
21#include "G4UImanager.hh"
22#include "globals.hh"
23
24#include "G4PrimaryParticle.hh"
25#include "G4PrimaryVertex.hh"
26#include "G4LorentzVector.hh"
27#include "G4Geantino.hh"
28
29#include "GaudiKernel/IMessageSvc.h"
30
31using namespace HepMC;
32
34 m_logLevel(level) {
35}
36
40
44
45//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
46
47//void AthenaHepMCtoG4EventAction::SetHepMCEvent(const HepMC::GenEvent *p) {
48void AthenaHepMCtoG4EventAction::SetHepMCEvent(McEventCol::iterator p) {
49
50 if ( m_logLevel <= int(MSG::DEBUG) ) {
51 std::cout << "AthenaHepMCtoG4EventAction: - Setting HepMC Event ptr"
52 << std::endl;
53 }
54
55 // p_evt = p;
56 p_evtCollItr = p;
57
58}
59
60//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
61
62// void AthenaHepMCtoG4EventAction::GeneratePrimaries(G4Event* anEvent)
63// {
64// if ( m_logLevel <= int(MSG::DEBUG) ) {
65// std::cout << "AthenaHepMCtoG4EventAction: - Generating Primaries"
66// << std::endl;
67// }
68
69// p_evt = (*p_evtCollItr)->pGenEvt();
70
71// if (p_evt == 0) {
72
73// if ( m_logLevel <= int(MSG::WARNING) ) {
74// std::cout << "AthenaHepMCtoG4EventAction: - HepMC ptr == null"
75// << std::endl;
76// }
77
78// return;
79
80// }
81
82// int nv = 1;
83// int mnv;
84
85// std::cout << "how many vertices: ";
86// std::cin >> mnv;
87
88// for ( HepMC::GenEvent::vertex_const_iterator v = p_evt->vertices_begin();
89// v != p_evt->vertices_end(); ++v ) {
90// bool IsGood=false;
91// for (HepMC::GenVertex::particle_iterator it=
92// (*v)->particles_begin(HepMC::children);
93// it!=(*v)->particles_end(HepMC::children);
94// it++) {
95
96// if (!(*it)->end_vertex() && (*it)->status()==1 ) {
97// IsGood=true;
98// break;
99// }
100// }
101
102// if (IsGood) {
103// std::cout << "found a good vertex, barcode: " << (*v)->barcode()
104// << std::endl;
105
106// G4LorentzVector lv=(*v)->position();
107// G4PrimaryVertex *vert= new G4PrimaryVertex(lv.x(),lv.y(),lv.z(),lv.t());
108
109// for (HepMC::GenVertex::particle_iterator it=
110// (*v)->particles_begin(HepMC::children);
111// it!=(*v)->particles_end(HepMC::children);
112// it++) {
113
114// // if ( (*it)->status() != 1) continue;
115
116// int pdgcode=(*it)->pdg_id();
117// GenVertex *dcy = (*it)->end_vertex();
118// std::cout << "found a good particle, barcode: " << (*it)->barcode()
119// << " pdg: " << pdgcode << " status: " << (*it)->status()
120// << " end: ";
121// if (dcy != 0) {
122// std::cout << dcy->barcode();
123// } else {
124// std::cout << "nil";
125// }
126// std::cout << std::endl;
127
128// const G4ThreeVector& p=(*it)->momentum();
129// G4PrimaryParticle *part;
130// if (pdgcode!=999) {
131// part=new G4PrimaryParticle (pdgcode,p.x()*GeV,p.y()*GeV,p.z()*GeV);
132// } else {
133// G4ParticleDefinition *pdef = G4Geantino::GeantinoDefinition();
134// part=new G4PrimaryParticle (pdef,p.x()*GeV,p.y()*GeV,p.z()*GeV);
135// }
136// vert->SetPrimary(part);
137// }
138// anEvent->AddPrimaryVertex(vert);
139// if (nv > mnv) { break; }
140// nv ++;
141// }
142// }
143
144// std::cout << "done generating event" << std::endl;
145
146// p_evtCollItr++;
147
148// }
149
150//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
151
153{
154 if ( m_logLevel <= int(MSG::DEBUG) ) {
155 std::cout << "AthenaHepMCtoG4EventAction: - Generating Primaries"
156 << std::endl;
157 }
158
159
160 p_evt = (const HepMC::GenEvent *)(*p_evtCollItr);
161
162
163 if (p_evt == 0) {
164
165 if ( m_logLevel <= int(MSG::WARNING) ) {
166 std::cout << "AthenaHepMCtoG4EventAction: - HepMC ptr == null"
167 << std::endl;
168 }
169
170 return;
171
172 }
173
174 G4PrimaryVertex* vertex = new G4PrimaryVertex(0.,0.,0.,0.);
175
176 int n=0;
177 for ( HepMC::GenEvent::vertex_const_iterator v = p_evt->vertices_begin();
178 v != p_evt->vertices_end(); ++v ) {
179 bool IsGood=false;
180 for (HepMC::GenVertex::particle_iterator it=
181 (*v)->particles_begin(HepMC::children);
182 it!=(*v)->particles_end(HepMC::children);
183 it++) {
184
185 if (!(*it)->end_vertex() && (*it)->status()==1 ) {
186 IsGood=true;
187 break;
188 }
189 }
190
191 if (IsGood) {
192// std::cout << "found a good vertex, barcode: " << (*v)->barcode()
193// << std::endl;
194
195 for (HepMC::GenVertex::particle_iterator it=
196 (*v)->particles_begin(HepMC::children);
197 it!=(*v)->particles_end(HepMC::children);
198 it++) {
199
200 if ( (*it)->status() != 1) continue;
201
202 int pdgcode=(*it)->pdg_id();
203// GenVertex *dcy = (*it)->end_vertex();
204// std::cout << "found a good particle, barcode: " << (*it)->barcode()
205// << " pdg: " << pdgcode << " status: " << (*it)->status()
206// << " end: ";
207// if (dcy != 0) {
208// std::cout << dcy->barcode();
209// } else {
210// std::cout << "nil";
211// }
212// std::cout << std::endl;
213
214 const G4ThreeVector& p=(*it)->momentum();
215 G4PrimaryParticle *part;
216 if (pdgcode!=999) {
217 part=new G4PrimaryParticle (pdgcode,p.x()*GeV,p.y()*GeV,p.z()*GeV);
218 } else {
219 G4ParticleDefinition *pdef = G4Geantino::GeantinoDefinition();
220 part=new G4PrimaryParticle (pdef,p.x()*GeV,p.y()*GeV,p.z()*GeV);
221 }
222
223 vertex->SetPosition((*v)->position().x(),
224 (*v)->position().y(),
225 (*v)->position().z());
226 vertex->SetT0((*v)->position().t());
227
228 vertex->SetPrimary(part);
229
230 n++;
231 }
232 }
233 }
234 anEvent->AddPrimaryVertex(vertex);
235
236 if ( m_logLevel <= int(MSG::DEBUG) ) {
237 std::cout << "AthenaHepMCtoG4EventAction: - done. G4Event has "
238 << n << " particles. "
239 << std::endl;
240 }
241
242 p_evtCollItr++;
243
244}
const Int_t n
@ INFO
Definition EvtReport.hh:52
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition KarLud.h:35
void SetHepMCEvent(McEventCol::iterator)