ATLAS Offline Software
EGammaTracksThinning.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
11  const std::string& name,
12  const IInterface* parent) :
13  base_class(type, name, parent)
14 {}
15 
17 
18  ATH_CHECK( m_electronsContainerKey.initialize() );
19  ATH_CHECK( m_photonsContainerKey.initialize() );
20  ATH_CHECK( m_tracksCollectionName.initialize (m_streamName) );
21  return StatusCode::SUCCESS;
22 }
23 
25 
26  return StatusCode::SUCCESS;
27 }
28 
30 {
31  const EventContext& ctx = Gaudi::Hive::currentContext();
32 
33  // retrieve the tracks collection
34 
36  (m_tracksCollectionName, ctx);
37  ATH_MSG_DEBUG( "Container '" << m_tracksCollectionName.key() << "' retrieved from StoreGate" );
38 
39  // retrieve the electron collection
40 
41  SG::ReadHandle<xAOD::ElectronContainer> electronContainer(m_electronsContainerKey, ctx);
42  if ( !electronContainer.isValid() )
43  {
44  ATH_MSG_WARNING( "Container '" << m_electronsContainerKey.key()
45  << "' could not be retrieved from StoreGate!" );
46  return StatusCode::FAILURE;
47  }
48  else
49  {
50  ATH_MSG_DEBUG( "Container '" << m_electronsContainerKey.key()
51  << "' retrieved from StoreGate" );
52  }
53 
54  // retrieve the photon collection
55 
56  SG::ReadHandle<xAOD::PhotonContainer> photonContainer(m_photonsContainerKey,ctx);
57  if ( !photonContainer.isValid() )
58  {
59  ATH_MSG_WARNING( "Container '" << m_photonsContainerKey.key()
60  << "' could not be retrieved from StoreGate!" );
61  return StatusCode::FAILURE;
62  }
63  else
64  {
65  ATH_MSG_DEBUG( "Container '" << m_photonsContainerKey.key()
66  << "' retrieved from StoreGate" );
67  }
68 
69  // loop over electrons and for each electron mark the interesting tracks
70 
71  std::set<int> goodTrackIDs;
72 
75  for (; eleItr != eleItrEnd; ++eleItr)
76  {
77  if ( (*eleItr)->pt() > m_minEtEg )
78  {
79 
80  ATH_MSG_DEBUG( "Electron at eta = " << (*eleItr)->eta() << " phi = " << (*eleItr)->phi() );
81 
82  // get the list of tracks associated to this object
83 
84  std::set<int> eg_trackList = findGoodTracks(trackCollection.cptr(), (*eleItr)->p4(), m_dr );
85 
86  // update the global list of tracks to keep
87 
88  goodTrackIDs.insert(eg_trackList.begin() , eg_trackList.end() ) ;
89 
90  }
91 
92  }
93 
94  // loop over photons and for each photon mark the interesting tracks
95 
98  for (; phoItr != phoItrEnd; ++phoItr)
99  {
100  if ( (*phoItr)->pt() > m_minEtEg )
101  {
102 
103  ATH_MSG_DEBUG( "Photon at eta = " << (*phoItr)->eta() << " phi = " << (*phoItr)->phi() );
104 
105  // get the list of tracks associated to this object
106 
107  std::set<int> eg_trackList = findGoodTracks(trackCollection.cptr(), (*phoItr)->p4(), m_dr );
108 
109  // update the global list of tracks to keep
110 
111  goodTrackIDs.insert(eg_trackList.begin() , eg_trackList.end() ) ;
112 
113  }
114 
115  }
116 
117  // now do the real thinning and keep all marked tracks
118 
119  ATH_CHECK( thinTracks( trackCollection, goodTrackIDs ) );
120 
121  ATH_MSG_DEBUG( "Track thinning : tracks = " << trackCollection->size()
122  << " accepted = " << goodTrackIDs.size() );
123 
124  return StatusCode::SUCCESS;
125 }
126 
127 // ========================================================
128 // For agiven electron/photon candidate this method
129 // marks the interesing tracks
130 // =======================================================
131 
133  const TLorentzVector& candHepLorentz,
134  double maxDeltaR ) const
135 {
136 
137  std::set<int> goodTracks;
138 
139  TrackCollection::const_iterator trackItr = trackCont->begin();
140  TrackCollection::const_iterator trackItrEnd = trackCont->end();
141  long int i=0; // This is the counter...
142  for (; trackItr != trackItrEnd; ++trackItr)
143  {
144  const Trk::Track* track = (*trackItr);
145 
146  if (!track){ continue; }
147 
148  // use track eta/phi at perigee
149 
150  double trketa = 0.,trkphi = 0;
151  const Trk::Perigee* startPerigee = track->perigeeParameters();
152  trketa = startPerigee->eta();
153  trkphi = startPerigee->parameters()[Trk::phi0];
154 
155  double deltaEta = trketa - candHepLorentz.Eta() ;
156  double deltaPhi = P4Helpers::deltaPhi(trkphi, candHepLorentz.Phi() );
157  double deltaR = sqrt(deltaEta*deltaEta+deltaPhi*deltaPhi);
158 
159  ATH_MSG_DEBUG( "Thin Tracks: eta = " << trketa << " phi = " << trkphi << " deltaR = " << deltaR );
160  if ( deltaR < maxDeltaR )
161  {
162  goodTracks.insert( i );
163  ATH_MSG_DEBUG( " Track in the cone, adding: " << " eta=" << trketa << " phi=" << trkphi );
164  }
165 
166  ++i; // Increment the counter
167 
168  }
169 
170  return goodTracks;
171 
172 }
173 
174 // ========================================================
175 // Once the list of tracks is built this method does the real
176 // thinning
177 // =======================================================
178 
180  const std::set<int>& goodTrackIDs ) const
181 {
182 
183  ATH_MSG_DEBUG( "==> thinTracks " << name() << "..." );
184 
185  // Declare the simple StatusCode
186  StatusCode sc(StatusCode::SUCCESS);
187 
188  // First, create the mask to be used for thinning
189 
190  std::vector<bool> mask(trackCollection->size());
191 
192  // Create also some bookkeeping counters
193  unsigned long nTotal = 0;
194  unsigned long nKeep = 0;
195  unsigned long nReject = 0;
196 
197  // loop over tracks
198 
199  for ( std::size_t i=0; i<trackCollection->size(); ++i )
200  {
201  ++nTotal;
202  if ( goodTrackIDs.find( i ) != goodTrackIDs.end() )
203  {
204  mask[i] = true;
205  ++nKeep;
206  }
207  else
208  {
209  mask[i] = false;
210  ++nReject;
211  }
212  } // End loop over Tracks
213 
214  // Write out a statistics message
215  ATH_MSG_DEBUG( " EGammaTracksThinning statistics: tracks processed " << nTotal
216  << " kept = " << nKeep
217  << " rejected " << nReject );
218 
219  // Perform the actual thinning
220  trackCollection.thin (mask);
221 
223  return sc;
224 
225 }
DerivationFramework::EGammaTracksThinning::finalize
virtual StatusCode finalize() override
Definition: EGammaTracksThinning.cxx:24
DerivationFramework::EGammaTracksThinning::initialize
virtual StatusCode initialize() override
Definition: EGammaTracksThinning.cxx:16
electronContainer
xAOD::ElectronContainer * electronContainer
Definition: TrigGlobEffCorrValidation.cxx:187
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TrackParameters.h
DerivationFramework::EGammaTracksThinning::thinTracks
StatusCode thinTracks(SG::ThinningHandle< TrackCollection > &trackCont, const std::set< int > &goodTracks) const
Definition: EGammaTracksThinning.cxx:179
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
DerivationFramework::EGammaTracksThinning::doThinning
virtual StatusCode doThinning() const override
Definition: EGammaTracksThinning.cxx:29
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
DerivationFramework::EGammaTracksThinning::EGammaTracksThinning
EGammaTracksThinning(const std::string &type, const std::string &name, const IInterface *parent)
Definition: EGammaTracksThinning.cxx:10
P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: P4Helpers.h:29
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:53
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ThinningHandleBase::thin
void thin(size_t ndx)
Mark that index ndx in the container should be thinned away.
Definition: ThinningHandleBase.cxx:57
DataVector< Trk::Track >
photonContainer
xAOD::PhotonContainer * photonContainer
Definition: TrigGlobEffCorrValidation.cxx:189
P4Helpers.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
EGammaTracksThinning.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
DerivationFramework::EGammaTracksThinning::findGoodTracks
std::set< int > findGoodTracks(const TrackCollection *trackCont, const TLorentzVector &candHepLorentz, double maxDeltaR) const
Definition: EGammaTracksThinning.cxx:132
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
Trk::phi0
@ phi0
Definition: ParamDefs.h:71
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.