CMS 3D CMS Logo

RecoTauMVATransform.cc
Go to the documentation of this file.
1 /*
2  * ============================================================================
3  * Filename: RecoTauMVATransform.cc
4  *
5  * Description: Transform TaNC output according to decay mode.
6  * Created: 10/22/2010 15:36:12
7  * Author: Evan K. Friis (UC Davis), evan.klose.friis@cern.ch
8  * ============================================================================
9  */
10 
11 #include <boost/ptr_container/ptr_map.hpp>
12 #include <memory>
13 
16 
19 
22 
25 
26 #include "TGraph.h"
27 
28 namespace {
29 
30 // Build the transformation function from the PSet format
31 std::unique_ptr<TGraph> buildTransform(const edm::ParameterSet &pset) {
32  double min = pset.getParameter<double>("min");
33  double max = pset.getParameter<double>("max");
34  const std::vector<double> &values =
35  pset.getParameter<std::vector<double> >("transform");
36  double stepSize = (max - min)/(values.size()-1);
37  std::unique_ptr<TGraph> output(new TGraph(values.size()));
38  for (size_t step = 0; step < values.size(); ++step) {
39  double x = min + step*stepSize;
40  output->SetPoint(step, x, values[step]);
41  }
42  return output;
43 }
44 
45 }
46 
48  public:
49  explicit RecoTauMVATransform(const edm::ParameterSet& pset);
50  ~RecoTauMVATransform() override {}
51 
52  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
53  double discriminate(const reco::PFTauRef&) const override;
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
56  private:
57  // Map a decay mode to a transformation
58  typedef boost::ptr_map<reco::PFTau::hadronicDecayMode, TGraph> TransformMap;
59  TransformMap transforms_;
60  // Points to raw TaNC output
63 };
64 
65 
68  input_ = pset.getParameter<edm::InputTag>("toTransform");
69  typedef std::vector<edm::ParameterSet> VPSet;
70  const VPSet& transforms = pset.getParameter<VPSet>("transforms");
72  for(auto const& transform : transforms) {
73  unsigned int nCharged = transform.getParameter<unsigned int>("nCharged");
74  unsigned int nPiZeros = transform.getParameter<unsigned int>("nPiZeros");
75  // Get the transform
76  const edm::ParameterSet &transformImpl =
77  transform.getParameter<edm::ParameterSet>("transform");
78  // Get the acutal decay mode
80  reco::tau::translateDecayMode(nCharged, nPiZeros);
81 
82  if (!transforms_.count(decayMode)) {
83  // Add it
84  transforms_.insert(decayMode, buildTransform(transformImpl).get());
85  } else {
86  edm::LogError("DecayModeNotUnique") << "The tau decay mode with "
87  "nCharged/nPiZero = " << nCharged << "/" << nPiZeros <<
88  " dm: " << decayMode <<
89  " is associated to multiple MVA transforms, "
90  "the second instantiation is being ignored!!!";
91  }
92  }
93 }
94 
95 // Update our discriminator handle at the begninng of the event
96 void
98  evt.getByLabel(input_, disc_);
99 }
100 
102  // Check if we support this decay mode:
103  TransformMap::const_iterator transformIter =
104  transforms_.find(tau->decayMode());
105  // Unsupported DM
106  if (transformIter == transforms_.end())
108  const TGraph *transform = transformIter->second;
109  // Get the discriminator output to transform
110  double value = (*disc_)[tau];
111  double result = transform->Eval(value);
112  return result;
113 }
114 
115 void
117  // recoTauMVATransform
119 
120  desc.add<edm::InputTag>("toTransform");
121 
122  edm::ParameterSetDescription vpsd_transforms;
123  vpsd_transforms.add<uint32_t>("nCharged");
124  vpsd_transforms.add<uint32_t>("nPiZeros");
125 
126  edm::ParameterSetDescription pset_transform;
127  pset_transform.add<double>("min");
128  pset_transform.add<double>("max");
129  pset_transform.add<std::vector<double>>("transform");
130  vpsd_transforms.add<edm::ParameterSetDescription>("transform", pset_transform);
131 
132  // name description no defaults items
133  desc.addVPSet("transforms", vpsd_transforms);
134 
135  fillProducerDescriptions(desc); // inherited from the base
136 
137  descriptions.add("recoTauMVATransform", desc);
138 }
139 
140 
T getParameter(std::string const &) const
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
PFTau::hadronicDecayMode translateDecayMode(unsigned int nCharged, unsigned int nPiZero)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillProducerDescriptions(edm::ParameterSetDescription &desc)
double discriminate(const reco::PFTauRef &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginEvent(const edm::Event &, const edm::EventSetup &) override
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
boost::ptr_map< reco::PFTau::hadronicDecayMode, TGraph > TransformMap
edm::Handle< reco::PFTauDiscriminator > disc_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
RecoTauMVATransform(const edm::ParameterSet &pset)
hadronicDecayMode
Definition: PFTau.h:36
step
Definition: StallMonitor.cc:94