Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-06 02:54:07

0001 #ifndef L1T_OmtfP1_OMTFConfiguration_H
0002 #define L1T_OmtfP1_OMTFConfiguration_H
0003 
0004 #include <map>
0005 #include <set>
0006 #include <vector>
0007 #include <ostream>
0008 #include <memory>
0009 
0010 //#undef BOOST_DISABLE_ASSERTS  //TODO remove for production version
0011 #include "boost/multi_array.hpp"
0012 
0013 #include "L1Trigger/L1TMuonOverlapPhase1/interface/ProcConfigurationBase.h"
0014 #include "CondFormats/L1TObjects/interface/L1TMuonOverlapParams.h"
0015 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0016 
0017 //typedef int omtfPdfValueType; //normal emulation is with int type
0018 typedef float PdfValueType;  //but floats are needed for the PatternOptimizer
0019 
0020 namespace edm {
0021   class ParameterSet;
0022 }
0023 
0024 class RefHitDef {
0025 public:
0026   //FIXME: default values should be sonnected to configuration values
0027   RefHitDef(unsigned int aInput = 15,
0028             int aPhiMin = 5760,
0029             int aPhiMax = 5760,
0030             unsigned int aRegion = 99,
0031             unsigned int aRefLayer = 99);
0032 
0033 public:
0034   bool fitsRange(int iPhi) const;
0035 
0036   ///Hit input number within a cone
0037   unsigned int iInput;
0038 
0039   ///Region number assigned to this referecne hit
0040   unsigned int iRegion;
0041 
0042   ///Reference layer logic number (0-7)
0043   unsigned int iRefLayer;
0044 
0045   ///Local to processor phi range.
0046   ///Hit has to fit into this range to be assigned to this iRegion;
0047   std::pair<int, int> range;
0048 
0049   friend std::ostream& operator<<(std::ostream& out, const RefHitDef& aRefHitDef);
0050 };
0051 
0052 class OMTFConfiguration : public ProcConfigurationBase {
0053 public:
0054   typedef std::vector<std::pair<unsigned int, unsigned int> > vector1D_pair;
0055   typedef std::vector<vector1D_pair> vector2D_pair;
0056   typedef std::vector<vector2D_pair> vector3D_pair;
0057 
0058   typedef std::vector<int> vector1D;
0059   typedef std::vector<vector1D> vector2D;
0060   typedef std::vector<vector2D> vector3D;
0061   typedef std::vector<vector3D> vector4D;
0062 
0063   OMTFConfiguration() { ; };
0064 
0065   virtual void configure(const L1TMuonOverlapParams* omtfParams);
0066 
0067   void initCounterMatrices();
0068 
0069   ///Find logic region number using first input number
0070   ///and then local phi value. The input and phi
0071   ///ranges are taken from DB.
0072   unsigned int getRegionNumberFromMap(unsigned int iInput, unsigned int iRefLayer, int iPhi) const;
0073 
0074   ///Check if given referecne hit is
0075   ///in phi range for some logic cone.
0076   ///Care is needed arounf +Pi and +2Pi points
0077   bool isInRegionRange(int iPhiStart, unsigned int coneSize, int iPhi) const;
0078 
0079   ///Return global phi for beggining of given processor
0080   ///Uses minim phi over all reference layers.
0081   int globalPhiStart(unsigned int iProcessor) const;
0082 
0083   ///Return layer number encoding subsystem, and
0084   ///station number in a simple formula:
0085   /// aLayer+100*detId.subdetId()
0086   ///where aLayer is a layer number counting from vertex
0087   uint32_t getLayerNumber(uint32_t rawId) const;
0088 
0089   unsigned int fwVersion() const { return (rawParams.fwVersion() >> 16) & 0xFFFF; };
0090   unsigned int patternsVersion() const { return rawParams.fwVersion() & 0xFFFF; };
0091 
0092   const L1TMuonOverlapParams* getRawParams() const { return &rawParams; };
0093 
0094   float minPdfVal() const { return 0.001; };
0095   unsigned int nLayers() const override { return rawParams.nLayers(); };
0096   unsigned int nHitsPerLayer() const { return rawParams.nHitsPerLayer(); };
0097   unsigned int nRefLayers() const { return rawParams.nRefLayers(); };
0098   unsigned int nPhiBits() const { return rawParams.nPhiBits(); };
0099   unsigned int nPdfAddrBits() const { return rawParams.nPdfAddrBits(); };
0100   unsigned int nPdfBins() const { return pdfBins; };
0101   unsigned int nPdfValBits() const { return rawParams.nPdfValBits(); };
0102   int pdfMaxValue() const { return pdfMaxVal; };
0103   unsigned int nPhiBins() const override { return rawParams.nPhiBins(); };
0104   unsigned int nRefHits() const { return rawParams.nRefHits(); };
0105   unsigned int nTestRefHits() const { return rawParams.nTestRefHits(); };
0106   //processors number per detector side
0107   unsigned int nProcessors() const { return rawParams.nProcessors(); };
0108   //total number of processors in the system
0109   unsigned int processorCnt() const { return 2 * rawParams.nProcessors(); };
0110   unsigned int nLogicRegions() const { return rawParams.nLogicRegions(); };
0111   unsigned int nInputs() const { return rawParams.nInputs(); };
0112   unsigned int nGoldenPatterns() const { return rawParams.nGoldenPatterns(); };
0113 
0114   const std::map<int, int>& getHwToLogicLayer() const { return hwToLogicLayer; }
0115   const std::map<int, int>& getLogicToHwLayer() const { return logicToHwLayer; }
0116   const std::map<int, int>& getLogicToLogic() const { return logicToLogic; }
0117   const std::set<int>& getBendingLayers() const { return bendingLayers; }
0118   const std::vector<int>& getRefToLogicNumber() const { return refToLogicNumber; }
0119 
0120   const std::vector<unsigned int>& getBarrelMin() const { return barrelMin; }
0121   const std::vector<unsigned int>& getBarrelMax() const { return barrelMax; }
0122   const std::vector<unsigned int>& getEndcap10DegMin() const { return endcap10DegMin; }
0123   const std::vector<unsigned int>& getEndcap10DegMax() const { return endcap10DegMax; }
0124   const std::vector<unsigned int>& getEndcap20DegMin() const { return endcap20DegMin; }
0125   const std::vector<unsigned int>& getEndcap20DegMax() const { return endcap20DegMax; }
0126 
0127   const std::vector<std::vector<int> >& getProcessorPhiVsRefLayer() const { return processorPhiVsRefLayer; }
0128   const std::vector<std::vector<std::vector<std::pair<int, int> > > >& getRegionPhisVsRefLayerVsInput() const {
0129     return regionPhisVsRefLayerVsInput;
0130   }
0131   const std::vector<std::vector<RefHitDef> >& getRefHitsDefs() const { return refHitsDefs; }
0132 
0133   const vector3D_pair& getConnections() const { return connections; };
0134 
0135   vector4D& getMeasurements4D() { return measurements4D; }
0136   vector4D& getMeasurements4Dref() { return measurements4Dref; }
0137 
0138   const vector4D& getMeasurements4D() const { return measurements4D; }
0139   const vector4D& getMeasurements4Dref() const { return measurements4Dref; }
0140 
0141   double ptUnit = 0.5;  // GeV/unit
0142   ///uGMT pt scale conversion
0143   double hwPtToGev(int hwPt) const override { return (hwPt - 1.) * ptUnit; }
0144 
0145   ///uGMT pt scale conversion: [0GeV, 0.5GeV) = 1 [0.5GeV, 1 Gev) = 2
0146   int ptGevToHw(double ptGev) const override { return (ptGev / ptUnit + 1); }
0147 
0148   double etaUnit = 0.010875;  //=2.61/240 TODO value taken from the interface note, should be defined somewhere globally
0149   ///center of eta bin
0150   virtual double hwEtaToEta(int hwEta) const { return (hwEta * etaUnit); }
0151 
0152   int etaToHwEta(double eta) const override { return (eta / etaUnit); }
0153 
0154   double phiGmtUnit = 2. * M_PI / 576;  //TODO from the interface note, should be defined somewhere globally
0155   //phi in radians
0156   virtual int phiToGlobalHwPhi(double phi) const { return std::floor(phi / phiGmtUnit); }
0157 
0158   //phi in radians
0159   virtual double hwPhiToGlobalPhi(int phi) const { return phi * phiGmtUnit; }
0160 
0161   ///iProcessor - 0...5
0162   ///phiRad [-pi,pi]
0163   ///return phi inside the processor
0164   int getProcScalePhi(unsigned int iProcessor, double phiRad) const;
0165 
0166   int getProcScalePhi(double phiRad, double procPhiZeroRad = 0) const override {
0167     return 0;  // TODO replace getProcScalePhi(unsigned int iProcessor, double phiRad) with this function
0168   }
0169 
0170   double procHwPhiToGlobalPhi(int procHwPhi, int procHwPhi0) const;
0171 
0172   int procPhiToGmtPhi(int procPhi) const {
0173     ///conversion factor from OMTF to uGMT scale is  5400/576 i.e. phiValue/=9.375;
0174     return floor(procPhi * 437. / (1 << 12));  // ie. use as in hw: 9.3729977
0175     //cannot be (procPhi * 437) >> 12, because this floor is needed
0176   }
0177 
0178   ///input phi should be in the hardware scale (nPhiBins units for 2pi), can be in range  -nPhiBins ... nPhiBins,
0179   //is converted to range -nPhiBins/2 +1 ... nPhiBins/2, pi = nPhiBins/2
0180   //virtual int foldPhi(int phi) const;
0181 
0182   ///Continuous processor number [0...12], to be used in as array index,
0183   unsigned int getProcIndx(unsigned int iProcessor, l1t::tftype mtfType) const {
0184     return ((mtfType - l1t::tftype::omtf_neg) * rawParams.nProcessors() + iProcessor);
0185   };
0186 
0187   //TODO implement more efficient
0188   bool isBendingLayer(unsigned int iLayer) const override { return getBendingLayers().count(iLayer); }
0189 
0190   ///pattern pt range in Gev
0191   struct PatternPt {
0192     double ptFrom = 0;
0193     double ptTo = 0;
0194     int charge = 0;
0195   };
0196 
0197   PatternPt getPatternPtRange(unsigned int patNum) const;
0198 
0199   //call it when the patterns are read directly from the xml, without using the LUTs
0200   void setPatternPtRange(const std::vector<PatternPt>& patternPts) { this->patternPts = patternPts; }
0201 
0202   ///charge: -1 - negative, +1 - positive
0203   unsigned int getPatternNum(double pt, int charge) const;
0204 
0205   static const unsigned int patternsInGroup = 4;
0206 
0207   //takes the groups from the key, it should be set during xml reading, or creating the goldenPats
0208   template <class GoldenPatternType>
0209   vector2D getPatternGroups(const std::vector<std::unique_ptr<GoldenPatternType> >& goldenPats) const {
0210     //unsigned int mergedCnt = 4;
0211     vector2D mergedPatterns;
0212     for (unsigned int iPat = 0; iPat < goldenPats.size(); iPat++) {
0213       unsigned int group = goldenPats.at(iPat)->key().theGroup;
0214 
0215       if (mergedPatterns.size() == group) {
0216         mergedPatterns.push_back(vector1D());
0217       }
0218 
0219       if (group < mergedPatterns.size()) {
0220         //theIndexInGroup starts from 1, as in xml
0221         if (mergedPatterns[group].size() == (goldenPats.at(iPat)->key().theIndexInGroup - 1))
0222           mergedPatterns[group].push_back(iPat);
0223         else
0224           return mergedPatterns;  //TODO should throw error
0225       } else
0226         return mergedPatterns;  //TODO should throw error
0227     }
0228     return mergedPatterns;
0229   }
0230 
0231   /**configuration from the edm::ParameterSet
0232    * the parameters are set (i.e. overwritten) only if their exist in the edmParameterSet
0233    */
0234   void configureFromEdmParameterSet(const edm::ParameterSet& edmParameterSet) override;
0235 
0236   int getGoldenPatternResultFinalizeFunction() const { return goldenPatternResultFinalizeFunction; }
0237 
0238   void setGoldenPatternResultFinalizeFunction(int goldenPatternResultFinalizeFunction = 0) {
0239     this->goldenPatternResultFinalizeFunction = goldenPatternResultFinalizeFunction;
0240   }
0241 
0242   friend std::ostream& operator<<(std::ostream& out, const OMTFConfiguration& aConfig);
0243 
0244   bool isNoHitValueInPdf() const { return noHitValueInPdf; }
0245 
0246   void setNoHitValueInPdf(bool noHitValueInPdf = false) { this->noHitValueInPdf = noHitValueInPdf; }
0247 
0248   int getSorterType() const { return sorterType; }
0249 
0250   void setSorterType(int sorterType = 0) { this->sorterType = sorterType; }
0251 
0252   const std::string& getGhostBusterType() const { return ghostBusterType; }
0253 
0254   void setGhostBusterType(const std::string& ghostBusterType = "") { this->ghostBusterType = ghostBusterType; }
0255 
0256   void printConfig() const;
0257 
0258 private:
0259   L1TMuonOverlapParams rawParams;
0260 
0261   std::map<int, int> hwToLogicLayer;
0262   std::map<int, int> logicToHwLayer;
0263   std::map<int, int> logicToLogic;
0264   std::set<int> bendingLayers;
0265   std::vector<int> refToLogicNumber;
0266 
0267   ///Starting and final sectors connected to
0268   ///processors.
0269   ///Index: processor number
0270   std::vector<unsigned int> barrelMin;
0271   std::vector<unsigned int> barrelMax;
0272   std::vector<unsigned int> endcap10DegMin;
0273   std::vector<unsigned int> endcap10DegMax;
0274   std::vector<unsigned int> endcap20DegMin;
0275   std::vector<unsigned int> endcap20DegMax;
0276 
0277   ///Starting iPhi for each processor and each referecne layer
0278   ///Global phi scale is used
0279   ///First index: processor number
0280   ///Second index: referecne layer number
0281   std::vector<std::vector<int> > processorPhiVsRefLayer;
0282 
0283   ///Begin and end local phi for each logis region
0284   ///First index: input number
0285   ///Second index: reference layer number
0286   ///Third index: region
0287   ///pair.first: starting phi of region (inclusive)
0288   ///pair.second: ending phi of region (inclusive)
0289   std::vector<std::vector<std::vector<std::pair<int, int> > > > regionPhisVsRefLayerVsInput;
0290 
0291   ///Vector with definitions of reference hits
0292   ///Vector has fixed size of nRefHits
0293   ///Order of elements defines priority order
0294   ///First index: processor number (0-5)
0295   ///Second index: ref hit number (0-127)
0296   std::vector<std::vector<RefHitDef> > refHitsDefs;
0297 
0298   ///Map of connections
0299   vector3D_pair connections;
0300 
0301   ///4D matrices used during creation of the connections tables.
0302   vector4D measurements4D;
0303   vector4D measurements4Dref;
0304 
0305   std::vector<PatternPt> patternPts;
0306 
0307   int pdfMaxVal = 0;
0308   unsigned int pdfBins = 0;
0309 
0310   int goldenPatternResultFinalizeFunction = 0;
0311 
0312   bool noHitValueInPdf = false;
0313 
0314   int sorterType = 0;
0315 
0316   std::string ghostBusterType = "";
0317 };
0318 
0319 #endif