ATLAS Offline Software
JetQuarkLabel.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 // JetQuarkLabel.cxx
7 // Source file for class JetQuarkLabel
9 
18 
20 #include <algorithm>
21 
22 
23 #define GeVtoMeV 1000.0
24 
25 namespace Analysis {
26 
28  : AsgTool(name),
29  m_deltaRCut(0.3),
30  m_ptCut(5.*GeVtoMeV),
31  m_noDoc(true),
32  m_inTime(-1)
33 {
34  declareProperty("deltaRCut", m_deltaRCut);
35  declareProperty("pTmin", m_ptCut);
36  declareProperty("NoUseDoc", m_noDoc);
37  declareProperty("PileUpInTime", m_inTime);
38 }
39 
41 
43  ATH_CHECK(m_truthEventContainerKey.initialize());
44  return StatusCode::SUCCESS;
45 }
46 
48  MatchInfo* info /*= nullptr*/) const
49 {
50  if (info)
51  *info = MatchInfo();
52 
54 
55  if (!truthEventContainerReadHandle.isValid()){
56  ATH_MSG_DEBUG(" Invalid ReadHandle for xAOD::TruthEventContainer with key: " << truthEventContainerReadHandle.key());
57  return false;
58  }
59 
60  return testJet(myJet,truthEventContainerReadHandle.cptr(), info);
61 
62 }
63 
64  bool JetQuarkLabel::testJet(const xAOD::Jet& myJet,
65  const xAOD::TruthEventContainer* truthEventContainer,
66  MatchInfo* info) const
67 {
68 
69  TLorentzVector jet_hlv = myJet.p4();
70 
71  ATH_MSG_DEBUG("Truth matching for jet " << myJet.pt() << " " << myJet.eta() << " " << myJet.phi() << " using pile-up event selection " << m_inTime);
72 
73 
74 
75  int NEventInCollection = truthEventContainer->size();
76  if (info)
77  info->NEventInCollection =NEventInCollection;
78 
79  // Tag only jet in the ID acceptance : not anymore...
80  // Labelling might be usefull also outside ID acceptance if (fabs(myJet.eta()) > 2.5) return false;
81  //
82  double deltaRC = 999.;
83  double deltaRB = 999.;
84  double deltaRT = 999.;
85  double deltaR = 999.;
86  int barcc = 0;
87  int barcb = 0;
88  unsigned int nLab = 0;
89 
90  xAOD::TruthEventContainer::const_iterator itEvt = truthEventContainer->begin(); // see if this works for now
91  xAOD::TruthEventContainer::const_iterator itEvtE = truthEventContainer->end();
92  const xAOD::TruthParticle* LabellingParticle(0);
93  //const xAOD::TruthEvent* LabellingEvent(0);
94  for (; itEvt != itEvtE; ++itEvt) {
95  const xAOD::TruthEvent* GenEvent = *itEvt;
96  std::vector<ElementLink<xAOD::TruthParticleContainer> >::const_iterator ELpitr = GenEvent->truthParticleLinks().begin();
97  std::vector<ElementLink<xAOD::TruthParticleContainer> >::const_iterator pitrE = GenEvent->truthParticleLinks().end();
98  for (; ELpitr != pitrE; ++ELpitr) {
100  if(!pitr.isValid() || !(*pitr)) {
101  // Allow for possibility that truth content has been thinned.
102  ATH_MSG_VERBOSE("Invalid ElementLink -- skipping.");
103  continue;
104  }
105  int pdg = (*pitr)->pdgId();
106 
107  // We want to use some special functions from HepLorentzVector
108  TLorentzVector part_momentum_lv = (*pitr)->p4();
109 
110  // label b, c and light jets
111  if (std::abs(pdg) == 5 || std::abs(pdg) == 4) {
112  double pt = part_momentum_lv.Pt();
113  if (pt > m_ptCut) {
114  // Herwig ! Do not use quark from Hadron decay !
115  //bool fromHadron = false; // put this back in later
116  ATH_MSG_VERBOSE( "MCTruth: part " << HepMC::barcode(*pitr) << " PDG= " << pdg
117  << " pT= " <<part_momentum_lv.Pt()
118  << " eta= " <<part_momentum_lv.Eta()
119  << " phi= " <<part_momentum_lv.Phi()
120  << " dR= " <<part_momentum_lv.DeltaR(jet_hlv));
121  // do not label by quark before FSR
122  bool afterFSR = true;
123  if ((*pitr)->hasDecayVtx()) {
124  std::vector<ElementLink<xAOD::TruthParticleContainer> >::const_iterator firstChild = (*pitr)->decayVtx()->outgoingParticleLinks().begin();
125  std::vector<ElementLink<xAOD::TruthParticleContainer> >::const_iterator endChild = (*pitr)->decayVtx()->outgoingParticleLinks().begin();
126  std::vector<ElementLink<xAOD::TruthParticleContainer> >::const_iterator thisChild = firstChild;
127  for(; thisChild != endChild; ++thisChild){
128  if(!thisChild->isValid() || !(**thisChild)) {
129  // Allow for possibility that truth content has been thinned.
130  ATH_MSG_VERBOSE("Invalid ElementLink -- skipping.");
131  continue;
132  }
133  if ((**thisChild)->pdgId() == pdg) afterFSR = false;
134  }
135  } else if ( ((*pitr)->status() == 3 && m_noDoc) || ((*pitr)->status() == HepMC::SPECIALSTATUS) ) {
136  // do not label by documentary quark
137  // (New 27/06/2006, for PYTHIA, with new Shower and maybe dependant on MSTP(128). What a mess !)
138  afterFSR = false;
139  }
140  if (afterFSR) {
141  //if (afterFSR && !fromHadron) {
142  deltaR=part_momentum_lv.DeltaR(jet_hlv);
143  if (std::abs(pdg) == 4 && deltaR < deltaRC) {deltaRC = deltaR; barcc = HepMC::barcode(*pitr); }
144  if (std::abs(pdg) == 5 && deltaR < deltaRB) {deltaRB = deltaR; barcb = HepMC::barcode(*pitr); LabellingParticle=(*pitr);}
145  }
146  }
147  }
148  if (std::abs(pdg) == 15) {
149  double pt = part_momentum_lv.Pt();
150  if (pt > m_ptCut) {
151  ATH_MSG_VERBOSE( "MCTruth: part " << HepMC::barcode(*pitr) << " PDG= " << pdg
152  << " pT= " <<part_momentum_lv.Pt()
153  << " eta= " <<part_momentum_lv.Eta()
154  << " phi= " <<part_momentum_lv.Phi()
155  << " dR= " <<part_momentum_lv.DeltaR(jet_hlv) );
156  deltaR=part_momentum_lv.DeltaR(jet_hlv);
157  if (deltaR < deltaRT) {deltaRT = deltaR;}
158  }
159  }
160  }
161  nLab++;
162  }
163  ATH_MSG_DEBUG("Number of events in the EventCollection : " << NEventInCollection << " and used for labelling " << nLab);
164 
165  if (info) {
166  info->distanceToQuarks.insert(std::make_pair("B",deltaRB));
167  info->distanceToQuarks.insert(std::make_pair("C",deltaRC));
168  info->distanceToQuarks.insert(std::make_pair("T",deltaRT)); //it is not a quark !
169  }
170  ATH_MSG_VERBOSE("DeltaR " << deltaRB << " " << deltaRC << " " << deltaRT);
171  if (deltaRB < m_deltaRCut) {
172  if (info) {
173  info->pdg = 5;
174  info->barcode = barcb; // FIXME barcode-based
175  info->jetLabel = 5;
176  }
177  ATH_MSG_VERBOSE("Jet matched with a b "<<barcb<<" after FSR, dR: " << deltaRB);
178  //JBdV Try Herwig !!! If Bhadron --> quark, the corresponding decay vertex is the primary !!
179  // (but the the following Hadron vertices are OK)
180  if (LabellingParticle == 0) {
181  ATH_MSG_WARNING("A b labelled jet without a labelling particle ? Should not exist");
182  return true;
183  }
184  return true;
185  } else if (deltaRC < m_deltaRCut) {
186  if (info) {
187  info->pdg = 4;
188  info->barcode = barcc; // FIXME barcode-based
189  info->jetLabel = 4;
190  }
191  ATH_MSG_VERBOSE("Jet matched with a c "<<barcc<<" after FSR, dR: " << deltaRC);
192  return true;
193  } else if (deltaRT < m_deltaRCut) {
194  ATH_MSG_VERBOSE("Jet matched with a tau dR: " << deltaRT);
195  if (info) {
196  info->pdg = 15;
197  info->jetLabel = 15;
198  }
199  return true;
200  } else {
201  if (info) {
202  info->pdg = 0;
203  info->barcode = HepMC::UNDEFINED_ID; // FIXME barcode-based
204  info->jetLabel = 0;
205  }
206  return true;
207  }
208  return false;
209 }
210 
212 }
213 
214 } // namespace Analysis
grepfile.info
info
Definition: grepfile.py:38
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Analysis::JetQuarkLabel::m_deltaRCut
double m_deltaRCut
deltaR cut value of the cone matching (max distance between Jet axis and momentum of truth particel)
Definition: JetQuarkLabel.h:62
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Analysis::IJetTruthMatching::MatchInfo
Definition: IJetTruthMatching.h:43
test_pyathena.pt
pt
Definition: test_pyathena.py:11
Analysis::JetQuarkLabel::testJet
bool testJet(const xAOD::Jet &, const xAOD::TruthEventContainer *, MatchInfo *info) const
Definition: JetQuarkLabel.cxx:64
xAOD::Jet_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: Jet_v1.cxx:54
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Analysis::JetQuarkLabel::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetQuarkLabel.cxx:42
HepMC::SPECIALSTATUS
constexpr int SPECIALSTATUS
Constant that the meaning of which is currently lost, to be recovered...
Definition: MagicNumbers.h:41
Analysis::JetQuarkLabel::JetQuarkLabel
JetQuarkLabel(const std::string &name)
Definition: JetQuarkLabel.cxx:27
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
Analysis::JetQuarkLabel::m_truthEventContainerKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventContainerKey
Definition: JetQuarkLabel.h:60
xAOD::TruthEvent_v1
Class describing a signal truth event in the MC record.
Definition: TruthEvent_v1.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Analysis::JetQuarkLabel::m_noDoc
bool m_noDoc
Definition: JetQuarkLabel.h:64
Analysis::JetQuarkLabel::matchJet
virtual bool matchJet(const xAOD::Jet &myJet, MatchInfo *info=nullptr) const override
AlgTool interface methods.
Definition: JetQuarkLabel.cxx:47
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::Jet_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: Jet_v1.cxx:49
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:55
HadronUtils.h
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
GeVtoMeV
#define GeVtoMeV
Purpose: label jets with b or c quarks.
Definition: JetQuarkLabel.cxx:23
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
MagicNumbers.h
ReadHandle.h
Handle class for reading from StoreGate.
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
Analysis::JetQuarkLabel::~JetQuarkLabel
virtual ~JetQuarkLabel()
Definition: JetQuarkLabel.cxx:40
xAOD::Jet_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: Jet_v1.cxx:71
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Analysis::JetQuarkLabel::m_ptCut
double m_ptCut
pT cut for partons
Definition: JetQuarkLabel.h:63
JetQuarkLabel.h
Analysis::JetQuarkLabel::m_inTime
short m_inTime
Definition: JetQuarkLabel.h:65
xAOD::TruthEventBase_v1::truthParticleLinks
const TruthParticleLinks_t & truthParticleLinks() const
Get all the truth particles.
xAOD::Jet_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition: Jet_v1.cxx:44
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Analysis::JetQuarkLabel::printParameterSettings
virtual void printParameterSettings() const override
print parameter settings of the truth match tool
Definition: JetQuarkLabel.cxx:211
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.