CMS 3D CMS Logo

PATTauIDEmbedder.cc
Go to the documentation of this file.
9 
11 {
12 public:
13 
14  explicit PATTauIDEmbedder(const edm::ParameterSet&);
15  ~PATTauIDEmbedder() override{};
16 
17  void produce(edm::Event&, const edm::EventSetup&) override;
18 
19 private:
20 
21 //--- configuration parameters
23  typedef std::pair<std::string, edm::InputTag> NameTag;
24  std::vector<NameTag> tauIDSrcs_;
25  std::vector<edm::EDGetTokenT<pat::PATTauDiscriminator> > patTauIDTokens_;
26 };
27 
29 {
30  src_ = consumes<pat::TauCollection>(cfg.getParameter<edm::InputTag>("src"));
31  // read the different tau ID names
32  edm::ParameterSet idps = cfg.getParameter<edm::ParameterSet>("tauIDSources");
33  std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
34  for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
35  tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
36  }
37  // but in any case at least once
38  if (tauIDSrcs_.empty()) throw cms::Exception("Configuration") <<
39  "PATTauProducer: id addTauID is true, you must specify:\n" <<
40  "\tPSet tauIDSources = { \n" <<
41  "\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
42  "\t}\n";
43  patTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<pat::PATTauDiscriminator>(tag.second);});
44 
45  produces<std::vector<pat::Tau> >();
46 }
47 
49 {
51  evt.getByToken(src_, inputTaus);
52 
53  auto outputTaus = std::make_unique<std::vector<pat::Tau> >();
54  outputTaus->reserve(inputTaus->size());
55 
56  int tau_idx = 0;
57  for(pat::TauCollection::const_iterator inputTau = inputTaus->begin(); inputTau != inputTaus->end(); ++inputTau, ++tau_idx){
58  pat::Tau outputTau(*inputTau);
59  pat::TauRef inputTauRef(inputTaus, tau_idx);
60  size_t nTauIds = inputTau->tauIDs().size();
61  std::vector<pat::Tau::IdPair> tauIds(nTauIds+tauIDSrcs_.size());
62 
63  for(size_t i = 0; i < nTauIds; ++i){
64  tauIds[i] = inputTau->tauIDs().at(i);
65  }
66 
68  for(size_t i = 0; i < tauIDSrcs_.size(); ++i){
69  evt.getByToken(patTauIDTokens_[i], tauDiscr);
70  tauIds[nTauIds+i].first = tauIDSrcs_[i].first;
71  tauIds[nTauIds+i].second = (*tauDiscr)[inputTauRef];
72  }
73 
74  outputTau.setTauIDs(tauIds);
75  outputTaus->push_back(outputTau);
76  }
77 
78  evt.put(std::move(outputTaus));
79 }
80 
82 
std::vector< edm::EDGetTokenT< pat::PATTauDiscriminator > > patTauIDTokens_
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< NameTag > tauIDSrcs_
void setTauIDs(const std::vector< IdPair > &ids)
Definition: Tau.h:384
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_]
~PATTauIDEmbedder() override
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
Analysis-level tau class.
Definition: Tau.h:55
PATTauIDEmbedder(const edm::ParameterSet &)
edm::EDGetTokenT< pat::TauCollection > src_
void produce(edm::Event &, const edm::EventSetup &) override
std::pair< std::string, edm::InputTag > NameTag
def move(src, dest)
Definition: eostools.py:510