ATLAS Offline Software
JetHistoResponseAndEff.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
10 
11 JetHistoResponseAndEff::JetHistoResponseAndEff( const std::string& type, const std::string & name ,const IInterface* parent):
13  m_refContainerKey("REFCONTAINER")
14 {
15  declareInterface<IJetHistoFiller>(this);
16  declareProperty("RefContainerName",m_refContainerKey);
17 }
18 
19 
21  ATH_CHECK( m_refContainerKey.initialize() );
22  ATH_MSG_DEBUG(" initialize "<< m_refContainerKey.key());
23  return StatusCode::SUCCESS;
24 }
25 
26 
27 StatusCode JetHistoResponseAndEff::processJetContainer(const JetMonitoringAlg& parentAlg, const xAOD::JetContainer & jets, const EventContext& ctx ) const {
28  if(jets.empty()) return StatusCode::SUCCESS;
29 
30  // retrieve the reference jet container (typically : truth jets)
32  if (! refJets.isValid() ) {
33  ATH_MSG_ERROR("evtStore() does not contain jet Collection with name "<< m_refContainerKey.key());
34  return StatusCode::FAILURE;
35  }
36 
37 
38  // declare the variables to be monitored by the framework
39  Monitored::Scalar<float> refPt("refPt");
40  Monitored::Scalar<float> refEta("refEta");
41  Monitored::Scalar<float> relDiff("relDiff");
42  Monitored::Scalar<float> closestDr("closestDr");
43  Monitored::Scalar<bool> passDr1("passDr1");
44  Monitored::Scalar<bool> passDr2("passDr2");
45  Monitored::Scalar<bool> passDr3("passDr3");
46 
47 
48  // use a list to be a bit more efficient.
49  std::list<const xAOD::Jet*> listJets(jets.begin(), jets.end());
50 
51  for ( const xAOD::Jet* refjet : *refJets ){
52  double dr2min = 500000;
53 
54  if (listJets.empty() ) break;
55  // find the min match
58  for( ; it != listJets.end(); ++it) {
59  double dr2 = xAOD::P4Helpers::deltaR2(*(*it),*refjet);
60  if(dr2 < dr2min) { dr2min = dr2; itmin = it ;}
61  }
62 
63  // calculate efficiency and response from matched jet
64  const xAOD::Jet* matched = *itmin;
65  listJets.erase(itmin);
66 
67  double dr = sqrt(dr2min);
68  refPt = refjet->pt() * m_energyScale;
69  closestDr = dr;
70 
71  // Set flag passDrX if (reco,truth) jets are closer than deltaR=0.X
72  passDr1 = dr<0.1;
73  passDr2 = dr<0.2;
74  passDr3 = dr<0.3;
75  // using these flags, the framework will fill 3 TEfficiency to draw ( efficiency_at_drX vs pT) (see also configuration) :
76  parentAlg.fill(m_group, refPt , passDr1, passDr2, passDr3 , closestDr);
77 
78  if( dr < 0.3) {
79  if (refPt > 0.) relDiff = ( matched->pt()* m_energyScale - refPt )/refPt;
80  else relDiff = -999;
81  refEta = refjet->eta();
82  parentAlg.fill(m_group, refPt , refEta, relDiff );
83  }
84 
85  }
86 
87  return StatusCode::SUCCESS;
88 }
89 
90 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JetHistoResponseAndEff.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
GenericMonitoringTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JetHistoResponseAndEff::m_energyScale
Gaudi::Property< float > m_energyScale
Definition: JetHistoResponseAndEff.h:30
JetHistoResponseAndEff::m_refContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_refContainerKey
Definition: JetHistoResponseAndEff.h:31
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JetHistoResponseAndEff::initialize
virtual StatusCode initialize()
Definition: JetHistoResponseAndEff.cxx:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
JetMonitoringAlg
Definition: JetMonitoringAlg.h:26
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetMonitoringAlg.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JetHistoResponseAndEff::JetHistoResponseAndEff
JetHistoResponseAndEff(const std::string &type, const std::string &name, const IInterface *parent)
Definition: JetHistoResponseAndEff.cxx:11
JetHistoResponseAndEff::m_group
Gaudi::Property< std::string > m_group
Definition: JetHistoResponseAndEff.h:29
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
JetHistoResponseAndEff::processJetContainer
virtual StatusCode processJetContainer(const JetMonitoringAlg &parentAlg, const xAOD::JetContainer &jets, const EventContext &ctx) const
Definition: JetHistoResponseAndEff.cxx:27
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
AthAlgTool
Definition: AthAlgTool.h:26