CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
TrackDistanceValueMapProducer Class Reference

#include <Calibration/TkAlCaRecoProducers/plugins/TrackDistanceValueMapProducer.cc>

Inheritance diagram for TrackDistanceValueMapProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 TrackDistanceValueMapProducer (const edm::ParameterSet &)
 
 ~TrackDistanceValueMapProducer () override=default
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

edm::EDPutTokenT< edm::ValueMap< std::vector< float > > > distancesPutToken_
 
edm::EDGetTokenT< edm::View< reco::Track > > muonTracksToken_
 
unsigned int nthClosestTrack_
 
edm::EDGetTokenT< edm::View< reco::Track > > otherTracksToken_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 declare what type of product will make and with which optional label More...
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Description: creates a value map for each saved muon track with all the distances of the other track w.r.t. the muon track

Definition at line 38 of file TrackDistanceValueMapProducer.cc.

Constructor & Destructor Documentation

◆ TrackDistanceValueMapProducer()

TrackDistanceValueMapProducer::TrackDistanceValueMapProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 63 of file TrackDistanceValueMapProducer.cc.

66  nthClosestTrack_(iConfig.getParameter<unsigned int>("saveUpToNthClosest")),
67  distancesPutToken_(produces<edm::ValueMap<std::vector<float>>>()) {}

◆ ~TrackDistanceValueMapProducer()

TrackDistanceValueMapProducer::~TrackDistanceValueMapProducer ( )
overridedefault

Member Function Documentation

◆ fillDescriptions()

void TrackDistanceValueMapProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 141 of file TrackDistanceValueMapProducer.cc.

141  {
143  desc.setComment("Produces a value map with all the distances with the other tracks in the event");
144  desc.add<edm::InputTag>("muonTracks", edm::InputTag("ALCARECOSiPixelCalSingleMuonTight"))
145  ->setComment("the probe muon tracks");
146  desc.add<edm::InputTag>("allTracks", edm::InputTag("generalTracks"))->setComment("all tracks in the event");
147  desc.add<unsigned int>("saveUpToNthClosest", 1)->setComment("save the distance only for the nth closest tracks");
148  descriptions.addWithDefaultLabel(desc);
149 }

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, and HLT_FULL_cff::InputTag.

◆ produce()

void TrackDistanceValueMapProducer::produce ( edm::StreamID  streamID,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 74 of file TrackDistanceValueMapProducer.cc.

76  {
77  using namespace edm;
78 
79  //=======================================================
80  // Retrieve the muon Track information
81  //=======================================================
82 
83  const auto& muonTrackCollectionHandle = iEvent.getHandle(muonTracksToken_);
84  if (!muonTrackCollectionHandle.isValid())
85  return;
86  auto const& muonTracks = *muonTrackCollectionHandle;
87 
88  //=======================================================
89  // Retrieve the general Track information
90  //=======================================================
91 
92  const auto& allTrackCollectionHandle = iEvent.getHandle(otherTracksToken_);
93  if (!allTrackCollectionHandle.isValid())
94  return;
95  auto const& allTracks = *allTrackCollectionHandle;
96 
97  //=======================================================
98  // fill the distance vector
99  //=======================================================
100 
101  // the map cannot be filled straight away, so create an intermediate vector
102  unsigned int Nit = muonTracks.size();
103  unsigned int Nall = allTracks.size();
104  std::vector<std::vector<float>> v2_dR2;
105 
106  for (unsigned int iit = 0; iit < Nit; iit++) {
107  const auto& muontrack = muonTracks.ptrAt(iit);
108 
109  std::vector<float> v_dR2;
110  for (unsigned int iAll = 0; iAll < Nall; iAll++) {
111  const auto& recotrack = allTracks.ptrAt(iAll);
112  const float dR2 = ::deltaR2(*muontrack, *recotrack);
113  if (dR2 != 0.f) { // exclude the track itself
114  v_dR2.push_back(dR2);
115  }
116  }
117 
118  // sort the tracks in ascending order of distance
119  std::sort(v_dR2.begin(), v_dR2.end(), [](const float& lhs, const float& rhs) { return lhs < rhs; });
120 
121  // just copy the first nth
122  std::vector<float> reduced_vdR2;
123  std::copy(v_dR2.begin(),
124  v_dR2.begin() + std::min(v_dR2.size(), static_cast<size_t>(nthClosestTrack_)),
125  std::back_inserter(reduced_vdR2));
126  v2_dR2.push_back(reduced_vdR2);
127  }
128 
129  //=======================================================
130  // Populate the event with the value map
131  //=======================================================
132 
133  std::unique_ptr<edm::ValueMap<std::vector<float>>> vm_dR2(new edm::ValueMap<std::vector<float>>());
134  edm::ValueMap<std::vector<float>>::Filler filler(*vm_dR2);
135  filler.insert(muonTrackCollectionHandle, v2_dR2.begin(), v2_dR2.end());
136  filler.fill();
137  iEvent.put(distancesPutToken_, std::move(vm_dR2));
138 }

References muonTagProbeFilters_cff::allTracks, filterCSVwithJSON::copy, HLTMuonOfflineAnalyzer_cfi::deltaR2, distancesPutToken_, f, trigObjTnPSource_cfi::filler, iEvent, min(), eostools::move(), muonTracksToken_, nthClosestTrack_, otherTracksToken_, and jetUpdater_cfi::sort.

Member Data Documentation

◆ distancesPutToken_

edm::EDPutTokenT<edm::ValueMap<std::vector<float> > > TrackDistanceValueMapProducer::distancesPutToken_
private

Definition at line 57 of file TrackDistanceValueMapProducer.cc.

Referenced by produce().

◆ muonTracksToken_

edm::EDGetTokenT<edm::View<reco::Track> > TrackDistanceValueMapProducer::muonTracksToken_
private

Definition at line 50 of file TrackDistanceValueMapProducer.cc.

Referenced by produce().

◆ nthClosestTrack_

unsigned int TrackDistanceValueMapProducer::nthClosestTrack_
private

Definition at line 54 of file TrackDistanceValueMapProducer.cc.

Referenced by produce().

◆ otherTracksToken_

edm::EDGetTokenT<edm::View<reco::Track> > TrackDistanceValueMapProducer::otherTracksToken_
private

Definition at line 51 of file TrackDistanceValueMapProducer.cc.

Referenced by produce().

TrackDistanceValueMapProducer::otherTracksToken_
edm::EDGetTokenT< edm::View< reco::Track > > otherTracksToken_
Definition: TrackDistanceValueMapProducer.cc:51
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
min
T min(T a, T b)
Definition: MathUtil.h:58
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
muonTagProbeFilters_cff.allTracks
allTracks
Definition: muonTagProbeFilters_cff.py:22
edm::View
Definition: CaloClusterFwd.h:14
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
TrackDistanceValueMapProducer::muonTracksToken_
edm::EDGetTokenT< edm::View< reco::Track > > muonTracksToken_
Definition: TrackDistanceValueMapProducer.cc:50
iEvent
int iEvent
Definition: GenABIO.cc:224
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::ProductRegistryHelper::produces
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
Definition: ProductRegistryHelper.h:108
eostools.move
def move(src, dest)
Definition: eostools.py:511
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
edm::ValueMap
Definition: ValueMap.h:107
TrackDistanceValueMapProducer::distancesPutToken_
edm::EDPutTokenT< edm::ValueMap< std::vector< float > > > distancesPutToken_
Definition: TrackDistanceValueMapProducer.cc:57
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:159
edm::InputTag
Definition: InputTag.h:15
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
TrackDistanceValueMapProducer::nthClosestTrack_
unsigned int nthClosestTrack_
Definition: TrackDistanceValueMapProducer.cc:54