ATLAS Offline Software
VHLowTrackJetFilterTool.cxx
Go to the documentation of this file.
1  /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 // VHLowTrackJetFilterTool.cxx, (c) ATLAS Detector software
8 
17 
18 
19 // Constructor
21  const std::string& n,
22  const IInterface* p ) :
23 AthAlgTool(t,n,p),
24 m_nEventsTotal(0),
25 m_nEventsPass(0),
26 m_nEventsPassJet(0),
27 m_nEventsPassElectron(0),
28 m_nEventsPassMuon(0),
29 m_nJetsPassAlphaMax(0),
30 m_nJetsPassCHF(0),
31 m_debug(true),
32 m_jetPtCut(0),
33 m_jetEtaCut(2.1),
34 m_TrackMinPt(400.0),
35 m_TrackZ0Max(0.3),
36 m_TrackD0Max(0.5),
37 m_AlphaMaxCut(0.05),
38 m_CHFCut(0.045),
39 m_nJetsReq(0),
40 m_electronIDKey("LHMedium"),
41 m_electronPtCut(0),
42 m_muonSelectionTool("CP::MuonSelectionTool/MuonSelectionTool"),
43 m_muonIDKey("Medium"),
44 m_muonPtCut(0)
45 
46 
47 {
48  declareInterface<DerivationFramework::ISkimmingTool>(this);
49  declareProperty("Debug", m_debug);
50 
51  declareProperty("JetPtCut", m_jetPtCut);
52  declareProperty("JetEtaCut", m_jetEtaCut);
53  declareProperty("TrackMinPt", m_TrackMinPt);
54  declareProperty("TrackZ0Max", m_TrackZ0Max);
55  declareProperty("TrackD0Max", m_TrackD0Max);
56  declareProperty("JetAlphaMaxCut", m_AlphaMaxCut);
57  declareProperty("JetCHFCut", m_CHFCut);
58  declareProperty("NJetsRequired", m_nJetsReq);
59 
60  declareProperty("ElectronIDKey", m_electronIDKey);
61  declareProperty("ElectronPtCut", m_electronPtCut);
62 
63  declareProperty("MuonIDKey", m_muonIDKey);
64  declareProperty("MuonPtCut", m_muonPtCut);
65 
66 }
67 
68 // Athena initialize
70 {
71  ATH_MSG_VERBOSE("initialize() ...");
72  ATH_CHECK(m_electronSGKey.initialize());
73  ATH_CHECK(m_electronIsoDecorKey.initialize());
74  ATH_CHECK(m_muonSGKey.initialize());
75  ATH_CHECK(m_muonIsoDecorKey.initialize());
76  ATH_CHECK(m_jetSGKey.initialize());
77  ATH_CHECK(m_jetBtagDecorKey.initialize());
78  ATH_CHECK(m_eventInfoKey.initialize());
79  ATH_CHECK(m_primaryVerticesKey.initialize());
80  return StatusCode::SUCCESS;
81 }
82 // Athena finalize
84 {
85  ATH_MSG_VERBOSE("finalize() ...");
86  ATH_MSG_INFO("Processed "<< m_nEventsTotal <<" events, "<< m_nEventsPass<<" events passed filter ");
87  ATH_MSG_INFO("Percent of events passed Jet filter "<< 100.0*(float)m_nEventsPassJet/(float)m_nEventsTotal <<" % ");
88  ATH_MSG_INFO("Percent of events passing CHF "<< 100.0*(float)m_nJetsPassCHF/(float)m_nEventsTotal <<" % ");
89  ATH_MSG_INFO("Percent of events passing alphaMax "<< 100.0*(float)m_nJetsPassAlphaMax/(float)m_nEventsTotal <<" % ");
90  ATH_MSG_INFO("Percent of events passed Electron filter "<< 100.0*(float)m_nEventsPassElectron/(float)m_nEventsTotal <<" % ");
91  ATH_MSG_INFO("Percent events passed Muon filter "<< 100.0*(float)m_nEventsPassMuon/(float)m_nEventsTotal <<" % ");
92  return StatusCode::SUCCESS;
93 }
94 
95 //-----------------------------------------------------------------------------------------------
96 
97 // The filter itself
99 {
101  typedef std::vector<TrackLink> TrackLinks;
102 
103  bool passesEl=false, passesMu=false, passesJet=false;
104  m_nEventsTotal++;
105 
106  SG::ReadHandle<xAOD::EventInfo> eventInfo(m_eventInfoKey);
107  if( !eventInfo.isValid() ) {
108  ATH_MSG_ERROR( "Could not retrieve event info" );
109  }
110 
111  //Vertex Container
112  SG::ReadHandle<xAOD::VertexContainer> vertices(m_primaryVerticesKey);
113  if( !eventInfo.isValid() ) {
114  ATH_MSG_FATAL("No vertex collection with name PrimaryVertices found in StoreGate!");
115  return false;
116  }
117 
118  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119 
120 
121  //electron portion
123  if( !electrons.isValid() ) {
124  ATH_MSG_FATAL("No electron collection with name " << m_electronSGKey << " found in StoreGate!");
125  return false;
126  }
127 
128 
129  // loop over the electrons in the container
130  for (auto electron : *electrons){
131 
132  if(electron->pt()<m_electronPtCut) continue;
133  if( (std::abs(electron->caloCluster()->etaBE(2))>1.37 && std::abs(electron->caloCluster()->etaBE(2))<1.52)
134  || std::abs(electron->caloCluster()->etaBE(2))>2.47 ) continue;
135 
136  if(electron->isolation(xAOD::Iso::topoetcone20)/electron->pt()>0.2) continue;
137 
138  bool passID=false;
139  if (!electron->passSelection(passID, m_electronIDKey)) {
140  ATH_MSG_WARNING("Cannot find the electron quality flag " << m_electronIDKey);
141  continue;
142  }
143  if(!passID) continue;
144 
145  for (auto vertex: *vertices){
146  // Select good primary vertex
147  if (vertex->vertexType() == xAOD::VxType::PriVtx) {
148  const xAOD::TrackParticle* tp = electron->trackParticle() ; //your input track particle from the electron
149  float sigd0 =std::abs( xAOD::TrackingHelpers::d0significance( tp, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(), eventInfo->beamPosSigmaXY() ));
150  double delta_z0 = tp->z0() + tp->vz() - vertex->z();
151  double theta = tp->theta();
152  float z0sintheta = std::abs(delta_z0 * sin(theta));
153 
154  if (sigd0>5) continue;
155  if (z0sintheta>0.5) continue;
156 
157  passesEl=true;
158  break;
159  }
160  }
161 
162  if (passesEl){
163  m_nEventsPassElectron++;
164  break;
165  }
166  }
167 
168 
169  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170 
171  //muon portion
172 
173  SG::ReadHandle<xAOD::MuonContainer> muons(m_muonSGKey);
174  if( !muons.isValid() ) {
175  ATH_MSG_FATAL("No muon collection with name " << m_muonSGKey << " found in StoreGate!");
176  return false;
177  }
178 
179 
180  for(auto muon : *muons){
181 
182  if (muon->pt()<m_muonPtCut) continue;
183  if (std::abs(muon->eta())>2.5) continue;
184  if (!(m_muonSelectionTool->passedMuonCuts(*muon))) continue;
185  if (muon->muonType()!=xAOD::Muon::Combined) continue;
186  if (muon->isolation(xAOD::Iso::topoetcone20)/muon->pt()>0.3) continue;
187 
188  for (auto vertex : *vertices) { // Select good primary vertex
189  if (vertex->vertexType() == xAOD::VxType::PriVtx) {
190  const xAOD::TrackParticle* tp = muon->primaryTrackParticle() ; //your input track particle from the electron
191 
192  double d0sig = xAOD::TrackingHelpers::d0significance( tp, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(), eventInfo->beamPosSigmaXY() );
193 
194  if (std::abs(d0sig)>3) continue;
195 
196  float delta_z0 = tp->z0() + tp->vz() - vertex->z();
197  float theta = tp->theta();
198  double z0sintheta = delta_z0 * sin(theta);
199 
200  if (std::abs(z0sintheta)>0.5) continue;
201 
202  passesMu = true;
203  break;
204  }
205  }
206 
207  if (passesMu) {
208  m_nEventsPassMuon++;
209  break;
210  }
211  }
212 
213  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
214 
215  //Jet portion
216 
217  int nJetsPassed=0;
219  if( !jets.isValid() ) {
220  ATH_MSG_WARNING("No Jet container found, will skip this event");
221  return false;
222  }
223 
224  std::vector<const xAOD::Jet*> goodJets;
225  for (auto jet : *jets) {
226 
227  if (jet->pt() < m_jetPtCut) continue;
228  if (std::abs(jet->eta()) > m_jetEtaCut) continue;
229 
230  TLorentzVector VJet = TLorentzVector(0.0,0.0,0.0,0.0);
231  VJet.SetPtEtaPhiE(jet->pt(), jet->eta(), jet->phi(), jet->e());
232 
233  float minDeltaR = 100;
234 
235  for (auto electron : *electrons ){
236 
237  if (electron->pt()<20000) continue;
238  if (std::abs(electron->eta())>2.47) continue;
239 
240  bool passLoose=false;
241  if (!electron->passSelection(passLoose, "LHLoose")){
242  ATH_MSG_WARNING("Cannot find the LHLoose electron quality flag");
243  continue;
244  }
245  if (!passLoose) continue;
246 
247  TLorentzVector VElec=electron->p4();
248  float deltaR = VJet.DeltaR(VElec);
249 
250  if (deltaR<minDeltaR) minDeltaR=deltaR;
251  }
252 
253  if (minDeltaR<0.2) continue;
254 
255  goodJets.push_back(jet);
256 
257  }
258 
259 
260  int jetNo=0;
261  for (auto jet : goodJets){
262  jetNo++;
263  if (jetNo>=3) break; //Only consider two leading jets
264 
265  TLorentzVector CHFNum = TLorentzVector(0.0,0.0,0.0,0.0);
266  const xAOD::BTagging *bjet(nullptr);
268  if (!bjet){
269  ATH_MSG_WARNING("Btag info unavailable");
270  continue;
271  }
272  static const SG::ConstAccessor<TrackLinks> BTagTrackToJetAssociatorAcc("BTagTrackToJetAssociator");
273  TrackLinks assocTracks = BTagTrackToJetAssociatorAcc(*bjet);
274 
275  std::vector<const xAOD::TrackParticle*> goodTracks;
276  for (auto track : assocTracks) {
277  if (!track.isValid()) continue;
278  goodTracks.push_back(*track);
279  }
280 
281  float alpha_max=-999;
282  for (auto vertex : *vertices) {
283  TLorentzVector alphaDen = TLorentzVector(0.0,0.0,0.0,0.0);
284  TLorentzVector alphaNum = TLorentzVector(0.0,0.0,0.0,0.0);
285  float alpha;
286 
287  for(auto track : goodTracks) {
288  if (track->pt() < m_TrackMinPt) continue;
289 
290  TLorentzVector VTrack = TLorentzVector(0.0,0.0,0.0,0.0);
291  VTrack.SetPtEtaPhiE(track->pt(),track->eta(), track->phi(), track->e());
292  alphaDen=alphaDen+VTrack;
293  if (std::abs(track->d0()) > m_TrackD0Max) continue;
294 
295  float z0 = track->z0() + track->vz() - vertex->z();
296  float theta = track->theta();
297  if (std::abs(z0*sin(theta)) > m_TrackZ0Max) continue;
298 
299  alphaNum=alphaNum+VTrack;
300  }
301  if (alphaDen.Pt()==0) alpha=-999;
302  else alpha = alphaNum.Pt()/alphaDen.Pt();
303 
304  if (alpha > alpha_max) alpha_max=alpha;
305  }
306 
307  CHFNum = TLorentzVector(0.0,0.0,0.0,0.0);
308  for(auto track : goodTracks) {
309  if (track->pt() < m_TrackMinPt) continue;
310  if (std::abs(track->d0()) > m_TrackD0Max) continue;
311 
312  TLorentzVector VTrack = TLorentzVector(0.0,0.0,0.0,0.0);
313  VTrack.SetPtEtaPhiE(track->pt(),track->eta(), track->phi(), track->e());
314  CHFNum=CHFNum+VTrack;
315 
316  }
317 
318  float chf = CHFNum.Pt()/jet->pt();
319 
320  if (alpha_max < m_AlphaMaxCut) m_nJetsPassAlphaMax++;
321  if (chf < m_CHFCut) m_nJetsPassCHF++;
322 
323  if (chf > m_CHFCut && alpha_max > m_AlphaMaxCut) continue;
324 
325  nJetsPassed++;
326 
327  }
328 
329  if (nJetsPassed >= m_nJetsReq){
330  passesJet=true;
331  m_nEventsPassJet++;
332  }
333 
334  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
335 
336  if (passesJet && (passesEl || passesMu)){
337  m_nEventsPass++;
338  return true;
339  }
340  else return false;
341 }
342 
BTaggingUtilities.h
python.BuildSignatureFlags.bjet
AthConfigFlags bjet(AthConfigFlags flags, str instanceName, str recoMode)
Definition: BuildSignatureFlags.py:335
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
VHLowTrackJetFilterTool.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DerivationFramework::VHLowTrackJetFilterTool::m_TrackMinPt
float m_TrackMinPt
Definition: VHLowTrackJetFilterTool.h:61
xAOD::Iso::topoetcone20
@ topoetcone20
Topo-cluster ET-sum.
Definition: IsolationType.h:48
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TrackParticlexAODHelpers.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrackLink
ElementLink< xAOD::TrackParticleContainer > TrackLink
Definition: MuonValidationPlots.cxx:11
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::VHLowTrackJetFilterTool::m_TrackZ0Max
float m_TrackZ0Max
Definition: VHLowTrackJetFilterTool.h:62
DerivationFramework::VHLowTrackJetFilterTool::m_jetPtCut
float m_jetPtCut
Definition: VHLowTrackJetFilterTool.h:59
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
xAOD::TrackingHelpers::d0significance
double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2)
Definition: TrackParticlexAODHelpers.cxx:42
DerivationFramework::VHLowTrackJetFilterTool::m_TrackD0Max
float m_TrackD0Max
Definition: VHLowTrackJetFilterTool.h:63
DerivationFramework::VHLowTrackJetFilterTool::m_AlphaMaxCut
float m_AlphaMaxCut
Definition: VHLowTrackJetFilterTool.h:64
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::EventInfo_v1::beamPosSigmaX
float beamPosSigmaX() const
The width of the beam spot in the X direction.
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::VHLowTrackJetFilterTool::m_electronIDKey
std::string m_electronIDKey
Definition: VHLowTrackJetFilterTool.h:69
DerivationFramework::VHLowTrackJetFilterTool::m_jetEtaCut
float m_jetEtaCut
Definition: VHLowTrackJetFilterTool.h:60
DerivationFramework::VHLowTrackJetFilterTool::VHLowTrackJetFilterTool
VHLowTrackJetFilterTool(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: VHLowTrackJetFilterTool.cxx:20
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
DerivationFramework::VHLowTrackJetFilterTool::m_debug
bool m_debug
Definition: VHLowTrackJetFilterTool.h:56
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TRT::Track::z0
@ z0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:63
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
xAOD::EventInfo_v1::beamPosSigmaY
float beamPosSigmaY() const
The width of the beam spot in the Y direction.
DerivationFramework::VHLowTrackJetFilterTool::m_CHFCut
float m_CHFCut
Definition: VHLowTrackJetFilterTool.h:65
BTaggingContainer.h
EventInfo.h
xAOD::BTaggingUtilities::getBTagging
const BTagging * getBTagging(const SG::AuxElement &part)
Access the default xAOD::BTagging object associated to an object.
Definition: BTaggingUtilities.cxx:37
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::EventInfo_v1::beamPosSigmaXY
float beamPosSigmaXY() const
The beam spot shape's X-Y correlation.
DerivationFramework::VHLowTrackJetFilterTool::finalize
virtual StatusCode finalize() override
Definition: VHLowTrackJetFilterTool.cxx:83
DerivationFramework::VHLowTrackJetFilterTool::initialize
virtual StatusCode initialize() override
Definition: VHLowTrackJetFilterTool.cxx:69
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::VHLowTrackJetFilterTool::m_electronPtCut
float m_electronPtCut
Definition: VHLowTrackJetFilterTool.h:70
DerivationFramework::VHLowTrackJetFilterTool::eventPassesFilter
virtual bool eventPassesFilter() const override
Check that the current event passes this filter.
Definition: VHLowTrackJetFilterTool.cxx:98
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
DerivationFramework::VHLowTrackJetFilterTool::m_nJetsReq
float m_nJetsReq
Definition: VHLowTrackJetFilterTool.h:66
DerivationFramework::VHLowTrackJetFilterTool::m_muonPtCut
float m_muonPtCut
Definition: VHLowTrackJetFilterTool.h:77
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
AthAlgTool
Definition: AthAlgTool.h:26
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
TrackingPrimitives.h
TrackParticleContainer.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
DerivationFramework::VHLowTrackJetFilterTool::m_muonIDKey
std::string m_muonIDKey
Definition: VHLowTrackJetFilterTool.h:74