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 247 of file PileupJetIdProducer.cc.

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

247  {
248  //The following says we do not know what parameters are allowed so do no validation
249  // Please change this to state exactly what you do use, even if it is no parameters
251  desc.setUnknown();
252  descriptions.addDefault(desc);
253 }
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 256 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().

256  {
257  GBRForestsAndConstants const* gc = globalCache();
258 
259  //jet energy correction levels to apply on raw jet
260  std::vector<std::string> jecLevels;
261  jecLevels.push_back("L1FastJet");
262  jecLevels.push_back("L2Relative");
263  jecLevels.push_back("L3Absolute");
264  if (isData && !gc->residualsFromTxt())
265  jecLevels.push_back("L2L3Residual");
266 
267  //check the corrector parameters needed according to the correction levels
268  auto const& parameters = iSetup.getData(parameters_token_);
269  for (std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll) {
270  const JetCorrectorParameters& ip = parameters[*ll];
271  jetCorPars_.push_back(ip);
272  }
273  if (isData && gc->residualsFromTxt()) {
275  }
276 
277  //instantiate the jet corrector
278  jecCor_ = std::make_unique<FactorizedJetCorrector>(jetCorPars_);
279 }
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(), pfClustersFromCombinedCaloHF_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_->setJetPhi(jet.phi());
165  jecCor_->setJetA(jet.jetArea());
166  jecCor_->setRho(rho);
167  jec = jecCor_->getCorrection();
168  }
169  // If it was requested AND the input is an uncorrected jet apply the JEC
170  bool applyJec = gc->applyJec() && (ispat || !gc->inputIsCorrected());
171  std::unique_ptr<reco::Jet> corrJet;
172 
173  if (applyJec) {
174  float scale = jec;
175  if (ispat) {
176  corrJet = std::make_unique<pat::Jet>(patjet->correctedJet(0));
177  } else {
178  corrJet.reset(dynamic_cast<reco::Jet*>(jet.clone()));
179  }
180  corrJet->scaleEnergy(scale);
181  }
182  const reco::Jet* theJet = (applyJec ? corrJet.get() : &jet);
183 
184  PileupJetIdentifier puIdentifier;
185  if (gc->produceJetIds()) {
186  // Compute the input variables
188  puIdentifier = ialgo->computeIdVariables(
189  theJet, jec, &(*vtx), *vertexes, rho, constituentWeights, gc->applyConstituentWeight());
190  ids.push_back(puIdentifier);
191  } else {
192  // Or read it from the value map
193  puIdentifier = (*vmap)[jets.refAt(i)];
194  puIdentifier.jetPt(theJet->pt()); // make sure JEC is applied when computing the MVA
195  puIdentifier.jetEta(theJet->eta());
196  puIdentifier.jetPhi(theJet->phi());
197  ialgo->set(puIdentifier);
198  puIdentifier = ialgo->computeMva();
199  }
200 
201  if (gc->runMvas()) {
202  // Compute the MVA and WP
203  mvas[algoi->first].push_back(puIdentifier.mva());
204  idflags[algoi->first].push_back(puIdentifier.idFlag());
205  for (++algoi; algoi != algos_.end(); ++algoi) {
206  ialgo = algoi->second.get();
207  ialgo->set(puIdentifier);
208  PileupJetIdentifier id = ialgo->computeMva();
209  mvas[algoi->first].push_back(id.mva());
210  idflags[algoi->first].push_back(id.idFlag());
211  }
212  }
213  }
214 
215  // Produce the output value maps
216  if (gc->runMvas()) {
217  for (const auto& ialgo : algos_) {
218  // MVA
219  vector<float>& mva = mvas[ialgo.first];
220  auto mvaout = std::make_unique<ValueMap<float>>();
221  ValueMap<float>::Filler mvafiller(*mvaout);
222  mvafiller.insert(jetHandle, mva.begin(), mva.end());
223  mvafiller.fill();
224  iEvent.put(std::move(mvaout), ialgo.first + "Discriminant");
225 
226  // WP
227  vector<int>& idflag = idflags[ialgo.first];
228  auto idflagout = std::make_unique<ValueMap<int>>();
229  ValueMap<int>::Filler idflagfiller(*idflagout);
230  idflagfiller.insert(jetHandle, idflag.begin(), idflag.end());
231  idflagfiller.fill();
232  iEvent.put(std::move(idflagout), ialgo.first + "Id");
233  }
234  }
235  // input variables
236  if (gc->produceJetIds()) {
237  assert(jetHandle->size() == ids.size());
238  auto idsout = std::make_unique<ValueMap<StoredPileupJetIdentifier>>();
240  idsfiller.insert(jetHandle, ids.begin(), ids.end());
241  idsfiller.fill();
242  iEvent.put(std::move(idsout));
243  }
244 }
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().