File indexing completed on 2024-08-09 23:47:44
0001 #include "FWCore/Framework/interface/global/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 "SimDataFormats/Associations/interface/TTTypes.h"
0013 #include "SimTracker/TrackTriggerAssociation/interface/StubAssociation.h"
0014 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0015
0016 #include <vector>
0017 #include <map>
0018 #include <set>
0019 #include <algorithm>
0020 #include <iterator>
0021 #include <cmath>
0022
0023 using namespace std;
0024 using namespace edm;
0025
0026 namespace tt {
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 class StubAssociator : public global::EDProducer<> {
0038 public:
0039 explicit StubAssociator(const ParameterSet&);
0040
0041 private:
0042 void produce(StreamID, Event&, const EventSetup&) const override;
0043
0044 EDGetTokenT<TTStubDetSetVec> getTokenTTStubDetSetVec_;
0045
0046 EDGetTokenT<TTClusterAssMap> getTokenTTClusterAssMap_;
0047
0048 EDPutTokenT<StubAssociation> putTokenReconstructable_;
0049
0050 EDPutTokenT<StubAssociation> putTokenSelection_;
0051
0052 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0053 };
0054
0055 StubAssociator::StubAssociator(const ParameterSet& iConfig) {
0056
0057 getTokenTTStubDetSetVec_ = consumes<TTStubDetSetVec>(iConfig.getParameter<InputTag>("InputTagTTStubDetSetVec"));
0058 getTokenTTClusterAssMap_ = consumes<TTClusterAssMap>(iConfig.getParameter<InputTag>("InputTagTTClusterAssMap"));
0059 putTokenReconstructable_ = produces<StubAssociation>(iConfig.getParameter<string>("BranchReconstructable"));
0060 putTokenSelection_ = produces<StubAssociation>(iConfig.getParameter<string>("BranchSelection"));
0061
0062 esGetTokenSetup_ = esConsumes<Setup, SetupRcd>();
0063 }
0064
0065 void StubAssociator::produce(StreamID, Event& iEvent, const EventSetup& iSetup) const {
0066 auto const& setup = iSetup.getData(esGetTokenSetup_);
0067
0068
0069 Handle<TTStubDetSetVec> handleTTStubDetSetVec = iEvent.getHandle(getTokenTTStubDetSetVec_);
0070 auto const& ttClusterAssMap = iEvent.get(getTokenTTClusterAssMap_);
0071
0072 map<TPPtr, vector<TTStubRef>> mapTPPtrsTTStubRefs;
0073 auto isNonnull = [](const TPPtr& tpPtr) { return tpPtr.isNonnull(); };
0074 for (TTStubDetSetVec::const_iterator ttModule = handleTTStubDetSetVec->begin();
0075 ttModule != handleTTStubDetSetVec->end();
0076 ttModule++) {
0077 for (TTStubDetSet::const_iterator ttStub = ttModule->begin(); ttStub != ttModule->end(); ttStub++) {
0078 const TTStubRef ttStubRef = makeRefTo(handleTTStubDetSetVec, ttStub);
0079 set<TPPtr> tpPtrs;
0080 for (unsigned int iClus = 0; iClus < 2; iClus++) {
0081 const vector<TPPtr>& assocPtrs = ttClusterAssMap.findTrackingParticlePtrs(ttStubRef->clusterRef(iClus));
0082 copy_if(assocPtrs.begin(), assocPtrs.end(), inserter(tpPtrs, tpPtrs.begin()), isNonnull);
0083 }
0084 for (const TPPtr& tpPtr : tpPtrs)
0085 mapTPPtrsTTStubRefs[tpPtr].push_back(ttStubRef);
0086 }
0087 }
0088
0089 StubAssociation reconstructable(&setup);
0090 StubAssociation selection(&setup);
0091 for (const auto& p : mapTPPtrsTTStubRefs) {
0092 if (!setup.useForReconstructable(*p.first) || !setup.reconstructable(p.second))
0093 continue;
0094 reconstructable.insert(p.first, p.second);
0095 if (setup.useForAlgEff(*p.first))
0096 selection.insert(p.first, p.second);
0097 }
0098 iEvent.emplace(putTokenReconstructable_, std::move(reconstructable));
0099 iEvent.emplace(putTokenSelection_, std::move(selection));
0100 }
0101
0102 }
0103
0104 DEFINE_FWK_MODULE(tt::StubAssociator);