Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:07

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 "SimTracker/TrackTriggerAssociation/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   /*! \class  tt::StubAssociator
0029    *  \brief  Class to associate reconstrucable TrackingParticles with TTStubs and vice versa
0030    *          It may associate multiple TPs with a TTStub and can therefore be used to associate
0031    *          TTTracks with TrackingParticles. This EDProducer creates two StubAssociation EDProducts,
0032    *          one using only TP that are "reconstructable" (produce stubs in a min. number of layers)
0033    *          and one using TP that are also "use for the tracking efficiency measurement".
0034    *  \author Thomas Schuh
0035    *  \date   2020, Apr
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     // ED input token of TTStubs
0044     EDGetTokenT<TTStubDetSetVec> getTokenTTStubDetSetVec_;
0045     // ED input token of TTClusterAssociation
0046     EDGetTokenT<TTClusterAssMap> getTokenTTClusterAssMap_;
0047     // ED output token for recosntructable stub association
0048     EDPutTokenT<StubAssociation> putTokenReconstructable_;
0049     // ED output token for selected stub association
0050     EDPutTokenT<StubAssociation> putTokenSelection_;
0051     // Setup token
0052     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0053   };
0054 
0055   StubAssociator::StubAssociator(const ParameterSet& iConfig) {
0056     // book in- and output ed products
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     // book ES product
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     // associate TTStubs with TrackingParticles
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     // associate reconstructable TrackingParticles with TTStubs
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 }  // namespace tt
0103 
0104 DEFINE_FWK_MODULE(tt::StubAssociator);