ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaFastElectronReAlgo.cxx
Go to the documentation of this file.
1// -*- C++ -*-
2/*
3 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
4*/
5
6/**************************************************************************
7 ** Description: Hypothesis algorithms to be run at Level 2 after
8 ** tracking algorithms: creates TrigElectrons
9 **
10 ** Author: R.Goncalo <r.goncalo@rhul.ac.uk> Thu Jan 20 22:02:43 BST 2005
11 ** P.Urquijo <Phillip.Urquijo@cern.ch>
12 **
13 ** Created: Sat Mar 1 19:55:56 GMT 2005
14 ** Modified: RG 18 Mar 06 - fix to always generate TrigElectrons
15 ** - use key2keyStore for collection names
16 ** N.Berger Dec.06 - migrate to new steering (RG)
17 **************************************************************************/
18
24
25
26
27
28TrigEgammaFastElectronReAlgo::TrigEgammaFastElectronReAlgo(const std::string & name, ISvcLocator* pSvcLocator)
29 : AthReentrantAlgorithm(name, pSvcLocator)
30{}
31
32
34{
35 ATH_MSG_DEBUG("Initialization:");
36
37 if (!m_monTool.empty()) {
38 ATH_MSG_DEBUG("Retrieving monTool");
39 CHECK(m_monTool.retrieve());
40 } else {
41 ATH_MSG_DEBUG("No monTool configured => NO MONITOING");
42 }
43
44 if ( m_caloExtensionTool.retrieve().isFailure() ) {
45 ATH_MSG_ERROR("Unable to locate TrackExtrapolator tool ");
46 return StatusCode::FAILURE;
47 }
48
49 // print out settings
50 ATH_MSG_DEBUG("Initialization completed successfully:");
51 ATH_MSG_DEBUG( "AcceptAll = "<< (m_acceptAll==true ? "True" : "False"));
52 ATH_MSG_DEBUG("TrackPt = " << m_trackPtthr);
53 ATH_MSG_DEBUG("TrackPtHighEt = " << m_trackPtthr_highet);
54 ATH_MSG_DEBUG("ClusEt = " << m_clusEtthr);
55 ATH_MSG_DEBUG("CaloTrackdEtaNoExtrap= " << m_calotrkdeta_noextrap);
56 ATH_MSG_DEBUG("CaloTrackdEtaNoExtrapHighEt= " << m_calotrkdeta_noextrap_highet);
57 ATH_MSG_DEBUG("CaloTrackdETA = " << m_calotrackdeta);
58 ATH_MSG_DEBUG("CaloTrackdPHI = " << m_calotrackdphi);
59 ATH_MSG_DEBUG("CaloTrackdEoverPLow = " << m_calotrackdeoverp_low);
60 ATH_MSG_DEBUG("CaloTrackdEoverPHigh = " << m_calotrackdeoverp_high);
61
62 ATH_CHECK( m_roiCollectionKey.initialize() );
65 ATH_CHECK( m_caloDetDescrMgrKey.initialize() );
66 ATH_CHECK( m_outputElectronsKey.initialize() );
68
69 return StatusCode::SUCCESS;
70}
71
72
73
74StatusCode TrigEgammaFastElectronReAlgo::execute(const EventContext& ctx) const
75{
76 using namespace xAOD;
77
78 ATH_MSG_DEBUG( "Executing " <<name());
79
80 auto trigElecColl = SG::makeHandle (m_outputElectronsKey, ctx);
81 ATH_CHECK( trigElecColl.record (std::make_unique<xAOD::TrigElectronContainer>(),
82 std::make_unique<xAOD::TrigEMClusterAuxContainer>()) );
83
84 ATH_MSG_DEBUG( "Made WriteHandle " << m_outputElectronsKey );
85
86 auto trigDummyElecColl = SG::makeHandle (m_outputDummyElectronsKey, ctx);
87
88 ATH_MSG_DEBUG( "Made Dummy WriteHandle " << m_outputDummyElectronsKey );
89 ATH_CHECK( trigDummyElecColl.record (std::make_unique<xAOD::TrigElectronContainer>(),
90 std::make_unique<xAOD::TrigEMClusterAuxContainer>()) );
91
92 auto roiCollection = SG::makeHandle(m_roiCollectionKey, ctx);
93 ATH_MSG_DEBUG( "Made handle " << m_roiCollectionKey );
94
95
96 if (roiCollection->size()==0) {
97 ATH_MSG_DEBUG(" RoI collection size = 0");
98 return StatusCode::SUCCESS;
99 }
100
101 const TrigRoiDescriptor* roiDescriptor = *(roiCollection->begin());
102
103 ATH_MSG_DEBUG(" RoI ID = " << (roiDescriptor)->roiId() << ": Eta = " << (roiDescriptor)->eta()
104 << ", Phi = " << (roiDescriptor)->phi());
105
106 float calo_eta(999), calo_phi(999), calo_et(-1);
107
108 auto clusterCont = SG::makeHandle (m_TrigEMClusterContainerKey, ctx);
109 ATH_MSG_DEBUG( "Made handle " << m_TrigEMClusterContainerKey );
110
111 //JTB Should only be 1 cluster in each RoI
112
113 const xAOD::TrigEMCluster *emCluster=(*clusterCont->begin());
115
116 // copy relevant quantities to local variables
117 calo_eta = emCluster->eta();
118 calo_phi = emCluster->phi();
119 calo_et = emCluster->et();
120
121
122 // Transverse em energy
123 ATH_MSG_DEBUG("Cluster: ET=" << calo_et);
124 ATH_MSG_DEBUG("searching a matching track: loop over tracks");
125
127 ATH_MSG_DEBUG( "Made handle " << m_TrackParticleContainerKey );
128
129
130 if (tracks->size() == 0){
131 return StatusCode::SUCCESS; // Exit early if there are no tracks
132 }
133
134 size_t coll_size = tracks->size();
135 trigElecColl->reserve(coll_size);
136
137 // monitoring
138 std::vector<float> calotrkdeta_noextrap_mon;
139
140 auto caloPtMon = Monitored::Collection("PtCalo", *trigElecColl, getCaloPt );
141 auto trackPtMon = Monitored::Collection("PtTrack", *trigElecColl, getTkPt );
142 auto caloTrackDEtaMon = Monitored::Collection("CaloTrackdEta", *trigElecColl, &xAOD::TrigElectron::trkClusDeta );
143 auto caloTrackDPhiMon = Monitored::Collection("CaloTrackdPhi", *trigElecColl, &xAOD::TrigElectron::trkClusDphi );
144 auto etOverPtMon = Monitored::Collection("CaloTrackEoverP", *trigElecColl, &xAOD::TrigElectron::etOverPt );
145 auto caloTrackDEtaNoExtrapMon = Monitored::Collection("CaloTrackdEtaNoExtrapMon", calotrkdeta_noextrap_mon );
146
147 auto mon = Monitored::Group(m_monTool, caloPtMon, trackPtMon, caloTrackDEtaMon, caloTrackDPhiMon, etOverPtMon, caloTrackDEtaNoExtrapMon );
148
149 // Make Dummy Electron
150 xAOD::TrigElectron* trigDummyElec = new xAOD::TrigElectron();
151
153
154 trigDummyElecColl->push_back(trigDummyElec);
155 trigDummyElec->init( 0, 0, 0, 0, clusEL, trackDummyEL);
156
157 //Pick the Calo Det Descr
158 SG::ReadCondHandle<CaloDetDescrManager> caloDetDescrMgrHandle{
160 ATH_CHECK(caloDetDescrMgrHandle.isValid());
161 const CaloDetDescrManager* caloDD = *caloDetDescrMgrHandle;
162
163 // loop over tracks
164 for(unsigned int track_index = 0; track_index < tracks->size(); track_index++)
165 {
166 const xAOD::TrackParticle_v1* trkIter = (*tracks)[track_index];
167 ATH_MSG_DEBUG("Track loop starts");
168 ATH_MSG_VERBOSE("AlgoId = " << (trkIter)->patternRecoInfo());
169 ATH_MSG_VERBOSE("At perigee:");
170 ATH_MSG_DEBUG(" Pt = " << std::abs((trkIter)->pt()));
171 ATH_MSG_DEBUG(" phi = " << std::abs((trkIter)->phi0()));
172 ATH_MSG_DEBUG(" eta = " << std::abs((trkIter)->eta()));
173 ATH_MSG_DEBUG(" z0 = " << std::abs((trkIter)->z0()));
174 ATH_MSG_DEBUG(" d0 = " << std::abs((trkIter)->d0()));
175 // ============================================= //
176 // Pt cut
177 float trkPt = std::abs((trkIter)->pt());
178 float etoverpt = std::abs(calo_et/trkPt);
179 float calotrkdeta_noextrap = (trkIter)->eta() - calo_eta;
180
181 double etaAtCalo=999.;
182 double phiAtCalo=999.;
183 if(m_acceptAll){
184 if(!extrapolate(ctx,*caloDD,emCluster,trkIter,etaAtCalo,phiAtCalo)){
185 ATH_MSG_VERBOSE("extrapolator failed");
186 continue;
187 }
188 else{
189 ATH_MSG_VERBOSE("REGTEST: TrigElectron: cluster index = " << clusEL.index() <<
190 " eta = " << etaAtCalo << " phi = " << phiAtCalo);
191
192 xAOD::TrigElectron* trigElec = new xAOD::TrigElectron();
193 trigElecColl->push_back(trigElec);
195 trigElec->init( roiDescriptor->roiWord(),
196 etaAtCalo, phiAtCalo, etoverpt,
197 clusEL,
198 trackEL);
199 calotrkdeta_noextrap_mon.push_back(calotrkdeta_noextrap);
200 }
201 }else {
202
203 ATH_MSG_DEBUG("Apply cuts on track with index: "<<track_index);
204 if(trkPt < m_trackPtthr){
205 ATH_MSG_DEBUG("Failed track pt cut " << trkPt);
206 continue;
207 }
208 if(std::abs(calotrkdeta_noextrap) > m_calotrkdeta_noextrap){
209 ATH_MSG_DEBUG("Failed pre extrapolation calo track deta " << calotrkdeta_noextrap);
210 continue;
211 }
212 if(calo_et > m_clusEtthr){
213 if(trkPt < m_trackPtthr_highet){
214 ATH_MSG_DEBUG("Failed track pt cut for high et cluster");
215 continue;
216 }
217 if(calotrkdeta_noextrap > m_calotrkdeta_noextrap_highet){
218 ATH_MSG_DEBUG("Failed pre extrapolation calo track deta for high et");
219 continue;
220 }
221 }
222 if (etoverpt < m_calotrackdeoverp_low){
223 ATH_MSG_DEBUG("failed low cut on ET/PT");
224 continue;
225 }
226 if (etoverpt > m_calotrackdeoverp_high){
227 ATH_MSG_DEBUG("failed high cut on ET/PT");
228 continue;
229 }
230 if(!extrapolate(ctx,*caloDD,emCluster,trkIter,etaAtCalo,phiAtCalo)){
231 ATH_MSG_DEBUG("extrapolator failed 1");
232 continue;
233 }
234 // all ok: do track-matching cuts
235 ATH_MSG_DEBUG("extrapolated eta/phi=" << etaAtCalo << "/" << phiAtCalo);
236 // match in eta
237 float dEtaCalo = std::abs(etaAtCalo - calo_eta);
238 ATH_MSG_DEBUG("deta = " << dEtaCalo);
239 if ( dEtaCalo > m_calotrackdeta){
240 ATH_MSG_DEBUG("failed eta match cut " << dEtaCalo);
241 continue;
242 }
243 // match in phi: deal with differences larger than Pi
244 float dPhiCalo = std::abs(phiAtCalo - calo_phi);
245 dPhiCalo = ( dPhiCalo < M_PI ? dPhiCalo : 2*M_PI - dPhiCalo );
246 ATH_MSG_DEBUG("dphi = " << dPhiCalo);
247 if ( dPhiCalo > m_calotrackdphi) {
248 ATH_MSG_DEBUG("failed phi match cut " << dPhiCalo);
249 continue;
250 }
251 // all cuts passed
257 ATH_MSG_DEBUG("pT of trackEL: "<<(*trackEL)->pt());
258
259 ATH_MSG_DEBUG("REGTEST: TrigElectron: cluster index = " << clusEL.index() <<
260 " track index= " << track_index << " eta = " << etaAtCalo << " phi = " << phiAtCalo <<
261 " deta = " << dEtaCalo << "dphi = " << dPhiCalo);
262 xAOD::TrigElectron* trigElec = new xAOD::TrigElectron();
263 trigElecColl->push_back(trigElec);
264 trigElec->init( roiDescriptor->roiWord(),
265 etaAtCalo, phiAtCalo, etoverpt,
266 clusEL,
267 trackEL);
268
269 ATH_MSG_DEBUG(" deta = " << dEtaCalo << " deta = " << trigElec->trkClusDeta()
270 << " dphi = " << dPhiCalo << " dphi = " << trigElec->trkClusDphi()
271 << " caloEta = " << calo_eta << " caloEta = " << trigElec->caloEta()
272 << " caloPhi = " << calo_phi << " calophi = " << trigElec->caloPhi()
273 << " etaAtCalo = " << etaAtCalo << " etaAtCalo = " << trigElec->trkEtaAtCalo()
274 << " phiAtCalo = " << phiAtCalo << " phiAtCalo = " << trigElec->trkPhiAtCalo()
275 );
276 calotrkdeta_noextrap_mon.push_back(calotrkdeta_noextrap);
277
278 }
279
280 }
281
282
283 ATH_MSG_DEBUG("REGTEST: returning an xAOD::TrigElectronContainer with size "<< trigElecColl->size() << ".");
284
285 return StatusCode::SUCCESS;
286}
287
289 const EventContext& ctx, const CaloDetDescrManager& caloDD,
290 const xAOD::TrigEMCluster* clus, const xAOD::TrackParticle* trk,
291 double& etaAtCalo, double& phiAtCalo) const {
292
293 // use the provided EM cluster to "guide" the extrapolation
294 // 1st figure which layer we want to shoot at
295 // in this case we chose between EMB2 or EME2
296 // given the cluster.
297 std::vector<CaloSampling::CaloSample> samples;
298 if (clus->energy(CaloSampling::CaloSample::EME2) >
299 clus->energy(CaloSampling::CaloSample::EMB2)) {
300 samples.push_back(CaloSampling::CaloSample::EME2);
301 } else {
302 samples.push_back(CaloSampling::CaloSample::EMB2);
303 }
304
305 // create the surfaces we want to reach.
306 // Aka either a cylinder for EME2 or a disc for EMB2
307 std::vector<std::unique_ptr<Trk::Surface>> caloSurfaces =
308 m_caloExtensionTool->caloSurfacesFromLayers(samples, clus->eta(), caloDD);
309
310 // And then try to reach them
311 const auto extension = m_caloExtensionTool->surfaceCaloExtension(
312 ctx, trk->perigeeParameters(), samples, caloSurfaces,
314
315 if (extension.empty()) {
316 ATH_MSG_VERBOSE("extrapolator failed 1");
317 return false;
318 }
319 // We target exactly one EMB2 or EME2 (the vector has 1 entry if not empty)
320 etaAtCalo = extension[0].second->position().eta();
321 phiAtCalo = extension[0].second->position().phi();
322
323 ATH_MSG_VERBOSE("Hit sampling :" << extension.at(0).first << " at eta : "
324 << etaAtCalo << " at phi : " << phiAtCalo);
325
326 return true;
327}
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#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)
#define CHECK(...)
Evaluate an expression and check for errors.
Header file to be included by clients of the Monitored infrastructure.
An algorithm that can be simultaneously executed in multiple threads.
This class provides the client interface for accessing the detector description information common to...
Group of local monitoring quantities and retain correlation when filling histograms
Gaudi::Property< float > m_calotrackdeoverp_high
SG::WriteHandleKey< xAOD::TrigElectronContainer > m_outputElectronsKey
static double getCaloPt(const xAOD::TrigElectron *el)
Gaudi::Property< float > m_calotrkdeta_noextrap_highet
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloDetDescrMgrKey
Gaudi::Property< float > m_trackPtthr_highet
SG::ReadHandleKey< xAOD::TrigEMClusterContainer > m_TrigEMClusterContainerKey
bool extrapolate(const EventContext &ctx, const CaloDetDescrManager &caloDD, const xAOD::TrigEMCluster *, const xAOD::TrackParticle *, double &, double &) const
Gaudi::Property< float > m_calotrkdeta_noextrap
TrigEgammaFastElectronReAlgo(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackParticleContainerKey
static double getTkPt(const xAOD::TrigElectron *el)
Gaudi::Property< float > m_calotrackdeoverp_low
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
SG::WriteHandleKey< xAOD::TrigElectronContainer > m_outputDummyElectronsKey
ToolHandle< GenericMonitoringTool > m_monTool
ToolHandle< Trk::IParticleCaloExtensionTool > m_caloExtensionTool
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
virtual unsigned int roiWord() const override final
Class describing a TrackParticle.
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
float et() const
get Et (calibrated)
float eta() const
get Eta (calibrated)
float phi() const
get Phi (calibrated)
float energy() const
get Energy (calibrated)
float trkClusDeta() const
The absolute value of the track-calo eta measurement difference.
float trkEtaAtCalo() const
Get the track's pseudorapidity extrapolated to the calorimeter.
float trkPhiAtCalo() const
Get the track's azimuthal angle extrapolated to the calorimeter.
float etOverPt() const
Get for the electron.
float caloEta() const
Pseudorapidity ( ) of the electron in the calorimeter.
void init(uint32_t roi, float trkEtaAtCalo, float trkPhiAtCalo, float etOverPt, const EMClusterLink_t &clLink, const TrackParticleLink_t &tpLink)
Initialisation function, setting most properties of the object.
float caloPhi() const
Azimuthal angle ( ) of the electron in the calorimeter.
float trkClusDphi() const
The absolute value of the track-calo phi measurement difference.
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
setRcore setEtHad setFside pt
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrigElectron_v1 TrigElectron
Declare the latest version of the class.
TrigEMCluster_v1 TrigEMCluster
Define the latest version of the trigger EM cluster class.
setTeId setLumiBlock roiId