31 return StatusCode::SUCCESS;
35 msg(MSG::INFO) <<
"Finalize successful" <<
endmsg;
36 return StatusCode::SUCCESS;
54 declareInterface<TrkPriVxPurityTool> (
this );
65 const std::vector<Trk::VxTrackAtVertex *> * tracks =
vertex->vxTrackAtVertex();
66 if ( tracks !=
nullptr ) {
71 if (
sc.isFailure() ) {
74 msg() <<
"Zero pointer returned." <<
endmsg;
81 const HepMC::GenEvent* genEvent= ( *it );
83 if( genEvent->vertices_empty() ) {
88 auto pv = genEvent->vertices()[0];
90 auto pv = *(genEvent->vertices_begin());
97 const auto& pv_pos =
pv ->position();
98 double pv_r = pv_pos.perp();
99 double pv_z = pv_pos.z();
103 std::map<int,HepMC::ConstGenVertexPtr> vertex_ids;
105 for (
const auto& vtx: genEvent->vertices()){
106 const auto& lv_pos = vtx->position();
107 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;}
110 for ( HepMC::GenEvent::vertex_const_iterator
i = genEvent->vertices_begin();
i != genEvent->vertices_end() ;++
i ) {
112 const auto& lv_pos = vtx->position();
122 if (
sc.isFailure() ) {
125 msg() <<
"Zero pointer returned" <<
endmsg;
131 std::vector<Trk::VxTrackAtVertex *>::const_iterator
vt = tracks->begin();
132 std::vector<Trk::VxTrackAtVertex *>::const_iterator ve = tracks->end();
133 unsigned int n_failed = 0;
134 std::vector<double> in_weights ( 0 );
135 std::vector<double> out_weights ( 0 );
136 std::vector<double> pu_weights ( 0 );
137 std::vector<double> no_correspondance ( 0 );
140 for ( ;
vt!=ve;++
vt ) {
143 if ( ( *
vt ) !=
nullptr ) {
145 ITrackLink * origLink = ( **vt ).trackOrParticleLink();
147 if ( origLink !=
nullptr ) {
150 if ( tr_part !=
nullptr && tr_part->
isValid()) {
153 std::map< Rec::TrackParticleTruthKey, TrackParticleTruth>::const_iterator ttItr = trackParticleTruthCollection->end();
167 if (ttItr != trackParticleTruthCollection->end() ) {
176 const auto *tpEvent = genParticle->parent_event();
177 if(tpEvent==genEvent) {
179 if (genParticle) pVertex = genParticle->production_vertex();
181 int link_pid = genParticle->pdg_id();
182 bool primary_track =
false;
183 bool secondary_track =
false;
188 auto idf_res = vertex_ids.find ( pVertex->id() );
195 if ( idf_res != vertex_ids.end() ) {
197 primary_track =
true;
198 in_weights.push_back ( ( *vt )->weight() );
203 if ( pVertex->particles_in_size() == 1 ) {
206 auto inp = pVertex->particles_in()[0] ;
208 auto inp =*(pVertex->particles_in_const_begin()) ;
210 auto tmpVertex_loc = inp ->production_vertex();
211 if ( inp ->pdg_id() == link_pid && tmpVertex_loc) {
214 pVertex = tmpVertex_loc;
216 secondary_track =
true;
217 out_weights.push_back ( ( *vt )->weight() );
223 secondary_track =
true;
224 out_weights.push_back ( ( *vt )->weight() );
227 }
while ( !primary_track && !secondary_track );
233 msg() <<
"A truth particle with no production vertex found."<<
endmsg;
234 msg() <<
"Since it does not come from PV, consider as PileUp"<<
endmsg;
236 pu_weights.push_back ( ( *vt )->weight() );
241 pu_weights.push_back ( ( *vt )->weight() );
247 no_correspondance.push_back ( ( *vt )->weight() );
270 n_failed, in_weights, out_weights );
274 msg()<<
"Empty vertex pointer received"<<
endmsg;
275 msg()<<
"Empty pointer returned."<<
endmsg;