CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PileupJetIdProducer (const edm::ParameterSet &)
 
 ~PileupJetIdProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void initJetEnergyCorrector (const edm::EventSetup &iSetup, bool isData)
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::vector< std::pair
< std::string, PileupJetIdAlgo * > > 
algos_
 
bool applyJec_
 
edm::EDGetTokenT< edm::View
< reco::Jet > > 
input_jet_token_
 
edm::EDGetTokenT< double > input_rho_token_
 
edm::EDGetTokenT
< reco::VertexCollection
input_vertex_token_
 
edm::EDGetTokenT
< edm::ValueMap
< StoredPileupJetIdentifier > > 
input_vm_pujetid_token_
 
bool inputIsCorrected_
 
std::string jec_
 
FactorizedJetCorrectorjecCor_
 
std::vector
< JetCorrectorParameters
jetCorPars_
 
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::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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 algos_, applyJec_, assert(), edm::ParameterSet::getParameter(), input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, inputIsCorrected_, jec_, jecCor_, 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  jecCor_ = 0;
40 
41  if( ! runMvas_ ) assert( algos.size() == 1 );
42 
43  if( produceJetIds_ ) {
44  produces<edm::ValueMap<StoredPileupJetIdentifier> > ("");
45  }
46  for(std::vector<edm::ParameterSet>::iterator it=algos.begin(); it!=algos.end(); ++it) {
47  std::string label = it->getParameter<std::string>("label");
48  algos_.push_back( std::make_pair(label,new PileupJetIdAlgo(*it)) );
49  if( runMvas_ ) {
50  produces<edm::ValueMap<float> > (label+"Discriminant");
51  produces<edm::ValueMap<int> > (label+"Id");
52  }
53  }
54 
55  input_jet_token_ = consumes<edm::View<reco::Jet> >(jets_);
56  input_vertex_token_ = consumes<reco::VertexCollection>(vertexes_);
57  input_vm_pujetid_token_ = consumes<edm::ValueMap<StoredPileupJetIdentifier> >(jetids_);
58  input_rho_token_ = consumes<double>(rho_);
59 
60 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
std::vector< std::pair< std::string, PileupJetIdAlgo * > > algos_
assert(m_qm.get())
edm::EDGetTokenT< edm::View< reco::Jet > > input_jet_token_
FactorizedJetCorrector * jecCor_
edm::EDGetTokenT< double > input_rho_token_
edm::FileInPath residualsTxt_
edm::EDGetTokenT< edm::ValueMap< StoredPileupJetIdentifier > > input_vm_pujetid_token_
PileupJetIdProducer::~PileupJetIdProducer ( )

Definition at line 65 of file PileupJetIdProducer.cc.

66 {
67 }

Member Function Documentation

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

Definition at line 226 of file PileupJetIdProducer.cc.

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

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

Definition at line 237 of file PileupJetIdProducer.cc.

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

Referenced by produce().

238 {
239  //jet energy correction levels to apply on raw jet
240  std::vector<std::string> jecLevels;
241  jecLevels.push_back("L1FastJet");
242  jecLevels.push_back("L2Relative");
243  jecLevels.push_back("L3Absolute");
244  if(isData && ! residualsFromTxt_ ) jecLevels.push_back("L2L3Residual");
245 
246  //check the corrector parameters needed according to the correction levels
248  iSetup.get<JetCorrectionsRecord>().get(jec_,parameters);
249  for(std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll)
250  {
251  const JetCorrectorParameters& ip = (*parameters)[*ll];
252  jetCorPars_.push_back(ip);
253  }
254  if( isData && residualsFromTxt_ ) {
256  }
257 
258  //instantiate the jet corrector
260 }
dictionary parameters
Definition: Parameters.py:2
std::vector< JetCorrectorParameters > jetCorPars_
FactorizedJetCorrector * jecCor_
edm::FileInPath residualsTxt_
const T & get() const
Definition: EventSetup.h:55
std::string fullPath() const
Definition: FileInPath.cc:165
void PileupJetIdProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 72 of file PileupJetIdProducer.cc.

References algos_, applyJec_, assert(), reco::CompositePtrCandidate::clone(), PileupJetIdAlgo::computeIdVariables(), PileupJetIdAlgo::computeMva(), reco::LeafCandidate::eta(), edm::Event::getByToken(), FactorizedJetCorrector::getCorrection(), i, PileupJetIdentifier::idFlag(), initJetEnergyCorrector(), input_jet_token_, input_rho_token_, input_vertex_token_, input_vm_pujetid_token_, inputIsCorrected_, edm::EventBase::isRealData(), patTestJEC_cfi::jec, jecCor_, metsig::jet, reco::Jet::jetArea(), StoredPileupJetIdentifier::jetEta(), PileupJetIdentifier::jetPhi(), StoredPileupJetIdentifier::jetPt(), fwrapper::jets, PileupJetIdentifier::mva(), reco::LeafCandidate::phi(), produceJetIds_, reco::LeafCandidate::pt(), edm::Event::put(), dt_dqm_sourceclient_common_cff::reco, rho, runMvas_, pileupReCalc_HLTpaths::scale, reco::Jet::scaleEnergy(), PileupJetIdAlgo::set(), FactorizedJetCorrector::setJetA(), FactorizedJetCorrector::setJetEta(), FactorizedJetCorrector::setJetPt(), and FactorizedJetCorrector::setRho().

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

Member Data Documentation

std::vector<std::pair<std::string, 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().

FactorizedJetCorrector* PileupJetIdProducer::jecCor_
private

Definition at line 69 of file PileupJetIdProducer.h.

Referenced by initJetEnergyCorrector(), PileupJetIdProducer(), 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().