Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:07

0001 // This is a helper function that can be used to decode hitpattern, which is a 7-bit integer produced by the Kalman filter (KF).
0002 // Hitpattern is stored at TTTrack objects (DataFormats/L1TrackTrigger/interface/TTTrack.h)
0003 // It can be accessed via TTTrack: hitPattern()
0004 //
0005 // There are two classes declared in HitPatternHelper (hph) namesapce:
0006 // 1)Setup: This is used to produce a layermap and a collection of <tt::SensorModule> needed by HitPatternHelper.
0007 // 2)HitPatternHelper: This function returns more specific information (e.g. module type, layer id,...) about each stub on the TTTrack objects.
0008 // This function needs three variables from TTTrack: hitPattern(),tanL() and z0().
0009 // It makes predictions in two different ways depending on which version of the KF is deployed:
0010 //
0011 // Old KF (L1Trigger/TrackFindingTMTT/plugins/TMTrackProducer.cc) is a CMSSW emulation of KF firmware that
0012 // ignores truncation effect and is not bit/clock cycle accurate.
0013 // With this version of the KF, HitPatternHelper relys on a hard-coded layermap to deterimne layer IDs of each stub.
0014 //
0015 // New KF (L1Trigger/TrackerTFP/plugins/ProducerKF.cc) is a new CMSSW emulation of KF firmware that
0016 // considers truncaton effect and is bit/clock cycle accurate.
0017 // With this version of the KF, HitPatternHelper makes predictions based on the spatial coordinates of tracks and detector modules.
0018 //
0019 //  Created by J.Li on 1/23/21.
0020 //
0021 
0022 #ifndef L1Trigger_TrackTrigger_interface_HitPatternHelper_h
0023 #define L1Trigger_TrackTrigger_interface_HitPatternHelper_h
0024 
0025 #include "FWCore/Framework/interface/data_default_record_trait.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0028 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0029 #include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h"
0030 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0031 #include "L1Trigger/TrackFindingTracklet/interface/HitPatternHelperRcd.h"
0032 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0033 #include "L1Trigger/TrackerTFP/interface/DataFormats.h"
0034 #include "L1Trigger/TrackerTFP/interface/LayerEncoding.h"
0035 
0036 #include <bitset>
0037 #include <iostream>
0038 #include <vector>
0039 #include <utility>
0040 #include <map>
0041 
0042 namespace hph {
0043 
0044   //Class that stores configuration for HitPatternHelper
0045   class Setup {
0046   public:
0047     Setup(const edm::ParameterSet& iConfig,
0048           const tt::Setup& setupTT,
0049           const trackerTFP::DataFormats& dataFormats,
0050           const trackerTFP::LayerEncoding& layerEncoding);
0051     ~Setup() {}
0052 
0053     bool hphDebug() const { return hphDebug_; }
0054     bool useNewKF() const { return useNewKF_; }
0055     double chosenRofZ() const { return chosenRofZ_; }
0056     std::vector<double> etaRegions() const { return etaRegions_; }
0057     std::map<int, std::map<int, std::vector<int>>> layermap() const { return layermap_; }
0058     int nKalmanLayers() const { return nKalmanLayers_; }
0059     int etaRegion(double z0, double cot, bool useNewKF) const;
0060     int digiCot(double cot, int binEta) const;
0061     int digiZT(double z0, double cot, int binEta) const;
0062     const std::vector<int>& layerEncoding(int binEta, int binZT, int binCot) const {
0063       return layerEncoding_.layerEncoding(binEta, binZT, binCot);
0064     }
0065     const std::map<int, const tt::SensorModule*>& layerEncodingMap(int binEta, int binZT, int binCot) const {
0066       return layerEncoding_.layerEncodingMap(binEta, binZT, binCot);
0067     }
0068 
0069   private:
0070     edm::ParameterSet iConfig_;
0071     edm::ParameterSet oldKFPSet_;
0072     const tt::Setup setupTT_;  // Helper class to store TrackTrigger configuration
0073     const trackerTFP::DataFormats dataFormats_;
0074     const trackerTFP::DataFormat dfcot_;
0075     const trackerTFP::DataFormat dfzT_;
0076     const trackerTFP::LayerEncoding layerEncoding_;
0077     bool hphDebug_;
0078     bool useNewKF_;
0079     double chosenRofZNewKF_;
0080     std::vector<double> etaRegionsNewKF_;
0081     double chosenRofZ_;
0082     std::vector<double> etaRegions_;
0083     std::map<int, std::map<int, std::vector<int>>> layermap_;  // Hard-coded layermap in Old KF
0084     int nEtaRegions_;                                          // # of eta regions
0085     int nKalmanLayers_;                                        // # of maximum KF layers allowed
0086   };  // Only needed by Old KF
0087 
0088   //Class that returns decoded information from hitpattern
0089   class HitPatternHelper {
0090   public:
0091     HitPatternHelper(const Setup* setup, int hitpattern, double cot, double z0);
0092     ~HitPatternHelper() {}
0093 
0094     int etaSector() { return etaSector_; }      //Eta sectors defined in KF
0095     int numExpLayer() { return numExpLayer_; }  //The number of layers KF expects
0096     int numMissingPS() {
0097       return numMissingPS_;
0098     }  //The number of PS layers that are missing. It includes layers that are missing:
0099     //1)before the innermost stub on the track,
0100     //2)after the outermost stub on the track.
0101     int numMissing2S() {
0102       return numMissing2S_;
0103     }  //The number of 2S layers that are missing. It includes the two types of layers mentioned above.
0104     int numPS() { return numPS_; }  //The number of PS layers are found in hitpattern
0105     int num2S() { return num2S_; }  //The number of 2S layers are found in hitpattern
0106     int numMissingInterior1() {
0107       return numMissingInterior1_;
0108     }  //The number of missing interior layers (using only hitpattern)
0109     int numMissingInterior2() {
0110       return numMissingInterior2_;
0111     }  //The number of missing interior layers (using hitpattern, layermap from Old KF and sensor modules)
0112     std::vector<int> binary() { return binary_; }  //11-bit hitmask needed by TrackQuality.cc (0~5->L1~L6;6~10->D1~D5)
0113     std::vector<float> bonusFeatures() { return bonusFeatures_; }  //bonus features for track quality
0114 
0115     int reducedId(
0116         int layerId);  //Converts layer ID (1~6->L1~L6;11~15->D1~D5) to reduced layer ID (0~5->L1~L6;6~10->D1~D5)
0117     int findLayer(int layerId);  //Search for a layer ID from sensor modules
0118 
0119   private:
0120     const Setup* setup_;
0121     bool hphDebug_;
0122     bool useNewKF_;
0123     std::vector<double> etaRegions_;
0124     std::map<int, std::map<int, std::vector<int>>> layermap_;
0125     int nKalmanLayers_;
0126     int etaBin_;
0127     int cotBin_;
0128     int zTBin_;
0129     std::vector<int> layerEncoding_;
0130     std::map<int, const tt::SensorModule*> layerEncodingMap_;
0131     int numExpLayer_;
0132     int hitpattern_;
0133     int etaSector_;
0134     int numMissingLayer_;
0135     int numMissingPS_;
0136     int numMissing2S_;
0137     int numPS_;
0138     int num2S_;
0139     int numMissingInterior1_;
0140     int numMissingInterior2_;
0141     std::vector<int> binary_;
0142     std::vector<float> bonusFeatures_;
0143   };
0144 
0145 }  // namespace hph
0146 
0147 EVENTSETUP_DATA_DEFAULT_RECORD(hph::Setup, hph::SetupRcd);
0148 
0149 #endif