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

Definition at line 47 of file PileupJetIdProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 72 of file PileupJetIdProducer.cc.

References algos_, applyJec_, edm::ParameterSet::getParameter(), inputIsCorrected_, jec_, jecCor_, jetids_, jets_, diffTwoXMLs::label, produceJetIds_, residualsFromTxt_, residualsTxt_, rho_, runMvas_, AlCaHLTBitMon_QueryRunRegistry::string, and vertexes_.

73 {
74  runMvas_ = iConfig.getParameter<bool>("runMvas");
75  produceJetIds_ = iConfig.getParameter<bool>("produceJetIds");
76  jets_ = iConfig.getParameter<edm::InputTag>("jets");
77  vertexes_ = iConfig.getParameter<edm::InputTag>("vertexes");
78  jetids_ = iConfig.getParameter<edm::InputTag>("jetids");
79  inputIsCorrected_ = iConfig.getParameter<bool>("inputIsCorrected");
80  applyJec_ = iConfig.getParameter<bool>("applyJec");
81  jec_ = iConfig.getParameter<std::string>("jec");
82  rho_ = iConfig.getParameter<edm::InputTag>("rho");
83  residualsFromTxt_ = iConfig.getParameter<bool>("residualsFromTxt");
84  residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt");
85  std::vector<edm::ParameterSet> algos = iConfig.getParameter<std::vector<edm::ParameterSet> >("algos");
86 
87  jecCor_ = 0;
88 
89  if( ! runMvas_ ) assert( algos.size() == 1 );
90 
91  if( produceJetIds_ ) {
92  produces<edm::ValueMap<StoredPileupJetIdentifier> > ("");
93  }
94  for(std::vector<edm::ParameterSet>::iterator it=algos.begin(); it!=algos.end(); ++it) {
95  std::string label = it->getParameter<std::string>("label");
96  algos_.push_back( std::make_pair(label,new PileupJetIdAlgo(*it)) );
97  if( runMvas_ ) {
98  produces<edm::ValueMap<float> > (label+"Discriminant");
99  produces<edm::ValueMap<int> > (label+"Id");
100  }
101  }
102 }
T getParameter(std::string const &) const
std::vector< std::pair< std::string, PileupJetIdAlgo * > > algos_
FactorizedJetCorrector * jecCor_
edm::FileInPath residualsTxt_
PileupJetIdProducer::~PileupJetIdProducer ( )

Definition at line 107 of file PileupJetIdProducer.cc.

108 {
109 }

Member Function Documentation

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

Definition at line 268 of file PileupJetIdProducer.cc.

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

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

Definition at line 279 of file PileupJetIdProducer.cc.

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

Referenced by produce().

280 {
281  //jet energy correction levels to apply on raw jet
282  std::vector<std::string> jecLevels;
283  jecLevels.push_back("L1FastJet");
284  jecLevels.push_back("L2Relative");
285  jecLevels.push_back("L3Absolute");
286  if(isData && ! residualsFromTxt_ ) jecLevels.push_back("L2L3Residual");
287 
288  //check the corrector parameters needed according to the correction levels
290  iSetup.get<JetCorrectionsRecord>().get(jec_,parameters);
291  for(std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll)
292  {
293  const JetCorrectorParameters& ip = (*parameters)[*ll];
294  jetCorPars_.push_back(ip);
295  }
296  if( isData && residualsFromTxt_ ) {
298  }
299 
300  //instantiate the jet corrector
302 }
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:171
void PileupJetIdProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 114 of file PileupJetIdProducer.cc.

References algos_, applyJec_, reco::CompositePtrCandidate::clone(), PileupJetIdAlgo::computeIdVariables(), PileupJetIdAlgo::computeMva(), reco::LeafCandidate::eta(), edm::Event::getByLabel(), FactorizedJetCorrector::getCorrection(), i, initJetEnergyCorrector(), inputIsCorrected_, edm::EventBase::isRealData(), patTestJEC_cfi::jec, jecCor_, metsig::jet, reco::Jet::jetArea(), jetids_, fwrapper::jets, jets_, reco::LeafCandidate::phi(), produceJetIds_, reco::LeafCandidate::pt(), edm::Event::put(), dt_dqm_sourceclient_common_cff::reco, rho, rho_, runMvas_, pileupReCalc_HLTpaths::scale, reco::Jet::scaleEnergy(), PileupJetIdAlgo::set(), FactorizedJetCorrector::setJetA(), FactorizedJetCorrector::setJetEta(), FactorizedJetCorrector::setJetPt(), FactorizedJetCorrector::setRho(), and vertexes_.

115 {
116  using namespace edm;
117  using namespace std;
118  using namespace reco;
119 
120  // Input jets
121  Handle<View<Jet> > jetHandle;
122  iEvent.getByLabel(jets_,jetHandle);
123  const View<Jet> & jets = *jetHandle;
124  // vertexes
125  Handle<VertexCollection> vertexHandle;
126  if( produceJetIds_ ) {
127  iEvent.getByLabel(vertexes_, vertexHandle);
128  }
129  const VertexCollection & vertexes = *(vertexHandle.product());
130  // input variables
132  if( ! produceJetIds_ ) {
133  iEvent.getByLabel(jetids_, vmap);
134  }
135  // rho
137  double rho = 0.;
138 
139  // products
140  vector<StoredPileupJetIdentifier> ids;
141  map<string, vector<float> > mvas;
142  map<string, vector<int> > idflags;
143 
144  VertexCollection::const_iterator vtx;
145  if( produceJetIds_ ) {
146  // require basic quality cuts on the vertexes
147  vtx = vertexes.begin();
148  while( vtx != vertexes.end() && ( vtx->isFake() || vtx->ndof() < 4 ) ) {
149  ++vtx;
150  }
151  if( vtx == vertexes.end() ) { vtx = vertexes.begin(); }
152  }
153 
154  // Loop over input jets
155  for ( unsigned int i=0; i<jets.size(); ++i ) {
156  // Pick the first algo to compute the input variables
157  vector<pair<string,PileupJetIdAlgo *> >::iterator algoi = algos_.begin();
158  PileupJetIdAlgo * ialgo = algoi->second;
159 
160  const Jet & jet = jets.at(i);
161  //const pat::Jet * patjet = dynamic_cast<const pat::Jet *>(&jet);
162  //bool ispat = patjet != 0;
163 
164  // Get jet energy correction
165  float jec = 0.;
166  if( applyJec_ ) {
167  // If haven't done it get rho from the event
168  if( rho == 0. ) {
169  iEvent.getByLabel(rho_,rhoH);
170  rho = *rhoH;
171  }
172  // jet corrector
173  if( jecCor_ == 0 ) {
174  initJetEnergyCorrector( iSetup, iEvent.isRealData() );
175  }
176  //if( ispat ) {
177  // jecCor_->setJetPt(patjet->correctedJet(0).pt());
178  //} else {
179  jecCor_->setJetPt(jet.pt());
180  //}
181  jecCor_->setJetEta(jet.eta());
182  jecCor_->setJetA(jet.jetArea());
183  jecCor_->setRho(rho);
184  jec = jecCor_->getCorrection();
185  }
186 
187  // If it was requested or the input is an uncorrected jet apply the JEC
188  bool applyJec = applyJec_ || !inputIsCorrected_; //( ! ispat && ! inputIsCorrected_ );
189  reco::Jet * corrJet = 0;
190  if( applyJec ) {
191  float scale = jec;
192  //if( ispat ) {
193  // corrJet = new pat::Jet(patjet->correctedJet(0)) ;
194  //} else {
195  corrJet = dynamic_cast<reco::Jet *>( jet.clone() );
196  //}
197  corrJet->scaleEnergy(scale);
198  }
199  const reco::Jet * theJet = ( applyJec ? corrJet : &jet );
200 
201  PileupJetIdentifier puIdentifier;
202  if( produceJetIds_ ) {
203  // Compute the input variables
204  puIdentifier = ialgo->computeIdVariables(theJet, jec, &(*vtx), vertexes, runMvas_);
205  ids.push_back( puIdentifier );
206  } else {
207  // Or read it from the value map
208  puIdentifier = (*vmap)[jets.refAt(i)];
209  puIdentifier.jetPt(theJet->pt()); // make sure JEC is applied when computing the MVA
210  puIdentifier.jetEta(theJet->eta());
211  puIdentifier.jetPhi(theJet->phi());
212  ialgo->set(puIdentifier);
213  puIdentifier = ialgo->computeMva();
214  }
215 
216  if( runMvas_ ) {
217  // Compute the MVA and WP
218  mvas[algoi->first].push_back( puIdentifier.mva() );
219  idflags[algoi->first].push_back( puIdentifier.idFlag() );
220  for( ++algoi; algoi!=algos_.end(); ++algoi) {
221  ialgo = algoi->second;
222  ialgo->set(puIdentifier);
223  PileupJetIdentifier id = ialgo->computeMva();
224  mvas[algoi->first].push_back( id.mva() );
225  idflags[algoi->first].push_back( id.idFlag() );
226  }
227  }
228 
229  // cleanup
230  if( corrJet ) { delete corrJet; }
231  }
232 
233  // Produce the output value maps
234  if( runMvas_ ) {
235  for(vector<pair<string,PileupJetIdAlgo *> >::iterator ialgo = algos_.begin(); ialgo!=algos_.end(); ++ialgo) {
236  // MVA
237  vector<float> & mva = mvas[ialgo->first];
238  auto_ptr<ValueMap<float> > mvaout(new ValueMap<float>());
239  ValueMap<float>::Filler mvafiller(*mvaout);
240  mvafiller.insert(jetHandle,mva.begin(),mva.end());
241  mvafiller.fill();
242  iEvent.put(mvaout,ialgo->first+"Discriminant");
243 
244  // WP
245  vector<int> & idflag = idflags[ialgo->first];
246  auto_ptr<ValueMap<int> > idflagout(new ValueMap<int>());
247  ValueMap<int>::Filler idflagfiller(*idflagout);
248  idflagfiller.insert(jetHandle,idflag.begin(),idflag.end());
249  idflagfiller.fill();
250  iEvent.put(idflagout,ialgo->first+"Id");
251  }
252  }
253  // input variables
254  if( produceJetIds_ ) {
255  assert( jetHandle->size() == ids.size() );
256  auto_ptr<ValueMap<StoredPileupJetIdentifier> > idsout(new ValueMap<StoredPileupJetIdentifier>());
258  idsfiller.insert(jetHandle,ids.begin(),ids.end());
259  idsfiller.fill();
260  iEvent.put(idsout);
261  }
262 }
void set(const PileupJetIdentifier &)
int i
Definition: DBlmapReader.cc:9
std::vector< std::pair< std::string, PileupJetIdAlgo * > > algos_
Base class for all types of Jets.
Definition: Jet.h:20
Definition: DDAxes.h:10
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
virtual void scaleEnergy(double fScale)
scale energy of the jet
Definition: Jet.cc:444
bool isRealData() const
Definition: EventBase.h:60
virtual CompositePtrCandidate * clone() const
returns a clone of the candidate
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
FactorizedJetCorrector * jecCor_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
vector< PseudoJet > jets
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)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
PileupJetIdentifier computeMva()
virtual float jetArea() const
get jet area
Definition: Jet.h:105
virtual float pt() const GCC11_FINAL
transverse momentum

Member Data Documentation

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

Definition at line 63 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::applyJec_
private

Definition at line 62 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::inputIsCorrected_
private

Definition at line 62 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

std::string PileupJetIdProducer::jec_
private

Definition at line 61 of file PileupJetIdProducer.cc.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().

FactorizedJetCorrector* PileupJetIdProducer::jecCor_
private

Definition at line 67 of file PileupJetIdProducer.cc.

Referenced by initJetEnergyCorrector(), PileupJetIdProducer(), and produce().

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

Definition at line 68 of file PileupJetIdProducer.cc.

Referenced by initJetEnergyCorrector().

edm::InputTag PileupJetIdProducer::jetids_
private

Definition at line 60 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

edm::InputTag PileupJetIdProducer::jets_
private

Definition at line 60 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::produceJetIds_
private

Definition at line 62 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::residualsFromTxt_
private

Definition at line 65 of file PileupJetIdProducer.cc.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().

edm::FileInPath PileupJetIdProducer::residualsTxt_
private

Definition at line 66 of file PileupJetIdProducer.cc.

Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().

edm::InputTag PileupJetIdProducer::rho_
private

Definition at line 60 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

bool PileupJetIdProducer::runMvas_
private

Definition at line 62 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().

edm::InputTag PileupJetIdProducer::vertexes_
private

Definition at line 60 of file PileupJetIdProducer.cc.

Referenced by PileupJetIdProducer(), and produce().