Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:47

0001 #ifndef RecoTauTag_RecoTau_TauDiscriminationProducerBase_H_
0002 #define RecoTauTag_RecoTau_TauDiscriminationProducerBase_H_
0003 
0004 /* class TauDiscriminationProducerBase
0005  *
0006  * Base classes for producing PFTau and PatTau discriminators
0007  *
0008  * PFTaus   - inherit from PFTauDiscriminationProducerBase
0009  * PatTaus - inherit from PatTauDiscriminationProducerBase
0010  *
0011  * The base class takes a (PF/PAT)Tau collection and a collection of
0012  * associated (PF/PAT)TauDiscriminators.  Each tau is required to pass the given
0013  * set of prediscriminants.  Taus that pass these are then passed to the
0014  * pure virtual function
0015  *
0016  *      double discriminate(const TauRef&);
0017  *
0018  * The derived classes should implement this function and return a double
0019  * giving the specific discriminant result for this tau.
0020  *
0021  * The edm::Event and EventSetup are available to the derived classes
0022  * at the beginning of the event w/ the virtual function
0023  *
0024  *      void beginEvent(...)
0025  *
0026  * The derived classes can set the desired value for taus that fail the
0027  * prediscriminants by setting the protected variable prediscriminantFailValue_
0028  *
0029  * created :  Wed Aug 12 16:58:37 PDT 2009
0030  * Authors :  Evan Friis (UC Davis), Simone Gennai (SNS)
0031  */
0032 
0033 #include "FWCore/Framework/interface/stream/EDProducer.h"
0034 #include "FWCore/Framework/interface/Event.h"
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 #include "FWCore/Framework/interface/MakerMacros.h"
0038 #include "FWCore/Framework/interface/ConsumesCollector.h"
0039 
0040 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0041 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0042 
0043 #include "DataFormats/TauReco/interface/PFTau.h"
0044 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
0045 #include "DataFormats/TauReco/interface/TauDiscriminatorContainer.h"
0046 
0047 #include "DataFormats/PatCandidates/interface/Tau.h"
0048 #include "DataFormats/PatCandidates/interface/PATTauDiscriminator.h"
0049 
0050 template <class TauType,
0051           class TauDiscriminator,
0052           class TauDiscriminatorDataType = double,
0053           class ConsumeType = TauDiscriminator>
0054 class TauDiscriminationProducerBase : public edm::stream::EDProducer<> {
0055 public:
0056   // setup framework types for this tautype
0057   typedef std::vector<TauType> TauCollection;
0058   typedef edm::Ref<TauCollection> TauRef;
0059   typedef edm::RefProd<TauCollection> TauRefProd;
0060 
0061   // standard constructor from PSet
0062   explicit TauDiscriminationProducerBase(const edm::ParameterSet& iConfig);
0063 
0064   // default constructor must not be called - it will throw an exception
0065   // derived!  classes must call the parameterset constructor.
0066   TauDiscriminationProducerBase();
0067 
0068   ~TauDiscriminationProducerBase() override {}
0069 
0070   void produce(edm::Event&, const edm::EventSetup&) override;
0071 
0072   // called at the beginning of every event - override if necessary.
0073   virtual void beginEvent(const edm::Event&, const edm::EventSetup&) {}
0074 
0075   // abstract functions implemented in derived classes.
0076   virtual TauDiscriminatorDataType discriminate(const TauRef& tau) const = 0;
0077 
0078   // called at the end of event processing - override if necessary.
0079   virtual void endEvent(edm::Event&) {}
0080 
0081   struct TauDiscInfo {
0082     edm::InputTag label;
0083     edm::Handle<ConsumeType> handle;
0084     edm::EDGetTokenT<ConsumeType> disc_token;
0085     // = consumes<ConsumeType>(label);
0086     double cut;
0087     void fill(const edm::Event& evt) {
0088       //    disc_token = consumes<ConsumeType>(label);
0089       evt.getByToken(disc_token, handle);
0090     };
0091   };
0092 
0093   static void fillProducerDescriptions(edm::ParameterSetDescription& desc);
0094 
0095   /// helper method to retrieve tau type name, e.g. to build correct cfi getter
0096   //string (i.e. PFTau/PATTauProducer)
0097   static std::string getTauTypeString();
0098 
0099 protected:
0100   //value given to taus that fail prediscriminants
0101   double prediscriminantFailValue_;
0102 
0103   edm::InputTag TauProducer_;
0104 
0105   std::string moduleLabel_;
0106   edm::EDGetTokenT<TauCollection> Tau_token;
0107 
0108   // current tau
0109   size_t tauIndex_;
0110 
0111 private:
0112   std::vector<TauDiscInfo> prediscriminants_;
0113   // select boolean operation on prediscriminants (and = 0x01, or = 0x00)
0114   uint8_t andPrediscriminants_;
0115 };
0116 
0117 // define our implementations
0118 typedef TauDiscriminationProducerBase<reco::PFTau,
0119                                       reco::TauDiscriminatorContainer,
0120                                       reco::SingleTauDiscriminatorContainer,
0121                                       reco::PFTauDiscriminator>
0122     PFTauDiscriminationContainerProducerBase;
0123 typedef TauDiscriminationProducerBase<reco::PFTau, reco::PFTauDiscriminator> PFTauDiscriminationProducerBase;
0124 typedef TauDiscriminationProducerBase<pat::Tau,
0125                                       reco::TauDiscriminatorContainer,
0126                                       reco::SingleTauDiscriminatorContainer,
0127                                       pat::PATTauDiscriminator>
0128     PATTauDiscriminationContainerProducerBase;
0129 typedef TauDiscriminationProducerBase<pat::Tau, pat::PATTauDiscriminator> PATTauDiscriminationProducerBase;
0130 
0131 #endif