Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-02 05:09:29

0001 #ifndef DataFormats_BTauReco_TaggingVariable_h
0002 #define DataFormats_BTauReco_TaggingVariable_h
0003 
0004 #include <utility>
0005 #include <vector>
0006 #include <string>
0007 
0008 #include <boost/pointee.hpp>
0009 #include <boost/type_traits/is_convertible.hpp>
0010 
0011 #include <Math/Functions.h>
0012 
0013 #include "DataFormats/Math/interface/Vector3D.h"
0014 
0015 #include "DataFormats/BTauReco/interface/RefMacros.h"
0016 #include "DataFormats/BTauReco/interface/ParticleMasses.h"
0017 
0018 namespace reco {
0019 
0020   namespace btau {
0021 
0022     inline double etaRel(const math::XYZVector& dir, const math::XYZVector& track) {
0023       double momPar = dir.Dot(track);
0024       double energy = std::sqrt(track.Mag2() + ROOT::Math::Square(reco::ParticleMasses::piPlus));
0025 
0026       return 0.5 * std::log((energy + momPar) / (energy - momPar));
0027     }
0028 
0029     // define the enum in a namespace to avoid polluting reco with all the enum values
0030     enum TaggingVariableName {
0031       jetEnergy = 0,       // jet energy
0032       jetPt,               // jet transverse momentum
0033       trackJetPt,          // track-based jet transverse momentum
0034       jetEta,              // jet pseudorapidity
0035       jetAbsEta,           // jet pseudorapidity
0036       jetPhi,              // jet polar angle
0037       jetNTracks,          // tracks associated to jet
0038       jetNSelectedTracks,  // tracks associated to jet
0039       jetNTracksEtaRel,    // number of tracks for which etaRel is computed
0040 
0041       trackMomentum,  // track momentum
0042       trackEta,       // track pseudorapidity
0043       trackPhi,       // track polar angle
0044 
0045       trackCharge,  // track charge
0046 
0047       trackPtRel,      // track transverse momentum, relative to the jet axis
0048       trackPPar,       // track parallel momentum, along the jet axis
0049       trackEtaRel,     // track pseudorapidity, relative to the jet axis
0050       trackDeltaR,     // track pseudoangular distance from the jet axis
0051       trackPtRatio,    // track transverse momentum, relative to the jet axis, normalized to its energy
0052       trackPParRatio,  // track parallel momentum, along the jet axis, normalized to its energy
0053 
0054       trackSip2dVal,           // track 2D signed impact parameter
0055       trackSip2dSig,           // track 2D signed impact parameter significance
0056       trackSip3dVal,           // track 3D signed impact parameter
0057       trackSip3dSig,           // track 3D signed impact parameter significance
0058       trackDecayLenVal,        // track decay length
0059       trackDecayLenSig,        // track decay length significance
0060       trackJetDistVal,         // minimum track approach distance to jet axis
0061       trackJetDistSig,         // minimum track approach distance to jet axis significance
0062       trackGhostTrackDistVal,  // minimum approach distance to ghost track
0063       trackGhostTrackDistSig,  // minimum approach distance to ghost track significance
0064       trackGhostTrackWeight,   // weight of track participation in ghost track fit
0065 
0066       trackSumJetEtRatio,  // ratio of track sum transverse energy over jet energy
0067       trackSumJetDeltaR,   // pseudoangular distance between jet axis and track fourvector sum
0068 
0069       vertexCategory,  // category of secondary vertex (Reco, Pseudo, No)
0070       vertexLeptonCategory,  // category of secondary vertex & soft lepton (RecoNo, PseudoNo, NoNo, RecoMu, PseudoMu, NoMu, RecoEl, PseudoEl, NoEl)
0071 
0072       jetNSecondaryVertices,    // number of reconstructed possible secondary vertices in jet
0073       jetNSingleTrackVertices,  // number of single-track ghost-track vertices
0074 
0075       vertexMass,     // mass of track sum at secondary vertex
0076       vertexNTracks,  // number of tracks at secondary vertex
0077       vertexFitProb,  // vertex fit probability
0078 
0079       vertexEnergyRatio,  // ratio of energy at secondary vertex over total energy
0080       vertexJetDeltaR,    // pseudoangular distance between jet axis and secondary vertex direction
0081 
0082       flightDistance1dVal,  // Longitudinal distance along the z-axis between primary and secondary vertex
0083       flightDistance1dSig,  // Longitudinal distance significance along the z-axis between primary and secondary vertex
0084       flightDistance2dVal,  // transverse distance between primary and secondary vertex
0085       flightDistance2dSig,  // transverse distance significance between primary and secondary vertex
0086       flightDistance3dVal,  // distance between primary and secondary vertex
0087       flightDistance3dSig,  // distance significance between primary and secondary vertex
0088 
0089       trackSip2dValAboveCharm,  // track 2D signed impact parameter of first track lifting mass above charm
0090       trackSip2dSigAboveCharm,  // track 2D signed impact parameter significance of first track lifting mass above charm
0091       trackSip3dValAboveCharm,  // track 3D signed impact parameter of first track lifting mass above charm
0092       trackSip3dSigAboveCharm,  // track 3D signed impact parameter significance of first track lifting mass above charm
0093 
0094       leptonQuality,   // lepton identification quality
0095       leptonQuality2,  // lepton identification quality 2
0096 
0097       trackP0Par,       // track momentum along the jet axis, in the jet rest frame
0098       trackP0ParRatio,  // track momentum along the jet axis, in the jet rest frame, normalized to its energy"
0099       trackChi2,        // track fit chi2
0100       trackNTotalHits,  // number of valid total hits
0101       trackNPixelHits,  // number of valid pixel hits
0102 
0103       chargedHadronEnergyFraction,  // fraction of the jet energy coming from charged hadrons
0104       neutralHadronEnergyFraction,  // fraction of the jet energy coming from neutral hadrons
0105       photonEnergyFraction,         // fraction of the jet energy coming from photons
0106       electronEnergyFraction,       // fraction of the jet energy coming from electrons
0107       muonEnergyFraction,           // fraction of the jet energy coming from muons
0108       chargedHadronMultiplicity,    // number of charged hadrons in the jet
0109       neutralHadronMultiplicity,    // number of neutral hadrons in the jet
0110       photonMultiplicity,           // number of photons in the jet
0111       electronMultiplicity,         // number of electrons in the jet
0112       muonMultiplicity,             // number of muons in the jet
0113       hadronMultiplicity,           // sum of number of charged and neutral hadrons in the jet
0114       hadronPhotonMultiplicity,     // sum of number of charged and neutral hadrons and photons in the jet
0115       totalMultiplicity,  // sum of number of charged and neutral hadrons, photons, electrons and muons in the jet
0116 
0117       massVertexEnergyFraction,  // vertexmass times fraction of the vertex energy w.r.t. the jet energy
0118       vertexBoostOverSqrtJetPt,  // variable related to the boost of the vertex system in flight direction
0119 
0120       leptonSip2d,     // 2D signed impact parameter of the soft lepton
0121       leptonSip3d,     // 3D signed impact parameter of the soft lepton
0122       leptonPtRel,     // transverse momentum of the soft lepton wrt. the jet axis
0123       leptonP0Par,     // momentum of the soft lepton along the jet direction, in the jet rest frame
0124       leptonEtaRel,    // pseudo)rapidity of the soft lepton along jet axis
0125       leptonDeltaR,    // pseudo)angular distance of the soft lepton to jet axis
0126       leptonRatio,     // momentum of the soft lepton over jet energy
0127       leptonRatioRel,  // momentum of the soft lepton parallel to jet axis over jet energy
0128       electronMVA,     // mva output from electron ID
0129 
0130       // ### specific to boosted double-b tagger (see BTV-15-002 PAS for more details) ###
0131       trackSip3dSig_0,  // 1st largest track 3D signed impact parameter significance
0132       trackSip3dSig_1,  // 2nd largest track 3D signed impact parameter significance
0133       trackSip3dSig_2,  // 3rd largest track 3D signed impact parameter significance
0134       trackSip3dSig_3,  // 4th largest track 3D signed impact parameter significance
0135       tau1_trackSip3dSig_0,  // 1st largest track 3D signed impact parameter significance associated to the 1st N-subjettiness axis
0136       tau1_trackSip3dSig_1,  // 2nd largest track 3D signed impact parameter significance associated to the 1st N-subjettiness axis
0137       tau2_trackSip3dSig_0,  // 1st largest track 3D signed impact parameter significance associated to the 2nd N-subjettiness axis
0138       tau2_trackSip3dSig_1,  // 2nd largest track 3D signed impact parameter significance associated to the 2nd N-subjettiness axis
0139       trackSip2dSigAboveBottom_0,  // track 2D signed impact parameter significance of 1st track lifting mass above bottom
0140       trackSip2dSigAboveBottom_1,  // track 2D signed impact parameter significance of 2nd track lifting mass above bottom
0141       tau1_trackEtaRel_0,  // 1st smallest track pseudorapidity, relative to the jet axis, associated to the 1st N-subjettiness axis
0142       tau1_trackEtaRel_1,  // 2nd smallest track pseudorapidity, relative to the jet axis, associated to the 1st N-subjettiness axis
0143       tau1_trackEtaRel_2,  // 3rd smallest track pseudorapidity, relative to the jet axis, associated to the 1st N-subjettiness axis
0144       tau2_trackEtaRel_0,  // 1st smallest track pseudorapidity, relative to the jet axis, associated to the 2nd N-subjettiness axis
0145       tau2_trackEtaRel_1,  // 2nd smallest track pseudorapidity, relative to the jet axis, associated to the 2nd N-subjettiness axis
0146       tau2_trackEtaRel_2,  // 3rd smallest track pseudorapidity, relative to the jet axis, associated to the 2nd N-subjettiness axis
0147       tau1_vertexMass,  // mass of track sum at secondary vertex associated to the 1st N-subjettiness axis
0148       tau1_vertexEnergyRatio,  // ratio of energy at secondary vertex over total energy associated to the 1st N-subjettiness axis
0149       tau1_flightDistance2dSig,  // transverse distance significance between primary and secondary vertex associated to the 1st N-subjettiness axis
0150       tau1_vertexDeltaR,  // pseudoangular distance between the 1st N-subjettiness axis and secondary vertex direction
0151       tau2_vertexMass,    // mass of track sum at secondary vertex associated to the 2nd N-subjettiness axis
0152       tau2_vertexEnergyRatio,  // ratio of energy at secondary vertex over total energy associated to the 2nd N-subjettiness axis
0153       tau2_flightDistance2dSig,  // transverse distance significance between primary and secondary vertex associated to the 2nd N-subjettiness axis
0154       tau2_vertexDeltaR,  // pseudoangular distance between the 2nd N-subjettiness axis and secondary vertex direction
0155       z_ratio,            // z ratio
0156 
0157       Jet_SoftMu,  // discriminator output of SoftMuon Tagger, used as input to (Deep)CMVA
0158       Jet_SoftEl,  // discriminator output of SoftElectron Tagger, used as input to (Deep)CMVA
0159       Jet_JBP,     // discriminator output of JPB Tagger, used as input to (Deep)CMVA
0160       Jet_JP,      // discriminator output of JP Tagger, used as input to (Deep)CMVA
0161       // #################################################################################
0162 
0163       algoDiscriminator,  // discriminator output of an algorithm
0164 
0165       lastTaggingVariable
0166     };
0167   }  // namespace btau
0168 
0169   // import only TaggingVariableName type into reco namespace
0170   using btau::TaggingVariableName;
0171 
0172   extern const char* const TaggingVariableDescription[];
0173   extern const char* const TaggingVariableTokens[];
0174 
0175   btau::TaggingVariableName getTaggingVariableName(const std::string& name);
0176 
0177   typedef float TaggingValue;
0178 
0179   // cannot use a const member since the STL containers relie on the default assignment operator
0180   // typedef std::pair< const TaggingVariableName, TaggingValue > TaggingVariable;
0181   typedef std::pair<btau::TaggingVariableName, TaggingValue> TaggingVariable;
0182 
0183   struct TaggingVariableCompare {
0184     bool operator()(const TaggingVariable& i, const TaggingVariable& j) { return i.first < j.first; }
0185 
0186     bool operator()(const TaggingVariable& i, btau::TaggingVariableName tag) { return i.first < tag; }
0187 
0188     bool operator()(btau::TaggingVariableName tag, const TaggingVariable& i) { return tag < i.first; }
0189   };
0190 
0191   // implementation via std::vector where
0192   //  - m_list is kept sorted via stable_sort after each insertion
0193   //  - extraction is done via binary search
0194   class TaggingVariableList {
0195   public:
0196     TaggingVariableList() : m_list() {}
0197     TaggingVariableList(const TaggingVariableList& list) : m_list(list.m_list) {}
0198     TaggingVariableList& operator=(const TaggingVariableList&) = default;
0199 
0200     // [begin, end) must identify a valid range of iterators to TaggingVariableList
0201     template <typename InputIterator>
0202     TaggingVariableList(const InputIterator begin, const InputIterator end) : m_list() {
0203       static_assert(
0204           (boost::is_convertible<const TaggingVariableList, typename boost::pointee<InputIterator>::type>::value));
0205       for (const InputIterator i = begin; i != end; i++)
0206         insert(*i);
0207     }
0208 
0209     /**
0210      *  STL-like accessors 
0211      */
0212     typedef std::vector<TaggingVariable>::const_iterator const_iterator;
0213     typedef std::pair<const_iterator, const_iterator> range;
0214     size_t size() const { return m_list.size(); }
0215     const_iterator begin() const { return m_list.begin(); }
0216     const_iterator end() const { return m_list.end(); }
0217     void push_back(const TaggingVariable& t) { m_list.push_back(t); }
0218 
0219     ~TaggingVariableList() {}
0220 
0221   private:
0222     std::vector<TaggingVariable> m_list;
0223 
0224   public:
0225     bool checkTag(btau::TaggingVariableName tag) const;
0226 
0227     void insert(const TaggingVariable& variable, bool delayed = false);
0228     void insert(const TaggingVariableList& list);
0229     void insert(btau::TaggingVariableName tag, TaggingValue value, bool delayed = false);
0230     void insert(btau::TaggingVariableName tag, const std::vector<TaggingValue>& values, bool delayed = false);
0231 
0232     void finalize(void);
0233 
0234     TaggingValue get(btau::TaggingVariableName tag) const;
0235     TaggingValue get(btau::TaggingVariableName tag, TaggingValue defaultValue) const;
0236     std::vector<TaggingValue> getList(btau::TaggingVariableName tag, bool throwOnEmptyList = true) const;
0237 
0238     range getRange(btau::TaggingVariableName tag) const;
0239 
0240     TaggingValue operator[](btau::TaggingVariableName tag) const { return get(tag); }
0241   };
0242 
0243   DECLARE_EDM_REFS(TaggingVariableList)
0244 
0245 }  // namespace reco
0246 
0247 #endif  // DataFormats_BTauReco_TaggingVariable_h