CMS 3D CMS Logo

PFTauDecayModeCutMultiplexer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PFTauDecayModeCutMultiplexer
4 // Class: PFTauDecayModeCutMultiplexer
5 //
6 /*
7 
8  Description: Applies a different cut to a PFTauDiscriminator, depending on the
9  the reconstructed DecayMode (stored by RecoTauTag/RecoTau/PFTauDecayModeIndexProducer)
10  in PFTauDiscriminator form.
11 
12  Produces a PFTauDiscriminator output with a binary (0 or 1) output.
13 
14  Cuts are specified in the decay mode PSets, which map the cuts
15  to collections of decay mode indices. These decay mode PSets are defined
16  in the same manner as TaNC MVA computers (which also map to specific decay modes)
17 
18 
19 */
20 //
21 // Original Author: Evan K. Friis, UC Davis (friis@physics.ucdavis.edu)
22 // Created: Thurs, April 16, 2009
23 //
24 //
25 
27 
30 
31 using namespace reco;
32 
34 public:
37 
38  struct ComputerAndCut {
40  double userCut;
41  };
42 
43  typedef std::vector<ComputerAndCut> CutList;
44  typedef std::map<int, CutList::iterator> DecayModeToCutMap;
45 
46  double discriminate(const PFTauRef& thePFTau) const override;
47  void beginEvent(const edm::Event& event, const edm::EventSetup& eventSetup) override;
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51 private:
52  // PFTau discriminator continaing the decaymode index of the tau collection
55 
56  // Discriminant to multiplex cut on
59 
60  DecayModeToCutMap computerMap_; //Maps decay mode to MVA implementation
62 
64  pfTauDecayModeIndices; // holds the decay mode indices for the taus in the current event
66  targetDiscriminant; // holds the discirminant values of the discriminant we will multiplex for the current event
67 };
68 
71  pfTauDecayModeIndexSrc_ = iConfig.getParameter<edm::InputTag>("PFTauDecayModeSrc");
72  discriminantToMultiplex_ = iConfig.getParameter<edm::InputTag>("PFTauDiscriminantToMultiplex");
73  pfTauDecayModeIndex_token = consumes<PFTauDiscriminator>(pfTauDecayModeIndexSrc_);
74  discriminant_token = consumes<PFTauDiscriminator>(discriminantToMultiplex_);
75  //get the computer/decay mode map
76  std::vector<edm::ParameterSet> decayModeMap = iConfig.getParameter<std::vector<edm::ParameterSet> >("computers");
77  computers_.reserve(decayModeMap.size());
78 
79  // for each decay mode MVA implementation (which may correspond to multiple decay modes, map the decay modes to the correct MVA computer
80  for (std::vector<edm::ParameterSet>::const_iterator iComputer = decayModeMap.begin(); iComputer != decayModeMap.end();
81  ++iComputer) {
82  ComputerAndCut toInsert;
83  toInsert.computerName = iComputer->getParameter<std::string>("computerName");
84  toInsert.userCut = iComputer->getParameter<double>("cut");
85  CutList::iterator computerJustAdded =
86  computers_.insert(computers_.end(), toInsert); //add this computer to the end of the list
87 
88  //populate the map
89  std::vector<int> associatedDecayModes = iComputer->getParameter<std::vector<int> >("decayModeIndices");
90  for (std::vector<int>::const_iterator iDecayMode = associatedDecayModes.begin();
91  iDecayMode != associatedDecayModes.end();
92  ++iDecayMode) {
93  //map this integer specifying the decay mode to the MVA comptuer we just added to the list
94  std::pair<DecayModeToCutMap::iterator, bool> insertResult =
95  computerMap_.insert(std::make_pair(*iDecayMode, computerJustAdded));
96 
97  //make sure we aren't double mapping a decay mode
98  if (insertResult.second == false) { //indicates that the current key (decaymode) has already been entered!
99  throw cms::Exception("PFTauDecayModeCutMultiplexer::ctor")
100  << "A tau decay mode: " << *iDecayMode << " has been mapped to two different MVA implementations, "
101  << insertResult.first->second->computerName << " and " << toInsert.computerName
102  << ". Please check the appropriate cfi file." << std::endl;
103  }
104  }
105  }
106 }
107 
108 // ------------ get the relevant decay mode index handles at the beginning of each event ------------
112 }
113 
115  // get decay mode for current tau
116  int decayMode = lrint((*pfTauDecayModeIndices)[pfTau]); //convert to int
117 
118  // get value we are trying to multiplex
119  float valueToMultiplex = (*targetDiscriminant)[pfTau];
120 
121  // Get correct cut
122  auto iterToComputer = computerMap_.find(decayMode);
123  if (iterToComputer != computerMap_.end()) //if we don't have a MVA mapped to this decay mode, skip it, it fails.
124  {
125  // use the supplied cut to make a decision
126  if (valueToMultiplex > iterToComputer->second->userCut)
127  return 1.0;
128  else
129  return 0.0;
130  }
131 
132  // no computer associated to this decay mode; it fails
133  return 0.;
134 }
135 
137  // pfTauDecayModeCutMultiplexer
139 
140  desc.add<edm::InputTag>("PFTauDecayModeSrc");
141  desc.add<edm::InputTag>("PFTauDiscriminantToMultiplex");
142 
143  edm::ParameterSetDescription vpsd_computers;
144  vpsd_computers.add<std::string>("computerName");
145  vpsd_computers.add<double>("cut");
146  vpsd_computers.add<std::vector<int> >("decayModeIndices");
147 
148  // name description defaults items
149  //desc.addVPSet("computers", vpsd_builders, builders_vector);
150  desc.addVPSet("computers", vpsd_computers);
151 
152  fillProducerDescriptions(desc); // inherited from the base
153 
154  descriptions.add("pfTauDecayModeCutMultiplexer", desc);
155 }
156 
ConfigurationDescriptions.h
PFTauDecayModeCutMultiplexer::beginEvent
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: PFTauDecayModeCutMultiplexer.cc:109
PFTauDecayModeCutMultiplexer::CutList
std::vector< ComputerAndCut > CutList
Definition: PFTauDecayModeCutMultiplexer.cc:43
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
PFTauDecayModeCutMultiplexer::PFTauDecayModeCutMultiplexer
PFTauDecayModeCutMultiplexer(const edm::ParameterSet &)
Definition: PFTauDecayModeCutMultiplexer.cc:69
TauDiscriminationProducerBase.h
edm::EDGetTokenT< PFTauDiscriminator >
PFTauDecayModeCutMultiplexer::DecayModeToCutMap
std::map< int, CutList::iterator > DecayModeToCutMap
Definition: PFTauDecayModeCutMultiplexer.cc:44
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
PFTauDecayModeCutMultiplexer::computers_
CutList computers_
Definition: PFTauDecayModeCutMultiplexer.cc:61
PFTauDecayModeCutMultiplexer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PFTauDecayModeCutMultiplexer.cc:136
edm::Handle< PFTauDiscriminator >
PFTauDecayModeCutMultiplexer::targetDiscriminant
edm::Handle< PFTauDiscriminator > targetDiscriminant
Definition: PFTauDecayModeCutMultiplexer.cc:66
PFTauDecayModeCutMultiplexer::pfTauDecayModeIndexSrc_
edm::InputTag pfTauDecayModeIndexSrc_
Definition: PFTauDecayModeCutMultiplexer.cc:53
edm::Ref< PFTauCollection >
PFTauDecayModeCutMultiplexer::discriminate
double discriminate(const PFTauRef &thePFTau) const override
Definition: PFTauDecayModeCutMultiplexer.cc:114
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TauDiscriminationProducerBase
Definition: TauDiscriminationProducerBase.h:55
ParameterSetDescription.h
taus_cff.decayMode
decayMode
Definition: taus_cff.py:58
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PFTauDecayModeCutMultiplexer::pfTauDecayModeIndex_token
edm::EDGetTokenT< PFTauDiscriminator > pfTauDecayModeIndex_token
Definition: PFTauDecayModeCutMultiplexer.cc:54
edm::ParameterSet
Definition: ParameterSet.h:47
TauDiscriminationProducerBase::fillProducerDescriptions
static void fillProducerDescriptions(edm::ParameterSetDescription &desc)
Definition: TauDiscriminationProducerBase.cc:173
PFTauDecayModeCutMultiplexer::~PFTauDecayModeCutMultiplexer
~PFTauDecayModeCutMultiplexer() override
Definition: PFTauDecayModeCutMultiplexer.cc:36
PFTauDecayModeCutMultiplexer::ComputerAndCut::computerName
std::string computerName
Definition: PFTauDecayModeCutMultiplexer.cc:39
iEvent
int iEvent
Definition: GenABIO.cc:224
PFTauDecayModeCutMultiplexer::ComputerAndCut::userCut
double userCut
Definition: PFTauDecayModeCutMultiplexer.cc:40
edm::EventSetup
Definition: EventSetup.h:58
PFTauDecayModeCutMultiplexer::pfTauDecayModeIndices
edm::Handle< PFTauDiscriminator > pfTauDecayModeIndices
Definition: PFTauDecayModeCutMultiplexer.cc:64
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
Exception
Definition: hltDiff.cc:245
PFTauDecayModeCutMultiplexer::discriminantToMultiplex_
edm::InputTag discriminantToMultiplex_
Definition: PFTauDecayModeCutMultiplexer.cc:57
PFTauDecayModeCutMultiplexer::discriminant_token
edm::EDGetTokenT< PFTauDiscriminator > discriminant_token
Definition: PFTauDecayModeCutMultiplexer.cc:58
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PFTauDecayModeCutMultiplexer::computerMap_
DecayModeToCutMap computerMap_
Definition: PFTauDecayModeCutMultiplexer.cc:60
PFTauDecayModeCutMultiplexer
Definition: PFTauDecayModeCutMultiplexer.cc:33
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
PFTauDecayModeCutMultiplexer::ComputerAndCut
Definition: PFTauDecayModeCutMultiplexer.cc:38