CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  std::auto_ptr<PFTauDiscriminator> output(
113  // loop over taus
114  for(size_t itau = 0; itau < pfTaus->size(); ++itau) {
115  PFTauRef tauRef(pfTaus, itau);
116  // discriminator result
117  std::vector<double> result = (*disc.plugin)(tauRef);
118  // The desired index
119  double selected_result = disc.defaultValue;
120  if (result.size()-1 < disc.index) {
121  selected_result = result[disc.index];
122  }
123  output->setValue(itau, selected_result);
124  }
125  evt.put(output, disc.collName);
126  }
127 }
128 
T getParameter(std::string const &) const
tuple pfTaus
Definition: pfTaus_cff.py:136
#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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
tuple result
Definition: query.py:137
void produce(edm::Event &, const edm::EventSetup &) override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
boost::shared_ptr< reco::tau::RecoTauDiscriminantPlugin > plugin
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:55