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  base_class(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 
41  declareProperty("JetContainer", m_jetSGKey = "AntiKt4LCTopoJets");
42 
43  declareProperty("RequireGRL", m_reqGRL = true);
44  declareProperty("ReqireLArError", m_reqLArError = true);
45  declareProperty("RequireTrigger", m_reqTrigger = true);
46  declareProperty("RequirePreselection", m_reqPreselection = true);
47  declareProperty("RequireJetPts", m_reqJetPts = true);
48  declareProperty("RequireJetsDEta", m_reqJetsDEta = true);
49  declareProperty("RequireDiJetMass", m_reqDiJetMass = true);
50  declareProperty("RequireJetsDPhi", m_reqJetsDPhi = true);
51 
52  declareProperty("GoodRunList", m_goodRunList = "");
53 
54  declareProperty("DefaultTrigger", m_defaultTrigger = "HLT_xe100");
55  declareProperty("Triggers", m_triggers = std::vector<std::string>());
56 
57  declareProperty("MinimumJetPt", m_minJetPt = 25*CLHEP::GeV);
58  declareProperty("MaxEta", m_maxEta = 4.8);
59 
60  declareProperty("LeadingJetPtCut", m_leadingJetPt = 75*CLHEP::GeV);
61  declareProperty("SubleadingJetPtCut", m_subleadingJetPt = 50*CLHEP::GeV);
62 
63  declareProperty("EtaSeparation", m_etaSeparation = 4.8);
64 
65  declareProperty("DiJetsMass", m_dijetMass = 1000*CLHEP::GeV);
66 
67  declareProperty("DiJetDPhi", m_jetDPhi = 2.5);
68 
69 }
70 
71 // Destructor
73 }
74 
75 // Athena initialize and finalize
77 {
78  ATH_MSG_VERBOSE("INITIALIZING VBFINV SELECTOR TOOL");
79 
81  // trigger decision tool
82  if(m_trigDecisionTool.retrieve(DisableTool{!m_reqTrigger}).isFailure()) {
83  ATH_MSG_FATAL("Failed to retrieve tool: " << m_trigDecisionTool);
84  return StatusCode::FAILURE;
85  }
86  if (!m_triggers.size()) m_triggers.push_back(m_defaultTrigger);
87  ATH_MSG_INFO("Retrieved tool: " << m_trigDecisionTool);
89 
90 
92  // jet energy calibration
93  m_JESTool.setTypeAndName("JetCalibrationTool/m_JESTool");
94  CHECK( m_JESTool.retrieve() ); //optional, just forces initializing the tool here instead of at first use
95  ATH_MSG_INFO("Retrieved tool: " << m_JESTool);
97 
98 
99  return StatusCode::SUCCESS;
100 }
101 
103 {
104  ATH_MSG_VERBOSE("finalize() ...");
105  ATH_MSG_INFO("Processed " << m_n_tot << " events, " << m_n_pass << " events passed filter ");
106 
107  ATH_MSG_INFO("GRL :: " << m_n_passGRL);
108  ATH_MSG_INFO("LAr Error :: " << m_n_passLArError);
109  ATH_MSG_INFO("Trigger :: " << m_n_passTrigger);
110  ATH_MSG_INFO("Preselect :: " << m_n_passPreselect);
111  ATH_MSG_INFO("JetPts :: " << m_n_passJetPts);
112  ATH_MSG_INFO("JetsDEta :: " << m_n_passJetsDEta);
113  ATH_MSG_INFO("DijetMass :: " << m_n_passDiJetMass);
114  ATH_MSG_INFO("JetsDPhi :: " << m_n_passJetsDPhi);
115 
116  return StatusCode::SUCCESS;
117 
118 }
119 
120 // The filter itself
122 {
123 
124  m_n_tot++;
125 
126  bool writeEvent(false);
127 
128  // int *leading = new int(0);
129  // if (!evtStore()->contains<int>("leading")) CHECK(evtStore()->record(leading, "leading"));
130 
131  if (!SubcutGoodRunList() && m_reqGRL ) return false;
132  if (!SubcutLArError() && m_reqLArError ) return false;
133  if (!SubcutTrigger() && m_reqTrigger ) return false;
134 
135  const auto jets = SubcutPreselect();
136  if (!m_reqPreselection) writeEvent = true;
137 
138  // There *must* be two jets for the remaining
139  // pieces, but you can still save the event...
140  if (jets) {
141 
142  bool passDiJets(true);
143  if (!SubcutJetPts(jets.value()) && m_reqJetPts ) passDiJets = false;
144  if (!SubcutJetDEta(jets.value()) && m_reqJetsDEta ) passDiJets = false;
145  if (!SubcutDijetMass(jets.value()) && m_reqDiJetMass) passDiJets = false;
146  if (!SubcutJetDPhi(jets.value()) && m_reqJetsDPhi ) passDiJets = false;
147  if (passDiJets) writeEvent = true;
148  }
149 
150  if (!writeEvent) return false;
151 
152  m_n_pass++;
153  return true;
154 
155 }
156 
158 
159  // Placeholder
160  m_n_passGRL++;
161  return true;
162 
163 }
164 
165 
167 
168  // Retrieve EventInfo
169  const xAOD::EventInfo *eventInfo(0);
170  ATH_CHECK(evtStore()->retrieve(eventInfo), false);
171 
172  const bool passLArError = !(eventInfo->errorState(xAOD::EventInfo::LAr) == xAOD::EventInfo::Error);
173 
174  if (passLArError) m_n_passLArError++;
175  return passLArError;
176 
177 }
178 
179 
181 
182  const xAOD::EventInfo *eventInfo(0);
183  ATH_CHECK(evtStore()->retrieve(eventInfo), false);
184 
185  bool passTrigger = false;
186 
187  for (unsigned int i = 0; i < m_triggers.size(); i++) {
188  bool thisTrig = m_trigDecisionTool->isPassed(m_triggers.at(i));
189  SG::Decorator<bool> acc(TriggerVarName(m_triggers.at(i)));
190  acc(*eventInfo) = thisTrig;
191  // ATH_MSG_INFO("TRIGGER = " << m_triggers.at(i) << " -->> " << thisTrig);
192  passTrigger |= thisTrig;
193  }
194 
195  // temporary pass-through of trigger cut for MC
196  if (eventInfo->eventType(xAOD::EventInfo::IS_SIMULATION)) passTrigger = true;
197 
198  if (passTrigger) m_n_passTrigger++;
199  return passTrigger;
200 
201 }
202 
203 std::optional<DerivationFramework::SkimmingToolEXOT14::LeadingJets_t>
205 
206  // xAOD::TStore store;
207  const xAOD::JetContainer *jets(0);
208  ATH_CHECK(evtStore()->retrieve(jets, m_jetSGKey), {});
209  xAOD::JetContainer::const_iterator jet_itr(jets->begin());
211 
212  xAOD::JetContainer calibJets;
213  calibJets.setStore(new xAOD::JetAuxContainer());
214 
215  TLorentzVector j1TLV, j2TLV;
216 
217  // Copy jets into the container to be calibrated
218  while(jet_itr != jet_end) {
219  xAOD::Jet* jetC = new xAOD::Jet();
220  jetC->setJetP4(xAOD::JetFourMom_t((*jet_itr)->pt(), (*jet_itr)->eta(), (*jet_itr)->phi(), (*jet_itr)->m()));
221  calibJets.push_back(jetC);
222  ++jet_itr;
223  }
224 
225  // Calibrate the jets
226  if(m_JESTool->applyCalibration(calibJets).isFailure())
227  ATH_MSG_WARNING("Jet calibration returned FAILURE!");
228 
229  jet_itr = calibJets.begin();
230  jet_end = calibJets.end();
231  while(jet_itr != jet_end) {
232 
233  if (abs((*jet_itr)->eta()) > m_maxEta) continue;
234 
235  if ((*jet_itr)->pt() > j1TLV.Pt()) {
236 
237  j2TLV = j1TLV;
238  j1TLV.SetPtEtaPhiE((*jet_itr)->pt(), (*jet_itr)->eta(), (*jet_itr)->phi(), (*jet_itr)->e());
239 
240  } else if ((*jet_itr)->pt() > j2TLV.Pt()) {
241 
242  j2TLV.SetPtEtaPhiE((*jet_itr)->pt(), (*jet_itr)->eta(), (*jet_itr)->phi(), (*jet_itr)->e());
243  }
244 
245  ++jet_itr;
246  }
247 
248  // save this for this code.
249  if (j2TLV.Pt() > m_minJetPt) {
250  m_n_passPreselect++;
251  return LeadingJets_t{j1TLV, j2TLV};
252  }
253 
254  return {};
255 
256 }
257 
258 
260 
261  bool passJetPts = (!m_leadingJetPt || jets[0].Pt() > m_leadingJetPt);
262  passJetPts &= (!m_subleadingJetPt || jets[1].Pt() > m_subleadingJetPt);
263 
264  if (passJetPts) m_n_passJetPts++;
265  return passJetPts;
266 
267 }
268 
270 
271  const double JetsDEta = fabs(jets[0].Eta() - jets[1].Eta());
272  const bool passJetsDEta = JetsDEta > m_etaSeparation;
273 
274  if (passJetsDEta) m_n_passJetsDEta++;
275  return passJetsDEta;
276 
277 }
278 
279 
281 
282  const double DiJetMass = (jets[0] + jets[1]).M();
283  const bool passDiJetMass = DiJetMass > m_dijetMass;
284 
285  if (passDiJetMass) m_n_passDiJetMass++;
286  return passDiJetMass;
287 
288 }
289 
291 
292  const double JetsDPhi = fabs(jets[0].DeltaPhi(jets[1]));
293  const bool passJetsDPhi = JetsDPhi < m_jetDPhi;
294 
295  if (passJetsDPhi) m_n_passJetsDPhi++;
296  return passJetsDPhi;
297 
298 }
299 
301  std::replace(s.begin(), s.end(), '-', '_'); return s;
302 }
303 
304 
305 
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
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:18
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
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
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::SkimmingToolEXOT14::SubcutTrigger
bool SubcutTrigger() const
Definition: SkimmingToolEXOT14.cxx:180
DerivationFramework::SkimmingToolEXOT14::SubcutJetDPhi
bool SubcutJetDPhi(const LeadingJets_t &jets) const
Definition: SkimmingToolEXOT14.cxx:290
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
DerivationFramework::SkimmingToolEXOT14::SubcutJetDEta
bool SubcutJetDEta(const LeadingJets_t &jets) const
Definition: SkimmingToolEXOT14.cxx:269
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
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
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:300
SG::Decorator< bool >
DerivationFramework::SkimmingToolEXOT14::m_reqPreselection
bool m_reqPreselection
Definition: SkimmingToolEXOT14.h:78
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:729
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:204
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:76
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:794
DerivationFramework::SkimmingToolEXOT14::SubcutDijetMass
bool SubcutDijetMass(const LeadingJets_t &jets) const
Definition: SkimmingToolEXOT14.cxx:280
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:166
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:72
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
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
DerivationFramework::SkimmingToolEXOT14::eventPassesFilter
virtual bool eventPassesFilter() const override
Check that the current event passes this filter.
Definition: SkimmingToolEXOT14.cxx:121
DerivationFramework::SkimmingToolEXOT14::finalize
virtual StatusCode finalize() override
Definition: SkimmingToolEXOT14.cxx:102
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:157
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:259