CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauDiscriminationProducerBase.cc
Go to the documentation of this file.
2 
3 using namespace reco;
4 
5 // default constructor; must not be called
6 template<class TauType, class TauDiscriminator>
8 {
9  throw cms::Exception("TauDiscriminationProducerBase") << " -- default ctor called; derived classes must call " <<
10  "TauDiscriminationProducerBase(const ParameterSet&)";
11 }
12 
13 //--- standard constructor from PSet
14 template<class TauType, class TauDiscriminator>
16 {
17  // tau collection to discriminate
18  TauProducer_ = iConfig.getParameter<edm::InputTag>(getProducerString<TauType>());
19 
20  // prediscriminant operator
21  // require the tau to pass the following prediscriminants
22  const edm::ParameterSet& prediscriminantConfig = iConfig.getParameter<edm::ParameterSet>("Prediscriminants");
23 
24  // determine boolean operator used on the prediscriminants
25  std::string pdBoolOperator = prediscriminantConfig.getParameter<std::string>("BooleanOperator");
26  // convert string to lowercase
27  transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
28 
29  if( pdBoolOperator == "and" )
30  {
31  andPrediscriminants_ = 0x1; //use chars instead of bools so we can do a bitwise trick later
32  }
33  else if ( pdBoolOperator == "or" )
34  {
35  andPrediscriminants_ = 0x0;
36  }
37  else
38  {
39  throw cms::Exception("TauDiscriminationProducerBase") << "PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
40  }
41 
42  // get the list of prediscriminants
43  std::vector<std::string> prediscriminantsNames = prediscriminantConfig.getParameterNamesForType<edm::ParameterSet>();
44 
45  for( std::vector<std::string>::const_iterator iDisc = prediscriminantsNames.begin();
46  iDisc != prediscriminantsNames.end(); ++iDisc )
47  {
48  const edm::ParameterSet& iPredisc = prediscriminantConfig.getParameter<edm::ParameterSet>(*iDisc);
49  const edm::InputTag& label = iPredisc.getParameter<edm::InputTag>("Producer");
50  double cut = iPredisc.getParameter<double>("cut");
51 
52  TauDiscInfo thisDiscriminator;
53  thisDiscriminator.label = label;
54  thisDiscriminator.cut = cut;
55  prediscriminants_.push_back(thisDiscriminator);
56  }
57 
58  prediscriminantFailValue_ = 0.;
59 
60  // register product
61  produces<TauDiscriminator>();
62 }
63 
64 template<class TauType, class TauDiscriminator>
66 {
67  // setup function - does nothing in base, but can be overridden to retrieve PV or other stuff
68  beginEvent(event, eventSetup);
69 
70  // retrieve the tau collection to discriminate
72  event.getByLabel(TauProducer_, taus);
73 
74  // output product
75  std::auto_ptr<TauDiscriminator> output(new TauDiscriminator(TauRefProd(taus)));
76 
77  size_t nTaus = taus->size();
78 
79  // load prediscriminators
80  size_t nPrediscriminants = prediscriminants_.size();
81  for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
82  {
83  prediscriminants_[iDisc].fill(event);
84  }
85 
86  // loop over taus
87  for( size_t iTau = 0; iTau < nTaus; ++iTau )
88  {
89  // get reference to tau
90  TauRef tauRef(taus, iTau);
91 
92  bool passesPrediscriminants = true;
93  // check tau passes prediscriminants
94  for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
95  {
96  // current discriminant result for this tau
97  double discResult = (*prediscriminants_[iDisc].handle)[tauRef];
98  uint8_t thisPasses = ( discResult > prediscriminants_[iDisc].cut ) ? 1 : 0;
99 
100 
101  // if we are using the AND option, as soon as one fails,
102  // the result is FAIL and we can quit looping.
103  // if we are using the OR option as soon as one passes,
104  // the result is pass and we can quit looping
105 
106  // truth table
107  // | result (thisPasses)
108  // | F | T
109  //-----------------------------------
110  // AND(T) | res=fails | continue
111  // | break |
112  //-----------------------------------
113  // OR (F) | continue | res=passes
114  // | | break
115 
116  if( thisPasses ^ andPrediscriminants_ ) //XOR
117  {
118  passesPrediscriminants = ( andPrediscriminants_ ? 0 : 1 ); //NOR
119  break;
120  }
121  }
122 
123  double result = prediscriminantFailValue_;
124  if( passesPrediscriminants )
125  {
126  // this tau passes the prereqs, call our implemented discrimination function
127  result = discriminate(tauRef);
128  }
129 
130  // store the result of this tau into our new discriminator
131  output->setValue(iTau, result);
132  }
133  event.put(output);
134 }
135 
136 // template specialiazation to get the correct (Calo/PF)TauProducer names
137 template<> std::string getProducerString<PFTau>() { return "PFTauProducer"; }
138 template<> std::string getProducerString<CaloTau>() { return "CaloTauProducer"; }
139 
140 // compile our desired types and make available to linker
T getParameter(std::string const &) const
const std::string & label
Definition: MVAComputer.cc:186
std::string getProducerString< CaloTau >()
void produce(edm::Event &, const edm::EventSetup &)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:189
tuple result
Definition: query.py:137
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
tuple cut
Definition: align_tpl.py:88
std::string getProducerString< PFTau >()