CMS 3D CMS Logo

PFTauMVAInputDiscriminantTranslator.cc
Go to the documentation of this file.
1 /*
2  * PFTauMVAInputDiscriminantTranslator
3  *
4  * Translate a list of given MVA (i.e. TaNC)
5  * variables into standard PFTauDiscriminators
6  * to facilitate embeddeing them into pat::Taus
7  *
8  * Author: Evan K. Friis (UC Davis)
9  *
10  */
11 
12 #include <memory>
13 #include <string>
19 
23 
24 using namespace reco;
25 
27  public:
31  size_t index;
32  float defaultValue;
33  std::shared_ptr<reco::tau::RecoTauDiscriminantPlugin> plugin;
34  };
35 
37  void produce(edm::Event&, const edm::EventSetup&) override;
38 
39  private:
41  std::vector<DiscriminantInfo> discriminators_;
42 };
43 
45  const edm::ParameterSet& pset) {
46  typedef std::vector<edm::ParameterSet> VPSet;
47  pfTauSource_ = pset.getParameter<edm::InputTag>("pfTauSource");
48  VPSet discriminants = pset.getParameter<VPSet>("discriminants");
49 
50  for(VPSet::const_iterator iDisc = discriminants.begin();
51  iDisc != discriminants.end(); ++iDisc) {
52  // WTF IS GOING ON HERE
53  std::string name = iDisc->getParameter<std::string>("name");
54  double defaultValue = (iDisc->exists("default")) ?
55  iDisc->getParameter<double>("default") : 0.;
56  // check if we are getting multiple indices
57  bool requestMultiple = iDisc->exists("indices");
58  if(requestMultiple) {
59  // make a discrimiantor for each desired index
60  std::vector<uint32_t> indices =
61  iDisc->getParameter<std::vector<uint32_t> >("indices");
62  for(std::vector<uint32_t>::const_iterator index = indices.begin();
63  index != indices.end(); ++index) {
64  DiscriminantInfo newDisc;
65  newDisc.name = name;
66  newDisc.index = *index;
67  newDisc.defaultValue = defaultValue;
68  // make a nice colleciton name
69  std::stringstream collectionName;
70  collectionName << name << *index;
71  newDisc.collName = collectionName.str();
72  // Build the plugin
73  edm::ParameterSet fakePSet;
74  newDisc.plugin = std::unique_ptr<reco::tau::RecoTauDiscriminantPlugin>(
76  reco::tau::discPluginName(name), fakePSet));
77  discriminators_.push_back(newDisc);
78  }
79  } else {
80  //single discriminant
81  DiscriminantInfo newDisc;
82  newDisc.name = name;
83  newDisc.collName = name;
84  newDisc.index = 0;
85  newDisc.defaultValue = defaultValue;
86  // Build the plugin
87  edm::ParameterSet fakePSet;
88  newDisc.plugin = std::unique_ptr<reco::tau::RecoTauDiscriminantPlugin>(
90  reco::tau::discPluginName(name), fakePSet));
91  discriminators_.push_back(newDisc);
92  }
93  }
94  // register products
95  for(auto const& disc : discriminators_) {
96  produces<PFTauDiscriminator>(disc.collName);
97  }
98 }
99 
101  const edm::EventSetup& es) {
102  // Handle to get PFTaus to associated to
104  evt.getByLabel(pfTauSource_, pfTaus);
105 
106  for(auto const& disc : discriminators_) {
107  // output for this discriminator
108  auto output = std::make_unique<PFTauDiscriminator>(edm::RefProd<PFTauCollection>(pfTaus));
109  // loop over taus
110  for(size_t itau = 0; itau < pfTaus->size(); ++itau) {
111  PFTauRef tauRef(pfTaus, itau);
112  // discriminator result
113  std::vector<double> result = (*disc.plugin)(tauRef);
114  // The desired index
115  double selected_result = disc.defaultValue;
116  if (result.size()-1 < disc.index) {
117  selected_result = result[disc.index];
118  }
119  output->setValue(itau, selected_result);
120  }
121  evt.put(std::move(output), disc.collName);
122  }
123 }
124 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
std::string discPluginName(const std::string &mvaName)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string const collectionName[nCollections]
Definition: Collections.h:47
void produce(edm::Event &, const edm::EventSetup &) override
std::shared_ptr< reco::tau::RecoTauDiscriminantPlugin > plugin
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
fixed size matrix
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55