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 <boost/shared_ptr.hpp>
13 #include <boost/foreach.hpp>
14 
15 #include <memory>
16 #include <string>
22 
26 
27 using namespace reco;
28 
30  public:
34  size_t index;
35  float defaultValue;
36  boost::shared_ptr<reco::tau::RecoTauDiscriminantPlugin> plugin;
37  };
38 
40  void produce(edm::Event&, const edm::EventSetup&) override;
41 
42  private:
44  std::vector<DiscriminantInfo> discriminators_;
45 };
46 
48  const edm::ParameterSet& pset) {
49  typedef std::vector<edm::ParameterSet> VPSet;
50  pfTauSource_ = pset.getParameter<edm::InputTag>("pfTauSource");
51  VPSet discriminants = pset.getParameter<VPSet>("discriminants");
52 
53  for(VPSet::const_iterator iDisc = discriminants.begin();
54  iDisc != discriminants.end(); ++iDisc) {
55  // WTF IS GOING ON HERE
56  std::string name = iDisc->getParameter<std::string>("name");
57  double defaultValue = (iDisc->exists("default")) ?
58  iDisc->getParameter<double>("default") : 0.;
59  // check if we are getting multiple indices
60  bool requestMultiple = iDisc->exists("indices");
61  if(requestMultiple) {
62  // make a discrimiantor for each desired index
63  std::vector<uint32_t> indices =
64  iDisc->getParameter<std::vector<uint32_t> >("indices");
65  for(std::vector<uint32_t>::const_iterator index = indices.begin();
66  index != indices.end(); ++index) {
67  DiscriminantInfo newDisc;
68  newDisc.name = name;
69  newDisc.index = *index;
70  newDisc.defaultValue = defaultValue;
71  // make a nice colleciton name
72  std::stringstream collectionName;
73  collectionName << name << *index;
74  newDisc.collName = collectionName.str();
75  // Build the plugin
76  edm::ParameterSet fakePSet;
77  newDisc.plugin.reset(
79  reco::tau::discPluginName(name), fakePSet));
80  discriminators_.push_back(newDisc);
81  }
82  } else {
83  //single discriminant
84  DiscriminantInfo newDisc;
85  newDisc.name = name;
86  newDisc.collName = name;
87  newDisc.index = 0;
88  newDisc.defaultValue = defaultValue;
89  // Build the plugin
90  edm::ParameterSet fakePSet;
91  newDisc.plugin.reset(
93  reco::tau::discPluginName(name), fakePSet));
94  discriminators_.push_back(newDisc);
95  }
96  }
97  // register products
98  BOOST_FOREACH(const DiscriminantInfo& disc, discriminators_) {
99  produces<PFTauDiscriminator>(disc.collName);
100  }
101 }
102 
104  const edm::EventSetup& es) {
105  // Handle to get PFTaus to associated to
107  evt.getByLabel(pfTauSource_, pfTaus);
108 
109  BOOST_FOREACH(const DiscriminantInfo& disc, discriminators_) {
110  // output for this discriminator
111  auto output = std::make_unique<PFTauDiscriminator>(edm::RefProd<PFTauCollection>(pfTaus));
112  // loop over taus
113  for(size_t itau = 0; itau < pfTaus->size(); ++itau) {
114  PFTauRef tauRef(pfTaus, itau);
115  // discriminator result
116  std::vector<double> result = (*disc.plugin)(tauRef);
117  // The desired index
118  double selected_result = disc.defaultValue;
119  if (result.size()-1 < disc.index) {
120  selected_result = result[disc.index];
121  }
122  output->setValue(itau, selected_result);
123  }
124  evt.put(std::move(output), disc.collName);
125  }
126 }
127 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
def create(alignables, pedeDump, additionalData, outputFile, config)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
std::string discPluginName(const std::string &mvaName)
std::string const collectionName[nCollections]
Definition: Collections.h:45
void produce(edm::Event &, const edm::EventSetup &) override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
fixed size matrix
boost::shared_ptr< reco::tau::RecoTauDiscriminantPlugin > plugin
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55