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
30{
31 const EventContext& ctx = Gaudi::Hive::currentContext();
32
33 // retrieve the tracks collection
34
37 ATH_MSG_DEBUG( "Container '" << m_tracksCollectionName.key() << "' retrieved from StoreGate" );
38
39 // retrieve the electron collection
40
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
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}
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
virtual StatusCode doThinning() const override
EGammaTracksThinning(const std::string &type, const std::string &name, const IInterface *parent)
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