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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

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::ValueMap< float > constituentWeights_
 
edm::EDGetTokenT< edm::ValueMap< float > > input_constituent_weights_token_
 
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_
 
edm::ESGetToken< JetCorrectorParametersCollection, JetCorrectionsRecordparameters_token_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< GBRForestsAndConstants > >
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::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 51 of file PileupJetIdProducer.cc.

References algos_, deDxTools::esConsumes(), edm::ParameterSet::getParameter(), input_constituent_weights_token_, input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, GBRForestsAndConstants::jec(), label, parameters_token_, GBRForestsAndConstants::produceJetIds(), GBRForestsAndConstants::runMvas(), PileupJetID_cfi::srcConstituentWeights, AlCaHLTBitMon_QueryRunRegistry::string, and GBRForestsAndConstants::vAlgoGBRForestsAndConstants().

51  {
52  if (globalCache->produceJetIds()) {
53  produces<edm::ValueMap<StoredPileupJetIdentifier>>("");
54  }
55  for (auto const& algoGBRForestsAndConstants : globalCache->vAlgoGBRForestsAndConstants()) {
56  std::string const& label = algoGBRForestsAndConstants.label();
57  algos_.emplace_back(label, std::make_unique<PileupJetIdAlgo>(&algoGBRForestsAndConstants));
58  if (globalCache->runMvas()) {
59  produces<edm::ValueMap<float>>(label + "Discriminant");
60  produces<edm::ValueMap<int>>(label + "Id");
61  }
62  }
63 
64  input_jet_token_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jets"));
65  input_vertex_token_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexes"));
67  consumes<edm::ValueMap<StoredPileupJetIdentifier>>(iConfig.getParameter<edm::InputTag>("jetids"));
68  input_rho_token_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
69  parameters_token_ = esConsumes(edm::ESInputTag("", globalCache->jec()));
70 
71  edm::InputTag srcConstituentWeights = iConfig.getParameter<edm::InputTag>("srcConstituentWeights");
72  if (!srcConstituentWeights.label().empty()) {
73  input_constituent_weights_token_ = consumes<edm::ValueMap<float>>(srcConstituentWeights);
74  }
75 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
edm::EDGetTokenT< edm::ValueMap< float > > input_constituent_weights_token_
char const * label
edm::EDGetTokenT< double > input_rho_token_
std::vector< std::pair< std::string, std::unique_ptr< PileupJetIdAlgo > > > algos_
edm::ESGetToken< JetCorrectorParametersCollection, JetCorrectionsRecord > parameters_token_
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_

◆ ~PileupJetIdProducer()

PileupJetIdProducer::~PileupJetIdProducer ( )
override

Definition at line 78 of file PileupJetIdProducer.cc.

78 {}

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 246 of file PileupJetIdProducer.cc.

References edm::ConfigurationDescriptions::addDefault(), and submitPVResolutionJobs::desc.

246  {
247  //The following says we do not know what parameters are allowed so do no validation
248  // Please change this to state exactly what you do use, even if it is no parameters
250  desc.setUnknown();
251  descriptions.addDefault(desc);
252 }
void addDefault(ParameterSetDescription const &psetDescription)

◆ 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.

References muonDTDigis_cfi::pset.

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

◆ initJetEnergyCorrector()

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

Definition at line 255 of file PileupJetIdProducer.cc.

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

Referenced by produce().

255  {
256  GBRForestsAndConstants const* gc = globalCache();
257 
258  //jet energy correction levels to apply on raw jet
259  std::vector<std::string> jecLevels;
260  jecLevels.push_back("L1FastJet");
261  jecLevels.push_back("L2Relative");
262  jecLevels.push_back("L3Absolute");
263  if (isData && !gc->residualsFromTxt())
264  jecLevels.push_back("L2L3Residual");
265 
266  //check the corrector parameters needed according to the correction levels
267  auto const& parameters = iSetup.getData(parameters_token_);
268  for (std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll) {
269  const JetCorrectorParameters& ip = parameters[*ll];
270  jetCorPars_.push_back(ip);
271  }
272  if (isData && gc->residualsFromTxt()) {
274  }
275 
276  //instantiate the jet corrector
277  jecCor_ = std::make_unique<FactorizedJetCorrector>(jetCorPars_);
278 }
std::vector< JetCorrectorParameters > jetCorPars_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::string fullPath() const
Definition: FileInPath.cc:161
edm::FileInPath const & residualsTxt() const
edm::ESGetToken< JetCorrectorParametersCollection, JetCorrectionsRecord > parameters_token_
std::unique_ptr< FactorizedJetCorrector > jecCor_

◆ produce()

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

Definition at line 81 of file PileupJetIdProducer.cc.

References algos_, GBRForestsAndConstants::applyConstituentWeight(), 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_constituent_weights_token_, input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, GBRForestsAndConstants::inputIsCorrected(), edm::EDGetTokenT< T >::isUninitialized(), jetMETDQMOfflineSource_cff::jec, jecCor_, metsig::jet, StoredPileupJetIdentifier::jetEta(), PileupJetIdentifier::jetPhi(), StoredPileupJetIdentifier::jetPt(), PDWG_EXODelayedJetMET_cff::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(), l1tEGammaCrystalsEmulatorProducer_cfi::scale, PileupJetIdAlgo::set(), jetsAK4_CHS_cff::vertexes, and L1BJetProducer_cff::vtx.

81  {
82  GBRForestsAndConstants const* gc = globalCache();
83 
84  using namespace edm;
85  using namespace std;
86  using namespace reco;
87 
88  // Input jets
89  Handle<View<Jet>> jetHandle;
90  iEvent.getByToken(input_jet_token_, jetHandle);
91  const View<Jet>& jets = *jetHandle;
92 
93  // Constituent weight (e.g PUPPI) Value Map
94  edm::ValueMap<float> constituentWeights;
96  constituentWeights = iEvent.get(input_constituent_weights_token_);
97  }
98 
99  // input variables
101  if (!gc->produceJetIds()) {
102  iEvent.getByToken(input_vm_pujetid_token_, vmap);
103  }
104  // rho
105  edm::Handle<double> rhoH;
106  double rho = 0.;
107 
108  // products
109  vector<StoredPileupJetIdentifier> ids;
110  map<string, vector<float>> mvas;
111  map<string, vector<int>> idflags;
112 
113  const VertexCollection* vertexes = nullptr;
114  VertexCollection::const_iterator vtx;
115  if (gc->produceJetIds()) {
116  // vertexes
117  Handle<VertexCollection> vertexHandle;
118  iEvent.getByToken(input_vertex_token_, vertexHandle);
119 
120  vertexes = vertexHandle.product();
121 
122  // require basic quality cuts on the vertexes
123  vtx = vertexes->begin();
124  while (vtx != vertexes->end() && (vtx->isFake() || vtx->ndof() < 4)) {
125  ++vtx;
126  }
127  if (vtx == vertexes->end()) {
128  vtx = vertexes->begin();
129  }
130  }
131 
132  // Loop over input jets
133  bool ispat = true;
134  for (unsigned int i = 0; i < jets.size(); ++i) {
135  // Pick the first algo to compute the input variables
136  auto algoi = algos_.begin();
137  PileupJetIdAlgo* ialgo = algoi->second.get();
138 
139  const Jet& jet = jets.at(i);
140  const pat::Jet* patjet = nullptr;
141  if (ispat) {
142  patjet = dynamic_cast<const pat::Jet*>(&jet);
143  ispat = patjet != nullptr;
144  }
145 
146  // Get jet energy correction
147  float jec = 0.;
148  if (gc->applyJec()) {
149  // If haven't done it get rho from the event
150  if (rho == 0.) {
151  iEvent.getByToken(input_rho_token_, rhoH);
152  rho = *rhoH;
153  }
154  // jet corrector
155  if (not jecCor_) {
156  initJetEnergyCorrector(iSetup, iEvent.isRealData());
157  }
158  if (ispat) {
159  jecCor_->setJetPt(patjet->correctedJet(0).pt());
160  } else {
161  jecCor_->setJetPt(jet.pt());
162  }
163  jecCor_->setJetEta(jet.eta());
164  jecCor_->setJetA(jet.jetArea());
165  jecCor_->setRho(rho);
166  jec = jecCor_->getCorrection();
167  }
168  // If it was requested AND the input is an uncorrected jet apply the JEC
169  bool applyJec = gc->applyJec() && (ispat || !gc->inputIsCorrected());
170  std::unique_ptr<reco::Jet> corrJet;
171 
172  if (applyJec) {
173  float scale = jec;
174  if (ispat) {
175  corrJet = std::make_unique<pat::Jet>(patjet->correctedJet(0));
176  } else {
177  corrJet.reset(dynamic_cast<reco::Jet*>(jet.clone()));
178  }
179  corrJet->scaleEnergy(scale);
180  }
181  const reco::Jet* theJet = (applyJec ? corrJet.get() : &jet);
182 
183  PileupJetIdentifier puIdentifier;
184  if (gc->produceJetIds()) {
185  // Compute the input variables
187  puIdentifier = ialgo->computeIdVariables(
188  theJet, jec, &(*vtx), *vertexes, rho, constituentWeights, gc->applyConstituentWeight());
189  ids.push_back(puIdentifier);
190  } else {
191  // Or read it from the value map
192  puIdentifier = (*vmap)[jets.refAt(i)];
193  puIdentifier.jetPt(theJet->pt()); // make sure JEC is applied when computing the MVA
194  puIdentifier.jetEta(theJet->eta());
195  puIdentifier.jetPhi(theJet->phi());
196  ialgo->set(puIdentifier);
197  puIdentifier = ialgo->computeMva();
198  }
199 
200  if (gc->runMvas()) {
201  // Compute the MVA and WP
202  mvas[algoi->first].push_back(puIdentifier.mva());
203  idflags[algoi->first].push_back(puIdentifier.idFlag());
204  for (++algoi; algoi != algos_.end(); ++algoi) {
205  ialgo = algoi->second.get();
206  ialgo->set(puIdentifier);
207  PileupJetIdentifier id = ialgo->computeMva();
208  mvas[algoi->first].push_back(id.mva());
209  idflags[algoi->first].push_back(id.idFlag());
210  }
211  }
212  }
213 
214  // Produce the output value maps
215  if (gc->runMvas()) {
216  for (const auto& ialgo : algos_) {
217  // MVA
218  vector<float>& mva = mvas[ialgo.first];
219  auto mvaout = std::make_unique<ValueMap<float>>();
220  ValueMap<float>::Filler mvafiller(*mvaout);
221  mvafiller.insert(jetHandle, mva.begin(), mva.end());
222  mvafiller.fill();
223  iEvent.put(std::move(mvaout), ialgo.first + "Discriminant");
224 
225  // WP
226  vector<int>& idflag = idflags[ialgo.first];
227  auto idflagout = std::make_unique<ValueMap<int>>();
228  ValueMap<int>::Filler idflagfiller(*idflagout);
229  idflagfiller.insert(jetHandle, idflag.begin(), idflag.end());
230  idflagfiller.fill();
231  iEvent.put(std::move(idflagout), ialgo.first + "Id");
232  }
233  }
234  // input variables
235  if (gc->produceJetIds()) {
236  assert(jetHandle->size() == ids.size());
237  auto idsout = std::make_unique<ValueMap<StoredPileupJetIdentifier>>();
239  idsfiller.insert(jetHandle, ids.begin(), ids.end());
240  idsfiller.fill();
241  iEvent.put(std::move(idsout));
242  }
243 }
const float & jetPhi() const
void set(const PileupJetIdentifier &)
double pt() const final
transverse momentum
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
Base class for all types of Jets.
Definition: Jet.h:20
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool applyConstituentWeight() const
assert(be >=bs)
edm::EDGetTokenT< edm::ValueMap< float > > input_constituent_weights_token_
const float & jetPt() const
int iEvent
Definition: GenABIO.cc:224
Definition: Jet.py:1
PileupJetIdentifier computeIdVariables(const reco::Jet *jet, float jec, const reco::Vertex *, const reco::VertexCollection &, double rho, edm::ValueMap< float > &constituentWeights, bool applyConstituentWeight)
edm::EDGetTokenT< double > input_rho_token_
Jet correctedJet(const std::string &level, const std::string &flavor="none", const std::string &set="") const
void initJetEnergyCorrector(const edm::EventSetup &iSetup, bool isData)
std::vector< std::pair< std::string, std::unique_ptr< PileupJetIdAlgo > > > algos_
const float & jetEta() const
PileupJetIdentifier computeMva()
Analysis-level calorimeter jet class.
Definition: Jet.h:77
fixed size matrix
HLT enums.
const int & idFlag() const
const float & mva() const
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_
double phi() const final
momentum azimuthal angle
std::unique_ptr< FactorizedJetCorrector > jecCor_
def move(src, dest)
Definition: eostools.py:511
double eta() const final
momentum pseudorapidity

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().

◆ constituentWeights_

edm::ValueMap<float> PileupJetIdProducer::constituentWeights_
private

Definition at line 102 of file PileupJetIdProducer.h.

◆ input_constituent_weights_token_

edm::EDGetTokenT<edm::ValueMap<float> > PileupJetIdProducer::input_constituent_weights_token_
private

Definition at line 103 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 104 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

◆ input_rho_token_

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

Definition at line 107 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

◆ input_vertex_token_

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

Definition at line 105 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 106 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().

◆ parameters_token_

edm::ESGetToken<JetCorrectorParametersCollection, JetCorrectionsRecord> PileupJetIdProducer::parameters_token_
private

Definition at line 108 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().