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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

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

Definition at line 24 of file MVAJetPuIdProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 54 of file MVAJetPuIdProducer.cc.

References jets_cff::algos, algos_, applyJec_, 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_.

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

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

Definition at line 211 of file MVAJetPuIdProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addVPSet(), DEFINE_FWK_MODULE, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 94 of file MVAJetPuIdProducer.cc.

References algos_, jets_cff::applyJec, applyJec_, reco::CompositePtrCandidate::clone(), MVAJetPuId::computeIdVariables(), MVAJetPuId::computeMva(), reco::LeafCandidate::eta(), edm::Event::getByToken(), FactorizedJetCorrector::getCorrection(), mps_fire::i, input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, inputIsCorrected_, patTestJEC_cfi::jec, jecCor_, metsig::jet, reco::Jet::jetArea(), StoredPileupJetIdentifier::jetEta(), PileupJetIdentifier::jetPhi(), StoredPileupJetIdentifier::jetPt(), fwrapper::jets, eostools::move(), DetachedQuadStep_cff::mva, RecoTauHPSTancTauProdcuer_cfi::mvas, reco::LeafCandidate::phi(), produceJetIds_, edm::Handle< T >::product(), reco::LeafCandidate::pt(), edm::Event::put(), edm::View< T >::refAt(), rho, runMvas_, Scenarios_cff::scale, reco::Jet::scaleEnergy(), MVAJetPuId::set(), FactorizedJetCorrector::setJetA(), FactorizedJetCorrector::setJetEta(), FactorizedJetCorrector::setJetPt(), FactorizedJetCorrector::setRho(), edm::View< T >::size(), jets_cff::vertexes, and badGlobalMuonTaggersAOD_cff::vtx.

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

Member Data Documentation

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

Definition at line 39 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

bool MVAJetPuIdProducer::applyJec_
private

Definition at line 38 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

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

Definition at line 46 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

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

Definition at line 49 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

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

Definition at line 47 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

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

Definition at line 48 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

bool MVAJetPuIdProducer::inputIsCorrected_
private

Definition at line 38 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

std::string MVAJetPuIdProducer::jec_
private

Definition at line 37 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

FactorizedJetCorrector* MVAJetPuIdProducer::jecCor_
private

Definition at line 43 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

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

Definition at line 44 of file MVAJetPuIdProducer.cc.

edm::InputTag MVAJetPuIdProducer::jetids_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

edm::InputTag MVAJetPuIdProducer::jets_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

bool MVAJetPuIdProducer::produceJetIds_
private

Definition at line 38 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

bool MVAJetPuIdProducer::residualsFromTxt_
private

Definition at line 41 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

edm::FileInPath MVAJetPuIdProducer::residualsTxt_
private

Definition at line 42 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

edm::InputTag MVAJetPuIdProducer::rho_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().

bool MVAJetPuIdProducer::runMvas_
private

Definition at line 38 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer(), and produce().

edm::InputTag MVAJetPuIdProducer::vertexes_
private

Definition at line 36 of file MVAJetPuIdProducer.cc.

Referenced by MVAJetPuIdProducer().