62 {
63
65 const std::vector<Trk::VxTrackAtVertex *> * tracks =
vertex->vxTrackAtVertex();
66 if ( tracks !=nullptr ) {
67
68
71 if (
sc.isFailure() ) {
74 msg() <<
"Zero pointer returned." <<
endmsg;
75 }
76 return nullptr;
77 }
78
79
82
83 if( genEvent->vertices_empty() ) {
85 return nullptr;
86 }
87 auto pv = genEvent->vertices()[0];
88
89
90
91
92
93 const auto& pv_pos =
pv ->position();
94 double pv_r = pv_pos.perp();
95 double pv_z = pv_pos.z();
96
97
98
99 std::map<int,HepMC::ConstGenVertexPtr> vertex_ids;
100 for (const auto& vtx: genEvent->vertices()){
101 const auto& lv_pos = vtx->position();
102 if ( std::abs ( lv_pos.perp() - pv_r ) <
m_r_tol && std::abs ( lv_pos.z() - pv_z ) <
m_z_tol ) {vertex_ids[vtx->id()] = vtx;}
103 }
104
105
108
109 if (
sc.isFailure() ) {
112 msg() <<
"Zero pointer returned" <<
endmsg;
113 }
114 return nullptr;
115 }
116
117
118 std::vector<Trk::VxTrackAtVertex *>::const_iterator
vt = tracks->begin();
119 std::vector<Trk::VxTrackAtVertex *>::const_iterator ve = tracks->end();
120 unsigned int n_failed = 0;
121 std::vector<double> in_weights ( 0 );
122 std::vector<double> out_weights ( 0 );
123 std::vector<double> pu_weights ( 0 );
124 std::vector<double> no_correspondance ( 0 );
125
126
127 for ( ;
vt!=ve;++
vt ) {
128
129
130 if ( ( *vt ) !=nullptr ) {
131
132 ITrackLink * origLink = ( **vt ).trackOrParticleLink();
133
134 if ( origLink !=nullptr ) {
135
136 LinkToTrackParticleBase * tr_part = dynamic_cast< LinkToTrackParticleBase * > ( origLink );
137 if ( tr_part !=nullptr && tr_part->isValid()) {
138
139
140 std::map< Rec::TrackParticleTruthKey, TrackParticleTruth>::const_iterator ttItr = trackParticleTruthCollection->end();
141
142 const Rec::TrackParticle* tp = dynamic_cast<const Rec::TrackParticle*>(**tr_part);
143 if(tp) {
144 const Rec::TrackParticleContainer* tpCont = dynamic_cast<const Rec::TrackParticleContainer*>(tr_part->getStorableObjectPointer());
145 if (tpCont) {
146 ElementLink<Rec::TrackParticleContainer> linkTruth;
149 ttItr = trackParticleTruthCollection->find(Rec::TrackParticleTruthKey(linkTruth));
150 }
151 }
152
153
154 if (ttItr != trackParticleTruthCollection->end() ) {
155 const HepMcParticleLink& particleLink = ttItr->second.particleLink();
157 if(genParticle) {
158 const auto *tpEvent = genParticle->parent_event();
159 if(tpEvent==genEvent) {
161 if (genParticle) pVertex = genParticle->production_vertex();
162 if ( pVertex) {
163 int link_pid = genParticle->pdg_id();
164 bool primary_track = false;
165 bool secondary_track = false;
166
167
168 do {
169 auto idf_res = vertex_ids.find ( pVertex->id() );
170
171
172
173 if ( idf_res != vertex_ids.end() ) {
174
175 primary_track = true;
176 in_weights.push_back ( ( *vt )->weight() );
177 }else {
178
179
180
181 if ( pVertex->particles_in_size() == 1 ) {
182
183 auto inp = pVertex->particles_in()[0] ;
184 auto tmpVertex_loc = inp ->production_vertex();
185 if ( inp ->pdg_id() == link_pid && tmpVertex_loc) {
186
187
188 pVertex = tmpVertex_loc;
189 }else {
190 secondary_track = true;
191 out_weights.push_back ( ( *vt )->weight() );
192 }
193 }else {
194
195
196
197 secondary_track = true;
198 out_weights.push_back ( ( *vt )->weight() );
199 }
200 }
201 }while ( !primary_track && !secondary_track );
202 }else {
203
204
205
207 msg() <<
"A truth particle with no production vertex found."<<
endmsg;
208 msg() <<
"Since it does not come from PV, consider as PileUp"<<
endmsg;
209 }
210 pu_weights.push_back ( ( *vt )->weight() );
211 }
212 }else {
213
214
215 pu_weights.push_back ( ( *vt )->weight() );
216 }
217 }else{
218
219
220
221 no_correspondance.push_back ( ( *vt )->weight() );
222 }
223 }
224 }else{
225 if (
msgLvl(MSG::DEBUG))
msg() <<
"This track at vertex has no valid link to its original trackparticle "<<
endmsg;
226 ++ n_failed;
227 }
228 }else{
229 if (
msgLvl(MSG::DEBUG))
msg() <<
"There is an empty pointer in the vector<VxTrackAtVertex *> for this vertex"<<
endmsg;
230 ++n_failed;
231 }
232 }
233 }
234
235
236
237
238
239
240
241
242
243 return new Trk::TrkPriVxPurity ( tracks->size(), pu_weights, no_correspondance,
244 n_failed, in_weights, out_weights );
245 }
246 }else{
248 msg()<<
"Empty vertex pointer received"<<
endmsg;
249 msg()<<
"Empty pointer returned."<<
endmsg;
250 }
251 return nullptr;
252 }
253 return nullptr;
254 }
Athena::TPCnvVers::Old TrackParticleTruthCollection
ServiceHandle< StoreGateSvc > & evtStore()
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
bool setElement(ElementType element)
Set link to point to an Element (slowest).
bool setStorableObject(BaseConstReference data, bool replace=false)
Set link storable to data object pointed by data (slower).
HepMC::ConstGenParticlePtr scptr() const
Dereference/smart pointer.
::StatusCode StatusCode
StatusCode definition for legacy code.
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
HepMC3::GenEvent GenEvent