ATLAS Offline Software
Loading...
Searching...
No Matches
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() );
21 return StatusCode::SUCCESS;
22}
23
25
26 return StatusCode::SUCCESS;
27}
28
29StatusCode DerivationFramework::EGammaTracksThinning::doThinning(const EventContext& ctx) const
30{
31
32 // retrieve the tracks collection
33
36 ATH_MSG_DEBUG( "Container '" << m_tracksCollectionName.key() << "' retrieved from StoreGate" );
37
38 // retrieve the electron collection
39
41 if ( !electronContainer.isValid() )
42 {
43 ATH_MSG_WARNING( "Container '" << m_electronsContainerKey.key()
44 << "' could not be retrieved from StoreGate!" );
45 return StatusCode::FAILURE;
46 }
47 else
48 {
49 ATH_MSG_DEBUG( "Container '" << m_electronsContainerKey.key()
50 << "' retrieved from StoreGate" );
51 }
52
53 // retrieve the photon collection
54
56 if ( !photonContainer.isValid() )
57 {
58 ATH_MSG_WARNING( "Container '" << m_photonsContainerKey.key()
59 << "' could not be retrieved from StoreGate!" );
60 return StatusCode::FAILURE;
61 }
62 else
63 {
64 ATH_MSG_DEBUG( "Container '" << m_photonsContainerKey.key()
65 << "' retrieved from StoreGate" );
66 }
67
68 // loop over electrons and for each electron mark the interesting tracks
69
70 std::set<int> goodTrackIDs;
71
74 for (; eleItr != eleItrEnd; ++eleItr)
75 {
76 if ( (*eleItr)->pt() > m_minEtEg )
77 {
78
79 ATH_MSG_DEBUG( "Electron at eta = " << (*eleItr)->eta() << " phi = " << (*eleItr)->phi() );
80
81 // get the list of tracks associated to this object
82
83 std::set<int> eg_trackList = findGoodTracks(trackCollection.cptr(), (*eleItr)->p4(), m_dr );
84
85 // update the global list of tracks to keep
86
87 goodTrackIDs.insert(eg_trackList.begin() , eg_trackList.end() ) ;
88
89 }
90
91 }
92
93 // loop over photons and for each photon mark the interesting tracks
94
97 for (; phoItr != phoItrEnd; ++phoItr)
98 {
99 if ( (*phoItr)->pt() > m_minEtEg )
100 {
101
102 ATH_MSG_DEBUG( "Photon at eta = " << (*phoItr)->eta() << " phi = " << (*phoItr)->phi() );
103
104 // get the list of tracks associated to this object
105
106 std::set<int> eg_trackList = findGoodTracks(trackCollection.cptr(), (*phoItr)->p4(), m_dr );
107
108 // update the global list of tracks to keep
109
110 goodTrackIDs.insert(eg_trackList.begin() , eg_trackList.end() ) ;
111
112 }
113
114 }
115
116 // now do the real thinning and keep all marked tracks
117
118 ATH_CHECK( thinTracks( trackCollection, goodTrackIDs ) );
119
120 ATH_MSG_DEBUG( "Track thinning : tracks = " << trackCollection->size()
121 << " accepted = " << goodTrackIDs.size() );
122
123 return StatusCode::SUCCESS;
124}
125
126// ========================================================
127// For agiven electron/photon candidate this method
128// marks the interesing tracks
129// =======================================================
130
132 const TLorentzVector& candHepLorentz,
133 double maxDeltaR ) const
134{
135
136 std::set<int> goodTracks;
137
138 TrackCollection::const_iterator trackItr = trackCont->begin();
139 TrackCollection::const_iterator trackItrEnd = trackCont->end();
140 long int i=0; // This is the counter...
141 for (; trackItr != trackItrEnd; ++trackItr)
142 {
143 const Trk::Track* track = (*trackItr);
144
145 if (!track){ continue; }
146
147 // use track eta/phi at perigee
148
149 double trketa = 0.,trkphi = 0;
150 const Trk::Perigee* startPerigee = track->perigeeParameters();
151 trketa = startPerigee->eta();
152 trkphi = startPerigee->parameters()[Trk::phi0];
153
154 double deltaEta = trketa - candHepLorentz.Eta() ;
155 double deltaPhi = P4Helpers::deltaPhi(trkphi, candHepLorentz.Phi() );
156 double deltaR = sqrt(deltaEta*deltaEta+deltaPhi*deltaPhi);
157
158 ATH_MSG_DEBUG( "Thin Tracks: eta = " << trketa << " phi = " << trkphi << " deltaR = " << deltaR );
159 if ( deltaR < maxDeltaR )
160 {
161 goodTracks.insert( i );
162 ATH_MSG_DEBUG( " Track in the cone, adding: " << " eta=" << trketa << " phi=" << trkphi );
163 }
164
165 ++i; // Increment the counter
166
167 }
168
169 return goodTracks;
170
171}
172
173// ========================================================
174// Once the list of tracks is built this method does the real
175// thinning
176// =======================================================
177
179 const std::set<int>& goodTrackIDs ) const
180{
181
182 ATH_MSG_DEBUG( "==> thinTracks " << name() << "..." );
183
184 // Declare the simple StatusCode
185 StatusCode sc(StatusCode::SUCCESS);
186
187 // First, create the mask to be used for thinning
188
189 std::vector<bool> mask(trackCollection->size());
190
191 // Create also some bookkeeping counters
192 unsigned long nTotal = 0;
193 unsigned long nKeep = 0;
194 unsigned long nReject = 0;
195
196 // loop over tracks
197
198 for ( std::size_t i=0; i<trackCollection->size(); ++i )
199 {
200 ++nTotal;
201 if ( goodTrackIDs.find( i ) != goodTrackIDs.end() )
202 {
203 mask[i] = true;
204 ++nKeep;
205 }
206 else
207 {
208 mask[i] = false;
209 ++nReject;
210 }
211 } // End loop over Tracks
212
213 // Write out a statistics message
214 ATH_MSG_DEBUG( " EGammaTracksThinning statistics: tracks processed " << nTotal
215 << " kept = " << nKeep
216 << " rejected " << nReject );
217
218 // Perform the actual thinning
219 trackCollection.thin (mask);
220
222 return sc;
223
224}
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Handle for requesting thinning for a data object.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
xAOD::ElectronContainer * electronContainer
xAOD::PhotonContainer * photonContainer
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
SG::ThinningHandleKey< TrackCollection > m_tracksCollectionName
std::set< int > findGoodTracks(const TrackCollection *trackCont, const TLorentzVector &candHepLorentz, double maxDeltaR) const
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsContainerKey
StatusCode thinTracks(SG::ThinningHandle< TrackCollection > &trackCont, const std::set< int > &goodTracks) const
SG::ReadHandleKey< xAOD::PhotonContainer > m_photonsContainerKey
EGammaTracksThinning(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode doThinning(const EventContext &ctx) const override
void thin(size_t ndx)
Mark that index ndx in the container should be thinned away.
Handle for requesting thinning for a data object.
double eta() const
Access method for pseudorapidity - from momentum.
double deltaR(double eta1, double eta2, double phi1, double phi2)
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition P4Helpers.h:34
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ phi0
Definition ParamDefs.h:65