ATLAS Offline Software
PhysicsTriggerVariablePlots.cxx
Go to the documentation of this file.
1 //Copyright (C) 2002-2021 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  std::vector< ElementLink< xAOD::VertexContainer > > SV1_vertex = bTag->auxdata<std::vector< ElementLink< xAOD::VertexContainer > > >("SV1_vertices");
142  if(SV1_vertex.size() >= 1) nJetsWithSV++;
143 
144  if (bTag->isAvailable< ElementLink<xAOD::MuonContainer> >("SMT_mu_link")) {
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_";
160  if( eventInfo->eventType(xAOD::EventInfo::EventType::IS_SIMULATION) ) {
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  if( matchedOfflineJet->isAvailable< int >( "HadronConeExclTruthLabelID" ) == false ) {
170  ATH_MSG_ERROR( "Input sample is MC but matched offline jet has no 'HadronConeExclTruthLabelID' aux data. Something is wrong!" );
171  return StatusCode::FAILURE;
172  }
173  int HadronConeExclTruthLabelID = matchedOfflineJet->auxdata< int >( "HadronConeExclTruthLabelID");
174  ATH_MSG_DEBUG( " ** 'HadronConeExclTruthLabelID' is " << HadronConeExclTruthLabelID );
175  ATH_CHECK( fillHistogram( chain + "_truth_label" , HadronConeExclTruthLabelID ) );
176  if( HadronConeExclTruthLabelID == 0 ) flavour = "U_";
177  else if( HadronConeExclTruthLabelID == 4 ) flavour = "C_";
178  else if( HadronConeExclTruthLabelID == 5 ) flavour = "B_";
179  else { m_nTotal_otherFlavour++; continue; }
180  }
181 
182  ATH_CHECK( analyseTrackParticleObjects( jet,primaryVertex,flavour,chain ) );
184  }
185  ATH_CHECK( fillHistogram( chain + "_nJets",n_qualityJets ) );
186  ATH_CHECK( fillHistogram( chain + "_nJetsWithMuon" , nJetsWithMuon ) );
187  ATH_CHECK( fillHistogram( chain + "_fracJetsWithMuon" , double(nJetsWithMuon)/double(n_qualityJets) ) );
188  ATH_CHECK( fillHistogram( chain + "_nJetsWithSV" , nJetsWithSV ) );
189  ATH_CHECK( fillHistogram( chain + "_fracJetsWithSV" , double(nJetsWithSV)/double(n_qualityJets) ) );
190  }
191 
192  return StatusCode::SUCCESS;
193  }
194 
196  ATH_MSG_INFO( "Finalizing " << name() << " ..." );
197  ATH_MSG_INFO( "Fraction of events skipped because no primary vertex was found: " << float(m_nTotal_noPV)/float(m_nTotal_events));
198  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));
199  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));
200  ATH_MSG_INFO("m_trigDec->getListOfTriggers() " << m_trigDec->getListOfTriggers());
201  return StatusCode::SUCCESS;
202  }
203 
204 }
205 
206 
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
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:250
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:410
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:195
FTAGValidation::PhysicsVariablePlots::initializeHistograms
StatusCode initializeHistograms()
Definition: PhysicsVariablePlots.cxx:179
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?
SG::AuxElement::auxdata
Accessor< T, ALLOC >::reference_type auxdata(const std::string &name)
Fetch an aux data variable, as a non-const reference.
BTaggingContainer.h
SG::AuxElement::isAvailable
bool isAvailable(const std::string &name, const std::string &clsname="") const
Check if an aux variable is available for reading.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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::IParticle::isAvailable
bool isAvailable(const std::string &name, const std::string &clsname="") const
Check if a user property is available for reading or not.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:131
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.
xAOD::IParticle::auxdata
T & auxdata(const std::string &name, const std::string &clsname="")
Fetch an aux data variable, as a non-const reference.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:96
FTAGValidation::PhysicsTriggerVariablePlots::m_bJetChains
std::vector< std::string > m_bJetChains
Definition: PhysicsTriggerVariablePlots.h:52
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
FTAGValidation::PhysicsTriggerVariablePlots::m_nTotal_events
int m_nTotal_events
Definition: PhysicsTriggerVariablePlots.h:37
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
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
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:125
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
FTAGValidation::FTAGValidationAlgorithm::getMatchedOfflineJetIndex
int getMatchedOfflineJetIndex(const xAOD::Jet *, std::vector< const xAOD::Jet * >) const
Definition: FTAGValidationAlgorithm.cxx:143