CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes

pat::PATElectronProducer Class Reference

Produces pat::Electron's. More...

#include <PhysicsTools/PatAlgos/interface/PATElectronProducer.h>

Inheritance diagram for pat::PATElectronProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 PATElectronProducer (const edm::ParameterSet &iConfig)
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 ~PATElectronProducer ()

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)

Private Types

typedef edm::RefToBase
< reco::GsfElectron
ElectronBaseRef
typedef std::vector
< edm::Handle
< edm::Association
< reco::GenParticleCollection > > > 
GenAssociations
typedef std::vector
< edm::Handle< edm::ValueMap
< IsoDeposit > > > 
IsoDepositMaps
typedef std::pair
< pat::IsolationKeys,
edm::InputTag
IsolationLabel
typedef std::vector
< IsolationLabel
IsolationLabels
typedef std::vector
< edm::Handle< edm::ValueMap
< double > > > 
IsolationValueMaps
typedef std::pair< std::string,
edm::InputTag
NameTag

Private Member Functions

void fillElectron (Electron &aElectron, const ElectronBaseRef &electronRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
 common electron filling, for both the standard and PF2PAT case
void fillElectron2 (Electron &anElectron, const reco::CandidatePtr &candPtrForIsolation, const reco::CandidatePtr &candPtrForGenMatch, const reco::CandidatePtr &candPtrForLoader, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
void readIsolationLabels (const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels)

Private Attributes

bool addEfficiencies_
bool addElecID_
bool addGenMatch_
bool addResolutions_
edm::InputTag beamLineSrc_
pat::helper::EfficiencyLoader efficiencyLoader_
std::vector< NameTagelecIDSrcs_
edm::InputTag electronSrc_
bool embedGenMatch_
bool embedGsfElectronCore_
bool embedGsfTrack_
bool embedHighLevelSelection_
 embed high level selection variables?
bool embedPFCandidate_
bool embedSuperCluster_
bool embedTrack_
std::vector< edm::InputTaggenMatchSrc_
IsolationLabels isoDepositLabels_
IsolationLabels isolationValueLabels_
pat::helper::MultiIsolator isolator_
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
edm::InputTag pfElecSrc_
GreaterByPt< ElectronpTComparator_
edm::InputTag pvSrc_
pat::helper::KinResolutionsLoader resolutionLoader_
bool useParticleFlow_
 pflow specific
bool usePV_
pat::PATUserDataHelper
< pat::Electron
userDataHelper_
bool useUserData_

Detailed Description

Produces pat::Electron's.

The PATElectronProducer produces analysis-level pat::Electron's starting from a collection of objects of reco::GsfElectron.

Author:
Steven Lowette, James Lamb\
Version:
Id:
PATElectronProducer.h,v 1.24 2011/02/08 09:11:41 chamont Exp

Definition at line 52 of file PATElectronProducer.h.


Member Typedef Documentation

Definition at line 87 of file PATElectronProducer.h.

Definition at line 86 of file PATElectronProducer.h.

Definition at line 88 of file PATElectronProducer.h.

Definition at line 108 of file PATElectronProducer.h.

Definition at line 109 of file PATElectronProducer.h.

typedef std::vector< edm::Handle< edm::ValueMap<double> > > pat::PATElectronProducer::IsolationValueMaps [private]

Definition at line 89 of file PATElectronProducer.h.

typedef std::pair<std::string, edm::InputTag> pat::PATElectronProducer::NameTag [private]

Definition at line 118 of file PATElectronProducer.h.


Constructor & Destructor Documentation

PATElectronProducer::PATElectronProducer ( const edm::ParameterSet iConfig) [explicit]

Definition at line 44 of file PATElectronProducer.cc.

References addEfficiencies_, addElecID_, addGenMatch_, addResolutions_, beamLineSrc_, efficiencyLoader_, elecIDSrcs_, electronSrc_, embedGenMatch_, embedGsfElectronCore_, embedGsfTrack_, embedHighLevelSelection_, embedPFCandidate_, embedSuperCluster_, embedTrack_, edm::ParameterSet::existsAs(), genMatchSrc_, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), isoDepositLabels_, isolationValueLabels_, h::names, pfElecSrc_, pvSrc_, readIsolationLabels(), resolutionLoader_, useParticleFlow_, usePV_, userDataHelper_, and useUserData_.

                                                                        :
  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), false) ,
  useUserData_(iConfig.exists("userData"))
{

  // general configurables
  electronSrc_      = iConfig.getParameter<edm::InputTag>( "electronSource" );
  embedGsfElectronCore_    = iConfig.getParameter<bool>         ( "embedGsfElectronCore" );
  embedGsfTrack_    = iConfig.getParameter<bool>         ( "embedGsfTrack" );
  embedSuperCluster_= iConfig.getParameter<bool>         ( "embedSuperCluster" );
  embedTrack_       = iConfig.getParameter<bool>         ( "embedTrack" );

  // pflow specific
  pfElecSrc_           = iConfig.getParameter<edm::InputTag>( "pfElectronSource" );
  useParticleFlow_        = iConfig.getParameter<bool>( "useParticleFlow" );
  embedPFCandidate_   = iConfig.getParameter<bool>( "embedPFCandidate" );


  // MC matching configurables
  addGenMatch_      = iConfig.getParameter<bool>          ( "addGenMatch" );
  if (addGenMatch_) {
    embedGenMatch_ = iConfig.getParameter<bool>         ( "embedGenMatch" );
    if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
      genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
    } else {
      genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
    }
  }

  // resolution configurables
  addResolutions_   = iConfig.getParameter<bool>         ( "addResolutions" );
  if (addResolutions_) {
    resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
  }


  // electron ID configurables
  addElecID_        = iConfig.getParameter<bool>         ( "addElectronID" );
  if (addElecID_) {
    // it might be a single electron ID
    if (iConfig.existsAs<edm::InputTag>("electronIDSource")) {
      elecIDSrcs_.push_back(NameTag("", iConfig.getParameter<edm::InputTag>("electronIDSource")));
    }
    // or there might be many of them
    if (iConfig.existsAs<edm::ParameterSet>("electronIDSources")) {
      // please don't configure me twice
      if (!elecIDSrcs_.empty()) throw cms::Exception("Configuration") <<
                                  "PATElectronProducer: you can't specify both 'electronIDSource' and 'electronIDSources'\n";
      // read the different electron ID names
      edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("electronIDSources");
      std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
      for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
        elecIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
      }
    }
    // but in any case at least once
    if (elecIDSrcs_.empty()) throw cms::Exception("Configuration") <<
                               "PATElectronProducer: id addElectronID is true, you must specify either:\n" <<
                               "\tInputTag electronIDSource = <someTag>\n" << "or\n" <<
                               "\tPSet electronIDSources = { \n" <<
                               "\t\tInputTag <someName> = <someTag>   // as many as you want \n " <<
                               "\t}\n";
  }

  // construct resolution calculator

  //   // IsoDeposit configurables
  //   if (iConfig.exists("isoDeposits")) {
  //      edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
  //      if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(TrackerIso, depconf.getParameter<edm::InputTag>("tracker")));
  //      if (depconf.exists("ecal"))    isoDepositLabels_.push_back(std::make_pair(ECalIso, depconf.getParameter<edm::InputTag>("ecal")));
  //      if (depconf.exists("hcal"))    isoDepositLabels_.push_back(std::make_pair(HCalIso, depconf.getParameter<edm::InputTag>("hcal")));


  //      if (depconf.exists("user")) {
  //         std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
  //         std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
  //         int key = UserBaseIso;
  //         for ( ; it != ed; ++it, ++key) {
  //             isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
  //         }
  //      }
  //   }

  // read isoDeposit labels, for direct embedding
  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_);

  // read isolation value labels, for direct embedding
  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_);

  // Efficiency configurables
  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
  if (addEfficiencies_) {
    efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
  }

  // Check to see if the user wants to add user data
  if ( useUserData_ ) {
    userDataHelper_ = PATUserDataHelper<Electron>(iConfig.getParameter<edm::ParameterSet>("userData"));
  }

  // embed high level selection variables?
  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
  if ( embedHighLevelSelection_ ) {
    beamLineSrc_ = iConfig.getParameter<edm::InputTag>("beamLineSrc");
    usePV_ = iConfig.getParameter<bool>("usePV");
    pvSrc_ = iConfig.getParameter<edm::InputTag>("pvSrc");
  }


  // produces vector of muons
  produces<std::vector<Electron> >();

}
PATElectronProducer::~PATElectronProducer ( )

Definition at line 160 of file PATElectronProducer.cc.

                                          {
}

Member Function Documentation

void PATElectronProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions) [static]

Reimplemented from edm::EDProducer.

Definition at line 606 of file PATElectronProducer.cc.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addNode(), edm::ParameterSetDescription::addOptional(), pat::helper::KinResolutionsLoader::fillDescription(), edm::ParameterSetDescription::setAllowAnything(), and edm::ParameterSetDescription::setComment().

{
  edm::ParameterSetDescription iDesc;
  iDesc.setComment("PAT electron producer module");

  // input source
  iDesc.add<edm::InputTag>("electronSource", edm::InputTag("no default"))->setComment("input collection");

  // embedding
  iDesc.add<bool>("embedGsfElectronCore", true)->setComment("embed external gsf electron core");
  iDesc.add<bool>("embedGsfTrack", true)->setComment("embed external gsf track");
  iDesc.add<bool>("embedSuperCluster", true)->setComment("embed external super cluster");
  iDesc.add<bool>("embedTrack", false)->setComment("embed external track");

  // pf specific parameters
  iDesc.add<edm::InputTag>("pfElectronSource", edm::InputTag("pfElectrons"))->setComment("particle flow input collection");
  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");

  // MC matching configurables
  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
  std::vector<edm::InputTag> emptySourceVector;
  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
                 edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
                 )->setComment("input with MC match information");

  // electron ID configurables
  iDesc.add<bool>("addElectronID",true)->setComment("add electron ID variables");
  edm::ParameterSetDescription electronIDSourcesPSet;
  electronIDSourcesPSet.setAllowAnything();
  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("electronIDSource", edm::InputTag(), true) xor
                 edm::ParameterDescription<edm::ParameterSetDescription>("electronIDSources", electronIDSourcesPSet, true)
                 )->setComment("input with electron ID variables");


  // IsoDeposit configurables
  edm::ParameterSetDescription isoDepositsPSet;
  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
  iDesc.addOptional("isoDeposits", isoDepositsPSet);

  // isolation values configurables
  edm::ParameterSetDescription isolationValuesPSet;
  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
  isolationValuesPSet.addOptional<edm::InputTag>("pfAllParticles");
  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
  isolationValuesPSet.addOptional<std::vector<edm::InputTag> >("user");
  iDesc.addOptional("isolationValues", isolationValuesPSet);

  // Efficiency configurables
  edm::ParameterSetDescription efficienciesPSet;
  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
  iDesc.add("efficiencies", efficienciesPSet);
  iDesc.add<bool>("addEfficiencies", false);

  // Check to see if the user wants to add user data
  edm::ParameterSetDescription userDataPSet;
  PATUserDataHelper<Electron>::fillDescription(userDataPSet);
  iDesc.addOptional("userData", userDataPSet);

  // electron shapes
  iDesc.add<bool>("addElectronShapes", true);
  iDesc.add<edm::InputTag>("reducedBarrelRecHitCollection", edm::InputTag("reducedEcalRecHitsEB"));
  iDesc.add<edm::InputTag>("reducedEndcapRecHitCollection", edm::InputTag("reducedEcalRecHitsEE"));

  edm::ParameterSetDescription isolationPSet;
  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
  iDesc.add("userIsolation", isolationPSet);

  // Resolution configurables
  pat::helper::KinResolutionsLoader::fillDescription(iDesc);

  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
  edm::ParameterSetDescription highLevelPSet;
  highLevelPSet.setAllowAnything();
  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
                 )->setComment("input with high level selection");
  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("pvSrc", edm::InputTag(), true)
                 )->setComment("input with high level selection");
  iDesc.addNode( edm::ParameterDescription<bool>("usePV", bool(), true)
                 )->setComment("input with high level selection, use primary vertex (true) or beam line (false)");

  descriptions.add("PATElectronProducer", iDesc);

}
void PATElectronProducer::fillElectron ( Electron aElectron,
const ElectronBaseRef electronRef,
const reco::CandidateBaseRef baseRef,
const GenAssociations genMatches,
const IsoDepositMaps deposits,
const IsolationValueMaps isolationValues 
) const [private]

common electron filling, for both the standard and PF2PAT case

Definition at line 445 of file PATElectronProducer.cc.

References addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), efficiencyLoader_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::Electron::embedGsfElectronCore(), embedGsfElectronCore_, pat::Electron::embedGsfTrack(), embedGsfTrack_, pat::Electron::embedSuperCluster(), embedSuperCluster_, pat::Electron::embedTrack(), embedTrack_, pat::helper::KinResolutionsLoader::enabled(), pat::helper::EfficiencyLoader::enabled(), first, i, edm::Ref< C, T, F >::isNull(), isoDepositLabels_, isolationValueLabels_, j, n, pat::Electron::pfCandidateRef(), resolutionLoader_, pat::helper::EfficiencyLoader::setEfficiencies(), pat::Lepton< LeptonType >::setIsoDeposit(), pat::Lepton< LeptonType >::setIsolation(), pat::helper::KinResolutionsLoader::setResolutions(), LaserTracksInput_cfi::source, and useParticleFlow_.

Referenced by produce().

                                               {

  //COLIN: might want to use the PFCandidate 4-mom. Which one is in use now?
  //   if (useParticleFlow_)
  //     aMuon.setP4( aMuon.pfCandidateRef()->p4() );

  //COLIN:
  //In the embedding case, the reference cannot be used to look into a value map.
  //therefore, one has to had the PFCandidateRef to this function, which becomes a bit
  //too much specific.

  // in fact, this function needs a baseref or ptr for genmatch
  // and a baseref or ptr for isodeposits and isolationvalues.
  // baseref is not needed
  // the ptrForIsolation and ptrForMatching should be defined upstream.

  // is the concrete elecRef needed for the efficiency loader? what is this loader?
  // how can we make it compatible with the particle flow electrons?

  if (embedGsfElectronCore_) anElectron.embedGsfElectronCore();
  if (embedGsfTrack_) anElectron.embedGsfTrack();
  if (embedSuperCluster_) anElectron.embedSuperCluster();
  if (embedTrack_) anElectron.embedTrack();

  // store the match to the generated final state muons
  if (addGenMatch_) {
    for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
      if(useParticleFlow_) {
        reco::GenParticleRef genElectron = (*genMatches[i])[anElectron.pfCandidateRef()];
        anElectron.addGenParticleRef(genElectron);
      }
      else {
        reco::GenParticleRef genElectron = (*genMatches[i])[elecRef];
        anElectron.addGenParticleRef(genElectron);
      }
    }
    if (embedGenMatch_) anElectron.embedGenParticle();
  }

  if (efficiencyLoader_.enabled()) {
    efficiencyLoader_.setEfficiencies( anElectron, elecRef );
  }

  if (resolutionLoader_.enabled()) {
    resolutionLoader_.setResolutions(anElectron);
  }

  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
    if(useParticleFlow_) {

      reco::PFCandidateRef pfcandref =  anElectron.pfCandidateRef();
      assert(!pfcandref.isNull());
      reco::CandidatePtr source = pfcandref->sourceCandidatePtr(0);
      anElectron.setIsoDeposit(isoDepositLabels_[j].first,
                          (*deposits[j])[source]);
    }
    else
      anElectron.setIsoDeposit(isoDepositLabels_[j].first,
                          (*deposits[j])[elecRef]);
  }

  for (size_t j = 0; j<isolationValues.size(); ++j) {
    if(useParticleFlow_) {
      reco::CandidatePtr source = anElectron.pfCandidateRef()->sourceCandidatePtr(0);
      anElectron.setIsolation(isolationValueLabels_[j].first,
                         (*isolationValues[j])[source]);
    }
    else
      anElectron.setIsolation(isolationValueLabels_[j].first,
                         (*isolationValues[j])[elecRef]);
  }



}
void PATElectronProducer::fillElectron2 ( Electron anElectron,
const reco::CandidatePtr candPtrForIsolation,
const reco::CandidatePtr candPtrForGenMatch,
const reco::CandidatePtr candPtrForLoader,
const GenAssociations genMatches,
const IsoDepositMaps deposits,
const IsolationValueMaps isolationValues 
) const [private]

Definition at line 527 of file PATElectronProducer.cc.

References addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), edm::contains(), pat::EcalIso, efficiencyLoader_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::Electron::embedGsfElectronCore(), embedGsfElectronCore_, pat::Electron::embedGsfTrack(), embedGsfTrack_, pat::Electron::embedSuperCluster(), embedSuperCluster_, pat::Electron::embedTrack(), embedTrack_, pat::helper::KinResolutionsLoader::enabled(), pat::helper::EfficiencyLoader::enabled(), first, pat::HcalIso, i, edm::Ptr< T >::id(), isoDepositLabels_, isolationValueLabels_, j, n, reco::LeafCandidate::p4(), pat::Electron::pfCandidateRef(), resolutionLoader_, pat::Electron::setEcalDrivenMomentum(), pat::helper::EfficiencyLoader::setEfficiencies(), pat::Lepton< LeptonType >::setIsoDeposit(), pat::Lepton< LeptonType >::setIsolation(), reco::GsfElectron::setMva(), reco::LeafCandidate::setP4(), pat::helper::KinResolutionsLoader::setResolutions(), and pat::TrackIso.

Referenced by produce().

                                                                                          {

  //COLIN/Florian: use the PFCandidate 4-mom.
  anElectron.setEcalDrivenMomentum(anElectron.p4()) ;
  anElectron.setP4( anElectron.pfCandidateRef()->p4() );
  // Safer to take the mva from the PFCandidate in case of ambiguosity
  anElectron.setMva( anElectron.pfCandidateRef()->mva_e_pi() ); 

  // is the concrete elecRef needed for the efficiency loader? what is this loader?
  // how can we make it compatible with the particle flow electrons?

  if (embedGsfElectronCore_) anElectron.embedGsfElectronCore();
  if (embedGsfTrack_) anElectron.embedGsfTrack();
  if (embedSuperCluster_) anElectron.embedSuperCluster();
  if (embedTrack_) anElectron.embedTrack();

  // store the match to the generated final state muons

  if (addGenMatch_) {
    for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
      reco::GenParticleRef genElectron = (*genMatches[i])[candPtrForGenMatch];
      anElectron.addGenParticleRef(genElectron);
    }
    if (embedGenMatch_) anElectron.embedGenParticle();
  }

  //COLIN what's this? does it have to be GsfElectron specific?
  if (efficiencyLoader_.enabled()) {
    efficiencyLoader_.setEfficiencies( anElectron, candPtrForLoader );
  }

  if (resolutionLoader_.enabled()) {
    resolutionLoader_.setResolutions(anElectron);
  }

  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
    if( isoDepositLabels_[j].first==pat::TrackIso ||
        isoDepositLabels_[j].first==pat::EcalIso ||
        isoDepositLabels_[j].first==pat::HcalIso ) {

      anElectron.setIsoDeposit(isoDepositLabels_[j].first,
                               (*deposits[j])[candPtrForGenMatch]);
    }
    else if (deposits[j]->contains(candPtrForIsolation.id())) {
      anElectron.setIsoDeposit(isoDepositLabels_[j].first,
                               (*deposits[j])[candPtrForIsolation]);
    }
    else {
      anElectron.setIsoDeposit(isoDepositLabels_[j].first,
                               (*deposits[j])[candPtrForIsolation->sourceCandidatePtr(0)]);
    }
  }

  for (size_t j = 0; j<isolationValues.size(); ++j) {
    if( isolationValueLabels_[j].first==pat::TrackIso ||
        isolationValueLabels_[j].first==pat::EcalIso ||
        isolationValueLabels_[j].first==pat::HcalIso ) {
      anElectron.setIsolation(isolationValueLabels_[j].first,
                              (*isolationValues[j])[candPtrForGenMatch]);
    }
    else if (isolationValues[j]->contains(candPtrForIsolation.id())) {
      anElectron.setIsolation(isolationValueLabels_[j].first,
                              (*isolationValues[j])[candPtrForIsolation]);
    }
    else {
      anElectron.setIsolation(isolationValueLabels_[j].first,
                              (*isolationValues[j])[candPtrForIsolation->sourceCandidatePtr(0)]);
    }
  }
}
void PATElectronProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 164 of file PATElectronProducer.cc.

References IPTools::absoluteTransverseImpactParameter(), pat::PATUserDataHelper< ObjectType >::add(), addElecID_, addGenMatch_, beamLineSrc_, ExpressReco_HICollisions_FallBack::beamSpot, pat::helper::MultiIsolator::beginEvent(), ExpressReco_HICollisions_FallBack::deposits, efficiencyLoader_, elecIDSrcs_, electronSrc_, embedGenMatch_, embedHighLevelSelection_, pat::Electron::embedPFCandidate(), embedPFCandidate_, pat::helper::KinResolutionsLoader::enabled(), pat::helper::MultiIsolator::enabled(), pat::helper::EfficiencyLoader::enabled(), pat::helper::MultiIsolator::endEvent(), pat::helper::MultiIsolator::fill(), fillElectron(), fillElectron2(), first, genMatchSrc_, edm::EventSetup::get(), edm::Event::getByLabel(), i, getHLTprescales::index, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), isoDepositLabels_, isolationValueLabels_, isolator_, isolatorTmpStorage_, edm::EventBase::isRealData(), edm::HandleBase::isValid(), j, reco::Matched, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), electronProducer_cfi::patElectrons, pfElecSrc_, pTComparator_, edm::Event::put(), pvSrc_, resolutionLoader_, query::result, edm::second(), pat::Electron::setDB(), pat::Electron::setElectronIDs(), pat::Lepton< LeptonType >::setIsoDeposit(), pat::Lepton< LeptonType >::setIsolation(), pat::Electron::setPFCandidateRef(), python::multivaluedict::sort(), ExpressReco_HICollisions_FallBack::track, useParticleFlow_, usePV_, userDataHelper_, useUserData_, reco::BeamSpot::x0(), reco::BeamSpot::y0(), and reco::BeamSpot::z0().

                                                                                 {

  // Get the collection of electrons from the event
  edm::Handle<edm::View<reco::GsfElectron> > electrons;
  iEvent.getByLabel(electronSrc_, electrons);

  if (iEvent.isRealData()){
       addGenMatch_ = false;
       embedGenMatch_ = false;
   }

  // Get the ESHandle for the transient track builder, if needed for
  // high level selection embedding
  edm::ESHandle<TransientTrackBuilder> trackBuilder;

  if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);

  if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);

  IsoDepositMaps deposits(isoDepositLabels_.size());
  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
    iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]);
  }

  IsolationValueMaps isolationValues(isolationValueLabels_.size());
  for (size_t j = 0; j<isolationValueLabels_.size(); ++j) {
    iEvent.getByLabel(isolationValueLabels_[j].second, isolationValues[j]);
  }

  // prepare the MC matching
  GenAssociations  genMatches(genMatchSrc_.size());
  if (addGenMatch_) {
    for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
      iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
    }
  }

  // prepare ID extraction
  std::vector<edm::Handle<edm::ValueMap<float> > > idhandles;
  std::vector<pat::Electron::IdPair>               ids;
  if (addElecID_) {
    idhandles.resize(elecIDSrcs_.size());
    ids.resize(elecIDSrcs_.size());
    for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
      iEvent.getByLabel(elecIDSrcs_[i].second, idhandles[i]);
      ids[i].first = elecIDSrcs_[i].first;
    }
  }


  // prepare the high level selection:
  // needs beamline
  reco::TrackBase::Point beamPoint(0,0,0);
  reco::Vertex primaryVertex;
  if ( embedHighLevelSelection_ ) {
    // Get the beamspot
    reco::BeamSpot beamSpot;
    edm::Handle<reco::BeamSpot> beamSpotHandle;
    iEvent.getByLabel(beamLineSrc_, beamSpotHandle);


    // Get the primary vertex
    edm::Handle< std::vector<reco::Vertex> > pvHandle;
    iEvent.getByLabel( pvSrc_, pvHandle );

    if ( ! usePV_ ) {
      if ( beamSpotHandle.isValid() ){
        beamSpot = *beamSpotHandle;
      } else{
        edm::LogError("DataNotAvailable")
          << "No beam spot available from EventSetup, not adding high level selection \n";
      }

      double x0 = beamSpot.x0();
      double y0 = beamSpot.y0();
      double z0 = beamSpot.z0();

      beamPoint = reco::TrackBase::Point ( x0, y0, z0 );
    } else {
      if ( pvHandle.isValid() ) {
        primaryVertex = pvHandle->at(0);
      } else {
        edm::LogError("DataNotAvailable")
          << "No primary vertex available from EventSetup, not adding high level selection \n";
      }

      // This is needed by the IPTools methods from the tracking group
      iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
    }
  }

  std::vector<Electron> * patElectrons = new std::vector<Electron>();

  if( useParticleFlow_ ) {
    edm::Handle< reco::PFCandidateCollection >  pfElectrons;
    iEvent.getByLabel(pfElecSrc_, pfElectrons);
    unsigned index=0;

    for( reco::PFCandidateConstIterator i = pfElectrons->begin();
         i != pfElectrons->end(); ++i, ++index) {

      reco::PFCandidateRef pfRef(pfElectrons, index);
      reco::PFCandidatePtr ptrToPFElectron(pfElectrons,index);
//       reco::CandidateBaseRef pfBaseRef( pfRef );

      reco::GsfTrackRef PfTk= i->gsfTrackRef();

      bool Matched=false;
      bool MatchedToAmbiguousGsfTrack=false;
      for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end(); ++itElectron) {
        unsigned int idx = itElectron - electrons->begin();
        if (Matched || MatchedToAmbiguousGsfTrack) continue;

        reco::GsfTrackRef EgTk= itElectron->gsfTrack();

        if (itElectron->gsfTrack()==i->gsfTrackRef()){
          Matched=true;
        }
        else {
          for( reco::GsfTrackRefVector::const_iterator it = itElectron->ambiguousGsfTracksBegin() ;
               it!=itElectron->ambiguousGsfTracksEnd(); it++ ){
            MatchedToAmbiguousGsfTrack |= (bool)(i->gsfTrackRef()==(*it));
          }
        }

        if (Matched || MatchedToAmbiguousGsfTrack){

          // ptr needed for finding the matched gen particle
          reco::CandidatePtr ptrToGsfElectron(electrons,idx);

          // ref to base needed for the construction of the pat object
          const edm::RefToBase<reco::GsfElectron>& elecsRef = electrons->refAt(idx);
          Electron anElectron(elecsRef);
          anElectron.setPFCandidateRef( pfRef  );

          if( embedPFCandidate_ ) anElectron.embedPFCandidate();

          if ( useUserData_ ) {
            userDataHelper_.add( anElectron, iEvent, iSetup );
          }


          // embed high level selection
          if ( embedHighLevelSelection_ ) {
            // get the global track
            reco::GsfTrackRef track = PfTk;

            // Make sure the collection it points to is there
            if ( track.isNonnull() && track.isAvailable() ) {

              if ( !usePV_ ) {
                double corr_d0 = track->dxy( beamPoint );
                anElectron.setDB( corr_d0, -1.0 );
              } else {
                reco::TransientTrack tt = trackBuilder->build(track);
                std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
                double d0_corr = result.second.value();
                double d0_err = result.second.error();
                anElectron.setDB( d0_corr, d0_err );
              }
            }
          }

          //Electron Id

          if (addElecID_) {
            //STANDARD EL ID
            for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
              ids[i].second = (*idhandles[i])[elecsRef];
            }
            //SPECIFIC PF ID
            ids.push_back(std::make_pair("pf_evspi",pfRef->mva_e_pi()));
            ids.push_back(std::make_pair("pf_evsmu",pfRef->mva_e_mu()));
            anElectron.setElectronIDs(ids);
          }

//        fillElectron(anElectron,elecsRef,pfBaseRef,
//                     genMatches, deposits, isolationValues);

          //COLIN small warning !
          // we are currently choosing to take the 4-momentum of the PFCandidate;
          // the momentum of the GsfElectron is saved though
          // we must therefore match the GsfElectron.
          // because of this, we should not change the source of the electron matcher
          // to the collection of PFElectrons in the python configuration
          // I don't know what to do with the efficiencyLoader, since I don't know
          // what this class is for. 
          fillElectron2( anElectron, 
                         ptrToPFElectron, 
                         ptrToGsfElectron, 
                         ptrToGsfElectron, 
                         genMatches, deposits, isolationValues );

          //COLIN need to use fillElectron2 in the non-pflow case as well, and to test it.

          patElectrons->push_back(anElectron);
        }
      }
      //if( !Matched && !MatchedToAmbiguousGsfTrack) std::cout << "!!!!A pf electron could not be matched to a gsf!!!!"  << std::endl;
    }
  }

  else{
    for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end(); ++itElectron) {
      // construct the Electron from the ref -> save ref to original object
      unsigned int idx = itElectron - electrons->begin();
      edm::RefToBase<reco::GsfElectron> elecsRef = electrons->refAt(idx);
      reco::CandidateBaseRef elecBaseRef(elecsRef);
      Electron anElectron(elecsRef);

      // add resolution info

      // Isolation
      if (isolator_.enabled()) {
        isolator_.fill(*electrons, idx, isolatorTmpStorage_);
        typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
        // better to loop backwards, so the vector is resized less times
        for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
          anElectron.setIsolation(it->first, it->second);
        }
      }

      for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
        anElectron.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[elecsRef]);
      }

      // add electron ID info
      if (addElecID_) {
        for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
          ids[i].second = (*idhandles[i])[elecsRef];
        }
        anElectron.setElectronIDs(ids);
      }


      if ( useUserData_ ) {
        userDataHelper_.add( anElectron, iEvent, iSetup );
      }


      // embed high level selection
      if ( embedHighLevelSelection_ ) {
        // get the global track
        reco::GsfTrackRef track = itElectron->gsfTrack();

        // Make sure the collection it points to is there
        if ( track.isNonnull() && track.isAvailable() ) {

          if ( !usePV_ ) {
            double corr_d0 = track->dxy( beamPoint );
            anElectron.setDB( corr_d0, -1.0 );
          } else {
            reco::TransientTrack tt = trackBuilder->build(track);
            std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
            double d0_corr = result.second.value();
            double d0_err = result.second.error();
            anElectron.setDB( d0_corr, d0_err );
          }
        }
      }

      // add sel to selected
      fillElectron( anElectron, elecsRef,elecBaseRef,
                    genMatches, deposits, isolationValues);
      patElectrons->push_back(anElectron);
    }
  }

  // sort electrons in pt
  std::sort(patElectrons->begin(), patElectrons->end(), pTComparator_);

  // add the electrons to the event output
  std::auto_ptr<std::vector<Electron> > ptr(patElectrons);
  iEvent.put(ptr);

  // clean up
  if (isolator_.enabled()) isolator_.endEvent();

}
void PATElectronProducer::readIsolationLabels ( const edm::ParameterSet iConfig,
const char *  psetName,
IsolationLabels labels 
) [private]

fill the labels vector from the contents of the parameter set, for the isodeposit or isolation values embedding

Definition at line 705 of file PATElectronProducer.cc.

References pat::EcalIso, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), pat::HcalIso, combine::key, pat::PfAllParticleIso, pat::PfChargedHadronIso, pat::PfGammaIso, pat::PfNeutralHadronIso, pat::TrackIso, and pat::UserBaseIso.

Referenced by PATElectronProducer().

                                                                        {

  labels.clear();

  if (iConfig.exists( psetName )) {
    edm::ParameterSet depconf
      = iConfig.getParameter<edm::ParameterSet>(psetName);

    if (depconf.exists("tracker")) labels.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
    if (depconf.exists("ecal"))    labels.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
    if (depconf.exists("hcal"))    labels.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
    if (depconf.exists("pfAllParticles"))  {
      labels.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
    }
    if (depconf.exists("pfChargedHadrons"))  {
      labels.push_back(std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons")));
    }
    if (depconf.exists("pfNeutralHadrons"))  {
      labels.push_back(std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons")));
    }
    if (depconf.exists("pfPhotons")) {
      labels.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons")));
    }
    if (depconf.exists("user")) {
      std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
      std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
      int key = UserBaseIso;
      for ( ; it != ed; ++it, ++key) {
        labels.push_back(std::make_pair(IsolationKeys(key), *it));
      }
    }
  }


}

Member Data Documentation

Definition at line 129 of file PATElectronProducer.h.

Referenced by PATElectronProducer().

Definition at line 117 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 71 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), PATElectronProducer(), and produce().

Definition at line 132 of file PATElectronProducer.h.

Referenced by PATElectronProducer().

Definition at line 82 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 130 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), PATElectronProducer(), and produce().

Definition at line 119 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 66 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 72 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), PATElectronProducer(), and produce().

Definition at line 67 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), and PATElectronProducer().

Definition at line 68 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), and PATElectronProducer().

embed high level selection variables?

Definition at line 81 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 78 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 69 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), and PATElectronProducer().

Definition at line 70 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), and PATElectronProducer().

Definition at line 73 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 126 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), PATElectronProducer(), and produce().

Definition at line 127 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), PATElectronProducer(), and produce().

Definition at line 124 of file PATElectronProducer.h.

Referenced by produce().

Definition at line 125 of file PATElectronProducer.h.

Referenced by produce().

Definition at line 77 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 122 of file PATElectronProducer.h.

Referenced by produce().

Definition at line 84 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 133 of file PATElectronProducer.h.

Referenced by fillElectron(), fillElectron2(), PATElectronProducer(), and produce().

pflow specific

Definition at line 76 of file PATElectronProducer.h.

Referenced by fillElectron(), PATElectronProducer(), and produce().

Definition at line 83 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 136 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().

Definition at line 135 of file PATElectronProducer.h.

Referenced by PATElectronProducer(), and produce().