19#include "fastjet/ClusterSequence.hh"
20#include "fastjet/ClusterSequenceArea.hh"
21#include <fastjet/AreaDefinition.hh>
53 ATH_MSG_ERROR(
"JetForwardPFlowJvtTool needs to have its input jet container configured!");
54 return StatusCode::FAILURE;
88#ifndef XAOD_STANDALONE
94 return StatusCode::SUCCESS;
98 std::vector<TVector2> pileupMomenta;
104 if(pileupMomenta.empty()) {
105 ATH_MSG_DEBUG(
"pileupMomenta is empty, this can happen for events with no PU vertices."
106 <<
" fJVT won't be computed for this event and will be set to 0 instead." );
108 fjvtHandle(*jetF) = 1;
109 fjvtRawHandle(*jetF) = 0;
111 return StatusCode::SUCCESS;
115 fjvtHandle(*jetF) = 1;
116 fjvtRawHandle(*jetF) = 0;
119 double fjvt =
getFJVT(jetF,pileupMomenta);
121 fjvtRawHandle(*jetF) = fjvt;
124 return StatusCode::SUCCESS;
128 TVector2 fjet(
jet->pt()*cos(
jet->phi()),
jet->pt()*sin(
jet->phi()));
130 for (
const TVector2& pu : pileupMomenta) {
131 double projection = pu*fjet/fjet.Mod();
132 if (projection<fjvt) fjvt = projection;
134 return -1*fjvt/fjet.Mod();
138 int pvind,
int vertices)
const {
139 std::vector<TVector2> pileupMomenta;
141 const std::size_t pv_index = (pvind==-1) ?
getPV() : std::size_t(pvind);
147 if(vx->index()==(
size_t)pv_index)
continue;
150 jname += vx->index();
154 ATH_MSG_WARNING(
" Some issue appeared while building the pflow pileup jets for vertex "
155 << vx->index() <<
" (vxType = " << vx->vertexType()<<
" )!" );
156 return pileupMomenta;
168 vertex_met += TVector2(
jet->pt()*cos(
jet->phi()),
jet->pt()*sin(
jet->phi()) ) ;
176 pileupMomenta.push_back(vertex_met);
177 if(vertices!=-1 &&
int(vx->index())==vertices)
break;
179 return pileupMomenta;
184 char jet_nnjvtpass=
false;
186 jet_nnjvtpass = passJvtHandle(*pjet);
187 if (pjet->p4().DeltaR(
jet->p4())<0.3 && jet_nnjvtpass &&
isCentralJet(pjet) )
return true;
196 std::vector<fastjet::PseudoJet> input_pfo;
197 std::set<int> charged_pfo;
202 ATH_MSG_ERROR(
"Could not retrieve the TrackVertexAssociation: "
213 if (!orHandle(*fe))
continue;
215 if (fe->isCharged()) {
218 if (vx.index()==pv_index && std::abs((vx.
z()-track->z0())*sin(track->theta()))>
m_dzCut)
220 if (vx.index()!=pv_index
221 && (!tvaHandle->associatedVertex(track)
222 || vx.index()!=tvaHandle->associatedVertex(track)->index())
225 charged_pfo.insert(fe->index());
227 else if (std::abs(fe->eta())<
m_neutMaxRap && !fe->isCharged() && fe->e()>0)
239 if (!orHandle(*pfo))
continue;
241 if (pfo->isCharged()) {
242 if (vx.index()==pv_index && std::abs((vx.
z()-pfo->track(0)->z0())*sin(pfo->track(0)->theta()))>
m_dzCut)
244 if (vx.index()!=pv_index
245 && (!tvaHandle->associatedVertex(pfo->track(0))
246 || vx.index()!=tvaHandle->associatedVertex(pfo->track(0))->index())
249 charged_pfo.insert(pfo->index());
251 else if (std::abs(pfo->eta())<
m_neutMaxRap && !pfo->isCharged() && pfo->eEM()>0)
258 std::shared_ptr<xAOD::JetContainer> vertjets = std::make_shared<xAOD::JetContainer>();
259 std::shared_ptr<xAOD::JetAuxContainer> vertjetsAux = std::make_shared<xAOD::JetAuxContainer>();
261 vertjets->setStore(vertjetsAux.get());
263 newname += vx.index();
266 std::vector<int> seeds;
268 if (!evtInfoHandle.isValid())
275 fastjet::JetDefinition jet_def(fastjet::antikt_algorithm,0.4);
276 fastjet::AreaDefinition area_def(fastjet::active_area_explicit_ghosts,
277 fastjet::GhostedAreaSpec(fastjet::SelectorAbsRapMax(
m_maxRap)));
278 area_def = area_def.with_fixed_seed(seeds);
279 fastjet::ClusterSequenceArea clust_pfo(input_pfo,jet_def,area_def);
280 std::vector<fastjet::PseudoJet> inclusive_jets = sorted_by_pt(clust_pfo.inclusive_jets(5000.));
282 for (
size_t i = 0; i < inclusive_jets.size(); i++) {
285 inclusive_jets[i].
eta(),
286 inclusive_jets[i].
phi(),
287 inclusive_jets[i].m());
289 inclusive_jets[i].area_4vector().
eta(),
290 inclusive_jets[i].area_4vector().
phi(),
291 inclusive_jets[i].area_4vector().m());
292 vertjets->push_back(
jet);
293 jet->setJetP4(tempjetp4);
295 static const std::string p4Str1{
"JetConstitScaleMomentum"};
296 static const std::string p4Str2{
"JetPileupScaleMomentum"};
297 static const std::string activeAreaStr{
"ActiveArea4vec"};
298 static const std::string detectorEtaStr{
"DetectorEta"};
300 jet->setJetP4(p4Str1,tempjetp4);
301 jet->setJetP4(p4Str2,tempjetp4);
302 jet->setAttribute(activeAreaStr,newArea);
303 jet->setAttribute(detectorEtaStr,
jet->eta());
305 std::vector<fastjet::PseudoJet> constituents = inclusive_jets[i].constituents();
306 float chargedpart = 0;
307 for (
size_t j = 0; j < constituents.size(); j++) {
308 if (charged_pfo.count(constituents[j].user_index())>=1) {
309 chargedpart += constituents[j].perp();
316 if((
m_pfoJES->modify(*vertjets)).isFailure()){
321 pu_jets.
jetCont = std::move(vertjets);
327 TLorentzVector pfo_p4;
330 if( (
m_wpfotool->fillWeight(*pfo,pweight)).isSuccess() ){
332 pfo_p4= TLorentzVector(pfo->
p4().Px()*pweight,pfo->
p4().Py()*pweight,pfo->
p4().Pz()*pweight,pfo->
e()*pweight);
337 fastjet::PseudoJet psj(pfo_p4);
340 psj.set_user_index(pfo->index());
342 psj.set_user_index(-1);
349 TLorentzVector fe_p4;
352 if( (
m_wpfotool->fillWeight(*fe,pweight)).isSuccess() ){
354 fe_p4= TLorentzVector(fe->
p4().Px()*pweight,fe->
p4().Py()*pweight,fe->
p4().Pz()*pweight,fe->
e()*pweight);
359 fastjet::PseudoJet psj(fe_p4);
362 psj.set_user_index(fe->index());
364 psj.set_user_index(-1);
393 ATH_MSG_DEBUG(
"Successfully retrieved primary vertex container");
398 if(vxContHandle->empty() ){
400 }
else if(vxContHandle->size() != 1 ){
401 ATH_MSG_WARNING(
"Couldn't identify the hard-scatter primary vertex (no vertex with \"vx->vertexType()==xAOD::VxType::PriVtx\" in the container)! ");
415 for(
const xAOD::Jet *tjet : *truthJets) {
416 if (tjet->p4().DeltaR(
jet->p4())<0.3 && tjet->pt()>10e3) ishs =
true;
417 if (tjet->p4().DeltaR(
jet->p4())<0.6) ispu =
false;
419 isHSHandle(*
jet)=ishs;
420 isPUHandle(*
jet)=ispu;
422 return StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
Scalar perp() const
perp method - perpendicular length
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
Defines enum to access jet attribute and associated particles/objects.
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
virtual double e() const override
The total energy of the particle.
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
TLorentzVector GetVertexCorrectedEMFourVec(const xAOD::Vertex &vertexToCorrectTo) const
Correct EM scale 4-vector to point at a vertex.
virtual double e() const
The total energy of the particle.
float z() const
Returns the z position.
TLorentzVector getVertexCorrectedFourVec(const xAOD::FlowElement &fe, const xAOD::Vertex &vertexToCorrectTo)
void seedsFromEventInfo(const xAOD::EventInfo *ei, std::vector< int > &seeds)
Fill seeds vector from run & event number. This functio is separated from the class so it's easier to...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Jet_v1 Jet
Definition of the current "jet version".
PFO_v1 PFO
Definition of the current "pfo version".
FlowElement_v1 FlowElement
Definition of the current "pfo version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
std::shared_ptr< xAOD::JetAuxContainer > jetAuxCont
std::shared_ptr< xAOD::JetContainer > jetCont