ATLAS Offline Software
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 
12 #include "GaudiKernel/EventContext.h"
13 
14 using namespace xAOD;
15 namespace DerivationFramework {
16 
17  AugOriginalCounts::AugOriginalCounts(const std::string& t,
18  const std::string& n,
19  const IInterface* p) :
20  AthAlgTool(t,n,p),
21  m_TrackContainername("InDetTrackParticles"),
22  m_TrackContainerLRTname("InDetLargeD0TrackParticles"),
23  m_PVContainername("PrimaryVertices")
24  {
25  declareInterface<DerivationFramework::IAugmentationTool>(this);
26 
27  declareProperty("TrackContainer", m_TrackContainername);
28  declareProperty("TrackLRTContainer", m_TrackContainerLRTname);
29  declareProperty("VertexContainer", m_PVContainername);
30  declareProperty("AddPVCountsByType", m_addPVCountsByType = false);
31  // decorate PVs with track counts and/or sqrt(sum(pt^2))
32  // (needed if track collection will be thinned)
33  declareProperty("AddNTracksToPVs", m_addNTracksToPVs = false);
34  declareProperty("AddSqrtPt2SumToPVs", m_addSqrtPt2SumToPVs = false);
35  }
36 
38  {
42 
43  if(!m_PVContainername.empty()){
44  std::string pvstring = "EventInfo.OriginalCount_";
45  pvstring += m_PVContainername.key();
46  m_OrigPVNTracks = std::move(pvstring);
48  }
49  if ( m_addPVCountsByType ) {
50  std::string pv0string = "EventInfo.OriginalCount_type0_"+m_PVContainername.key();
51  std::string pv1string = "EventInfo.OriginalCount_type1_"+m_PVContainername.key();
52  std::string pv2string = "EventInfo.OriginalCount_type2_"+m_PVContainername.key();
53  std::string pv3string = "EventInfo.OriginalCount_type3_"+m_PVContainername.key();
54  std::string pvUstring = "EventInfo.OriginalCount_typeUnknown_"+m_PVContainername.key();
55  m_OrigNtype0 = std::move(pv0string);
56  m_OrigNtype1 = std::move(pv1string);
57  m_OrigNtype2 = std::move(pv2string);
58  m_OrigNtype3 = std::move(pv3string);
59  m_OrigNtypeUnknown = std::move(pvUstring);
65  }
66  if ( m_addSqrtPt2SumToPVs ) {
67  std::string trackcon = m_PVContainername.key();
68  trackcon += ".OriginalCount_";
69  trackcon += m_TrackContainername.key();
70  m_OrigSqrtPt2Sum = std::move(trackcon);
71  ATH_CHECK(m_OrigSqrtPt2Sum.initialize());
72  }
73  if ( m_addNTracksToPVs ) {
74  std::string name = m_PVContainername.key();
75  name+= ".OrigNTracks";
76  m_d_nPVTracks = std::move(name);
77  ATH_CHECK(m_d_nPVTracks.initialize());
78  }
80  m_OrigNTracksKeys = "EventInfo.OriginalCount_" + m_TrackContainername.key();
82  }
84  m_OrigNTracksLRTKeys = "EventInfo.OriginalCount_" + m_TrackContainerLRTname.key();
86  }
87  return StatusCode::SUCCESS;
88  }
89 
91  {
92 
93  const EventContext& ctx = Gaudi::Hive::currentContext();
94 
95  if(!m_PVContainername.empty()){
96 
99  PV_count(0) = vertices->size();
100 
101  if ( m_addPVCountsByType ) {
107 
108  // now count
109  constexpr int nvtypes = 5;
110  int nvtc[] = {0, 0, 0, 0, 0};
111  for (auto vtx : *vertices) {
112  VxType::VertexType vt = vtx->vertexType();
113  if ( vt >=0 && vt < nvtypes ) {
114  nvtc[vt]++; // vertex types 0 - 3
115  } else {
116  nvtc[nvtypes-1]++; // unknown
117  }
118  }
119  PV0_count(0) = nvtc[0];
120  PV1_count(0) = nvtc[1];
121  PV2_count(0) = nvtc[2];
122  PV3_count(0) = nvtc[3];
123  PVUnk_count(0) = nvtc[4];
124  } // m_addPVCountsByType
125 
126  // decorate PVs with track counts
127  // (needed if track collection will be thinned)
128  if ( m_addNTracksToPVs ) {
130  for (auto vtx : *vertices) {
131  d_nPVTracks(*vtx) = (int)vtx->nTrackParticles();
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  for (auto vtx : *vertices) {
140  float sqrtPt2Sum(0.);
141  for (auto tp : vtx->trackParticleLinks()) {
142  sqrtPt2Sum += std::sqrt(pow((*tp)->pt(),2));
143  }
144  d_pvSqrtPt2Sum(*vtx) = sqrtPt2Sum;
145  }
146  } // m_addSqrtPt2SumToPVs
147  }
148 
152  track_count(0) = tracks->size();
153  }
157  track_count(0) = tracks->size();
158  }
159 
160  return StatusCode::SUCCESS;
161  }
162 }
DerivationFramework::AugOriginalCounts::m_PVContainername
SG::ReadHandleKey< xAOD::VertexContainer > m_PVContainername
Definition: AugOriginalCounts.h:85
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::AugOriginalCounts::m_OrigPVNTracks
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigPVNTracks
Definition: AugOriginalCounts.h:72
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
DerivationFramework::AugOriginalCounts::m_OrigNtype1
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype1
Definition: AugOriginalCounts.h:76
xAOD::VxType::VertexType
VertexType
Vertex types.
Definition: TrackingPrimitives.h:569
DerivationFramework::AugOriginalCounts::initialize
virtual StatusCode initialize() override
Definition: AugOriginalCounts.cxx:37
DerivationFramework::AugOriginalCounts::m_addNTracksToPVs
bool m_addNTracksToPVs
Definition: AugOriginalCounts.h:87
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
DerivationFramework::AugOriginalCounts::m_OrigNTracksLRTKeys
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNTracksLRTKeys
Definition: AugOriginalCounts.h:74
DerivationFramework::AugOriginalCounts::m_OrigNtypeUnknown
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtypeUnknown
Definition: AugOriginalCounts.h:79
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
DerivationFramework::AugOriginalCounts::m_addPVCountsByType
bool m_addPVCountsByType
Definition: AugOriginalCounts.h:86
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::AugOriginalCounts::m_OrigNtype3
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype3
Definition: AugOriginalCounts.h:78
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DerivationFramework::AugOriginalCounts::addBranches
virtual StatusCode addBranches() const override
Main method called for each event.
Definition: AugOriginalCounts.cxx:90
DerivationFramework::AugOriginalCounts::m_d_nPVTracks
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_d_nPVTracks
Definition: AugOriginalCounts.h:82
DerivationFramework::AugOriginalCounts::m_addSqrtPt2SumToPVs
bool m_addSqrtPt2SumToPVs
Definition: AugOriginalCounts.h:88
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DerivationFramework::AugOriginalCounts::m_OrigNTracksKeys
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNTracksKeys
Definition: AugOriginalCounts.h:73
DerivationFramework::AugOriginalCounts::m_OrigNtype2
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype2
Definition: AugOriginalCounts.h:77
DerivationFramework::AugOriginalCounts::m_OrigNtype0
SG::WriteDecorHandleKey< xAOD::EventInfo > m_OrigNtype0
Definition: AugOriginalCounts.h:75
AugOriginalCounts.h
Augmentation with primary vertex counts (before thinning)
validateBDTTau.vt
vt
Definition: validateBDTTau.py:43
DerivationFramework::AugOriginalCounts::m_TrackContainerLRTname
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainerLRTname
Definition: AugOriginalCounts.h:84
DerivationFramework::AugOriginalCounts::m_OrigSqrtPt2Sum
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_OrigSqrtPt2Sum
Definition: AugOriginalCounts.h:81
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
DerivationFramework::AugOriginalCounts::m_TrackContainername
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainername
Definition: AugOriginalCounts.h:83
AthAlgTool
Definition: AthAlgTool.h:26
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.