CMS 3D CMS Logo

PATTauIDEmbedder.cc
Go to the documentation of this file.
10 
12 public:
13  explicit PATTauIDEmbedder(const edm::ParameterSet&);
14  ~PATTauIDEmbedder() override{};
15 
16  void produce(edm::Event&, const edm::EventSetup&) override;
17 
18 private:
19  //--- configuration parameters
21  typedef std::pair<std::string, edm::InputTag> NameTag;
22  typedef std::pair<std::string, int> NameWPIdx;
23  //to save input module tag and corresponding pairs <working point name for the output tree, WP index in the input ID container>
24  typedef std::pair<edm::InputTag, std::vector<NameWPIdx> > IDContainerData;
25  std::vector<NameTag> tauIDSrcs_;
26  std::vector<std::vector<NameWPIdx> > tauIDSrcContainers_;
27  std::vector<edm::EDGetTokenT<pat::PATTauDiscriminator> > patTauIDTokens_;
28  std::vector<edm::EDGetTokenT<reco::TauDiscriminatorContainer> > patTauIDContainerTokens_;
30  size_t nNewTauIds_;
31 };
32 
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 }
71 
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 }
131 
133 
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:428
PATTauDiscriminator.h
PATTauIDEmbedder::src_
edm::EDGetTokenT< pat::TauCollection > src_
Definition: PATTauIDEmbedder.cc:20
edm::EDGetTokenT< pat::TauCollection >
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
generateEDF.cont
cont
load Luminosity info ##
Definition: generateEDF.py:629
EDProducer.h
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
PATTauIDEmbedder::patTauIDTokens_
std::vector< edm::EDGetTokenT< pat::PATTauDiscriminator > > patTauIDTokens_
Definition: PATTauIDEmbedder.cc:27
edm::Handle
Definition: AssociativeIterator.h:50
Tau.h
edm::Ref
Definition: AssociativeIterator.h:58
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
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:535
PATTauIDEmbedder::NameWPIdx
std::pair< std::string, int > NameWPIdx
Definition: PATTauIDEmbedder.cc:22
PATTauIDEmbedder
Definition: PATTauIDEmbedder.cc:11
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
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
PATTauIDEmbedder::PATTauIDEmbedder
PATTauIDEmbedder(const edm::ParameterSet &)
Definition: PATTauIDEmbedder.cc:33
edm::ParameterSet
Definition: ParameterSet.h:47
PDWG_TauSkim_cff.workingPoints
workingPoints
Definition: PDWG_TauSkim_cff.py:15
Event.h
edm::ParameterSet::getParameterNamesForType
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
PATTauIDEmbedder::nNewPlainTauIds_
size_t nNewPlainTauIds_
Definition: PATTauIDEmbedder.cc:29
edm::stream::EDProducer
Definition: EDProducer.h:38
TauDiscriminatorContainer.h
edm::EventSetup
Definition: EventSetup.h:58
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
PATTauIDEmbedder::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PATTauIDEmbedder.cc:72
PATTauIDEmbedder::tauIDSrcContainers_
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
Definition: PATTauIDEmbedder.cc:26
eostools.move
def move(src, dest)
Definition: eostools.py:511
PATTauIDEmbedder::~PATTauIDEmbedder
~PATTauIDEmbedder() override
Definition: PATTauIDEmbedder.cc:14
transform.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
cms::Exception
Definition: Exception.h:70
ParameterSet.h
pat::Tau::setTauIDs
void setTauIDs(const std::vector< IdPair > &ids)
Definition: Tau.h:347
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
PATTauIDEmbedder::IDContainerData
std::pair< edm::InputTag, std::vector< NameWPIdx > > IDContainerData
Definition: PATTauIDEmbedder.cc:24
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:342
edm::InputTag
Definition: InputTag.h:15