ATLAS Offline Software
Loading...
Searching...
No Matches
BPhysPVThinningTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6// ThinningToolExample.cxx
8// Author: James Catmore (James.Catmore@cern.ch)
9// This is a trivial example of an implementation of a thinning tool
10// which removes all ID tracks which do not pass a user-defined cut
11
12#include "BPhysPVThinningTool.h"
18#include <algorithm>
19#include <numeric>
20#include <vector>
21#include <string>
22
23using namespace std;
24using namespace xAOD;
25// Constructor
27 const std::string& n,
28 const IInterface* p ) :
29 base_class(t,n,p),
30 m_TrackContainerName("InDetTrackParticles"),
31 m_PVContainerName("PrimaryVertices"),
32 m_ntot(0),
34{
35 declareProperty("CandidateCollections" , m_BPhyCandList);
36 declareProperty("KeepPVTracks", m_keepTracks);
37 declareProperty("TrackParticleContainerName", m_TrackContainerName);
38 declareProperty("PrimaryVertexContainerName", m_PVContainerName);
39}
40
41// Destructor
44
45// Athena initialize and finalize
47{
48 ATH_MSG_VERBOSE("initialize() ...");
49 ATH_CHECK(m_BPhyCandList.initialize());
50 if(not m_TrackContainerName.key().empty()) ATH_CHECK(m_TrackContainerName.initialize(m_streamName));
52
53 return StatusCode::SUCCESS;
54}
56{
57 ATH_MSG_VERBOSE("finalize() ...");
58 ATH_MSG_INFO("Processed "<< m_ntot <<" PV, "<< m_npass<< " were retained ");
59 if(m_keepTracks) ATH_MSG_INFO("Additional tracks kept " << m_tracks_kept);
60 return StatusCode::SUCCESS;
61}
62
63// The thinning itself
65{
66 const EventContext& ctx = Gaudi::Hive::currentContext();
67 // Get the track container
69 if(!PV_col.isValid()) {
70 ATH_MSG_ERROR ("Couldn't retrieve VertexContainer with key PrimaryVertices");
71 return StatusCode::FAILURE;
72 }
73 m_ntot+=PV_col->size();
74 // Loop over tracks, see if they pass, set mask
75 std::vector<bool> mask(PV_col->size(), false);
76
81
82
83
84 for(auto &str : m_BPhyCandList) {
86 ATH_CHECK(Container.isValid());
87 size_t s = Container->size();
88 for(size_t i = 0; i<s; i++) {
89 xAOD::BPhysHelper vtx(Container->at(i));
90
91 for(size_t i =0; i < 4; i++) {
92 const xAOD::Vertex* origPv = vtx.origPv(pvtypes[i]);
93 if(origPv==nullptr) continue;
94 auto pvit = std::find (PV_col->begin(), PV_col->end(), origPv);
95 if(pvit == PV_col->end()) {
96 ATH_MSG_WARNING("PV not found in container");
97 continue;
98 }
99 size_t x = std::distance(PV_col->begin(), pvit);
100 mask.at(x) = true;
101 }
102
103 }
104 }
105
106 m_npass += std::accumulate(mask.begin(), mask.end(), 0);
107
108 if(m_keepTracks){
110 std::vector<bool> trackmask(importedTrackParticles->size(), false);
111 size_t pvnum = mask.size();
112 for(size_t i =0; i<pvnum;i++){
113 if(mask[i] == false) continue;
114 auto vtx = PV_col->at(i);
115 size_t s = vtx->nTrackParticles();
116 for(size_t j=0;j<s;j++){
117 auto trackit = std::find(importedTrackParticles->begin(), importedTrackParticles->end(), vtx->trackParticle(j));
118 if(trackit == importedTrackParticles->end()){
119 ATH_MSG_WARNING("track not found in container");
120 continue;
121 }
122 size_t x = std::distance(importedTrackParticles->begin(), trackit);
123 trackmask.at(x) = true;
124 }
125 }
126 importedTrackParticles.keep(trackmask);
127 m_tracks_kept += std::accumulate(trackmask.begin(), trackmask.end(), 0);
128 }
129 PV_col.keep(mask);
130
131 return StatusCode::SUCCESS;
132}
133
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
: B-physics xAOD helpers.
Handle for requesting thinning for a data object.
#define x
SG::ReadHandleKeyArray< xAOD::VertexContainer > m_BPhyCandList
BPhysPVThinningTool(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
SG::ThinningHandleKey< xAOD::VertexContainer > m_PVContainerName
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_TrackContainerName
virtual StatusCode doThinning() const override
Check that the current event passes this filter.
storage of the time histories of all the cells
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
const xAOD::Vertex * origPv(const pv_type vertexType=BPhysHelper::PV_MIN_A0)
original PV
pv_type
: Enum type of the PV
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Vertex_v1 Vertex
Define the latest version of the vertex class.