CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
pat::PATTauProducer Class Reference

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

Inheritance diagram for pat::PATTauProducer:
edm::stream::EDProducer<>

Public Member Functions

 PATTauProducer (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~PATTauProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

typedef std::pair< edm::InputTag, std::vector< NameWPIdx > > IDContainerData
 
typedef std::pair< std::string, edm::InputTagNameTag
 
typedef std::pair< std::string, WPIdxNameWPIdx
 
typedef std::pair< std::string, std::string > WPCfg
 
typedef std::pair< WPCfg, int > WPIdx
 

Private Member Functions

template<typename TauCollectionType , typename TauDiscrType >
float getTauIdDiscriminator (const edm::Handle< TauCollectionType > &, size_t, const edm::Handle< TauDiscrType > &)
 
float getTauIdDiscriminatorFromContainer (const edm::Handle< reco::PFTauCollection > &, size_t, const edm::Handle< reco::TauDiscriminatorContainer > &, int)
 

Private Attributes

bool addEfficiencies_
 
bool addGenJetMatch_
 
bool addGenMatch_
 
bool addResolutions_
 
bool addTauID_
 
bool addTauJetCorrFactors_
 
edm::EDGetTokenT< edm::View< reco::BaseTau > > baseTauToken_
 
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_
 
bool firstOccurence_
 
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
 
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
 
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
 
pat::helper::MultiIsolator isolator_
 
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
 
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > pfTauIDContainerTokens_
 
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > pfTauIDTokens_
 
edm::EDGetTokenT< reco::PFTauCollectionpfTauToken_
 
edm::ProcessHistoryID phID_
 
PositionAtECalEntranceComputer posAtECalEntranceComputer_
 
GreaterByPt< TaupTTauComparator_
 
pat::helper::KinResolutionsLoader resolutionLoader_
 
bool skipMissingTauID_
 
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
 
std::vector< NameTagtauIDSrcs_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< TauJetCorrFactors > > > tauJetCorrFactorsTokens_
 
edm::InputTag tauTransverseImpactParameterSrc_
 
edm::EDGetTokenT< PFTauTIPAssociationByReftauTransverseImpactParameterToken_
 
pat::PATUserDataHelper< pat::TauuserDataHelper_
 
bool useUserData_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

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

Definition at line 56 of file PATTauProducer.cc.

Member Typedef Documentation

◆ IDContainerData

typedef std::pair<edm::InputTag, std::vector<NameWPIdx> > pat::PATTauProducer::IDContainerData
private

Definition at line 105 of file PATTauProducer.cc.

◆ NameTag

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

Definition at line 100 of file PATTauProducer.cc.

◆ NameWPIdx

typedef std::pair<std::string, WPIdx> pat::PATTauProducer::NameWPIdx
private

Definition at line 103 of file PATTauProducer.cc.

◆ WPCfg

typedef std::pair<std::string, std::string> pat::PATTauProducer::WPCfg
private

Definition at line 101 of file PATTauProducer.cc.

◆ WPIdx

typedef std::pair<WPCfg, int> pat::PATTauProducer::WPIdx
private

Definition at line 102 of file PATTauProducer.cc.

Constructor & Destructor Documentation

◆ PATTauProducer()

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

Definition at line 143 of file PATTauProducer.cc.

References addEfficiencies_, addGenJetMatch_, addGenMatch_, addResolutions_, addTauID_, addTauJetCorrFactors_, baseTauToken_, pat::EcalIso, efficiencyLoader_, embedGenJetMatch_, embedGenMatch_, embedIsolationPFCands_, embedIsolationPFChargedHadrCands_, embedIsolationPFGammaCands_, embedIsolationPFNeutralHadrCands_, embedIsolationTracks_, embedLeadPFCand_, embedLeadPFChargedHadrCand_, embedLeadPFNeutralCand_, embedLeadTrack_, embedSignalPFCands_, embedSignalPFChargedHadrCands_, embedSignalPFGammaCands_, embedSignalPFNeutralHadrCands_, embedSignalTracks_, Exception, edm::ParameterSet::exists(), dqmdumpme::first, firstOccurence_, genJetMatchToken_, genMatchTokens_, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), pat::HcalIso, isoDepositLabels_, isoDepositTokens_, crabWrapper::key, label, Skims_PA_cff::name, names, pat::PfAllParticleIso, pat::PfChargedHadronIso, pat::PfGammaIso, pat::PfNeutralHadronIso, pfTauIDContainerTokens_, pfTauIDTokens_, pfTauToken_, resolutionLoader_, skipMissingTauID_, AlCaHLTBitMon_QueryRunRegistry::string, makeGlobalPositionRcd_cfg::tag, tauIDSrcContainers_, tauIDSrcs_, tauJetCorrFactorsTokens_, tauTransverseImpactParameterSrc_, tauTransverseImpactParameterToken_, pat::TrackIso, pat::UserBaseIso, userDataHelper_, useUserData_, and edm::vector_transform().

144  : isolator_(iConfig.getParameter<edm::ParameterSet>("userIsolation"), consumesCollector(), false),
145  useUserData_(iConfig.exists("userData")),
146  posAtECalEntranceComputer_(consumesCollector()) {
147  firstOccurence_ = true;
148  // initialize the configurables
149  baseTauToken_ = consumes<edm::View<reco::BaseTau>>(iConfig.getParameter<edm::InputTag>("tauSource"));
150  tauTransverseImpactParameterSrc_ = iConfig.getParameter<edm::InputTag>("tauTransverseImpactParameterSource");
151  tauTransverseImpactParameterToken_ = consumes<PFTauTIPAssociationByRef>(tauTransverseImpactParameterSrc_);
152  pfTauToken_ = consumes<reco::PFTauCollection>(iConfig.getParameter<edm::InputTag>("tauSource"));
153  embedIsolationTracks_ = iConfig.getParameter<bool>("embedIsolationTracks");
154  embedLeadTrack_ = iConfig.getParameter<bool>("embedLeadTrack");
155  embedSignalTracks_ = iConfig.getParameter<bool>("embedSignalTracks");
156  embedLeadPFCand_ = iConfig.getParameter<bool>("embedLeadPFCand");
157  embedLeadPFChargedHadrCand_ = iConfig.getParameter<bool>("embedLeadPFChargedHadrCand");
158  embedLeadPFNeutralCand_ = iConfig.getParameter<bool>("embedLeadPFNeutralCand");
159  embedSignalPFCands_ = iConfig.getParameter<bool>("embedSignalPFCands");
160  embedSignalPFChargedHadrCands_ = iConfig.getParameter<bool>("embedSignalPFChargedHadrCands");
161  embedSignalPFNeutralHadrCands_ = iConfig.getParameter<bool>("embedSignalPFNeutralHadrCands");
162  embedSignalPFGammaCands_ = iConfig.getParameter<bool>("embedSignalPFGammaCands");
163  embedIsolationPFCands_ = iConfig.getParameter<bool>("embedIsolationPFCands");
164  embedIsolationPFChargedHadrCands_ = iConfig.getParameter<bool>("embedIsolationPFChargedHadrCands");
165  embedIsolationPFNeutralHadrCands_ = iConfig.getParameter<bool>("embedIsolationPFNeutralHadrCands");
166  embedIsolationPFGammaCands_ = iConfig.getParameter<bool>("embedIsolationPFGammaCands");
167  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
168  if (addGenMatch_) {
169  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
171  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
172  }
173  addGenJetMatch_ = iConfig.getParameter<bool>("addGenJetMatch");
174  if (addGenJetMatch_) {
175  embedGenJetMatch_ = iConfig.getParameter<bool>("embedGenJetMatch");
177  consumes<edm::Association<reco::GenJetCollection>>(iConfig.getParameter<edm::InputTag>("genJetMatch"));
178  }
179  addTauJetCorrFactors_ = iConfig.getParameter<bool>("addTauJetCorrFactors");
181  iConfig.getParameter<std::vector<edm::InputTag>>("tauJetCorrFactorsSource"),
182  [this](edm::InputTag const& tag) { return mayConsume<edm::ValueMap<TauJetCorrFactors>>(tag); });
183  // tau ID configurables
184  addTauID_ = iConfig.getParameter<bool>("addTauID");
185  if (addTauID_) {
186  // read the different tau ID names
187  edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("tauIDSources");
188  std::vector<std::string> names = idps.getParameterNamesForType<edm::ParameterSet>();
189  std::map<std::string, IDContainerData> idContainerMap;
190  for (auto const& name : names) {
191  auto const& idp = idps.getParameter<edm::ParameterSet>(name);
192  std::string prov_cfg_label = idp.getParameter<std::string>("provenanceConfigLabel");
193  std::string prov_ID_label = idp.getParameter<std::string>("idLabel");
194  edm::InputTag tag = idp.getParameter<edm::InputTag>("inputTag");
195  if (prov_cfg_label.empty()) {
196  tauIDSrcs_.push_back(NameTag(name, tag));
197  } else {
198  if (prov_cfg_label != "rawValues" && prov_cfg_label != "workingPoints" && prov_cfg_label != "IDdefinitions" &&
199  prov_cfg_label != "IDWPdefinitions" && prov_cfg_label != "direct_rawValues" &&
200  prov_cfg_label != "direct_workingPoints")
201  throw cms::Exception("Configuration")
202  << "PATTauProducer: Parameter 'provenanceConfigLabel' does only accept 'rawValues', 'workingPoints', "
203  "'IDdefinitions', 'IDWPdefinitions', 'direct_rawValues', 'direct_workingPoints'\n";
204  std::map<std::string, IDContainerData>::iterator it;
205  it = idContainerMap.insert({tag.label() + tag.instance(), {tag, std::vector<NameWPIdx>()}}).first;
206  it->second.second.push_back(NameWPIdx(name, WPIdx(WPCfg(prov_cfg_label, prov_ID_label), -99)));
207  }
208  }
209  // but in any case at least once
210  if (tauIDSrcs_.empty() && idContainerMap.empty())
211  throw cms::Exception("Configuration") << "PATTauProducer: id addTauID is true, you must specify either:\n"
212  << "\tPSet tauIDSources = { \n"
213  << "\t\tInputTag <someName> = <someTag> // as many as you want \n "
214  << "\t}\n";
215 
216  for (auto const& mapEntry : idContainerMap) {
217  tauIDSrcContainers_.push_back(mapEntry.second.second);
218  pfTauIDContainerTokens_.push_back(mayConsume<reco::TauDiscriminatorContainer>(mapEntry.second.first));
219  }
220  }
222  tauIDSrcs_, [this](NameTag const& tag) { return mayConsume<reco::PFTauDiscriminator>(tag.second); });
223  skipMissingTauID_ = iConfig.getParameter<bool>("skipMissingTauID");
224  // IsoDeposit configurables
225  if (iConfig.exists("isoDeposits")) {
226  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
227  if (depconf.exists("tracker"))
228  isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
229  if (depconf.exists("ecal"))
230  isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
231  if (depconf.exists("hcal"))
232  isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
233  if (depconf.exists("pfAllParticles"))
234  isoDepositLabels_.push_back(
235  std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
236  if (depconf.exists("pfChargedHadron"))
237  isoDepositLabels_.push_back(
238  std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadron")));
239  if (depconf.exists("pfNeutralHadron"))
240  isoDepositLabels_.push_back(
241  std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadron")));
242  if (depconf.exists("pfGamma"))
243  isoDepositLabels_.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfGamma")));
244 
245  if (depconf.exists("user")) {
246  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag>>("user");
247  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
248  int key = UserBaseIso;
249  for (; it != ed; ++it, ++key) {
250  isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
251  }
252  }
253  }
255  edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys, edm::InputTag> const& label) {
256  return consumes<edm::ValueMap<IsoDeposit>>(label.second);
257  });
258  // Efficiency configurables
259  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
260  if (addEfficiencies_) {
262  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
263  }
264  // Resolution configurables
265  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
266  if (addResolutions_) {
268  pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"), consumesCollector());
269  }
270  // Check to see if the user wants to add user data
271  if (useUserData_) {
272  userDataHelper_ = PATUserDataHelper<Tau>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
273  }
274  // produces vector of taus
275  produces<std::vector<Tau>>();
276 }
Assists in assimilating all pat::UserData into pat objects.
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::pair< std::string, edm::InputTag > NameTag
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
bool exists(std::string const &parameterName) const
checks if a parameter exists
pat::helper::EfficiencyLoader efficiencyLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
const std::string names[nVars_]
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > pfTauIDContainerTokens_
bool embedIsolationPFChargedHadrCands_
char const * label
edm::EDGetTokenT< PFTauTIPAssociationByRef > tauTransverseImpactParameterToken_
pat::helper::MultiIsolator isolator_
edm::EDGetTokenT< edm::View< reco::BaseTau > > baseTauToken_
bool embedIsolationPFNeutralHadrCands_
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:180
pat::PATUserDataHelper< pat::Tau > userDataHelper_
std::vector< edm::EDGetTokenT< edm::ValueMap< TauJetCorrFactors > > > tauJetCorrFactorsTokens_
edm::InputTag tauTransverseImpactParameterSrc_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
std::pair< std::string, WPIdx > NameWPIdx
std::pair< std::string, std::string > WPCfg
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
std::pair< WPCfg, int > WPIdx
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > pfTauIDTokens_
std::vector< NameTag > tauIDSrcs_
edm::EDGetTokenT< reco::PFTauCollection > pfTauToken_
PositionAtECalEntranceComputer posAtECalEntranceComputer_

◆ ~PATTauProducer()

PATTauProducer::~PATTauProducer ( )
override

Definition at line 278 of file PATTauProducer.cc.

278 {}

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 836 of file PATTauProducer.cc.

References edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addNode(), edm::ParameterSetDescription::addOptional(), pat::helper::KinResolutionsLoader::fillDescription(), pat::PATUserDataHelper< ObjectType >::fillDescription(), ProducerED_cfi::InputTag, edm::ParameterSetDescription::setAllowAnything(), edm::ParameterSetDescription::setComment(), and edm::ParameterDescriptionNode::setComment().

836  {
838  iDesc.setComment("PAT tau producer module");
839 
840  // input source
841  iDesc.add<edm::InputTag>("tauSource", edm::InputTag())->setComment("input collection");
842 
843  // embedding
844  iDesc.add<bool>("embedIsolationTracks", false)->setComment("embed external isolation tracks");
845  iDesc.add<bool>("embedLeadTrack", false)->setComment("embed external leading track");
846  iDesc.add<bool>("embedLeadTracks", false)->setComment("embed external signal tracks");
847 
848  // MC matching configurables
849  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
850  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
851  std::vector<edm::InputTag> emptySourceVector;
852  iDesc
853  .addNode(edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
854  edm::ParameterDescription<std::vector<edm::InputTag>>("genParticleMatch", emptySourceVector, true))
855  ->setComment("input with MC match information");
856 
857  // MC jet matching variables
858  iDesc.add<bool>("addGenJetMatch", true)->setComment("add MC jet matching");
859  iDesc.add<bool>("embedGenJetMatch", false)->setComment("embed MC jet matched jet information");
860  iDesc.add<edm::InputTag>("genJetMatch", edm::InputTag("tauGenJetMatch"));
861 
863 
864  // tau ID configurables
865  iDesc.add<bool>("addTauID", true)->setComment("add tau ID variables");
866  edm::ParameterSetDescription tauIDSourcesPSet;
867  tauIDSourcesPSet.setAllowAnything();
868  iDesc
870  edm::ParameterDescription<edm::ParameterSetDescription>("tauIDSources", tauIDSourcesPSet, true))
871  ->setComment("input with tau ID variables");
872  // (Dis)allow to skip missing tauId sources
873  iDesc.add<bool>("skipMissingTauID", false)
874  ->setComment("allow to skip a tau ID variable when not present in the event");
875 
876  // IsoDeposit configurables
877  edm::ParameterSetDescription isoDepositsPSet;
878  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
879  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
880  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
881  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
882  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadron");
883  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadron");
884  isoDepositsPSet.addOptional<edm::InputTag>("pfGamma");
885  isoDepositsPSet.addOptional<std::vector<edm::InputTag>>("user");
886  iDesc.addOptional("isoDeposits", isoDepositsPSet);
887 
888  // Efficiency configurables
889  edm::ParameterSetDescription efficienciesPSet;
890  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
891  iDesc.add("efficiencies", efficienciesPSet);
892  iDesc.add<bool>("addEfficiencies", false);
893 
894  // Check to see if the user wants to add user data
895  edm::ParameterSetDescription userDataPSet;
897  iDesc.addOptional("userData", userDataPSet);
898 
899  edm::ParameterSetDescription isolationPSet;
900  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
901  iDesc.add("userIsolation", isolationPSet);
902 }
void setComment(std::string const &value)
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
void setAllowAnything()
allow any parameter label/value pairs
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
static void fillDescription(edm::ParameterSetDescription &iDesc)
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.

◆ getTauIdDiscriminator()

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 810 of file PATTauProducer.cc.

References RecoTauValidationMiniAOD_cfi::tauCollection, and taus_cff::tauIdx.

Referenced by produce().

812  {
814  return (*tauIdDiscr)[tauRef];
815 }

◆ getTauIdDiscriminatorFromContainer()

float PATTauProducer::getTauIdDiscriminatorFromContainer ( const edm::Handle< reco::PFTauCollection > &  tauCollection,
size_t  tauIdx,
const edm::Handle< reco::TauDiscriminatorContainer > &  tauIdDiscr,
int  wpIdx 
)
private

Definition at line 816 of file PATTauProducer.cc.

References PDWG_TauSkim_cff::rawValues, RecoTauValidationMiniAOD_cfi::tauCollection, taus_cff::tauIdx, and PDWG_TauSkim_cff::workingPoints.

Referenced by produce().

819  {
821  if (wpIdx < 0) {
822  //Only 0th component filled with default value if prediscriminor in RecoTauDiscriminator failed.
823  if ((*tauIdDiscr)[tauRef].rawValues.size() == 1)
824  return (*tauIdDiscr)[tauRef].rawValues.at(0);
825  //uses negative indices to access rawValues. In most cases only one rawValue at wpIdx=-1 exists.
826  return (*tauIdDiscr)[tauRef].rawValues.at(-1 - wpIdx);
827  } else {
828  //WP vector not filled if prediscriminor in RecoTauDiscriminator failed. Set PAT output to false in this case
829  if ((*tauIdDiscr)[tauRef].workingPoints.empty())
830  return 0.0;
831  return (*tauIdDiscr)[tauRef].workingPoints.at(wpIdx);
832  }
833 }

◆ produce()

void PATTauProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 280 of file PATTauProducer.cc.

References pat::PATUserDataHelper< ObjectType >::add(), addGenJetMatch_, addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), pat::Tau::addJECFactors(), addTauID_, addTauJetCorrFactors_, baseTauToken_, PositionAtECalEntranceComputer::beginEvent(), pat::helper::MultiIsolator::beginEvent(), pat::PackedCandidate::bestTrack(), pat::PackedCandidate::caloFraction(), CandIsolatorFromDeposits_cfi::deposits, reco::PFTauTransverseImpactParameter::dxy(), pat::tau::TauPFEssential::dxy_, reco::PFTauTransverseImpactParameter::dxy_error(), pat::tau::TauPFEssential::dxy_error_, reco::PFTauTransverseImpactParameter::dxy_PCA(), pat::tau::TauPFEssential::dxy_PCA_, MillePedeFileConverter_cfg::e, reco::PFCandidate::ecalEnergy(), electrons_cff::ecalEnergy, pat::tau::TauPFEssential::ecalEnergy_, pat::tau::TauPFEssential::ecalEnergyLeadChargedHadrCand_, 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::tau::TauPFEssential::emFraction_, pat::helper::EfficiencyLoader::enabled(), pat::helper::KinResolutionsLoader::enabled(), pat::helper::MultiIsolator::enabled(), pat::helper::MultiIsolator::endEvent(), reco::LeafCandidate::energy(), pat::PackedCandidate::energy(), pat::PackedCandidate::eta(), pat::tau::TauPFEssential::etaAtEcalEntrance_, pat::tau::TauPFEssential::etaAtEcalEntranceLeadChargedCand_, Exception, pat::helper::MultiIsolator::fill(), spr::find(), dqmdumpme::first, firstOccurence_, reco::PFTauTransverseImpactParameter::flightLength(), pat::tau::TauPFEssential::flightLength_, reco::PFTauTransverseImpactParameter::flightLengthSig(), pat::tau::TauPFEssential::flightLengthSig_, newFWLiteAna::found, jetProducer_cfi::genJetMatch, genJetMatchToken_, genMatchTokens_, edm::Ptr< T >::get(), edm::Ref< C, T, F >::get(), getTauIdDiscriminator(), getTauIdDiscriminatorFromContainer(), reco::PFCandidate::gsfTrackRef(), reco::PFTauTransverseImpactParameter::hasSecondaryVertex(), pat::tau::TauPFEssential::hasSV_, reco::PFCandidate::hcalEnergy(), pat::tau::TauPFEssential::hcalEnergy_, pat::tau::TauPFEssential::hcalEnergyLeadChargedHadrCand_, pat::PackedCandidate::hcalFraction(), mps_fire::i, heavyIonCSV_trainingSettings::idx, iEvent, pat::Tau::initializeJEC(), reco::PFTauTransverseImpactParameter::ip3d(), pat::tau::TauPFEssential::ip3d_, reco::PFTauTransverseImpactParameter::ip3d_error(), pat::tau::TauPFEssential::ip3d_error_, edm::Ref< C, T, F >::isAvailable(), edm::Ptr< T >::isNonnull(), edm::Ref< C, T, F >::isNonnull(), isoDepositLabels_, isoDepositTokens_, isolator_, isolatorTmpStorage_, pat::Tau::isPFTau(), dqmiolumiharvest::j, edm::InputTag::label(), pat::tau::TauPFEssential::leadingTrackNormChi2_, GCP_tree_cfg::levels, eostools::move(), reco::PFCandidate::muonRef(), dqmiodumpmetadata::n, Skims_PA_cff::name, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), TauSpinnerFilter_cfi::ntaus, edm::parameterSet(), hemisphereProducer_cfi::patTaus, pat::Tau::pfEssential_, pfTauIDContainerTokens_, pfTauIDTokens_, pfTauToken_, pat::PackedCandidate::phi(), pat::tau::TauPFEssential::phiAtEcalEntrance_, phID_, posAtECalEntranceComputer_, reco::PFCandidate::positionAtECALEntrance(), pat::tau::TauPFEssential::ptLeadChargedCand_, pTTauComparator_, 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(), skipMissingTauID_, jetUpdater_cfi::sort, edm::Provenance::stable(), AlCaHLTBitMon_QueryRunRegistry::string, summarizeEdmComparisonLogfiles::success, tauIDSrcContainers_, tauIDSrcs_, tauJetCorrFactorsTokens_, tauTransverseImpactParameterSrc_, tauTransverseImpactParameterToken_, HLT_2023v12_cff::track, reco::PFCandidate::trackRef(), userDataHelper_, and useUserData_.

280  {
281  // switch off embedding (in unschedules mode)
282  if (iEvent.isRealData()) {
283  addGenMatch_ = false;
284  embedGenMatch_ = false;
285  addGenJetMatch_ = false;
286  }
287 
288  // Get the collection of taus from the event
290  try {
291  iEvent.getByToken(baseTauToken_, anyTaus);
292  } catch (const edm::Exception& e) {
293  edm::LogWarning("DataSource") << "WARNING! No Tau collection found. This missing input will not block the job. "
294  "Instead, an empty tau collection is being be produced.";
295  auto patTaus = std::make_unique<std::vector<Tau>>();
296  iEvent.put(std::move(patTaus));
297  return;
298  }
299 
301 
302  if (isolator_.enabled())
303  isolator_.beginEvent(iEvent, iSetup);
304 
309 
310  std::vector<edm::Handle<edm::ValueMap<IsoDeposit>>> deposits(isoDepositTokens_.size());
311  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
312  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
313  }
314 
315  // prepare the MC matching
316  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> genMatches(genMatchTokens_.size());
317  if (addGenMatch_) {
318  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
319  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
320  }
321  }
322 
324  if (addGenJetMatch_)
325  iEvent.getByToken(genJetMatchToken_, genJetMatch);
326 
327  // read in the jet correction factors ValueMap
328  std::vector<edm::ValueMap<TauJetCorrFactors>> tauJetCorrs;
329  if (addTauJetCorrFactors_) {
330  for (size_t i = 0; i < tauJetCorrFactorsTokens_.size(); ++i) {
332  iEvent.getByToken(tauJetCorrFactorsTokens_[i], tauJetCorr);
333  tauJetCorrs.push_back(*tauJetCorr);
334  }
335  }
336 
337  auto patTaus = std::make_unique<std::vector<Tau>>();
338 
339  bool first = true; // this is introduced to issue warnings only for the first tau-jet
340  for (size_t idx = 0, ntaus = anyTaus->size(); idx < ntaus; ++idx) {
341  edm::RefToBase<reco::BaseTau> tausRef = anyTaus->refAt(idx);
342  edm::Ptr<reco::BaseTau> tausPtr = anyTaus->ptrAt(idx);
343 
344  Tau aTau(tausRef);
345  if (embedLeadTrack_)
346  aTau.embedLeadTrack();
347  if (embedSignalTracks_)
348  aTau.embedSignalTracks();
350  aTau.embedIsolationTracks();
351  if (embedLeadPFCand_) {
352  if (aTau.isPFTau())
353  aTau.embedLeadPFCand();
354  else
355  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
356  "from a reco::PFTau is impossible.\n";
357  }
359  if (aTau.isPFTau())
360  aTau.embedLeadPFChargedHadrCand();
361  else
362  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
363  "from a reco::PFTau is impossible.\n";
364  }
366  if (aTau.isPFTau())
367  aTau.embedLeadPFNeutralCand();
368  else
369  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
370  "from a reco::PFTau is impossible.\n";
371  }
372  if (embedSignalPFCands_) {
373  if (aTau.isPFTau())
374  aTau.embedSignalPFCands();
375  else
376  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
377  "from a reco::PFTau is impossible.\n";
378  }
380  if (aTau.isPFTau())
381  aTau.embedSignalPFChargedHadrCands();
382  else
383  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
384  "from a reco::PFTau is impossible.\n";
385  }
387  if (aTau.isPFTau())
388  aTau.embedSignalPFNeutralHadrCands();
389  else
390  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
391  "from a reco::PFTau is impossible.\n";
392  }
394  if (aTau.isPFTau())
395  aTau.embedSignalPFGammaCands();
396  else
397  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
398  "from a reco::PFTau is impossible.\n";
399  }
401  if (aTau.isPFTau())
402  aTau.embedIsolationPFCands();
403  else
404  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
405  "from a reco::PFTau is impossible.\n";
406  }
408  if (aTau.isPFTau())
409  aTau.embedIsolationPFChargedHadrCands();
410  else
411  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
412  "from a reco::PFTau is impossible.\n";
413  }
415  if (aTau.isPFTau())
416  aTau.embedIsolationPFNeutralHadrCands();
417  else
418  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
419  "from a reco::PFTau is impossible.\n";
420  }
422  if (aTau.isPFTau())
423  aTau.embedIsolationPFGammaCands();
424  else
425  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
426  "from a reco::PFTau is impossible.\n";
427  }
428 
429  if (addTauJetCorrFactors_) {
430  // add additional JetCorrs to the jet
431  for (unsigned int i = 0; i < tauJetCorrs.size(); ++i) {
432  const TauJetCorrFactors& tauJetCorr = tauJetCorrs[i][tausRef];
433  // uncomment for debugging
434  // tauJetCorr.print();
435  aTau.addJECFactors(tauJetCorr);
436  }
437  std::vector<std::string> levels = tauJetCorrs[0][tausRef].correctionLabels();
438  if (std::find(levels.begin(), levels.end(), "L2L3Residual") != levels.end()) {
439  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L2L3Residual"));
440  } else if (std::find(levels.begin(), levels.end(), "L3Absolute") != levels.end()) {
441  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L3Absolute"));
442  } else {
443  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("Uncorrected"));
444  if (first) {
445  edm::LogWarning("L3Absolute not found")
446  << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
447  << "of module " << tauJetCorrs[0][tausRef].jecSet() << " jets will remain"
448  << " uncorrected.";
449  first = false;
450  }
451  }
452  }
453 
454  // store the match to the generated final state muons
455  if (addGenMatch_) {
456  for (size_t i = 0, n = genMatches.size(); i < n; ++i) {
457  reco::GenParticleRef genTau = (*genMatches[i])[tausRef];
458  aTau.addGenParticleRef(genTau);
459  }
460  if (embedGenMatch_)
461  aTau.embedGenParticle();
462  }
463 
464  // store the match to the visible part of the generated tau
465  if (addGenJetMatch_) {
466  reco::GenJetRef genJetTau = (*genJetMatch)[tausRef];
467  if (genJetTau.isNonnull() && genJetTau.isAvailable()) {
468  aTau.setGenJet(genJetTau);
469  } // leave empty if no match found
470  }
471 
472  // prepare ID extraction
473  if (addTauID_) {
474  size_t numberPlainTauIds = tauIDSrcs_.size();
475  size_t numberTauIds = numberPlainTauIds;
476  for (auto const& it : tauIDSrcContainers_) {
477  numberTauIds += it.size();
478  }
479  // if ID containers exist, product incices need to be retrieved from provenanceConfigLabel.
480  // This is done if config history changes, in particular for the first event.
481  if (numberPlainTauIds != numberTauIds && phID_ != iEvent.processHistoryID()) {
482  phID_ = iEvent.processHistoryID();
483  for (size_t idx = 0; idx < tauIDSrcContainers_.size(); ++idx) {
484  auto pfTauIdDiscr = iEvent.getHandle(pfTauIDContainerTokens_[idx]);
485  if (!pfTauIdDiscr.isValid())
486  continue; // missing IDs will be skipped lateron or crash there depending on skipMissingTauID_
487  const edm::Provenance* prov = pfTauIdDiscr.provenance();
488  for (NameWPIdx& idcfg : tauIDSrcContainers_[idx]) {
489  std::string prov_cfg_label = idcfg.second.first.first;
490  std::string prov_ID_label = idcfg.second.first.second;
491  bool found = false;
492  if (prov_cfg_label == "rawValues" || prov_cfg_label == "workingPoints") {
493  const std::vector<std::string> psetsFromProvenance =
494  edm::parameterSet(prov->stable(), iEvent.processHistory())
495  .getParameter<std::vector<std::string>>(prov_cfg_label);
496  for (size_t i = 0; i < psetsFromProvenance.size(); ++i) {
497  if (psetsFromProvenance[i] == prov_ID_label) {
498  // using negative indices for raw values
499  if (prov_cfg_label == "rawValues")
500  idcfg.second.second = -1 - i;
501  else
502  idcfg.second.second = i;
503  found = true;
504  }
505  }
506  } else if (prov_cfg_label == "IDdefinitions" || prov_cfg_label == "IDWPdefinitions") {
507  const std::vector<edm::ParameterSet> psetsFromProvenance =
508  edm::parameterSet(prov->stable(), iEvent.processHistory())
509  .getParameter<std::vector<edm::ParameterSet>>(prov_cfg_label);
510  for (size_t i = 0; i < psetsFromProvenance.size(); ++i) {
511  if (psetsFromProvenance[i].getParameter<std::string>("IDname") == prov_ID_label) {
512  // using negative indices for raw values
513  if (prov_cfg_label == "IDdefinitions")
514  idcfg.second.second = -1 - i;
515  else
516  idcfg.second.second = i;
517  found = true;
518  }
519  }
520  } else {
521  // checked prov_cfg_label before, so it must be a direct access via indices
522  try {
523  int i = std::stoi(prov_ID_label);
524  if (prov_cfg_label == "direct_rawValues")
525  idcfg.second.second = -1 - i;
526  else
527  idcfg.second.second = i;
528  found = true;
529  } catch (std::invalid_argument const& e) {
530  throw cms::Exception("Configuration") << "PATTauProducer: Direct access to ID container requested, so "
531  "argument of 'idLabel' must be convertable to int!\n";
532  }
533  }
534  if (!found) {
535  throw cms::Exception("Configuration") << "PATTauProducer: Requested working point '" << prov_ID_label
536  << "' for ID '" << idcfg.first << "' not found!\n";
537  }
538  }
539  }
540  }
541  std::string missingDiscriminators;
542  std::vector<pat::Tau::IdPair> ids(numberTauIds);
543  auto const& tausDeref = *tausRef;
544  if (typeid(tausDeref) == typeid(reco::PFTau)) {
545  edm::Handle<reco::PFTauCollection> pfTauCollection;
546  iEvent.getByToken(pfTauToken_, pfTauCollection);
547  for (size_t i = 0; i < numberPlainTauIds; ++i) {
548  //std::cout << "filling PFTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
549 
550  auto pfTauIdDiscr = iEvent.getHandle(pfTauIDTokens_[i]);
551 
552  if (skipMissingTauID_ && !pfTauIdDiscr.isValid()) {
553  if (!missingDiscriminators.empty()) {
554  missingDiscriminators += ", ";
555  }
556  missingDiscriminators += tauIDSrcs_[i].first;
557  continue;
558  }
559  ids[i].first = tauIDSrcs_[i].first;
560  ids[i].second = getTauIdDiscriminator(pfTauCollection, idx, pfTauIdDiscr);
561  }
562  for (size_t i = 0; i < tauIDSrcContainers_.size(); ++i) {
563  auto pfTauIdDiscr = iEvent.getHandle(pfTauIDContainerTokens_[i]);
564  if (skipMissingTauID_ && !pfTauIdDiscr.isValid()) {
565  for (auto const& it : tauIDSrcContainers_[i]) {
566  if (!missingDiscriminators.empty()) {
567  missingDiscriminators += ", ";
568  }
569  missingDiscriminators += it.first;
570  }
571  continue;
572  }
573  for (size_t j = 0; j < tauIDSrcContainers_[i].size(); ++j) {
574  ids[numberPlainTauIds + j].first = tauIDSrcContainers_[i][j].first;
575  ids[numberPlainTauIds + j].second = getTauIdDiscriminatorFromContainer(
576  pfTauCollection, idx, pfTauIdDiscr, tauIDSrcContainers_[i][j].second.second);
577  }
578  numberPlainTauIds += tauIDSrcContainers_[i].size();
579  }
580  } else {
581  throw cms::Exception("Type Mismatch")
582  << "PATTauProducer: unsupported datatype '" << typeid(tausDeref).name() << "' for tauSource\n";
583  }
584  if (!missingDiscriminators.empty() && firstOccurence_) {
585  edm::LogWarning("DataSource") << "The following tau discriminators have not been found in the event:\n"
586  << missingDiscriminators << "\n"
587  << "They will not be embedded into the pat::Tau object.\n"
588  << "Note: this message will be printed only at first occurence.";
589  firstOccurence_ = false;
590  }
591  aTau.setTauIDs(ids);
592  }
593 
594  // extraction of reconstructed tau decay mode
595  // (only available for PFTaus)
596  if (aTau.isPFTau()) {
598  iEvent.getByToken(pfTauToken_, pfTaus);
599  reco::PFTauRef pfTauRef(pfTaus, idx);
600 
601  aTau.setDecayMode(pfTauRef->decayMode());
602  }
603 
604  // extraction of variables needed to rerun MVA isolation and anti-electron discriminator on MiniAOD
605  if (!aTau.pfEssential_.empty()) {
607  iEvent.getByToken(pfTauToken_, pfTaus);
608  reco::PFTauRef pfTauRef(pfTaus, idx);
609  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
610  float ecalEnergy = 0;
611  float hcalEnergy = 0;
612  float sumPhiTimesEnergy = 0.;
613  float sumEtaTimesEnergy = 0.;
614  float sumEnergy = 0.;
615  float leadChargedCandPt = -99;
616  float leadChargedCandEtaAtEcalEntrance = -99;
617  const std::vector<reco::CandidatePtr>& signalCands = pfTauRef->signalCands();
618  for (const auto& it : signalCands) {
619  const reco::PFCandidate* ipfcand = dynamic_cast<const reco::PFCandidate*>(it.get());
620  if (ipfcand != nullptr) {
621  ecalEnergy += ipfcand->ecalEnergy();
622  hcalEnergy += ipfcand->hcalEnergy();
623  sumPhiTimesEnergy += ipfcand->positionAtECALEntrance().phi() * ipfcand->energy();
624  sumEtaTimesEnergy += ipfcand->positionAtECALEntrance().eta() * ipfcand->energy();
625  sumEnergy += ipfcand->energy();
626  const reco::Track* track = nullptr;
627  if (ipfcand->trackRef().isNonnull())
628  track = ipfcand->trackRef().get();
629  else if (ipfcand->muonRef().isNonnull() && ipfcand->muonRef()->innerTrack().isNonnull())
630  track = ipfcand->muonRef()->innerTrack().get();
631  else if (ipfcand->muonRef().isNonnull() && ipfcand->muonRef()->globalTrack().isNonnull())
632  track = ipfcand->muonRef()->globalTrack().get();
633  else if (ipfcand->muonRef().isNonnull() && ipfcand->muonRef()->outerTrack().isNonnull())
634  track = ipfcand->muonRef()->outerTrack().get();
635  else if (ipfcand->gsfTrackRef().isNonnull())
636  track = ipfcand->gsfTrackRef().get();
637  if (track) {
638  if (track->pt() > leadChargedCandPt) {
639  leadChargedCandEtaAtEcalEntrance = ipfcand->positionAtECALEntrance().eta();
640  leadChargedCandPt = track->pt();
641  }
642  }
643  } else {
644  // TauReco@MiniAOD: individual ECAL and HCAL energies recovered from fractions,
645  // and position at ECAL entrance computed on-the-fly
646  const pat::PackedCandidate* ipatcand = dynamic_cast<const pat::PackedCandidate*>(it.get());
647  if (ipatcand != nullptr) {
648  ecalEnergy += ipatcand->caloFraction() * ipatcand->energy() * (1. - ipatcand->hcalFraction());
649  hcalEnergy += ipatcand->caloFraction() * ipatcand->energy() * ipatcand->hcalFraction();
650  double posAtECal_phi = ipatcand->phi();
651  double posAtECal_eta = ipatcand->eta();
652  bool success = false;
653  reco::Candidate::Point posAtECalEntrance = posAtECalEntranceComputer_(ipatcand, success);
654  if (success) {
655  posAtECal_phi = posAtECalEntrance.phi();
656  posAtECal_eta = posAtECalEntrance.eta();
657  }
658  sumPhiTimesEnergy += posAtECal_phi * ipatcand->energy();
659  sumEtaTimesEnergy += posAtECal_eta * ipatcand->energy();
660  sumEnergy += ipatcand->energy();
661  const reco::Track* track = ipatcand->bestTrack();
662  if (track != nullptr) {
663  if (track->pt() > leadChargedCandPt) {
664  leadChargedCandEtaAtEcalEntrance = posAtECal_eta;
665  leadChargedCandPt = track->pt();
666  }
667  }
668  }
669  }
670  }
671  aTauPFEssential.ecalEnergy_ = ecalEnergy;
672  aTauPFEssential.hcalEnergy_ = hcalEnergy;
673  aTauPFEssential.ptLeadChargedCand_ = leadChargedCandPt;
674  aTauPFEssential.etaAtEcalEntranceLeadChargedCand_ = leadChargedCandEtaAtEcalEntrance;
675  if (sumEnergy != 0.) {
676  aTauPFEssential.phiAtEcalEntrance_ = sumPhiTimesEnergy / sumEnergy;
677  aTauPFEssential.etaAtEcalEntrance_ = sumEtaTimesEnergy / sumEnergy;
678  } else {
679  aTauPFEssential.phiAtEcalEntrance_ = -99.;
680  aTauPFEssential.etaAtEcalEntrance_ = -99.;
681  }
682  float leadingTrackNormChi2 = 0;
683  float ecalEnergyLeadChargedHadrCand = -99.;
684  float hcalEnergyLeadChargedHadrCand = -99.;
685  float emFraction = -1.;
686  float myHCALenergy = 0.;
687  float myECALenergy = 0.;
688  const reco::CandidatePtr& leadingPFCharged = pfTauRef->leadChargedHadrCand();
689  if (leadingPFCharged.isNonnull()) {
690  const reco::PFCandidate* pfCandPtr = dynamic_cast<const reco::PFCandidate*>(leadingPFCharged.get());
691  if (pfCandPtr != nullptr) { // PFTau made from PFCandidates
692  ecalEnergyLeadChargedHadrCand = pfCandPtr->ecalEnergy();
693  hcalEnergyLeadChargedHadrCand = pfCandPtr->hcalEnergy();
694  reco::TrackRef trackRef = pfCandPtr->trackRef();
695  if (trackRef.isNonnull()) {
696  leadingTrackNormChi2 = trackRef->normalizedChi2();
697  for (const auto& isoPFCand : pfTauRef->isolationPFCands()) {
698  myHCALenergy += isoPFCand->hcalEnergy();
699  myECALenergy += isoPFCand->ecalEnergy();
700  }
701  for (const auto& signalPFCand : pfTauRef->signalPFCands()) {
702  myHCALenergy += signalPFCand->hcalEnergy();
703  myECALenergy += signalPFCand->ecalEnergy();
704  }
705  if (myHCALenergy + myECALenergy != 0.) {
706  emFraction = myECALenergy / (myHCALenergy + myECALenergy);
707  }
708  }
709  } else {
710  const pat::PackedCandidate* packedCandPtr = dynamic_cast<const pat::PackedCandidate*>(leadingPFCharged.get());
711  if (packedCandPtr != nullptr) {
712  // TauReco@MiniAOD: individual ECAL and HCAL energies recovered from fractions,
713  // and position at ECAL entrance computed on-the-fly
714  ecalEnergyLeadChargedHadrCand =
715  packedCandPtr->caloFraction() * packedCandPtr->energy() * (1. - packedCandPtr->hcalFraction());
716  hcalEnergyLeadChargedHadrCand =
717  packedCandPtr->caloFraction() * packedCandPtr->energy() * packedCandPtr->hcalFraction();
718  const reco::Track* track = packedCandPtr->bestTrack();
719  if (track != nullptr) {
720  leadingTrackNormChi2 = track->normalizedChi2();
721  for (const auto& isoCand : pfTauRef->isolationCands()) {
722  //can safely use static_cast as it is ensured that this PFTau is
723  //built with packedCands as its leadingCanidate
724  const pat::PackedCandidate* isoPackedCand = static_cast<const pat::PackedCandidate*>(isoCand.get());
725  myHCALenergy += isoPackedCand->caloFraction() * isoPackedCand->energy() * isoPackedCand->hcalFraction();
726  myECALenergy +=
727  isoPackedCand->caloFraction() * isoPackedCand->energy() * (1. - isoPackedCand->hcalFraction());
728  }
729  for (const auto& signalCand : pfTauRef->signalCands()) {
730  //can safely use static_cast as it is ensured that this PFTau is
731  //built with packedCands as its leadingCanidate
732  const pat::PackedCandidate* sigPackedCand = static_cast<const pat::PackedCandidate*>(signalCand.get());
733  myHCALenergy += sigPackedCand->caloFraction() * sigPackedCand->energy() * sigPackedCand->hcalFraction();
734  myECALenergy +=
735  sigPackedCand->caloFraction() * sigPackedCand->energy() * (1. - sigPackedCand->hcalFraction());
736  }
737  if (myHCALenergy + myECALenergy != 0.) {
738  emFraction = myECALenergy / (myHCALenergy + myECALenergy);
739  }
740  }
741  }
742  }
743  }
744 
745  aTauPFEssential.emFraction_ = emFraction;
746  aTauPFEssential.leadingTrackNormChi2_ = leadingTrackNormChi2;
747  aTauPFEssential.ecalEnergyLeadChargedHadrCand_ = ecalEnergyLeadChargedHadrCand;
748  aTauPFEssential.hcalEnergyLeadChargedHadrCand_ = hcalEnergyLeadChargedHadrCand;
749  // extraction of tau lifetime information
750  if (!tauTransverseImpactParameterSrc_.label().empty()) {
751  edm::Handle<PFTauTIPAssociationByRef> tauLifetimeInfos;
752  iEvent.getByToken(tauTransverseImpactParameterToken_, tauLifetimeInfos);
753  const reco::PFTauTransverseImpactParameter& tauLifetimeInfo = *(*tauLifetimeInfos)[pfTauRef];
754  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
755  aTauPFEssential.dxy_PCA_ = tauLifetimeInfo.dxy_PCA();
756  aTauPFEssential.dxy_ = tauLifetimeInfo.dxy();
757  aTauPFEssential.dxy_error_ = tauLifetimeInfo.dxy_error();
758  aTauPFEssential.hasSV_ = tauLifetimeInfo.hasSecondaryVertex();
759  aTauPFEssential.flightLength_ = tauLifetimeInfo.flightLength();
760  aTauPFEssential.flightLengthSig_ = tauLifetimeInfo.flightLengthSig();
761  aTauPFEssential.ip3d_ = tauLifetimeInfo.ip3d();
762  aTauPFEssential.ip3d_error_ = tauLifetimeInfo.ip3d_error();
763  }
764  }
765 
766  // Isolation
767  if (isolator_.enabled()) {
769  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
770  // better to loop backwards, so the vector is resized less times
771  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
772  ed = isolatorTmpStorage_.rend();
773  it != ed;
774  ++it) {
775  aTau.setIsolation(it->first, it->second);
776  }
777  }
778 
779  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
780  aTau.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[tausRef]);
781  }
782 
783  if (efficiencyLoader_.enabled()) {
784  efficiencyLoader_.setEfficiencies(aTau, tausRef);
785  }
786 
787  if (resolutionLoader_.enabled()) {
789  }
790 
791  if (useUserData_) {
792  userDataHelper_.add(aTau, iEvent, iSetup);
793  }
794 
795  patTaus->push_back(aTau);
796  }
797 
798  // sort taus in pT
799  std::sort(patTaus->begin(), patTaus->end(), pTTauComparator_);
800 
801  // put genEvt object in Event
802  iEvent.put(std::move(patTaus));
803 
804  // clean up
805  if (isolator_.enabled())
807 }
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:469
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:55
void beginEvent(const edm::EventSetup &)
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
pat::helper::EfficiencyLoader efficiencyLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:388
float getTauIdDiscriminator(const edm::Handle< TauCollectionType > &, size_t, const edm::Handle< TauDiscrType > &)
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
std::string const & label() const
Definition: InputTag.h:36
float caloFraction() const
Set the fraction of ECAL+HCAL energy over candidate energy.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > pfTauIDContainerTokens_
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:84
bool embedIsolationPFChargedHadrCands_
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
edm::EDGetTokenT< PFTauTIPAssociationByRef > tauTransverseImpactParameterToken_
double eta() const override
momentum pseudorapidity
pat::helper::MultiIsolator isolator_
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:233
edm::EDGetTokenT< edm::View< reco::BaseTau > > baseTauToken_
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
bool embedIsolationPFNeutralHadrCands_
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
bool isAvailable() const
Definition: Ref.h:541
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
float getTauIdDiscriminatorFromContainer(const edm::Handle< reco::PFTauCollection > &, size_t, const edm::Handle< reco::TauDiscriminatorContainer > &, int)
pat::PATUserDataHelper< pat::Tau > userDataHelper_
genJetMatch
switch on/off embedding of matched genJet&#39;s
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:221
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:450
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
Definition: Tau.py:1
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:17
std::vector< edm::EDGetTokenT< edm::ValueMap< TauJetCorrFactors > > > tauJetCorrFactorsTokens_
edm::InputTag tauTransverseImpactParameterSrc_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
std::pair< std::string, WPIdx > NameWPIdx
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
float hcalFraction() const
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
double energy() const override
energy
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:437
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
Log< level::Warning, false > LogWarning
edm::ProcessHistoryID phID_
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > pfTauIDTokens_
StableProvenance const & stable() const
Definition: Provenance.h:42
std::vector< NameTag > tauIDSrcs_
edm::EDGetTokenT< reco::PFTauCollection > pfTauToken_
def move(src, dest)
Definition: eostools.py:511
double phi() const override
momentum azimuthal angle
GreaterByPt< Tau > pTTauComparator_
PositionAtECalEntranceComputer posAtECalEntranceComputer_
double energy() const final
energy

Member Data Documentation

◆ addEfficiencies_

bool pat::PATTauProducer::addEfficiencies_
private

Definition at line 120 of file PATTauProducer.cc.

Referenced by PATTauProducer().

◆ addGenJetMatch_

bool pat::PATTauProducer::addGenJetMatch_
private

Definition at line 92 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ addGenMatch_

bool pat::PATTauProducer::addGenMatch_
private

Definition at line 88 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ addResolutions_

bool pat::PATTauProducer::addResolutions_
private

Definition at line 123 of file PATTauProducer.cc.

Referenced by PATTauProducer().

◆ addTauID_

bool pat::PATTauProducer::addTauID_
private

Definition at line 99 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ addTauJetCorrFactors_

bool pat::PATTauProducer::addTauJetCorrFactors_
private

Definition at line 96 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ baseTauToken_

edm::EDGetTokenT<edm::View<reco::BaseTau> > pat::PATTauProducer::baseTauToken_
private

Definition at line 69 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ efficiencyLoader_

pat::helper::EfficiencyLoader pat::PATTauProducer::efficiencyLoader_
private

Definition at line 121 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedGenJetMatch_

bool pat::PATTauProducer::embedGenJetMatch_
private

Definition at line 93 of file PATTauProducer.cc.

Referenced by PATTauProducer().

◆ embedGenMatch_

bool pat::PATTauProducer::embedGenMatch_
private

Definition at line 89 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedIsolationPFCands_

bool pat::PATTauProducer::embedIsolationPFCands_
private

Definition at line 83 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedIsolationPFChargedHadrCands_

bool pat::PATTauProducer::embedIsolationPFChargedHadrCands_
private

Definition at line 84 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedIsolationPFGammaCands_

bool pat::PATTauProducer::embedIsolationPFGammaCands_
private

Definition at line 86 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedIsolationPFNeutralHadrCands_

bool pat::PATTauProducer::embedIsolationPFNeutralHadrCands_
private

Definition at line 85 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedIsolationTracks_

bool pat::PATTauProducer::embedIsolationTracks_
private

Definition at line 73 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedLeadPFCand_

bool pat::PATTauProducer::embedLeadPFCand_
private

Definition at line 76 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedLeadPFChargedHadrCand_

bool pat::PATTauProducer::embedLeadPFChargedHadrCand_
private

Definition at line 77 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedLeadPFNeutralCand_

bool pat::PATTauProducer::embedLeadPFNeutralCand_
private

Definition at line 78 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedLeadTrack_

bool pat::PATTauProducer::embedLeadTrack_
private

Definition at line 74 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedSignalPFCands_

bool pat::PATTauProducer::embedSignalPFCands_
private

Definition at line 79 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedSignalPFChargedHadrCands_

bool pat::PATTauProducer::embedSignalPFChargedHadrCands_
private

Definition at line 80 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedSignalPFGammaCands_

bool pat::PATTauProducer::embedSignalPFGammaCands_
private

Definition at line 82 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedSignalPFNeutralHadrCands_

bool pat::PATTauProducer::embedSignalPFNeutralHadrCands_
private

Definition at line 81 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ embedSignalTracks_

bool pat::PATTauProducer::embedSignalTracks_
private

Definition at line 75 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ firstOccurence_

bool pat::PATTauProducer::firstOccurence_
private

Definition at line 66 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ genJetMatchToken_

edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > pat::PATTauProducer::genJetMatchToken_
private

Definition at line 94 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ genMatchTokens_

std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection> > > pat::PATTauProducer::genMatchTokens_
private

Definition at line 90 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ isoDepositLabels_

std::vector<std::pair<pat::IsolationKeys, edm::InputTag> > pat::PATTauProducer::isoDepositLabels_
private

Definition at line 117 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ isoDepositTokens_

std::vector<edm::EDGetTokenT<edm::ValueMap<IsoDeposit> > > pat::PATTauProducer::isoDepositTokens_
private

Definition at line 118 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ isolator_

pat::helper::MultiIsolator pat::PATTauProducer::isolator_
private

Definition at line 115 of file PATTauProducer.cc.

Referenced by produce().

◆ isolatorTmpStorage_

pat::helper::MultiIsolator::IsolationValuePairs pat::PATTauProducer::isolatorTmpStorage_
private

Definition at line 116 of file PATTauProducer.cc.

Referenced by produce().

◆ pfTauIDContainerTokens_

std::vector<edm::EDGetTokenT<reco::TauDiscriminatorContainer> > pat::PATTauProducer::pfTauIDContainerTokens_
private

Definition at line 109 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ pfTauIDTokens_

std::vector<edm::EDGetTokenT<reco::PFTauDiscriminator> > pat::PATTauProducer::pfTauIDTokens_
private

Definition at line 108 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ pfTauToken_

edm::EDGetTokenT<reco::PFTauCollection> pat::PATTauProducer::pfTauToken_
private

Definition at line 71 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ phID_

edm::ProcessHistoryID pat::PATTauProducer::phID_
private

Definition at line 111 of file PATTauProducer.cc.

Referenced by produce().

◆ posAtECalEntranceComputer_

PositionAtECalEntranceComputer pat::PATTauProducer::posAtECalEntranceComputer_
private

Definition at line 136 of file PATTauProducer.cc.

Referenced by produce().

◆ pTTauComparator_

GreaterByPt<Tau> pat::PATTauProducer::pTTauComparator_
private

Definition at line 113 of file PATTauProducer.cc.

Referenced by produce().

◆ resolutionLoader_

pat::helper::KinResolutionsLoader pat::PATTauProducer::resolutionLoader_
private

Definition at line 124 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ skipMissingTauID_

bool pat::PATTauProducer::skipMissingTauID_
private

Definition at line 110 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ tauIDSrcContainers_

std::vector<std::vector<NameWPIdx> > pat::PATTauProducer::tauIDSrcContainers_
private

Definition at line 107 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ tauIDSrcs_

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

Definition at line 106 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ tauJetCorrFactorsTokens_

std::vector<edm::EDGetTokenT<edm::ValueMap<TauJetCorrFactors> > > pat::PATTauProducer::tauJetCorrFactorsTokens_
private

Definition at line 97 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ tauTransverseImpactParameterSrc_

edm::InputTag pat::PATTauProducer::tauTransverseImpactParameterSrc_
private

Definition at line 72 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ tauTransverseImpactParameterToken_

edm::EDGetTokenT<PFTauTIPAssociationByRef> pat::PATTauProducer::tauTransverseImpactParameterToken_
private

Definition at line 70 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ userDataHelper_

pat::PATUserDataHelper<pat::Tau> pat::PATTauProducer::userDataHelper_
private

Definition at line 127 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().

◆ useUserData_

bool pat::PATTauProducer::useUserData_
private

Definition at line 126 of file PATTauProducer.cc.

Referenced by PATTauProducer(), and produce().