CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoBTau/JetTagComputer/interface/JetTagComputer.h

Go to the documentation of this file.
00001 #ifndef RecoBTau_JetTagComputer_h
00002 #define RecoBTau_JetTagComputer_h
00003 
00004 #include <vector>
00005 #include <string>
00006 
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include "DataFormats/BTauReco/interface/BaseTagInfo.h"
00011 
00012 class JetTagComputer {
00013     public:
00014         class TagInfoHelper {
00015             public:
00016                 TagInfoHelper(const std::vector<const reco::BaseTagInfo*> &infos) :
00017                         m_tagInfos(infos) {}
00018                 ~TagInfoHelper() {}
00019 
00020                 const reco::BaseTagInfo &getBase(unsigned int index) const
00021                 {
00022                         if (index >= m_tagInfos.size())
00023                                 throw cms::Exception("InvalidIndex")
00024                                         << "Invalid index " << index << " "
00025                                            "in call to JetTagComputer::get."
00026                                         << std::endl;
00027 
00028                         const reco::BaseTagInfo *info = m_tagInfos[index];
00029                         if (!info)
00030                                 throw cms::Exception("ProductMissing")
00031                                         << "Missing TagInfo "
00032                                            "in call to JetTagComputer::get."
00033                                         << std::endl;
00034 
00035                         return *info;
00036                 }
00037 
00038                 template<class T>
00039                 const T &get(unsigned int index = 0) const
00040                 {
00041                         const reco::BaseTagInfo *info = &getBase(index);
00042                         const T *castInfo = dynamic_cast<const T*>(info);
00043                         if (!castInfo)
00044                                 throw cms::Exception("InvalidCast")
00045                                         << "Invalid TagInfo cast "
00046                                            "in call to JetTagComputer::get."
00047                                         << std::endl;
00048 
00049                         return *castInfo;
00050                 }
00051 
00052             private:
00053                 const std::vector<const reco::BaseTagInfo*>     &m_tagInfos;
00054         };
00055 
00056         // default constructor
00057         JetTagComputer() : m_setupDone(false) {}
00058         virtual ~JetTagComputer() {}
00059 
00060         // explicit constructor accepting a ParameterSet for configuration
00061         explicit JetTagComputer(const edm::ParameterSet& configuration) :
00062                 m_setupDone(false) {}
00063 
00064         virtual void setEventSetup(const edm::EventSetup&) const {}
00065 
00066         float operator () (const reco::BaseTagInfo& info) const;
00067         inline float operator () (const TagInfoHelper &helper) const
00068         { return discriminator(helper); }
00069 
00070         inline const std::vector<std::string> &getInputLabels() const
00071         { m_setupDone = true; return m_inputLabels; }
00072 
00073     protected:
00074         void uses(unsigned int id, const std::string &label);
00075         void uses(const std::string &label) { uses(0, label); }
00076 
00077         virtual float discriminator(const reco::BaseTagInfo&) const;
00078         virtual float discriminator(const TagInfoHelper&) const;
00079 
00080     private:
00081         std::vector<std::string>        m_inputLabels;
00082         mutable bool                    m_setupDone;
00083 };
00084 
00085 #endif // RecoBTau_JetTagComputer_h