Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:09

0001 #ifndef RecoTracker_FinalTrackSelectors_trackAlgoPriorityOrder_h
0002 #define RecoTracker_FinalTrackSelectors_trackAlgoPriorityOrder_h
0003 
0004 #include "DataFormats/TrackReco/interface/TrackBase.h"
0005 
0006 #include <array>
0007 
0008 /**
0009  * To obtain the priority order, please use the TrackAlgoPriorityOrder
0010  * class instead. This header is internal to it, and exists in a
0011  * separate file only to allow a unit test to be run.
0012  *
0013  * The trackAlgoPriorityOrder maps an reco::TrackBase::TrackAlgorithm
0014  * enumerator to its priority in track list merging. The mapping is
0015  * needed because the order of the enumerators themselves does not, in
0016  * general, convey useful information.
0017  */
0018 namespace impl {
0019 
0020   /**
0021    * This array defines the priority order in merging for the
0022    * algorithms. The order is ascending, i.e. the first algorithm has
0023    * the highest priority etc. The size of the array should be
0024    * reco::TrackBase:algoSize (checked below with static_assert), and
0025    * each reco::TrackBase::TrackAlgorithm enumerator should be in the
0026    * array exactly once (checked below in findIndex() function).
0027    */
0028   constexpr reco::TrackBase::TrackAlgorithm algoPriorityOrder[] = {reco::TrackBase::undefAlgorithm,
0029                                                                    reco::TrackBase::ctf,
0030                                                                    reco::TrackBase::cosmics,
0031                                                                    reco::TrackBase::duplicateMerge,
0032                                                                    reco::TrackBase::initialStep,
0033                                                                    reco::TrackBase::highPtTripletStep,
0034                                                                    reco::TrackBase::detachedQuadStep,
0035                                                                    reco::TrackBase::detachedTripletStep,
0036                                                                    reco::TrackBase::lowPtQuadStep,
0037                                                                    reco::TrackBase::lowPtTripletStep,
0038                                                                    reco::TrackBase::pixelPairStep,
0039                                                                    reco::TrackBase::mixedTripletStep,
0040                                                                    reco::TrackBase::pixelLessStep,
0041                                                                    reco::TrackBase::tobTecStep,
0042                                                                    reco::TrackBase::displacedGeneralStep,
0043                                                                    reco::TrackBase::jetCoreRegionalStep,
0044                                                                    reco::TrackBase::conversionStep,
0045                                                                    reco::TrackBase::muonSeededStepInOut,
0046                                                                    reco::TrackBase::muonSeededStepOutIn,
0047                                                                    reco::TrackBase::displacedRegionalStep,
0048                                                                    reco::TrackBase::outInEcalSeededConv,
0049                                                                    reco::TrackBase::inOutEcalSeededConv,
0050                                                                    reco::TrackBase::nuclInter,
0051                                                                    reco::TrackBase::standAloneMuon,
0052                                                                    reco::TrackBase::globalMuon,
0053                                                                    reco::TrackBase::cosmicStandAloneMuon,
0054                                                                    reco::TrackBase::cosmicGlobalMuon,
0055                                                                    reco::TrackBase::bTagGhostTracks,
0056                                                                    reco::TrackBase::beamhalo,
0057                                                                    reco::TrackBase::gsf,
0058                                                                    reco::TrackBase::hltPixel,
0059                                                                    reco::TrackBase::hltIter0,
0060                                                                    reco::TrackBase::hltIter1,
0061                                                                    reco::TrackBase::hltIter2,
0062                                                                    reco::TrackBase::hltIter3,
0063                                                                    reco::TrackBase::hltIter4,
0064                                                                    reco::TrackBase::hltIterX,
0065                                                                    reco::TrackBase::hiRegitMuInitialStep,
0066                                                                    reco::TrackBase::hiRegitMuPixelPairStep,
0067                                                                    reco::TrackBase::hiRegitMuMixedTripletStep,
0068                                                                    reco::TrackBase::hiRegitMuPixelLessStep,
0069                                                                    reco::TrackBase::hiRegitMuDetachedTripletStep,
0070                                                                    reco::TrackBase::hiRegitMuMuonSeededStepInOut,
0071                                                                    reco::TrackBase::hiRegitMuMuonSeededStepOutIn,
0072                                                                    reco::TrackBase::hiRegitMuLowPtTripletStep,
0073                                                                    reco::TrackBase::hiRegitMuTobTecStep};
0074 
0075   static_assert(reco::TrackBase::algoSize == sizeof(algoPriorityOrder) / sizeof(unsigned int),
0076                 "Please update me too after adding new enumerators to reco::TrackBase::TrackAlgorithm");
0077 
0078   /**
0079    * Recursive implementation of searching the index of an algorithm in the algoPriorityOrder
0080    *
0081    * @param algo   Algorithm whose index is searched for
0082    * @param index  Current index
0083    *
0084    * @return Index of the algorithm; if not found results compile error
0085    */
0086   constexpr unsigned int findIndex(const reco::TrackBase::TrackAlgorithm algo, const unsigned int index) {
0087     return index < sizeof(algoPriorityOrder)/sizeof(unsigned int) ?
0088       (algo == algoPriorityOrder[index] ? index : findIndex(algo, index+1)) :
0089       throw "Index out of bounds, this means that some reco::TrackBase::TrackAlgorithm enumerator is missing from impl::algoPriorityOrder array.";
0090   }
0091 
0092   /**
0093    * Find the order priority for a track algorithm
0094    *
0095    * @param algo  algorithm whose index is searched for
0096    *
0097    * @return Index of the algorithm in impl::algoPriorityOrder array; if not found results compile error
0098    *
0099    * @see findIndex()
0100    */
0101   constexpr unsigned int priorityForAlgo(const reco::TrackBase::TrackAlgorithm algo) { return findIndex(algo, 0); }
0102 
0103   /**
0104    * Helper template to initialize std::array compile-time.
0105    *
0106    * Idea is that it "loops" over all reco::TrackBase::TrackAlgorithm
0107    * enumerators from end to beginning. In each "iteration", the order
0108    * priority is obtained from impl::algoPriorityOrder array, and the
0109    * priority is added to a parameter pack. When the beginning is
0110    * reached (termination condition is a partial specialization, see
0111    * below), the std::array is initialized from the parameter pack.
0112    * The "looping" is implemented as recursion.
0113    *
0114    * @tparam T  value_type of the std::array
0115    * @tparam N  Size of the std::array
0116    * @tparam I  Current index
0117    */
0118   template <typename T, size_t N, size_t I>
0119   struct MakeArray {
0120     template <typename... Args>
0121     constexpr static std::array<T, N> value(Args&&... args) {
0122       return MakeArray<T, N, I - 1>::value(priorityForAlgo(static_cast<reco::TrackBase::TrackAlgorithm>(I - 1)),
0123                                            std::forward<Args>(args)...);
0124     }
0125   };
0126 
0127   /**
0128    * Partial specialization for the termination condition.
0129    */
0130   template <typename T, size_t N>
0131   struct MakeArray<T, N, 0> {
0132     template <typename... Args>
0133     constexpr static std::array<T, N> value(Args&&... args) {
0134       return std::array<T, N>{{std::forward<Args>(args)...}};
0135     }
0136   };
0137 
0138   /**
0139    * Create compile-time an std::array mapping
0140    * reco::TrackBase::TrackAlgorithm enumerators to their order
0141    * priorities as defined in impl::algoPriorityOrder array.
0142    *
0143    * @tparam T  value_type of the std::array
0144    * @tparam N  Size of the std::array
0145    */
0146   template <typename T, size_t N>
0147   constexpr std::array<T, N> makeArray() {
0148     return MakeArray<T, N, N>::value();
0149   }
0150 
0151 }  // namespace impl
0152 
0153 /**
0154  * Array mapping reco::TrackBase::TrackAlgorithm enumerators to their
0155  * order priorities in track list merging.
0156  */
0157 constexpr std::array<unsigned int, reco::TrackBase::algoSize> trackAlgoPriorityOrder =
0158     impl::makeArray<unsigned int, reco::TrackBase::algoSize>();
0159 
0160 #endif  // DataFormats_TrackReco_trackAlgoPriorityOrder_h