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

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

46  {
47  if (globalCache->produceJetIds()) {
48  produces<edm::ValueMap<StoredPileupJetIdentifier>>("");
49  }
50  for (auto const& algoGBRForestsAndConstants : globalCache->vAlgoGBRForestsAndConstants()) {
51  std::string const& label = algoGBRForestsAndConstants.label();
52  algos_.emplace_back(label, std::make_unique<PileupJetIdAlgo>(&algoGBRForestsAndConstants));
53  if (globalCache->runMvas()) {
54  produces<edm::ValueMap<float>>(label + "Discriminant");
55  produces<edm::ValueMap<int>>(label + "Id");
56  }
57  }
58 
59  input_jet_token_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jets"));
60  input_vertex_token_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexes"));
62  consumes<edm::ValueMap<StoredPileupJetIdentifier>>(iConfig.getParameter<edm::InputTag>("jetids"));
63  input_rho_token_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
64  parameters_token_ = esConsumes(edm::ESInputTag("", globalCache->jec()));
65 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_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 68 of file PileupJetIdProducer.cc.

68 {}

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 228 of file PileupJetIdProducer.cc.

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

228  {
229  //The following says we do not know what parameters are allowed so do no validation
230  // Please change this to state exactly what you do use, even if it is no parameters
232  desc.setUnknown();
233  descriptions.addDefault(desc);
234 }
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 237 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().

237  {
238  GBRForestsAndConstants const* gc = globalCache();
239 
240  //jet energy correction levels to apply on raw jet
241  std::vector<std::string> jecLevels;
242  jecLevels.push_back("L1FastJet");
243  jecLevels.push_back("L2Relative");
244  jecLevels.push_back("L3Absolute");
245  if (isData && !gc->residualsFromTxt())
246  jecLevels.push_back("L2L3Residual");
247 
248  //check the corrector parameters needed according to the correction levels
249  auto const& parameters = iSetup.getData(parameters_token_);
250  for (std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll) {
251  const JetCorrectorParameters& ip = parameters[*ll];
252  jetCorPars_.push_back(ip);
253  }
254  if (isData && gc->residualsFromTxt()) {
256  }
257 
258  //instantiate the jet corrector
259  jecCor_ = std::make_unique<FactorizedJetCorrector>(jetCorPars_);
260 }
std::vector< JetCorrectorParameters > jetCorPars_
std::string fullPath() const
Definition: FileInPath.cc:161
edm::FileInPath const & residualsTxt() const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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 71 of file PileupJetIdProducer.cc.

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(), L1EGammaClusterEmuProducer_cfi::scale, PileupJetIdAlgo::set(), GBRForestsAndConstants::usePuppi(), jetsAK4_CHS_cff::vertexes, and extraflags_cff::vtx.

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

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

◆ parameters_token_

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

Definition at line 106 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().