ATLAS Offline Software
eflowTrackCaloExtensionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6 
7  NAME: eflowTrackCaloExtensionTool.cxx
8  PACKAGE: offline/Reconstruction/eflowRec
9 
10  AUTHORS: T.Guttenberger
11  CREATED: 19th September, 2014
12 
13  ********************************************************************/
14 
16 
19 
20 #include "TrkParameters/TrackParameters.h" // typedef
23 
25 
26 #include "GaudiKernel/ListItem.h"
27 
28 #include <map>
29 #include <vector>
30 #include <utility>
31 
32 eflowTrackCaloExtensionTool::eflowTrackCaloExtensionTool(const std::string& type, const std::string& name, const IInterface* parent) :
34  m_theTrackExtrapolatorTool("Trk::ParticleCaloExtensionTool",this),
35  m_trackParametersIdHelper(std::make_unique<Trk::TrackParametersIdHelper>())
36 {
37  declareInterface<eflowTrackExtrapolatorBaseAlgTool>(this);
38  declareProperty("TrackCaloExtensionTool", m_theTrackExtrapolatorTool, "TrackCaloExtension Tool Handle");
39 }
40 
42 
44  /* Tool service */
45  IToolSvc* myToolSvc;
46  if (service("ToolSvc", myToolSvc).isFailure()) {
47  ATH_MSG_WARNING(" Tool Service Not Found");
48  return StatusCode::SUCCESS;
49  }
50 
51  if (m_theTrackExtrapolatorTool.retrieve().isFailure()) {
52  ATH_MSG_WARNING("Cannot find Extrapolation tool "
53  << m_theTrackExtrapolatorTool.typeAndName());
54  return StatusCode::SUCCESS;
55  } else {
56  ATH_MSG_VERBOSE("Successfully retrieved Extrapolation tool "
57  << m_theTrackExtrapolatorTool.typeAndName());
58  }
59 
60  if (!m_ParticleCacheKey.key().empty()) ATH_CHECK(m_ParticleCacheKey.initialize());
61  else m_useOldCalo = true;
62 
63  if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
64 
65  return StatusCode::SUCCESS;
66 }
67 
68 std::unique_ptr<eflowTrackCaloPoints> eflowTrackCaloExtensionTool::execute(const xAOD::TrackParticle* track) const {
69 
70  ATH_MSG_VERBOSE(" Now running eflowTrackCaloExtensionTool");
71 
72  auto execution_timer = Monitored::Timer<std::chrono::microseconds>( "TIME_execute" );
73  Monitored::ScopedTimer execution_time(execution_timer);
74  auto extrapolation_timer = Monitored::Timer<std::chrono::microseconds>( "TIME_extrapolation" );
75  auto track_pt = Monitored::Scalar<float>("track_pt");
76  auto group = Monitored::Group(m_monTool, execution_timer, extrapolation_timer, track_pt);
77 
78  track_pt = track->pt() * m_invGeV ;
79 
80  /*Create a map to index the TrackParameters at calo (owned by the extension) wrt to layers*/
81  std::map<eflowCalo::LAYER, const Trk::TrackParameters*> parametersMap;
82  std::map<CaloCell_ID::CaloSample,const Trk::TrackParameters*> tileParametersMap;
83 
84  /*get the CaloExtension object*/
85  const Trk::CaloExtension * extension = nullptr;
86  std::unique_ptr<Trk::CaloExtension> uniqueExtension;
87  const int index = track->index();
88  ATH_MSG_VERBOSE("Getting element " << index << " from the particleCache");
89 
90  extrapolation_timer.start();
91  if (m_useOldCalo) {
92  /* If CaloExtensionBuilder is unavailable, use the calo extension tool */
93  ATH_MSG_VERBOSE("Using the CaloExtensionTool");
94  uniqueExtension = m_theTrackExtrapolatorTool->caloExtension(
95  Gaudi::Hive::currentContext(), *track);
96  extension = uniqueExtension.get();
97  } else {
98  /*get the CaloExtension object*/
100  ATH_MSG_VERBOSE("Using the CaloExtensionBuilder Cache");
101  extension = (*particleCache)[index];
102  ATH_MSG_VERBOSE("Getting element " << index << " from the particleCache");
103  if( not extension ){
104  ATH_MSG_VERBOSE("Cache does not contain a calo extension -> Calculating with the a CaloExtensionTool" );
105  uniqueExtension = m_theTrackExtrapolatorTool->caloExtension(
106  Gaudi::Hive::currentContext(), *track);
107  extension = uniqueExtension.get();
108  }
109  }
110  extrapolation_timer.stop();
111 
112  if (extension != nullptr) {
113 
114  /*extract the CurvilinearParameters*/
115  const std::vector<Trk::CurvilinearParameters>& clParametersVector = extension->caloLayerIntersections();
116 
117  /*The parameters are owned by the CaloExtension so are handled by it the eflowTrackCaloPoints does
118  * not take ownership */
119  for ( const Trk::CurvilinearParameters& clParameter : clParametersVector) {
120  if (parametersMap[getLayer(&clParameter)] == nullptr) {
121  parametersMap[getLayer(&clParameter)] = &clParameter;
122  } else if (m_trackParametersIdHelper->isEntryToVolume(clParameter.cIdentifier())) {
123  parametersMap[getLayer(&clParameter)] = &clParameter;
124  }
125 
126  CaloCell_ID::CaloSample caloSample = m_trackParametersIdHelper->caloSample(clParameter.cIdentifier());
127 
128  if (tileParametersMap[caloSample] == nullptr){
129  tileParametersMap[caloSample] = &clParameter;
130  } else if (m_trackParametersIdHelper->isEntryToVolume(clParameter.cIdentifier())){
131  tileParametersMap[caloSample] = &clParameter;
132  }
133 
134  }
135 
136 
137  /*
138  parametersMap may have several entries for Tile1,2,3.
139  The impact is negligible as the eta/phi of these entries are very similar
140  https://its.cern.ch/jira/browse/ATLJETMET-242
141  */
142 
143  return std::make_unique<eflowTrackCaloPoints>(parametersMap,tileParametersMap);
144 
145  }
146  else{
147  if (track->pt() > 3*Gaudi::Units::GeV) ATH_MSG_WARNING("TrackExtension failed for track with pt and eta " << track->pt() << " and " << track->eta());
148  parametersMap[eflowCalo::LAYER::Unknown] = nullptr;
149  return std::make_unique<eflowTrackCaloPoints>(parametersMap);
150  }
151 }
152 
154  return StatusCode::SUCCESS;
155 }
156 
157 /*This function translates the information embedded within the CurvilinearParameters of the CaloExtension object into an eflowCaloLayer*/
159  unsigned int parametersIdentifier = clParameter->cIdentifier();
160 
161  /*Return unknown when the identifier is invalid */
162  if (!m_trackParametersIdHelper->isValid(parametersIdentifier)) {
163  ATH_MSG_ERROR("invalid Track Identifier");
165  };
166 
167  if(m_trackParametersIdHelper->isEntryToVolume(parametersIdentifier)) {
168  ATH_MSG_VERBOSE("is Volume Entry");
169  } else {
170  ATH_MSG_VERBOSE("is Volume Exit");
171  }
172 
173  return eflowCalo::translateSampl(m_trackParametersIdHelper->caloSample(parametersIdentifier));
174 }
eflowTrackCaloExtensionTool::m_theTrackExtrapolatorTool
ToolHandle< Trk::IParticleCaloExtensionTool > m_theTrackExtrapolatorTool
Definition: eflowTrackCaloExtensionTool.h:56
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrackParameters.h
eflowTrackCaloExtensionTool.h
Trk::CaloExtension
Tracking class to hold the extrapolation from a particle from the ID to the muon system (or the other...
Definition: CaloExtension.h:18
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
eflowTrackCaloExtensionTool::m_invGeV
const float m_invGeV
Definition: eflowTrackCaloExtensionTool.h:52
CaloDepthTool.h
Declaration of CaloDepthTool. Created by Claire Bourdarios, 25.10.2004.
CaloExtension.h
eflowTrackCaloExtensionTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Online monitoring tool for recording histograms of the alg in action.
Definition: eflowTrackCaloExtensionTool.h:67
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
eflowTrackCaloPoints.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackParametersIdHelper.h
Trk::CurvilinearParametersT::cIdentifier
unsigned int cIdentifier() const
the curvilinear parameters identifier
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
eflowTrackCaloExtensionTool::getLayer
eflowCalo::LAYER getLayer(const Trk::CurvilinearParameters *clParameters) const
Definition: eflowTrackCaloExtensionTool.cxx:158
eflowTrackCaloExtensionTool::eflowTrackCaloExtensionTool
eflowTrackCaloExtensionTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: eflowTrackCaloExtensionTool.cxx:32
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::CurvilinearParametersT
Definition: CurvilinearParametersT.h:48
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
eflowDepthCalculator.h
eflowTrackCaloExtensionTool::initialize
virtual StatusCode initialize() override
Definition: eflowTrackCaloExtensionTool.cxx:43
DeMoScan.index
string index
Definition: DeMoScan.py:362
eflowCalo::LAYER
LAYER
Definition: eflowCaloRegions.h:36
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
eflowTrackCaloExtensionTool::m_trackParametersIdHelper
std::unique_ptr< Trk::TrackParametersIdHelper > m_trackParametersIdHelper
Definition: eflowTrackCaloExtensionTool.h:58
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
eflowTrackCaloExtensionTool::finalize
virtual StatusCode finalize() override
Definition: eflowTrackCaloExtensionTool.cxx:153
eflowTrackCaloExtensionTool::m_ParticleCacheKey
SG::ReadHandleKey< CaloExtensionCollection > m_ParticleCacheKey
Definition: eflowTrackCaloExtensionTool.h:61
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
eflowTrackCaloExtensionTool::execute
virtual std::unique_ptr< eflowTrackCaloPoints > execute(const xAOD::TrackParticle *track) const override
Definition: eflowTrackCaloExtensionTool.cxx:68
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Trk::CaloExtension::caloLayerIntersections
const std::vector< CurvilinearParameters > & caloLayerIntersections() const
access to the intersections with the calorimeter layers.
Definition: CaloExtension.h:76
eflowTrackCaloExtensionTool::m_useOldCalo
Gaudi::Property< bool > m_useOldCalo
Definition: eflowTrackCaloExtensionTool.h:64
AthAlgTool
Definition: AthAlgTool.h:26
Monitored::ScopedTimer
Helper class to create a scoped timer.
Definition: MonitoredTimer.h:95
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
eflowCalo::translateSampl
static LAYER translateSampl(CaloCell_ID::CaloSample sampl)
Definition: eflowCaloRegions.cxx:45
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
eflowTrackCaloExtensionTool::~eflowTrackCaloExtensionTool
~eflowTrackCaloExtensionTool()