CMS 3D CMS Logo

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

pat::PATTauProducer Class Reference

Produces pat::Tau's. More...

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

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

List of all members.

Public Member Functions

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

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)

Private Types

typedef std::pair< std::string,
edm::InputTag
NameTag

Private Member Functions

template<typename TauCollectionType , typename TauDiscrType >
float getTauIdDiscriminator (const edm::Handle< TauCollectionType > &, size_t, const edm::Handle< TauDiscrType > &)

Private Attributes

bool addEfficiencies_
bool addGenJetMatch_
bool addGenMatch_
bool addResolutions_
bool addTauID_
bool addTauJetCorrFactors_
pat::helper::EfficiencyLoader efficiencyLoader_
bool embedGenJetMatch_
bool embedGenMatch_
bool embedIsolationPFCands_
bool embedIsolationPFChargedHadrCands_
bool embedIsolationPFGammaCands_
bool embedIsolationPFNeutralHadrCands_
bool embedIsolationTracks_
bool embedLeadPFCand_
bool embedLeadPFChargedHadrCand_
bool embedLeadPFNeutralCand_
bool embedLeadTrack_
bool embedSignalPFCands_
bool embedSignalPFChargedHadrCands_
bool embedSignalPFGammaCands_
bool embedSignalPFNeutralHadrCands_
bool embedSignalTracks_
edm::InputTag genJetMatchSrc_
std::vector< edm::InputTaggenMatchSrc_
std::vector< std::pair
< pat::IsolationKeys,
edm::InputTag > > 
isoDepositLabels_
pat::helper::MultiIsolator isolator_
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
GreaterByPt< TaupTTauComparator_
pat::helper::KinResolutionsLoader resolutionLoader_
std::vector< NameTagtauIDSrcs_
std::vector< edm::InputTagtauJetCorrFactorsSrc_
edm::InputTag tauSrc_
pat::PATUserDataHelper< pat::TauuserDataHelper_
bool useUserData_

Detailed Description

Produces pat::Tau's.

The PATTauProducer produces analysis-level pat::Tau's starting from a collection of objects of TauType.

Author:
Steven Lowette, Christophe Delaere
Version:
Id:
PATTauProducer.h,v 1.23 2011/09/26 12:36:30 veelken Exp

Definition at line 47 of file PATTauProducer.h.


Member Typedef Documentation

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

Definition at line 89 of file PATTauProducer.h.


Constructor & Destructor Documentation

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

Definition at line 31 of file PATTauProducer.cc.

References addEfficiencies_, addGenJetMatch_, addGenMatch_, addResolutions_, addTauID_, addTauJetCorrFactors_, pat::EcalIso, efficiencyLoader_, embedGenJetMatch_, embedGenMatch_, embedIsolationPFCands_, embedIsolationPFChargedHadrCands_, embedIsolationPFGammaCands_, embedIsolationPFNeutralHadrCands_, embedIsolationTracks_, embedLeadPFCand_, embedLeadPFChargedHadrCand_, embedLeadPFNeutralCand_, embedLeadTrack_, embedSignalPFCands_, embedSignalPFChargedHadrCands_, embedSignalPFGammaCands_, embedSignalPFNeutralHadrCands_, embedSignalTracks_, Exception, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), genJetMatchSrc_, genMatchSrc_, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), pat::HcalIso, isoDepositLabels_, combine::key, cscdqm::h::names, pat::PfAllParticleIso, pat::PfChargedHadronIso, pat::PfGammaIso, pat::PfNeutralHadronIso, resolutionLoader_, tauIDSrcs_, tauJetCorrFactorsSrc_, tauSrc_, pat::TrackIso, pat::UserBaseIso, userDataHelper_, and useUserData_.

                                                             :
  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), false) ,
  useUserData_(iConfig.exists("userData"))
{
  // initialize the configurables
  tauSrc_ = iConfig.getParameter<edm::InputTag>( "tauSource" );
  embedIsolationTracks_ = iConfig.getParameter<bool>( "embedIsolationTracks" );
  embedLeadTrack_ = iConfig.getParameter<bool>( "embedLeadTrack" );
  embedSignalTracks_ = iConfig.getParameter<bool>( "embedSignalTracks" );
  embedLeadPFCand_ = iConfig.getParameter<bool>( "embedLeadPFCand" );
  embedLeadPFChargedHadrCand_ = iConfig.getParameter<bool>( "embedLeadPFChargedHadrCand" );
  embedLeadPFNeutralCand_ = iConfig.getParameter<bool>( "embedLeadPFNeutralCand" );
  embedSignalPFCands_ = iConfig.getParameter<bool>( "embedSignalPFCands" );
  embedSignalPFChargedHadrCands_ = iConfig.getParameter<bool>( "embedSignalPFChargedHadrCands" );
  embedSignalPFNeutralHadrCands_ = iConfig.getParameter<bool>( "embedSignalPFNeutralHadrCands" );
  embedSignalPFGammaCands_ = iConfig.getParameter<bool>( "embedSignalPFGammaCands" );
  embedIsolationPFCands_ = iConfig.getParameter<bool>( "embedIsolationPFCands" );
  embedIsolationPFChargedHadrCands_ = iConfig.getParameter<bool>( "embedIsolationPFChargedHadrCands" );
  embedIsolationPFNeutralHadrCands_ = iConfig.getParameter<bool>( "embedIsolationPFNeutralHadrCands" );
  embedIsolationPFGammaCands_ = iConfig.getParameter<bool>( "embedIsolationPFGammaCands" );
  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" );
    }
  }
  addGenJetMatch_ = iConfig.getParameter<bool>( "addGenJetMatch" );
  if(addGenJetMatch_) {
    embedGenJetMatch_ = iConfig.getParameter<bool>( "embedGenJetMatch" );
    genJetMatchSrc_ = iConfig.getParameter<edm::InputTag>( "genJetMatch" );
  }
  addTauJetCorrFactors_ = iConfig.getParameter<bool>( "addTauJetCorrFactors" );
  tauJetCorrFactorsSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "tauJetCorrFactorsSource" );
  // tau ID configurables
  addTauID_ = iConfig.getParameter<bool>( "addTauID" );
  if ( addTauID_ ) {
    // it might be a single tau ID
    if (iConfig.existsAs<edm::InputTag>("tauIDSource")) {
      tauIDSrcs_.push_back(NameTag("", iConfig.getParameter<edm::InputTag>("tauIDSource")));
    }
    // or there might be many of them
    if (iConfig.existsAs<edm::ParameterSet>("tauIDSources")) {
      // please don't configure me twice
      if (!tauIDSrcs_.empty()){
        throw cms::Exception("Configuration") << "PATTauProducer: you can't specify both 'tauIDSource' and 'tauIDSources'\n";
      }
      // read the different tau ID names
      edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("tauIDSources");
      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) {
        tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
      }
    }
    // but in any case at least once
    if (tauIDSrcs_.empty()) throw cms::Exception("Configuration") <<
      "PATTauProducer: id addTauID is true, you must specify either:\n" <<
      "\tInputTag tauIDSource = <someTag>\n" << "or\n" <<
      "\tPSet tauIDSources = { \n" <<
      "\t\tInputTag <someName> = <someTag>   // as many as you want \n " <<
      "\t}\n";
  }
  // IsoDeposit configurables
  if (iConfig.exists("isoDeposits")) {
    edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
    if ( depconf.exists("tracker")         ) isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
    if ( depconf.exists("ecal")            ) isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
    if ( depconf.exists("hcal")            ) isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
    if ( depconf.exists("pfAllParticles")  ) isoDepositLabels_.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
    if ( depconf.exists("pfChargedHadron") ) isoDepositLabels_.push_back(std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadron")));
    if ( depconf.exists("pfNeutralHadron") ) isoDepositLabels_.push_back(std::make_pair(pat::PfNeutralHadronIso,depconf.getParameter<edm::InputTag>("pfNeutralHadron")));
    if ( depconf.exists("pfGamma")         ) isoDepositLabels_.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfGamma")));
    
    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));
      }
    }
  }
  // Efficiency configurables
  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
  if (addEfficiencies_) {
     efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
  }
  // Resolution configurables
  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
  if (addResolutions_) {
     resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
  }
  // Check to see if the user wants to add user data
  if ( useUserData_ ) {
    userDataHelper_ = PATUserDataHelper<Tau>(iConfig.getParameter<edm::ParameterSet>("userData"));
  }
  // produces vector of taus
  produces<std::vector<Tau> >();
}
PATTauProducer::~PATTauProducer ( )

Definition at line 134 of file PATTauProducer.cc.

{
}

Member Function Documentation

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

Reimplemented from edm::EDProducer.

Definition at line 408 of file PATTauProducer.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 tau producer module");

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

  // embedding
  iDesc.add<bool>("embedIsolationTracks", false)->setComment("embed external isolation tracks");
  iDesc.add<bool>("embedLeadTrack", false)->setComment("embed external leading track");
  iDesc.add<bool>("embedLeadTracks", false)->setComment("embed external signal tracks");

  // 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");

  // MC jet matching variables
  iDesc.add<bool>("addGenJetMatch", true)->setComment("add MC jet matching");
  iDesc.add<bool>("embedGenJetMatch", false)->setComment("embed MC jet matched jet information");
  iDesc.add<edm::InputTag>("genJetMatch", edm::InputTag("tauGenJetMatch"));


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

  // tau ID configurables
  iDesc.add<bool>("addTauID", true)->setComment("add tau ID variables");
  edm::ParameterSetDescription tauIDSourcesPSet;
  tauIDSourcesPSet.setAllowAnything(); 
  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("tauIDSource", edm::InputTag(), true) xor
                 edm::ParameterDescription<edm::ParameterSetDescription>("tauIDSources", tauIDSourcesPSet, 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>("pfChargedHadron");
  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadron");
  isoDepositsPSet.addOptional<edm::InputTag>("pfGamma");
  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
  iDesc.addOptional("isoDeposits", isoDepositsPSet);

  // 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<Tau>::fillDescription(userDataPSet);
  iDesc.addOptional("userData", userDataPSet);

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

}
template<typename TauCollectionType , typename TauDiscrType >
float PATTauProducer::getTauIdDiscriminator ( const edm::Handle< TauCollectionType > &  tauCollection,
size_t  tauIdx,
const edm::Handle< TauDiscrType > &  tauIdDiscr 
) [private]

Definition at line 401 of file PATTauProducer.cc.

Referenced by produce().

{
  edm::Ref<TauCollectionType> tauRef(tauCollection, tauIdx);
  return (*tauIdDiscr)[tauRef];
}     
void PATTauProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 138 of file PATTauProducer.cc.

References pat::PATUserDataHelper< ObjectType >::add(), addGenJetMatch_, addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), pat::Tau::addJECFactors(), addTauID_, addTauJetCorrFactors_, pat::helper::MultiIsolator::beginEvent(), alignCSCRings::e, efficiencyLoader_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::Tau::embedIsolationPFCands(), embedIsolationPFCands_, pat::Tau::embedIsolationPFChargedHadrCands(), embedIsolationPFChargedHadrCands_, pat::Tau::embedIsolationPFGammaCands(), embedIsolationPFGammaCands_, pat::Tau::embedIsolationPFNeutralHadrCands(), embedIsolationPFNeutralHadrCands_, pat::Tau::embedIsolationTracks(), embedIsolationTracks_, pat::Tau::embedLeadPFCand(), embedLeadPFCand_, pat::Tau::embedLeadPFChargedHadrCand(), embedLeadPFChargedHadrCand_, pat::Tau::embedLeadPFNeutralCand(), embedLeadPFNeutralCand_, pat::Tau::embedLeadTrack(), embedLeadTrack_, pat::Tau::embedSignalPFCands(), embedSignalPFCands_, pat::Tau::embedSignalPFChargedHadrCands(), embedSignalPFChargedHadrCands_, pat::Tau::embedSignalPFGammaCands(), embedSignalPFGammaCands_, pat::Tau::embedSignalPFNeutralHadrCands(), embedSignalPFNeutralHadrCands_, pat::Tau::embedSignalTracks(), embedSignalTracks_, pat::helper::KinResolutionsLoader::enabled(), pat::helper::MultiIsolator::enabled(), pat::helper::EfficiencyLoader::enabled(), pat::helper::MultiIsolator::endEvent(), Exception, pat::helper::MultiIsolator::fill(), spr::find(), first, genJetMatchSrc_, genMatchSrc_, edm::Event::getByLabel(), getTauIdDiscriminator(), i, customizeTrackingMonitorSeedNumber::idx, pat::Tau::initializeJEC(), edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), isoDepositLabels_, isolator_, isolatorTmpStorage_, pat::Tau::isPFTau(), edm::EventBase::isRealData(), j, n, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), tauProducer_cfi::patTaus, pfTaus_cff::pfTaus, pTTauComparator_, edm::Event::put(), resolutionLoader_, edm::second(), pat::Tau::setDecayMode(), pat::helper::EfficiencyLoader::setEfficiencies(), pat::Tau::setGenJet(), pat::Lepton< LeptonType >::setIsoDeposit(), pat::Lepton< LeptonType >::setIsolation(), pat::helper::KinResolutionsLoader::setResolutions(), pat::Tau::setTauIDs(), python::multivaluedict::sort(), tauIDSrcs_, tauJetCorrFactorsSrc_, tauSrc_, userDataHelper_, and useUserData_.

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

  // Get the collection of taus from the event
  edm::Handle<edm::View<reco::BaseTau> > anyTaus;
  try {
    iEvent.getByLabel(tauSrc_, anyTaus);
  } catch (const edm::Exception &e) {
    edm::LogWarning("DataSource") << "WARNING! No Tau collection found. This missing input will not block the job. Instead, an empty tau collection is being be produced.";
    std::auto_ptr<std::vector<Tau> > patTaus(new std::vector<Tau>()); 
    iEvent.put(patTaus);
    return;
  }

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

  if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
   
  std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositLabels_.size());
  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
    iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]);
  }

  // prepare the MC matching
  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
  if (addGenMatch_) {
    for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
      iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
    }
  }

  edm::Handle<edm::Association<reco::GenJetCollection> > genJetMatch;  
  if (addGenJetMatch_) iEvent.getByLabel(genJetMatchSrc_, genJetMatch); 

  // read in the jet correction factors ValueMap
  std::vector<edm::ValueMap<TauJetCorrFactors> > tauJetCorrs;
  if (addTauJetCorrFactors_) {
    for ( size_t i = 0; i < tauJetCorrFactorsSrc_.size(); ++i ) {
      edm::Handle<edm::ValueMap<TauJetCorrFactors> > tauJetCorr;
      iEvent.getByLabel(tauJetCorrFactorsSrc_[i], tauJetCorr);
      tauJetCorrs.push_back( *tauJetCorr );
    }
  }  

  std::auto_ptr<std::vector<Tau> > patTaus(new std::vector<Tau>()); 

  bool first=true; // this is introduced to issue warnings only for the first tau-jet
  for (size_t idx = 0, ntaus = anyTaus->size(); idx < ntaus; ++idx) {
    edm::RefToBase<reco::BaseTau> tausRef = anyTaus->refAt(idx);
    edm::Ptr<reco::BaseTau> tausPtr = anyTaus->ptrAt(idx);
    
    Tau aTau(tausRef);
    if (embedLeadTrack_)       aTau.embedLeadTrack();
    if (embedSignalTracks_)    aTau.embedSignalTracks();
    if (embedIsolationTracks_) aTau.embedIsolationTracks();    
    if (embedLeadPFCand_) {
      if (aTau.isPFTau() )
        aTau.embedLeadPFCand();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedLeadPFChargedHadrCand_) {
      if (aTau.isPFTau() )
        aTau.embedLeadPFChargedHadrCand();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedLeadPFNeutralCand_) {
      if (aTau.isPFTau() )
        aTau.embedLeadPFNeutralCand();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedSignalPFCands_) {
      if (aTau.isPFTau() )
        aTau.embedSignalPFCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedSignalPFChargedHadrCands_) {
      if (aTau.isPFTau() )
        aTau.embedSignalPFChargedHadrCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedSignalPFNeutralHadrCands_) {
      if (aTau.isPFTau() )
        aTau.embedSignalPFNeutralHadrCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedSignalPFGammaCands_) {
      if (aTau.isPFTau() )
        aTau.embedSignalPFGammaCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedIsolationPFCands_) {
      if (aTau.isPFTau() )
        aTau.embedIsolationPFCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedIsolationPFChargedHadrCands_) {
      if (aTau.isPFTau() )
        aTau.embedIsolationPFChargedHadrCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedIsolationPFNeutralHadrCands_) {
      if (aTau.isPFTau() )
        aTau.embedIsolationPFNeutralHadrCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    if (embedIsolationPFGammaCands_) {
      if (aTau.isPFTau() )
        aTau.embedIsolationPFGammaCands();
      else 
        edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made from a reco::PFTau is impossible.\n";
    }
    
    if (addTauJetCorrFactors_) {
      // add additional JetCorrs to the jet 
      for ( unsigned int i=0; i<tauJetCorrFactorsSrc_.size(); ++i ) {
        const TauJetCorrFactors& tauJetCorr = tauJetCorrs[i][tausRef];
        // uncomment for debugging
        // tauJetCorr.print();
        aTau.addJECFactors(tauJetCorr);
      }
      std::vector<std::string> levels = tauJetCorrs[0][tausRef].correctionLabels();
      if(std::find(levels.begin(), levels.end(), "L2L3Residual")!=levels.end()){
        aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L2L3Residual"));
      }
      else if(std::find(levels.begin(), levels.end(), "L3Absolute")!=levels.end()){
        aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L3Absolute"));
      }
      else{
        aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("Uncorrected"));
        if(first){        
          edm::LogWarning("L3Absolute not found") 
            << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
            << "of module " <<  tauJetCorrs[0][tausRef].jecSet() << " jets will remain"
            << " uncorrected."; 
          first=false;
        }
      }
    }

    // store the match to the generated final state muons
    if (addGenMatch_) {
      for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
          reco::GenParticleRef genTau = (*genMatches[i])[tausRef];
          aTau.addGenParticleRef(genTau);
      }
      if (embedGenMatch_) aTau.embedGenParticle();
    }
    
    // store the match to the visible part of the generated tau
    if (addGenJetMatch_) {
      reco::GenJetRef genJetTau = (*genJetMatch)[tausRef];
      if (genJetTau.isNonnull() && genJetTau.isAvailable() ) {
        aTau.setGenJet( genJetTau );
      } // leave empty if no match found
    }

    // prepare ID extraction 
    if ( addTauID_ ) {
      std::vector<pat::Tau::IdPair> ids(tauIDSrcs_.size());
      for ( size_t i = 0; i < tauIDSrcs_.size(); ++i ) {
        edm::Handle<reco::CaloTauDiscriminator> caloTauIdDiscr;
        iEvent.getByLabel(tauIDSrcs_[i].second, caloTauIdDiscr);

        edm::Handle<reco::PFTauDiscriminator> pfTauIdDiscr;
        iEvent.getByLabel(tauIDSrcs_[i].second, pfTauIdDiscr);
        
        if ( typeid(*tausRef) == typeid(reco::PFTau) ) {
          //std::cout << "filling PFTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
          edm::Handle<reco::PFTauCollection> pfTauCollection; 
          iEvent.getByLabel(tauSrc_, pfTauCollection);

          edm::Handle<reco::PFTauDiscriminator> pfTauIdDiscr;
          iEvent.getByLabel(tauIDSrcs_[i].second, pfTauIdDiscr);

          ids[i].first = tauIDSrcs_[i].first;
          ids[i].second = getTauIdDiscriminator(pfTauCollection, idx, pfTauIdDiscr);
        } else if ( typeid(*tausRef) == typeid(reco::CaloTau) ) {
          //std::cout << "filling CaloTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
          edm::Handle<reco::CaloTauCollection> caloTauCollection; 
          iEvent.getByLabel(tauSrc_, caloTauCollection);

          edm::Handle<reco::CaloTauDiscriminator> caloTauIdDiscr;
          iEvent.getByLabel(tauIDSrcs_[i].second, caloTauIdDiscr);

          ids[i].first = tauIDSrcs_[i].first;
          ids[i].second = getTauIdDiscriminator(caloTauCollection, idx, caloTauIdDiscr);
        } else {
          throw cms::Exception("Type Mismatch") <<
            "PATTauProducer: unsupported datatype '" << typeid(*tausRef).name() << "' for tauSource\n";
        }
      }

      aTau.setTauIDs(ids);
    }

    // extraction of reconstructed tau decay mode 
    // (only available for PFTaus)
    if ( aTau.isPFTau() ) {
      edm::Handle<reco::PFTauCollection> pfTaus;
      iEvent.getByLabel(tauSrc_, pfTaus);
      reco::PFTauRef pfTauRef(pfTaus, idx);

      aTau.setDecayMode(pfTauRef->decayMode());
    }

    // Isolation
    if (isolator_.enabled()) {
      isolator_.fill(*anyTaus, 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) {
        aTau.setIsolation(it->first, it->second);
      }
    }
    
    for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
      aTau.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[tausRef]);
    }

    if (efficiencyLoader_.enabled()) {
      efficiencyLoader_.setEfficiencies( aTau, tausRef );
    }

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

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

    patTaus->push_back(aTau);
  }

  // sort taus in pT
  std::sort(patTaus->begin(), patTaus->end(), pTTauComparator_);

  // put genEvt object in Event
  iEvent.put(patTaus);

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

Member Data Documentation

Definition at line 99 of file PATTauProducer.h.

Referenced by PATTauProducer().

Definition at line 81 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 77 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 102 of file PATTauProducer.h.

Referenced by PATTauProducer().

Definition at line 88 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 85 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 100 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 82 of file PATTauProducer.h.

Referenced by PATTauProducer().

Definition at line 78 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 72 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 73 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 75 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 74 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 62 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 65 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 66 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 67 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 63 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 68 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 69 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 71 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 70 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 64 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 83 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 79 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 97 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 95 of file PATTauProducer.h.

Referenced by produce().

Definition at line 96 of file PATTauProducer.h.

Referenced by produce().

Definition at line 93 of file PATTauProducer.h.

Referenced by produce().

Definition at line 103 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

std::vector<NameTag> pat::PATTauProducer::tauIDSrcs_ [private]

Definition at line 90 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 86 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 61 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 106 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().

Definition at line 105 of file PATTauProducer.h.

Referenced by PATTauProducer(), and produce().