CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
PileupJetIdProducer Class Reference

#include <CMGTools/PileupJetIdProducer/src/PileupJetIdProducer.cc>

Inheritance diagram for PileupJetIdProducer:
edm::stream::EDProducer< edm::GlobalCache< GBRForestsAndConstants > >

Public Member Functions

 PileupJetIdProducer (const edm::ParameterSet &, GBRForestsAndConstants const *)
 
 ~PileupJetIdProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< GBRForestsAndConstants > >
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static void globalEndJob (GBRForestsAndConstants *)
 
static std::unique_ptr< GBRForestsAndConstantsinitializeGlobalCache (edm::ParameterSet const &pset)
 

Private Member Functions

void initJetEnergyCorrector (const edm::EventSetup &iSetup, bool isData)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::vector< std::pair< std::string, std::unique_ptr< PileupJetIdAlgo > > > algos_
 
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
 
edm::EDGetTokenT< double > input_rho_token_
 
edm::EDGetTokenT< reco::VertexCollectioninput_vertex_token_
 
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_
 
std::unique_ptr< FactorizedJetCorrectorjecCor_
 
std::vector< JetCorrectorParametersjetCorPars_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< GBRForestsAndConstants > >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Description: Produces a value map of jet --> pileup jet ID

Implementation: [Notes on implementation]

Definition at line 79 of file PileupJetIdProducer.h.

Constructor & Destructor Documentation

◆ PileupJetIdProducer()

PileupJetIdProducer::PileupJetIdProducer ( const edm::ParameterSet iConfig,
GBRForestsAndConstants const *  globalCache 
)
explicit

Definition at line 44 of file PileupJetIdProducer.cc.

44  {
45  if (globalCache->produceJetIds()) {
46  produces<edm::ValueMap<StoredPileupJetIdentifier>>("");
47  }
48  for (auto const& algoGBRForestsAndConstants : globalCache->vAlgoGBRForestsAndConstants()) {
49  std::string const& label = algoGBRForestsAndConstants.label();
50  algos_.emplace_back(label, std::make_unique<PileupJetIdAlgo>(&algoGBRForestsAndConstants));
51  if (globalCache->runMvas()) {
52  produces<edm::ValueMap<float>>(label + "Discriminant");
53  produces<edm::ValueMap<int>>(label + "Id");
54  }
55  }
56 
57  input_jet_token_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jets"));
58  input_vertex_token_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexes"));
60  consumes<edm::ValueMap<StoredPileupJetIdentifier>>(iConfig.getParameter<edm::InputTag>("jetids"));
61  input_rho_token_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
62 }

References algos_, edm::ParameterSet::getParameter(), input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, label, GBRForestsAndConstants::produceJetIds(), GBRForestsAndConstants::runMvas(), AlCaHLTBitMon_QueryRunRegistry::string, and GBRForestsAndConstants::vAlgoGBRForestsAndConstants().

◆ ~PileupJetIdProducer()

PileupJetIdProducer::~PileupJetIdProducer ( )
override

Definition at line 65 of file PileupJetIdProducer.cc.

65 {}

Member Function Documentation

◆ fillDescriptions()

void PileupJetIdProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 225 of file PileupJetIdProducer.cc.

225  {
226  //The following says we do not know what parameters are allowed so do no validation
227  // Please change this to state exactly what you do use, even if it is no parameters
229  desc.setUnknown();
230  descriptions.addDefault(desc);
231 }

References edm::ConfigurationDescriptions::addDefault(), and edm::ParameterSetDescription::setUnknown().

◆ globalEndJob()

static void PileupJetIdProducer::globalEndJob ( GBRForestsAndConstants )
inlinestatic

Definition at line 90 of file PileupJetIdProducer.h.

90 {}

◆ initializeGlobalCache()

static std::unique_ptr<GBRForestsAndConstants> PileupJetIdProducer::initializeGlobalCache ( edm::ParameterSet const &  pset)
inlinestatic

Definition at line 86 of file PileupJetIdProducer.h.

86  {
87  return std::make_unique<GBRForestsAndConstants>(pset);
88  }

References muonDTDigis_cfi::pset.

◆ initJetEnergyCorrector()

void PileupJetIdProducer::initJetEnergyCorrector ( const edm::EventSetup iSetup,
bool  isData 
)
private

Definition at line 234 of file PileupJetIdProducer.cc.

234  {
235  GBRForestsAndConstants const* gc = globalCache();
236 
237  //jet energy correction levels to apply on raw jet
238  std::vector<std::string> jecLevels;
239  jecLevels.push_back("L1FastJet");
240  jecLevels.push_back("L2Relative");
241  jecLevels.push_back("L3Absolute");
242  if (isData && !gc->residualsFromTxt())
243  jecLevels.push_back("L2L3Residual");
244 
245  //check the corrector parameters needed according to the correction levels
247  iSetup.get<JetCorrectionsRecord>().get(gc->jec(), parameters);
248  for (std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll) {
249  const JetCorrectorParameters& ip = (*parameters)[*ll];
250  jetCorPars_.push_back(ip);
251  }
252  if (isData && gc->residualsFromTxt()) {
254  }
255 
256  //instantiate the jet corrector
257  jecCor_ = std::make_unique<FactorizedJetCorrector>(jetCorPars_);
258 }

References edm::FileInPath::fullPath(), edm::EventSetup::get(), get, HLTBitAnalyser_cfi::isData, GBRForestsAndConstants::jec(), jecCor_, jetCorPars_, GBRForestsAndConstants::residualsFromTxt(), and GBRForestsAndConstants::residualsTxt().

Referenced by produce().

◆ produce()

void PileupJetIdProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 68 of file PileupJetIdProducer.cc.

68  {
69  GBRForestsAndConstants const* gc = globalCache();
70 
71  using namespace edm;
72  using namespace std;
73  using namespace reco;
74 
75  // Input jets
76  Handle<View<Jet>> jetHandle;
77  iEvent.getByToken(input_jet_token_, jetHandle);
78  const View<Jet>& jets = *jetHandle;
79 
80  // input variables
82  if (!gc->produceJetIds()) {
83  iEvent.getByToken(input_vm_pujetid_token_, vmap);
84  }
85  // rho
87  double rho = 0.;
88 
89  // products
90  vector<StoredPileupJetIdentifier> ids;
91  map<string, vector<float>> mvas;
92  map<string, vector<int>> idflags;
93 
94  const VertexCollection* vertexes = nullptr;
95  VertexCollection::const_iterator vtx;
96  if (gc->produceJetIds()) {
97  // vertexes
98  Handle<VertexCollection> vertexHandle;
99  iEvent.getByToken(input_vertex_token_, vertexHandle);
100 
101  vertexes = vertexHandle.product();
102 
103  // require basic quality cuts on the vertexes
104  vtx = vertexes->begin();
105  while (vtx != vertexes->end() && (vtx->isFake() || vtx->ndof() < 4)) {
106  ++vtx;
107  }
108  if (vtx == vertexes->end()) {
109  vtx = vertexes->begin();
110  }
111  }
112 
113  // Loop over input jets
114  bool ispat = true;
115  for (unsigned int i = 0; i < jets.size(); ++i) {
116  // Pick the first algo to compute the input variables
117  auto algoi = algos_.begin();
118  PileupJetIdAlgo* ialgo = algoi->second.get();
119 
120  const Jet& jet = jets.at(i);
121  const pat::Jet* patjet = nullptr;
122  if (ispat) {
123  patjet = dynamic_cast<const pat::Jet*>(&jet);
124  ispat = patjet != nullptr;
125  }
126 
127  // Get jet energy correction
128  float jec = 0.;
129  if (gc->applyJec()) {
130  // If haven't done it get rho from the event
131  if (rho == 0.) {
132  iEvent.getByToken(input_rho_token_, rhoH);
133  rho = *rhoH;
134  }
135  // jet corrector
136  if (not jecCor_) {
137  initJetEnergyCorrector(iSetup, iEvent.isRealData());
138  }
139  if (ispat) {
140  jecCor_->setJetPt(patjet->correctedJet(0).pt());
141  } else {
142  jecCor_->setJetPt(jet.pt());
143  }
144  jecCor_->setJetEta(jet.eta());
145  jecCor_->setJetA(jet.jetArea());
146  jecCor_->setRho(rho);
147  jec = jecCor_->getCorrection();
148  }
149  // If it was requested AND the input is an uncorrected jet apply the JEC
150  bool applyJec = gc->applyJec() && (ispat || !gc->inputIsCorrected());
151  std::unique_ptr<reco::Jet> corrJet;
152 
153  if (applyJec) {
154  float scale = jec;
155  if (ispat) {
156  corrJet.reset(new pat::Jet(patjet->correctedJet(0)));
157  } else {
158  corrJet.reset(dynamic_cast<reco::Jet*>(jet.clone()));
159  }
160  corrJet->scaleEnergy(scale);
161  }
162  const reco::Jet* theJet = (applyJec ? corrJet.get() : &jet);
163 
164  PileupJetIdentifier puIdentifier;
165  if (gc->produceJetIds()) {
166  // Compute the input variables
167  puIdentifier = ialgo->computeIdVariables(theJet, jec, &(*vtx), *vertexes, rho, gc->usePuppi());
168  ids.push_back(puIdentifier);
169  } else {
170  // Or read it from the value map
171  puIdentifier = (*vmap)[jets.refAt(i)];
172  puIdentifier.jetPt(theJet->pt()); // make sure JEC is applied when computing the MVA
173  puIdentifier.jetEta(theJet->eta());
174  puIdentifier.jetPhi(theJet->phi());
175  ialgo->set(puIdentifier);
176  puIdentifier = ialgo->computeMva();
177  }
178 
179  if (gc->runMvas()) {
180  // Compute the MVA and WP
181  mvas[algoi->first].push_back(puIdentifier.mva());
182  idflags[algoi->first].push_back(puIdentifier.idFlag());
183  for (++algoi; algoi != algos_.end(); ++algoi) {
184  ialgo = algoi->second.get();
185  ialgo->set(puIdentifier);
186  PileupJetIdentifier id = ialgo->computeMva();
187  mvas[algoi->first].push_back(id.mva());
188  idflags[algoi->first].push_back(id.idFlag());
189  }
190  }
191  }
192 
193  // Produce the output value maps
194  if (gc->runMvas()) {
195  for (const auto& ialgo : algos_) {
196  // MVA
197  vector<float>& mva = mvas[ialgo.first];
198  auto mvaout = std::make_unique<ValueMap<float>>();
199  ValueMap<float>::Filler mvafiller(*mvaout);
200  mvafiller.insert(jetHandle, mva.begin(), mva.end());
201  mvafiller.fill();
202  iEvent.put(std::move(mvaout), ialgo.first + "Discriminant");
203 
204  // WP
205  vector<int>& idflag = idflags[ialgo.first];
206  auto idflagout = std::make_unique<ValueMap<int>>();
207  ValueMap<int>::Filler idflagfiller(*idflagout);
208  idflagfiller.insert(jetHandle, idflag.begin(), idflag.end());
209  idflagfiller.fill();
210  iEvent.put(std::move(idflagout), ialgo.first + "Id");
211  }
212  }
213  // input variables
214  if (gc->produceJetIds()) {
215  assert(jetHandle->size() == ids.size());
216  auto idsout = std::make_unique<ValueMap<StoredPileupJetIdentifier>>();
218  idsfiller.insert(jetHandle, ids.begin(), ids.end());
219  idsfiller.fill();
220  iEvent.put(std::move(idsout));
221  }
222 }

References algos_, jetMETDQMOfflineSource_cff::applyJec, GBRForestsAndConstants::applyJec(), cms::cuda::assert(), PileupJetIdAlgo::computeIdVariables(), PileupJetIdAlgo::computeMva(), pat::Jet::correctedJet(), reco::LeafCandidate::eta(), mps_fire::i, PileupJetIdentifier::idFlag(), iEvent, initJetEnergyCorrector(), input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, GBRForestsAndConstants::inputIsCorrected(), jetMETDQMOfflineSource_cff::jec, jecCor_, metsig::jet, StoredPileupJetIdentifier::jetEta(), PileupJetIdentifier::jetPhi(), StoredPileupJetIdentifier::jetPt(), singleTopDQM_cfi::jets, eostools::move(), PileupJetIdentifier::mva(), beam_dqm_sourceclient-live_cfg::mva, reco::LeafCandidate::phi(), GBRForestsAndConstants::produceJetIds(), edm::Handle< T >::product(), reco::LeafCandidate::pt(), rho, GBRForestsAndConstants::runMvas(), Scenarios_cff::scale, PileupJetIdAlgo::set(), GBRForestsAndConstants::usePuppi(), jets_cff::vertexes, and badGlobalMuonTaggersAOD_cff::vtx.

Member Data Documentation

◆ algos_

std::vector<std::pair<std::string, std::unique_ptr<PileupJetIdAlgo> > > PileupJetIdProducer::algos_
private

Definition at line 97 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

◆ input_jet_token_

edm::EDGetTokenT<edm::View<reco::Jet> > PileupJetIdProducer::input_jet_token_
private

Definition at line 102 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

◆ input_rho_token_

edm::EDGetTokenT<double> PileupJetIdProducer::input_rho_token_
private

Definition at line 105 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

◆ input_vertex_token_

edm::EDGetTokenT<reco::VertexCollection> PileupJetIdProducer::input_vertex_token_
private

Definition at line 103 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

◆ input_vm_pujetid_token_

edm::EDGetTokenT<edm::ValueMap<StoredPileupJetIdentifier> > PileupJetIdProducer::input_vm_pujetid_token_
private

Definition at line 104 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

◆ jecCor_

std::unique_ptr<FactorizedJetCorrector> PileupJetIdProducer::jecCor_
private

Definition at line 99 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), and produce().

◆ jetCorPars_

std::vector<JetCorrectorParameters> PileupJetIdProducer::jetCorPars_
private

Definition at line 100 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector().

PileupJetIdProducer::input_vertex_token_
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
Definition: PileupJetIdProducer.h:103
mps_fire.i
i
Definition: mps_fire.py:355
reco::Jet
Base class for all types of Jets.
Definition: Jet.h:20
edm::Handle::product
T const * product() const
Definition: Handle.h:70
PileupJetIdProducer::input_jet_token_
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
Definition: PileupJetIdProducer.h:102
PileupJetIdProducer::jetCorPars_
std::vector< JetCorrectorParameters > jetCorPars_
Definition: PileupJetIdProducer.h:100
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
PileupJetIdentifier::mva
const float & mva() const
Definition: PileupJetIdentifier.h:94
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
cms::cuda::assert
assert(be >=bs)
jets_cff.vertexes
vertexes
Definition: jets_cff.py:644
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
PileupJetIdProducer::jecCor_
std::unique_ptr< FactorizedJetCorrector > jecCor_
Definition: PileupJetIdProducer.h:99
beam_dqm_sourceclient-live_cfg.mva
mva
Definition: beam_dqm_sourceclient-live_cfg.py:116
GBRForestsAndConstants::applyJec
bool applyJec() const
Definition: PileupJetIdProducer.h:60
edm::Handle
Definition: AssociativeIterator.h:50
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
PileupJetIdAlgo::set
void set(const PileupJetIdentifier &)
Definition: PileupJetIdAlgo.cc:146
GBRForestsAndConstants::usePuppi
bool usePuppi() const
Definition: PileupJetIdProducer.h:64
pat::Jet
Analysis-level calorimeter jet class.
Definition: Jet.h:77
GBRForestsAndConstants
Definition: PileupJetIdProducer.h:49
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
GBRForestsAndConstants::residualsFromTxt
bool residualsFromTxt() const
Definition: PileupJetIdProducer.h:62
Jet
Definition: Jet.py:1
GBRForestsAndConstants::runMvas
bool runMvas() const
Definition: PileupJetIdProducer.h:57
HLTBitAnalyser_cfi.isData
isData
Definition: HLTBitAnalyser_cfi.py:29
PileupJetIdProducer::input_rho_token_
edm::EDGetTokenT< double > input_rho_token_
Definition: PileupJetIdProducer.h:105
edm::ESHandle
Definition: DTSurvey.h:22
PileupJetIdProducer::initJetEnergyCorrector
void initJetEnergyCorrector(const edm::EventSetup &iSetup, bool isData)
Definition: PileupJetIdProducer.cc:234
PileupJetIdAlgo::computeIdVariables
PileupJetIdentifier computeIdVariables(const reco::Jet *jet, float jec, const reco::Vertex *, const reco::VertexCollection &, double rho, bool usePuppi)
Definition: PileupJetIdAlgo.cc:251
JetCorrectionsRecord
Definition: JetCorrectionsRecord.h:11
DDAxes::rho
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View
Definition: CaloClusterFwd.h:14
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
GBRForestsAndConstants::inputIsCorrected
bool inputIsCorrected() const
Definition: PileupJetIdProducer.h:59
GBRForestsAndConstants::residualsTxt
edm::FileInPath const & residualsTxt() const
Definition: PileupJetIdProducer.h:63
PileupJetIdAlgo::computeMva
PileupJetIdentifier computeMva()
Definition: PileupJetIdAlgo.cc:245
iEvent
int iEvent
Definition: GenABIO.cc:224
PileupJetIdentifier
Definition: PileupJetIdentifier.h:74
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
get
#define get
PileupJetIdentifier::idFlag
const int & idFlag() const
Definition: PileupJetIdentifier.h:91
StoredPileupJetIdentifier::jetEta
const float & jetEta() const
Definition: PileupJetIdentifier.h:31
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
GBRForestsAndConstants::produceJetIds
bool produceJetIds() const
Definition: PileupJetIdProducer.h:58
PileupJetIdentifier::jetPhi
const float & jetPhi() const
Definition: PileupJetIdentifier.h:96
metsig::jet
Definition: SignAlgoResolutions.h:47
edm::ValueMap
Definition: ValueMap.h:107
GBRForestsAndConstants::jec
std::string const & jec() const
Definition: PileupJetIdProducer.h:61
PileupJetIdProducer::algos_
std::vector< std::pair< std::string, std::unique_ptr< PileupJetIdAlgo > > > algos_
Definition: PileupJetIdProducer.h:97
JetCorrectorParameters
Definition: JetCorrectorParameters.h:25
pat::Jet::correctedJet
Jet correctedJet(const std::string &level, const std::string &flavor="none", const std::string &set="") const
jetMETDQMOfflineSource_cff.jec
jec
Definition: jetMETDQMOfflineSource_cff.py:27
edm::helper::Filler
Definition: ValueMap.h:22
PileupJetIdAlgo
Definition: PileupJetIdAlgo.h:22
StoredPileupJetIdentifier::jetPt
const float & jetPt() const
Definition: PileupJetIdentifier.h:32
PileupJetIdProducer::input_vm_pujetid_token_
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_
Definition: PileupJetIdProducer.h:104
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
edm::InputTag
Definition: InputTag.h:15
jetMETDQMOfflineSource_cff.applyJec
applyJec
Definition: jetMETDQMOfflineSource_cff.py:28
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27