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 > Class Template Referenceabstract

#include <TauDiscriminationProducerBase.h>

Inheritance diagram for TauDiscriminationProducerBase< TauType, TauDiscriminator >:
edm::stream::EDProducer<> CaloRecoTauDiscriminationByDeltaE CaloRecoTauDiscriminationByLeadingTrackPtCut PATTauDiscriminantCutMultiplexer PATTauDiscriminationAgainstElectronMVA6 PFRecoTauDiscriminationAgainstElectron2 PFRecoTauDiscriminationAgainstElectronMVA5 PFRecoTauDiscriminationAgainstElectronMVA6 PFRecoTauDiscriminationAgainstMuon PFRecoTauDiscriminationAgainstMuon2 PFRecoTauDiscriminationAgainstMuonMVA PFRecoTauDiscriminationAgainstMuonSimple PFRecoTauDiscriminationByCharge PFRecoTauDiscriminationByDeltaE PFRecoTauDiscriminationByFlightPathSignificance PFRecoTauDiscriminationByHPSSelection PFRecoTauDiscriminationByInvMass PFRecoTauDiscriminationByIsolation PFRecoTauDiscriminationByIsolationMVA2 PFRecoTauDiscriminationByLeadingObjectPtCut PFRecoTauDiscriminationByNProngs PFRecoTauDiscriminationByTauPolarization PFTauDecayModeCutMultiplexer PFTauDiscriminatorLogicalAndProducer reco::tau::PATTauDiscriminationByMVAIsolationRun2 reco::tau::PFRecoTauDiscriminationByMVAIsolationRun2 RecoTauDecayModeCutMultiplexer RecoTauDiscriminantCutMultiplexer RecoTauDiscriminationByGenMatch RecoTauMVATransform TauDiscriminationAgainstElectronDeadECAL< TauType, TauDiscriminator >

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<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Public Member Functions

virtual void beginEvent (const edm::Event &, const edm::EventSetup &)
 
virtual double 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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

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 TauDiscriminationProducerBase< TauType, TauDiscriminator >

Definition at line 54 of file TauDiscriminationProducerBase.h.

Member Typedef Documentation

template<class TauType , class TauDiscriminator >
typedef std::vector<TauType> TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauCollection

Definition at line 57 of file TauDiscriminationProducerBase.h.

template<class TauType , class TauDiscriminator >
typedef edm::Ref<TauCollection> TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauRef

Definition at line 58 of file TauDiscriminationProducerBase.h.

template<class TauType , class TauDiscriminator >
typedef edm::RefProd<TauCollection> TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauRefProd

Definition at line 59 of file TauDiscriminationProducerBase.h.

Constructor & Destructor Documentation

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

Definition at line 17 of file TauDiscriminationProducerBase.cc.

References TauDiscriminationProducerBase< TauType, TauDiscriminator >::andPrediscriminants_, TkAlMuonSelectors_cfi::cut, Exception, edm::ParameterSet::getParameter(), TauDiscriminationProducerBase< TauType, TauDiscriminator >::getTauTypeString(), label, TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauDiscInfo::label, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminantFailValue_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminants_, AlCaHLTBitMon_QueryRunRegistry::string, TauDiscriminationProducerBase< TauType, TauDiscriminator >::Tau_token, TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauProducer_, and create_public_lumi_plots::transform.

18  : moduleLabel_(iConfig.getParameter<std::string>("@module_label"))
19 {
20  // tau collection to discriminate
21  TauProducer_ = iConfig.getParameter<edm::InputTag>(getTauTypeString() + "Producer");
22  Tau_token = consumes<TauCollection>(TauProducer_);
23 
24  // prediscriminant operator
25  // require the tau to pass the following prediscriminants
26  const edm::ParameterSet& prediscriminantConfig = iConfig.getParameter<edm::ParameterSet>("Prediscriminants");
27 
28  // determine boolean operator used on the prediscriminants
29  std::string pdBoolOperator = prediscriminantConfig.getParameter<std::string>("BooleanOperator");
30  // convert string to lowercase
31  transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
32 
33  if( pdBoolOperator == "and" )
34  {
35  andPrediscriminants_ = 0x1; //use chars instead of bools so we can do a bitwise trick later
36  }
37  else if ( pdBoolOperator == "or" )
38  {
40  }
41  else
42  {
43  throw cms::Exception("TauDiscriminationProducerBase") << "PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
44  }
45 
46  // get the list of prediscriminants
47  std::vector<std::string> prediscriminantsNames = prediscriminantConfig.getParameterNamesForType<edm::ParameterSet>();
48 
49  for( std::vector<std::string>::const_iterator iDisc = prediscriminantsNames.begin();
50  iDisc != prediscriminantsNames.end(); ++iDisc )
51  {
52  const edm::ParameterSet& iPredisc = prediscriminantConfig.getParameter<edm::ParameterSet>(*iDisc);
53  const edm::InputTag& label = iPredisc.getParameter<edm::InputTag>("Producer");
54  double cut = iPredisc.getParameter<double>("cut");
55 
56  TauDiscInfo thisDiscriminator;
57  thisDiscriminator.label = label;
58  thisDiscriminator.cut = cut;
59  thisDiscriminator.disc_token = consumes<TauDiscriminator>(label);
60  prediscriminants_.push_back(thisDiscriminator);
61  }
62 
64 
65  // register product
66  produces<TauDiscriminator>();
67 }
T getParameter(std::string const &) const
std::vector< TauDiscInfo > prediscriminants_
char const * label
edm::EDGetTokenT< TauCollection > Tau_token
static std::string getTauTypeString()
helper method to retrieve tau type name, e.g. to build correct cfi getter
template<class TauType , class TauDiscriminator >
TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauDiscriminationProducerBase ( )

Definition at line 9 of file TauDiscriminationProducerBase.cc.

References Exception.

10 {
11  throw cms::Exception("TauDiscriminationProducerBase") << " -- default ctor called; derived classes must call " <<
12  "TauDiscriminationProducerBase(const ParameterSet&)";
13 }
template<class TauType , class TauDiscriminator >
TauDiscriminationProducerBase< TauType, TauDiscriminator >::~TauDiscriminationProducerBase ( )
inlineoverride

Member Function Documentation

template<class TauType , class TauDiscriminator >
virtual void TauDiscriminationProducerBase< TauType, TauDiscriminator >::beginEvent ( const edm::Event ,
const edm::EventSetup  
)
inlinevirtual
template<class TauType , class TauDiscriminator >
virtual double TauDiscriminationProducerBase< TauType, TauDiscriminator >::discriminate ( const TauRef tau) const
pure virtual
template<class TauType , class TauDiscriminator >
virtual void TauDiscriminationProducerBase< TauType, TauDiscriminator >::endEvent ( edm::Event )
inlinevirtual
template<class TauType , class TauDiscriminator >
void TauDiscriminationProducerBase< TauType, TauDiscriminator >::fillProducerDescriptions ( edm::ParameterSetDescription desc)
static

Definition at line 160 of file TauDiscriminationProducerBase.cc.

References edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), TauDiscriminationProducerBase< TauType, TauDiscriminator >::getTauTypeString(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauDiscInfo::fill(), RecoTauDecayModeCutMultiplexer::fillDescriptions(), RecoTauDiscriminantCutMultiplexer::fillDescriptions(), PATTauDiscriminantCutMultiplexer::fillDescriptions(), PFTauDecayModeCutMultiplexer::fillDescriptions(), TauDiscriminationAgainstElectronDeadECAL< TauType, TauDiscriminator >::fillDescriptions(), RecoTauMVATransform::fillDescriptions(), and reco::tau::PFRecoTauDiscriminationByMVAIsolationRun2::fillDescriptions().

160  {
161  // helper function, it fills the description of the Producers parameter
162  desc.add<edm::InputTag>(getTauTypeString() + "Producer", edm::InputTag("fixme"));
163  {
164  edm::ParameterSetDescription pset_prediscriminants;
165  pset_prediscriminants.add<std::string>("BooleanOperator","AND");
166  // optional producers // will it pass if I don't specify them?
167 
168  {
169  edm::ParameterSetDescription producer_params;
170  producer_params.add<double>("cut",0.);
171  producer_params.add<edm::InputTag>("Producer",edm::InputTag("fixme"));
172 
173  pset_prediscriminants.addOptional<edm::ParameterSetDescription>("leadTrack", producer_params);
174  pset_prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", producer_params);
175  }
176 
177  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_prediscriminants);
178  }
179 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static std::string getTauTypeString()
helper method to retrieve tau type name, e.g. to build correct cfi getter
template<class TauType , class TauDiscriminator >
std::string TauDiscriminationProducerBase< TauType, TauDiscriminator >::getTauTypeString ( )
static

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

Definition at line 182 of file TauDiscriminationProducerBase.cc.

References Exception, and relativeConstraints::value.

Referenced by TauDiscriminationAgainstElectronDeadECAL< TauType, TauDiscriminator >::discriminate(), TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauDiscInfo::fill(), TauDiscriminationProducerBase< TauType, TauDiscriminator >::fillProducerDescriptions(), and TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauDiscriminationProducerBase().

182  {
184  return "PFTau";
186  return "CaloTau";
188  return "PATTau";
189  throw cms::Exception("TauDiscriminationProducerBase")
190  << "Unsupported TauType used. You must use either PFTau, PATTau or CaloTau.";
191 }
template<class TauType , class TauDiscriminator >
void TauDiscriminationProducerBase< TauType, TauDiscriminator >::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
override

Definition at line 70 of file TauDiscriminationProducerBase.cc.

References TauDiscriminationProducerBase< TauType, TauDiscriminator >::andPrediscriminants_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::beginEvent(), TauDiscriminationProducerBase< TauType, TauDiscriminator >::discriminate(), TauDiscriminationProducerBase< TauType, TauDiscriminator >::endEvent(), Exception, edm::HandleBase::id(), eostools::move(), convertSQLitetoXML_cfg::output, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminantFailValue_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminants_, mps_fire::result, TauDiscriminationProducerBase< TauType, TauDiscriminator >::Tau_token, TauDiscriminationProducerBase< TauType, TauDiscriminator >::tauIndex_, TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauProducer_, and nano_cff::taus.

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

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

Member Data Documentation

template<class TauType , class TauDiscriminator >
uint8_t TauDiscriminationProducerBase< TauType, TauDiscriminator >::andPrediscriminants_
private
template<class TauType , class TauDiscriminator >
std::string TauDiscriminationProducerBase< TauType, TauDiscriminator >::moduleLabel_
protected
template<class TauType , class TauDiscriminator >
double TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminantFailValue_
protected
template<class TauType , class TauDiscriminator >
std::vector<TauDiscInfo> TauDiscriminationProducerBase< TauType, TauDiscriminator >::prediscriminants_
private
template<class TauType , class TauDiscriminator >
edm::EDGetTokenT<TauCollection> TauDiscriminationProducerBase< TauType, TauDiscriminator >::Tau_token
protected
template<class TauType , class TauDiscriminator >
size_t TauDiscriminationProducerBase< TauType, TauDiscriminator >::tauIndex_
protected
template<class TauType , class TauDiscriminator >
edm::InputTag TauDiscriminationProducerBase< TauType, TauDiscriminator >::TauProducer_
protected