ATLAS Offline Software
Loading...
Searching...
No Matches
PhysicsTriggerVariablePlots.cxx
Go to the documentation of this file.
1//Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3
5
9
12
13#include "CxxUtils/phihelper.h"
14
15namespace FTAGValidation {
16
18 ISvcLocator* pSvcLocator ) :
19 PhysicsVariablePlots( name, pSvcLocator )
21 {
22 declareProperty("bJetChains", m_bJetChains);
23 }
24
26
27 /* ===================================================================== */
28
30 ATH_MSG_INFO( "Inizializing " << name() << " ..." );
32
33 ATH_MSG_INFO( "Properties declaration:" );
34 ATH_MSG_INFO( " -- " << m_trigVertexKey );
35 ATH_MSG_INFO( " -- " << m_trigTrackKey );
36 ATH_MSG_INFO( " -- " << m_offJetKey );
37 ATH_MSG_INFO( " -- " << m_trigDec );
38 ATH_MSG_INFO( " -- " << m_bJetChains );
39
40 ATH_MSG_INFO( " -- " << m_minJetEta );
41 ATH_MSG_INFO( " -- " << m_maxJetEta );
42 ATH_MSG_INFO( " -- " << m_minJetPt );
43
44 ATH_CHECK( m_trigVertexKey.initialize() );
45 ATH_CHECK( m_trigTrackKey.initialize() );
46 ATH_CHECK( m_offJetKey.initialize() );
47
49
51 m_nTotal_noPV = 0;
55
56 return StatusCode::SUCCESS;
57 }
58
59 StatusCode PhysicsTriggerVariablePlots::execute(const EventContext& ctx) {
60 ATH_MSG_DEBUG( "Executing " << name() << " ..." );
62
63 /* =========================================================================================================================================== */
64 /* ==== Retrieve Collections */
65 /* =========================================================================================================================================== */
66
67 // Event Info
69 ATH_CHECK( eventInfoHandle.isValid() );
70 const xAOD::EventInfo *eventInfo = eventInfoHandle.get();
71
72 // Retrieve Offline-Jet Collection
73 const xAOD::JetContainer *offlineJetCollection = nullptr;
74 ATH_CHECK( retrieveCollectionfromStoreGate( ctx,offlineJetCollection,m_offJetKey ) );
75
76 std::vector< const xAOD::Jet* > qualityOfflineJetCollection;
77 for ( const xAOD::Jet *jet : *offlineJetCollection ) {
78 //For the moment running without offline jet quality requirments
79 //if ( not passJetQualitySelection( jet ) ) continue;
80 //if ( not passJetKinematicSelection( jet ) ) continue;
81 //if ( not passJetJVTSelection( jet ) ) continue;
82 qualityOfflineJetCollection.push_back( jet );
83 }
84
85 //run over b-jet chains
86 for( const std::string& chain: m_bJetChains ){
87 if( m_trigDec->isPassed(chain) ){
88 ATH_MSG_DEBUG("Chain passed " << chain);
89 }
90 else{
91 ATH_MSG_DEBUG("Chain did not pass " << chain);
92 continue;
93 }
94
95 // ==== Primary Vertex =================
96 // Chain is passed, only one PV per event, retrieve it in a standard way, filled once, doesnt matter how many jets
97 const xAOD::VertexContainer *vertexCollection = nullptr;
99 const xAOD::Vertex *primaryVertex = getPrimaryVertex( vertexCollection );
100 if ( primaryVertex == nullptr ) {
101 ATH_MSG_WARNING( "Could not retrieve Primary Vertex. Skip this event!" );
103 return StatusCode::SUCCESS;
104 }
105 ATH_CHECK( fillHistogram( chain + "_nPrimVtx", vertexCollection->size() ) );
106 ATH_CHECK( fillHistogram( chain + "_nTracksPrimVtx", primaryVertex->nTrackParticles() ) );
107 ATH_CHECK( fillHistogram( chain + "_PV_x", primaryVertex->x() ) );
108 ATH_CHECK( fillHistogram( chain + "_PV_y", primaryVertex->y() ) );
109 ATH_CHECK( fillHistogram( chain + "_PV_z", primaryVertex->z() ) );
110
111 // ==== Tracks =========================
112 const xAOD::TrackParticleContainer *trackParticleCollection = nullptr;
113 ATH_CHECK( retrieveCollectionfromStoreGate( ctx,trackParticleCollection,m_trigTrackKey) );
114 ATH_CHECK( fillHistogram( chain + "_nTracks",trackParticleCollection->size() ) );
115
116 // ==== Jet ============================
117 int nJetsWithMuon = 0;
118 int nJetsWithSV = 0;
119
120 std::vector< TrigCompositeUtils::LinkInfo<xAOD::JetContainer> > onlineJets = m_trigDec->features<xAOD::JetContainer>(chain, TrigDefs::Physics);
121 ATH_MSG_DEBUG("onlineJets.size(): " << onlineJets.size() );
122 int n_qualityJets = 0;
123 for( const auto& jetLinkInfo : onlineJets ) {
124 const xAOD::Jet* jet = *(jetLinkInfo.link);
125 //Check quality requirement
126 if ( not passTriggerJetKinematicSelection( jet ) ) continue;
127 n_qualityJets++;
129
130 ATH_MSG_DEBUG( "JET KINEMATICS:" );
131 ATH_MSG_DEBUG( " ** pt=" << jet->p4().Et() / Gaudi::Units::GeV << " eta=" << jet->eta() << " phi=" << jet->phi() );
132 ATH_CHECK( fillHistogram( chain + "_jet_E" , jet->e() / Gaudi::Units::GeV ) );
133 ATH_CHECK( fillHistogram( chain + "_jet_pT" , jet->pt() / Gaudi::Units::GeV ) );
134 ATH_CHECK( fillHistogram( chain + "_jet_eta" , jet->eta() ) );
135 ATH_CHECK( fillHistogram( chain + "_jet_phi" , jet->phi() ) );
136
137 //nMuons and nSV1
139 static const SG::ConstAccessor<std::vector< ElementLink< xAOD::VertexContainer > > > SV1_verticesAcc("SV1_vertices");
140 std::vector< ElementLink< xAOD::VertexContainer > > SV1_vertex = SV1_verticesAcc(*bTag);
141 if(SV1_vertex.size() >= 1) nJetsWithSV++;
142
143 static const SG::ConstAccessor< ElementLink<xAOD::MuonContainer> > SMT_mu_linkAcc("SMT_mu_link");
144 if (SMT_mu_linkAcc.isAvailable(*bTag)) {
145 ElementLink<xAOD::MuonContainer> muonLink = SMT_mu_linkAcc(*bTag);
146 if ( muonLink.isValid() ) {
147 const xAOD::Muon* muon=(*muonLink);
148 if ( muon != 0 ) {
149 nJetsWithMuon++;
150 ATH_CHECK( fillHistogram( chain + "_muon_pT_frac" , muon->pt() / jet->pt() ) );
151 }
152 }
153 }
154 else {
155 ATH_MSG_DEBUG( "SMT_mu_link is not available." );
156 }
157
158 // Retrieve jet flavour
159 std::string flavour = "DATA_";
161 int offlineJetIndex = getMatchedOfflineJetIndex( jet, qualityOfflineJetCollection );
162 if( offlineJetIndex == -1 ) {
163 ATH_MSG_WARNING("Could not match online jet to an offline jet. Skipping Event.");
165 continue;
166 }
167 const xAOD::Jet *matchedOfflineJet = qualityOfflineJetCollection.at(offlineJetIndex);
168
169 static const SG::ConstAccessor< int > HadronConeExclTruthLabelIDAcc( "HadronConeExclTruthLabelID" );
170 if( HadronConeExclTruthLabelIDAcc.isAvailable( *matchedOfflineJet ) == false ) {
171 ATH_MSG_ERROR( "Input sample is MC but matched offline jet has no 'HadronConeExclTruthLabelID' aux data. Something is wrong!" );
172 return StatusCode::FAILURE;
173 }
174 int HadronConeExclTruthLabelID = HadronConeExclTruthLabelIDAcc( *matchedOfflineJet );
175 ATH_MSG_DEBUG( " ** 'HadronConeExclTruthLabelID' is " << HadronConeExclTruthLabelID );
176 ATH_CHECK( fillHistogram( chain + "_truth_label" , HadronConeExclTruthLabelID ) );
177 if( HadronConeExclTruthLabelID == 0 ) flavour = "U_";
178 else if( HadronConeExclTruthLabelID == 4 ) flavour = "C_";
179 else if( HadronConeExclTruthLabelID == 5 ) flavour = "B_";
180 else { m_nTotal_otherFlavour++; continue; }
181 }
182
183 ATH_CHECK( analyseTrackParticleObjects( jet,primaryVertex,flavour,chain ) );
184 ATH_CHECK( analyseBTaggingObject( jet,flavour,chain ) );
185 }
186 ATH_CHECK( fillHistogram( chain + "_nJets",n_qualityJets ) );
187 ATH_CHECK( fillHistogram( chain + "_nJetsWithMuon" , nJetsWithMuon ) );
188 ATH_CHECK( fillHistogram( chain + "_fracJetsWithMuon" , double(nJetsWithMuon)/double(n_qualityJets) ) );
189 ATH_CHECK( fillHistogram( chain + "_nJetsWithSV" , nJetsWithSV ) );
190 ATH_CHECK( fillHistogram( chain + "_fracJetsWithSV" , double(nJetsWithSV)/double(n_qualityJets) ) );
191 }
192
193 return StatusCode::SUCCESS;
194 }
195
197 ATH_MSG_INFO( "Finalizing " << name() << " ..." );
198 ATH_MSG_INFO( "Fraction of events skipped because no primary vertex was found: " << float(m_nTotal_noPV)/float(m_nTotal_events));
199 ATH_MSG_INFO( "Fraction of online jets skipped because no offline jet could be matched (average over all chains): " << float(m_nTotal_noMatchedOffJet)/float(m_nTotal_qualityOnlineJets));
200 ATH_MSG_INFO( "Fraction of online jets skipped because flavour was different from u,c,b (average over all chains): " << float(m_nTotal_otherFlavour)/float(m_nTotal_qualityOnlineJets-m_nTotal_noMatchedOffJet));
201 ATH_MSG_INFO("m_trigDec->getListOfTriggers() " << m_trigDec->getListOfTriggers());
202 return StatusCode::SUCCESS;
203 }
204
205}
206
207
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
size_type size() const noexcept
Returns the number of elements in the collection.
bool passTriggerJetKinematicSelection(const xAOD::Jet *) const
StatusCode retrieveCollectionfromStoreGate(const EventContext &, const CONTAINER *&, const SG::ReadHandleKey< CONTAINER > &) const
const xAOD::Vertex * getPrimaryVertex(const xAOD::VertexContainer *) const
int getMatchedOfflineJetIndex(const xAOD::Jet *, const std::vector< const xAOD::Jet * > &) const
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
SG::ReadHandleKey< xAOD::VertexContainer > m_trigVertexKey
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trigTrackKey
SG::ReadHandleKey< xAOD::JetContainer > m_offJetKey
StatusCode analyseBTaggingObject(const xAOD::Jet *, const std::string &, std::string="")
StatusCode fillHistogram(const std::string &, T)
StatusCode analyseTrackParticleObjects(const xAOD::Jet *, const xAOD::Vertex *, const std::string &, std::string="")
PhysicsVariablePlots(const std::string &name, ISvcLocator *pSvcLocator)
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
float z() const
Returns the z position.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
float y() const
Returns the y position.
float x() const
Returns the x position.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
const BTagging * getBTagging(const SG::AuxElement &part)
Access the default xAOD::BTagging object associated to an object.
Jet_v1 Jet
Definition of the current "jet version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
BTagging_v1 BTagging
Definition of the current "BTagging version".
Definition BTagging.h:17
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version:
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Helper for azimuthal angle calculations.