13#include "fastjet/PseudoJet.hh"
14#include "fastjet/contrib/ConstituentSubtractor.hh"
15#include "fastjet/Selector.hh"
16#include "fastjet/tools/GridMedianBackgroundEstimator.hh"
17#include "fastjet/contrib/RescalingClasses.hh"
34 ATH_MSG_ERROR(
"Incompatible configuration: setting both IgnoreChargedPFO and ApplyToChargedPFO to true"
35 <<
"will set all cPFOs to zero");
36 return StatusCode::FAILURE;
39 ATH_MSG_ERROR(
"Incompatible configuration: ApplyToNeutralPFO=False -- what kind of pileup do you wish to suppress?");
40 return StatusCode::FAILURE;
47 ATH_MSG_ERROR(
"Incompatible configuration: You set both, DoRapidityRescaling and DoRapidityPhiRescaling, to true. Use maximally only one of them.");
48 return StatusCode::FAILURE;
52 ATH_MSG_ERROR(
"Incompatible configuration: You have chosen a background rescaling, but you have not specified the path to the file with rescaling histograms or the name of the histogram. Specify properties FileRescaling and HistogramRescaling.");
53 return StatusCode::FAILURE;
58 if (fullPathToFile.empty()){
59 ATH_MSG_ERROR(
"Incompatible configuration: The provided file for rescaling was not found using PathResolver.");
60 return StatusCode::FAILURE;
62 std::unique_ptr<TFile>
file(TFile::Open(fullPathToFile.data(),
"READ"));
63 if (
file->IsZombie()){
64 ATH_MSG_ERROR(
"Incompatible configuration: The file for rescaling has been tried to open, but it was found it is zombie.");
65 return StatusCode::FAILURE;
69 ATH_MSG_ERROR(
"Incompatible configuration: The provided histogram name was not found in the root file.");
70 return StatusCode::FAILURE;
74 if (
object->InheritsFrom(TH1D::Class())){
75 m_hist.reset(
static_cast<TH1D*
>(
object->Clone(
"hist_cloned")));
76 m_hist->SetDirectory(
nullptr);
77 m_rescaling.reset(
static_cast<fastjet::FunctionOfPseudoJet<double>*
>(
new contrib::BackgroundRescalingYFromRoot<TH1D>(
m_hist.get())));
80 ATH_MSG_ERROR(
"Incompatible configuration: You want to do rapidity rescaling, but the provided histogram name is not a TH1D.");
81 return StatusCode::FAILURE;
85 if (
object->InheritsFrom(TH2D::Class())){
88 m_rescaling.reset(
static_cast<fastjet::FunctionOfPseudoJet<double>*
>(
new contrib::BackgroundRescalingYPhiFromRoot<TH2D>(
m_hist2D.get())));
91 ATH_MSG_ERROR(
"Incompatible configuration: You want to do rapidity-phi rescaling, but the provided histogram name is not a TH2D.");
92 return StatusCode::FAILURE;
98 return StatusCode::SUCCESS;
106 contrib::ConstituentSubtractor subtractor;
118 subtractor.set_use_nearby_hard(-1,-1);
121 std::vector<PseudoJet> inputs_to_correct, inputs_to_not_correct;
122 inputs_to_correct.reserve(cont->
size());
123 inputs_to_not_correct.reserve(cont->
size());
134 bool accept = part->e() > -1*FLT_MIN;
141 accept &= fabs(pfo->
charge())<FLT_MIN;
150 accept &= (tcc->
taste()!= 0)*(tcc->
pt()>-1.*FLT_MIN);
153 accept &= fabs(part->eta()) <=
m_maxEta;
155 PseudoJet pj( part->p4() );
156 pj.set_user_index( i );
158 ATH_MSG_VERBOSE(
"Using " << part->type() <<
" with pt " << part->pt());
159 inputs_to_correct.push_back(pj);
161 if (pj.rap()<minRap) minRap = pj.rap();
162 if (pj.rap()>maxRap) maxRap = pj.rap();
164 ATH_MSG_VERBOSE(
"Will not correct " << part->type() <<
" with pt " << part->pt());
165 inputs_to_not_correct.push_back(pj);
176 bge_rho.set_particles(inputs_to_correct);
177 subtractor.set_background_estimator(&bge_rho);
181 ATH_MSG_DEBUG(
"Subtracting event density from constituents");
182 std::vector<PseudoJet> corrected_event=subtractor.subtract_event(inputs_to_correct,
m_maxEta);
188 for(PseudoJet & pj : corrected_event) {
189 ATH_MSG_VERBOSE(
"Setting four-mom for constituent " << pj.user_index() <<
", pt = " << pj.pt());
190 corrected_p4s[pj.user_index()].SetCoordinates(pj.pt(),pj.eta(),pj.phi(),pj.m());
192 for(PseudoJet & pj : inputs_to_not_correct) {
193 ATH_MSG_VERBOSE(
"Setting four-mom for constituent " << pj.user_index() <<
", pt = " << pj.pt());
194 corrected_p4s[pj.user_index()].SetCoordinates(pj.pt(),pj.eta(),pj.phi(),pj.m());
196 for(PseudoJet & pj : inputs_to_not_correct) {
197 ATH_MSG_VERBOSE(
"Setting four-mom for constituent " << pj.user_index() <<
", pt = " << pj.pt());
198 corrected_p4s[pj.user_index()].SetCoordinates(pj.pt(),pj.eta(),pj.phi(),pj.m());
206 ATH_MSG_VERBOSE(
"Initial pt: " << part->pt() <<
", subtracted pt: " << corrected_p4s[i].Pt());
207 ATH_MSG_VERBOSE(
"Initial eta: " << part->eta() <<
", subtracted pt: " << corrected_p4s[i].Eta());
208 ATH_MSG_VERBOSE(
"Initial phi: " << part->phi() <<
", subtracted pt: " << corrected_p4s[i].Phi());
215 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
size_type size() const noexcept
Returns the number of elements in the collection.
JetConstituentModifierBase(const std::string &name)
StatusCode setP4(xAOD::IParticle *obj, const xAOD::JetFourMom_t &p4, const SG::AuxElement::Accessor< float > *weightAcc=nullptr) const
SG::Accessor< T, ALLOC > Accessor
Class providing the definition of the 4-vector interface.
float charge() const
get charge of PFO
virtual int taste() const
The taste of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
@ ParticleFlow
The object is a particle-flow object.
@ FlowElement
The object is a track-calo-cluster.
@ TrackCaloCluster
The object is a track-calo-cluster.
PFO_v1 PFO
Definition of the current "pfo version".
FlowElement_v1 FlowElement
Definition of the current "pfo version".
TrackCaloCluster_v1 TrackCaloCluster
Reference the current persistent version:
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.