Back to home page

Project CMSSW displayed by LXR

 
 

    


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   /*! \class  tt::StubAssociator
0025    *  \brief  Class to associate reconstrucable TrackingParticles with TTStubs and vice versa
0026    *          It may associate multiple TPs with a TTStub and can therefore be used to associate
0027    *          TTTracks with TrackingParticles. This EDProducer creates two StubAssociation EDProducts,
0028    *          one using only TP that are "reconstructable" (produce stubs in a min. number of layers)
0029    *          and one using TP that are also "use for the tracking efficiency measurement".
0030    *  \author Thomas Schuh
0031    *  \date   2020, Apr
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     // helper classe to store configurations
0042     const Setup* setup_;
0043     // ED input token of TTStubs
0044     edm::EDGetTokenT<TTStubDetSetVec> getTokenTTStubDetSetVec_;
0045     // ED input token of TTClusterAssociation
0046     edm::EDGetTokenT<TTClusterAssMap> getTokenTTClusterAssMap_;
0047     // ED output token for recosntructable stub association
0048     edm::EDPutTokenT<StubAssociation> putTokenReconstructable_;
0049     // ED output token for selected stub association
0050     edm::EDPutTokenT<StubAssociation> putTokenSelection_;
0051     // Setup token
0052     edm::ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0053     //
0054     StubAssociation::Config iConfig_;
0055     // required number of associated stub layers to a TP to consider it reconstruct-able
0056     int minLayers_;
0057     // required number of associated ps stub layers to a TP to consider it reconstruct-able
0058     int minLayersPS_;
0059     // pt cut in GeV
0060     double minPt_;
0061     // max eta for TP with z0 = 0
0062     double maxEta0_;
0063     // half lumi region size in cm
0064     double maxZ0_;
0065     // cut on impact parameter in cm
0066     double maxD0_;
0067     // cut on vertex pos r in cm
0068     double maxVertR_;
0069     // cut on vertex pos z in cm
0070     double maxVertZ_;
0071     // cut on TP zT
0072     double maxZT_;
0073     // selector to partly select TPs for efficiency measurements
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     // book in- and output ed products
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     // book ES product
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     // configure TrackingParticleSelector
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     // associate TTStubs with TrackingParticles
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     // associate reconstructable TrackingParticles with TTStubs
0140     StubAssociation reconstructable(iConfig_, setup_);
0141     StubAssociation selection(iConfig_, setup_);
0142     for (const auto& p : mapTPPtrsTTStubRefs) {
0143       // require min layers
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       // require parameter space
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       // require signal only and min pt
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 }  // namespace tt
0167 
0168 DEFINE_FWK_MODULE(tt::StubAssociator);