ATLAS Offline Software
TrackCountHypoAlg.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TrackCountHypoAlg.h"
6 #include "TrackCountHypoTool.h"
8 #include "AthViews/ViewHelper.h"
10 
23 
24 TrackCountHypoAlg::TrackCountHypoAlg(const std::string &name, ISvcLocator *pSvcLocator) : ::HypoBase(name, pSvcLocator)
25 {
26 }
27 
29 {
31  ATH_CHECK(m_trackCountKey.initialize());
33  ATH_CHECK(m_minPt.size() == m_maxZ0.size());
34 
35  if (m_tracksKey.key() == "Undefined" || m_trackCountKey.key() == "Undefined")
36  {
37  ATH_MSG_ERROR("either track Key name or track count key name is undefined ");
38  return StatusCode::FAILURE;
39  }
40 
41  ATH_CHECK(m_hypoTools.retrieve());
42  if (!m_monTool.empty())
43  ATH_CHECK(m_monTool.retrieve());
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 StatusCode TrackCountHypoAlg::execute(const EventContext &context) const
49 {
50  ATH_MSG_DEBUG("Executing " << name() << "...");
51  auto previousDecisionsHandle = SG::makeHandle(decisionInput(), context);
52 
53  if (not previousDecisionsHandle.isValid())
54  { //implicit
55  ATH_MSG_DEBUG("No implicit RH for previous decisions " << decisionInput().key() << ": is this expected?");
56  return StatusCode::SUCCESS;
57  }
58 
59  if (previousDecisionsHandle->size() == 0)
60  {
61  ATH_MSG_DEBUG("No previous decision, nothing to do.");
62  return StatusCode::SUCCESS;
63  }
64  else if (previousDecisionsHandle->size() > 1)
65  {
66  ATH_MSG_ERROR("Found " << previousDecisionsHandle->size() << " previous decisions.");
67  return StatusCode::FAILURE;
68  }
69 
70  ATH_MSG_DEBUG("Running with " << previousDecisionsHandle->size() << " implicit ReadHandles for previous decisions");
71 
72  const auto viewTrk = (previousDecisionsHandle->at(0))->objectLink<ViewContainer>(viewString());
73  ATH_CHECK(viewTrk.isValid());
74  auto tracksHandle = ViewHelper::makeHandle(*viewTrk, m_tracksKey, context);
75  ATH_CHECK(tracksHandle.isValid());
76  ATH_MSG_DEBUG("spacepoint handle size: " << tracksHandle->size() << "...");
77 
78  float vertexZ = 0;
79  float maxWeight = -1;
80  auto linkToVertex = findLink<xAOD::TrigCompositeContainer>(previousDecisionsHandle->at(0), featureString());
81  if ( linkToVertex.link.isValid() ) {
82  auto all_verties = linkToVertex.link.getDataPtr();
83  for ( auto vtxInfo: *all_verties) {
84  const float weight = vtxInfo->getDetail<float>("zfinder_vtx_weight");
85  if ( weight > maxWeight ) {
86  maxWeight = weight;
87  vertexZ = vtxInfo->getDetail<float>("zfinder_vtx_z");
88  }
89  }
90  ATH_MSG_DEBUG("Obtained vertex from ZFinder z:" << vertexZ << " weight " << maxWeight);
91  } else {
92  ATH_MSG_DEBUG("No vertex from ZFinder");
93  }
94 
95 
96  const int ntrks = tracksHandle->size();
97  ATH_MSG_DEBUG("Successfully retrieved track container of size" << ntrks);
98  auto trkPt = Monitored::Collection("trkPt", *tracksHandle, [](const auto& trk){ return trk->pt()*1.e-3; } );
99  auto trkEta = Monitored::Collection("trkEta", *tracksHandle, [](const auto& trk){ return trk->eta(); } );
100  Monitored::Group(m_monTool, trkPt, trkEta);
101  std::vector<int> counts(m_minPt.size());
102  for (const auto trackPtr : *tracksHandle)
103  {
104  const double pT = trackPtr->pt();
105  const double z0 = trackPtr->z0();
106  const double sinTheta = std::sin(trackPtr->theta());
107 
108  for (long unsigned int i = 0; i < m_minPt.size(); i++)
109  {
110  if (pT >= m_minPt[i]
111  && std::fabs(z0) < m_maxZ0[i]
112  && ( std::abs((z0-vertexZ)*sinTheta) < m_vertexZ[i] ) )
113  counts[i]++;
114  }
115  }
116  for (long unsigned int i = 0; i < m_minPt.size(); i++)
117  {
118  ATH_MSG_DEBUG("Number of tracks found with pT cut= " << m_minPt[i] << " MeV ="
119  << "and z0 cut= " << m_maxZ0[i] << counts[i]);
120  }
121 
122  // Recording Data
123  auto trackCountContainer = std::make_unique<xAOD::TrigCompositeContainer>();
124  auto trackCountContainerAux = std::make_unique<xAOD::TrigCompositeAuxContainer>();
125  trackCountContainer->setStore(trackCountContainerAux.get());
126 
127  xAOD::TrigComposite *trackCount = new xAOD::TrigComposite();
128  trackCountContainer->push_back(trackCount);
129  trackCount->setDetail("ntrks", ntrks);
130  trackCount->setDetail("pTcuts", static_cast<std::vector<float>>(m_minPt));
131  trackCount->setDetail("z0cuts", static_cast<std::vector<float>>(m_maxZ0));
132  trackCount->setDetail("vertexZcuts", static_cast<std::vector<float>>(m_vertexZ));
133  trackCount->setDetail("counts", counts);
134 
135  auto mon_ntrks = Monitored::Scalar<int>("ntrks", ntrks);
136  Monitored::Group(m_monTool, mon_ntrks);
137  for (long unsigned int i = 0; i < counts.size(); i++)
138  {
139  auto mon_counts = Monitored::Scalar<int>("countsSelection" + std::to_string(i), counts[i]);
140  Monitored::Group(m_monTool, mon_counts);
141  }
142 
144  auto decisions = outputHandle.ptr();
145 
148 
150  TrigCompositeUtils::decisionIDs(previousDecisionsHandle->at(0), prev);
151 
152  TrackCountHypoTool::TrkCountsInfo trkinfo{d, trackCount, prev};
153 
154  for (auto &tool : m_hypoTools)
155  {
156  ATH_CHECK(tool->decide(trkinfo));
157  }
158 
160  ATH_CHECK(trackCountHandle.record(std::move(trackCountContainer), std::move(trackCountContainerAux)));
162  ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
163  return StatusCode::SUCCESS;
164 }
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
xAOD::TrigComposite_v1::setDetail
bool setDetail(const std::string &name, const TYPE &value)
Set an TYPE detail on the object.
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
TrigCompositeUtils.h
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
TrigCompositeUtils::newDecisionIn
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
Definition: TrigCompositeUtilsRoot.cxx:46
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:906
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:258
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounce
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Definition: AthCommonDataStore.h:380
TrackCountHypoAlg::m_hypoTools
ToolHandleArray< TrackCountHypoTool > m_hypoTools
Definition: TrackCountHypoAlg.h:26
HypoBase::decisionInput
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & decisionInput() const
methods for derived classes to access handles of the base class input other read/write handles may be...
Definition: HypoBase.cxx:16
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
TrackCountHypoAlg::m_minPt
Gaudi::Property< std::vector< float > > m_minPt
Definition: TrackCountHypoAlg.h:29
ViewHelper.h
HypoBase::decisionOutput
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutput() const
methods for derived classes to access handles of the base class output other read/write handles may b...
Definition: HypoBase.cxx:20
TrackCountHypoAlg.h
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
TrackCountHypoTool.h
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrackCountHypoAlg::m_maxZ0
Gaudi::Property< std::vector< float > > m_maxZ0
Definition: TrackCountHypoAlg.h:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackCountHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrackCountHypoAlg.cxx:28
TrackParticleAuxContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
HypoBase::hypoBaseOutputProcessing
StatusCode hypoBaseOutputProcessing(SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle, MSG::Level lvl=MSG::DEBUG) const
Base class function to be called once slice specific code has finished. Handles debug printing and va...
Definition: HypoBase.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
TrackCountHypoAlg::m_tracksKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksKey
Definition: TrackCountHypoAlg.h:27
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
TRT::Track::z0
@ z0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:63
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
TrigCompositeUtils::DecisionAuxContainer
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
Definition: TrigCompositeAuxContainer.h:20
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
HypoBase
Hypothesis algorithms take the output of reco algorithms and the decision from the preceeding InputMa...
Definition: HypoBase.h:13
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
TrackCountHypoAlg::TrackCountHypoAlg
TrackCountHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackCountHypoAlg.cxx:24
TrackCountHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrackCountHypoAlg.h:33
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigCompositeUtils::linkToPrevious
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
Definition: TrigCompositeUtilsRoot.cxx:139
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrigCompositeUtils::findLink
LinkInfo< T > findLink(const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
TrackCountHypoAlg::m_vertexZ
Gaudi::Property< std::vector< float > > m_vertexZ
Definition: TrackCountHypoAlg.h:31
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrackCountHypoTool::TrkCountsInfo
Definition: TrackCountHypoTool.h:21
TrackCountHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrackCountHypoAlg.cxx:48
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:882
TrackCountHypoAlg::m_trackCountKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_trackCountKey
Definition: TrackCountHypoAlg.h:28
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37