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  edm::ProductID tauProductID = taus.id();
75 
76  // output product
77  std::auto_ptr<TauDiscriminator> output(new TauDiscriminator(TauRefProd(taus)));
78 
79  size_t nTaus = taus->size();
80 
81  // load prediscriminators
82  size_t nPrediscriminants = prediscriminants_.size();
83  for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
84  {
85  prediscriminants_[iDisc].fill(event);
86 
87  // Check to make sure the product is correct for the discriminator.
88  // If not, throw a more informative exception.
89  edm::ProductID discKeyId =
90  prediscriminants_[iDisc].handle->keyProduct().id();
91  if (tauProductID != discKeyId) {
92  throw cms::Exception("MisconfiguredPrediscriminant")
93  << "The tau collection with input tag " << TauProducer_
94  << " has product ID: " << tauProductID
95  << " but the pre-discriminator with input tag "
96  << prediscriminants_[iDisc].label
97  << " is keyed with product ID: " << discKeyId << std::endl;
98  }
99  }
100 
101  // loop over taus
102  for( size_t iTau = 0; iTau < nTaus; ++iTau )
103  {
104  // get reference to tau
105  TauRef tauRef(taus, iTau);
106 
107  bool passesPrediscriminants = true;
108  // check tau passes prediscriminants
109  for( size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc )
110  {
111  // current discriminant result for this tau
112  double discResult = (*prediscriminants_[iDisc].handle)[tauRef];
113  uint8_t thisPasses = ( discResult > prediscriminants_[iDisc].cut ) ? 1 : 0;
114 
115  // if we are using the AND option, as soon as one fails,
116  // the result is FAIL and we can quit looping.
117  // if we are using the OR option as soon as one passes,
118  // the result is pass and we can quit looping
119 
120  // truth table
121  // | result (thisPasses)
122  // | F | T
123  //-----------------------------------
124  // AND(T) | res=fails | continue
125  // | break |
126  //-----------------------------------
127  // OR (F) | continue | res=passes
128  // | | break
129 
130  if( thisPasses ^ andPrediscriminants_ ) //XOR
131  {
132  passesPrediscriminants = ( andPrediscriminants_ ? 0 : 1 ); //NOR
133  break;
134  }
135  }
136 
137  double result = prediscriminantFailValue_;
138  if( passesPrediscriminants )
139  {
140  // this tau passes the prereqs, call our implemented discrimination function
141  result = discriminate(tauRef);
142  }
143 
144  // store the result of this tau into our new discriminator
145  output->setValue(iTau, result);
146  }
147  event.put(output);
148 
149  // function to put additional information into the event - does nothing in base, but can be overridden in derived classes
150  endEvent(event);
151 }
152 
153 // template specialiazation to get the correct (Calo/PF)TauProducer names
154 template<> std::string getProducerString<PFTau>() { return "PFTauProducer"; }
155 template<> std::string getProducerString<CaloTau>() { return "CaloTauProducer"; }
156 
157 // compile our desired types and make available to linker
T getParameter(std::string const &) const
ProductID id() const
Definition: HandleBase.cc:15
std::string getProducerString< CaloTau >()
void produce(edm::Event &, const edm::EventSetup &)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:195
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
std::string getProducerString< PFTau >()
ProductIndex id() const
Definition: ProductID.h:38