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

Public Member Functions

 PileupJetIdProducer (const edm::ParameterSet &)
 
 ~PileupJetIdProducer () override
 
- 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, std::unique_ptr< PileupJetIdAlgo > > > 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_
 
std::unique_ptr< 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

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

Constructor & Destructor Documentation

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

Definition at line 24 of file PileupJetIdProducer.cc.

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

25 {
26  runMvas_ = iConfig.getParameter<bool>("runMvas");
27  produceJetIds_ = iConfig.getParameter<bool>("produceJetIds");
28  jets_ = iConfig.getParameter<edm::InputTag>("jets");
29  vertexes_ = iConfig.getParameter<edm::InputTag>("vertexes");
30  jetids_ = iConfig.getParameter<edm::InputTag>("jetids");
31  inputIsCorrected_ = iConfig.getParameter<bool>("inputIsCorrected");
32  applyJec_ = iConfig.getParameter<bool>("applyJec");
33  jec_ = iConfig.getParameter<std::string>("jec");
34  rho_ = iConfig.getParameter<edm::InputTag>("rho");
35  residualsFromTxt_ = iConfig.getParameter<bool>("residualsFromTxt");
36  if(residualsFromTxt_) residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt");
37  std::vector<edm::ParameterSet> algos = iConfig.getParameter<std::vector<edm::ParameterSet> >("algos");
38 
39 
40  if( ! runMvas_ ) assert( algos.size() == 1 );
41 
42  if( produceJetIds_ ) {
43  produces<edm::ValueMap<StoredPileupJetIdentifier> > ("");
44  }
45  for(std::vector<edm::ParameterSet>::iterator it=algos.begin(); it!=algos.end(); ++it) {
46  std::string label = it->getParameter<std::string>("label");
47  algos_.emplace_back( label, std::make_unique<PileupJetIdAlgo>(*it, runMvas_));
48  if( runMvas_ ) {
49  produces<edm::ValueMap<float> > (label+"Discriminant");
50  produces<edm::ValueMap<int> > (label+"Id");
51  }
52  }
53 
54  input_jet_token_ = consumes<edm::View<reco::Jet> >(jets_);
55  input_vertex_token_ = consumes<reco::VertexCollection>(vertexes_);
56  input_vm_pujetid_token_ = consumes<edm::ValueMap<StoredPileupJetIdentifier> >(jetids_);
57  input_rho_token_ = consumes<double>(rho_);
58 
59 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
edm::EDGetTokenT< double > input_rho_token_
edm::FileInPath residualsTxt_
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 64 of file PileupJetIdProducer.cc.

65 {
66 }

Member Function Documentation

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

Definition at line 229 of file PileupJetIdProducer.cc.

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

229  {
230  //The following says we do not know what parameters are allowed so do no validation
231  // Please change this to state exactly what you do use, even if it is no parameters
233  desc.setUnknown();
234  descriptions.addDefault(desc);
235 }
void addDefault(ParameterSetDescription const &psetDescription)
void PileupJetIdProducer::initJetEnergyCorrector ( const edm::EventSetup iSetup,
bool  isData 
)
private

Definition at line 240 of file PileupJetIdProducer.cc.

References DEFINE_FWK_MODULE, edm::FileInPath::fullPath(), edm::EventSetup::get(), jec_, jecCor_, jetCorPars_, residualsFromTxt_, and residualsTxt_.

Referenced by produce().

241 {
242  //jet energy correction levels to apply on raw jet
243  std::vector<std::string> jecLevels;
244  jecLevels.push_back("L1FastJet");
245  jecLevels.push_back("L2Relative");
246  jecLevels.push_back("L3Absolute");
247  if(isData && ! residualsFromTxt_ ) jecLevels.push_back("L2L3Residual");
248 
249  //check the corrector parameters needed according to the correction levels
251  iSetup.get<JetCorrectionsRecord>().get(jec_,parameters);
252  for(std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll)
253  {
254  const JetCorrectorParameters& ip = (*parameters)[*ll];
255  jetCorPars_.push_back(ip);
256  }
257  if( isData && residualsFromTxt_ ) {
259  }
260 
261  //instantiate the jet corrector
262  jecCor_ = std::make_unique<FactorizedJetCorrector>(jetCorPars_);
263 }
std::vector< JetCorrectorParameters > jetCorPars_
edm::FileInPath residualsTxt_
const T & get() const
Definition: EventSetup.h:59
std::string fullPath() const
Definition: FileInPath.cc:197
std::unique_ptr< FactorizedJetCorrector > jecCor_
void PileupJetIdProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 71 of file PileupJetIdProducer.cc.

References algos_, hltMVAJetPuId_cff::applyJec, 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(), electrons_cff::ids, initJetEnergyCorrector(), input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, inputIsCorrected_, edm::EventBase::isRealData(), patTestJEC_cfi::jec, jecCor_, metsig::jet, nanoDQM_cfi::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(), produceJetIds_, edm::Handle< T >::product(), reco::LeafCandidate::pt(), edm::Event::put(), edm::View< T >::refAt(), rho, runMvas_, Scenarios_cff::scale, reco::Jet::scaleEnergy(), PileupJetIdAlgo::set(), edm::View< T >::size(), hltMVAJetPuId_cff::vertexes, and badGlobalMuonTaggersAOD_cff::vtx.

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

Member Data Documentation

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

Definition at line 65 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::applyJec_
private

Definition at line 64 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

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

Definition at line 72 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

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

Definition at line 75 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

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

Definition at line 73 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

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

Definition at line 74 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::inputIsCorrected_
private

Definition at line 64 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

std::string PileupJetIdProducer::jec_
private

Definition at line 63 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().

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

Definition at line 69 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), and produce().

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

Definition at line 70 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector().

edm::InputTag PileupJetIdProducer::jetids_
private

Definition at line 62 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer().

edm::InputTag PileupJetIdProducer::jets_
private

Definition at line 62 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer().

bool PileupJetIdProducer::produceJetIds_
private

Definition at line 64 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::residualsFromTxt_
private

Definition at line 67 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().

edm::FileInPath PileupJetIdProducer::residualsTxt_
private

Definition at line 68 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().

edm::InputTag PileupJetIdProducer::rho_
private

Definition at line 62 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer().

bool PileupJetIdProducer::runMvas_
private

Definition at line 64 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer(), and produce().

edm::InputTag PileupJetIdProducer::vertexes_
private

Definition at line 62 of file PileupJetIdProducer.h.

Referenced by PileupJetIdProducer().