ATLAS Offline Software
DStarSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //==================================================
6 // Selection of D*+ -> pi+ + D0
7 //==================================================
8 
12 #include "GaudiKernel/ThreadLocalContext.h"
13 #include "Gaudi/Property.h"
14 
17 
18 namespace{
19  static const SG::AuxElement::ConstAccessor<Char_t> flag_D0("passed_D0");
20  static const SG::AuxElement::ConstAccessor<Char_t> flag_D0b("passed_D0b");
21  static const SG::Accessor<std::vector<float>> acc_reFit_Px("RefTrackPx");
22  static const SG::Accessor<std::vector<float>> acc_reFit_Py("RefTrackPy");
23  static const SG::Accessor<std::vector<float>> acc_reFit_Pz("RefTrackPz");
24 }
25 
26 
27 namespace DerivationFramework {
28 
30  ATH_MSG_DEBUG("in initialize()");
32  ATH_CHECK(m_inputVtxContainerName.initialize());
34  ATH_CHECK(m_vertexDecoKey.initialize());
35  return StatusCode::SUCCESS;
36 
37 }
38 
40  const EventContext& ctx = Gaudi::Hive::currentContext();
41 
42  // Track container
43  const xAOD::TrackParticleContainer* trackParticleContainer{nullptr};
44  ATH_CHECK(SG::get(trackParticleContainer, m_trackKey, ctx));
45 
46  // Vertex container
47  const xAOD::VertexContainer* D0Container{nullptr};
48  ATH_CHECK(SG::get(D0Container, m_inputVtxContainerName, ctx));
49 
50  // Mask for track / vertex skimming
51  std::vector<char> track_pass_map(trackParticleContainer->size());
52  std::vector<char> vertex_pass_map(D0Container->size());
53 
54  // Loop over D0 candidate vertices
55  for(const xAOD::Vertex* vertex: *D0Container) {
56 
57  // Check vertex passes loose D0 cuts defined in python
58 
59  bool passed_D0_or_D0b = (flag_D0(*vertex) || flag_D0b(*vertex));
60 
61  // Only consider vertices which have passed D0 mass window for
62  // matching to soft pion canddiates
63  if(!passed_D0_or_D0b) continue;
64 
65  const xAOD::TrackParticle* track1 = vertex->trackParticle(0);
66  const xAOD::TrackParticle* track2 = vertex->trackParticle(1);
67 
68  if(!track1) { ATH_MSG_WARNING("Could not find track at D0 vertex (index 0)"); continue; }
69  if(!track2) { ATH_MSG_WARNING("Could not find track at D0 vertex (index 1)"); continue; }
70 
71  // Re-fitted D0 track 4-vectors
72 
73  const std::vector<float>& reFit_Px = acc_reFit_Px(*vertex);
74  const std::vector<float>& reFit_Py = acc_reFit_Py(*vertex);
75  const std::vector<float>& reFit_Pz = acc_reFit_Pz(*vertex);
76 
77  TLorentzVector track1_pion, track1_kaon;
78  track1_pion.SetXYZM(reFit_Px.at(0),reFit_Py.at(0),reFit_Pz.at(0),m_pionMass);
79  track1_kaon.SetXYZM(reFit_Px.at(0),reFit_Py.at(0),reFit_Pz.at(0),m_kaonMass);
80 
81  TLorentzVector track2_pion, track2_kaon;
82  track2_pion.SetXYZM(reFit_Px.at(1),reFit_Py.at(1),reFit_Pz.at(1),m_pionMass);
83  track2_kaon.SetXYZM(reFit_Px.at(1),reFit_Py.at(1),reFit_Pz.at(1),m_kaonMass);
84 
85  // Consider both D0 and D0bar hypotheses (irrespective of charges)
86  TLorentzVector D0_hypo1 = track1_pion + track2_kaon;
87  TLorentzVector D0_hypo2 = track1_kaon + track2_pion;
88 
89  bool passed_Dstar = false;
90 
91  // Loop over tracks
92  for(const xAOD::TrackParticle* track3: *trackParticleContainer) {
93 
94  // Avoid duplicates
95  if( track1->index() == track3->index() ) continue;
96  if( track2->index() == track3->index() ) continue;
97 
98  TLorentzVector track3_pion= track3->p4();
99 
100  const double deltaM_hypo1 = (D0_hypo1 + track3_pion).M() - D0_hypo1.M();
101  const double deltaM_hypo2 = (D0_hypo2 + track3_pion).M() - D0_hypo2.M();
102 
103  // Selection of loose D*+ ->pi+ + D0 candidates based on mass difference
104  // Keep both "right" and "wrong" charge combinations
105  if( deltaM_hypo1 < m_deltaMassMax || deltaM_hypo2 < m_deltaMassMax ) {
106 
107  passed_Dstar = true;
108 
109  // Mark all tracks as being part of a D*+ -> D0 + pi+ (+c.c.) candidate
110  track_pass_map[track1->index()] = true;
111  track_pass_map[track2->index()] = true;
112  track_pass_map[track3->index()] = true;
113 
114  }
115 
116  } // Loop over tracks
117 
118  // Adjust mask if we'd like to retain this vertex
119  if(passed_Dstar) {
120  vertex_pass_map[vertex->index()] = true;
121  }
122 
123  } // Loop over D0 candidate vertices
124 
125  // Decorate tracks with skim decision flag
126 
128  // Loop over tracks
129  for(const xAOD::TrackParticle* track:*trackParticleContainer) {
130 
131  flagTrackPass(*track) = track_pass_map[track->index()] ; // Mark track to keep/drop during skimming
132 
133  } // Loop over tracks
134 
135  // Decorate vertex for skimming decision (Char used for compatability for BPhys skim/slim tools)
137 
138  // Loop over D0 candidate vertices
139  for(const xAOD::Vertex* vertex: *D0Container) {
140 
141  // Mark vertex to keep during skimming, based on earlier decision
142  flagVertexPass(*vertex) = vertex_pass_map[vertex->index()];
143 
144  } // Loop over D0 candidate vertices
145 
146  return StatusCode::SUCCESS;
147 }
148 
149 
150 
151 }
DerivationFramework::DStarSelectionTool::m_deltaMassMax
Gaudi::Property< double > m_deltaMassMax
Definition: DStarSelectionTool.h:44
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
DerivationFramework::DStarSelectionTool::initialize
StatusCode initialize() override
Definition: DStarSelectionTool.cxx:29
DerivationFramework::DStarSelectionTool::m_trackKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackKey
Definition: DStarSelectionTool.h:45
DerivationFramework::DStarSelectionTool::m_inputVtxContainerName
SG::ReadHandleKey< xAOD::VertexContainer > m_inputVtxContainerName
Definition: DStarSelectionTool.h:43
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
WriteDecorHandle.h
Handle class for adding a decoration to an object.
DerivationFramework::DStarSelectionTool::m_kaonMass
const double m_kaonMass
Definition: DStarSelectionTool.h:50
DerivationFramework::DStarSelectionTool::m_trackDecoKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_trackDecoKey
Definition: DStarSelectionTool.h:46
ReadHandle.h
Handle class for reading from StoreGate.
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
DerivationFramework::DStarSelectionTool::addBranches
virtual StatusCode addBranches() const override
Definition: DStarSelectionTool.cxx:39
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.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DStarSelectionTool.h
DerivationFramework::DStarSelectionTool::m_pionMass
const double m_pionMass
Definition: DStarSelectionTool.h:49
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TrackParticleContainer.h
DerivationFramework::DStarSelectionTool::m_vertexDecoKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_vertexDecoKey
Definition: DStarSelectionTool.h:47