ATLAS Offline Software
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 
10 #include "xAODMuon/MuonContainer.h"
12 
13 #include "CxxUtils/phihelper.h"
14 
15 namespace FTAGValidation {
16 
18  ISvcLocator* pSvcLocator ) :
19  PhysicsVariablePlots( name, pSvcLocator )
20  ,m_bJetChains{}
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() );
46  ATH_CHECK( m_offJetKey.initialize() );
47 
49 
50  m_nTotal_events = 0;
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!" );
104  m_nTotal_noPV++;
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_";
162  if( eventInfo->eventType(xAOD::EventInfo::EventType::IS_SIMULATION) ) {
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 ) );
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 
FTAGValidation::PhysicsTriggerVariablePlots::~PhysicsTriggerVariablePlots
virtual ~PhysicsTriggerVariablePlots()
Definition: PhysicsTriggerVariablePlots.cxx:25
FTAGValidation::FTAGValidationAlgorithm::passTriggerJetKinematicSelection
bool passTriggerJetKinematicSelection(const xAOD::Jet *) const
Definition: FTAGValidationAlgorithm.cxx:30
BTaggingUtilities.h
xAOD::Vertex_v1::x
float x() const
Returns the x position.
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
FTAGValidation::FTAGValidationAlgorithm::m_minJetEta
Gaudi::Property< float > m_minJetEta
Definition: FTAGValidationAlgorithm.h:50
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
FTAGValidation::PhysicsVariablePlots::analyseTrackParticleObjects
StatusCode analyseTrackParticleObjects(const xAOD::Jet *, const xAOD::Vertex *, const std::string &, std::string="")
Definition: PhysicsVariablePlots.cxx:254
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FTAGValidation::PhysicsVariablePlots::analyseBTaggingObject
StatusCode analyseBTaggingObject(const xAOD::Jet *, const std::string &, std::string="")
Definition: PhysicsVariablePlots.cxx:415
FTAGValidation::PhysicsTriggerVariablePlots::m_nTotal_otherFlavour
int m_nTotal_otherFlavour
Definition: PhysicsTriggerVariablePlots.h:40
FTAGValidation::FTAGValidationAlgorithm::retrieveCollectionfromStoreGate
StatusCode retrieveCollectionfromStoreGate(const EventContext &, const CONTAINER *&, const SG::ReadHandleKey< CONTAINER > &) const
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
FTAGValidation::PhysicsTriggerVariablePlots::initialize
virtual StatusCode initialize() override
Definition: PhysicsTriggerVariablePlots.cxx:29
FTAGValidation::PhysicsTriggerVariablePlots::execute
virtual StatusCode execute() override
Definition: PhysicsTriggerVariablePlots.cxx:59
FTAGValidation::PhysicsTriggerVariablePlots::finalize
virtual StatusCode finalize() override
Definition: PhysicsTriggerVariablePlots.cxx:198
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
FTAGValidation::PhysicsVariablePlots::initializeHistograms
StatusCode initializeHistograms()
Definition: PhysicsVariablePlots.cxx:183
FTAGValidation::PhysicsTriggerVariablePlots::m_trigVertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_trigVertexKey
Definition: PhysicsTriggerVariablePlots.h:44
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
FTAGValidation::PhysicsTriggerVariablePlots::m_offJetKey
SG::ReadHandleKey< xAOD::JetContainer > m_offJetKey
Definition: PhysicsTriggerVariablePlots.h:48
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
MuonAuxContainer.h
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
BTaggingAuxContainer.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FTAGValidation::PhysicsTriggerVariablePlots::m_nTotal_qualityOnlineJets
int m_nTotal_qualityOnlineJets
Definition: PhysicsTriggerVariablePlots.h:41
FTAGValidation
Definition: FTAGValidationAlgorithm.h:16
FTAGValidation::PhysicsTriggerVariablePlots::m_trigDec
ToolHandle< Trig::TrigDecisionTool > m_trigDec
Definition: PhysicsTriggerVariablePlots.h:50
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FTAGValidation::PhysicsTriggerVariablePlots::PhysicsTriggerVariablePlots
PhysicsTriggerVariablePlots()
xAOD::Vertex_v1::z
float z() const
Returns the z position.
FTAGValidation::FTAGValidationAlgorithm::m_minJetPt
Gaudi::Property< float > m_minJetPt
Definition: FTAGValidationAlgorithm.h:56
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
FTAGValidation::FTAGValidationAlgorithm::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: FTAGValidationAlgorithm.h:47
FTAGValidation::PhysicsTriggerVariablePlots::m_nTotal_noPV
int m_nTotal_noPV
Definition: PhysicsTriggerVariablePlots.h:38
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
BTaggingContainer.h
FTAGValidation::FTAGValidationAlgorithm::getMatchedOfflineJetIndex
int getMatchedOfflineJetIndex(const xAOD::Jet *, const std::vector< const xAOD::Jet * > &) const
Definition: FTAGValidationAlgorithm.cxx:144
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
phihelper.h
Helper for azimuthal angle calculations.
FTAGValidation::PhysicsTriggerVariablePlots::m_nTotal_noMatchedOffJet
int m_nTotal_noMatchedOffJet
Definition: PhysicsTriggerVariablePlots.h:39
FTAGValidation::PhysicsVariablePlots
Definition: PhysicsVariablePlots.h:20
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
MuonContainer.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
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::Vertex_v1::y
float y() const
Returns the y position.
FTAGValidation::PhysicsTriggerVariablePlots::m_bJetChains
std::vector< std::string > m_bJetChains
Definition: PhysicsTriggerVariablePlots.h:52
FTAGValidation::PhysicsTriggerVariablePlots::m_nTotal_events
int m_nTotal_events
Definition: PhysicsTriggerVariablePlots.h:37
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
FTAGValidation::PhysicsTriggerVariablePlots::m_trigTrackKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trigTrackKey
Definition: PhysicsTriggerVariablePlots.h:46
FTAGValidation::FTAGValidationAlgorithm::m_maxJetEta
Gaudi::Property< float > m_maxJetEta
Definition: FTAGValidationAlgorithm.h:53
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
PhysicsTriggerVariablePlots.h
FTAGValidation::PhysicsVariablePlots::fillHistogram
StatusCode fillHistogram(const std::string &, T)
FTAGValidation::FTAGValidationAlgorithm::initialize
virtual StatusCode initialize()
Definition: FTAGValidationAlgorithm.cxx:13
FTAGValidation::FTAGValidationAlgorithm::getPrimaryVertex
const xAOD::Vertex * getPrimaryVertex(const xAOD::VertexContainer *) const
Definition: FTAGValidationAlgorithm.cxx:126
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.