CMS 3D CMS Logo

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

pat::PATMuonProducer Class Reference

class definition More...

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

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

List of all members.

Public Member Functions

 PATMuonProducer (const edm::ParameterSet &iConfig)
 default constructir
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 everything that needs to be done during the event loop
 ~PATMuonProducer ()
 default destructur

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 description of config file parameters

Private Types

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 edm::RefToBase
< reco::Muon
MuonBaseRef
 typedefs for convenience

Private Member Functions

void embedHighLevel (pat::Muon &aMuon, reco::TrackRef track, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
void fillMuon (Muon &aMuon, const MuonBaseRef &muonRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
 common muon filling, for both the standard and PF2PAT case
void readIsolationLabels (const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels)

Private Attributes

bool addEfficiencies_
 add efficiencies to the muon (this will be data members of th muon even w/o embedding)
bool addGenMatch_
 add generator match information
bool addResolutions_
 add resolutions to the muon (this will be data members of th muon even w/o embedding)
edm::InputTag beamLineSrc_
 input source of the primary vertex/beamspot
edm::InputTag caloMETMuonCorrs_
 source of caloMET muon corrections
pat::helper::EfficiencyLoader efficiencyLoader_
 helper class to add efficiencies to the muon
bool embedBestTrack_
 embed the track from best muon measurement
bool embedCaloMETMuonCorrs_
 embed muon MET correction info for caloMET into the muon
bool embedCombinedMuon_
 embed track of the combined fit into the muon
bool embedDytMuon_
 embed track from DYT muon fit into the muon
bool embedGenMatch_
 embed the gen match information into the muon
bool embedHighLevelSelection_
 embed high level selection variables
bool embedPFCandidate_
 embed pfCandidates into the muon
bool embedPickyMuon_
 embed track from picky muon fit into the muon
bool embedStandAloneMuon_
 embed track from muon system into the muon
bool embedTcMETMuonCorrs_
 embed muon MET correction info for tcMET into the muon
bool embedTpfmsMuon_
 embed track from tpfms muon fit into the muon
bool embedTrack_
 embed the track from inner tracker into the muon
std::vector< edm::InputTaggenMatchSrc_
 input tags for generator match information
IsolationLabels isoDepositLabels_
 input source for isoDeposits
IsolationLabels isolationValueLabels_
 input source isolation value maps
pat::helper::MultiIsolator isolator_
 helper class to add userdefined isolation values to the muon
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
 isolation value pair for temporary storage before being folded into the muon
edm::InputTag muonSrc_
 input source
edm::InputTag pfMuonSrc_
 input source pfCandidates that will be to be transformed into pat::Muons, when using PF2PAT
GreaterByPt< MuonpTComparator_
edm::InputTag pvSrc_
 input source of the primary vertex
pat::helper::KinResolutionsLoader resolutionLoader_
 helper class to add resolutions to the muon
edm::InputTag tcMETMuonCorrs_
 source of tcMET muon corrections
bool useParticleFlow_
 switch to use particle flow (PF2PAT) or not
bool usePV_
 use the primary vertex or the beamspot
pat::PATUserDataHelper< pat::MuonuserDataHelper_
 helper class to add userData to the muon
bool useUserData_
 add user data to the muon (this will be data members of th muon even w/o embedding)

Detailed Description

class definition

Produces pat::Muon's.

The PATMuonProducer produces analysis-level pat::Muon's starting from a collection of objects of reco::Muon.

Author:
Steven Lowette, Roger Wolf
Version:
Id:
PATMuonProducer.h,v 1.29 2012/08/22 15:02:52 bellan Exp

Definition at line 43 of file PATMuonProducer.h.


Member Typedef Documentation

Definition at line 58 of file PATMuonProducer.h.

Definition at line 59 of file PATMuonProducer.h.

Definition at line 61 of file PATMuonProducer.h.

typedef std::vector<IsolationLabel> pat::PATMuonProducer::IsolationLabels [private]

Definition at line 62 of file PATMuonProducer.h.

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

Definition at line 60 of file PATMuonProducer.h.

typedefs for convenience

Definition at line 57 of file PATMuonProducer.h.


Constructor & Destructor Documentation

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

default constructir

Definition at line 47 of file PATMuonProducer.cc.

References addEfficiencies_, addGenMatch_, addResolutions_, beamLineSrc_, caloMETMuonCorrs_, efficiencyLoader_, embedBestTrack_, embedCaloMETMuonCorrs_, embedCombinedMuon_, embedDytMuon_, embedGenMatch_, embedHighLevelSelection_, embedPFCandidate_, embedPickyMuon_, embedStandAloneMuon_, embedTcMETMuonCorrs_, embedTpfmsMuon_, embedTrack_, edm::ParameterSet::existsAs(), genMatchSrc_, edm::ParameterSet::getParameter(), isoDepositLabels_, isolationValueLabels_, muonSrc_, pfMuonSrc_, pvSrc_, readIsolationLabels(), resolutionLoader_, tcMETMuonCorrs_, useParticleFlow_, usePV_, userDataHelper_, and useUserData_.

                                                                : useUserData_(iConfig.exists("userData")), 
  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), false)
{
  // input source
  muonSrc_ = iConfig.getParameter<edm::InputTag>( "muonSource" );
  // embedding of tracks
  embedBestTrack_ = iConfig.getParameter<bool>( "embedMuonBestTrack" );
  embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
  embedCombinedMuon_ = iConfig.getParameter<bool>( "embedCombinedMuon"   );
  embedStandAloneMuon_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
  // embedding of muon MET correction information
  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs" );
  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs"   );
  caloMETMuonCorrs_ = iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs" );
  tcMETMuonCorrs_ = iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs"   );
  // pflow specific configurables
  useParticleFlow_ = iConfig.getParameter<bool>( "useParticleFlow" );
  embedPFCandidate_ = iConfig.getParameter<bool>( "embedPFCandidate" );
  pfMuonSrc_ = iConfig.getParameter<edm::InputTag>( "pfMuonSource" );
  // embedding of tracks from TeV refit
  embedPickyMuon_ = iConfig.getParameter<bool>( "embedPickyMuon" );
  embedTpfmsMuon_ = iConfig.getParameter<bool>( "embedTpfmsMuon" );
  embedDytMuon_ = iConfig.getParameter<bool>( "embedDytMuon" );
  // Monte Carlo matching
  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" );
    }
  }
  // efficiencies
  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
  if(addEfficiencies_){
    efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
  }
  // resolutions
  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
  if (addResolutions_) {
    resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
  }
  // read isoDeposit labels, for direct embedding
  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_);
  // read isolation value labels, for direct embedding
  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_);
  // check to see if the user wants to add user data
  if( useUserData_ ){
    userDataHelper_ = PATUserDataHelper<Muon>(iConfig.getParameter<edm::ParameterSet>("userData"));
  }
  // embed high level selection variables
  usePV_ = true;
  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<Muon> >();
}
PATMuonProducer::~PATMuonProducer ( )

default destructur

Definition at line 111 of file PATMuonProducer.cc.

{
}

Member Function Documentation

void PATMuonProducer::embedHighLevel ( pat::Muon aMuon,
reco::TrackRef  track,
reco::TransientTrack tt,
reco::Vertex primaryVertex,
bool  primaryVertexIsValid,
reco::BeamSpot beamspot,
bool  beamspotIsValid 
) [private]

Definition at line 579 of file PATMuonProducer.cc.

References pat::Muon::BS2D, pat::Muon::BS3D, reco::BeamSpot::position(), pat::Muon::PV2D, pat::Muon::PV3D, query::result, reco::BeamSpot::rotatedCovariance3D(), pat::Muon::setDB(), IPTools::signedImpactParameter3D(), and IPTools::signedTransverseImpactParameter().

Referenced by produce().

{
  // Correct to PV

  // PV2D
  std::pair<bool,Measurement1D> result =
    IPTools::signedTransverseImpactParameter(tt,
                                             GlobalVector(track->px(),
                                                          track->py(),
                                                          track->pz()),
                                             primaryVertex); 
  double d0_corr = result.second.value();
  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV2D);


  // PV3D
  result =
    IPTools::signedImpactParameter3D(tt,
                                     GlobalVector(track->px(),
                                                  track->py(),
                                                  track->pz()),
                                     primaryVertex);
  d0_corr = result.second.value();
  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV3D);
  

  // Correct to beam spot
  // make a fake vertex out of beam spot
  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
  
  // BS2D
  result =
    IPTools::signedTransverseImpactParameter(tt,
                                             GlobalVector(track->px(),
                                                          track->py(),
                                                          track->pz()),
                                             vBeamspot);
  d0_corr = result.second.value();
  d0_err = beamspotIsValid ? result.second.error() : -1.0;
  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS2D);
  
    // BS3D
  result =
    IPTools::signedImpactParameter3D(tt,
                                     GlobalVector(track->px(),
                                                  track->py(),
                                                    track->pz()),
                                     vBeamspot);
  d0_corr = result.second.value();
  d0_err = beamspotIsValid ? result.second.error() : -1.0;
  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS3D);
}
void PATMuonProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions) [static]

description of config file parameters

Reimplemented from edm::EDProducer.

Definition at line 442 of file PATMuonProducer.cc.

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

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

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

  // embedding
  iDesc.add<bool>("embedMuonBestTrack", true)->setComment("embed muon best track");
  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky track");
  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms track");
  iDesc.add<bool>("embedDytMuon", false)->setComment("embed external dyt track ");

  // embedding of MET muon corrections
  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer"  , "muCorrData"))->setComment("source of MET muon corrections for caloMET");
  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer"  , "muCorrData"))->setComment("source of MET muon corrections for tcMET");

  // pf specific parameters
  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->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");

  pat::helper::KinResolutionsLoader::fillDescription(iDesc);

  // IsoDeposit configurables
  edm::ParameterSetDescription isoDepositsPSet;
  isoDepositsPSet.addOptional<edm::InputTag>("tracker"); 
  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
  isoDepositsPSet.addOptional<edm::InputTag>("particle");
  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
  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>("particle");
  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
  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<Muon>::fillDescription(userDataPSet);
  iDesc.addOptional("userData", userDataPSet);

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

  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("PATMuonProducer", iDesc);
}
void PATMuonProducer::fillMuon ( Muon aMuon,
const MuonBaseRef muonRef,
const reco::CandidateBaseRef baseRef,
const GenAssociations genMatches,
const IsoDepositMaps deposits,
const IsolationValueMaps isolationValues 
) const [private]

common muon filling, for both the standard and PF2PAT case

Definition at line 368 of file PATMuonProducer.cc.

References addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), edm::contains(), reco::Muon::DYT, efficiencyLoader_, embedBestTrack_, pat::Muon::embedCombinedMuon(), embedCombinedMuon_, pat::Muon::embedDytMuon(), embedDytMuon_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::Muon::embedMuonBestTrack(), pat::Muon::embedPickyMuon(), embedPickyMuon_, pat::Muon::embedStandAloneMuon(), embedStandAloneMuon_, pat::Muon::embedTpfmsMuon(), embedTpfmsMuon_, pat::Muon::embedTrack(), embedTrack_, pat::helper::KinResolutionsLoader::enabled(), pat::helper::EfficiencyLoader::enabled(), first, i, edm::RefToBase< T >::id(), reco::Muon::isAValidMuonTrack(), reco::Muon::isGlobalMuon(), isoDepositLabels_, isolationValueLabels_, j, n, pat::Muon::pfCandidateRef(), reco::Muon::Picky, resolutionLoader_, pat::helper::EfficiencyLoader::setEfficiencies(), pat::Lepton< LeptonType >::setIsoDeposit(), pat::Lepton< LeptonType >::setIsolation(), reco::LeafCandidate::setP4(), pat::helper::KinResolutionsLoader::setResolutions(), LaserTracksInput_cfi::source, reco::Muon::TPFMS, and useParticleFlow_.

Referenced by produce().

{
  // in the particle flow algorithm, 
  // the muon momentum is recomputed. 
  // the new value is stored as the momentum of the 
  // resulting PFCandidate of type Muon, and choosen 
  // as the pat::Muon momentum
  if (useParticleFlow_) 
    aMuon.setP4( aMuon.pfCandidateRef()->p4() );
  if (embedBestTrack_)      aMuon.embedMuonBestTrack();
  if (embedTrack_)          aMuon.embedTrack();
  if (embedStandAloneMuon_) aMuon.embedStandAloneMuon();
  if (embedCombinedMuon_)   aMuon.embedCombinedMuon();

  // embed the TeV refit track refs (only available for globalMuons)
  if (aMuon.isGlobalMuon()) {
    if (embedPickyMuon_ && aMuon.isAValidMuonTrack(reco::Muon::Picky))
      aMuon.embedPickyMuon();
    if (embedTpfmsMuon_ && aMuon.isAValidMuonTrack(reco::Muon::TPFMS))
      aMuon.embedTpfmsMuon();
    if (embedDytMuon_ && aMuon.isAValidMuonTrack(reco::Muon::DYT))
      aMuon.embedDytMuon();
  }

  // store the match to the generated final state muons
  if (addGenMatch_) {
    for(size_t i = 0, n = genMatches.size(); i < n; ++i) {      
      reco::GenParticleRef genMuon = (*genMatches[i])[baseRef];
      aMuon.addGenParticleRef(genMuon);
    }
    if (embedGenMatch_) aMuon.embedGenParticle();
  }
  if (efficiencyLoader_.enabled()) {
    efficiencyLoader_.setEfficiencies( aMuon, muonRef );
  }

  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
    if(useParticleFlow_) {
      if (deposits[j]->contains(baseRef.id())) {
        aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
      } else if (deposits[j]->contains(muonRef.id())){
        aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
      } else {  
        reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0); 
        aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
      }
    }
    else{
      aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
    }
  }
  
  for (size_t j = 0; j<isolationValues.size(); ++j) {
    if(useParticleFlow_) {
      if (isolationValues[j]->contains(baseRef.id())) {
        aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
      } else if (isolationValues[j]->contains(muonRef.id())) {
        aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);     
      } else {
        reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);      
        aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
      }
    }
    else{
      aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
    }
  }

  if (resolutionLoader_.enabled()) {
    resolutionLoader_.setResolutions(aMuon);
  }
}
void PATMuonProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

everything that needs to be done during the event loop

Implements edm::EDProducer.

Definition at line 115 of file PATMuonProducer.cc.

References IPTools::absoluteTransverseImpactParameter(), pat::PATUserDataHelper< ObjectType >::add(), addGenMatch_, beamLineSrc_, SiPixelRawToDigiRegional_cfi::beamSpot, pat::helper::MultiIsolator::beginEvent(), caloMETMuonCorrs_, efficiencyLoader_, pat::Muon::embedCaloMETMuonCorrs(), embedCaloMETMuonCorrs_, embedGenMatch_, embedHighLevel(), embedHighLevelSelection_, pat::Muon::embedPFCandidate(), embedPFCandidate_, pat::Muon::embedTcMETMuonCorrs(), embedTcMETMuonCorrs_, pat::helper::KinResolutionsLoader::enabled(), pat::helper::MultiIsolator::enabled(), pat::helper::EfficiencyLoader::enabled(), pat::helper::MultiIsolator::endEvent(), pat::helper::MultiIsolator::fill(), fillMuon(), genMatchSrc_, edm::EventSetup::get(), edm::Event::getByLabel(), i, customizeTrackingMonitorSeedNumber::idx, getHLTprescales::index, susybsm::HSCParticleType::innerTrack, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), isoDepositLabels_, isolationValueLabels_, isolator_, isolatorTmpStorage_, edm::EventBase::isRealData(), edm::HandleBase::isValid(), j, reco::PFCandidate::muonRef(), patZpeak::muons, muonSrc_, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), muonProducer_cfi::patMuons, pfMuons_cff::pfMuons, pfMuonSrc_, pTComparator_, edm::Event::put(), pvSrc_, resolutionLoader_, query::result, edm::second(), pat::Muon::setDB(), pat::Lepton< LeptonType >::setIsolation(), pat::Muon::setNormChi2(), pat::Muon::setNumberOfValidHits(), pat::Muon::setPFCandidateRef(), python::multivaluedict::sort(), tcMETMuonCorrs_, groupFilesInBlocks::tt, useParticleFlow_, usePV_, userDataHelper_, useUserData_, reco::BeamSpot::x0(), reco::BeamSpot::y0(), and reco::BeamSpot::z0().

{ 
  // switch off embedding (in unschedules mode) 
  if (iEvent.isRealData()){
    addGenMatch_   = false;
    embedGenMatch_ = false;
  }

  edm::Handle<edm::View<reco::Muon> > muons;
  iEvent.getByLabel(muonSrc_, muons);

  // 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; j<isoDepositLabels_.size(); ++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 the high level selection: needs beamline
  // OR primary vertex, depending on user selection
  reco::TrackBase::Point beamPoint(0,0,0);
  reco::Vertex primaryVertex;
  reco::BeamSpot beamSpot;
  bool beamSpotIsValid = false;
  bool primaryVertexIsValid = false;
  if ( embedHighLevelSelection_ ) {
    // get the 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( beamSpotHandle.isValid() ){
      beamSpot = *beamSpotHandle;
      beamSpotIsValid = true;
    } else{
      edm::LogError("DataNotAvailable")
        << "No beam spot available from EventSetup, not adding high level selection \n";
    }
    beamPoint = reco::TrackBase::Point ( beamSpot.x0(), beamSpot.y0(), beamSpot.z0() );
    if( pvHandle.isValid() && !pvHandle->empty() ) {
      primaryVertex = pvHandle->at(0);
      primaryVertexIsValid = true;
    } 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);
  }

  // this will be the new object collection
  std::vector<Muon> * patMuons = new std::vector<Muon>();

  if( useParticleFlow_ ){
    // get the PFCandidates of type muons 
    edm::Handle< reco::PFCandidateCollection >  pfMuons;
    iEvent.getByLabel(pfMuonSrc_, pfMuons);

    unsigned index=0;
    for( reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
      const reco::PFCandidate& pfmu = *i;
      //const reco::IsolaPFCandidate& pfmu = *i;
      const reco::MuonRef& muonRef = pfmu.muonRef();
      assert( muonRef.isNonnull() );

      MuonBaseRef muonBaseRef(muonRef);
      Muon aMuon(muonBaseRef);

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

      // embed high level selection
      if ( embedHighLevelSelection_ ) {
        // get the tracks
        reco::TrackRef innerTrack = muonBaseRef->innerTrack();
        reco::TrackRef globalTrack= muonBaseRef->globalTrack();
        reco::TrackRef bestTrack  = muonBaseRef->muonBestTrack();
        reco::TrackRef chosenTrack = innerTrack;
        // Make sure the collection it points to is there
        if ( bestTrack.isNonnull() && bestTrack.isAvailable() ) 
          chosenTrack = bestTrack;

        if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
          unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
          aMuon.setNumberOfValidHits( nhits );

          reco::TransientTrack tt = trackBuilder->build(chosenTrack);
          embedHighLevel( aMuon, 
                          chosenTrack,
                          tt,
                          primaryVertex,
                          primaryVertexIsValid,
                          beamSpot,
                          beamSpotIsValid );

          // Correct to PV, or beam spot
          if ( !usePV_ ) {
            double corr_d0 = -1.0 * chosenTrack->dxy( beamPoint );
            aMuon.setDB( corr_d0, -1.0 );
          } else {
            std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
            double d0_corr = result.second.value();
            double d0_err = result.second.error();
            aMuon.setDB( d0_corr, d0_err );
          }
        }

        if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
          double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
          aMuon.setNormChi2( norm_chi2 );
        }
      }
      reco::PFCandidateRef pfRef(pfMuons,index);
      //reco::PFCandidatePtr ptrToMother(pfMuons,index);
      reco::CandidateBaseRef pfBaseRef( pfRef ); 

      aMuon.setPFCandidateRef( pfRef  );     
      if( embedPFCandidate_ ) aMuon.embedPFCandidate();
      fillMuon( aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues );
      patMuons->push_back(aMuon); 
    }
  }
  else {
    edm::Handle<edm::View<reco::Muon> > muons;
    iEvent.getByLabel(muonSrc_, muons);

    // embedding of muon MET corrections
    edm::Handle<edm::ValueMap<reco::MuonMETCorrectionData> > caloMETMuonCorrs;
    //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
    if(embedCaloMETMuonCorrs_){
      iEvent.getByLabel(caloMETMuonCorrs_, caloMETMuonCorrs);
      //caloMETmuCorValueMap  = *caloMETmuCorValueMap_h;
    }
    edm::Handle<edm::ValueMap<reco::MuonMETCorrectionData> > tcMETMuonCorrs;
    //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
    if(embedTcMETMuonCorrs_) {
      iEvent.getByLabel(tcMETMuonCorrs_, tcMETMuonCorrs);
      //tcMETmuCorValueMap  = *tcMETmuCorValueMap_h;
    }
    for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
      // construct the Muon from the ref -> save ref to original object
      unsigned int idx = itMuon - muons->begin();
      MuonBaseRef muonRef = muons->refAt(idx);
      reco::CandidateBaseRef muonBaseRef( muonRef ); 
      
      Muon aMuon(muonRef);
      fillMuon( aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);

      // Isolation
      if (isolator_.enabled()) {
        //reco::CandidatePtr mother =  ptrToMother->sourceCandidatePtr(0);
        isolator_.fill(*muons, 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) {
          aMuon.setIsolation(it->first, it->second);
        }
      }
 
      //       for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
      //        aMuon.setIsoDeposit(isoDepositLabels_[j].first, 
      //                            (*deposits[j])[muonRef]);
      //       }

      // add sel to selected
      edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
      if ( useUserData_ ) {
        userDataHelper_.add( aMuon, iEvent, iSetup );
      }

      // embed high level selection
      if ( embedHighLevelSelection_ ) {
        // get the tracks
        reco::TrackRef innerTrack = itMuon->innerTrack();
        reco::TrackRef globalTrack= itMuon->globalTrack();
        reco::TrackRef bestTrack  = itMuon->muonBestTrack();
        reco::TrackRef chosenTrack = innerTrack;
        // Make sure the collection it points to is there
        if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
          chosenTrack = bestTrack;
        if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
          unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
          aMuon.setNumberOfValidHits( nhits );

          reco::TransientTrack tt = trackBuilder->build(chosenTrack);
          embedHighLevel( aMuon, 
                          chosenTrack,
                          tt,
                          primaryVertex,
                          primaryVertexIsValid,
                          beamSpot,
                          beamSpotIsValid );

          // Correct to PV, or beam spot
          if ( !usePV_ ) {
            double corr_d0 = -1.0 * chosenTrack->dxy( beamPoint );
            aMuon.setDB( corr_d0, -1.0 );
          } else {
            std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
            double d0_corr = result.second.value();
            double d0_err = result.second.error();
            aMuon.setDB( d0_corr, d0_err );
          }
        }

        if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
          double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
          aMuon.setNormChi2( norm_chi2 );
        }
      }

      // embed MET muon corrections
      if( embedCaloMETMuonCorrs_ ) aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
      if( embedTcMETMuonCorrs_ ) aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs  )[muonRef]);      

      patMuons->push_back(aMuon);
    }
  }

  // sort muons in pt
  std::sort(patMuons->begin(), patMuons->end(), pTComparator_);

  // put genEvt object in Event
  std::auto_ptr<std::vector<Muon> > ptr(patMuons);
  iEvent.put(ptr);

  if (isolator_.enabled()) isolator_.endEvent();
}
void PATMuonProducer::readIsolationLabels ( const edm::ParameterSet iConfig,
const char *  psetName,
IsolationLabels labels 
) [private]

fill label vector from the contents of the parameter set, for the embedding of isoDeposits or userIsolation values

Definition at line 536 of file PATMuonProducer.cc.

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

Referenced by PATMuonProducer().

{
  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("pfChargedAll"))  {
      labels.push_back(std::make_pair(pat::PfChargedAllIso, depconf.getParameter<edm::InputTag>("pfChargedAll")));
    } 
    if (depconf.exists("pfPUChargedHadrons"))  {
      labels.push_back(std::make_pair(pat::PfPUChargedHadronIso, depconf.getParameter<edm::InputTag>("pfPUChargedHadrons")));
    }
    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

add efficiencies to the muon (this will be data members of th muon even w/o embedding)

Definition at line 138 of file PATMuonProducer.h.

Referenced by PATMuonProducer().

add generator match information

Definition at line 110 of file PATMuonProducer.h.

Referenced by fillMuon(), PATMuonProducer(), and produce().

add resolutions to the muon (this will be data members of th muon even w/o embedding)

Definition at line 116 of file PATMuonProducer.h.

Referenced by PATMuonProducer().

input source of the primary vertex/beamspot

Definition at line 128 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

source of caloMET muon corrections

Definition at line 98 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

helper class to add efficiencies to the muon

Definition at line 150 of file PATMuonProducer.h.

Referenced by fillMuon(), PATMuonProducer(), and produce().

embed the track from best muon measurement

Definition at line 88 of file PATMuonProducer.h.

Referenced by fillMuon(), and PATMuonProducer().

embed muon MET correction info for caloMET into the muon

Definition at line 96 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

embed track of the combined fit into the muon

Definition at line 94 of file PATMuonProducer.h.

Referenced by fillMuon(), and PATMuonProducer().

embed track from DYT muon fit into the muon

Definition at line 108 of file PATMuonProducer.h.

Referenced by fillMuon(), and PATMuonProducer().

embed the gen match information into the muon

Definition at line 114 of file PATMuonProducer.h.

Referenced by fillMuon(), PATMuonProducer(), and produce().

embed high level selection variables

Definition at line 126 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

embed pfCandidates into the muon

Definition at line 124 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

embed track from picky muon fit into the muon

Definition at line 104 of file PATMuonProducer.h.

Referenced by fillMuon(), and PATMuonProducer().

embed track from muon system into the muon

Definition at line 92 of file PATMuonProducer.h.

Referenced by fillMuon(), and PATMuonProducer().

embed muon MET correction info for tcMET into the muon

Definition at line 100 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

embed track from tpfms muon fit into the muon

Definition at line 106 of file PATMuonProducer.h.

Referenced by fillMuon(), and PATMuonProducer().

embed the track from inner tracker into the muon

Definition at line 90 of file PATMuonProducer.h.

Referenced by fillMuon(), and PATMuonProducer().

input tags for generator match information

Definition at line 112 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

input source for isoDeposits

Definition at line 134 of file PATMuonProducer.h.

Referenced by fillMuon(), PATMuonProducer(), and produce().

input source isolation value maps

Definition at line 136 of file PATMuonProducer.h.

Referenced by fillMuon(), PATMuonProducer(), and produce().

helper class to add userdefined isolation values to the muon

Definition at line 146 of file PATMuonProducer.h.

Referenced by produce().

isolation value pair for temporary storage before being folded into the muon

Definition at line 148 of file PATMuonProducer.h.

Referenced by produce().

input source

Definition at line 85 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

input source pfCandidates that will be to be transformed into pat::Muons, when using PF2PAT

Definition at line 122 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

--- tools --- comparator for pt ordering

Definition at line 144 of file PATMuonProducer.h.

Referenced by produce().

input source of the primary vertex

Definition at line 132 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

helper class to add resolutions to the muon

Definition at line 118 of file PATMuonProducer.h.

Referenced by fillMuon(), PATMuonProducer(), and produce().

source of tcMET muon corrections

Definition at line 102 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

switch to use particle flow (PF2PAT) or not

Definition at line 120 of file PATMuonProducer.h.

Referenced by fillMuon(), PATMuonProducer(), and produce().

use the primary vertex or the beamspot

Definition at line 130 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

helper class to add userData to the muon

Definition at line 152 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().

add user data to the muon (this will be data members of th muon even w/o embedding)

Definition at line 140 of file PATMuonProducer.h.

Referenced by PATMuonProducer(), and produce().