ATLAS Offline Software
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 
13 #include "xAODJet/JetContainer.h"
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 
65  ATH_CHECK(m_jetInputContainer_key.initialize());
67  ATH_CHECK(m_elInputContainer_key.initialize());
70 
71  return StatusCode::SUCCESS;
72 }
73 
74 
76 
77  using OutContTypeCl = ConstDataVector<xAOD::CaloClusterContainer>;
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
86  if(!m_useOnlyclInJets){
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 
106  using OutContTypeTr = ConstDataVector<xAOD::TrackParticleContainer>;
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 
128 std::vector<const xAOD::Electron*> JetInputElRemovalTool::selectElectron()const{
129 
130  std::vector<const xAOD::Electron*> selected_electrons_v;
131 
132  auto handle = SG::makeHandle(m_elInputContainer_key);
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 
143  SG::Decorator< char > idflagDec( m_elIDname );
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 
172 int 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 
181  auto handle = SG::makeHandle(m_clInputContainer_key);
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 
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 
254 int 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 
292 
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;
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 
332 int 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 
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 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::CaloCluster_v1::rawE
flt_t rawE() const
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JetInputElRemovalTool::m_clEMFrac
float m_clEMFrac
Definition: JetInputElRemovalTool.h:99
xAOD::JetConstituentVector::end
iterator end() const
iterator after the last constituent
Definition: JetConstituentVector.cxx:104
skel.it
it
Definition: skel.GENtoEVGEN.py:423
xAOD::JetConstituentVector::isValid
bool isValid() const
Check if element links are valid.
Definition: JetConstituentVector.cxx:92
JetInputElRemovalTool::m_elIDname
std::string m_elIDname
Definition: JetInputElRemovalTool.h:94
JetInputElRemovalTool::fillSelectedClustersInJets
int fillSelectedClustersInJets(std::vector< const xAOD::Electron * > &selected_el, ConstDataVector< xAOD::CaloClusterContainer > &selected_cl) const
Definition: JetInputElRemovalTool.cxx:254
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
TruthTest.itE
itE
Definition: TruthTest.py:25
EgammaContainer.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
JetInputElRemovalTool::m_trkOutputContainer_key
TrkOutHandleKey m_trkOutputContainer_key
Definition: JetInputElRemovalTool.h:114
JetInputElRemovalTool::m_trkInputContainer_key
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkInputContainer_key
Definition: JetInputElRemovalTool.h:101
xAOD::JetConstituentVector::begin
iterator begin() const
iterator on the first constituent
Definition: JetConstituentVector.cxx:103
JetInputElRemovalTool::selectElectron
std::vector< const xAOD::Electron * > selectElectron() const
Select the electron of the event My select :
Definition: JetInputElRemovalTool.cxx:128
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
JetInputElRemovalTool::execute
int execute() const
Method to be called for each event.
Definition: JetInputElRemovalTool.cxx:75
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
SG::Decorator< char >
JetInputElRemovalTool::m_clInputContainer_key
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clInputContainer_key
Definition: JetInputElRemovalTool.h:103
JetInputElRemovalTool::fillSelectedTracks
int fillSelectedTracks(std::vector< const xAOD::Electron * > &selected_el, ConstDataVector< xAOD::TrackParticleContainer > &selected_trk) const
Definition: JetInputElRemovalTool.cxx:332
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
JetInputElRemovalTool::m_clRemovRadius
float m_clRemovRadius
Definition: JetInputElRemovalTool.h:98
JetInputElRemovalTool::fillSelectedClusters
int fillSelectedClusters(std::vector< const xAOD::Electron * > &selected_el, ConstDataVector< xAOD::CaloClusterContainer > &selected_cl) const
: Select TopoClusters away of the electrons may select :
Definition: JetInputElRemovalTool.cxx:172
JetInputElRemovalTool.h
JetInputElRemovalTool::m_clOutputContainer_key
ClOutHandleKey m_clOutputContainer_key
Definition: JetInputElRemovalTool.h:109
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::JetConstituent::rawConstituent
const IParticle * rawConstituent() const
Access the real underlying IParticle.
Definition: JetConstituentVector.h:102
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
JetInputElRemovalTool::JetInputElRemovalTool
JetInputElRemovalTool(const std::string &t)
Definition: JetInputElRemovalTool.cxx:20
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
JetInputElRemovalTool::m_useOnlyclInJets
bool m_useOnlyclInJets
Definition: JetInputElRemovalTool.h:96
JetInputElRemovalTool::m_jetInputContainer_key
SG::ReadHandleKey< xAOD::JetContainer > m_jetInputContainer_key
Definition: JetInputElRemovalTool.h:102
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
JetInputElRemovalTool::m_elInputContainer_key
SG::ReadHandleKey< xAOD::EgammaContainer > m_elInputContainer_key
Definition: JetInputElRemovalTool.h:104
JetInputElRemovalTool::finalize
StatusCode finalize()
Definition: JetInputElRemovalTool.cxx:122
xAOD::Electron_v1
Definition: Electron_v1.h:34
plotIsoValidation.el_trk
el_trk
Definition: plotIsoValidation.py:166
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetInputElRemovalTool::m_elPt
float m_elPt
Definition: JetInputElRemovalTool.h:95
xAOD::CaloCluster_v1::eSample
float eSample(const CaloSample sampling) const
Definition: CaloCluster_v1.cxx:521
JetContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
xAOD::JetConstituentVector
A vector of jet constituents at the scale used during jet finding.
Definition: JetConstituentVector.h:117
xAOD::JetConstituentVector::iterator
Definition: JetConstituentVector.h:121
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
JetInputElRemovalTool::~JetInputElRemovalTool
~JetInputElRemovalTool()
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
Decorator.h
Helper class to provide type-safe access to aux data.
JetInputElRemovalTool::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetInputElRemovalTool.cxx:60
TrackParticleContainer.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56