Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:52

0001 #ifndef DataFormats_BTauReco_TemplatedSoftLeptonTagInfo_h
0002 #define DataFormats_BTauReco_TemplatedSoftLeptonTagInfo_h
0003 
0004 #include <vector>
0005 #include <limits>
0006 
0007 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0008 #include "DataFormats/BTauReco/interface/RefMacros.h"
0009 #include "DataFormats/BTauReco/interface/JetTagInfo.h"
0010 #include "DataFormats/BTauReco/interface/IPTagInfo.h"
0011 #include "DataFormats/BTauReco/interface/TaggingVariable.h"
0012 
0013 namespace reco {
0014 
0015   class SoftLeptonProperties {
0016   public:
0017     SoftLeptonProperties()
0018         : sip2dsig(std::numeric_limits<float>::quiet_NaN()),
0019           sip3dsig(std::numeric_limits<float>::quiet_NaN()),
0020           sip2d(std::numeric_limits<float>::quiet_NaN()),
0021           sip3d(std::numeric_limits<float>::quiet_NaN()),
0022           ptRel(std::numeric_limits<float>::quiet_NaN()),
0023           p0Par(std::numeric_limits<float>::quiet_NaN()),
0024           etaRel(std::numeric_limits<float>::quiet_NaN()),
0025           deltaR(std::numeric_limits<float>::quiet_NaN()),
0026           ratio(std::numeric_limits<float>::quiet_NaN()),
0027           ratioRel(std::numeric_limits<float>::quiet_NaN()),
0028           elec_mva(std::numeric_limits<float>::quiet_NaN()),
0029           charge(-10) {}
0030 
0031     float sip2dsig;  // 2D signed impact parameter significance
0032     float sip3dsig;  // 3D signed impact parameter significance
0033     float sip2d;     // 2D signed impact parameter
0034     float sip3d;     // 3D signed impact parameter
0035     float ptRel;     // transverse momentum wrt. the jet axis
0036     float p0Par;     // momentum along the jet direction, in the jet rest frame
0037 
0038     float etaRel;    // (pseudo)rapidity along jet axis
0039     float deltaR;    // (pseudo)angular distance to jet axis
0040     float ratio;     // momentum over jet energy
0041     float ratioRel;  // momentum parallel to jet axis over jet energy
0042 
0043     float elec_mva;
0044 
0045     int charge;
0046 
0047     struct Quality {
0048       static const float undef;
0049 
0050       // these first two entries work for both electrons and muons,
0051       // entries afterwards can be specific to either one
0052       // electrons & muons shared the same indicies to avoid waste of space
0053       enum Generic { leptonId = 0, btagLeptonCands };
0054 
0055       enum Electron { pfElectronId = 0, btagElectronCands, egammaElectronId };
0056 
0057       enum Muon { muonId = 0, btagMuonCands };
0058 
0059       template <typename T>
0060       static inline T byName(const char *name) {
0061         return static_cast<T>(internalByName(name));
0062       }
0063 
0064     private:
0065       static unsigned int internalByName(const char *name);
0066     };
0067 
0068     // check to see if quality has been set
0069 
0070     inline float hasQuality() const { return quality() != Quality::undef; }
0071     inline float hasQuality(Quality::Generic qual) const {
0072       return quality((unsigned int)qual, false) != Quality::undef;
0073     }
0074     inline float hasQuality(Quality::Muon qual) const { return quality((unsigned int)qual, false) != Quality::undef; }
0075     inline float hasQuality(Quality::Electron qual) const {
0076       return quality((unsigned int)qual, false) != Quality::undef;
0077     }
0078 
0079     // retrieve lepton quality
0080 
0081     inline float quality(Quality::Generic qual, bool throwIfUndefined = true) const {
0082       return quality((unsigned int)qual, throwIfUndefined);
0083     }
0084     inline float quality(Quality::Muon qual, bool throwIfUndefined = true) const {
0085       return quality((unsigned int)qual, throwIfUndefined);
0086     }
0087     inline float quality(Quality::Electron qual, bool throwIfUndefined = true) const {
0088       return quality((unsigned int)qual, throwIfUndefined);
0089     }
0090 
0091     // default value
0092     inline float quality() const { return quality(0, false); }
0093 
0094     // set lepton quality
0095 
0096     inline void setQuality(Quality::Generic qual, float value) { setQuality((unsigned int)qual, value); }
0097     inline void setQuality(Quality::Muon qual, float value) { setQuality((unsigned int)qual, value); }
0098     inline void setQuality(Quality::Electron qual, float value) { setQuality((unsigned int)qual, value); }
0099 
0100   private:
0101     float quality(unsigned int index, bool throwIfUndefined) const;
0102     void setQuality(unsigned int index, float value);
0103 
0104     std::vector<float> qualities_;  // lepton qualities
0105   };
0106 
0107   template <class REF>
0108   class TemplatedSoftLeptonTagInfo : public JetTagInfo {
0109   public:
0110     typedef std::vector<std::pair<REF, SoftLeptonProperties> > LeptonMap;
0111 
0112     TemplatedSoftLeptonTagInfo(void) : m_leptons() {}
0113 
0114     ~TemplatedSoftLeptonTagInfo(void) override {}
0115 
0116     TemplatedSoftLeptonTagInfo *clone(void) const override { return new TemplatedSoftLeptonTagInfo(*this); }
0117 
0118     unsigned int leptons(void) const { return m_leptons.size(); }
0119 
0120     const REF &lepton(size_t i) const { return m_leptons[i].first; }
0121 
0122     const SoftLeptonProperties &properties(size_t i) const { return m_leptons[i].second; }
0123 
0124     void insert(const REF &lepton, const SoftLeptonProperties &properties) {
0125       m_leptons.push_back(std::pair<REF, SoftLeptonProperties>(lepton, properties));
0126     }
0127 
0128     /// returns a description of the extended informations in a TaggingVariableList
0129     TaggingVariableList taggingVariables(void) const override;
0130 
0131     // Used by ROOT storage
0132     CMS_CLASS_VERSION(2)
0133 
0134   private:
0135     LeptonMap m_leptons;
0136   };
0137 
0138   template <class REF>
0139   TaggingVariableList TemplatedSoftLeptonTagInfo<REF>::taggingVariables(void) const {
0140     TaggingVariableList list;
0141 
0142     const Jet &jet = *(this->jet());
0143     list.insert(TaggingVariable(btau::jetEnergy, jet.energy()), true);
0144     list.insert(TaggingVariable(btau::jetPt, jet.et()), true);
0145     list.insert(TaggingVariable(btau::jetEta, jet.eta()), true);
0146     list.insert(TaggingVariable(btau::jetPhi, jet.phi()), true);
0147 
0148     for (unsigned int i = 0; i < m_leptons.size(); ++i) {
0149       const REF &trackRef = m_leptons[i].first;
0150       list.insert(TaggingVariable(btau::trackMomentum, reco::btag::toTrack(trackRef)->p()), true);
0151       list.insert(TaggingVariable(btau::trackEta, reco::btag::toTrack(trackRef)->eta()), true);
0152       list.insert(TaggingVariable(btau::trackPhi, reco::btag::toTrack(trackRef)->phi()), true);
0153       list.insert(TaggingVariable(btau::trackChi2, reco::btag::toTrack(trackRef)->normalizedChi2()), true);
0154       const SoftLeptonProperties &data = m_leptons[i].second;
0155       list.insert(TaggingVariable(btau::leptonQuality, data.quality(SoftLeptonProperties::Quality::leptonId, false)),
0156                   true);
0157       list.insert(
0158           TaggingVariable(btau::leptonQuality2, data.quality(SoftLeptonProperties::Quality::btagLeptonCands, false)),
0159           true);
0160       list.insert(TaggingVariable(btau::trackSip2dVal, data.sip2d), true);
0161       list.insert(TaggingVariable(btau::trackSip3dVal, data.sip3d), true);
0162       list.insert(TaggingVariable(btau::trackSip2dSig, data.sip2dsig), true);
0163       list.insert(TaggingVariable(btau::trackSip3dSig, data.sip3dsig), true);
0164       list.insert(TaggingVariable(btau::trackPtRel, data.ptRel), true);
0165       list.insert(TaggingVariable(btau::trackP0Par, data.p0Par), true);
0166       list.insert(TaggingVariable(btau::trackEtaRel, data.etaRel), true);
0167       list.insert(TaggingVariable(btau::trackDeltaR, data.deltaR), true);
0168       list.insert(TaggingVariable(btau::trackPParRatio, data.ratioRel), true);
0169       list.insert(TaggingVariable(btau::electronMVA, data.elec_mva), true);
0170       list.insert(TaggingVariable(btau::trackCharge, data.charge), true);
0171     }
0172 
0173     list.finalize();
0174     return list;
0175   }
0176 
0177 }  // namespace reco
0178 
0179 #endif  // DataFormats_BTauReco_TemplatedSoftLeptonTagInfo_h