ATLAS Offline Software
InDetSecVtxTrackCut.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 //Author: Lianyou Shan <lianyou.shan@cern.ch>
5 // -*- c++ -*-
6 // InDetSecVtxTrackCut.h
7 // Declarations of objects to perform cuts for InDetTrackSelectionTool
8 
9 #ifndef INDETSECVTXTRACKSELECTIONTOOL_INDETTRACKCUT_H
10 #define INDETSECVTXTRACKSELECTIONTOOL_INDETTRACKCUT_H
11 
13 //#include "InDetSecVtxTrackSelectionTool/InDetSecVtxTrackSelectionTool.h"
14 
15 #include <map>
16 #include <array>
17 
18 namespace InDet {
19 
20 // class InDetTrackSelectionTool;
21  class InDetSecVtxTrackSelectionTool;
22 
23  // ---------------- SecVtxTrackCut ----------------
24 
26  // abstract interface class for all cuts.
27  public:
29  virtual ~SecVtxTrackCut() = 0;
30  // initialize should find the accessor(s) or create them if they don't exist
31  virtual StatusCode initialize();
32  virtual bool result() const = 0; // whether the cut passes
33  operator bool() const {return this->result();}
34  protected:
35  // a function that gets the accessor labelled by "name", adding it if it needs to.
36  template <class AccessorType>
37  StatusCode getAccessor(const std::string& name, std::shared_ptr<AccessorType>& accessor);
38  private:
39  // a pointer to the tool's accessors so we can modify it in initialize()
40  std::unordered_map< std::string, std::shared_ptr<SecVtxTrackAccessor> >* m_trackAccessors;
41  // a pointer to the tool so that we can create the accessors when need be, as they inherit from AsgMessaging and need a pointer to the tool
43  }; // class SecVtxTrackCut
44 
45 class D0minCut : public virtual SecVtxTrackCut {
46  public:
48  void setMinValue(Double_t min) { m_minValue = min;}
49  virtual StatusCode initialize();
50  virtual bool result() const;
51  private:
52  Double_t m_minValue;
53  std::shared_ptr< svParamAccessor<0> > m_paramAccessor;
54  }; // class D0Cut
55 
56  template <size_t N>
57  class FuncSummaryValueCut : public virtual SecVtxTrackCut {
58  public:
59  FuncSummaryValueCut( InDetSecVtxTrackSelectionTool*, const std::array<xAOD::SummaryType,N>&&);
60  void setFunction(std::function<bool(const std::array<uint8_t,N>&)> func) {m_func = func;}
61  virtual StatusCode initialize();
62  virtual bool result() const;
63  private:
64  std::function<bool(const std::array<uint8_t,N>&)> m_func;
65  std::array< xAOD::SummaryType, N> m_summaryTypes;
66  std::array< std::shared_ptr<SummaryAccessor>,N > m_summaryAccessors;
67  }; // class FuncSummaryValueCut
68 
69 } // namespace InDet
70 
71 template <class AccessorType>
72 StatusCode InDet::SecVtxTrackCut::getAccessor(const std::string& accessorName,
73  std::shared_ptr<AccessorType>& accessor)
74 {
75  // this function looks for the accessor indicated by "name" in the tool's
76  // track accessors and assigns "accessor" to it if it exists, creating
77  // the accessor if it does not.
78  std::unordered_map< std::string, std::shared_ptr<SecVtxTrackAccessor> >::const_iterator it =
79  std::find_if(m_trackAccessors->begin(), m_trackAccessors->end(),
80  [&] (std::pair< std::string, std::shared_ptr<SecVtxTrackAccessor> > acc)
81  {return acc.first == accessorName;} );
82  if (it == m_trackAccessors->end()) {
83  // if we can't find the accessor, add one to the tool
84  if (!m_selectionTool) {
85  ATH_MSG_ERROR( "Must initialize SecVtxTrackCut with pointer to the selection tool before adding accessors." );
86  return StatusCode::FAILURE;
87  }
88  accessor = std::make_shared<AccessorType>(m_selectionTool);
89  (*m_trackAccessors)[accessorName] = accessor;
90  ATH_MSG_DEBUG( "Adding accessor " << accessorName );
91  } else {
92  accessor = std::dynamic_pointer_cast<AccessorType>(it->second);
93  if (accessor==nullptr) {
94  ATH_MSG_ERROR( "Logic error: could not cast accessor to type " << typeid(AccessorType).name() );
95  return StatusCode::FAILURE;
96  }
97  }
98 
99  if (!accessor) {
100  // this could happen if the accessor indicated by "name" is not of type "AccessorType"
101  ATH_MSG_ERROR( "Could not instantiate "<< accessorName <<
102  " accessor. Pointer to accessor is to type " <<
103  typeid(AccessorType).name() << ". Is this correct?" );
104  return StatusCode::FAILURE;
105  }
106  return StatusCode::SUCCESS;
107 }
108 
109 
110 #endif // INDETTRACKSELECTIONTOOL_INDETTRACKCUT_H
InDet::FuncSummaryValueCut::m_summaryTypes
std::array< xAOD::SummaryType, N > m_summaryTypes
Definition: InDetSecVtxTrackCut.h:65
InDet::FuncSummaryValueCut::initialize
virtual StatusCode initialize()
Definition: InDetSecVtxTrackCut.cxx:71
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
skel.it
it
Definition: skel.GENtoEVGEN.py:423
InDet::D0minCut
Definition: InDetSecVtxTrackCut.h:45
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
InDet::D0minCut::D0minCut
D0minCut(InDetSecVtxTrackSelectionTool *, Double_t min=-99.)
Definition: InDetSecVtxTrackCut.cxx:38
InDet::FuncSummaryValueCut::FuncSummaryValueCut
FuncSummaryValueCut(InDetSecVtxTrackSelectionTool *, const std::array< xAOD::SummaryType, N > &&)
Definition: InDetSecVtxTrackCut.cxx:64
InDet::SecVtxTrackCut::initialize
virtual StatusCode initialize()
Definition: InDetSecVtxTrackCut.cxx:26
InDet::SecVtxTrackCut::m_selectionTool
InDetSecVtxTrackSelectionTool * m_selectionTool
Definition: InDetSecVtxTrackCut.h:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
InDet::D0minCut::result
virtual bool result() const
Definition: InDetSecVtxTrackCut.cxx:52
InDet::D0minCut::m_paramAccessor
std::shared_ptr< svParamAccessor< 0 > > m_paramAccessor
Definition: InDetSecVtxTrackCut.h:53
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
InDet::SecVtxTrackCut::result
virtual bool result() const =0
InDet::SecVtxTrackCut::SecVtxTrackCut
SecVtxTrackCut(InDetSecVtxTrackSelectionTool *)
Definition: InDetSecVtxTrackCut.cxx:16
InDet::D0minCut::m_minValue
Double_t m_minValue
Definition: InDetSecVtxTrackCut.h:52
InDet::SecVtxTrackCut
Definition: InDetSecVtxTrackCut.h:25
InDet::FuncSummaryValueCut::result
virtual bool result() const
Definition: InDetSecVtxTrackCut.cxx:89
InDet::FuncSummaryValueCut::setFunction
void setFunction(std::function< bool(const std::array< uint8_t, N > &)> func)
Definition: InDetSecVtxTrackCut.h:60
min
#define min(a, b)
Definition: cfImp.cxx:40
InDet::SecVtxTrackCut::m_trackAccessors
std::unordered_map< std::string, std::shared_ptr< SecVtxTrackAccessor > > * m_trackAccessors
Definition: InDetSecVtxTrackCut.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
InDet::D0minCut::setMinValue
void setMinValue(Double_t min)
Definition: InDetSecVtxTrackCut.h:48
InDet::InDetSecVtxTrackSelectionTool
Implementation of the track selector tool.
Definition: InDetSecVtxTrackSelectionTool.h:36
InDet::FuncSummaryValueCut::m_func
std::function< bool(const std::array< uint8_t, N > &)> m_func
Definition: InDetSecVtxTrackCut.h:64
InDet::SecVtxTrackCut::getAccessor
StatusCode getAccessor(const std::string &name, std::shared_ptr< AccessorType > &accessor)
Definition: InDetSecVtxTrackCut.h:72
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
InDet::FuncSummaryValueCut::m_summaryAccessors
std::array< std::shared_ptr< SummaryAccessor >, N > m_summaryAccessors
Definition: InDetSecVtxTrackCut.h:66
InDet::SecVtxTrackCut::~SecVtxTrackCut
virtual ~SecVtxTrackCut()=0
InDet::FuncSummaryValueCut
Definition: InDetSecVtxTrackCut.h:57
InDet::D0minCut::initialize
virtual StatusCode initialize()
Definition: InDetSecVtxTrackCut.cxx:45
InDetSecVtxTrackAccessor.h
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60