ATLAS Offline Software
TCCHelpers.h
Go to the documentation of this file.
1 // this file is -*- C++ -*-
2 /*
3  Copyright (C) 2020, 2022 CERN for the benefit of the ATLAS collaboration
4 */
5 
6 #ifndef TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECTOOLS_TCCHELPERS_H
7 #define TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECTOOLS_TCCHELPERS_H
8 #include "GaudiKernel/MsgStream.h"
9 #
17 
18 namespace TCCHelpers {
19 
34  struct CombinedUFOLoop {
35 
36  virtual ~CombinedUFOLoop(){}
37 
38  // These members are used to collect info.
39  // They are expected to be set by the clients.
40  std::string m_orig_pfoK;
41  std::string m_orig_FlowElemK;
42  std::string m_clustersLinkK;
43 
44 
45 
49  const SG::ReadDecorHandleKey<xAOD::TrackParticleContainer>* m_linkdecorkey=nullptr; // in order to access ReadDecorHandles inside the struct, pass the (initialised) key as a pointer from the parent algorithm into the struct, so we can build the ReadDecorHandle inside the struct function.
50 
51  virtual void processPFO(const xAOD::TrackParticle* trk, const xAOD::FlowElement* pfo) = 0;
52  virtual void processTrk(const xAOD::TrackParticle* trk) = 0;
53 
54  virtual void combinedUFOLoop(const TrackCaloClusterInfo *tccInfo, const xAOD::FlowElementContainer* pfos){
57 
58 
59 
60  // For performance reasons, we create a map<track, bool> before looping on the tracks.
61  std::map<const xAOD::TrackParticle*, bool> isIsolatedMatchedTrack;
62  for(const xAOD::FlowElement* pfo: *pfos ){
63  if( ! pfo->isCharged() ) continue;
64 
65  static const SG::AuxElement::ConstAccessor<int> acc_isInDenseEnvironment("IsInDenseEnvironment");
66  if(!acc_isInDenseEnvironment.isAvailable(*pfo)){
67  asg::msgUserCode::ANA_MSG_ERROR("TCCHelpers.h: Dense environ variable not found, skipping given FE");
68  continue;
69  }
70  if(acc_isInDenseEnvironment(*pfo)==1){
71  continue;
72  }
73  const xAOD::IParticle* pfo_iparticle=pfo->chargedObjects().at(0);
74  //cast to track, since output of chargedObjects is an IParticle
75  const xAOD::TrackParticle* pfoTrack=dynamic_cast<const xAOD::TrackParticle*>(pfo_iparticle);
76  isIsolatedMatchedTrack[pfoTrack] = true;
77  }
78 
79  if(m_linkdecorkey==nullptr){
80  asg::msgUserCode::ANA_MSG_ERROR("TCCHelpers.h m_linkdecorkey is not initialised in the struct to do anything, not sure what this means? Skip this case");
81  return;
82  }
83  const EventContext& ctx =Gaudi::Hive::currentContext();
85 
86  if(!trackcalodecor.isPresent()){
87  asg::msgUserCode::ANA_MSG_ERROR("TCCHelpers.h: no link between track and cluster. We need these links : "<<m_linkdecorkey->key());
88  }
89 
90  for(const xAOD::TrackParticle * trk: *tccInfo->allTracks){
91  // Only include tracks which aren't associated to a charged PFO -- don't want to double count!
92  if (isIsolatedMatchedTrack.find(trk) != isIsolatedMatchedTrack.end() ) continue;
93 
94  // if not matched to PV0, ignore track
95  if (! m_trackVertexAssoTool->isCompatible(*trk, *tccInfo->pv0) ) continue ;
96  //access the link ReadDecorHandle (saved as struct), and then apply it
97 
98 
99 
100 
101 
102  const auto& clustLinks=trackcalodecor(*trk);
103  if(clustLinks.empty() ){
104  continue;
105  }
106 
107 
108  // follow the link to the calorimeter clusters
109  for( const auto& clLink : clustLinks) {
110 
111  const xAOD::CaloCluster* cluster = *clLink;
112 
113  // See if any of the PFO are matched to this cluster
114  for ( const xAOD::FlowElement* pfo : *pfos ){
115  if(pfo->pt()<=0.) continue;
116 
117  const xAOD::IParticle* pfo_orig = nullptr;
118  if ( orig_pfo.isAvailable(*pfo) ) pfo_orig = *orig_pfo( *pfo ) ;
119  else pfo_orig = pfo;
120 
121  if( !(std::abs(pfo_orig->eta() - cluster->rawEta() )<0.01 && std::abs( pfo_orig->phi() - cluster->rawPhi() )<0.01)) continue; // temp disable origin logic. Matt A: not 100% sure if its needed now anyway
122 
123  if( ! pfo->isCharged() ){
124  // Only want to apply this to PFO which aren't able to be subtracted with E/p
125  if(cluster->rawE() < m_clusterEcut) continue;
126  }
127 
128  // this pfo is matched to a cluster associated to the track -->
129  // Call the specialized function to accumulate either :
130  // - E sharing weights (ex: in TrackCaloClusterInfoAlg.cxx)
131  // - clusters/pfo mometum associated to the current trk (ex: TrackCaloClusterTool)
132  processPFO(trk, pfo);
133 
134  } // pfo loop
135  } // cluster associated to trk loop
136 
137  // When building UFO, the specialized func below will create a combined UFO from this
138  // track and the accumulated momentum from the associated cluster/pfo
139  processTrk(trk);
140 
141  } // track loop
142 
143 
144  }
145 
146  };
147 
148 }
149 
150 #endif
xAOD::CaloCluster_v1::rawE
flt_t rawE() const
xAOD::CaloCluster_v1::rawEta
flt_t rawEta() const
Get in signal state UNCALIBRATED.
CP::ITrackVertexAssociationTool
Definition: ITrackVertexAssociationTool.h:24
CP::ITrackVertexAssociationTool::isCompatible
virtual bool isCompatible(const xAOD::TrackParticle &trk, const xAOD::Vertex &vx) const =0
This function just return the decision of whether the track is matched to the Vertex Not sure whether...
TCCHelpers::CombinedUFOLoop::m_orig_pfoK
std::string m_orig_pfoK
Definition: TCCHelpers.h:40
SG::ReadDecorHandle::isPresent
bool isPresent() const
Is the referenced container present in SG?
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
TrackCaloClusterInfo::allTracks
const xAOD::TrackParticleContainer * allTracks
Definition: TrackCaloClusterInfo.h:32
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
TCCHelpers::CombinedUFOLoop::processTrk
virtual void processTrk(const xAOD::TrackParticle *trk)=0
TCCHelpers::CombinedUFOLoop::processPFO
virtual void processPFO(const xAOD::TrackParticle *trk, const xAOD::FlowElement *pfo)=0
TCCHelpers::CombinedUFOLoop::m_trackVertexAssoTool
const CP::ITrackVertexAssociationTool * m_trackVertexAssoTool
Definition: TCCHelpers.h:46
TrackCaloClusterInfo
Definition: TrackCaloClusterInfo.h:23
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
MessageCheck.h
macros for messaging and checking status codes
TCCHelpers::CombinedUFOLoop::m_orig_FlowElemK
std::string m_orig_FlowElemK
Definition: TCCHelpers.h:41
TCCHelpers::CombinedUFOLoop::combinedUFOLoop
virtual void combinedUFOLoop(const TrackCaloClusterInfo *tccInfo, const xAOD::FlowElementContainer *pfos)
Definition: TCCHelpers.h:54
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TCCHelpers::CombinedUFOLoop::m_clustersLinkK
std::string m_clustersLinkK
Definition: TCCHelpers.h:42
TCCHelpers::CombinedUFOLoop::m_useEnergy
bool m_useEnergy
Definition: TCCHelpers.h:48
TCCHelpers
\bried Internal helper class for TCC & UFO building.
Definition: TrackCaloClusterInfoAlg.cxx:103
TrackCaloClusterInfo::pv0
const xAOD::Vertex * pv0
Definition: TrackCaloClusterInfo.h:34
xAOD::CaloCluster_v1::rawPhi
flt_t rawPhi() const
Get in signal state UNCALIBRATED.
xAOD::IParticle::eta
virtual double eta() const =0
The pseudorapidity ( ) of the particle.
TCCHelpers::CombinedUFOLoop::m_clusterEcut
float m_clusterEcut
Definition: TCCHelpers.h:47
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::IParticle::phi
virtual double phi() const =0
The azimuthal angle ( ) of the particle.
SG::ReadDecorHandleKey
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Definition: StoreGate/StoreGate/ReadDecorHandleKey.h:85
TCCHelpers::CombinedUFOLoop
Implements a loop over tracks and pflow object to build UFOs.
Definition: TCCHelpers.h:34
TCCHelpers::CombinedUFOLoop::~CombinedUFOLoop
virtual ~CombinedUFOLoop()
Definition: TCCHelpers.h:36
TCCHelpers::CombinedUFOLoop::m_linkdecorkey
const SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > * m_linkdecorkey
Definition: TCCHelpers.h:49
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25