ATLAS Offline Software
Loading...
Searching...
No Matches
Reco_4mu.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Reco_4mu.cxx
8// Author: James Catmore <james.catmore@cern.ch>
9
10#include "Reco_4mu.h"
14#include "BPhysPVTools.h"
18
19namespace DerivationFramework {
20
21 Reco_4mu::Reco_4mu(const std::string& t,
22 const std::string& n,
23 const IInterface* p) :
24 base_class(t,n,p)
25 {
26 }
27
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
29
31 {
32
33 ATH_MSG_DEBUG("in initialize()");
34 ATH_CHECK(m_pvContainerName.initialize());
35 ATH_CHECK(m_refPVContainerName.initialize());
36 ATH_CHECK(m_pairName.initialize());
37 ATH_CHECK(m_quadName.initialize());
38 // retrieve V0 tools
39 ATH_CHECK( m_v0Tools.retrieve() );
40
41 // get the JpsiFinder tool
42 ATH_CHECK( m_fourMuonTool.retrieve() );
43
44 // get the PrimaryVertexRefitter tool
45 ATH_CHECK( m_pvRefitter.retrieve() );
46
47 return StatusCode::SUCCESS;
48
49 }
50
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
52
53 StatusCode Reco_4mu::addBranches(const EventContext & ctx) const
54 {
55 // Output containers and its auxilliary store
57 ATH_CHECK(pairContainer.record(std::make_unique<xAOD::VertexContainer>(), std::make_unique<xAOD::VertexAuxContainer>()));
59 ATH_CHECK(quadContainer.record(std::make_unique<xAOD::VertexContainer>(), std::make_unique<xAOD::VertexAuxContainer>()));
60 bool acceptEvent = false; // this is a dummy
61 //----------------------------------------------------
62 // call finder
63 //----------------------------------------------------
64 if( !m_fourMuonTool->performSearch(pairContainer.ptr(), quadContainer.ptr(), acceptEvent, ctx).isSuccess() ) {
65 ATH_MSG_FATAL("4mu tool (" << m_fourMuonTool << ") failed.");
66 return StatusCode::FAILURE;
67 }
68
69 //----------------------------------------------------
70 // retrieve primary vertices
71 //----------------------------------------------------
73 ATH_CHECK(pvContainer.isValid());
74 //----------------------------------------------------
75 // Refit primary vertices
76 //----------------------------------------------------
78 if (m_refitPV) {
79 // refitted PV container does not exist. Create a new one.
80 refPvContainer = SG::makeHandle(m_refPVContainerName, ctx);
81 ATH_CHECK(refPvContainer.record(std::make_unique<xAOD::VertexContainer>(), std::make_unique<xAOD::VertexAuxContainer>()));
82 }
83
84 BPhysPVTools helper(&(*m_v0Tools));//Give the helper class the ptr to v0tools to use
85
86 if (m_refitPV) {
87 if (quadContainer->size() >0) {
88 if (helper.FillCandwithRefittedVertices(quadContainer.ptr(), pvContainer.cptr(), refPvContainer.ptr(), &(*m_pvRefitter) , m_PV_max, m_DoVertexType).isFailure()){
89 ATH_MSG_FATAL("refitting failed - check the vertices you passed");
90 return StatusCode::FAILURE;
91 }
92 }
93 if (pairContainer->size()>0) {
94 if (helper.FillCandwithRefittedVertices(pairContainer.ptr(), pvContainer.cptr(), refPvContainer.ptr(), &(*m_pvRefitter) , m_PV_max, m_DoVertexType).isFailure()){
95 ATH_MSG_FATAL("refitting failed - check the vertices you passed");
96 return StatusCode::FAILURE;
97 }
98 }
99 } else {
100 if (quadContainer->size() >0) {
101 auto sc = helper.FillCandExistingVertices(quadContainer.ptr(), pvContainer.cptr(), m_DoVertexType);
102 sc.ignore();
103 }
104 if (pairContainer->size() >0) {
105 auto sc = helper.FillCandExistingVertices(pairContainer.ptr(), pvContainer.cptr(), m_DoVertexType);
106 sc.ignore();
107 }
108 }
109
110 //----------------------------------------------------
111 // Mass-hypothesis dependent quantities
112 //----------------------------------------------------
113
114 std::vector<double> muonPairMasses = std::vector<double>(2, ParticleConstants::muonMassInMeV);
115 std::vector<double> muonQuadMasses = std::vector<double>(4, ParticleConstants::muonMassInMeV);
116
117 bool doPt = (m_DoVertexType & 1) != 0;
118 bool doA0 = (m_DoVertexType & 2) != 0;
119 bool doZ0 = (m_DoVertexType & 4) != 0;
120 bool doZ0BA = (m_DoVertexType & 8) != 0;
121
122 // loop over pairs
123 ATH_MSG_DEBUG("Indices/masses of pairs follows....");
124 for(xAOD::Vertex* pairVtx : *pairContainer) {
125 // create BPhysHypoHelper
126 xAOD::BPhysHypoHelper pairHelper("PAIR", pairVtx);
127
128 //----------------------------------------------------
129 // decorate the vertex
130 //----------------------------------------------------
131 // a) invariant mass and error
132 if( !pairHelper.setMass(muonPairMasses) ) ATH_MSG_WARNING("Decoration pair.setMass failed");
133
134 double massErr = m_v0Tools->invariantMassError(pairHelper.vtx(), muonPairMasses);
135 if( !pairHelper.setMassErr(massErr) ) ATH_MSG_WARNING("Decoration pair.setMassErr failed");
136
137 // b) proper decay time and error:
138 // retrieve the refitted PV (or the original one, if the PV refitting was turned off)
139 if(doPt) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MAX_SUM_PT2, muonPairMasses);
140 if(doA0) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MIN_A0, muonPairMasses);
141 if(doZ0) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MIN_Z0, muonPairMasses);
142 if(doZ0BA) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MIN_Z0_BA, muonPairMasses);
143 static const SG::ConstAccessor<std::string> CombinationCodeAcc("CombinationCode");
144 ATH_MSG_DEBUG(CombinationCodeAcc(*pairVtx) << " : " << pairHelper.mass() << " +/- " << pairHelper.massErr());
145 }
146
147 // loop over quadruplets
148 ATH_MSG_DEBUG("Indices/masses of quadruplets follows....");
149 for (xAOD::Vertex* quadVtx: *quadContainer) {
150 // create BPhysHypoHelper
151 xAOD::BPhysHypoHelper quadHelper("QUAD", quadVtx);
152
153 //----------------------------------------------------
154 // decorate the vertex
155 //----------------------------------------------------
156 // a) invariant mass and error
157 if( !quadHelper.setMass(muonQuadMasses) ) ATH_MSG_WARNING("Decoration quad.setMass failed");
158
159 double massErr = m_v0Tools->invariantMassError(quadHelper.vtx(), muonQuadMasses);
160 if( !quadHelper.setMassErr(massErr) ) ATH_MSG_WARNING("Decoration quad.setMassErr failed");
161
162 // b) proper decay time and error:
163 // retrieve the refitted PV (or the original one, if the PV refitting was turned off)
164 if(doPt) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MAX_SUM_PT2, muonQuadMasses);
165 if(doA0) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MIN_A0, muonQuadMasses);
166 if(doZ0) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MIN_Z0, muonQuadMasses);
167 if(doZ0BA) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MIN_Z0_BA, muonQuadMasses);
168 static const SG::ConstAccessor<std::string> CombinationCodeAcc("CombinationCode");
169 ATH_MSG_DEBUG(CombinationCodeAcc(*quadVtx) << " : " << quadHelper.mass() << " +/- " << quadHelper.massErr());
170 }
171
172 return StatusCode::SUCCESS;
173 }
174
175
176 void Reco_4mu::ProcessVertex(xAOD::BPhysHypoHelper &hypoHelper, xAOD::BPhysHelper::pv_type pv_t, std::vector<double> trackMasses) const{
177
178 const xAOD::Vertex* pv = hypoHelper.pv(pv_t);
179 if(pv) {
180 // decorate the vertex.
181
182 BPHYS_CHECK( hypoHelper.setTau( m_v0Tools->tau(hypoHelper.vtx(), pv, trackMasses),
183 pv_t,
185
186 BPHYS_CHECK( hypoHelper.setTauErr( m_v0Tools->tauError(hypoHelper.vtx(), pv, trackMasses),
187 pv_t,
189
190 //enum pv_type {PV_MAX_SUM_PT2, PV_MIN_A0, PV_MIN_Z0, PV_MIN_Z0BA};
191 }else{
192
193 const float errConst = -9999999;
194 BPHYS_CHECK( hypoHelper.setTau( errConst,
195 pv_t,
197
198 BPHYS_CHECK( hypoHelper.setTauErr( errConst,
199 pv_t,
201 }
202
203 return;
204 }
205
206}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define BPHYS_CHECK(EXP)
Useful CHECK macro.
: B-physics xAOD helpers.
Helper class to provide constant type-safe access to aux data.
static Double_t sc
A number of constexpr particle constants to avoid hardcoding them directly in various places.
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition Reco_4mu.cxx:53
ToolHandle< DerivationFramework::FourMuonTool > m_fourMuonTool
Definition Reco_4mu.h:47
Gaudi::Property< bool > m_refitPV
Definition Reco_4mu.h:56
ToolHandle< Analysis::PrimaryVertexRefitter > m_pvRefitter
Definition Reco_4mu.h:48
Reco_4mu(const std::string &t, const std::string &n, const IInterface *p)
Definition Reco_4mu.cxx:21
SG::WriteHandleKey< xAOD::VertexContainer > m_pairName
job options
Definition Reco_4mu.h:52
PublicToolHandle< Trk::V0Tools > m_v0Tools
Definition Reco_4mu.h:46
SG::ReadHandleKey< xAOD::VertexContainer > m_pvContainerName
Definition Reco_4mu.h:54
Gaudi::Property< int > m_PV_max
Definition Reco_4mu.h:57
SG::WriteHandleKey< xAOD::VertexContainer > m_refPVContainerName
Definition Reco_4mu.h:55
Gaudi::Property< int > m_DoVertexType
Definition Reco_4mu.h:58
virtual StatusCode initialize() override final
Definition Reco_4mu.cxx:30
void ProcessVertex(xAOD::BPhysHypoHelper &, xAOD::BPhysHelper::pv_type, std::vector< double > trackMasses) const
tools
Definition Reco_4mu.cxx:176
SG::WriteHandleKey< xAOD::VertexContainer > m_quadName
Definition Reco_4mu.h:53
Helper class to provide constant type-safe access to aux data.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
const xAOD::Vertex * vtx() const
Getter method for the cached xAOD::Vertex.
const xAOD::Vertex * pv(const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Get the refitted collision vertex of type pv_type.
pv_type
: Enum type of the PV
float mass() const
Get invariant mass and its error.
bool setMass(const float val)
Set given invariant mass and its error.
float massErr() const
invariant mass error
bool setTau(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0, const tau_type tauType=BPhysHypoHelper::TAU_CONST_MASS)
: Set the proper decay time and error.
bool setMassErr(const float val)
invariant mass error
bool setTauErr(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0, const tau_type tauType=BPhysHypoHelper::TAU_CONST_MASS)
proper decay time error
THE reconstruction tool.
constexpr double muonMassInMeV
the mass of the muon (in MeV)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Vertex_v1 Vertex
Define the latest version of the vertex class.