CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Attributes
PATTauIDEmbedder Class Reference
Inheritance diagram for PATTauIDEmbedder:
edm::stream::EDProducer<>

Public Member Functions

 PATTauIDEmbedder (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PATTauIDEmbedder () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Types

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

Private Attributes

size_t nNewPlainTauIds_
 
size_t nNewTauIds_
 
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > patTauIDContainerTokens_
 
std::vector< edm::EDGetTokenT< pat::PATTauDiscriminator > > patTauIDTokens_
 
edm::EDGetTokenT< pat::TauCollectionsrc_
 
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
 
std::vector< NameTagtauIDSrcs_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 11 of file PATTauIDEmbedder.cc.

Member Typedef Documentation

◆ IDContainerData

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

Definition at line 24 of file PATTauIDEmbedder.cc.

◆ NameTag

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

Definition at line 21 of file PATTauIDEmbedder.cc.

◆ NameWPIdx

typedef std::pair<std::string, int> PATTauIDEmbedder::NameWPIdx
private

Definition at line 22 of file PATTauIDEmbedder.cc.

Constructor & Destructor Documentation

◆ PATTauIDEmbedder()

PATTauIDEmbedder::PATTauIDEmbedder ( const edm::ParameterSet cfg)
explicit

Definition at line 33 of file PATTauIDEmbedder.cc.

33  {
34  src_ = consumes<pat::TauCollection>(cfg.getParameter<edm::InputTag>("src"));
35  // read the different tau ID names
36  edm::ParameterSet idps = cfg.getParameter<edm::ParameterSet>("tauIDSources");
37  std::vector<std::string> names = idps.getParameterNamesForType<edm::ParameterSet>();
38  std::map<std::string, IDContainerData> idContainerMap;
39  for (auto const& name : names) {
41  int wpidx = idp.getParameter<int>("workingPointIndex");
42  edm::InputTag tag = idp.getParameter<edm::InputTag>("inputTag");
43  if (wpidx == -99) {
44  tauIDSrcs_.push_back(NameTag(name, tag));
45  } else {
46  std::map<std::string, IDContainerData>::iterator it;
47  it = idContainerMap.insert({tag.label() + tag.instance(), {tag, std::vector<NameWPIdx>()}}).first;
48  it->second.second.push_back(NameWPIdx(name, wpidx));
49  }
50  }
51  // but in any case at least once
52  if (tauIDSrcs_.empty() && idContainerMap.empty())
53  throw cms::Exception("Configuration") << "PATTauProducer: id addTauID is true, you must specify:\n"
54  << "\tPSet tauIDSources = { \n"
55  << "\t\tInputTag <someName> = <someTag> // as many as you want \n "
56  << "\t}\n";
57  for (auto const& mapEntry : idContainerMap) {
58  tauIDSrcContainers_.push_back(mapEntry.second.second);
59  patTauIDContainerTokens_.push_back(mayConsume<reco::TauDiscriminatorContainer>(mapEntry.second.first));
60  }
62  tauIDSrcs_, [this](NameTag const& tag) { return mayConsume<pat::PATTauDiscriminator>(tag.second); });
65  for (auto const& cont : tauIDSrcContainers_) {
66  nNewTauIds_ += cont.size();
67  }
68 
69  produces<std::vector<pat::Tau> >();
70 }

References looper::cfg, generateEDF::cont, dqmdumpme::first, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), Skims_PA_cff::name, names, nNewPlainTauIds_, nNewTauIds_, patTauIDContainerTokens_, patTauIDTokens_, src_, GlobalPosition_Frontier_DevDB_cff::tag, tauIDSrcContainers_, tauIDSrcs_, and edm::vector_transform().

◆ ~PATTauIDEmbedder()

PATTauIDEmbedder::~PATTauIDEmbedder ( )
inlineoverride

Definition at line 14 of file PATTauIDEmbedder.cc.

14 {};

Member Function Documentation

◆ produce()

void PATTauIDEmbedder::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 72 of file PATTauIDEmbedder.cc.

72  {
74  evt.getByToken(src_, inputTaus);
75 
76  auto outputTaus = std::make_unique<std::vector<pat::Tau> >();
77  outputTaus->reserve(inputTaus->size());
78 
79  int tau_idx = 0;
80  for (pat::TauCollection::const_iterator inputTau = inputTaus->begin(); inputTau != inputTaus->end();
81  ++inputTau, ++tau_idx) {
82  pat::Tau outputTau(*inputTau);
83  pat::TauRef inputTauRef(inputTaus, tau_idx);
84  size_t nTauIds = inputTau->tauIDs().size();
85  std::vector<pat::Tau::IdPair> tauIds(nTauIds + nNewTauIds_);
86 
87  // copy IDs that are already stored in PAT taus
88  for (size_t i = 0; i < nTauIds; ++i) {
89  tauIds[i] = inputTau->tauIDs().at(i);
90  }
91 
92  // store IDs that were produced in PATTauDiscriminator format
94  for (size_t i = 0; i < nNewPlainTauIds_; ++i) {
95  evt.getByToken(patTauIDTokens_[i], tauDiscr);
96  tauIds[nTauIds + i].first = tauIDSrcs_[i].first;
97  tauIds[nTauIds + i].second = (*tauDiscr)[inputTauRef];
98  }
99 
100  // store IDs that were produced in PATTauDiscriminatorContainer format
101  size_t nEmbeddedIDs = nTauIds + nNewPlainTauIds_;
102  for (size_t i = 0; i < tauIDSrcContainers_.size(); ++i) {
103  auto const& tauDiscrCont = evt.get(patTauIDContainerTokens_[i]);
104  for (size_t j = 0; j < tauIDSrcContainers_[i].size(); ++j) {
105  tauIds[nEmbeddedIDs + j].first = tauIDSrcContainers_[i][j].first;
106  int wpIdx = tauIDSrcContainers_[i][j].second;
107  if (wpIdx < 0) {
108  if (tauDiscrCont[inputTauRef].rawValues.size() == 1)
109  //Only 0th component filled with default value if prediscriminor in PatTauDiscriminator failed.
110  tauIds[nEmbeddedIDs + j].second = tauDiscrCont[inputTauRef].rawValues.at(0);
111  else
112  //uses negative indices to access rawValues. In most cases only one rawValue at WPIdx=-1 exists.
113  tauIds[nEmbeddedIDs + j].second = tauDiscrCont[inputTauRef].rawValues.at(-1 - wpIdx);
114  } else {
115  if (tauDiscrCont[inputTauRef].workingPoints.empty())
116  //WP vector not filled if prediscriminor in PatTauDiscriminator failed. Set PAT output to false in this case
117  tauIds[nEmbeddedIDs + j].second = 0.0;
118  else
119  tauIds[nEmbeddedIDs + j].second = tauDiscrCont[inputTauRef].workingPoints.at(wpIdx);
120  }
121  }
122  nEmbeddedIDs += tauIDSrcContainers_[i].size();
123  }
124 
125  outputTau.setTauIDs(tauIds);
126  outputTaus->push_back(outputTau);
127  }
128 
129  evt.put(std::move(outputTaus));
130 }

References edm::Event::get(), edm::Event::getByToken(), mps_fire::i, dqmiolumiharvest::j, eostools::move(), nNewPlainTauIds_, nNewTauIds_, patTauIDContainerTokens_, patTauIDTokens_, edm::Event::put(), PDWG_TauSkim_cff::rawValues, edm::second(), pat::Tau::setTauIDs(), src_, tauIDSrcContainers_, tauIDSrcs_, and PDWG_TauSkim_cff::workingPoints.

Member Data Documentation

◆ nNewPlainTauIds_

size_t PATTauIDEmbedder::nNewPlainTauIds_
private

Definition at line 29 of file PATTauIDEmbedder.cc.

Referenced by PATTauIDEmbedder(), and produce().

◆ nNewTauIds_

size_t PATTauIDEmbedder::nNewTauIds_
private

Definition at line 30 of file PATTauIDEmbedder.cc.

Referenced by PATTauIDEmbedder(), and produce().

◆ patTauIDContainerTokens_

std::vector<edm::EDGetTokenT<reco::TauDiscriminatorContainer> > PATTauIDEmbedder::patTauIDContainerTokens_
private

Definition at line 28 of file PATTauIDEmbedder.cc.

Referenced by PATTauIDEmbedder(), and produce().

◆ patTauIDTokens_

std::vector<edm::EDGetTokenT<pat::PATTauDiscriminator> > PATTauIDEmbedder::patTauIDTokens_
private

Definition at line 27 of file PATTauIDEmbedder.cc.

Referenced by PATTauIDEmbedder(), and produce().

◆ src_

edm::EDGetTokenT<pat::TauCollection> PATTauIDEmbedder::src_
private

Definition at line 20 of file PATTauIDEmbedder.cc.

Referenced by PATTauIDEmbedder(), and produce().

◆ tauIDSrcContainers_

std::vector<std::vector<NameWPIdx> > PATTauIDEmbedder::tauIDSrcContainers_
private

Definition at line 26 of file PATTauIDEmbedder.cc.

Referenced by PATTauIDEmbedder(), and produce().

◆ tauIDSrcs_

std::vector<NameTag> PATTauIDEmbedder::tauIDSrcs_
private

Definition at line 25 of file PATTauIDEmbedder.cc.

Referenced by PATTauIDEmbedder(), and produce().

PDWG_TauSkim_cff.rawValues
rawValues
Definition: PDWG_TauSkim_cff.py:13
PATTauIDEmbedder::patTauIDContainerTokens_
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > patTauIDContainerTokens_
Definition: PATTauIDEmbedder.cc:28
mps_fire.i
i
Definition: mps_fire.py:355
PATTauIDEmbedder::src_
edm::EDGetTokenT< pat::TauCollection > src_
Definition: PATTauIDEmbedder.cc:20
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
generateEDF.cont
cont
load Luminosity info ##
Definition: generateEDF.py:629
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
PATTauIDEmbedder::patTauIDTokens_
std::vector< edm::EDGetTokenT< pat::PATTauDiscriminator > > patTauIDTokens_
Definition: PATTauIDEmbedder.cc:27
edm::Handle
Definition: AssociativeIterator.h:50
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edm::Ref
Definition: AssociativeIterator.h:58
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:122
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
PATTauIDEmbedder::tauIDSrcs_
std::vector< NameTag > tauIDSrcs_
Definition: PATTauIDEmbedder.cc:25
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
PATTauIDEmbedder::NameWPIdx
std::pair< std::string, int > NameWPIdx
Definition: PATTauIDEmbedder.cc:22
edm::vector_transform
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
PATTauIDEmbedder::nNewTauIds_
size_t nNewTauIds_
Definition: PATTauIDEmbedder.cc:30
edm::ParameterSet
Definition: ParameterSet.h:36
PDWG_TauSkim_cff.workingPoints
workingPoints
Definition: PDWG_TauSkim_cff.py:15
edm::ParameterSet::getParameterNamesForType
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:168
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:132
PATTauIDEmbedder::nNewPlainTauIds_
size_t nNewPlainTauIds_
Definition: PATTauIDEmbedder.cc:29
looper.cfg
cfg
Definition: looper.py:297
PATTauIDEmbedder::tauIDSrcContainers_
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
Definition: PATTauIDEmbedder.cc:26
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
cms::Exception
Definition: Exception.h:70
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
PATTauIDEmbedder::NameTag
std::pair< std::string, edm::InputTag > NameTag
Definition: PATTauIDEmbedder.cc:21
edm::Event::get
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:337
edm::InputTag
Definition: InputTag.h:15