CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
MVAJetPuIdProducer Class Reference
Inheritance diagram for MVAJetPuIdProducer:
edm::stream::EDProducer<>

Public Member Functions

 MVAJetPuIdProducer (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 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)
 

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, MVAJetPuId * > > algos_
 
bool applyJec_
 
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_
 
bool inputIsCorrected_
 
std::string jec_
 
FactorizedJetCorrectorjecCor_
 
std::vector< JetCorrectorParametersjetCorPars_
 
edm::InputTag jetids_
 
edm::InputTag jets_
 
bool produceJetIds_
 
bool residualsFromTxt_
 
edm::FileInPath residualsTxt_
 
edm::InputTag rho_
 
bool runMvas_
 
edm::InputTag vertexes_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
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

Definition at line 23 of file MVAJetPuIdProducer.cc.

Constructor & Destructor Documentation

◆ MVAJetPuIdProducer()

MVAJetPuIdProducer::MVAJetPuIdProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 50 of file MVAJetPuIdProducer.cc.

References hltPFPuppi_cfi::algos, algos_, applyJec_, cms::cuda::assert(), edm::ParameterSet::getParameter(), input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, inputIsCorrected_, jec_, jecCor_, jetids_, jets_, label, produceJetIds_, residualsFromTxt_, residualsTxt_, rho_, runMvas_, AlCaHLTBitMon_QueryRunRegistry::string, and vertexes_.

50  {
51  runMvas_ = iConfig.getParameter<bool>("runMvas");
52  produceJetIds_ = iConfig.getParameter<bool>("produceJetIds");
53  jets_ = iConfig.getParameter<edm::InputTag>("jets");
54  vertexes_ = iConfig.getParameter<edm::InputTag>("vertexes");
55  jetids_ = iConfig.getParameter<edm::InputTag>("jetids");
56  inputIsCorrected_ = iConfig.getParameter<bool>("inputIsCorrected");
57  applyJec_ = iConfig.getParameter<bool>("applyJec");
58  jec_ = iConfig.getParameter<std::string>("jec");
59  rho_ = iConfig.getParameter<edm::InputTag>("rho");
60  residualsFromTxt_ = iConfig.getParameter<bool>("residualsFromTxt");
62  residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt");
63  std::vector<edm::ParameterSet> algos = iConfig.getParameter<std::vector<edm::ParameterSet>>("algos");
64 
65  jecCor_ = nullptr;
66 
67  if (!runMvas_)
68  assert(algos.size() == 1);
69 
70  if (produceJetIds_) {
71  produces<edm::ValueMap<StoredPileupJetIdentifier>>("");
72  }
73  for (std::vector<edm::ParameterSet>::iterator it = algos.begin(); it != algos.end(); ++it) {
74  std::string label = it->getParameter<std::string>("label");
75  algos_.push_back(std::make_pair(label, new MVAJetPuId(*it)));
76  if (runMvas_) {
77  produces<edm::ValueMap<float>>(label + "Discriminant");
78  produces<edm::ValueMap<int>>(label + "Id");
79  }
80  }
81 
82  input_jet_token_ = consumes<edm::View<reco::Jet>>(jets_);
83  input_vertex_token_ = consumes<reco::VertexCollection>(vertexes_);
84  input_vm_pujetid_token_ = consumes<edm::ValueMap<StoredPileupJetIdentifier>>(jetids_);
85  input_rho_token_ = consumes<double>(rho_);
86 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
FactorizedJetCorrector * jecCor_
assert(be >=bs)
edm::FileInPath residualsTxt_
char const * label
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
std::vector< std::pair< std::string, MVAJetPuId * > > algos_
edm::EDGetTokenT< double > input_rho_token_
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 205 of file MVAJetPuIdProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), submitPVResolutionJobs::desc, HLT_2022v15_cff::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

205  {
207  desc.add<bool>("runMvas", true);
208  desc.add<bool>("inputIsCorrected", true);
209  desc.add<edm::InputTag>("vertexes", edm::InputTag("hltPixelVertices"));
210  desc.add<bool>("produceJetIds", true);
211  desc.add<std::string>("jec", "AK4PF");
212  desc.add<bool>("residualsFromTxt", false);
213  desc.add<bool>("applyJec", false);
214  desc.add<edm::InputTag>("jetids", edm::InputTag(""));
215  desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAll"));
216  desc.add<edm::InputTag>("jets", edm::InputTag("hltAK4PFJetsCorrected"));
218  vpsd1.add<std::vector<std::string>>("tmvaVariables",
219  {
220  "rho",
221  "nParticles",
222  "nCharged",
223  "majW",
224  "minW",
225  "frac01",
226  "frac02",
227  "frac03",
228  "frac04",
229  "ptD",
230  "beta",
231  "betaStar",
232  "dR2Mean",
233  "pull",
234  "jetR",
235  "jetRchg",
236  });
237  vpsd1.add<std::string>("tmvaMethod", "JetID");
238  vpsd1.add<bool>("cutBased", false);
239  vpsd1.add<std::string>("tmvaWeights", "RecoJets/JetProducers/data/MVAJetPuID.weights.xml.gz");
240  vpsd1.add<std::vector<std::string>>("tmvaSpectators",
241  {
242  "jetEta",
243  "jetPt",
244  });
245  vpsd1.add<std::string>("label", "CATEv0");
246  vpsd1.add<int>("version", -1);
247  {
249  psd0.add<std::vector<double>>("Pt2030_Tight",
250  {
251  0.73,
252  0.05,
253  -0.26,
254  -0.42,
255  });
256  psd0.add<std::vector<double>>("Pt2030_Loose",
257  {
258  -0.63,
259  -0.6,
260  -0.55,
261  -0.45,
262  });
263  psd0.add<std::vector<double>>("Pt3050_Medium",
264  {
265  0.1,
266  -0.36,
267  -0.54,
268  -0.54,
269  });
270  psd0.add<std::vector<double>>("Pt1020_Tight",
271  {
272  -0.83,
273  -0.81,
274  -0.74,
275  -0.81,
276  });
277  psd0.add<std::vector<double>>("Pt2030_Medium",
278  {
279  0.1,
280  -0.36,
281  -0.54,
282  -0.54,
283  });
284  psd0.add<std::vector<double>>("Pt010_Tight",
285  {
286  -0.83,
287  -0.81,
288  -0.74,
289  -0.81,
290  });
291  psd0.add<std::vector<double>>("Pt1020_Loose",
292  {
293  -0.95,
294  -0.96,
295  -0.94,
296  -0.95,
297  });
298  psd0.add<std::vector<double>>("Pt010_Medium",
299  {
300  -0.83,
301  -0.92,
302  -0.9,
303  -0.92,
304  });
305  psd0.add<std::vector<double>>("Pt1020_Medium",
306  {
307  -0.83,
308  -0.92,
309  -0.9,
310  -0.92,
311  });
312  psd0.add<std::vector<double>>("Pt010_Loose",
313  {
314  -0.95,
315  -0.96,
316  -0.94,
317  -0.95,
318  });
319  psd0.add<std::vector<double>>("Pt3050_Loose",
320  {
321  -0.63,
322  -0.6,
323  -0.55,
324  -0.45,
325  });
326  psd0.add<std::vector<double>>("Pt3050_Tight",
327  {
328  0.73,
329  0.05,
330  -0.26,
331  -0.42,
332  });
333  vpsd1.add<edm::ParameterSetDescription>("JetIdParams", psd0);
334  }
335  vpsd1.add<double>("impactParTkThreshold", 1.0);
336  std::vector<edm::ParameterSet> temp1;
337  temp1.reserve(1);
338 
339  desc.addVPSet("algos", vpsd1, temp1);
340 
341  descriptions.add("MVAJetPuIdProducer", desc);
342 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ initJetEnergyCorrector()

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

◆ produce()

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

Definition at line 88 of file MVAJetPuIdProducer.cc.

References algos_, jetMETDQMOfflineSource_cff::applyJec, applyJec_, cms::cuda::assert(), MVAJetPuId::computeIdVariables(), MVAJetPuId::computeMva(), reco::LeafCandidate::eta(), FactorizedJetCorrector::getCorrection(), mps_fire::i, iEvent, input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, inputIsCorrected_, jetMETDQMOfflineSource_cff::jec, jecCor_, metsig::jet, StoredPileupJetIdentifier::jetEta(), PileupJetIdentifier::jetPhi(), StoredPileupJetIdentifier::jetPt(), PDWG_EXODelayedJetMET_cff::jets, eostools::move(), beam_dqm_sourceclient-live_cfg::mva, reco::LeafCandidate::phi(), produceJetIds_, edm::Handle< T >::product(), reco::LeafCandidate::pt(), rho, runMvas_, L1EGammaClusterEmuProducer_cfi::scale, reco::Jet::scaleEnergy(), MVAJetPuId::set(), FactorizedJetCorrector::setJetA(), FactorizedJetCorrector::setJetEta(), FactorizedJetCorrector::setJetPt(), FactorizedJetCorrector::setRho(), trackerHitRTTI::vector, jetsAK4_CHS_cff::vertexes, and extraflags_cff::vtx.

88  {
89  using namespace edm;
90  using namespace std;
91  using namespace reco;
92 
93  Handle<View<Jet>> jetHandle;
94  iEvent.getByToken(input_jet_token_, jetHandle);
95  const View<Jet> &jets = *jetHandle;
96  Handle<VertexCollection> vertexHandle;
97  if (produceJetIds_) {
98  iEvent.getByToken(input_vertex_token_, vertexHandle);
99  }
100  const VertexCollection &vertexes = *(vertexHandle.product());
102  if (!produceJetIds_) {
103  iEvent.getByToken(input_vm_pujetid_token_, vmap);
104  }
105  edm::Handle<double> rhoH;
106  double rho = 0.;
107 
108  vector<StoredPileupJetIdentifier> ids;
109  map<string, vector<float>> mvas;
110  map<string, vector<int>> idflags;
111 
112  VertexCollection::const_iterator vtx;
113  if (produceJetIds_) {
114  vtx = vertexes.begin();
115  while (vtx != vertexes.end() && (vtx->isFake() || vtx->ndof() < 4)) {
116  ++vtx;
117  }
118  if (vtx == vertexes.end()) {
119  vtx = vertexes.begin();
120  }
121  }
122 
123  for (unsigned int i = 0; i < jets.size(); ++i) {
124  vector<pair<string, MVAJetPuId *>>::iterator algoi = algos_.begin();
125  MVAJetPuId *ialgo = algoi->second;
126 
127  const Jet &jet = jets[i];
128 
129  float jec = 0.;
130  if (applyJec_) {
131  if (rho == 0.) {
132  iEvent.getByToken(input_rho_token_, rhoH);
133  rho = *rhoH;
134  }
135  jecCor_->setJetPt(jet.pt());
136  jecCor_->setJetEta(jet.eta());
137  jecCor_->setJetA(jet.jetArea());
138  jecCor_->setRho(rho);
140  }
141 
143  reco::Jet *corrJet = nullptr;
144  if (applyJec) {
145  float scale = jec;
146  corrJet = dynamic_cast<reco::Jet *>(jet.clone());
147  corrJet->scaleEnergy(scale);
148  }
149  const reco::Jet *theJet = (applyJec ? corrJet : &jet);
150  PileupJetIdentifier puIdentifier;
151  if (produceJetIds_) {
152  puIdentifier = ialgo->computeIdVariables(theJet, jec, &(*vtx), vertexes, runMvas_);
153  ids.push_back(puIdentifier);
154  } else {
155  puIdentifier = (*vmap)[jets.refAt(i)];
156  puIdentifier.jetPt(theJet->pt()); /*make sure JEC is applied when computing the MVA*/
157  puIdentifier.jetEta(theJet->eta());
158  puIdentifier.jetPhi(theJet->phi());
159  ialgo->set(puIdentifier);
160  puIdentifier = ialgo->computeMva();
161  }
162 
163  if (runMvas_) {
164  for (; algoi != algos_.end(); ++algoi) {
165  ialgo = algoi->second;
166  ialgo->set(puIdentifier);
167  PileupJetIdentifier id = ialgo->computeMva();
168  mvas[algoi->first].push_back(id.mva());
169  idflags[algoi->first].push_back(id.idFlag());
170  }
171  }
172 
173  if (corrJet) {
174  delete corrJet;
175  }
176  }
177 
178  if (runMvas_) {
179  for (vector<pair<string, MVAJetPuId *>>::iterator ialgo = algos_.begin(); ialgo != algos_.end(); ++ialgo) {
180  vector<float> &mva = mvas[ialgo->first];
181  auto mvaout = std::make_unique<ValueMap<float>>();
182  ValueMap<float>::Filler mvafiller(*mvaout);
183  mvafiller.insert(jetHandle, mva.begin(), mva.end());
184  mvafiller.fill();
185  iEvent.put(std::move(mvaout), ialgo->first + "Discriminant");
186 
187  vector<int> &idflag = idflags[ialgo->first];
188  auto idflagout = std::make_unique<ValueMap<int>>();
189  ValueMap<int>::Filler idflagfiller(*idflagout);
190  idflagfiller.insert(jetHandle, idflag.begin(), idflag.end());
191  idflagfiller.fill();
192  iEvent.put(std::move(idflagout), ialgo->first + "Id");
193  }
194  }
195  if (produceJetIds_) {
196  assert(jetHandle->size() == ids.size());
197  auto idsout = std::make_unique<ValueMap<StoredPileupJetIdentifier>>();
199  idsfiller.insert(jetHandle, ids.begin(), ids.end());
200  idsfiller.fill();
201  iEvent.put(std::move(idsout));
202  }
203 }
const float & jetPhi() const
virtual void scaleEnergy(double fScale)
scale energy of the jet
double pt() const final
transverse momentum
FactorizedJetCorrector * jecCor_
Base class for all types of Jets.
Definition: Jet.h:20
T const * product() const
Definition: Handle.h:70
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
assert(be >=bs)
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, bool calculateMva=false)
Definition: MVAJetPuId.cc:196
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
std::vector< std::pair< std::string, MVAJetPuId * > > algos_
const float & jetEta() const
void set(const PileupJetIdentifier &)
Definition: MVAJetPuId.cc:143
fixed size matrix
HLT enums.
PileupJetIdentifier computeMva()
Definition: MVAJetPuId.cc:191
edm::EDGetTokenT< double > input_rho_token_
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_
double phi() const final
momentum azimuthal angle
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
double eta() const final
momentum pseudorapidity

Member Data Documentation

◆ algos_

std::vector<std::pair<std::string, MVAJetPuId *> > MVAJetPuIdProducer::algos_
private

Definition at line 37 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ applyJec_

bool MVAJetPuIdProducer::applyJec_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ input_jet_token_

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

Definition at line 44 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ input_rho_token_

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

Definition at line 47 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ input_vertex_token_

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

Definition at line 45 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ input_vm_pujetid_token_

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

Definition at line 46 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ inputIsCorrected_

bool MVAJetPuIdProducer::inputIsCorrected_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ jec_

std::string MVAJetPuIdProducer::jec_
private

Definition at line 35 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

◆ jecCor_

FactorizedJetCorrector* MVAJetPuIdProducer::jecCor_
private

Definition at line 41 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ jetCorPars_

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

Definition at line 42 of file MVAJetPuIdProducer.cc.

◆ jetids_

edm::InputTag MVAJetPuIdProducer::jetids_
private

Definition at line 34 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

◆ jets_

edm::InputTag MVAJetPuIdProducer::jets_
private

Definition at line 34 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

◆ produceJetIds_

bool MVAJetPuIdProducer::produceJetIds_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ residualsFromTxt_

bool MVAJetPuIdProducer::residualsFromTxt_
private

Definition at line 39 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

◆ residualsTxt_

edm::FileInPath MVAJetPuIdProducer::residualsTxt_
private

Definition at line 40 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

◆ rho_

edm::InputTag MVAJetPuIdProducer::rho_
private

Definition at line 34 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

◆ runMvas_

bool MVAJetPuIdProducer::runMvas_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

◆ vertexes_

edm::InputTag MVAJetPuIdProducer::vertexes_
private

Definition at line 34 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().