Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:45

0001 #ifndef RecoBTag_SecondaryVertex_VertexSorting_h
0002 #define RecoBTag_SecondaryVertex_VertexSorting_h
0003 
0004 #include <vector>
0005 #include <string>
0006 
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include <map>
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
0011 #include "DataFormats/VertexReco/interface/Vertex.h"
0012 #include "RecoBTag/SecondaryVertex/interface/SecondaryVertex.h"
0013 #include "RecoBTag/SecondaryVertex/interface/VertexSorting.h"
0014 
0015 namespace reco {
0016 
0017   template <class SecondaryVertex>
0018   class VertexSorting {
0019   public:
0020     VertexSorting(const edm::ParameterSet &params)
0021         : sortCriterium(getSortCriterium(params.getParameter<std::string>("sortCriterium"))) {}
0022     ~VertexSorting() {}
0023 
0024     std::vector<unsigned int> operator()(const std::vector<SecondaryVertex> &svCandidates) const;
0025 
0026   private:
0027     enum SortCriterium { sortDist3dVal = 0, sortDist3dErr, sortDist3dSig, sortDist2dErr, sortDist2dSig, sortDist2dVal };
0028 
0029     static SortCriterium getSortCriterium(const std::string &criterium);
0030 
0031     SortCriterium sortCriterium;
0032   };
0033 
0034   template <class SecondaryVertex>
0035   typename VertexSorting<SecondaryVertex>::SortCriterium VertexSorting<SecondaryVertex>::getSortCriterium(
0036       const std::string &criterium) {
0037     if (criterium == "dist3dError")
0038       return sortDist3dErr;
0039     if (criterium == "dist3dValue")
0040       return sortDist3dVal;
0041     if (criterium == "dist3dSignificance")
0042       return sortDist3dSig;
0043     if (criterium == "dist2dError")
0044       return sortDist2dErr;
0045     if (criterium == "dist2dValue")
0046       return sortDist2dVal;
0047     if (criterium == "dist2dSignificance")
0048       return sortDist2dSig;
0049 
0050     throw cms::Exception("InvalidArgument") << "Vertex sort criterium \"" << criterium << "\" is invalid." << std::endl;
0051   }
0052 
0053   // identify most probable SV (closest to interaction point, significance-wise)
0054   // FIXME: identify if this is the best strategy!
0055   template <class SecondaryVertex>
0056   std::vector<unsigned int> VertexSorting<SecondaryVertex>::operator()(
0057       const std::vector<SecondaryVertex> &svCandidates) const {
0058     Measurement1D (SecondaryVertex::*measurementFn)() const = nullptr;
0059     switch (sortCriterium) {
0060       case sortDist3dErr:
0061       case sortDist3dVal:
0062       case sortDist3dSig:
0063         measurementFn = &SecondaryVertex::dist3d;
0064         break;
0065       case sortDist2dErr:
0066       case sortDist2dVal:
0067       case sortDist2dSig:
0068         measurementFn = &SecondaryVertex::dist2d;
0069         break;
0070     }
0071 
0072     double (Measurement1D::*valueFn)() const = nullptr;
0073     switch (sortCriterium) {
0074       case sortDist3dErr:
0075       case sortDist2dErr:
0076         valueFn = &Measurement1D::error;
0077         break;
0078       case sortDist3dVal:
0079       case sortDist2dVal:
0080         valueFn = &Measurement1D::value;
0081         break;
0082       case sortDist3dSig:
0083       case sortDist2dSig:
0084         valueFn = &Measurement1D::significance;
0085         break;
0086     }
0087 
0088     std::multimap<double, unsigned int> sortedMap;
0089     unsigned int i = 0;
0090     for (typename std::vector<SecondaryVertex>::const_iterator iter = svCandidates.begin(); iter != svCandidates.end();
0091          iter++) {
0092       double value = std::abs((((*iter).*measurementFn)().*valueFn)());
0093       sortedMap.insert(std::make_pair(value, i++));
0094     }
0095 
0096     std::vector<unsigned int> result;
0097     for (std::multimap<double, unsigned int>::const_iterator iter = sortedMap.begin(); iter != sortedMap.end(); iter++)
0098       result.push_back(iter->second);
0099 
0100     return result;
0101   }
0102 }  // namespace reco
0103 
0104 #endif  // RecoBTag_SecondaryVertex_VertexSorting_h