BOSS 8.0.0
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 2005/08/17 06:45:46 dengzy Exp $
12// Simulation/G4Sim/G4Svc tag $Name: G4Svc-00-01-58 $
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 "G4Geantino.hh"
25#include "G4LorentzVector.hh"
26#include "G4PrimaryParticle.hh"
27#include "G4PrimaryVertex.hh"
28
29#include "GaudiKernel/IMessageSvc.h"
30
31using namespace HepMC;
32
33AthenaHepMCtoG4EventAction::AthenaHepMCtoG4EventAction( int level ) : m_logLevel( level ) {}
34
36
38
39//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
40
41// void AthenaHepMCtoG4EventAction::SetHepMCEvent(const HepMC::GenEvent *p) {
42void AthenaHepMCtoG4EventAction::SetHepMCEvent( McEventCol::iterator p ) {
43
44 if ( m_logLevel <= int( MSG::DEBUG ) )
45 { std::cout << "AthenaHepMCtoG4EventAction: - Setting HepMC Event ptr" << std::endl; }
46
47 // p_evt = p;
48 p_evtCollItr = p;
49}
50
51//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
52
53// void AthenaHepMCtoG4EventAction::GeneratePrimaries(G4Event* anEvent)
54// {
55// if ( m_logLevel <= int(MSG::DEBUG) ) {
56// std::cout << "AthenaHepMCtoG4EventAction: - Generating Primaries"
57// << std::endl;
58// }
59
60// p_evt = (*p_evtCollItr)->pGenEvt();
61
62// if (p_evt == 0) {
63
64// if ( m_logLevel <= int(MSG::WARNING) ) {
65// std::cout << "AthenaHepMCtoG4EventAction: - HepMC ptr == null"
66// << std::endl;
67// }
68
69// return;
70
71// }
72
73// int nv = 1;
74// int mnv;
75
76// std::cout << "how many vertices: ";
77// std::cin >> mnv;
78
79// for ( HepMC::GenEvent::vertex_const_iterator v = p_evt->vertices_begin();
80// v != p_evt->vertices_end(); ++v ) {
81// bool IsGood=false;
82// for (HepMC::GenVertex::particle_iterator it=
83// (*v)->particles_begin(HepMC::children);
84// it!=(*v)->particles_end(HepMC::children);
85// it++) {
86
87// if (!(*it)->end_vertex() && (*it)->status()==1 ) {
88// IsGood=true;
89// break;
90// }
91// }
92
93// if (IsGood) {
94// std::cout << "found a good vertex, barcode: " << (*v)->barcode()
95// << std::endl;
96
97// G4LorentzVector lv=(*v)->position();
98// G4PrimaryVertex *vert= new G4PrimaryVertex(lv.x(),lv.y(),lv.z(),lv.t());
99
100// for (HepMC::GenVertex::particle_iterator it=
101// (*v)->particles_begin(HepMC::children);
102// it!=(*v)->particles_end(HepMC::children);
103// it++) {
104
105// // if ( (*it)->status() != 1) continue;
106
107// int pdgcode=(*it)->pdg_id();
108// GenVertex *dcy = (*it)->end_vertex();
109// std::cout << "found a good particle, barcode: " << (*it)->barcode()
110// << " pdg: " << pdgcode << " status: " << (*it)->status()
111// << " end: ";
112// if (dcy != 0) {
113// std::cout << dcy->barcode();
114// } else {
115// std::cout << "nil";
116// }
117// std::cout << std::endl;
118
119// const G4ThreeVector& p=(*it)->momentum();
120// G4PrimaryParticle *part;
121// if (pdgcode!=999) {
122// part=new G4PrimaryParticle (pdgcode,p.x()*GeV,p.y()*GeV,p.z()*GeV);
123// } else {
124// G4ParticleDefinition *pdef = G4Geantino::GeantinoDefinition();
125// part=new G4PrimaryParticle (pdef,p.x()*GeV,p.y()*GeV,p.z()*GeV);
126// }
127// vert->SetPrimary(part);
128// }
129// anEvent->AddPrimaryVertex(vert);
130// if (nv > mnv) { break; }
131// nv ++;
132// }
133// }
134
135// std::cout << "done generating event" << std::endl;
136
137// p_evtCollItr++;
138
139// }
140
141//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
142
144 if ( m_logLevel <= int( MSG::DEBUG ) )
145 { std::cout << "AthenaHepMCtoG4EventAction: - Generating Primaries" << std::endl; }
146
147 p_evt = (const HepMC::GenEvent*)( *p_evtCollItr );
148
149 if ( p_evt == 0 )
150 {
151
152 if ( m_logLevel <= int( MSG::WARNING ) )
153 { std::cout << "AthenaHepMCtoG4EventAction: - HepMC ptr == null" << std::endl; }
154
155 return;
156 }
157
158 G4PrimaryVertex* vertex = new G4PrimaryVertex( 0., 0., 0., 0. );
159
160 int n = 0;
161 for ( HepMC::GenEvent::vertex_const_iterator v = p_evt->vertices_begin();
162 v != p_evt->vertices_end(); ++v )
163 {
164 bool IsGood = false;
165 for ( HepMC::GenVertex::particle_iterator it = ( *v )->particles_begin( HepMC::children );
166 it != ( *v )->particles_end( HepMC::children ); it++ )
167 {
168
169 if ( !( *it )->end_vertex() && ( *it )->status() == 1 )
170 {
171 IsGood = true;
172 break;
173 }
174 }
175
176 if ( IsGood )
177 {
178 // std::cout << "found a good vertex, barcode: " << (*v)->barcode()
179 // << std::endl;
180
181 for ( HepMC::GenVertex::particle_iterator it =
182 ( *v )->particles_begin( HepMC::children );
183 it != ( *v )->particles_end( HepMC::children ); it++ )
184 {
185
186 if ( ( *it )->status() != 1 ) continue;
187
188 int pdgcode = ( *it )->pdg_id();
189 // GenVertex *dcy = (*it)->end_vertex();
190 // std::cout << "found a good particle, barcode: " << (*it)->barcode()
191 // << " pdg: " << pdgcode << " status: " << (*it)->status()
192 // << " end: ";
193 // if (dcy != 0) {
194 // std::cout << dcy->barcode();
195 // } else {
196 // std::cout << "nil";
197 // }
198 // std::cout << std::endl;
199
200 const G4ThreeVector& p = ( *it )->momentum();
201 G4PrimaryParticle* part;
202 if ( pdgcode != 999 )
203 { part = new G4PrimaryParticle( pdgcode, p.x() * GeV, p.y() * GeV, p.z() * GeV ); }
204 else
205 {
206 G4ParticleDefinition* pdef = G4Geantino::GeantinoDefinition();
207 part = new G4PrimaryParticle( pdef, p.x() * GeV, p.y() * GeV, p.z() * GeV );
208 }
209
210 vertex->SetPosition( ( *v )->position().x(), ( *v )->position().y(),
211 ( *v )->position().z() );
212 vertex->SetT0( ( *v )->position().t() );
213
214 vertex->SetPrimary( part );
215
216 n++;
217 }
218 }
219 }
220 anEvent->AddPrimaryVertex( vertex );
221
222 if ( m_logLevel <= int( MSG::DEBUG ) )
223 {
224 std::cout << "AthenaHepMCtoG4EventAction: - done. G4Event has " << n << " particles. "
225 << std::endl;
226 }
227
228 p_evtCollItr++;
229}
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)