CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes
TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType > Class Template Referenceabstract

#include <TauDiscriminationProducerBase.h>

Inheritance diagram for TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >:
edm::stream::EDProducer<> PFRecoTauDiscriminationAgainstElectron2 PFRecoTauDiscriminationAgainstMuon PFRecoTauDiscriminationAgainstMuon2 PFRecoTauDiscriminationAgainstMuon2Container PFRecoTauDiscriminationAgainstMuonMVA PFRecoTauDiscriminationAgainstMuonSimple PFRecoTauDiscriminationByHPSSelection PFRecoTauDiscriminationByIPCut PFRecoTauDiscriminationByIsolation PFRecoTauDiscriminationByIsolationContainer PFRecoTauDiscriminationByIsolationMVA2 PFRecoTauDiscriminationByLeadingObjectPtCut PFRecoTauDiscriminationByNProngs PFTauDecayModeCutMultiplexer PFTauDiscriminatorLogicalAndProducer reco::tau::PATTauDiscriminationByMVAIsolationRun2 reco::tau::PFRecoTauDiscriminationByMVAIsolationRun2

Classes

struct  TauDiscInfo
 

Public Types

typedef std::vector< TauType > TauCollection
 
typedef edm::Ref< TauCollectionTauRef
 
typedef edm::RefProd< TauCollectionTauRefProd
 
- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Public Member Functions

virtual void beginEvent (const edm::Event &, const edm::EventSetup &)
 
virtual TauDiscriminatorDataType discriminate (const TauRef &tau) const =0
 
virtual void endEvent (edm::Event &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 TauDiscriminationProducerBase (const edm::ParameterSet &iConfig)
 
 TauDiscriminationProducerBase ()
 
 ~TauDiscriminationProducerBase () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillProducerDescriptions (edm::ParameterSetDescription &desc)
 
static std::string getTauTypeString ()
 helper method to retrieve tau type name, e.g. to build correct cfi getter More...
 

Protected Attributes

std::string moduleLabel_
 
double prediscriminantFailValue_
 
edm::EDGetTokenT< TauCollectionTau_token
 
size_t tauIndex_
 
edm::InputTag TauProducer_
 

Private Attributes

uint8_t andPrediscriminants_
 
std::vector< TauDiscInfoprediscriminants_
 

Detailed Description

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
class TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >

Definition at line 54 of file TauDiscriminationProducerBase.h.

Member Typedef Documentation

◆ TauCollection

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
typedef std::vector<TauType> TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::TauCollection

Definition at line 57 of file TauDiscriminationProducerBase.h.

◆ TauRef

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
typedef edm::Ref<TauCollection> TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::TauRef

Definition at line 58 of file TauDiscriminationProducerBase.h.

◆ TauRefProd

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
typedef edm::RefProd<TauCollection> TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::TauRefProd

Definition at line 59 of file TauDiscriminationProducerBase.h.

Constructor & Destructor Documentation

◆ TauDiscriminationProducerBase() [1/2]

template<class TauType , class TauDiscriminator , class TauDiscriminatorDataType , class ConsumeType >
TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::TauDiscriminationProducerBase ( const edm::ParameterSet iConfig)
explicit

Definition at line 40 of file TauDiscriminationProducerBase.cc.

41  : moduleLabel_(iConfig.getParameter<std::string>("@module_label")) {
42  // tau collection to discriminate
43  TauProducer_ = iConfig.getParameter<edm::InputTag>(getTauTypeString() + "Producer");
44  Tau_token = consumes<TauCollection>(TauProducer_);
45 
46  // prediscriminant operator
47  // require the tau to pass the following prediscriminants
48  const edm::ParameterSet& prediscriminantConfig = iConfig.getParameter<edm::ParameterSet>("Prediscriminants");
49 
50  // determine boolean operator used on the prediscriminants
51  std::string pdBoolOperator = prediscriminantConfig.getParameter<std::string>("BooleanOperator");
52  // convert string to lowercase
53  transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
54 
55  if (pdBoolOperator == "and") {
56  andPrediscriminants_ = 0x1; //use chars instead of bools so we can do a bitwise trick later
57  } else if (pdBoolOperator == "or") {
59  } else {
60  throw cms::Exception("TauDiscriminationProducerBase")
61  << "PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
62  }
63 
64  // get the list of prediscriminants
65  std::vector<std::string> prediscriminantsNames = prediscriminantConfig.getParameterNamesForType<edm::ParameterSet>();
66 
67  for (std::vector<std::string>::const_iterator iDisc = prediscriminantsNames.begin();
68  iDisc != prediscriminantsNames.end();
69  ++iDisc) {
70  const edm::ParameterSet& iPredisc = prediscriminantConfig.getParameter<edm::ParameterSet>(*iDisc);
71  const edm::InputTag& label = iPredisc.getParameter<edm::InputTag>("Producer");
72  double cut = iPredisc.getParameter<double>("cut");
73 
74  TauDiscInfo thisDiscriminator;
75  thisDiscriminator.label = label;
76  thisDiscriminator.cut = cut;
77  thisDiscriminator.disc_token = consumes<ConsumeType>(label);
78  prediscriminants_.push_back(thisDiscriminator);
79  }
80 
82 
83  // register product
84  produces<TauDiscriminator>();
85 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
char const * label
static std::string getTauTypeString()
helper method to retrieve tau type name, e.g. to build correct cfi getter
edm::EDGetTokenT< TauCollection > Tau_token
std::vector< TauDiscInfo > prediscriminants_
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ TauDiscriminationProducerBase() [2/2]

template<class TauType , class TauDiscriminator , class TauDiscriminatorDataType , class ConsumeType >
TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::TauDiscriminationProducerBase ( )

Definition at line 32 of file TauDiscriminationProducerBase.cc.

32  {
33  throw cms::Exception("TauDiscriminationProducerBase") << " -- default ctor called; derived classes must call "
34  << "TauDiscriminationProducerBase(const ParameterSet&)";
35 }

◆ ~TauDiscriminationProducerBase()

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::~TauDiscriminationProducerBase ( )
inlineoverride

Definition at line 68 of file TauDiscriminationProducerBase.h.

68 {}

Member Function Documentation

◆ beginEvent()

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
virtual void TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::beginEvent ( const edm::Event ,
const edm::EventSetup  
)
inlinevirtual

◆ discriminate()

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
virtual TauDiscriminatorDataType TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::discriminate ( const TauRef tau) const
pure virtual

◆ endEvent()

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
virtual void TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::endEvent ( edm::Event )
inlinevirtual

Definition at line 79 of file TauDiscriminationProducerBase.h.

79 {}

◆ fillProducerDescriptions()

template<class TauType , class TauDiscriminator , class TauDiscriminatorDataType , class ConsumeType >
void TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::fillProducerDescriptions ( edm::ParameterSetDescription desc)
static

Definition at line 173 of file TauDiscriminationProducerBase.cc.

Referenced by PFTauDecayModeCutMultiplexer::fillDescriptions(), TauDiscriminationAgainstElectronDeadECAL< TauType, TauDiscriminator >::fillDescriptions(), and reco::tau::PFRecoTauDiscriminationByMVAIsolationRun2::fillDescriptions().

173  {
174  // helper function, it fills the description of the Producers parameter
175  desc.add<edm::InputTag>(getTauTypeString() + "Producer", edm::InputTag("fixme"));
176  {
177  edm::ParameterSetDescription pset_prediscriminants;
178  pset_prediscriminants.add<std::string>("BooleanOperator", "AND");
179  // optional producers // will it pass if I don't specify them?
180 
181  {
182  edm::ParameterSetDescription producer_params;
183  producer_params.add<double>("cut", 0.);
184  producer_params.add<edm::InputTag>("Producer", edm::InputTag("fixme"));
185 
186  pset_prediscriminants.addOptional<edm::ParameterSetDescription>("leadTrack", producer_params);
187  pset_prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", producer_params);
188  }
189 
190  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_prediscriminants);
191  }
192 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
static std::string getTauTypeString()
helper method to retrieve tau type name, e.g. to build correct cfi getter
ParameterDescriptionBase * add(U const &iLabel, T const &value)

◆ getTauTypeString()

template<class TauType , class TauDiscriminator , class TauDiscriminatorDataType , class ConsumeType >
std::string TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::getTauTypeString ( )
static

helper method to retrieve tau type name, e.g. to build correct cfi getter

Definition at line 196 of file TauDiscriminationProducerBase.cc.

Referenced by TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauDiscriminationProducerBase().

196  {
198  return "PFTau";
200  return "PATTau";
201  throw cms::Exception("TauDiscriminationProducerBase")
202  << "Unsupported TauType used. You must use either PFTau or PATTau.";
203 }

◆ produce()

template<class TauType , class TauDiscriminator , class TauDiscriminatorDataType , class ConsumeType >
void TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
override

Definition at line 88 of file TauDiscriminationProducerBase.cc.

89  {
90  tauIndex_ = 0;
91  // setup function - does nothing in base, but can be overridden to retrieve PV or other stuff
93 
94  // retrieve the tau collection to discriminate
96  event.getByToken(Tau_token, taus);
97 
98  edm::ProductID tauProductID = taus.id();
99 
100  // output product
101  std::unique_ptr<TauDiscriminator> output = helper<TauDiscriminator, TauCollection>::init_result_object(taus);
102 
103  size_t nTaus = taus->size();
104 
105  // load prediscriminators
106  size_t nPrediscriminants = prediscriminants_.size();
107  for (size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
108  prediscriminants_[iDisc].fill(event);
109 
110  // Check to make sure the product is correct for the discriminator.
111  // If not, throw a more informative exception.
112  edm::ProductID discKeyId = prediscriminants_[iDisc].handle->keyProduct().id();
113  if (tauProductID != discKeyId) {
114  throw cms::Exception("MisconfiguredPrediscriminant")
115  << "The tau collection with input tag " << TauProducer_ << " has product ID: " << tauProductID
116  << " but the pre-discriminator with input tag " << prediscriminants_[iDisc].label
117  << " is keyed with product ID: " << discKeyId << std::endl;
118  }
119  }
120 
121  // loop over taus
122  for (size_t iTau = 0; iTau < nTaus; ++iTau) {
123  // get reference to tau
124  TauRef tauRef(taus, iTau);
125 
126  bool passesPrediscriminants = (andPrediscriminants_ ? 1 : 0);
127  // check tau passes prediscriminants
128  for (size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
129  // current discriminant result for this tau
130  double discResult = (*prediscriminants_[iDisc].handle)[tauRef];
131  uint8_t thisPasses = (discResult > prediscriminants_[iDisc].cut) ? 1 : 0;
132 
133  // if we are using the AND option, as soon as one fails,
134  // the result is FAIL and we can quit looping.
135  // if we are using the OR option as soon as one passes,
136  // the result is pass and we can quit looping
137 
138  // truth table
139  // | result (thisPasses)
140  // | F | T
141  //-----------------------------------
142  // AND(T) | res=fails | continue
143  // | break |
144  //-----------------------------------
145  // OR (F) | continue | res=passes
146  // | | break
147 
148  if (thisPasses ^ andPrediscriminants_) //XOR
149  {
150  passesPrediscriminants = (andPrediscriminants_ ? 0 : 1); //NOR
151  break;
152  }
153  }
154 
155  TauDiscriminatorDataType result = TauDiscriminatorDataType(prediscriminantFailValue_);
156  if (passesPrediscriminants) {
157  // this tau passes the prereqs, call our implemented discrimination function
158  result = discriminate(tauRef);
159  ++tauIndex_;
160  }
161 
162  // store the result of this tau into our new discriminator
163  (*output)[tauRef] = result;
164  }
165  event.put(std::move(output));
166 
167  // function to put additional information into the event - does nothing in base, but can be overridden in derived classes
168  endEvent(event);
169 }
virtual TauDiscriminatorDataType discriminate(const TauRef &tau) const =0
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< TauCollection > Tau_token
Definition: output.py:1
std::vector< TauDiscInfo > prediscriminants_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1

Member Data Documentation

◆ andPrediscriminants_

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
uint8_t TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::andPrediscriminants_
private

◆ moduleLabel_

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
std::string TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::moduleLabel_
protected

◆ prediscriminantFailValue_

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
double TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::prediscriminantFailValue_
protected

◆ prediscriminants_

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
std::vector<TauDiscInfo> TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::prediscriminants_
private

◆ Tau_token

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
edm::EDGetTokenT<TauCollection> TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::Tau_token
protected

◆ tauIndex_

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
size_t TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::tauIndex_
protected

Definition at line 109 of file TauDiscriminationProducerBase.h.

◆ TauProducer_

template<class TauType, class TauDiscriminator, class TauDiscriminatorDataType = double, class ConsumeType = TauDiscriminator>
edm::InputTag TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >::TauProducer_
protected