ATLAS Offline Software
Loading...
Searching...
No Matches
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
18namespace InDet {
19
20// class InDetTrackSelectionTool;
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
45class 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
71template <class AccessorType>
72StatusCode 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
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define min(a, b)
Definition cfImp.cxx:40
virtual StatusCode initialize()
void setMinValue(Double_t min)
virtual bool result() const
std::shared_ptr< svParamAccessor< 0 > > m_paramAccessor
D0minCut(InDetSecVtxTrackSelectionTool *, Double_t min=-99.)
std::function< bool(const std::array< uint8_t, N > &)> m_func
FuncSummaryValueCut(InDetSecVtxTrackSelectionTool *, const std::array< xAOD::SummaryType, N > &&)
std::array< xAOD::SummaryType, N > m_summaryTypes
void setFunction(std::function< bool(const std::array< uint8_t, N > &)> func)
std::array< std::shared_ptr< SummaryAccessor >, N > m_summaryAccessors
Implementation of the track selector tool.
SecVtxTrackCut(InDetSecVtxTrackSelectionTool *)
std::unordered_map< std::string, std::shared_ptr< SecVtxTrackAccessor > > * m_trackAccessors
StatusCode getAccessor(const std::string &name, std::shared_ptr< AccessorType > &accessor)
virtual ~SecVtxTrackCut()=0
InDetSecVtxTrackSelectionTool * m_selectionTool
virtual StatusCode initialize()
virtual bool result() const =0
Class mimicking the AthMessaging class from the offline software.
Primary Vertex Finder.