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

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_
 

Additional Inherited Members

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

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 82 of file PileupJetIdProducer.h.

Constructor & Destructor Documentation

PileupJetIdProducer::PileupJetIdProducer ( const edm::ParameterSet iConfig,
GBRForestsAndConstants const *  globalCache 
)
explicit

Definition at line 45 of file PileupJetIdProducer.cc.

References edm::ParameterSet::getParameter(), label, 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"));
61  input_vm_pujetid_token_ = consumes<edm::ValueMap<StoredPileupJetIdentifier> >(iConfig.getParameter<edm::InputTag>("jetids"));
62  input_rho_token_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
63 }
T getParameter(std::string const &) const
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::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_
PileupJetIdProducer::~PileupJetIdProducer ( )
override

Definition at line 68 of file PileupJetIdProducer.cc.

69 {
70 }

Member Function Documentation

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

Definition at line 232 of file PileupJetIdProducer.cc.

References edm::ConfigurationDescriptions::addDefault(), and edm::ParameterSetDescription::setUnknown().

232  {
233  //The following says we do not know what parameters are allowed so do no validation
234  // Please change this to state exactly what you do use, even if it is no parameters
236  desc.setUnknown();
237  descriptions.addDefault(desc);
238 }
void addDefault(ParameterSetDescription const &psetDescription)
static void PileupJetIdProducer::globalEndJob ( GBRForestsAndConstants )
inlinestatic

Definition at line 93 of file PileupJetIdProducer.h.

93 { }
static std::unique_ptr<GBRForestsAndConstants> PileupJetIdProducer::initializeGlobalCache ( edm::ParameterSet const &  pset)
inlinestatic

Definition at line 89 of file PileupJetIdProducer.h.

References muonDTDigis_cfi::pset.

89  {
90  return std::make_unique<GBRForestsAndConstants>(pset);
91  }
void PileupJetIdProducer::initJetEnergyCorrector ( const edm::EventSetup iSetup,
bool  isData 
)
private

Definition at line 243 of file PileupJetIdProducer.cc.

References DEFINE_FWK_MODULE, edm::FileInPath::fullPath(), edm::EventSetup::get(), GBRForestsAndConstants::jec(), GBRForestsAndConstants::residualsFromTxt(), and GBRForestsAndConstants::residualsTxt().

244 {
245  GBRForestsAndConstants const* gc = globalCache();
246 
247  //jet energy correction levels to apply on raw jet
248  std::vector<std::string> jecLevels;
249  jecLevels.push_back("L1FastJet");
250  jecLevels.push_back("L2Relative");
251  jecLevels.push_back("L3Absolute");
252  if(isData && ! gc->residualsFromTxt() ) jecLevels.push_back("L2L3Residual");
253 
254  //check the corrector parameters needed according to the correction levels
256  iSetup.get<JetCorrectionsRecord>().get(gc->jec(),parameters);
257  for(std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll)
258  {
259  const JetCorrectorParameters& ip = (*parameters)[*ll];
260  jetCorPars_.push_back(ip);
261  }
262  if( isData && gc->residualsFromTxt() ) {
264  }
265 
266  //instantiate the jet corrector
267  jecCor_ = std::make_unique<FactorizedJetCorrector>(jetCorPars_);
268 }
std::vector< JetCorrectorParameters > jetCorPars_
std::string const & jec() const
edm::FileInPath const & residualsTxt() const
T get() const
Definition: EventSetup.h:71
std::string fullPath() const
Definition: FileInPath.cc:163
std::unique_ptr< FactorizedJetCorrector > jecCor_
void PileupJetIdProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 75 of file PileupJetIdProducer.cc.

References GBRForestsAndConstants::applyJec(), edm::View< T >::at(), reco::CompositePtrCandidate::clone(), PileupJetIdAlgo::computeIdVariables(), PileupJetIdAlgo::computeMva(), pat::Jet::correctedJet(), reco::LeafCandidate::eta(), edm::Event::getByToken(), mps_fire::i, PileupJetIdentifier::idFlag(), GBRForestsAndConstants::inputIsCorrected(), edm::EventBase::isRealData(), GBRForestsAndConstants::jec(), metsig::jet, reco::Jet::jetArea(), StoredPileupJetIdentifier::jetEta(), PileupJetIdentifier::jetPhi(), StoredPileupJetIdentifier::jetPt(), fwrapper::jets, eostools::move(), PileupJetIdentifier::mva(), DetachedQuadStep_cff::mva, RecoTauHPSTancTauProdcuer_cfi::mvas, reco::LeafCandidate::phi(), GBRForestsAndConstants::produceJetIds(), edm::Handle< T >::product(), reco::LeafCandidate::pt(), edm::Event::put(), edm::View< T >::refAt(), rho, GBRForestsAndConstants::runMvas(), Scenarios_cff::scale, PileupJetIdAlgo::set(), edm::View< T >::size(), GBRForestsAndConstants::usePuppi(), jets_cff::vertexes, and extraflags_cff::vtx.

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

Member Data Documentation

std::vector<std::pair<std::string, std::unique_ptr<PileupJetIdAlgo> > > PileupJetIdProducer::algos_
private

Definition at line 101 of file PileupJetIdProducer.h.

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

Definition at line 106 of file PileupJetIdProducer.h.

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

Definition at line 109 of file PileupJetIdProducer.h.

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

Definition at line 107 of file PileupJetIdProducer.h.

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

Definition at line 108 of file PileupJetIdProducer.h.

std::unique_ptr<FactorizedJetCorrector> PileupJetIdProducer::jecCor_
private

Definition at line 103 of file PileupJetIdProducer.h.

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

Definition at line 104 of file PileupJetIdProducer.h.