File indexing completed on 2025-06-03 00:12:41
0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/InputTag.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "FWCore/Utilities/interface/EDPutToken.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011
0012 #include "SimTracker/TrackTriggerAssociation/interface/StubAssociation.h"
0013 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0014
0015 #include <vector>
0016 #include <map>
0017 #include <utility>
0018 #include <set>
0019 #include <algorithm>
0020 #include <iterator>
0021
0022 namespace tt {
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 class StubAssociator : public edm::stream::EDProducer<> {
0034 public:
0035 explicit StubAssociator(const edm::ParameterSet&);
0036 ~StubAssociator() override = default;
0037
0038 private:
0039 void beginRun(const edm::Run&, const edm::EventSetup&) override;
0040 void produce(edm::Event&, const edm::EventSetup&) override;
0041
0042 const Setup* setup_;
0043
0044 edm::EDGetTokenT<TTStubDetSetVec> getTokenTTStubDetSetVec_;
0045
0046 edm::EDGetTokenT<TTClusterAssMap> getTokenTTClusterAssMap_;
0047
0048 edm::EDPutTokenT<StubAssociation> putTokenReconstructable_;
0049
0050 edm::EDPutTokenT<StubAssociation> putTokenSelection_;
0051
0052 edm::ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0053
0054 StubAssociation::Config iConfig_;
0055
0056 int minLayers_;
0057
0058 int minLayersPS_;
0059
0060 double minPt_;
0061
0062 double maxEta0_;
0063
0064 double maxZ0_;
0065
0066 double maxD0_;
0067
0068 double maxVertR_;
0069
0070 double maxVertZ_;
0071
0072 double maxZT_;
0073
0074 TrackingParticleSelector tpSelector_;
0075 };
0076
0077 StubAssociator::StubAssociator(const edm::ParameterSet& iConfig)
0078 : minLayers_(iConfig.getParameter<int>("MinLayers")),
0079 minLayersPS_(iConfig.getParameter<int>("MinLayersPS")),
0080 minPt_(iConfig.getParameter<double>("MinPt")),
0081 maxEta0_(iConfig.getParameter<double>("MaxEta0")),
0082 maxZ0_(iConfig.getParameter<double>("MaxZ0")),
0083 maxD0_(iConfig.getParameter<double>("MaxD0")),
0084 maxVertR_(iConfig.getParameter<double>("MaxVertR")),
0085 maxVertZ_(iConfig.getParameter<double>("MaxVertZ")) {
0086 iConfig_.minLayersGood_ = iConfig.getParameter<int>("MinLayersGood");
0087 iConfig_.minLayersGoodPS_ = iConfig.getParameter<int>("MinLayersGoodPS");
0088 iConfig_.maxLayersBad_ = iConfig.getParameter<int>("MaxLayersBad");
0089 iConfig_.maxLayersBadPS_ = iConfig.getParameter<int>("MaxLayersBadPS");
0090
0091 getTokenTTStubDetSetVec_ =
0092 consumes<TTStubDetSetVec>(iConfig.getParameter<edm::InputTag>("InputTagTTStubDetSetVec"));
0093 getTokenTTClusterAssMap_ =
0094 consumes<TTClusterAssMap>(iConfig.getParameter<edm::InputTag>("InputTagTTClusterAssMap"));
0095 putTokenReconstructable_ = produces<StubAssociation>(iConfig.getParameter<std::string>("BranchReconstructable"));
0096 putTokenSelection_ = produces<StubAssociation>(iConfig.getParameter<std::string>("BranchSelection"));
0097
0098 esGetTokenSetup_ = esConsumes<Setup, SetupRcd, edm::Transition::BeginRun>();
0099 }
0100
0101 void StubAssociator::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0102 setup_ = &iSetup.getData(esGetTokenSetup_);
0103 maxZT_ = std::sinh(maxEta0_) * setup_->chosenRofZ();
0104
0105 constexpr double ptMax = 9.e9;
0106 constexpr int minHit = 0;
0107 constexpr bool signalOnly = true;
0108 constexpr bool intimeOnly = true;
0109 constexpr bool chargedOnly = true;
0110 constexpr bool stableOnly = false;
0111 const double maxEta = std::asinh((maxZT_ + maxZ0_) / setup_->chosenRofZ());
0112 tpSelector_ = TrackingParticleSelector(
0113 minPt_, ptMax, -maxEta, maxEta, maxVertR_, maxVertZ_, minHit, signalOnly, intimeOnly, chargedOnly, stableOnly);
0114 }
0115
0116 void StubAssociator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0117
0118 edm::Handle<TTStubDetSetVec> handleTTStubDetSetVec;
0119 iEvent.getByToken<TTStubDetSetVec>(getTokenTTStubDetSetVec_, handleTTStubDetSetVec);
0120 edm::Handle<TTClusterAssMap> handleTTClusterAssMap;
0121 iEvent.getByToken<TTClusterAssMap>(getTokenTTClusterAssMap_, handleTTClusterAssMap);
0122 std::map<TPPtr, std::vector<TTStubRef>> mapTPPtrsTTStubRefs;
0123 auto isNonnull = [](const TPPtr& tpPtr) { return tpPtr.isNonnull(); };
0124 for (TTStubDetSetVec::const_iterator ttModule = handleTTStubDetSetVec->begin();
0125 ttModule != handleTTStubDetSetVec->end();
0126 ttModule++) {
0127 for (TTStubDetSet::const_iterator ttStub = ttModule->begin(); ttStub != ttModule->end(); ttStub++) {
0128 const TTStubRef ttStubRef = makeRefTo(handleTTStubDetSetVec, ttStub);
0129 std::set<TPPtr> tpPtrs;
0130 for (unsigned int iClus = 0; iClus < 2; iClus++) {
0131 const std::vector<TPPtr>& assocPtrs =
0132 handleTTClusterAssMap->findTrackingParticlePtrs(ttStubRef->clusterRef(iClus));
0133 std::copy_if(assocPtrs.begin(), assocPtrs.end(), std::inserter(tpPtrs, tpPtrs.begin()), isNonnull);
0134 }
0135 for (const TPPtr& tpPtr : tpPtrs)
0136 mapTPPtrsTTStubRefs[tpPtr].push_back(ttStubRef);
0137 }
0138 }
0139
0140 StubAssociation reconstructable(iConfig_, setup_);
0141 StubAssociation selection(iConfig_, setup_);
0142 for (const auto& p : mapTPPtrsTTStubRefs) {
0143
0144 std::set<int> hitPattern, hitPatternPS;
0145 for (const TTStubRef& ttStubRef : p.second) {
0146 const int layerId = setup_->layerId(ttStubRef);
0147 hitPattern.insert(layerId);
0148 if (setup_->psModule(ttStubRef))
0149 hitPatternPS.insert(layerId);
0150 }
0151 if (static_cast<int>(hitPattern.size()) < minLayers_ || static_cast<int>(hitPatternPS.size()) < minLayersPS_)
0152 continue;
0153 reconstructable.insert(p.first, p.second);
0154
0155 const double zT = p.first->z0() + p.first->tanl() * setup_->chosenRofZ();
0156 if ((std::abs(p.first->d0()) > maxD0_) || (std::abs(p.first->z0()) > maxZ0_) || (std::abs(zT) > maxZT_))
0157 continue;
0158
0159 if (tpSelector_(*p.first))
0160 selection.insert(p.first, p.second);
0161 }
0162 iEvent.emplace(putTokenReconstructable_, std::move(reconstructable));
0163 iEvent.emplace(putTokenSelection_, std::move(selection));
0164 }
0165
0166 }
0167
0168 DEFINE_FWK_MODULE(tt::StubAssociator);