ATLAS Offline Software
Reco_4mu.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // Reco_4mu.cxx
8 // Author: James Catmore <james.catmore@cern.ch>
9 
17 
18 namespace DerivationFramework {
19 
20  Reco_4mu::Reco_4mu(const std::string& t,
21  const std::string& n,
22  const IInterface* p) :
23  AthAlgTool(t,n,p),
24  m_v0Tools("Trk::V0Tools"),
25  m_fourMuonTool("DerivationFramework::FourMuonTool",this),
26  m_pvRefitter("Analysis::PrimaryVertexRefitter",this)
27  {
28  declareInterface<DerivationFramework::IAugmentationTool>(this);
29 
30  // Declare tools
31  declareProperty("V0Tools" , m_v0Tools);
32  declareProperty("FourMuonTool", m_fourMuonTool);
33  declareProperty("PVRefitter", m_pvRefitter);
34 
35  // Declare user-defined properties
36  declareProperty("PairContainerName" , m_pairName = "Pairs");
37  declareProperty("QuadrupletContainerName", m_quadName = "Quadruplets");
38  declareProperty("PVContainerName" , m_pvContainerName = "PrimaryVertices");
39  declareProperty("RefPVContainerName" , m_refPVContainerName = "RefittedPrimaryVertices");
40  declareProperty("RefitPV" , m_refitPV = false);
41  declareProperty("MaxPVrefit" , m_PV_max = 1);
42  declareProperty("DoVertexType" , m_DoVertexType = 1);
43  }
44 
45  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
46 
48  {
49 
50  ATH_MSG_DEBUG("in initialize()");
51 
52  // retrieve V0 tools
53  CHECK( m_v0Tools.retrieve() );
54 
55  // get the JpsiFinder tool
56  CHECK( m_fourMuonTool.retrieve() );
57 
58  // get the PrimaryVertexRefitter tool
59  CHECK( m_pvRefitter.retrieve() );
60 
61  return StatusCode::SUCCESS;
62 
63  }
64 
65  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
66 
68  {
69  // everything all right
70  return StatusCode::SUCCESS;
71  }
72 
73  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
74 
76  {
77  // Output containers and its auxilliary store
78  xAOD::VertexContainer* pairContainer = NULL;
79  xAOD::VertexAuxContainer* pairAuxContainer = NULL;
80  xAOD::VertexContainer* quadContainer = NULL;
81  xAOD::VertexAuxContainer* quadAuxContainer = NULL;
82  bool acceptEvent = false; // this is a dummy
83  //----------------------------------------------------
84  // call finder
85  //----------------------------------------------------
86  if( !m_fourMuonTool->performSearch(pairContainer, pairAuxContainer, quadContainer, quadAuxContainer, acceptEvent).isSuccess() ) {
87  ATH_MSG_FATAL("4mu tool (" << m_fourMuonTool << ") failed.");
88  return StatusCode::FAILURE;
89  }
90 
91  //----------------------------------------------------
92  // event selection
93  //----------------------------------------------------
94  /*if (quadContainer->size()==0) {
95  if (pairContainer!=NULL) delete pairContainer;
96  if (pairAuxContainer!=NULL) delete pairAuxContainer;
97  if (quadContainer!=NULL) delete quadContainer;
98  if (quadAuxContainer!=NULL) delete quadAuxContainer;
99  return(acceptEvent);
100  // acceptEvent based on muon selection only, not quads
101  }*/
102 
103  //----------------------------------------------------
104  // retrieve primary vertices
105  //----------------------------------------------------
106  const xAOD::VertexContainer* pvContainer = NULL;
107  auto sc = evtStore()->retrieve(pvContainer, m_pvContainerName);
108  if(sc.isFailure()){
109  ATH_MSG_FATAL("Cannot find PV Container");
110  return StatusCode::FAILURE;
111  }
112  //----------------------------------------------------
113  // Refit primary vertices
114  //----------------------------------------------------
115  xAOD::VertexContainer* refPvContainer = NULL;
116  xAOD::VertexAuxContainer* refPvAuxContainer = NULL;
117 
118  if(m_refitPV) {
119  refPvContainer = new xAOD::VertexContainer;
120  refPvAuxContainer = new xAOD::VertexAuxContainer;
121  refPvContainer->setStore(refPvAuxContainer);
122  }
123 
124  BPhysPVTools helper(&(*m_v0Tools));//Give the helper class the ptr to v0tools to use
125 
126  if(m_refitPV){
127  if(quadContainer->size() >0){
128  StatusCode SC = helper.FillCandwithRefittedVertices(quadContainer, pvContainer, refPvContainer, &(*m_pvRefitter) , m_PV_max, m_DoVertexType);
129  if(SC.isFailure()){
130  ATH_MSG_FATAL("refitting failed - check the vertices you passed");
131  return StatusCode::FAILURE;
132  }
133  }
134  if(pairContainer->size()>0) {
135  StatusCode SC = helper.FillCandwithRefittedVertices(pairContainer, pvContainer, refPvContainer, &(*m_pvRefitter) , m_PV_max, m_DoVertexType);
136  if(SC.isFailure()){
137  ATH_MSG_FATAL("refitting failed - check the vertices you passed");
138  return StatusCode::FAILURE;
139  }
140  }
141  }else{
142  if(quadContainer->size() >0){
143  auto sc = helper.FillCandExistingVertices(quadContainer, pvContainer, m_DoVertexType);
144  sc.ignore();
145  }
146  if(pairContainer->size() >0)
147  {
148  auto sc = helper.FillCandExistingVertices(pairContainer, pvContainer, m_DoVertexType);
149  sc.ignore();
150  }
151  }
152 
153  //----------------------------------------------------
154  // Mass-hypothesis dependent quantities
155  //----------------------------------------------------
156 
157  std::vector<double> muonPairMasses = std::vector<double>(2, 105.658);
158  std::vector<double> muonQuadMasses = std::vector<double>(4, 105.658);
159 
160  bool doPt = (m_DoVertexType & 1) != 0;
161  bool doA0 = (m_DoVertexType & 2) != 0;
162  bool doZ0 = (m_DoVertexType & 4) != 0;
163  bool doZ0BA = (m_DoVertexType & 8) != 0;
164 
165  // loop over pairs
166  xAOD::VertexContainer::iterator pairItr = pairContainer->begin();
167  ATH_MSG_DEBUG("Indices/masses of pairs follows....");
168  for(; pairItr!=pairContainer->end(); ++pairItr) {
169  // create BPhysHypoHelper
170  xAOD::BPhysHypoHelper pairHelper("PAIR", *pairItr);
171 
172  //----------------------------------------------------
173  // decorate the vertex
174  //----------------------------------------------------
175  // a) invariant mass and error
176  if( !pairHelper.setMass(muonPairMasses) ) ATH_MSG_WARNING("Decoration pair.setMass failed");
177 
178  double massErr = m_v0Tools->invariantMassError(pairHelper.vtx(), muonPairMasses);
179  if( !pairHelper.setMassErr(massErr) ) ATH_MSG_WARNING("Decoration pair.setMassErr failed");
180 
181  // b) proper decay time and error:
182  // retrieve the refitted PV (or the original one, if the PV refitting was turned off)
183  if(doPt) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MAX_SUM_PT2, muonPairMasses);
184  if(doA0) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MIN_A0, muonPairMasses);
185  if(doZ0) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MIN_Z0, muonPairMasses);
186  if(doZ0BA) ProcessVertex(pairHelper, xAOD::BPhysHelper::PV_MIN_Z0_BA, muonPairMasses);
187  static const SG::ConstAccessor<std::string> CombinationCodeAcc("CombinationCode");
188  ATH_MSG_DEBUG(CombinationCodeAcc(**pairItr) << " : " << pairHelper.mass() << " +/- " << pairHelper.massErr());
189  }
190 
191  // loop over quadruplets
192  xAOD::VertexContainer::iterator quadItr = quadContainer->begin();
193  ATH_MSG_DEBUG("Indices/masses of quadruplets follows....");
194  for(; quadItr!=quadContainer->end(); ++quadItr) {
195  // create BPhysHypoHelper
196  xAOD::BPhysHypoHelper quadHelper("QUAD", *quadItr);
197 
198  //----------------------------------------------------
199  // decorate the vertex
200  //----------------------------------------------------
201  // a) invariant mass and error
202  if( !quadHelper.setMass(muonQuadMasses) ) ATH_MSG_WARNING("Decoration quad.setMass failed");
203 
204  double massErr = m_v0Tools->invariantMassError(quadHelper.vtx(), muonQuadMasses);
205  if( !quadHelper.setMassErr(massErr) ) ATH_MSG_WARNING("Decoration quad.setMassErr failed");
206 
207  // b) proper decay time and error:
208  // retrieve the refitted PV (or the original one, if the PV refitting was turned off)
209  if(doPt) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MAX_SUM_PT2, muonQuadMasses);
210  if(doA0) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MIN_A0, muonQuadMasses);
211  if(doZ0) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MIN_Z0, muonQuadMasses);
212  if(doZ0BA) ProcessVertex(quadHelper, xAOD::BPhysHelper::PV_MIN_Z0_BA, muonQuadMasses);
213  static const SG::ConstAccessor<std::string> CombinationCodeAcc("CombinationCode");
214  ATH_MSG_DEBUG(CombinationCodeAcc(**quadItr) << " : " << quadHelper.mass() << " +/- " << quadHelper.massErr());
215  }
216 
217  //----------------------------------------------------
218  // save in the StoreGate
219  //----------------------------------------------------
220  // Pairs
221  if (!evtStore()->contains<xAOD::VertexContainer>(m_pairName))
222  evtStore()->record(pairContainer, m_pairName).ignore();
223  if (!evtStore()->contains<xAOD::VertexAuxContainer>(m_pairName+"Aux."))
224  evtStore()->record(pairAuxContainer, m_pairName+"Aux.").ignore();
225 
226  // Quads
227  if (!evtStore()->contains<xAOD::VertexContainer>(m_quadName))
228  evtStore()->record(quadContainer, m_quadName).ignore();
229  if (!evtStore()->contains<xAOD::VertexAuxContainer>(m_quadName+"Aux."))
230  evtStore()->record(quadAuxContainer, m_quadName+"Aux.").ignore();
231 
232  // Refitted PVs
233  if(m_refitPV) {
234  evtStore()->record(refPvContainer , m_refPVContainerName).ignore();
235  evtStore()->record(refPvAuxContainer, m_refPVContainerName+"Aux.").ignore();
236  }
237 
238  return StatusCode::SUCCESS;
239  }
240 
241 
242  void Reco_4mu::ProcessVertex(xAOD::BPhysHypoHelper &hypoHelper, xAOD::BPhysHelper::pv_type pv_t, std::vector<double> trackMasses) const{
243 
244  const xAOD::Vertex* pv = hypoHelper.pv(pv_t);
245  if(pv) {
246  // decorate the vertex.
247 
248  BPHYS_CHECK( hypoHelper.setTau( m_v0Tools->tau(hypoHelper.vtx(), pv, trackMasses),
249  pv_t,
251 
252  BPHYS_CHECK( hypoHelper.setTauErr( m_v0Tools->tauError(hypoHelper.vtx(), pv, trackMasses),
253  pv_t,
255 
256  //enum pv_type {PV_MAX_SUM_PT2, PV_MIN_A0, PV_MIN_Z0, PV_MIN_Z0BA};
257  }else{
258 
259  const float errConst = -9999999;
260  BPHYS_CHECK( hypoHelper.setTau( errConst,
261  pv_t,
263 
264  BPHYS_CHECK( hypoHelper.setTauErr( errConst,
265  pv_t,
267  }
268 
269  return;
270  }
271 
272 }
BPhysPVTools.h
xAOD::BPhysHypoHelper::setMass
bool setMass(const float val)
Set given invariant mass and its error.
Definition: BPhysHypoHelper.cxx:49
V0Tools.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DerivationFramework::Reco_4mu::m_DoVertexType
int m_DoVertexType
Definition: Reco_4mu.h:59
xAOD::VertexAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: VertexAuxContainer_v1.h:32
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
xAOD::BPhysHypoHelper::setTauErr
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
Definition: BPhysHypoHelper.cxx:176
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::Reco_4mu::m_pvContainerName
std::string m_pvContainerName
Definition: Reco_4mu.h:55
DerivationFramework::Reco_4mu::ProcessVertex
void ProcessVertex(xAOD::BPhysHypoHelper &, xAOD::BPhysHelper::pv_type, std::vector< double > trackMasses) const
tools
Definition: Reco_4mu.cxx:242
DerivationFramework::BPhysPVTools
Definition: BPhysPVTools.h:25
DerivationFramework::Reco_4mu::finalize
StatusCode finalize()
Definition: Reco_4mu.cxx:67
xAOD::BPhysHelper::PV_MIN_Z0
@ PV_MIN_Z0
Definition: BPhysHelper.h:475
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::VertexContainer
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Definition: VertexContainer.h:14
xAOD::BPhysHypoHelper::massErr
float massErr() const
invariant mass error
Definition: BPhysHypoHelper.cxx:44
xAOD::BPhysHypoHelper::TAU_INV_MASS
@ TAU_INV_MASS
Definition: BPhysHypoHelper.h:137
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
DerivationFramework::Reco_4mu::m_pvRefitter
ToolHandle< Analysis::PrimaryVertexRefitter > m_pvRefitter
Definition: Reco_4mu.h:49
DerivationFramework::Reco_4mu::m_PV_max
int m_PV_max
Definition: Reco_4mu.h:58
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
xAOD::BPhysHypoHelper
Definition: BPhysHypoHelper.h:73
BPHYS_CHECK
#define BPHYS_CHECK(EXP)
Useful CHECK macro.
Definition: BPhysHelper.h:738
xAOD::BPhysHypoHelper::mass
float mass() const
Get invariant mass and its error.
Definition: BPhysHypoHelper.cxx:39
DerivationFramework::Reco_4mu::m_pairName
std::string m_pairName
job options
Definition: Reco_4mu.h:53
DerivationFramework::Reco_4mu::m_v0Tools
ToolHandle< Trk::V0Tools > m_v0Tools
Definition: Reco_4mu.h:47
xAOD::BPhysHelper::pv_type
pv_type
: Enum type of the PV
Definition: BPhysHelper.h:475
DerivationFramework::Reco_4mu::m_quadName
std::string m_quadName
Definition: Reco_4mu.h:54
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
xAOD::VertexAuxContainer
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
Definition: VertexAuxContainer.h:19
beamspotman.n
n
Definition: beamspotman.py:731
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
BPhysHypoHelper.h
: B-physcis xAOD helpers.
xAOD::BPhysHelper::PV_MIN_A0
@ PV_MIN_A0
Definition: BPhysHelper.h:475
TRT_PAI_gasdata::SC
const float SC[NC]
Cross sections for Carbon.
Definition: TRT_PAI_gasdata.h:255
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework::Reco_4mu::m_refPVContainerName
std::string m_refPVContainerName
Definition: Reco_4mu.h:56
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
Reco_4mu.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DerivationFramework::Reco_4mu::m_fourMuonTool
ToolHandle< DerivationFramework::FourMuonTool > m_fourMuonTool
Definition: Reco_4mu.h:48
xAOD::BPhysHelper::vtx
const xAOD::Vertex * vtx() const
Getter method for the cached xAOD::Vertex.
Definition: BPhysHelper.h:108
xAOD::BPhysHelper::PV_MAX_SUM_PT2
@ PV_MAX_SUM_PT2
Definition: BPhysHelper.h:475
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DerivationFramework::Reco_4mu::Reco_4mu
Reco_4mu(const std::string &t, const std::string &n, const IInterface *p)
Definition: Reco_4mu.cxx:20
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::Reco_4mu::m_refitPV
bool m_refitPV
Definition: Reco_4mu.h:57
python.changerun.pv
pv
Definition: changerun.py:81
xAOD::BPhysHelper::pv
const xAOD::Vertex * pv(const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Get the refitted collision vertex of type pv_type.
Definition: BPhysHelper.cxx:796
DerivationFramework::Reco_4mu::initialize
StatusCode initialize()
Definition: Reco_4mu.cxx:47
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::BPhysHypoHelper::setTau
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.
Definition: BPhysHypoHelper.cxx:140
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::BPhysHelper::PV_MIN_Z0_BA
@ PV_MIN_Z0_BA
Definition: BPhysHelper.h:475
xAOD::BPhysHypoHelper::setMassErr
bool setMassErr(const float val)
invariant mass error
Definition: BPhysHypoHelper.cxx:54
DerivationFramework::Reco_4mu::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: Reco_4mu.cxx:75
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
VertexAuxContainer.h