CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: PFTauDecayModeCutMultiplexer.cc,v 1.3 2010/10/19 21:29:13 wmtan Exp $
24 //
25 //
26 
28 
29 using namespace reco;
30 
32  public:
35 
36  struct ComputerAndCut {
38  double userCut;
39  };
40 
41  typedef std::vector<ComputerAndCut> CutList;
42  typedef std::map<int, CutList::iterator> DecayModeToCutMap;
43 
44  double discriminate(const PFTauRef& thePFTau);
45  void beginEvent(const edm::Event& event, const edm::EventSetup& eventSetup);
46 
47  private:
48  // PFTau discriminator continaing the decaymode index of the tau collection
50 
51  // Discriminant to multiplex cut on
53 
54  DecayModeToCutMap computerMap_; //Maps decay mode to MVA implementation
56 
57  edm::Handle<PFTauDiscriminator> pfTauDecayModeIndices; // holds the decay mode indices for the taus in the current event
58  edm::Handle<PFTauDiscriminator> targetDiscriminant; // holds the discirminant values of the discriminant we will multiplex for the current event
59 };
60 
62 {
63  pfTauDecayModeIndexSrc_ = iConfig.getParameter<edm::InputTag>("PFTauDecayModeSrc");
64  discriminantToMultiplex_ = iConfig.getParameter<edm::InputTag>("PFTauDiscriminantToMultiplex");
65 
66  //get the computer/decay mode map
67  std::vector<edm::ParameterSet> decayModeMap = iConfig.getParameter<std::vector<edm::ParameterSet> >("computers");
68  computers_.reserve(decayModeMap.size());
69 
70  // for each decay mode MVA implementation (which may correspond to multiple decay modes, map the decay modes to the correct MVA computer
71  for(std::vector<edm::ParameterSet>::const_iterator iComputer = decayModeMap.begin();
72  iComputer != decayModeMap.end();
73  ++iComputer)
74  {
75  ComputerAndCut toInsert;
76  toInsert.computerName = iComputer->getParameter<std::string>("computerName");
77  toInsert.userCut = iComputer->getParameter<double>("cut");
78  CutList::iterator computerJustAdded = computers_.insert(computers_.end(), toInsert); //add this computer to the end of the list
79 
80  //populate the map
81  std::vector<int> associatedDecayModes = iComputer->getParameter<std::vector<int> >("decayModeIndices");
82  for(std::vector<int>::const_iterator iDecayMode = associatedDecayModes.begin();
83  iDecayMode != associatedDecayModes.end();
84  ++iDecayMode)
85  {
86  //map this integer specifying the decay mode to the MVA comptuer we just added to the list
87  std::pair<DecayModeToCutMap::iterator, bool> insertResult = computerMap_.insert(std::make_pair(*iDecayMode, computerJustAdded));
88 
89  //make sure we aren't double mapping a decay mode
90  if(insertResult.second == false) { //indicates that the current key (decaymode) has already been entered!
91  throw cms::Exception("PFTauDecayModeCutMultiplexer::ctor") << "A tau decay mode: " << *iDecayMode << " has been mapped to two different MVA implementations, "
92  << insertResult.first->second->computerName << " and " << toInsert.computerName
93  << ". Please check the appropriate cfi file." << std::endl;
94  }
95  }
96  }
97 }
98 
99 // ------------ get the relevant decay mode index handles at the beginning of each event ------------
100 void
102 {
103 
106 }
107 
109 {
110  // get decay mode for current tau
111  int decayMode = lrint( (*pfTauDecayModeIndices)[pfTau] ); //convert to int
112 
113  // get value we are trying to multiplex
114  float valueToMultiplex = (*targetDiscriminant)[pfTau];
115 
116  // Get correct cut
117  DecayModeToCutMap::iterator iterToComputer = computerMap_.find(decayMode);
118  if(iterToComputer != computerMap_.end()) //if we don't have a MVA mapped to this decay mode, skip it, it fails.
119  {
120  // use the supplied cut to make a decision
121  if (valueToMultiplex > iterToComputer->second->userCut)
122  return 1.0;
123  else
124  return 0.0;
125  }
126 
127  // no computer associated to this decay mode; it fails
128  return 0.;
129 }
130 
T getParameter(std::string const &) const
std::vector< ComputerAndCut > CutList
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< int, CutList::iterator > DecayModeToCutMap
int iEvent
Definition: GenABIO.cc:243
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
edm::Handle< PFTauDiscriminator > pfTauDecayModeIndices
PFTauDecayModeCutMultiplexer(const edm::ParameterSet &)
edm::Handle< PFTauDiscriminator > targetDiscriminant
double discriminate(const PFTauRef &thePFTau)