ATLAS Offline Software
TrackCaloClusterInfoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // TrackCaloClusterInfoAlgs includes
7 
10 
12 
13 TrackCaloClusterInfoAlg::TrackCaloClusterInfoAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
14  AthAlgorithm( name, pSvcLocator ) {}
15 
16 
18  ATH_MSG_DEBUG ("Initializing " << name() << "...");
21  ATH_CHECK(m_inputVertexHandle.initialize());
23 
24  ATH_CHECK(m_assoClustersKey.initialize());
25 
26  return StatusCode::SUCCESS;
27 }
28 
29 
31  ATH_MSG_DEBUG ("Executing " << name() << "...");
32 
33  // Prepare a TrackCaloClusterInfo map :
35  ATH_CHECK( tccInfo.record( std::make_unique<TrackCaloClusterInfo>() ) );
36 
37  // Retrieve the input containers
41 
42  tccInfo->allClusters = &*clusterContainer;
43  tccInfo->allTracks = &*tracks;
44 
45  // retrieve PV0 if it exists
46  if(!vertices->empty()) {
47  tccInfo->pv0=(*vertices)[0]; // Hard code HS vertex as PV0 : WARNING we expect it is the same as was used for m_inputTrackCaloAssocName !!
48  } else {
49  ATH_MSG_ERROR ("Vertex container " << m_inputVertexHandle << " is empty! Can't perform TVA!");
50  return StatusCode::FAILURE;
51  }
52 
53  // Fill the maps
54  ATH_CHECK( fillInfo(tccInfo) );
55 
56  return StatusCode::SUCCESS;
57 }
58 
59 
61 
62  std::multimap <const xAOD::IParticle*, const xAOD::TrackParticle*> clusterToTracksMap;
63 
65  static const xAOD::IParticle::FourMom_t nullV(0,0,0,0);
66 
67  for(const xAOD::TrackParticle* trk : *tccInfo->allTracks){
68  const auto & clustLinks = clusterLinks( *trk );
69  if(clustLinks.empty() ) continue;
70  // follow the link to the calorimeter clusters
71  for( const auto& clLink : clustLinks) {
72  const xAOD::IParticle* cluster = *clLink;
73  clusterToTracksMap.insert(std::make_pair(cluster, trk));
74  // find FourMom_t for trk or insert (0,0,0,0) if not yet in map :
75  xAOD::IParticle::FourMom_t & totalP4 = ( tccInfo->trackTotalClusterPt.insert( {trk, nullV} ) ).first->second;
76  totalP4 += cluster->p4(); // add the cluster p4 into the map.
77  }
78  }
79 
80 
81  // Create cluster-to-tracks weight map
82  for (std::pair<const xAOD::IParticle*, const xAOD::TrackParticle*> entry : clusterToTracksMap)
83  {
84  const xAOD::IParticle* cluster = entry.first;
85  double cluster_pt = m_useEnergy ? cluster->e() : cluster->pt();
86  double totalcluster_pt = m_useEnergy ? tccInfo->trackTotalClusterPt.at(entry.second).E() : tccInfo->trackTotalClusterPt.at(entry.second).Pt();
87 
88  // find FourMom_t for trk or insert (0,0,0,0) if not yet in map :
89  xAOD::IParticle::FourMom_t & totalP4 = ( tccInfo->clusterToTracksWeightMap.insert( {cluster, nullV} ) ).first->second;
90  totalP4 += entry.second->p4() * (cluster_pt/totalcluster_pt); // add the track p4 into the map.
91  }
92 
93 
94  return StatusCode::SUCCESS;
95 }
96 
97 
98 
99 
100 
101 
102 
103 namespace TCCHelpers{
104 
109 
110  // additional members
111  std::multimap <const xAOD::IParticle*, const xAOD::TrackParticle*> pfoToTracksMap;
113 
115 
116  virtual void processPFO(const xAOD::TrackParticle* trk, const xAOD::FlowElement* pfo) {
118  pfoToTracksMap.insert(std::make_pair(pfo, trk));
119  // get the total p4 for this track, creating it from nullV if not existing.
120  xAOD::IParticle::FourMom_t & totalP4 = ( tccInfo_nonconst->trackTotalClusterPt.insert( {trk, nullV} ) ).first->second;
121  totalP4 += pfo->p4(); // this modifies the totalP4 stored inside the map (reference access)
122  }
123 
124  virtual void processTrk(const xAOD::TrackParticle* ) { }
125 
126  };
127 }
128 
129 
130 
131 TrackCaloClusterInfoUFOAlg::TrackCaloClusterInfoUFOAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
132  TrackCaloClusterInfoAlg( name, pSvcLocator ) {}
133 
134 
136  ATH_CHECK(m_trackVertexAssoTool.retrieve() );
137  ATH_CHECK(m_inputPFOHandle.initialize() );
138  ATH_MSG_DEBUG("TCC_INFO_UFO_ALG_INIT");
139  //ATH_MSG_INFO(m_trackVertexAssoTool.get()->name());
140  ATH_MSG_DEBUG("END INIT BLOCK");
141  ATH_MSG_DEBUG("m_orig_pfo "+m_orig_pfo);
142  ATH_MSG_DEBUG("m_inputPFOHandle"+m_inputPFOHandle.key());
143  ATH_MSG_DEBUG("m_trackVertexAssoTool "+m_trackVertexAssoTool.name());
145  ATH_MSG_DEBUG("DEBUG OF VarHandleInits");
146  ATH_MSG_DEBUG("TCC DIAGNOSTIC");
147 
148  ATH_MSG_DEBUG("inputTracksHandle "+m_inputTracksHandle.key());
149  ATH_MSG_DEBUG("assoClustersKey "+m_assoClustersKey.key());
150  ATH_MSG_DEBUG("inputClustersHandle "+m_inputClustersHandle.key());
151  ATH_MSG_DEBUG("inputVertexHandle "+m_inputVertexHandle.key());
152  ATH_MSG_DEBUG("useEnergy? "+m_useEnergy);
153  ATH_MSG_DEBUG("END TCC READLHANDLE DIAGNOSTIC");
155  ATH_MSG_DEBUG("WRITEHANDLE DIAGNOSTIC");
156 
157  ATH_MSG_DEBUG("TCC INITS FROM PARENT CLASS");
160  ATH_CHECK(m_inputVertexHandle.initialize());
162  ATH_CHECK(m_assoClustersKey.initialize());
163  ATH_MSG_DEBUG("TCC INITS DONE");
164 
165 
166  return StatusCode::SUCCESS;
167 }
168 
170  ATH_MSG_VERBOSE("TCC_UFO_ALG fillInfo start");
171 
172 
174  if(!pfos.isValid() ){
175  ATH_MSG_ERROR("Can't retrieve FlowElementContainer "<< m_inputPFOHandle.key() ); return StatusCode::FAILURE;
176  }
177 
179 
180  ATH_MSG_VERBOSE("GOT FE");
181  // We use a dedicated helper to collect the weights mapping tracks to FlowElement.
183  wcoll.m_orig_pfoK = m_orig_pfo;
184  ATH_MSG_VERBOSE("GOT ORIG PFO");
185 
187  ATH_MSG_VERBOSE("ReadDecorHandle's default container: "<<clusterLinks.key());
188  ATH_MSG_VERBOSE("is ReadDecorHandle available? " <<clusterLinks.isAvailable());
189  ATH_MSG_VERBOSE("ReadDecorHandleKey: "<<clusterLinks.decorKey());
190 
194  wcoll.m_useEnergy = m_useEnergy;
195  wcoll.tccInfo_nonconst = tccInfo.ptr();
196 
197 
198  // perform the weight collection : this populates tccInfo.trackTotalClusterPt and tccInfo.pfoToTracksMap maps
199  wcoll.combinedUFOLoop(tccInfo.cptr(), pfos.cptr());
200 
201 
202  static const xAOD::IParticle::FourMom_t nullV(0,0,0,0);
203 
204  // Create cluster-to-tracks weight map
205  for (std::pair<const xAOD::IParticle*, const xAOD::TrackParticle*> entry : wcoll.pfoToTracksMap){
206  double cluster_pt = m_useEnergy ? entry.first->e() : entry.first->pt();
207  double totalcluster_pt = m_useEnergy ? tccInfo->trackTotalClusterPt.at(entry.second).E() : tccInfo->trackTotalClusterPt.at(entry.second).Pt();
208 
209  // find FourMom_t for trk or insert (0,0,0,0) if not yet in map :
210  xAOD::IParticle::FourMom_t & totalP4 = ( tccInfo->clusterToTracksWeightMap.insert( {entry.first, nullV} ) ).first->second;
211  totalP4 += entry.second->p4() * (cluster_pt/totalcluster_pt); // add the track p4 into the map.
212  }
213 
214  return StatusCode::SUCCESS;
215 
216 }
TrackCaloClusterInfoAlg::initialize
virtual StatusCode initialize() override
Definition: TrackCaloClusterInfoAlg.cxx:17
TrackCaloClusterInfoUFOAlg::m_orig_pfo
Gaudi::Property< std::string > m_orig_pfo
Definition: TrackCaloClusterInfoAlg.h:89
TrackCaloClusterInfoUFOAlg::initialize
virtual StatusCode initialize() override
Definition: TrackCaloClusterInfoAlg.cxx:135
TrackCaloClusterInfoAlg::TrackCaloClusterInfoAlg
TrackCaloClusterInfoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackCaloClusterInfoAlg.cxx:13
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::decorKeyFromKey
std::string decorKeyFromKey(const std::string &key)
Extract the decoration part of key.
Definition: DecorKeyHelpers.cxx:41
TCCHelpers::CombinedUFOLoop::m_orig_pfoK
std::string m_orig_pfoK
Definition: TCCHelpers.h:40
TrackCaloClusterInfoUFOAlg::m_clusterEcut
Gaudi::Property< float > m_clusterEcut
cluster with E below this cut won't be considered in the TCC alg. WARNING cut must be configured as i...
Definition: TrackCaloClusterInfoAlg.h:93
TrackCaloClusterInfo::allTracks
const xAOD::TrackParticleContainer * allTracks
Definition: TrackCaloClusterInfo.h:32
TrackCaloClusterInfo::trackTotalClusterPt
std::map< const xAOD::TrackParticle *, FourMom_t > trackTotalClusterPt
Definition: TrackCaloClusterInfo.h:29
SG::WriteHandle::cptr
const_pointer_type cptr() const
Dereference the pointer.
TrackCaloClusterInfoUFOAlg::fillInfo
virtual StatusCode fillInfo(SG::WriteHandle< TrackCaloClusterInfo > &tccInfo) const override
Definition: TrackCaloClusterInfoAlg.cxx:169
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
TrackCaloClusterInfoAlg::m_assoClustersKey
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_assoClustersKey
Decoration of tracks expected by this alg (set by TrackParticleClusterAssociationAlg)
Definition: TrackCaloClusterInfoAlg.h:52
DecorKeyHelpers.h
Some common helper functions used by decoration handles.
TrackCaloClusterInfoUFOAlg::TrackCaloClusterInfoUFOAlg
TrackCaloClusterInfoUFOAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackCaloClusterInfoAlg.cxx:131
TrackCaloClusterInfoUFOAlg::m_trackVertexAssoTool
ToolHandle< CP::ITrackVertexAssociationTool > m_trackVertexAssoTool
Definition: TrackCaloClusterInfoAlg.h:95
TCCHelpers::WeightsCollector::nullV
const xAOD::IParticle::FourMom_t nullV
Definition: TrackCaloClusterInfoAlg.cxx:114
TrackCaloClusterInfoAlg::m_inputClustersHandle
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inputClustersHandle
Original clusters from which the m_inputObjectName are build ()
Definition: TrackCaloClusterInfoAlg.h:55
TCCHelpers::CombinedUFOLoop::m_trackVertexAssoTool
const CP::ITrackVertexAssociationTool * m_trackVertexAssoTool
Definition: TCCHelpers.h:46
xAOD::IParticle::FourMom_t
TLorentzVector FourMom_t
Definition of the 4-momentum type.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:69
TrackCaloClusterInfo
Definition: TrackCaloClusterInfo.h:23
TrackCaloClusterInfoAlg::m_tccInfoHandle
SG::WriteHandleKey< TrackCaloClusterInfo > m_tccInfoHandle
TrackCaloClusterInfo created by this alg.
Definition: TrackCaloClusterInfoAlg.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
TCCHelpers::WeightsCollector::tccInfo_nonconst
TrackCaloClusterInfo * tccInfo_nonconst
Definition: TrackCaloClusterInfoAlg.cxx:112
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.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TCCHelpers::WeightsCollector::pfoToTracksMap
std::multimap< const xAOD::IParticle *, const xAOD::TrackParticle * > pfoToTracksMap
Definition: TrackCaloClusterInfoAlg.cxx:111
SG::ReadDecorHandle::decorKey
const std::string & decorKey() const
Return the name of the decoration alias (CONT.DECOR).
TrackCaloClusterInfoUFOAlg::m_inputPFOHandle
SG::ReadHandleKey< xAOD::FlowElementContainer > m_inputPFOHandle
Definition: TrackCaloClusterInfoAlg.h:86
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
TCCHelpers::CombinedUFOLoop::combinedUFOLoop
virtual void combinedUFOLoop(const TrackCaloClusterInfo *tccInfo, const xAOD::FlowElementContainer *pfos)
Definition: TCCHelpers.h:54
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TCCHelpers::CombinedUFOLoop::m_clustersLinkK
std::string m_clustersLinkK
Definition: TCCHelpers.h:42
xAOD::IParticle::pt
virtual double pt() const =0
The transverse momentum ( ) of the particle.
TrackCaloClusterInfoAlg::m_inputTracksHandle
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTracksHandle
Tracks used by this alg.
Definition: TrackCaloClusterInfoAlg.h:50
TrackCaloClusterInfoAlg::m_useEnergy
Gaudi::Property< bool > m_useEnergy
use cluster energy or pt?
Definition: TrackCaloClusterInfoAlg.h:60
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
TCCHelpers::CombinedUFOLoop::m_useEnergy
bool m_useEnergy
Definition: TCCHelpers.h:48
TCCHelpers.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TCCHelpers
\bried Internal helper class for TCC & UFO building.
Definition: TrackCaloClusterInfoAlg.cxx:103
TCCHelpers::WeightsCollector::processTrk
virtual void processTrk(const xAOD::TrackParticle *)
Definition: TrackCaloClusterInfoAlg.cxx:124
TrackCaloClusterInfo::clusterToTracksWeightMap
std::map< const xAOD::IParticle *, FourMom_t > clusterToTracksWeightMap
Definition: TrackCaloClusterInfo.h:30
xAOD::IParticle::p4
virtual FourMom_t p4() const =0
The full 4-momentum of the particle.
TrackCaloClusterInfo::pv0
const xAOD::Vertex * pv0
Definition: TrackCaloClusterInfo.h:34
TrackCaloClusterInfoAlg::execute
virtual StatusCode execute() override
Definition: TrackCaloClusterInfoAlg.cxx:30
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrackCaloClusterInfoAlg.h
xAOD::FlowElement_v1::p4
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
Definition: FlowElement_v1.cxx:33
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrackCaloClusterInfoAlg::m_inputVertexHandle
SG::ReadHandleKey< xAOD::VertexContainer > m_inputVertexHandle
Definition: TrackCaloClusterInfoAlg.h:57
TCCHelpers::WeightsCollector
Implement a concrete CombinedUFOLoop dedicated to collection of energy sharing weights for UFO see TC...
Definition: TrackCaloClusterInfoAlg.cxx:108
TCCHelpers::CombinedUFOLoop::m_clusterEcut
float m_clusterEcut
Definition: TCCHelpers.h:47
TCCHelpers::WeightsCollector::processPFO
virtual void processPFO(const xAOD::TrackParticle *trk, const xAOD::FlowElement *pfo)
Definition: TrackCaloClusterInfoAlg.cxx:116
TrackCaloClusterInfoAlg
Definition: TrackCaloClusterInfoAlg.h:32
ReadDecorHandle.h
Handle class for reading a decoration on an object.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TrackCaloClusterInfoAlg::fillInfo
virtual StatusCode fillInfo(SG::WriteHandle< TrackCaloClusterInfo > &tccInfo) const
Definition: TrackCaloClusterInfoAlg.cxx:60
TCCHelpers::CombinedUFOLoop
Implements a loop over tracks and pflow object to build UFOs.
Definition: TCCHelpers.h:34
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
TrackCaloClusterInfo::allClusters
const xAOD::CaloClusterContainer * allClusters
Definition: TrackCaloClusterInfo.h:33
TCCHelpers::CombinedUFOLoop::m_linkdecorkey
const SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > * m_linkdecorkey
Definition: TCCHelpers.h:49
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
xAOD::IParticle::e
virtual double e() const =0
The total energy of the particle.
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25