From d7aab409e06bf7265d6e7fde7346dfd08d295f46 Mon Sep 17 00:00:00 2001 From: mmusich Date: Mon, 12 Apr 2021 16:11:16 +0200 Subject: [PATCH] add valueMap producer for the track distances --- .../TkAlCaRecoProducers/plugins/BuildFile.xml | 5 + .../plugins/TrackDistanceValueMapProducer.cc | 136 ++++++++++++++++++ ...ECOSiPixelCalSingleMuonTight_Output_cff.py | 3 +- .../ALCARECOSiPixelCalSingleMuonTight_cff.py | 9 +- .../TrackDistanceValueMapProducer_cfi.py | 6 + 5 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 Calibration/TkAlCaRecoProducers/plugins/TrackDistanceValueMapProducer.cc create mode 100644 Calibration/TkAlCaRecoProducers/python/TrackDistanceValueMapProducer_cfi.py diff --git a/Calibration/TkAlCaRecoProducers/plugins/BuildFile.xml b/Calibration/TkAlCaRecoProducers/plugins/BuildFile.xml index 7b881f869abf4..77617fc58ce2c 100644 --- a/Calibration/TkAlCaRecoProducers/plugins/BuildFile.xml +++ b/Calibration/TkAlCaRecoProducers/plugins/BuildFile.xml @@ -53,3 +53,8 @@ + + + + + diff --git a/Calibration/TkAlCaRecoProducers/plugins/TrackDistanceValueMapProducer.cc b/Calibration/TkAlCaRecoProducers/plugins/TrackDistanceValueMapProducer.cc new file mode 100644 index 0000000000000..35d0d983a4bec --- /dev/null +++ b/Calibration/TkAlCaRecoProducers/plugins/TrackDistanceValueMapProducer.cc @@ -0,0 +1,136 @@ +// -*- C++ -*- +// +// Package: Calibration/TkAlCaRecoProducers +// Class: TrackDistanceValueMapProducer +// +/**\class TrackDistanceValueMapProducer TrackDistanceValueMapProducer.cc Calibration/TkAlCaRecoProducers/plugins/TrackDistanceValueMapProducer.cc + + Description: creates a value map for each saved muon track with all the distances of the other track w.r.t. the muon track + +*/ +// +// Original Author: Marco Musich +// Created: Mon, 12 Apr 2021 11:59:39 GMT +// +// + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" + +#include "DataFormats/Math/interface/deltaR.h" +// +// class declaration +// + +class TrackDistanceValueMapProducer : public edm::stream::EDProducer<> { +public: + explicit TrackDistanceValueMapProducer(const edm::ParameterSet&); + ~TrackDistanceValueMapProducer() override = default; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::Event&, const edm::EventSetup&) override; + + // ----------member data --------------------------- + // edToken + edm::EDGetTokenT> muonTracksToken_; + edm::EDGetTokenT> otherTracksToken_; + + // putToken + edm::EDPutTokenT>> distancesPutToken_; +}; + +// +// constructors and destructor +// +TrackDistanceValueMapProducer::TrackDistanceValueMapProducer(const edm::ParameterSet& iConfig) + : muonTracksToken_(consumes>(iConfig.getParameter("muonTracks"))), + otherTracksToken_(consumes>(iConfig.getParameter("allTracks"))), + distancesPutToken_(produces>>()) {} + +// +// member functions +// + +// ------------ method called to produce the data ------------ +void TrackDistanceValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + using namespace edm; + + //======================================================= + // Retrieve the muon Track information + //======================================================= + + edm::Handle> muonTrackCollectionHandle; + iEvent.getByToken(muonTracksToken_, muonTrackCollectionHandle); + if (!muonTrackCollectionHandle.isValid()) + return; + auto const& muonTracks = *muonTrackCollectionHandle; + + //======================================================= + // Retrieve the general Track information + //======================================================= + + edm::Handle> allTrackCollectionHandle; + iEvent.getByToken(otherTracksToken_, allTrackCollectionHandle); + if (!allTrackCollectionHandle.isValid()) + return; + auto const& allTracks = *allTrackCollectionHandle; + + //======================================================= + // fill the distance vector + //======================================================= + + // the map cannot be filled straight away, so create an intermediate vector + unsigned int Nit = muonTracks.size(); + unsigned int Nall = allTracks.size(); + std::vector> v2_dR2; + + for (unsigned int iit = 0; iit < Nit; iit++) { + const auto& muontrack = muonTracks.ptrAt(iit); + + std::vector v_dR2; + for (unsigned int iAll = 0; iAll < Nall; iAll++) { + const auto& recotrack = allTracks.ptrAt(iAll); + const float dR2 = ::deltaR2(*muontrack, *recotrack); + v_dR2.push_back(dR2); + } + v2_dR2.push_back(v_dR2); + } + + //======================================================= + // Populate the event with the value map + //======================================================= + + std::unique_ptr>> vm_dR2(new edm::ValueMap>()); + edm::ValueMap>::Filler filler(*vm_dR2); + filler.insert(muonTrackCollectionHandle, v2_dR2.begin(), v2_dR2.end()); + filler.fill(); + iEvent.put(distancesPutToken_, std::move(vm_dR2)); +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void TrackDistanceValueMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.setComment("Produces a value map with all the distances with the other tracks in the event"); + desc.add("muonTracks", edm::InputTag("ALCARECOSiPixelCalSingleMuonTight")) + ->setComment("the probe muon tracks"); + desc.add("allTracks", edm::InputTag("generalTracks"))->setComment("all tracks in the event"); + descriptions.addWithDefaultLabel(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(TrackDistanceValueMapProducer); diff --git a/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_Output_cff.py b/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_Output_cff.py index 9b54c5595b086..3349e359c81b6 100644 --- a/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_Output_cff.py +++ b/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_Output_cff.py @@ -9,7 +9,8 @@ 'keep *_muons__*', 'keep *_offlinePrimaryVertices_*_*', 'keep *_*riggerResults_*_HLT', - 'keep *_*closebyPixelClusters*_*_*' + 'keep *_*closebyPixelClusters*_*_*', + 'keep *_*trackDistances*_*_*', ) ) OutALCARECOSiPixelCalSingleMuonTight=OutALCARECOSiPixelCalSingleMuonTight_noDrop.clone() diff --git a/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_cff.py b/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_cff.py index ee5bae5da79db..419e54fabe48e 100644 --- a/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_cff.py +++ b/Calibration/TkAlCaRecoProducers/python/ALCARECOSiPixelCalSingleMuonTight_cff.py @@ -60,7 +60,7 @@ # Track refitter ################################################################## from RecoVertex.BeamSpotProducer.BeamSpot_cff import * -from RecoTracker.Configuration.RecoTrackerP5_cff import * +#from RecoTracker.Configuration.RecoTrackerP5_cff import * from RecoTracker.TrackProducer.TrackRefitter_cfi import * ALCARECOSiPixelCalSingleMuonTightTracksRefit = TrackRefitter.clone(src = cms.InputTag("ALCARECOSiPixelCalSingleMuonTight"), @@ -80,6 +80,12 @@ ALCARECOSiPixelCalSingleMuonTightOffTrackClusters = cms.Sequence(ALCARECOSiPixelCalSingleMuonTightTracksRefit + closebyPixelClusters) +################################################################## +# Producer of distances value map +################################################################## +import Calibration.TkAlCaRecoProducers.TrackDistanceValueMapProducer_cfi as TrackDistanceValueMap +trackDistances = TrackDistanceValueMap.TrackDistanceValueMapProducer.clone(muonTracks = 'ALCARECOSiPixelCalSingleMuonTight') + ################################################################## # Final Tight sequence ################################################################## @@ -89,4 +95,5 @@ ALCARECOSiPixelCalSingleMuonTightGoodMuons+ ALCARECOSiPixelCalSingleMuonTightRelCombIsoMuons+ ALCARECOSiPixelCalSingleMuonTight+ + trackDistances + ALCARECOSiPixelCalSingleMuonTightOffTrackClusters) diff --git a/Calibration/TkAlCaRecoProducers/python/TrackDistanceValueMapProducer_cfi.py b/Calibration/TkAlCaRecoProducers/python/TrackDistanceValueMapProducer_cfi.py new file mode 100644 index 0000000000000..e724edc95a997 --- /dev/null +++ b/Calibration/TkAlCaRecoProducers/python/TrackDistanceValueMapProducer_cfi.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + +TrackDistanceValueMapProducer = cms.EDProducer('TrackDistanceValueMapProducer', + muonTracks = cms.InputTag('muonTracks'), # input muon tracks + allTracks = cms.InputTag('generalTracks') # input generalTracks + )