ATLAS Offline Software
Loading...
Searching...
No Matches
AugOriginalCounts.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "AugOriginalCounts.h"
12#include "GaudiKernel/EventContext.h"
13
14using namespace xAOD;
15namespace DerivationFramework {
16
18 const std::string& n,
19 const IInterface* p) :
20 base_class(t,n,p),
21 m_TrackContainername("InDetTrackParticles"),
22 m_TrackContainerLRTname("InDetLargeD0TrackParticles"),
23 m_PVContainername("PrimaryVertices")
24 {
25
26 declareProperty("TrackContainer", m_TrackContainername);
27 declareProperty("TrackLRTContainer", m_TrackContainerLRTname);
28 declareProperty("VertexContainer", m_PVContainername);
29 declareProperty("AddPVCountsByType", m_addPVCountsByType = false);
30 // decorate PVs with track counts and/or sqrt(sum(pt^2))
31 // (needed if track collection will be thinned)
32 declareProperty("AddNTracksToPVs", m_addNTracksToPVs = false);
33 declareProperty("AddSqrtPt2SumToPVs", m_addSqrtPt2SumToPVs = false);
34 }
35
37 {
41
42 if(!m_PVContainername.empty()){
43 std::string pvstring = "EventInfo.OriginalCount_";
44 pvstring += m_PVContainername.key();
45 m_OrigPVNTracks = std::move(pvstring);
46 ATH_CHECK(m_OrigPVNTracks.initialize());
47 }
48 if ( m_addPVCountsByType ) {
49 std::string pv0string = "EventInfo.OriginalCount_type0_"+m_PVContainername.key();
50 std::string pv1string = "EventInfo.OriginalCount_type1_"+m_PVContainername.key();
51 std::string pv2string = "EventInfo.OriginalCount_type2_"+m_PVContainername.key();
52 std::string pv3string = "EventInfo.OriginalCount_type3_"+m_PVContainername.key();
53 std::string pvUstring = "EventInfo.OriginalCount_typeUnknown_"+m_PVContainername.key();
54 m_OrigNtype0 = std::move(pv0string);
55 m_OrigNtype1 = std::move(pv1string);
56 m_OrigNtype2 = std::move(pv2string);
57 m_OrigNtype3 = std::move(pv3string);
58 m_OrigNtypeUnknown = std::move(pvUstring);
59 ATH_CHECK(m_OrigNtype0.initialize());
60 ATH_CHECK(m_OrigNtype1.initialize());
61 ATH_CHECK(m_OrigNtype2.initialize());
62 ATH_CHECK(m_OrigNtype3.initialize());
63 ATH_CHECK(m_OrigNtypeUnknown.initialize());
64 }
66 std::string trackcon = m_PVContainername.key();
67 trackcon += ".OriginalCount_";
68 trackcon += m_TrackContainername.key();
69 m_OrigSqrtPt2Sum = std::move(trackcon);
70 ATH_CHECK(m_OrigSqrtPt2Sum.initialize());
71 }
72 if ( m_addNTracksToPVs ) {
73 std::string name = m_PVContainername.key();
74 name+= ".OrigNTracks";
75 m_d_nPVTracks = std::move(name);
76 ATH_CHECK(m_d_nPVTracks.initialize());
77 }
78 if(!m_TrackContainername.empty()){
79 m_OrigNTracksKeys = "EventInfo.OriginalCount_" + m_TrackContainername.key();
80 ATH_CHECK(m_OrigNTracksKeys.initialize());
81 }
82 if(!m_TrackContainerLRTname.empty()){
83 m_OrigNTracksLRTKeys = "EventInfo.OriginalCount_" + m_TrackContainerLRTname.key();
84 ATH_CHECK(m_OrigNTracksLRTKeys.initialize());
85 }
86 return StatusCode::SUCCESS;
87 }
88
89 StatusCode AugOriginalCounts::addBranches(const EventContext& ctx) const
90 {
91
92
93 if(!m_PVContainername.empty()){
94
97 if(!PV_count.isAvailable()) PV_count(0) = vertices->size();
98
99 if ( m_addPVCountsByType ) {
105
106 // now count
107 constexpr int nvtypes = 5;
108 int nvtc[] = {0, 0, 0, 0, 0};
109 for (auto vtx : *vertices) {
110 VxType::VertexType vt = vtx->vertexType();
111 if ( vt >=0 && vt < nvtypes ) {
112 nvtc[vt]++; // vertex types 0 - 3
113 } else {
114 nvtc[nvtypes-1]++; // unknown
115 }
116 }
117 if(!PV0_count.isAvailable()) PV0_count(0) = nvtc[0];
118 if(!PV1_count.isAvailable()) PV1_count(0) = nvtc[1];
119 if(!PV2_count.isAvailable()) PV2_count(0) = nvtc[2];
120 if(!PV3_count.isAvailable()) PV3_count(0) = nvtc[3];
121 if(!PVUnk_count.isAvailable()) PVUnk_count(0) = nvtc[4];
122 } // m_addPVCountsByType
123
124 // decorate PVs with track counts
125 // (needed if track collection will be thinned)
126 if ( m_addNTracksToPVs ) {
128 if(!d_nPVTracks.isAvailable()){
129 for (auto vtx : *vertices) {
130 d_nPVTracks(*vtx) = (int)vtx->nTrackParticles();
131 }
132 }
133 } // m_addNTracksToPVs
134
135 // decorate PVs with sqrt(sum(pt^2)) of tracks
136 // (needed if track collection will be thinned)
137 if ( m_addSqrtPt2SumToPVs ) {
139 if(!d_pvSqrtPt2Sum.isAvailable()){
140 for (auto vtx : *vertices) {
141 float sqrtPt2Sum(0.);
142 for (auto tp : vtx->trackParticleLinks()) {
143 sqrtPt2Sum += std::sqrt(pow((*tp)->pt(),2));
144 }
145 d_pvSqrtPt2Sum(*vtx) = sqrtPt2Sum;
146 }
147 }
148 } // m_addSqrtPt2SumToPVs
149 }
150
151 if(!m_TrackContainername.empty()){
154 if(!track_count.isAvailable()) track_count(0) = tracks->size();
155 }
156 if(!m_TrackContainerLRTname.empty()){
159 if(!track_count.isAvailable()) track_count(0) = tracks->size();
160 }
161
162 return StatusCode::SUCCESS;
163 }
164}
#define ATH_CHECK
Evaluate an expression and check for errors.
Augmentation with primary vertex counts (before thinning)
Handle class for adding a decoration to an object.
constexpr int pow(int base, int exp) noexcept
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigPVNTracks
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_d_nPVTracks
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNTracksKeys
AugOriginalCounts(const std::string &t, const std::string &n, const IInterface *p)
Main constructor.
virtual StatusCode initialize() override
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_OrigSqrtPt2Sum
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtypeUnknown
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainerLRTname
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype0
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainername
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype3
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNTracksLRTKeys
SG::ReadHandleKey< xAOD::VertexContainer > m_PVContainername
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype1
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype2
virtual StatusCode addBranches(const EventContext &ctx) const override
Main method called for each event.
Handle class for adding a decoration to an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
THE reconstruction tool.
VertexType
Vertex types.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
setRawEt setRawPhi int