ATLAS Offline Software
SkimmingToolEXOT14.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 // Based on DerivationFramework::SkimmingToolExample
7 
9 #include <vector>
10 #include <string>
11 
12 #include "CLHEP/Units/SystemOfUnits.h"
13 
17 // #include "xAODTracking/TrackingPrimitives.h"
18 
19 // #include "JetCalibTools/JetCalibrationTool.h"
20 
21 
22 // Constructor
24  const std::string& n,
25  const IInterface* p) :
26  AthAlgTool(t, n, p),
27  m_trigDecisionTool("Trig::TrigDecisionTool/TrigDecisionTool"),
28  m_n_tot(0),
29  m_n_passGRL(0),
30  m_n_passLArError(0),
31  m_n_passTrigger(0),
32  m_n_passPreselect(0),
33  m_n_passJetPts(0),
34  m_n_passJetsDEta(0),
35  m_n_passDiJetMass(0),
36  m_n_passJetsDPhi(0),
37  m_n_pass(0)
38 {
39 
40  declareInterface<DerivationFramework::ISkimmingTool>(this);
41 
42  declareProperty("JetContainer", m_jetSGKey = "AntiKt4LCTopoJets");
43 
44  declareProperty("RequireGRL", m_reqGRL = true);
45  declareProperty("ReqireLArError", m_reqLArError = true);
46  declareProperty("RequireTrigger", m_reqTrigger = true);
47  declareProperty("RequirePreselection", m_reqPreselection = true);
48  declareProperty("RequireJetPts", m_reqJetPts = true);
49  declareProperty("RequireJetsDEta", m_reqJetsDEta = true);
50  declareProperty("RequireDiJetMass", m_reqDiJetMass = true);
51  declareProperty("RequireJetsDPhi", m_reqJetsDPhi = true);
52 
53  declareProperty("GoodRunList", m_goodRunList = "");
54 
55  declareProperty("DefaultTrigger", m_defaultTrigger = "HLT_xe100");
56  declareProperty("Triggers", m_triggers = std::vector<std::string>());
57 
58  declareProperty("MinimumJetPt", m_minJetPt = 25*CLHEP::GeV);
59  declareProperty("MaxEta", m_maxEta = 4.8);
60 
61  declareProperty("LeadingJetPtCut", m_leadingJetPt = 75*CLHEP::GeV);
62  declareProperty("SubleadingJetPtCut", m_subleadingJetPt = 50*CLHEP::GeV);
63 
64  declareProperty("EtaSeparation", m_etaSeparation = 4.8);
65 
66  declareProperty("DiJetsMass", m_dijetMass = 1000*CLHEP::GeV);
67 
68  declareProperty("DiJetDPhi", m_jetDPhi = 2.5);
69 
70 }
71 
72 // Destructor
74 }
75 
76 // Athena initialize and finalize
78 {
79  ATH_MSG_VERBOSE("INITIALIZING VBFINV SELECTOR TOOL");
80 
82  // trigger decision tool
83  if(m_trigDecisionTool.retrieve(DisableTool{!m_reqTrigger}).isFailure()) {
84  ATH_MSG_FATAL("Failed to retrieve tool: " << m_trigDecisionTool);
85  return StatusCode::FAILURE;
86  }
87  if (!m_triggers.size()) m_triggers.push_back(m_defaultTrigger);
88  ATH_MSG_INFO("Retrieved tool: " << m_trigDecisionTool);
90 
91 
93  // jet energy calibration
94  m_JESTool.setTypeAndName("JetCalibrationTool/m_JESTool");
95  CHECK( m_JESTool.retrieve() ); //optional, just forces initializing the tool here instead of at first use
96  ATH_MSG_INFO("Retrieved tool: " << m_JESTool);
98 
99 
100  return StatusCode::SUCCESS;
101 }
102 
104 {
105  ATH_MSG_VERBOSE("finalize() ...");
106  ATH_MSG_INFO("Processed " << m_n_tot << " events, " << m_n_pass << " events passed filter ");
107 
108  ATH_MSG_INFO("GRL :: " << m_n_passGRL);
109  ATH_MSG_INFO("LAr Error :: " << m_n_passLArError);
110  ATH_MSG_INFO("Trigger :: " << m_n_passTrigger);
111  ATH_MSG_INFO("Preselect :: " << m_n_passPreselect);
112  ATH_MSG_INFO("JetPts :: " << m_n_passJetPts);
113  ATH_MSG_INFO("JetsDEta :: " << m_n_passJetsDEta);
114  ATH_MSG_INFO("DijetMass :: " << m_n_passDiJetMass);
115  ATH_MSG_INFO("JetsDPhi :: " << m_n_passJetsDPhi);
116 
117  return StatusCode::SUCCESS;
118 
119 }
120 
121 // The filter itself
123 {
124 
125  m_n_tot++;
126 
127  bool writeEvent(false);
128 
129  // int *leading = new int(0);
130  // if (!evtStore()->contains<int>("leading")) CHECK(evtStore()->record(leading, "leading"));
131 
132  if (!SubcutGoodRunList() && m_reqGRL ) return false;
133  if (!SubcutLArError() && m_reqLArError ) return false;
134  if (!SubcutTrigger() && m_reqTrigger ) return false;
135 
136  const auto jets = SubcutPreselect();
137  if (!m_reqPreselection) writeEvent = true;
138 
139  // There *must* be two jets for the remaining
140  // pieces, but you can still save the event...
141  if (jets) {
142 
143  bool passDiJets(true);
144  if (!SubcutJetPts(jets.value()) && m_reqJetPts ) passDiJets = false;
145  if (!SubcutJetDEta(jets.value()) && m_reqJetsDEta ) passDiJets = false;
146  if (!SubcutDijetMass(jets.value()) && m_reqDiJetMass) passDiJets = false;
147  if (!SubcutJetDPhi(jets.value()) && m_reqJetsDPhi ) passDiJets = false;
148  if (passDiJets) writeEvent = true;
149  }
150 
151  if (!writeEvent) return false;
152 
153  m_n_pass++;
154  return true;
155 
156 }
157 
159 
160  // Placeholder
161  m_n_passGRL++;
162  return true;
163 
164 }
165 
166 
168 
169  // Retrieve EventInfo
170  const xAOD::EventInfo *eventInfo(0);
171  ATH_CHECK(evtStore()->retrieve(eventInfo), false);
172 
173  const bool passLArError = !(eventInfo->errorState(xAOD::EventInfo::LAr) == xAOD::EventInfo::Error);
174 
175  if (passLArError) m_n_passLArError++;
176  return passLArError;
177 
178 }
179 
180 
182 
183  const xAOD::EventInfo *eventInfo(0);
184  ATH_CHECK(evtStore()->retrieve(eventInfo), false);
185 
186  bool passTrigger = false;
187 
188  for (unsigned int i = 0; i < m_triggers.size(); i++) {
189  bool thisTrig = m_trigDecisionTool->isPassed(m_triggers.at(i));
190  SG::Decorator<bool> acc(TriggerVarName(m_triggers.at(i)));
191  acc(*eventInfo) = thisTrig;
192  // ATH_MSG_INFO("TRIGGER = " << m_triggers.at(i) << " -->> " << thisTrig);
193  passTrigger |= thisTrig;
194  }
195 
196  // temporary pass-through of trigger cut for MC
197  if (eventInfo->eventType(xAOD::EventInfo::IS_SIMULATION)) passTrigger = true;
198 
199  if (passTrigger) m_n_passTrigger++;
200  return passTrigger;
201 
202 }
203 
204 std::optional<DerivationFramework::SkimmingToolEXOT14::LeadingJets_t>
206 
207  // xAOD::TStore store;
208  const xAOD::JetContainer *jets(0);
209  ATH_CHECK(evtStore()->retrieve(jets, m_jetSGKey), {});
210  xAOD::JetContainer::const_iterator jet_itr(jets->begin());
212 
213  xAOD::JetContainer calibJets;
214  calibJets.setStore(new xAOD::JetAuxContainer());
215 
216  TLorentzVector j1TLV, j2TLV;
217 
218  // Copy jets into the container to be calibrated
219  while(jet_itr != jet_end) {
220  xAOD::Jet* jetC = new xAOD::Jet();
221  jetC->setJetP4(xAOD::JetFourMom_t((*jet_itr)->pt(), (*jet_itr)->eta(), (*jet_itr)->phi(), (*jet_itr)->m()));
222  calibJets.push_back(jetC);
223  ++jet_itr;
224  }
225 
226  // Calibrate the jets
227  if(m_JESTool->applyCalibration(calibJets).isFailure())
228  ATH_MSG_WARNING("Jet calibration returned FAILURE!");
229 
230  jet_itr = calibJets.begin();
231  jet_end = calibJets.end();
232  while(jet_itr != jet_end) {
233 
234  if (abs((*jet_itr)->eta()) > m_maxEta) continue;
235 
236  if ((*jet_itr)->pt() > j1TLV.Pt()) {
237 
238  j2TLV = j1TLV;
239  j1TLV.SetPtEtaPhiE((*jet_itr)->pt(), (*jet_itr)->eta(), (*jet_itr)->phi(), (*jet_itr)->e());
240 
241  } else if ((*jet_itr)->pt() > j2TLV.Pt()) {
242 
243  j2TLV.SetPtEtaPhiE((*jet_itr)->pt(), (*jet_itr)->eta(), (*jet_itr)->phi(), (*jet_itr)->e());
244  }
245 
246  ++jet_itr;
247  }
248 
249  // save this for this code.
250  if (j2TLV.Pt() > m_minJetPt) {
251  m_n_passPreselect++;
252  return LeadingJets_t{j1TLV, j2TLV};
253  }
254 
255  return {};
256 
257 }
258 
259 
261 
262  bool passJetPts = (!m_leadingJetPt || jets[0].Pt() > m_leadingJetPt);
263  passJetPts &= (!m_subleadingJetPt || jets[1].Pt() > m_subleadingJetPt);
264 
265  if (passJetPts) m_n_passJetPts++;
266  return passJetPts;
267 
268 }
269 
271 
272  const double JetsDEta = fabs(jets[0].Eta() - jets[1].Eta());
273  const bool passJetsDEta = JetsDEta > m_etaSeparation;
274 
275  if (passJetsDEta) m_n_passJetsDEta++;
276  return passJetsDEta;
277 
278 }
279 
280 
282 
283  const double DiJetMass = (jets[0] + jets[1]).M();
284  const bool passDiJetMass = DiJetMass > m_dijetMass;
285 
286  if (passDiJetMass) m_n_passDiJetMass++;
287  return passDiJetMass;
288 
289 }
290 
292 
293  const double JetsDPhi = fabs(jets[0].DeltaPhi(jets[1]));
294  const bool passJetsDPhi = JetsDPhi < m_jetDPhi;
295 
296  if (passJetsDPhi) m_n_passJetsDPhi++;
297  return passJetsDPhi;
298 
299 }
300 
302  std::replace(s.begin(), s.end(), '-', '_'); return s;
303 }
304 
305 
306 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
DerivationFramework::SkimmingToolEXOT14::m_subleadingJetPt
double m_subleadingJetPt
Definition: SkimmingToolEXOT14.h:94
DerivationFramework::SkimmingToolEXOT14::m_triggers
std::vector< std::string > m_triggers
Definition: SkimmingToolEXOT14.h:89
DerivationFramework::SkimmingToolEXOT14::m_leadingJetPt
double m_leadingJetPt
Definition: SkimmingToolEXOT14.h:93
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::SkimmingToolEXOT14::SubcutTrigger
bool SubcutTrigger() const
Definition: SkimmingToolEXOT14.cxx:181
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::SkimmingToolEXOT14::SubcutJetDPhi
bool SubcutJetDPhi(const LeadingJets_t &jets) const
Definition: SkimmingToolEXOT14.cxx:291
DerivationFramework::SkimmingToolEXOT14::SubcutJetDEta
bool SubcutJetDEta(const LeadingJets_t &jets) const
Definition: SkimmingToolEXOT14.cxx:270
DerivationFramework::SkimmingToolEXOT14::m_minJetPt
double m_minJetPt
Definition: SkimmingToolEXOT14.h:91
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
xAOD::EventInfo_v1::LAr
@ LAr
The LAr calorimeter.
Definition: EventInfo_v1.h:335
DerivationFramework::SkimmingToolEXOT14::m_defaultTrigger
std::string m_defaultTrigger
Definition: SkimmingToolEXOT14.h:88
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition: EventInfo_v1.h:349
xAOD::Jet_v1::setJetP4
void setJetP4(const JetFourMom_t &p4)
Definition: Jet_v1.cxx:171
xAOD::JetAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: JetAuxContainer_v1.h:37
DerivationFramework::SkimmingToolEXOT14::m_reqJetsDPhi
bool m_reqJetsDPhi
Definition: SkimmingToolEXOT14.h:82
DerivationFramework::SkimmingToolEXOT14::LeadingJets_t
std::array< TLorentzVector, 2 > LeadingJets_t
Definition: SkimmingToolEXOT14.h:103
DerivationFramework::SkimmingToolEXOT14::TriggerVarName
std::string TriggerVarName(std::string s) const
Definition: SkimmingToolEXOT14.cxx:301
SG::Decorator< bool >
DerivationFramework::SkimmingToolEXOT14::m_reqPreselection
bool m_reqPreselection
Definition: SkimmingToolEXOT14.h:78
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::SkimmingToolEXOT14::m_reqJetPts
bool m_reqJetPts
Definition: SkimmingToolEXOT14.h:79
DerivationFramework::SkimmingToolEXOT14::m_reqLArError
bool m_reqLArError
Definition: SkimmingToolEXOT14.h:76
DerivationFramework::SkimmingToolEXOT14::SubcutPreselect
std::optional< LeadingJets_t > SubcutPreselect() const
Definition: SkimmingToolEXOT14.cxx:205
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::SkimmingToolEXOT14::initialize
virtual StatusCode initialize() override
Definition: SkimmingToolEXOT14.cxx:77
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework::SkimmingToolEXOT14::m_maxEta
double m_maxEta
Definition: SkimmingToolEXOT14.h:92
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DerivationFramework::SkimmingToolEXOT14::SubcutDijetMass
bool SubcutDijetMass(const LeadingJets_t &jets) const
Definition: SkimmingToolEXOT14.cxx:281
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
DerivationFramework::SkimmingToolEXOT14::SubcutLArError
bool SubcutLArError() const
Definition: SkimmingToolEXOT14.cxx:167
DerivationFramework::SkimmingToolEXOT14::m_reqTrigger
bool m_reqTrigger
Definition: SkimmingToolEXOT14.h:77
DerivationFramework::SkimmingToolEXOT14::m_reqDiJetMass
bool m_reqDiJetMass
Definition: SkimmingToolEXOT14.h:81
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DerivationFramework::SkimmingToolEXOT14::m_dijetMass
double m_dijetMass
Definition: SkimmingToolEXOT14.h:96
DerivationFramework::SkimmingToolEXOT14::m_jetDPhi
double m_jetDPhi
Definition: SkimmingToolEXOT14.h:97
EventInfo.h
DerivationFramework::SkimmingToolEXOT14::SkimmingToolEXOT14
SkimmingToolEXOT14(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: SkimmingToolEXOT14.cxx:23
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DerivationFramework::SkimmingToolEXOT14::m_jetSGKey
std::string m_jetSGKey
Definition: SkimmingToolEXOT14.h:72
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
DerivationFramework::SkimmingToolEXOT14::m_reqJetsDEta
bool m_reqJetsDEta
Definition: SkimmingToolEXOT14.h:80
DerivationFramework::SkimmingToolEXOT14::~SkimmingToolEXOT14
~SkimmingToolEXOT14()
Destructor.
Definition: SkimmingToolEXOT14.cxx:73
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::SkimmingToolEXOT14::m_goodRunList
std::string m_goodRunList
Definition: SkimmingToolEXOT14.h:86
xAOD::EventInfo_v1::errorState
EventFlagErrorState errorState(EventFlagSubDet subDet) const
Get the error state for a particular sub-detector.
Definition: EventInfo_v1.cxx:817
JetAuxContainer.h
DerivationFramework::SkimmingToolEXOT14::m_reqGRL
bool m_reqGRL
Definition: SkimmingToolEXOT14.h:75
DerivationFramework::SkimmingToolEXOT14::eventPassesFilter
virtual bool eventPassesFilter() const override
Check that the current event passes this filter.
Definition: SkimmingToolEXOT14.cxx:122
DerivationFramework::SkimmingToolEXOT14::finalize
virtual StatusCode finalize() override
Definition: SkimmingToolEXOT14.cxx:103
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
AthAlgTool
Definition: AthAlgTool.h:26
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
Decorator.h
Helper class to provide type-safe access to aux data.
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
DerivationFramework::SkimmingToolEXOT14::SubcutGoodRunList
bool SubcutGoodRunList() const
Definition: SkimmingToolEXOT14.cxx:158
Eta
@ Eta
Definition: RPCdef.h:8
SkimmingToolEXOT14.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
DerivationFramework::SkimmingToolEXOT14::m_etaSeparation
double m_etaSeparation
Definition: SkimmingToolEXOT14.h:95
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
DerivationFramework::SkimmingToolEXOT14::SubcutJetPts
bool SubcutJetPts(const LeadingJets_t &jets) const
Definition: SkimmingToolEXOT14.cxx:260