Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef RecoTracker_TkTrackingRegions_PixelInactiveAreaFinder_H
0002 #define RecoTracker_TkTrackingRegions_PixelInactiveAreaFinder_H
0003 
0004 #include "DataFormats/DetId/interface/DetIdCollection.h"
0005 #include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h"
0006 
0007 #include "RecoTracker/TkSeedingLayers/interface/SeedingLayerSetsBuilder.h"
0008 
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/Utilities/interface/VecArray.h"
0011 #include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"
0012 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0013 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0014 
0015 #include "AreaSeededTrackingRegionsBuilder.h"
0016 
0017 class SiPixelQuality;
0018 class TrackerGeometry;
0019 class TrackerTopology;
0020 
0021 // Adapted from a summer student project of Niko Leskinen (HIP, Finland)
0022 
0023 class PixelInactiveAreaFinder {
0024 public:
0025   using Area = AreaSeededTrackingRegionsBuilder::Area;
0026   using SeedingLayerId = SeedingLayerSetsBuilder::SeedingLayerId;
0027   using LayerSetIndex = SeedingLayerSetsHits::LayerSetIndex;
0028 
0029   struct DetGroupSpan {
0030     int subdetId;
0031     std::pair<float, float> phiSpan;
0032     std::pair<float, float> zSpan;
0033     std::pair<float, float> rSpan;
0034     unsigned int layer;
0035     unsigned int disk;
0036     DetGroupSpan() : subdetId(0), phiSpan(0, 0), zSpan(0, 0), rSpan(0, 0), layer(0), disk(0) {}
0037   };
0038   using DetGroupSpanContainer = std::vector<DetGroupSpan>;
0039 
0040   class InactiveAreas {
0041   public:
0042     InactiveAreas(const std::vector<SeedingLayerId>* inactiveLayers,
0043                   std::vector<DetGroupSpanContainer>&& inactiveSpans,
0044                   const std::vector<std::pair<unsigned short, unsigned short> >* inactiveLayerPairIndices,
0045                   const std::vector<std::vector<LayerSetIndex> >* layerSetIndexInactiveToActive)
0046         : inactiveLayers_(inactiveLayers),
0047           inactiveSpans_(std::move(inactiveSpans)),
0048           inactiveLayerPairIndices_(inactiveLayerPairIndices),
0049           layerSetIndexInactiveToActive_(layerSetIndexInactiveToActive) {}
0050 
0051     template <typename T>
0052     using VecArray2 = edm::VecArray<
0053         T,
0054         2>;  // 2 inactive layers (using VecArray for possible extension to 1 inactive layer, i.e. triplet mitigation)
0055     std::vector<std::pair<VecArray2<Area>, std::vector<LayerSetIndex> > > areasAndLayerSets(const GlobalPoint& point,
0056                                                                                             float zwidth) const;
0057     std::vector<std::pair<VecArray2<DetGroupSpan>, std::vector<LayerSetIndex> > > spansAndLayerSets(
0058         const GlobalPoint& point, float zwidth) const;
0059 
0060   private:
0061     const std::vector<SeedingLayerId>* inactiveLayers_;  // pointer to PixelInactiveAreaFinder::layers_
0062     std::vector<DetGroupSpanContainer> inactiveSpans_;  // inactive areas for each layer, indexing corresponds to layers_
0063     const std::vector<std::pair<unsigned short, unsigned short> >*
0064         inactiveLayerPairIndices_;  // indices to the layer pair within the input SeedingLayerSetsHits for pairs of layers to check for correlated inactive regions
0065     const std::vector<std::vector<LayerSetIndex> >*
0066         layerSetIndexInactiveToActive_;  // mapping from index in "inactive" seeding layers to "active" seeding layers
0067   };
0068 
0069   PixelInactiveAreaFinder(const edm::ParameterSet& iConfig,
0070                           const std::vector<SeedingLayerId>& seedingLayers,
0071                           const SeedingLayerSetsLooper& seedingLayerSetsLooper,
0072                           edm::ConsumesCollector&& iC);
0073   ~PixelInactiveAreaFinder() = default;
0074 
0075   static void fillDescriptions(edm::ParameterSetDescription& desc);
0076 
0077   InactiveAreas inactiveAreas(const edm::Event& iEvent, const edm::EventSetup& iSetup);
0078 
0079 private:
0080   // Configuration
0081   const bool debug_;
0082   const bool createPlottingFiles_;
0083   const bool ignoreSingleFPixPanelModules_;
0084 
0085   std::vector<SeedingLayerId> inactiveLayers_;  // layers to check for inactive regions
0086   std::vector<std::pair<unsigned short, unsigned short> > inactiveLayerSetIndices_;  // indices within inactiveLayers_
0087   std::vector<std::vector<LayerSetIndex> >
0088       layerSetIndexInactiveToActive_;  // mapping from index in inactiveLayers_ to constructor seedingLayers+seedingLayerSetsLooper
0089 
0090   std::vector<edm::EDGetTokenT<DetIdCollection> > inactivePixelDetectorTokens_;
0091   std::vector<edm::EDGetTokenT<PixelFEDChannelCollection> > badPixelFEDChannelsTokens_;
0092   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometryToken_;
0093   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyToken_;
0094   edm::ESGetToken<SiPixelQuality, SiPixelQualityRcd> pixelQualityToken_;
0095 
0096   // Output type aliases
0097   using DetGroupSpanContainerPair = std::pair<DetGroupSpanContainer, DetGroupSpanContainer>;
0098   using OverlapSpans = std::vector<DetGroupSpan>;
0099   using OverlapSpansContainer = std::vector<OverlapSpans>;
0100   // static data members; TODO see if these could be obtained from the geometry
0101   std::array<unsigned short, 4> nBPixLadders;
0102   unsigned short nModulesPerLadder;
0103   // type aliases
0104   using det_t = uint32_t;
0105   using DetContainer = std::vector<uint32_t>;
0106   using DetGroup = std::vector<uint32_t>;
0107   using DetGroupContainer = std::vector<DetGroup>;
0108   using DetectorSet = std::set<uint32_t>;
0109   using Stream = std::stringstream;
0110   // data handles and containers;
0111   edm::ESWatcher<TrackerDigiGeometryRecord> geometryWatcher_;
0112 
0113   const SiPixelQuality* pixelQuality_ = nullptr;
0114   const TrackerGeometry* trackerGeometry_ = nullptr;
0115   const TrackerTopology* trackerTopology_ = nullptr;
0116 
0117   DetContainer pixelDetsBarrel_;
0118   DetContainer pixelDetsEndcap_;
0119   DetContainer badPixelDetsBarrel_;
0120   DetContainer badPixelDetsEndcap_;
0121   // functions for fetching date from handles
0122   void updatePixelDets(const edm::EventSetup& iSetup);
0123   void getBadPixelDets(const edm::Event& iEvent, const edm::EventSetup& iSetup);
0124   // Printing functions
0125   void detInfo(const det_t& det, Stream& ss);
0126   void printPixelDets();
0127   void printBadPixelDets();
0128   void printBadDetGroups();
0129   void printBadDetGroupSpans();
0130   void createPlottingFiles();
0131   // Functions for finding bad detGroups
0132   bool detWorks(det_t det);
0133   DetGroup badAdjecentDetsBarrel(const det_t& det);
0134   DetGroup badAdjecentDetsEndcap(const det_t& det);
0135   DetGroup reachableDetGroup(const det_t& initDet, DetectorSet& foundDets);
0136   DetGroupContainer badDetGroupsBarrel();
0137   DetGroupContainer badDetGroupsEndcap();
0138   // Functions for finding ranges that detGroups cover
0139   void getPhiSpanBarrel(const DetGroup& detGroup, DetGroupSpan& cspan);
0140   void getPhiSpanEndcap(const DetGroup& detGroup, DetGroupSpan& cspan);
0141   void getZSpan(const DetGroup& detGroup, DetGroupSpan& cspan);
0142   void getRSpan(const DetGroup& detGroup, DetGroupSpan& cspan);
0143   void getSpan(const DetGroup& detGroup, DetGroupSpan& cspan);
0144   DetGroupSpanContainerPair detGroupSpans();
0145 };
0146 
0147 #endif