Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:10

0001 /*! \class TTStubBuilder
0002 * \brief Plugin to load the Stub finding algorithm and produce the
0003 * collection of Stubs that goes in the event content.
0004 * \details After moving from SimDataFormats to DataFormats,
0005 * the template structure of the class was maintained
0006 * in order to accomodate any types other than PixelDigis
0007 * in case there is such a need in the future.
0008 *
0009 * \author Andrew W. Rose
0010 * \author Nicola Pozzobon
0011 * \author Ivan Reid
0012 * \author Ian Tomalin
0013 * \date 2013 - 2020
0014 *
0015 */
0016 
0017 #ifndef L1_TRACK_TRIGGER_STUB_BUILDER_H
0018 #define L1_TRACK_TRIGGER_STUB_BUILDER_H
0019 
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/one/EDProducer.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/Utilities/interface/ESGetToken.h"
0028 
0029 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0030 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0031 
0032 #include "L1Trigger/TrackTrigger/interface/TTStubAlgorithm.h"
0033 #include "L1Trigger/TrackTrigger/interface/TTStubAlgorithmRecord.h"
0034 
0035 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0036 
0037 #include <memory>
0038 #include <map>
0039 #include <vector>
0040 
0041 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0042 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0043 
0044 template <typename T>
0045 class TTStubBuilder : public edm::one::EDProducer<edm::one::WatchRuns> {
0046 public:
0047   /// Constructor
0048   explicit TTStubBuilder(const edm::ParameterSet& iConfig);
0049 
0050   /// Destructor;
0051   ~TTStubBuilder() override;
0052 
0053   // TTStub bendOffset has this added to it, if stub truncated by FE, to indicate reason.
0054   static constexpr int CBCFailOffset = 500, CICFailOffset = 1000;
0055 
0056 private:
0057   /// Data members
0058   edm::ESHandle<TTStubAlgorithm<T>> theStubFindingAlgoHandle;
0059   edm::EDGetTokenT<edmNew::DetSetVector<TTCluster<T>>> clustersToken;
0060   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken;
0061   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tGeomToken;
0062   edm::ESGetToken<TTStubAlgorithm<T>, TTStubAlgorithmRecord> ttStubToken;
0063   bool ForbidMultipleStubs;
0064 
0065   /// Mandatory methods
0066   void beginRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
0067   void endRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
0068   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0069 
0070   /// Sorting method for stubs
0071   /// NOTE: this must be static!
0072   static bool SortStubBendPairs(const std::pair<unsigned int, double>& left,
0073                                 const std::pair<unsigned int, double>& right);
0074   static bool SortStubsBend(const TTStub<T>& left, const TTStub<T>& right);
0075 
0076   /// Fill output cluster & stub collections.
0077   template <typename TT>
0078   void fill(edmNew::DetSetVector<TT>& outputEP, const DetId& detId, const std::vector<TT>& inputVec) const {
0079     /// Create the FastFiller
0080     typename edmNew::DetSetVector<TT>::FastFiller outputFiller(outputEP, detId);
0081     outputFiller.resize(inputVec.size());
0082     std::copy(inputVec.begin(), inputVec.end(), outputFiller.begin());
0083   }
0084 
0085   /// Update output stubs with Refs to cluster collection that is associated to stubs.
0086   void updateStubs(const edm::OrphanHandle<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>>& clusterHandle,
0087                    const edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>& inputEDstubs,
0088                    edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>& outputEDstubs) const;
0089 
0090   /// FE truncation
0091 
0092   bool applyFE;  // Turn ON (true) or OFF (false) the dynamic FE stub truncation.
0093 
0094   // Tuncation cut-offs
0095   unsigned int maxStubs_2S;         // CBC chip limit (in stubs/chip/BX)
0096   unsigned int maxStubs_PS;         // MPA chip limit (in stubs/chip/2BX)
0097   unsigned int maxStubs_2S_CIC_5;   // 2S 5G chip limit (in stubs/CIC/8BX)
0098   unsigned int maxStubs_PS_CIC_5;   // PS 5G chip limit (in stubs/CIC/8BX)
0099   unsigned int maxStubs_PS_CIC_10;  // PS 10G chip limit (in stubs/CIC/8BX)
0100 
0101   // Which modules read by 10Gb/s links instead of 5Gb/s
0102   // (Unlike TkLayout, CMSSW starts ring count at 1 for the innermost physically present ring in each disk)
0103   // sviret comment (221217): this info should be made available in conddb at some point
0104   // (not in TrackerTopology, as modules may switch between 10G & 5G transmission schems during running?)
0105   unsigned int high_rate_max_ring[5];  //Outermost ring with 10Gb/s link vs disk.
0106   unsigned int high_rate_max_layer;    // Outermost barrel layer with 10Gb/s link.
0107 
0108   /// Temporary storage for stubs over several events for truncation use.
0109   int ievt;
0110   std::unordered_map<int, std::vector<TTStub<Ref_Phase2TrackerDigi_>>> moduleStubs_CIC;
0111   std::unordered_map<int, int> moduleStubs_MPA;
0112   std::unordered_map<int, int> moduleStubs_CBC;
0113 
0114 };  /// Close class
0115 
0116 /*! \brief Implementation of methods
0117 * \details Here, in the header file, the methods which do not depend
0118 * on the specific type <T> that can fit the template.
0119 * Other methods, with type-specific features, are implemented
0120 * in the source file.
0121 */
0122 
0123 /// Constructors
0124 template <typename T>
0125 TTStubBuilder<T>::TTStubBuilder(const edm::ParameterSet& iConfig) {
0126   clustersToken = consumes<edmNew::DetSetVector<TTCluster<T>>>(iConfig.getParameter<edm::InputTag>("TTClusters"));
0127   tTopoToken = esConsumes<TrackerTopology, TrackerTopologyRcd>();
0128   tGeomToken = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
0129   ttStubToken = esConsumes<TTStubAlgorithm<T>, TTStubAlgorithmRecord, edm::Transition::BeginRun>();
0130   ForbidMultipleStubs = iConfig.getParameter<bool>("OnlyOnePerInputCluster");
0131   applyFE = iConfig.getParameter<bool>("FEineffs");
0132   maxStubs_2S = iConfig.getParameter<uint32_t>("CBClimit");
0133   maxStubs_PS = iConfig.getParameter<uint32_t>("MPAlimit");
0134   maxStubs_2S_CIC_5 = iConfig.getParameter<uint32_t>("SS5GCIClimit");
0135   maxStubs_PS_CIC_5 = iConfig.getParameter<uint32_t>("PS5GCIClimit");
0136   maxStubs_PS_CIC_10 = iConfig.getParameter<uint32_t>("PS10GCIClimit");
0137   unsigned int tedd1_max10Gring = iConfig.getParameter<uint32_t>("TEDD1Max10GRing");
0138   unsigned int tedd2_max10Gring = iConfig.getParameter<uint32_t>("TEDD2Max10GRing");
0139   high_rate_max_layer = iConfig.getParameter<uint32_t>("BarrelMax10GLay");
0140   // Stubs passing & failing FE chip cuts, plus associated clusters.
0141   produces<edmNew::DetSetVector<TTCluster<T>>>("ClusterAccepted");
0142   produces<edmNew::DetSetVector<TTCluster<T>>>("ClusterRejected");
0143   produces<edmNew::DetSetVector<TTStub<T>>>("StubAccepted");
0144   produces<edmNew::DetSetVector<TTStub<T>>>("StubRejected");
0145 
0146   high_rate_max_ring[0] = tedd1_max10Gring;
0147   high_rate_max_ring[1] = tedd1_max10Gring;
0148   high_rate_max_ring[2] = tedd2_max10Gring;
0149   high_rate_max_ring[3] = tedd2_max10Gring;
0150   high_rate_max_ring[4] = tedd2_max10Gring;
0151 }
0152 
0153 /// Destructor
0154 template <typename T>
0155 TTStubBuilder<T>::~TTStubBuilder() {}
0156 
0157 /// Begin run
0158 template <typename T>
0159 void TTStubBuilder<T>::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
0160   /// Get the stub finding algorithm
0161   theStubFindingAlgoHandle = iSetup.getHandle(ttStubToken);
0162   ievt = 0;
0163   moduleStubs_CIC.clear();
0164   moduleStubs_MPA.clear();
0165   moduleStubs_CBC.clear();
0166 }
0167 
0168 /// End run
0169 template <typename T>
0170 void TTStubBuilder<T>::endRun(const edm::Run& run, const edm::EventSetup& iSetup) {}
0171 
0172 /// Sort routine for stub ordering
0173 template <typename T>
0174 bool TTStubBuilder<T>::SortStubBendPairs(const std::pair<unsigned int, double>& left,
0175                                          const std::pair<unsigned int, double>& right) {
0176   return std::abs(left.second) < std::abs(right.second);
0177 }
0178 
0179 /// Analogous sorting routine directly from stubs
0180 template <typename T>
0181 bool TTStubBuilder<T>::SortStubsBend(const TTStub<T>& left, const TTStub<T>& right) {
0182   return std::abs(left.bendFE()) < std::abs(right.bendFE());
0183 }
0184 
0185 /// Implement the producer
0186 template <>
0187 void TTStubBuilder<Ref_Phase2TrackerDigi_>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup);
0188 
0189 #endif