ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
GeneratorObjectsTPCnv
src
initMcEventCollection.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
GeneratorObjectsTPCnv/initMcEventCollection.h
"
5
6
// HepMC includes
7
#include "
AtlasHepMC/GenEvent.h
"
8
#include "
AtlasHepMC/GenParticle.h
"
9
#include "
AtlasHepMC/GenVertex.h
"
10
11
// CLHEP includes
12
#include "CLHEP/Units/SystemOfUnits.h"
13
14
#include "
GeneratorObjectsTPCnv/HepMcParticleLinkCnv_p1.h
"
15
#include "
StoreGate/WriteHandle.h
"
16
#include "
GeneratorObjects/McEventCollection.h
"
17
#include "
TruthUtils/MagicNumbers.h
"
18
#include "
AthenaKernel/ExtendedEventContext.h
"
19
#include "GaudiKernel/ThreadLocalContext.h"
20
21
#include "
TestTools/initGaudi.h
"
22
23
namespace
Athena_test
{
24
bool
initMcEventCollection
(ISvcLocator*& pSvcLoc, std::vector<HepMC::GenParticlePtr>& genPartList,
const
bool
initGaudi
)
25
{
26
if
(
initGaudi
&& !
Athena_test::initGaudi
(pSvcLoc)) {
27
std::cerr <<
"This test can not be run"
<< std::endl;
28
return
false
;
29
}
30
// create dummy input McEventCollection with a name that
31
// HepMcParticleLink knows about
32
SG::WriteHandle<McEventCollection>
inputTestDataHandle{
"TruthEvent"
};
33
inputTestDataHandle = std::make_unique<McEventCollection>();
34
35
// Add a dummy GenEvent
36
const
int
process_id1(20);
37
const
int
event_number1(17);
38
inputTestDataHandle->push_back(
HepMC::newGenEvent
(process_id1, event_number1));
39
HepMC::GenEvent
& ge1 = *(inputTestDataHandle->at(0));
40
populateGenEvent
(ge1,-11,11,genPartList);
41
populateGenEvent
(ge1,-13,13,genPartList);
42
populateGenEvent
(ge1,-11,11,genPartList);
43
populateGenEvent
(ge1,-13,13,genPartList);
44
populateGenEvent
(ge1,-11,11,genPartList);
45
populateGenEvent
(ge1,22,22,genPartList);
46
inputTestDataHandle->push_back(
new
HepMC::GenEvent
(ge1));
47
HepMC::GenEvent
& ge2 = *(inputTestDataHandle->at(1));
48
const
int
event_number2(89);
49
ge2.set_event_number(event_number2);
50
populateFilteredGenEvent
(ge2,genPartList);
51
return
true
;
52
}
53
54
int
maximumBarcode
(std::vector<HepMC::GenParticlePtr>& genPartList)
55
{
56
int
maxBarcode{0};
57
if
(genPartList.empty()) {
return
maxBarcode; }
58
for
(
HepMC::GenParticlePtr
genPart : genPartList)
59
{
60
maxBarcode = std::max(maxBarcode,
HepMC::barcode
(genPart));
61
}
62
return
maxBarcode;
63
}
64
65
void
populateGenEvent
(
HepMC::GenEvent
& ge,
int
pdgid1,
int
pdgid2, std::vector<HepMC::GenParticlePtr>& genPartList)
66
{
67
int
maxBarcode =
maximumBarcode
(genPartList);
68
HepMC::FourVector
myPos( 0.0, 0.0, 0.0, 0.0);
69
HepMC::GenVertexPtr
myVertex =
HepMC::newGenVertexPtr
( myPos, -1 );
70
HepMC::FourVector
fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
71
HepMC::GenParticlePtr
inParticle1 =
HepMC::newGenParticlePtr
(fourMomentum1, pdgid1, 2);
72
myVertex->add_particle_in(inParticle1);
73
HepMC::FourVector
fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
74
HepMC::GenParticlePtr
inParticle2 =
HepMC::newGenParticlePtr
(fourMomentum2, pdgid2, 2);
75
myVertex->add_particle_in(inParticle2);
76
HepMC::FourVector
fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
77
HepMC::GenParticlePtr
inParticle3 =
HepMC::newGenParticlePtr
(fourMomentum3, pdgid1, 1);
78
myVertex->add_particle_out(inParticle3);
79
genPartList.push_back(inParticle3);
80
HepMC::FourVector
fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
81
HepMC::GenParticlePtr
inParticle4 =
HepMC::newGenParticlePtr
(fourMomentum4, pdgid2, 1);
82
myVertex->add_particle_out(inParticle4);
83
genPartList.push_back(inParticle4);
84
ge.add_vertex( myVertex );
85
HepMC::suggest_barcode
(inParticle1,maxBarcode+1);
86
HepMC::suggest_barcode
(inParticle2,maxBarcode+2);
87
HepMC::suggest_barcode
(inParticle3,maxBarcode+3);
88
HepMC::suggest_barcode
(inParticle4,maxBarcode+4);
89
HepMC::set_signal_process_vertex
(&ge, myVertex );
90
ge.set_beam_particles(std::move(inParticle1),std::move(inParticle2));
91
}
92
93
void
populateFilteredGenEvent
(
HepMC::GenEvent
& ge, std::vector<HepMC::GenParticlePtr>& genPartVector)
94
{
95
//.......Create new particle (geantino) to link hits from pileup
96
HepMC::GenParticlePtr
genPart=
HepMC::newGenParticlePtr
();
97
genPart->set_pdg_id(999);
//Geantino
98
genPart->set_status(1);
99
HepMC::suggest_barcode
(genPart,
HepMC::SUPPRESSED_PILEUP_BARCODE
);
100
101
HepMC::GenVertexPtr
genVertex=
HepMC::newGenVertexPtr
();
102
genVertex->add_particle_out(genPart);
103
genPartVector.push_back(genPart);
104
105
//to set geantino vertex as a truth primary vertex
106
HepMC::GenVertexPtr
hScatVx =
HepMC::barcode_to_vertex
(&ge,-3);
107
if
(hScatVx!=
nullptr
) {
108
HepMC::FourVector
pmvxpos=hScatVx->position();
109
genVertex->set_position(pmvxpos);
110
//to set geantino kinematic phi=eta=0, E=p=E_hard_scat
111
auto
itrp =hScatVx->particles_in().cbegin();
112
if
(hScatVx->particles_in().size()==2) {
113
HepMC::FourVector
mom1=(*itrp)->momentum();
114
HepMC::FourVector
mom2=(*(++itrp))->momentum();
115
HepMC::FourVector
vxmom;
116
vxmom.setPx(mom1.e()+mom2.e());
117
vxmom.setPy(0.);
118
vxmom.setPz(0.);
119
vxmom.setE(mom1.e()+mom2.e());
120
genPart->set_momentum(vxmom);
121
}
122
}
123
124
if
(!ge.vertices().empty()) {
125
std::vector<HepMC::GenVertexPtr> vtxvec;
126
for
(
const
auto
& vtx: ge.vertices()) {
127
vtxvec.push_back(vtx);
128
ge.remove_vertex(vtx);
129
}
130
vtxvec.clear();
131
}
132
133
//.....add new vertex with geantino
134
ge.add_vertex(std::move(genVertex));
135
HepMC::suggest_barcode
(genPart,
HepMC::SUPPRESSED_PILEUP_BARCODE
);
136
}
137
}
ExtendedEventContext.h
GenEvent.h
GenParticle.h
GenVertex.h
HepMcParticleLinkCnv_p1.h
MagicNumbers.h
McEventCollection.h
WriteHandle.h
Handle class for recording to StoreGate.
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:71
initGaudi.h
minimal gaudi initialization for AthenaServices unit testing
initMcEventCollection.h
minimal gaudi initialization and record an McEventCollection in StoreGate
Athena_test
functions & macros to test the difference between floats
Definition
InitGaudiGoogleTest.h:30
Athena_test::maximumBarcode
int maximumBarcode(std::vector< HepMC::GenParticlePtr > &genPartList)
Definition
initMcEventCollection.cxx:54
Athena_test::initMcEventCollection
bool initMcEventCollection(ISvcLocator *&pSvcLoc, std::vector< HepMC::GenParticlePtr > &genPartVector, const bool initGaudi=true)
Definition
initMcEventCollection.cxx:24
Athena_test::initGaudi
bool initGaudi(ISvcLocator *&pSvcLoc)
Minimal Gaudi initialization for unit testing without job options.
Definition
initGaudi.cxx:25
Athena_test::populateGenEvent
void populateGenEvent(HepMC::GenEvent &ge, int pdgid1, int pdgid2, std::vector< HepMC::GenParticlePtr > &genPartVector)
Definition
initMcEventCollection.cxx:65
Athena_test::populateFilteredGenEvent
void populateFilteredGenEvent(HepMC::GenEvent &ge, std::vector< HepMC::GenParticlePtr > &genPartVector)
Definition
initMcEventCollection.cxx:93
HepMC::barcode_to_vertex
ConstGenVertexPtr barcode_to_vertex(const GenEvent *e, int id)
Definition
GenEvent.h:403
HepMC::barcode
int barcode(const T *p)
Definition
Barcode.h:15
HepMC::FourVector
HepMC3::FourVector FourVector
Definition
SimpleVector.h:11
HepMC::set_signal_process_vertex
void set_signal_process_vertex(GenEvent *e, T &v)
Definition
GenEvent.h:591
HepMC::SUPPRESSED_PILEUP_BARCODE
constexpr int SUPPRESSED_PILEUP_BARCODE(std::numeric_limits< int32_t >::max())
This barcode is used by objects matched to particles from pile-up interactions in standard MC Product...
HepMC::newGenParticlePtr
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition
GenParticle.h:21
HepMC::suggest_barcode
bool suggest_barcode(T &p, int i)
Definition
GenEvent.h:607
HepMC::GenParticlePtr
HepMC3::GenParticlePtr GenParticlePtr
Definition
GenParticle.h:19
HepMC::newGenVertexPtr
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
Definition
GenVertex.h:25
HepMC::GenVertexPtr
HepMC3::GenVertexPtr GenVertexPtr
Definition
GenVertex.h:23
HepMC::newGenEvent
GenEvent * newGenEvent(const int signal_process_id, const int event_number)
Definition
GenEvent.h:360
HepMC::GenEvent
HepMC3::GenEvent GenEvent
Definition
GenEvent.h:39
Generated on
for ATLAS Offline Software by
1.17.0