Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-06 23:18:39

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