ATLAS Offline Software
Loading...
Searching...
No Matches
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
13TrackCaloClusterInfoAlg::TrackCaloClusterInfoAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
14 AthAlgorithm( name, pSvcLocator ) {}
15
16
18 ATH_MSG_DEBUG ("Initializing " << name() << "...");
19 ATH_CHECK(m_inputClustersHandle.initialize() );
20 ATH_CHECK(m_inputTracksHandle.initialize() );
21 ATH_CHECK(m_inputVertexHandle.initialize());
22 ATH_CHECK(m_tccInfoHandle.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
103namespace 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
131TrackCaloClusterInfoUFOAlg::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");
158 ATH_CHECK(m_inputClustersHandle.initialize() );
159 ATH_CHECK(m_inputTracksHandle.initialize() );
160 ATH_CHECK(m_inputVertexHandle.initialize());
161 ATH_CHECK(m_tccInfoHandle.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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Some common helper functions used by decoration handles.
Handle class for reading a decoration on an object.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Handle class for reading a decoration on an object.
const std::string & decorKey() const
Return the name of the decoration alias (CONT.DECOR).
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
const_pointer_type cptr() const
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
virtual StatusCode execute() override
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTracksHandle
Tracks used by this alg.
virtual StatusCode initialize() override
virtual StatusCode fillInfo(SG::WriteHandle< TrackCaloClusterInfo > &tccInfo) const
TrackCaloClusterInfoAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inputClustersHandle
Original clusters from which the m_inputObjectName are build ()
Gaudi::Property< bool > m_useEnergy
use cluster energy or pt?
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_assoClustersKey
Decoration of tracks expected by this alg (set by TrackParticleClusterAssociationAlg)
SG::WriteHandleKey< TrackCaloClusterInfo > m_tccInfoHandle
TrackCaloClusterInfo created by this alg.
SG::ReadHandleKey< xAOD::VertexContainer > m_inputVertexHandle
virtual StatusCode initialize() override
TrackCaloClusterInfoUFOAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::string > m_orig_pfo
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...
SG::ReadHandleKey< xAOD::FlowElementContainer > m_inputPFOHandle
ToolHandle< CP::ITrackVertexAssociationTool > m_trackVertexAssoTool
virtual StatusCode fillInfo(SG::WriteHandle< TrackCaloClusterInfo > &tccInfo) const override
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
Class providing the definition of the 4-vector interface.
virtual FourMom_t p4() const =0
The full 4-momentum of the particle.
virtual double pt() const =0
The transverse momentum ( ) of the particle.
TLorentzVector FourMom_t
Definition of the 4-momentum type.
virtual double e() const =0
The total energy of the particle.
std::string decorKeyFromKey(const std::string &key, const std::string &deflt)
Extract the decoration part of key.
\bried Internal helper class for TCC & UFO building.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Implements a loop over tracks and pflow object to build UFOs.
Definition TCCHelpers.h:34
const SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > * m_linkdecorkey
Definition TCCHelpers.h:49
const CP::ITrackVertexAssociationTool * m_trackVertexAssoTool
Definition TCCHelpers.h:46
virtual void combinedUFOLoop(const TrackCaloClusterInfo *tccInfo, const xAOD::FlowElementContainer *pfos)
Definition TCCHelpers.h:54
Implement a concrete CombinedUFOLoop dedicated to collection of energy sharing weights for UFO see TC...
virtual void processPFO(const xAOD::TrackParticle *trk, const xAOD::FlowElement *pfo)
const xAOD::IParticle::FourMom_t nullV
std::multimap< const xAOD::IParticle *, const xAOD::TrackParticle * > pfoToTracksMap
virtual void processTrk(const xAOD::TrackParticle *)
Holds all the necessary information to build TrackCaloCluster objects.