ATLAS Offline Software
eflowTrackCaloExtensionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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/TypeNameString.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 
45  if (m_theTrackExtrapolatorTool.retrieve().isFailure()) {
46  ATH_MSG_WARNING("Cannot find Extrapolation tool "
47  << m_theTrackExtrapolatorTool.typeAndName());
48  return StatusCode::SUCCESS;
49  } else {
50  ATH_MSG_VERBOSE("Successfully retrieved Extrapolation tool "
51  << m_theTrackExtrapolatorTool.typeAndName());
52  }
53 
54  if (!m_ParticleCacheKey.key().empty()) ATH_CHECK(m_ParticleCacheKey.initialize());
55  else m_useOldCalo = true;
56 
57  if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
58 
59  return StatusCode::SUCCESS;
60 }
61 
62 std::unique_ptr<eflowTrackCaloPoints> eflowTrackCaloExtensionTool::execute(const xAOD::TrackParticle* track) const {
63 
64  ATH_MSG_VERBOSE(" Now running eflowTrackCaloExtensionTool");
65 
66  auto execution_timer = Monitored::Timer<std::chrono::microseconds>( "TIME_execute" );
67  Monitored::ScopedTimer execution_time(execution_timer);
68  auto extrapolation_timer = Monitored::Timer<std::chrono::microseconds>( "TIME_extrapolation" );
69  auto track_pt = Monitored::Scalar<float>("track_pt");
70  auto group = Monitored::Group(m_monTool, execution_timer, extrapolation_timer, track_pt);
71 
72  track_pt = track->pt() * m_invGeV ;
73 
74  /*Create a map to index the TrackParameters at calo (owned by the extension) wrt to layers*/
75  std::map<eflowCalo::LAYER, const Trk::TrackParameters*> parametersMap;
76  std::map<CaloCell_ID::CaloSample,const Trk::TrackParameters*> tileParametersMap;
77 
78  /*get the CaloExtension object*/
79  const Trk::CaloExtension * extension = nullptr;
80  std::unique_ptr<Trk::CaloExtension> uniqueExtension;
81  const int index = track->index();
82  ATH_MSG_VERBOSE("Getting element " << index << " from the particleCache");
83 
84  extrapolation_timer.start();
85  if (m_useOldCalo) {
86  /* If CaloExtensionBuilder is unavailable, use the calo extension tool */
87  ATH_MSG_VERBOSE("Using the CaloExtensionTool");
88  uniqueExtension = m_theTrackExtrapolatorTool->caloExtension(
89  Gaudi::Hive::currentContext(), *track);
90  extension = uniqueExtension.get();
91  } else {
92  /*get the CaloExtension object*/
94  ATH_MSG_VERBOSE("Using the CaloExtensionBuilder Cache");
95  extension = (*particleCache)[index];
96  ATH_MSG_VERBOSE("Getting element " << index << " from the particleCache");
97  if( not extension ){
98  ATH_MSG_VERBOSE("Cache does not contain a calo extension -> Calculating with the a CaloExtensionTool" );
99  uniqueExtension = m_theTrackExtrapolatorTool->caloExtension(
100  Gaudi::Hive::currentContext(), *track);
101  extension = uniqueExtension.get();
102  }
103  }
104  extrapolation_timer.stop();
105 
106  if (extension != nullptr) {
107 
108  /*extract the CurvilinearParameters*/
109  const std::vector<Trk::CurvilinearParameters>& clParametersVector = extension->caloLayerIntersections();
110 
111  /*The parameters are owned by the CaloExtension so are handled by it the eflowTrackCaloPoints does
112  * not take ownership */
113  for ( const Trk::CurvilinearParameters& clParameter : clParametersVector) {
114  if (parametersMap[getLayer(&clParameter)] == nullptr) {
115  parametersMap[getLayer(&clParameter)] = &clParameter;
116  } else if (m_trackParametersIdHelper->isEntryToVolume(clParameter.cIdentifier())) {
117  parametersMap[getLayer(&clParameter)] = &clParameter;
118  }
119 
120  CaloCell_ID::CaloSample caloSample = m_trackParametersIdHelper->caloSample(clParameter.cIdentifier());
121 
122  if (tileParametersMap[caloSample] == nullptr){
123  tileParametersMap[caloSample] = &clParameter;
124  } else if (m_trackParametersIdHelper->isEntryToVolume(clParameter.cIdentifier())){
125  tileParametersMap[caloSample] = &clParameter;
126  }
127 
128  }
129 
130 
131  /*
132  parametersMap may have several entries for Tile1,2,3.
133  The impact is negligible as the eta/phi of these entries are very similar
134  https://its.cern.ch/jira/browse/ATLJETMET-242
135  */
136 
137  return std::make_unique<eflowTrackCaloPoints>(parametersMap,tileParametersMap);
138 
139  }
140  else{
141  if (track->pt() > 3*Gaudi::Units::GeV) ATH_MSG_WARNING("TrackExtension failed for track with pt and eta " << track->pt() << " and " << track->eta());
142  parametersMap[eflowCalo::LAYER::Unknown] = nullptr;
143  return std::make_unique<eflowTrackCaloPoints>(parametersMap);
144  }
145 }
146 
148  return StatusCode::SUCCESS;
149 }
150 
151 /*This function translates the information embedded within the CurvilinearParameters of the CaloExtension object into an eflowCaloLayer*/
153  unsigned int parametersIdentifier = clParameter->cIdentifier();
154 
155  /*Return unknown when the identifier is invalid */
156  if (!m_trackParametersIdHelper->isValid(parametersIdentifier)) {
157  ATH_MSG_ERROR("invalid Track Identifier");
159  };
160 
161  if(m_trackParametersIdHelper->isEntryToVolume(parametersIdentifier)) {
162  ATH_MSG_VERBOSE("is Volume Entry");
163  } else {
164  ATH_MSG_VERBOSE("is Volume Exit");
165  }
166 
167  return eflowCalo::translateSampl(m_trackParametersIdHelper->caloSample(parametersIdentifier));
168 }
eflowTrackCaloExtensionTool::m_theTrackExtrapolatorTool
ToolHandle< Trk::IParticleCaloExtensionTool > m_theTrackExtrapolatorTool
Definition: eflowTrackCaloExtensionTool.h:56
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
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:152
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:228
eflowDepthCalculator.h
eflowTrackCaloExtensionTool::initialize
virtual StatusCode initialize() override
Definition: eflowTrackCaloExtensionTool.cxx:43
DeMoScan.index
string index
Definition: DeMoScan.py:364
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:147
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:62
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
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()