ATLAS Offline Software
Loading...
Searching...
No Matches
PhysicsTriggerVariablePlots.cxx
Go to the documentation of this file.
1//Copyright (C) 2002-2024 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
60 ATH_MSG_DEBUG( "Executing " << name() << " ..." );
62
63 const EventContext context = getContext();
64
65 /* =========================================================================================================================================== */
66 /* ==== Retrieve Collections */
67 /* =========================================================================================================================================== */
68
69 // Event Info
71 ATH_CHECK( eventInfoHandle.isValid() );
72 const xAOD::EventInfo *eventInfo = eventInfoHandle.get();
73
74 // Retrieve Offline-Jet Collection
75 const xAOD::JetContainer *offlineJetCollection = nullptr;
76 ATH_CHECK( retrieveCollectionfromStoreGate( context,offlineJetCollection,m_offJetKey ) );
77
78 std::vector< const xAOD::Jet* > qualityOfflineJetCollection;
79 for ( const xAOD::Jet *jet : *offlineJetCollection ) {
80 //For the moment running without offline jet quality requirments
81 //if ( not passJetQualitySelection( jet ) ) continue;
82 //if ( not passJetKinematicSelection( jet ) ) continue;
83 //if ( not passJetJVTSelection( jet ) ) continue;
84 qualityOfflineJetCollection.push_back( jet );
85 }
86
87 //run over b-jet chains
88 for( const std::string& chain: m_bJetChains ){
89 if( m_trigDec->isPassed(chain) ){
90 ATH_MSG_DEBUG("Chain passed " << chain);
91 }
92 else{
93 ATH_MSG_DEBUG("Chain did not pass " << chain);
94 continue;
95 }
96
97 // ==== Primary Vertex =================
98 // Chain is passed, only one PV per event, retrieve it in a standard way, filled once, doesnt matter how many jets
99 const xAOD::VertexContainer *vertexCollection = nullptr;
100 ATH_CHECK( retrieveCollectionfromStoreGate( context,vertexCollection,m_trigVertexKey ) );
101 const xAOD::Vertex *primaryVertex = getPrimaryVertex( vertexCollection );
102 if ( primaryVertex == nullptr ) {
103 ATH_MSG_WARNING( "Could not retrieve Primary Vertex. Skip this event!" );
105 return StatusCode::SUCCESS;
106 }
107 ATH_CHECK( fillHistogram( chain + "_nPrimVtx", vertexCollection->size() ) );
108 ATH_CHECK( fillHistogram( chain + "_nTracksPrimVtx", primaryVertex->nTrackParticles() ) );
109 ATH_CHECK( fillHistogram( chain + "_PV_x", primaryVertex->x() ) );
110 ATH_CHECK( fillHistogram( chain + "_PV_y", primaryVertex->y() ) );
111 ATH_CHECK( fillHistogram( chain + "_PV_z", primaryVertex->z() ) );
112
113 // ==== Tracks =========================
114 const xAOD::TrackParticleContainer *trackParticleCollection = nullptr;
115 ATH_CHECK( retrieveCollectionfromStoreGate( context,trackParticleCollection,m_trigTrackKey) );
116 ATH_CHECK( fillHistogram( chain + "_nTracks",trackParticleCollection->size() ) );
117
118 // ==== Jet ============================
119 int nJetsWithMuon = 0;
120 int nJetsWithSV = 0;
121
122 std::vector< TrigCompositeUtils::LinkInfo<xAOD::JetContainer> > onlineJets = m_trigDec->features<xAOD::JetContainer>(chain, TrigDefs::Physics);
123 ATH_MSG_DEBUG("onlineJets.size(): " << onlineJets.size() );
124 int n_qualityJets = 0;
125 for( const auto& jetLinkInfo : onlineJets ) {
126 const xAOD::Jet* jet = *(jetLinkInfo.link);
127 //Check quality requirement
128 if ( not passTriggerJetKinematicSelection( jet ) ) continue;
129 n_qualityJets++;
131
132 ATH_MSG_DEBUG( "JET KINEMATICS:" );
133 ATH_MSG_DEBUG( " ** pt=" << jet->p4().Et() / Gaudi::Units::GeV << " eta=" << jet->eta() << " phi=" << jet->phi() );
134 ATH_CHECK( fillHistogram( chain + "_jet_E" , jet->e() / Gaudi::Units::GeV ) );
135 ATH_CHECK( fillHistogram( chain + "_jet_pT" , jet->pt() / Gaudi::Units::GeV ) );
136 ATH_CHECK( fillHistogram( chain + "_jet_eta" , jet->eta() ) );
137 ATH_CHECK( fillHistogram( chain + "_jet_phi" , jet->phi() ) );
138
139 //nMuons and nSV1
141 static const SG::ConstAccessor<std::vector< ElementLink< xAOD::VertexContainer > > > SV1_verticesAcc("SV1_vertices");
142 std::vector< ElementLink< xAOD::VertexContainer > > SV1_vertex = SV1_verticesAcc(*bTag);
143 if(SV1_vertex.size() >= 1) nJetsWithSV++;
144
145 static const SG::ConstAccessor< ElementLink<xAOD::MuonContainer> > SMT_mu_linkAcc("SMT_mu_link");
146 if (SMT_mu_linkAcc.isAvailable(*bTag)) {
147 ElementLink<xAOD::MuonContainer> muonLink = SMT_mu_linkAcc(*bTag);
148 if ( muonLink.isValid() ) {
149 const xAOD::Muon* muon=(*muonLink);
150 if ( muon != 0 ) {
151 nJetsWithMuon++;
152 ATH_CHECK( fillHistogram( chain + "_muon_pT_frac" , muon->pt() / jet->pt() ) );
153 }
154 }
155 }
156 else {
157 ATH_MSG_DEBUG( "SMT_mu_link is not available." );
158 }
159
160 // Retrieve jet flavour
161 std::string flavour = "DATA_";
163 int offlineJetIndex = getMatchedOfflineJetIndex( jet, qualityOfflineJetCollection );
164 if( offlineJetIndex == -1 ) {
165 ATH_MSG_WARNING("Could not match online jet to an offline jet. Skipping Event.");
167 continue;
168 }
169 const xAOD::Jet *matchedOfflineJet = qualityOfflineJetCollection.at(offlineJetIndex);
170
171 static const SG::ConstAccessor< int > HadronConeExclTruthLabelIDAcc( "HadronConeExclTruthLabelID" );
172 if( HadronConeExclTruthLabelIDAcc.isAvailable( *matchedOfflineJet ) == false ) {
173 ATH_MSG_ERROR( "Input sample is MC but matched offline jet has no 'HadronConeExclTruthLabelID' aux data. Something is wrong!" );
174 return StatusCode::FAILURE;
175 }
176 int HadronConeExclTruthLabelID = HadronConeExclTruthLabelIDAcc( *matchedOfflineJet );
177 ATH_MSG_DEBUG( " ** 'HadronConeExclTruthLabelID' is " << HadronConeExclTruthLabelID );
178 ATH_CHECK( fillHistogram( chain + "_truth_label" , HadronConeExclTruthLabelID ) );
179 if( HadronConeExclTruthLabelID == 0 ) flavour = "U_";
180 else if( HadronConeExclTruthLabelID == 4 ) flavour = "C_";
181 else if( HadronConeExclTruthLabelID == 5 ) flavour = "B_";
182 else { m_nTotal_otherFlavour++; continue; }
183 }
184
185 ATH_CHECK( analyseTrackParticleObjects( jet,primaryVertex,flavour,chain ) );
186 ATH_CHECK( analyseBTaggingObject( jet,flavour,chain ) );
187 }
188 ATH_CHECK( fillHistogram( chain + "_nJets",n_qualityJets ) );
189 ATH_CHECK( fillHistogram( chain + "_nJetsWithMuon" , nJetsWithMuon ) );
190 ATH_CHECK( fillHistogram( chain + "_fracJetsWithMuon" , double(nJetsWithMuon)/double(n_qualityJets) ) );
191 ATH_CHECK( fillHistogram( chain + "_nJetsWithSV" , nJetsWithSV ) );
192 ATH_CHECK( fillHistogram( chain + "_fracJetsWithSV" , double(nJetsWithSV)/double(n_qualityJets) ) );
193 }
194
195 return StatusCode::SUCCESS;
196 }
197
199 ATH_MSG_INFO( "Finalizing " << name() << " ..." );
200 ATH_MSG_INFO( "Fraction of events skipped because no primary vertex was found: " << float(m_nTotal_noPV)/float(m_nTotal_events));
201 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));
202 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));
203 ATH_MSG_INFO("m_trigDec->getListOfTriggers() " << m_trigDec->getListOfTriggers());
204 return StatusCode::SUCCESS;
205 }
206
207}
208
209
#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
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.