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
64StatusCode DerivationFramework::BPhysPVThinningTool::doThinning(const EventContext& ctx) const
65{
66 // Get the track container
68 if(!PV_col.isValid()) {
69 ATH_MSG_ERROR ("Couldn't retrieve VertexContainer with key PrimaryVertices");
70 return StatusCode::FAILURE;
71 }
72 m_ntot+=PV_col->size();
73 // Loop over tracks, see if they pass, set mask
74 std::vector<bool> mask(PV_col->size(), false);
75
80
81
82
83 for(auto &str : m_BPhyCandList) {
85 ATH_CHECK(Container.isValid());
86 size_t s = Container->size();
87 for(size_t i = 0; i<s; i++) {
88 xAOD::BPhysHelper vtx(Container->at(i));
89
90 for(size_t i =0; i < 4; i++) {
91 const xAOD::Vertex* origPv = vtx.origPv(pvtypes[i]);
92 if(origPv==nullptr) continue;
93 auto pvit = std::find (PV_col->begin(), PV_col->end(), origPv);
94 if(pvit == PV_col->end()) {
95 ATH_MSG_WARNING("PV not found in container");
96 continue;
97 }
98 size_t x = std::distance(PV_col->begin(), pvit);
99 mask.at(x) = true;
100 }
101
102 }
103 }
104
105 m_npass += std::accumulate(mask.begin(), mask.end(), 0);
106
107 if(m_keepTracks){
109 std::vector<bool> trackmask(importedTrackParticles->size(), false);
110 size_t pvnum = mask.size();
111 for(size_t i =0; i<pvnum;i++){
112 if(mask[i] == false) continue;
113 auto vtx = PV_col->at(i);
114 size_t s = vtx->nTrackParticles();
115 for(size_t j=0;j<s;j++){
116 auto trackit = std::find(importedTrackParticles->begin(), importedTrackParticles->end(), vtx->trackParticle(j));
117 if(trackit == importedTrackParticles->end()){
118 ATH_MSG_WARNING("track not found in container");
119 continue;
120 }
121 size_t x = std::distance(importedTrackParticles->begin(), trackit);
122 trackmask.at(x) = true;
123 }
124 }
125 importedTrackParticles.keep(trackmask);
126 m_tracks_kept += std::accumulate(trackmask.begin(), trackmask.end(), 0);
127 }
128 PV_col.keep(mask);
129
130 return StatusCode::SUCCESS;
131}
132
#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 EventContext &ctx) 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.