CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
ElectronMVANtuplizer Class Reference

#include <RecoEgamma/ElectronIdentification/plugins/ElectronMVANtuplizer.cc>

Inheritance diagram for ElectronMVANtuplizer:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 ElectronMVANtuplizer (const edm::ParameterSet &)
 
 ~ElectronMVANtuplizer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

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

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
void findFirstNonElectronMother2 (const reco::Candidate *particle, int &ancestorPID, int &ancestorStatus)
 
template<class T , class V >
int matchToTruth (const T &el, const V &genParticles, int &genIdx)
 

Private Attributes

const double deltaR_
 
int ele3Q_
 
bool eleIsEB_
 
bool eleIsEBEEGap_
 
bool eleIsEBEtaGap_
 
bool eleIsEBPhiGap_
 
bool eleIsEE_
 
bool eleIsEEDeeGap_
 
bool eleIsEERingGap_
 
const std::vector< std::string > eleMapBranchNames_
 
const std::vector< std::string > eleMapTags_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > eleMapTokens_
 
float eleQ_
 
int genNpu_
 
const edm::EDGetToken genParticles_
 
const edm::EDGetToken genParticlesMiniAOD_
 
const bool isMC_
 
int matchedGenIdx_
 
int matchedToGenEle_
 
const std::vector< std::string > mvaCatBranchNames_
 
std::vector< int > mvaCats_
 
const std::vector< std::string > mvaCatTags_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< int > > > mvaCatTokens_
 
std::vector< int > mvaPasses_
 
std::vector< float > mvaValues_
 
MVAVariableManager< reco::GsfElectronmvaVarMngr_
 
const size_t nCats_
 
const size_t nEleMaps_
 
int nEvent_
 
int nLumi_
 
int nRun_
 
const size_t nValMaps_
 
int nVars_
 
const edm::EDGetToken pileup_
 
const edm::EDGetToken pileupMiniAOD_
 
const double ptThreshold_
 
const edm::EDGetToken src_
 
const edm::EDGetToken srcMiniAOD_
 
TTree * tree_
 
const std::vector< std::string > valMapBranchNames_
 
const std::vector< std::string > valMapTags_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > valMapTokens_
 
std::vector< float > vars_
 
const edm::EDGetToken vertices_
 
const edm::EDGetToken verticesMiniAOD_
 
int vtxN_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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: Ntuplizer for training and testing electron MVA IDs.

Implementation: [Notes on implementation]

Definition at line 56 of file ElectronMVANtuplizer.cc.

Constructor & Destructor Documentation

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

Definition at line 162 of file ElectronMVANtuplizer.cc.

References edm::EDConsumerBase::consumes(), ele3Q_, eleIsEB_, eleIsEBEEGap_, eleIsEBEtaGap_, eleIsEBPhiGap_, eleIsEE_, eleIsEEDeeGap_, eleIsEERingGap_, eleMapBranchNames_, eleMapTags_, eleMapTokens_, eleQ_, genNpu_, MVAVariableManager< ParticleType >::getGlobalInputTags(), MVAVariableManager< ParticleType >::getHelperInputTags(), MVAVariableManager< ParticleType >::getName(), MVAVariableManager< ParticleType >::getNVars(), mps_fire::i, isMC_, gen::k, TFileService::kSharedResource, TFileService::make(), matchedToGenEle_, mvaCatBranchNames_, mvaCats_, mvaCatTags_, mvaCatTokens_, mvaPasses_, mvaValues_, mvaVarMngr_, nCats_, nEleMaps_, nEvent_, nLumi_, nRun_, nValMaps_, nVars_, GlobalPosition_Frontier_DevDB_cff::tag, tree_, valMapBranchNames_, valMapTags_, valMapTokens_, vars_, and vtxN_.

163  :
165  vertices_ (consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("vertices"))),
166  pileup_ (consumes<std::vector< PileupSummaryInfo > >(iConfig.getParameter<edm::InputTag>("pileup"))),
169  verticesMiniAOD_ (consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("verticesMiniAOD"))),
170  pileupMiniAOD_ (consumes<std::vector< PileupSummaryInfo > >(iConfig.getParameter<edm::InputTag>("pileupMiniAOD"))),
172  mvaVarMngr_ (iConfig.getParameter<std::string>("variableDefinition")),
173  isMC_ (iConfig.getParameter<bool>("isMC")),
174  deltaR_ (iConfig.getParameter<double>("deltaR")),
175  ptThreshold_ (iConfig.getParameter<double>("ptThreshold")),
176  eleMapTags_ (iConfig.getUntrackedParameter<std::vector<std::string>>("eleMVAs")),
177  eleMapBranchNames_ (iConfig.getUntrackedParameter<std::vector<std::string>>("eleMVALabels")),
178  nEleMaps_ (eleMapBranchNames_.size()),
179  valMapTags_ (iConfig.getUntrackedParameter<std::vector<std::string>>("eleMVAValMaps")),
180  valMapBranchNames_ (iConfig.getUntrackedParameter<std::vector<std::string>>("eleMVAValMapLabels")),
181  nValMaps_ (valMapBranchNames_.size()),
182  mvaCatTags_ (iConfig.getUntrackedParameter<std::vector<std::string>>("eleMVACats")),
183  mvaCatBranchNames_ (iConfig.getUntrackedParameter<std::vector<std::string>>("eleMVACatLabels")),
184  nCats_ (mvaCatBranchNames_.size())
185 {
186  // eleMaps
187  for (size_t k = 0; k < nEleMaps_; ++k) {
188 
190 
191  // Initialize vectors for holding ID decisions
192  mvaPasses_.push_back(0);
193  }
194 
195  // valMaps
196  for (size_t k = 0; k < nValMaps_; ++k) {
198 
199  // Initialize vectors for holding MVA values
200  mvaValues_.push_back(0.0);
201  }
202 
203  // categories
204  for (size_t k = 0; k < nCats_; ++k) {
206 
207  // Initialize vectors for holding MVA values
208  mvaCats_.push_back(0);
209  }
210 
211  // Book tree
212  usesResource(TFileService::kSharedResource);
214  tree_ = fs->make<TTree>("tree","tree");
215 
217 
218  tree_->Branch("nEvent", &nEvent_);
219  tree_->Branch("nRun", &nRun_);
220  tree_->Branch("nLumi", &nLumi_);
221  if (isMC_) tree_->Branch("genNpu", &genNpu_);
222  tree_->Branch("vtxN", &vtxN_);
223 
224  tree_->Branch("ele_q",&eleQ_);
225  tree_->Branch("ele_3q",&ele3Q_);
226 
227  if (isMC_) {
228  tree_->Branch("matchedToGenEle", &matchedToGenEle_);
229  }
230 
231  // Has to be in two different loops
232  for (int i = 0; i < nVars_; ++i) {
233  vars_.push_back(0.0);
234  }
235  for (int i = 0; i < nVars_; ++i) {
236  tree_->Branch(mvaVarMngr_.getName(i).c_str(), &vars_[i]);
237  }
238 
239  tree_->Branch("ele_isEB",&eleIsEB_);
240  tree_->Branch("ele_isEE",&eleIsEE_);
241  tree_->Branch("ele_isEBEtaGap",&eleIsEBEtaGap_);
242  tree_->Branch("ele_isEBPhiGap",&eleIsEBPhiGap_);
243  tree_->Branch("ele_isEBEEGap", &eleIsEBEEGap_);
244  tree_->Branch("ele_isEEDeeGap",&eleIsEEDeeGap_);
245  tree_->Branch("ele_isEERingGap",&eleIsEERingGap_);
246 
247  // IDs
248  for (size_t k = 0; k < nValMaps_; ++k) {
249  tree_->Branch(valMapBranchNames_[k].c_str() , &mvaValues_[k]);
250  }
251 
252  for (size_t k = 0; k < nEleMaps_; ++k) {
253  tree_->Branch(eleMapBranchNames_[k].c_str() , &mvaPasses_[k]);
254  }
255 
256  for (size_t k = 0; k < nCats_; ++k) {
257  tree_->Branch(mvaCatBranchNames_[k].c_str() , &mvaCats_[k]);
258  }
259 
260  // All tokens for event content needed by this MVA
261  // Tags from the variable helper
262  for (auto &tag : mvaVarMngr_.getHelperInputTags()) {
263  consumes<edm::ValueMap<float>>(tag);
264  }
265  for (auto &tag : mvaVarMngr_.getGlobalInputTags()) {
266  consumes<double>(tag);
267  }
268 }
static const std::string kSharedResource
Definition: TFileService.h:76
const std::string getName(int index) const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const edm::EDGetToken srcMiniAOD_
const edm::EDGetToken verticesMiniAOD_
std::vector< edm::InputTag > getHelperInputTags() const
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< edm::EDGetTokenT< edm::ValueMap< int > > > mvaCatTokens_
std::vector< float > mvaValues_
const edm::EDGetToken vertices_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< int > mvaPasses_
const std::vector< std::string > valMapBranchNames_
std::vector< int > mvaCats_
const int getNVars() const
int k[5][pyjets_maxn]
const edm::EDGetToken genParticlesMiniAOD_
const std::vector< std::string > eleMapBranchNames_
std::vector< float > vars_
MVAVariableManager< reco::GsfElectron > mvaVarMngr_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > valMapTokens_
const edm::EDGetToken pileupMiniAOD_
const std::vector< std::string > mvaCatTags_
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > eleMapTokens_
const edm::EDGetToken pileup_
const edm::EDGetToken src_
const edm::EDGetToken genParticles_
const std::vector< std::string > mvaCatBranchNames_
std::vector< edm::InputTag > getGlobalInputTags() const
const std::vector< std::string > eleMapTags_
const std::vector< std::string > valMapTags_
ElectronMVANtuplizer::~ElectronMVANtuplizer ( )
override

Definition at line 271 of file ElectronMVANtuplizer.cc.

272 {
273 
274  // do anything here that needs to be done at desctruction time
275  // (e.g. close files, deallocate resources etc.)
276 
277 }

Member Function Documentation

void ElectronMVANtuplizer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 286 of file ElectronMVANtuplizer.cc.

References ele3Q_, eleIsEB_, eleIsEBEEGap_, eleIsEBEtaGap_, eleIsEBPhiGap_, eleIsEE_, eleIsEEDeeGap_, eleIsEERingGap_, eleMapTokens_, eleQ_, edm::EventID::event(), genNpu_, GenHFHadronMatcher_cfi::genParticles, genParticles_, genParticlesMiniAOD_, edm::Event::getByToken(), MVAVariableManager< ParticleType >::getValue(), edm::EventBase::id(), createfilelist::int, isMC_, edm::HandleBase::isValid(), gen::k, edm::EventBase::luminosityBlock(), matchedGenIdx_, matchedToGenEle_, matchToTruth(), mvaCats_, mvaCatTokens_, mvaPasses_, mvaValues_, mvaVarMngr_, nCats_, nEleMaps_, nEvent_, nLumi_, nRun_, nValMaps_, nVars_, ElectronMVANtuplizer_cfg::pileup, pileup_, pileupMiniAOD_, ptThreshold_, muons2muons_cfi::pu, edm::EventID::run(), TrackRefitter_38T_cff::src, src_, srcMiniAOD_, tree_, valMapTokens_, MuonErrorMatrixValues_cff::values, vars_, electrons_cff::vertices, vertices_, verticesMiniAOD_, and vtxN_.

287 {
288  // Fill global event info
289  nEvent_ = iEvent.id().event();
290  nRun_ = iEvent.id().run();
291  nLumi_ = iEvent.luminosityBlock();
292 
293 
294  // Retrieve Vertecies
296  iEvent.getByToken(vertices_, vertices);
297  if( !vertices.isValid() ){
298  iEvent.getByToken(verticesMiniAOD_,vertices);
299  if( !vertices.isValid() )
300  throw cms::Exception(" Collection not found: ")
301  << " failed to find a standard AOD or miniAOD vertex collection " << std::endl;
302  }
303 
304  vtxN_ = vertices->size();
305 
306  // Retrieve Pileup Info
307  if(isMC_) {
309  iEvent.getByToken(pileup_, pileup);
310  if( !pileup.isValid() ){
311  iEvent.getByToken(pileupMiniAOD_,pileup);
312  if( !pileup.isValid() )
313  throw cms::Exception(" Collection not found: ")
314  << " failed to find a standard AOD or miniAOD pileup collection " << std::endl;
315  }
316 
317  // Fill with true number of pileup
318  for(const auto& pu : *pileup)
319  {
320  int bx = pu.getBunchCrossing();
321  if(bx == 0)
322  {
323  genNpu_ = pu.getPU_NumInteractions();
324  break;
325  }
326  }
327  }
328 
329  // Retrieve genParticles
331  if(isMC_) {
332  iEvent.getByToken(genParticles_, genParticles);
333  if( !genParticles.isValid() ){
334  iEvent.getByToken(genParticlesMiniAOD_, genParticles);
335  if( !genParticles.isValid() )
336  throw cms::Exception(" Collection not found: ")
337  << " failed to find a standard AOD or miniAOD genParticle collection " << std::endl;
338  }
339  }
340 
341 
343 
344  // Retrieve the collection of particles from the event.
345  // If we fail to retrieve the collection with the standard AOD
346  // name, we next look for the one with the stndard miniAOD name.
347  iEvent.getByToken(src_, src);
348  if( !src.isValid() ){
349  iEvent.getByToken(srcMiniAOD_,src);
350  if( !src.isValid() )
351  throw cms::Exception(" Collection not found: ")
352  << " failed to find a standard AOD or miniAOD particle collection " << std::endl;
353  }
354 
355  // Get MVA decisions
357  for (size_t k = 0; k < nEleMaps_; ++k) {
358  iEvent.getByToken(eleMapTokens_[k],decisions[k]);
359  }
360 
361  // Get MVA values
363  for (size_t k = 0; k < nValMaps_; ++k) {
364  iEvent.getByToken(valMapTokens_[k],values[k]);
365  }
366 
367  // Get MVA categories
369  for (size_t k = 0; k < nCats_; ++k) {
370  iEvent.getByToken(mvaCatTokens_[k],mvaCats[k]);
371  }
372 
373  int nEle = src->size();
374 
375  for(int iEle = 0; iEle < nEle; ++iEle) {
376 
377  const auto ele = src->ptrAt(iEle);
378 
379  eleQ_ = ele->charge();
380  ele3Q_ = ele->chargeInfo().isGsfCtfScPixConsistent;
381 
382  if (ele->pt() < ptThreshold_) {
383  continue;
384  }
385 
386  for (int iVar = 0; iVar < nVars_; ++iVar) {
387  vars_[iVar] = mvaVarMngr_.getValue(iVar, ele, iEvent);
388  }
389 
390  if (isMC_) {
391  matchedToGenEle_ = matchToTruth( ele, genParticles, matchedGenIdx_);
392  }
393 
394  // gap variables
395  eleIsEB_ = ele->isEB();
396  eleIsEE_ = ele->isEE();
397  eleIsEBEEGap_ = ele->isEBEEGap();
398  eleIsEBEtaGap_ = ele->isEBEtaGap();
399  eleIsEBPhiGap_ = ele->isEBPhiGap();
400  eleIsEEDeeGap_ = ele->isEEDeeGap();
401  eleIsEERingGap_ = ele->isEERingGap();
402 
403  //
404  // Look up and save the ID decisions
405  //
406  for (size_t k = 0; k < nEleMaps_; ++k) {
407  mvaPasses_[k] = (int)(*decisions[k])[ele];
408  }
409 
410  for (size_t k = 0; k < nValMaps_; ++k) {
411  mvaValues_[k] = (*values[k])[ele];
412  }
413 
414  for (size_t k = 0; k < nCats_; ++k) {
415  mvaCats_[k] = (*mvaCats[k])[ele];
416  }
417 
418 
419  tree_->Fill();
420  }
421 
422 }
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
const edm::EDGetToken srcMiniAOD_
const edm::EDGetToken verticesMiniAOD_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
std::vector< edm::EDGetTokenT< edm::ValueMap< int > > > mvaCatTokens_
std::vector< float > mvaValues_
const edm::EDGetToken vertices_
std::vector< int > mvaPasses_
std::vector< int > mvaCats_
int matchToTruth(const T &el, const V &genParticles, int &genIdx)
bool isValid() const
Definition: HandleBase.h:74
int k[5][pyjets_maxn]
const edm::EDGetToken genParticlesMiniAOD_
std::vector< float > vars_
MVAVariableManager< reco::GsfElectron > mvaVarMngr_
float getValue(int index, const edm::Ptr< ParticleType > &ptclPtr, const edm::EventBase &iEvent) const
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > valMapTokens_
const edm::EDGetToken pileupMiniAOD_
edm::EventID id() const
Definition: EventBase.h:60
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > eleMapTokens_
const edm::EDGetToken pileup_
const edm::EDGetToken src_
const edm::EDGetToken genParticles_
void ElectronMVANtuplizer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 497 of file ElectronMVANtuplizer.cc.

498 {
499 }
void ElectronMVANtuplizer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 503 of file ElectronMVANtuplizer.cc.

504 {
505 }
void ElectronMVANtuplizer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 509 of file ElectronMVANtuplizer.cc.

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

509  {
510 
512  desc.add<edm::InputTag>("src");
513  desc.add<edm::InputTag>("vertices");
514  desc.add<edm::InputTag>("pileup");
515  desc.add<edm::InputTag>("genParticles");
516  desc.add<edm::InputTag>("srcMiniAOD");
517  desc.add<edm::InputTag>("verticesMiniAOD");
518  desc.add<edm::InputTag>("pileupMiniAOD");
519  desc.add<edm::InputTag>("genParticlesMiniAOD");
520  desc.add<std::string>("variableDefinition");
521  desc.add<bool>("isMC");
522  desc.add<double>("deltaR", 0.1);
523  desc.add<double>("ptThreshold", 5.0);
524  desc.addUntracked<std::vector<std::string>>("eleMVAs");
525  desc.addUntracked<std::vector<std::string>>("eleMVALabels");
526  desc.addUntracked<std::vector<std::string>>("eleMVAValMaps");
527  desc.addUntracked<std::vector<std::string>>("eleMVAValMapLabels");
528  desc.addUntracked<std::vector<std::string>>("eleMVACats");
529  desc.addUntracked<std::vector<std::string>>("eleMVACatLabels");
530  descriptions.addDefault(desc);
531 
532 }
void addDefault(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void ElectronMVANtuplizer::findFirstNonElectronMother2 ( const reco::Candidate particle,
int &  ancestorPID,
int &  ancestorStatus 
)
private

Definition at line 424 of file ElectronMVANtuplizer.cc.

References funct::abs(), reco::Candidate::mother(), reco::Candidate::pdgId(), and reco::Candidate::status().

Referenced by matchToTruth().

425  {
426 
427  if( particle == nullptr ){
428  edm::LogError ("ElectronNtuplizer") << "ElectronNtuplizer: ERROR! null candidate pointer, this should never happen";
429  return;
430  }
431 
432  // Is this the first non-electron parent? If yes, return, otherwise
433  // go deeper into recursion
434  if( abs(particle->pdgId()) == 11 ){
435  findFirstNonElectronMother2(particle->mother(0), ancestorPID, ancestorStatus);
436  }else{
437  ancestorPID = particle->pdgId();
438  ancestorStatus = particle->status();
439  }
440 
441  return;
442 }
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
virtual int status() const =0
status word
virtual int pdgId() const =0
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void findFirstNonElectronMother2(const reco::Candidate *particle, int &ancestorPID, int &ancestorStatus)
template<class T , class V >
int ElectronMVANtuplizer::matchToTruth ( const T el,
const V &  genParticles,
int &  genIdx 
)
private

Definition at line 445 of file ElectronMVANtuplizer.cc.

References funct::abs(), HiRegitMuonDetachedTripletStep_cff::DeltaR, deltaR_, PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, findFirstNonElectronMother2(), mps_fire::i, reco::Candidate::p4(), reco::Candidate::pdgId(), reco::Candidate::status(), TRUE_ELECTRON_FROM_TAU, TRUE_NON_PROMPT_ELECTRON, TRUE_PROMPT_ELECTRON, and UNMATCHED.

Referenced by analyze().

445  {
446 
447  //
448  // Explicit loop and geometric matching method (advised by Josh Bendavid)
449  //
450 
451  // Find the closest status 1 gen electron to the reco electron
452  double dR = 999;
453  const reco::Candidate *closestElectron = nullptr;
454  for(size_t i=0; i<prunedGenParticles->size();i++){
455  const reco::Candidate *particle = &(*prunedGenParticles)[i];
456  // Drop everything that is not electron or not status 1
457  if( abs(particle->pdgId()) != 11 || particle->status() != 1 )
458  continue;
459  //
460  double dRtmp = ROOT::Math::VectorUtil::DeltaR( el->p4(), particle->p4() );
461  if( dRtmp < dR ){
462  dR = dRtmp;
463  closestElectron = particle;
464  genIdx = i;
465  }
466  }
467  // See if the closest electron (if it exists) is close enough.
468  // If not, no match found.
469  if( !(closestElectron != nullptr && dR < deltaR_) ) {
470  return UNMATCHED;
471  }
472 
473  //
474  int ancestorPID = -999;
475  int ancestorStatus = -999;
476  findFirstNonElectronMother2(closestElectron, ancestorPID, ancestorStatus);
477 
478  if( ancestorPID == -999 && ancestorStatus == -999 ){
479  // No non-electron parent??? This should never happen.
480  // Complain.
481  edm::LogError ("ElectronNtuplizer") << "ElectronNtuplizer: ERROR! null candidate pointer, this should never happen";
482  return UNMATCHED;
483  }
484 
485  if( abs(ancestorPID) > 50 && ancestorStatus == 2 )
487 
488  if( abs(ancestorPID) == 15 && ancestorStatus == 2 )
489  return TRUE_ELECTRON_FROM_TAU;
490 
491  // What remains is true prompt electrons
492  return TRUE_PROMPT_ELECTRON;
493 }
virtual int status() const =0
status word
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
virtual int pdgId() const =0
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void findFirstNonElectronMother2(const reco::Candidate *particle, int &ancestorPID, int &ancestorStatus)

Member Data Documentation

const double ElectronMVANtuplizer::deltaR_
private

Definition at line 123 of file ElectronMVANtuplizer.cc.

Referenced by matchToTruth().

int ElectronMVANtuplizer::ele3Q_
private

Definition at line 102 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

bool ElectronMVANtuplizer::eleIsEB_
private

Definition at line 108 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

bool ElectronMVANtuplizer::eleIsEBEEGap_
private

Definition at line 112 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

bool ElectronMVANtuplizer::eleIsEBEtaGap_
private

Definition at line 110 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

bool ElectronMVANtuplizer::eleIsEBPhiGap_
private

Definition at line 111 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

bool ElectronMVANtuplizer::eleIsEE_
private

Definition at line 109 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

bool ElectronMVANtuplizer::eleIsEEDeeGap_
private

Definition at line 113 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

bool ElectronMVANtuplizer::eleIsEERingGap_
private

Definition at line 114 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const std::vector< std::string > ElectronMVANtuplizer::eleMapBranchNames_
private

Definition at line 129 of file ElectronMVANtuplizer.cc.

Referenced by ElectronMVANtuplizer().

const std::vector< std::string > ElectronMVANtuplizer::eleMapTags_
private

Definition at line 127 of file ElectronMVANtuplizer.cc.

Referenced by ElectronMVANtuplizer().

std::vector< edm::EDGetTokenT< edm::ValueMap<bool> > > ElectronMVANtuplizer::eleMapTokens_
private

Definition at line 128 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

float ElectronMVANtuplizer::eleQ_
private

Definition at line 101 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

int ElectronMVANtuplizer::genNpu_
private

Definition at line 97 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const edm::EDGetToken ElectronMVANtuplizer::genParticles_
private

Definition at line 80 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

const edm::EDGetToken ElectronMVANtuplizer::genParticlesMiniAOD_
private

Definition at line 86 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

const bool ElectronMVANtuplizer::isMC_
private

Definition at line 122 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

int ElectronMVANtuplizer::matchedGenIdx_
private

Definition at line 104 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

int ElectronMVANtuplizer::matchedToGenEle_
private

Definition at line 103 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const std::vector< std::string > ElectronMVANtuplizer::mvaCatBranchNames_
private

Definition at line 140 of file ElectronMVANtuplizer.cc.

Referenced by ElectronMVANtuplizer().

std::vector<int> ElectronMVANtuplizer::mvaCats_
private

Definition at line 119 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const std::vector< std::string > ElectronMVANtuplizer::mvaCatTags_
private

Definition at line 138 of file ElectronMVANtuplizer.cc.

Referenced by ElectronMVANtuplizer().

std::vector< edm::EDGetTokenT<edm::ValueMap<int> > > ElectronMVANtuplizer::mvaCatTokens_
private

Definition at line 139 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

std::vector<int> ElectronMVANtuplizer::mvaPasses_
private

Definition at line 117 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

std::vector<float> ElectronMVANtuplizer::mvaValues_
private

Definition at line 118 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

MVAVariableManager<reco::GsfElectron> ElectronMVANtuplizer::mvaVarMngr_
private

Definition at line 91 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const size_t ElectronMVANtuplizer::nCats_
private

Definition at line 141 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const size_t ElectronMVANtuplizer::nEleMaps_
private

Definition at line 130 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

int ElectronMVANtuplizer::nEvent_
private

Definition at line 96 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

int ElectronMVANtuplizer::nLumi_
private

Definition at line 96 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

int ElectronMVANtuplizer::nRun_
private

Definition at line 96 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const size_t ElectronMVANtuplizer::nValMaps_
private

Definition at line 136 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

int ElectronMVANtuplizer::nVars_
private

Definition at line 93 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const edm::EDGetToken ElectronMVANtuplizer::pileup_
private

Definition at line 79 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

const edm::EDGetToken ElectronMVANtuplizer::pileupMiniAOD_
private

Definition at line 85 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

const double ElectronMVANtuplizer::ptThreshold_
private

Definition at line 124 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

const edm::EDGetToken ElectronMVANtuplizer::src_
private

Definition at line 77 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

const edm::EDGetToken ElectronMVANtuplizer::srcMiniAOD_
private

Definition at line 83 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

TTree* ElectronMVANtuplizer::tree_
private

Definition at line 89 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const std::vector< std::string > ElectronMVANtuplizer::valMapBranchNames_
private

Definition at line 135 of file ElectronMVANtuplizer.cc.

Referenced by ElectronMVANtuplizer().

const std::vector< std::string > ElectronMVANtuplizer::valMapTags_
private

Definition at line 133 of file ElectronMVANtuplizer.cc.

Referenced by ElectronMVANtuplizer().

std::vector< edm::EDGetTokenT<edm::ValueMap<float> > > ElectronMVANtuplizer::valMapTokens_
private

Definition at line 134 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

std::vector<float> ElectronMVANtuplizer::vars_
private

Definition at line 92 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().

const edm::EDGetToken ElectronMVANtuplizer::vertices_
private

Definition at line 78 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

const edm::EDGetToken ElectronMVANtuplizer::verticesMiniAOD_
private

Definition at line 84 of file ElectronMVANtuplizer.cc.

Referenced by analyze().

int ElectronMVANtuplizer::vtxN_
private

Definition at line 98 of file ElectronMVANtuplizer.cc.

Referenced by analyze(), and ElectronMVANtuplizer().