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
 
 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
 

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<>
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

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.

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

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 }
std::vector< edm::EDGetTokenT< pat::PATTauDiscriminator > > patTauIDTokens_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< NameTag > tauIDSrcs_
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< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:180
edm::EDGetTokenT< pat::TauCollection > src_
std::pair< std::string, int > NameWPIdx
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
std::pair< std::string, edm::InputTag > NameTag
cont
load Luminosity info ##
Definition: generateEDF.py:620
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > patTauIDContainerTokens_

◆ ~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.

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.

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 }
std::vector< edm::EDGetTokenT< pat::PATTauDiscriminator > > patTauIDTokens_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:344
std::vector< NameTag > tauIDSrcs_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
U second(std::pair< T, U > const &p)
Analysis-level tau class.
Definition: Tau.h:53
edm::EDGetTokenT< pat::TauCollection > src_
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
def move(src, dest)
Definition: eostools.py:511
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > patTauIDContainerTokens_

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().