ATLAS Offline Software
Loading...
Searching...
No Matches
JetInputElRemovalTool.cxx
Go to the documentation of this file.
1//-*- C++ -*-
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
8// Author: Clement Camincher (ccaminch@cern.ch)
10
17
18
19
21 :AsgTool(t)
22
23 ,m_elIDname("DFCommonElectronsLHTight")
24 ,m_elPt(25000)
25 ,m_useOnlyclInJets(false)
26 ,m_clRemovRadius(0.15)
27 ,m_clEMFrac(0.8)
28{
29 declareProperty("ElectronQuality",m_elIDname);
30 declareProperty("ElectronMinpT",m_elPt);
31 declareProperty("ClusterRemovRadius",m_clRemovRadius);
32 declareProperty("ClusterEMFrac",m_clEMFrac);
33 declareProperty("UseOnlyclInJets",m_useOnlyclInJets);
34
35 declareProperty("TrkInputContainer",
36 m_trkInputContainer_key="InDetTrackParticles");
37
38 declareProperty("JetINputContainer",
39 m_jetInputContainer_key="AntiKt4EMTopoJets");
40
41
42 declareProperty("ClusterContainerName",
43 m_clInputContainer_key="CaloCalTopoClusters");
44
45 declareProperty("ElectronContainerName",
46 m_elInputContainer_key="Electrons");
47
48 declareProperty("ClusterNoElName",
49 m_clOutputContainer_key="CaloCalTopoClustersNoEl");
50
51 declareProperty("TrkOutputContainer",
52 m_trkOutputContainer_key="InDetTrackParticlesNoEl");
53
54
55}
56
58
59
61 ATH_MSG_INFO("Initializing tool " << name() << "...");
62 ATH_MSG_DEBUG("initializing version with data handles");
63
70
71 return StatusCode::SUCCESS;
72}
73
74
76
78 OutContTypeCl* filtered_clusters = new OutContTypeCl(SG::VIEW_ELEMENTS);
79
80 //Select the electrons with given properties
81 std::vector<const xAOD::Electron*> el_vector=selectElectron();
82
83 //Select the clusters away from electrons
84
85 //Use all the clusters in the event
87 fillSelectedClusters(el_vector,*filtered_clusters);
88 }
89 //Use only the cluster from jets in the event
90 else{
91 fillSelectedClustersInJets(el_vector,*filtered_clusters);
92 }
93
94 //Record clusters vector
95 {
97 if(!handle.record(std::unique_ptr<OutContTypeCl>(filtered_clusters))){
98 ATH_MSG_WARNING("Unable to record new clusters vector");
99 return 1;
100 }
101 }
102
103 //Store vector only if data vector name not empty
104 if (!m_trkInputContainer_key.key().empty()){
105
107
108 OutContTypeTr* filtered_tracks = new OutContTypeTr(SG::VIEW_ELEMENTS) ;
109
110 fillSelectedTracks(el_vector,*filtered_tracks);
111
112 auto handle_out = SG::makeHandle(m_trkOutputContainer_key);
113 if(!handle_out.record(std::unique_ptr<OutContTypeTr>(filtered_tracks))){
114 ATH_MSG_WARNING("Unable to record new tracks vector");
115 return 1;
116 }
117 }
118
119 return 0;
120}
121
123 return StatusCode::SUCCESS;
124}
125
126
127
128std::vector<const xAOD::Electron*> JetInputElRemovalTool::selectElectron()const{
129
130 std::vector<const xAOD::Electron*> selected_electrons_v;
131
133 if(!handle.isValid()){
134 ATH_MSG_WARNING("Unable to retrieve electrons");
135 return selected_electrons_v;
136 }
137
138 const auto *electrons = handle.cptr();
139
140 selected_electrons_v.clear();
141 bool isTight=false;
142
144 for (const auto *electron_itr : *electrons){
145
146 isTight=false;
147
148 //Select only el with given quality
149 if (idflagDec (*electron_itr)==1){
150 isTight=true;
151 }
152
153 if (! isTight) continue ;
154
155
156 //Select only el with pt>25GeV
157 if (electron_itr->pt()<m_elPt) continue;
158
159 selected_electrons_v.push_back(dynamic_cast<const xAOD::Electron*>(electron_itr));
160
161
162 }
163
164 return selected_electrons_v ;
165}
166
167
168
169
170
171
172int JetInputElRemovalTool::fillSelectedClusters(std::vector<const xAOD::Electron*>&selected_el,ConstDataVector<xAOD::CaloClusterContainer> & selected_cl)const{
173
174 //Initialize variables
175
176 int countRemoved_clusters=0;
177 double propEM=0;
178
179 //Get the Topo clusters of the event
180
182 if(!handle.isValid()){
183 ATH_MSG_WARNING("Unable to retrieve clusters");
184 return 0;
185 }
186
187 const auto *clusterContainer = handle.cptr();
188
189 //Loop over all the clusters
190 for (const xAOD::CaloCluster* cluster_itr : *clusterContainer){
191
192 //Compute the EMP proportion of the cluster
193 propEM=0;
194
195 double EMB_Enegy=cluster_itr->eSample(CaloSampling::CaloSample::PreSamplerB)+cluster_itr->eSample(CaloSampling::CaloSample::EMB1)+cluster_itr->eSample(CaloSampling::CaloSample::EMB2)+cluster_itr->eSample(CaloSampling::CaloSample::EMB3);
196
197 double EMEC_Energy=cluster_itr->eSample(CaloSampling::CaloSample::PreSamplerE)+cluster_itr->eSample(CaloSampling::CaloSample::EME1)+cluster_itr->eSample(CaloSampling::CaloSample::EME2)+cluster_itr->eSample(CaloSampling::CaloSample::EME3);
198
199 //Remove clusters w/o energy
200 if (cluster_itr->rawE()==0) {
201 continue;
202 }
203 propEM=(EMB_Enegy+EMEC_Energy)/cluster_itr->rawE();
204
205
206
207 //Check if close to electron
208 bool closetoel=false;
209
210 std::vector<const xAOD::Electron*>::iterator it=selected_el.begin();
211 std::vector<const xAOD::Electron*>::iterator itE =selected_el.end();
212 //For each el in the vector
213 for ( ; it != itE ;++it){
214 ATH_MSG_DEBUG( "Deleta R electron cluster = "<<(*it)->p4().DeltaR(cluster_itr->p4()) );
215 //Check if electron close to cluster
216 //if ((*it)->p4().DeltaR(cluster_itr->p4())<m_clRemovRadius){
217 if ((*it)->caloCluster()->p4().DeltaR(cluster_itr->p4())<m_clRemovRadius){
218
219 //if (TMath::Abs((*it)->caloCluster()->etaBE(2))<1.52 && TMath::Abs((*it)->caloCluster()->etaBE(2))>1.37){
220 if (TMath::Abs(cluster_itr->eta())<1.52 && TMath::Abs(cluster_itr->eta())>1.37){
221 closetoel=true;
222 }
223
224 //Check if the proportion of EM enegy above threshold
225 else if(propEM>=m_clEMFrac){
226 closetoel=true;
227 }
228 }
229
230 }
231 //If not close enough or not enough EM energy the cluster is kept
232 if (!closetoel){
233 selected_cl.push_back(dynamic_cast<const xAOD::CaloCluster*> (cluster_itr));
234 }
235 else{ //else it is removed
236 countRemoved_clusters+=1;
237 }
238 }//End loop over clusters
239
240
241 //ANA_CHECK(evtStore()->record( filtered_clusters , "CaloCalTopoClustersNoElec" ));
242
243 return countRemoved_clusters;
244}//End of SelectClusters()
245
246
247
248
249
250
251
252
253
254int JetInputElRemovalTool::fillSelectedClustersInJets(std::vector<const xAOD::Electron*>&selected_el,ConstDataVector<xAOD::CaloClusterContainer> & selected_cl)const{
255
256 int countRemoved_clusters=0;
257 double propEM=0;
258
260 if(!handle.isValid()){
261 ATH_MSG_WARNING("Unable to retrieve jets");
262 return 0;
263 }
264
265 const auto *jetsContainer = handle.cptr();
266
267 // const xAOD::JetContainer* jetsContainer;
268 // StatusCode sc=evtStore()->retrieve( jetsContainer, m_jetINputContainer );
269 // if (sc.isFailure()){
270 // ATH_MSG_WARNING("Unable to retrieve jets");
271 // return 0;
272 // }
273
274 for (const xAOD::Jet* jet_itr : *jetsContainer){
275
276
277 const xAOD::JetConstituentVector jetcons = jet_itr->getConstituents();
278
279
280 if (!jetcons.isValid()) continue ;
281
282 xAOD::JetConstituentVector::iterator jetcons_it = jetcons.begin();
283 xAOD::JetConstituentVector::iterator jetcons_itE = jetcons.end();
284
285 for( ; jetcons_it != jetcons_itE; ++jetcons_it){
286
287 propEM=0;
288 const xAOD::CaloCluster* cluster_itr= dynamic_cast<const xAOD::CaloCluster*> (jetcons_it->rawConstituent());
289
290
291 double EMB_Enegy=cluster_itr->eSample(CaloSampling::CaloSample::PreSamplerB)+cluster_itr->eSample(CaloSampling::CaloSample::EMB1)+cluster_itr->eSample(CaloSampling::CaloSample::EMB2)+cluster_itr->eSample(CaloSampling::CaloSample::EMB3);
292
293 double EMEC_Energy=cluster_itr->eSample(CaloSampling::CaloSample::PreSamplerE)+cluster_itr->eSample(CaloSampling::CaloSample::EME1)+cluster_itr->eSample(CaloSampling::CaloSample::EME2)+cluster_itr->eSample(CaloSampling::CaloSample::EME3);
294
295
296 //Remove Clusters w/o energy
297 if (cluster_itr->rawE()==0) {
298 continue;
299 };
300
301 propEM=(EMB_Enegy+EMEC_Energy)/cluster_itr->rawE();
302
303 bool closetoel=false;
304 std::vector<const xAOD::Electron*>::iterator it=selected_el.begin();
305 std::vector<const xAOD::Electron*>::iterator itE =selected_el.end();
306
307 for ( ; it != itE ;++it){
308 ATH_MSG_DEBUG( "Deleta R electron cluster = "<<(*it)->p4().DeltaR(cluster_itr->p4()) );
309 if ((*it)->p4().DeltaR(cluster_itr->p4())<m_clRemovRadius){
310 if(propEM>=m_clEMFrac){
311 closetoel=true;
312 }
313 }
314
315 }
316 if (!closetoel){
317 selected_cl.push_back(dynamic_cast<const xAOD::CaloCluster*> (cluster_itr));
318 }
319 else{
320 countRemoved_clusters+=1;
321 }
322 }//End loop over clusters
323
324 }//End loop over jets
325
326 //ANA_CHECK(evtStore()->record( filtered_clusters , "CaloCalTopoClustersNoElec" ));
327
328 return countRemoved_clusters;
329}
330
331
332int JetInputElRemovalTool::fillSelectedTracks(std::vector<const xAOD::Electron*>&selected_el,ConstDataVector<xAOD::TrackParticleContainer> & selected_cl)const{
333
334 int countRemoved_trk=0;
335
337 if(!handle.isValid()){
338 ATH_MSG_WARNING("Unable to retrieve jets");
339 return 0;
340 }
341
342 const auto *tkPrtclContainer = handle.cptr();
343
344 // PS
345 // const xAOD::TrackParticleContainer* tkPrtclContainer;
346 // StatusCode sc=evtStore()->retrieve( tkPrtclContainer, m_trkInputContainer );
347 // if (sc.isFailure()){
348 // ATH_MSG_WARNING("Unable to retrieve jets");
349 // return 0;
350 // }
351
352 //Loop over all the tracks
353 for (const xAOD::TrackParticle* trk_itr : *tkPrtclContainer){
354
355 //Check if close to electron
356 bool is_eltrk=false;
357
358 std::vector<const xAOD::Electron*>::iterator it=selected_el.begin();
359 std::vector<const xAOD::Electron*>::iterator itE =selected_el.end();
360 //For each el in the vector
361 for ( ; it != itE ;++it){
362
363 const xAOD::TrackParticle* el_trk=(*it)->trackParticle();
364
365 ATH_MSG_DEBUG( "Deleta R electron trkack = "<<(*it)->p4().DeltaR(trk_itr->p4()) );
366 //Check if electron close to cluster
367 if (el_trk==trk_itr){
368 is_eltrk=true;
369 }
370
371 }
372 //If not close enough or not enough EM energy the cluster is kept
373 if (!is_eltrk){
374 selected_cl.push_back(dynamic_cast<const xAOD::TrackParticle*> (trk_itr));
375 }
376 else{ //else it is removed
377 countRemoved_trk+=1;
378 }
379 }//End loop over tracks
380
381
382 return countRemoved_trk;
383}
384
385
386
387
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for recording to StoreGate.
Helper class to provide type-safe access to aux data.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ClOutHandleKey m_clOutputContainer_key
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clInputContainer_key
int fillSelectedClusters(std::vector< const xAOD::Electron * > &selected_el, ConstDataVector< xAOD::CaloClusterContainer > &selected_cl) const
: Select TopoClusters away of the electrons may select :
StatusCode initialize()
Dummy implementation of the initialisation function.
SG::ReadHandleKey< xAOD::EgammaContainer > m_elInputContainer_key
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkInputContainer_key
int fillSelectedClustersInJets(std::vector< const xAOD::Electron * > &selected_el, ConstDataVector< xAOD::CaloClusterContainer > &selected_cl) const
JetInputElRemovalTool(const std::string &t)
std::vector< const xAOD::Electron * > selectElectron() const
Select the electron of the event My select :
int execute() const
Method to be called for each event.
TrkOutHandleKey m_trkOutputContainer_key
int fillSelectedTracks(std::vector< const xAOD::Electron * > &selected_el, ConstDataVector< xAOD::TrackParticleContainer > &selected_trk) const
SG::ReadHandleKey< xAOD::JetContainer > m_jetInputContainer_key
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
flt_t rawE() const
float eSample(const CaloSample sampling) const
virtual FourMom_t p4() const
The full 4-momentum of the particle.
A vector of jet constituents at the scale used during jet finding.
iterator begin() const
iterator on the first constituent
bool isValid() const
Check if element links are valid.
iterator end() const
iterator after the last constituent
const IParticle * rawConstituent() const
Access the real underlying IParticle.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Jet_v1 Jet
Definition of the current "jet version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Electron_v1 Electron
Definition of the current "egamma version".