CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
pat::MatcherUsingTracks Class Reference

Matcher of reconstructed objects to other reconstructed objects using the tracks inside them. More...

Inheritance diagram for pat::MatcherUsingTracks:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MatcherUsingTracks (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~MatcherUsingTracks () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () 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
 
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)
 
 ~ProducerBase () 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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

template<typename T >
void storeValueMap (edm::Event &iEvent, const edm::Handle< edm::View< reco::Candidate > > &handle, const std::vector< T > &values, const std::string &label) const
 Store extra information in a ValueMap. More...
 

Private Attributes

MatcherUsingTracksAlgorithm algo_
 The real workhorse. More...
 
bool dontFailOnMissingInput_
 Some extra configurables. More...
 
edm::EDGetTokenT< edm::View< reco::Candidate > > matchedToken_
 
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
 Labels for input collections. More...
 
bool writeExtraPATOutput_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer 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
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
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 ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Matcher of reconstructed objects to other reconstructed objects using the tracks inside them.

Author
Giovanni Petrucciani
Version
Id
MatcherUsingTracks.cc,v 1.5 2010/07/12 20:56:11 gpetrucc Exp

Definition at line 31 of file MatcherUsingTracks.cc.

Constructor & Destructor Documentation

pat::MatcherUsingTracks::MatcherUsingTracks ( const edm::ParameterSet iConfig)
explicit

Definition at line 61 of file MatcherUsingTracks.cc.

References algo_, and writeExtraPATOutput_.

61  :
64  algo_(iConfig),
65  dontFailOnMissingInput_(iConfig.existsAs<bool>("dontFailOnMissingInput") ? iConfig.getParameter<bool>("dontFailOnMissingInput") : false),
66  writeExtraPATOutput_(iConfig.existsAs<bool>("writeExtraPATOutput") ? iConfig.getParameter<bool>("writeExtraPATOutput") : false)
67 {
68  // this is the basic output (edm::Association is not generic)
69  produces<edm::ValueMap<reco::CandidatePtr> >();
71  // this is the crazy stuff to get the same with UserData
72  produces<edm::OwnVector<pat::UserData> >();
73  produces<edm::ValueMap<edm::Ptr<pat::UserData> > >();
74  }
75  // this is the extra stuff
76  if (algo_.hasMetrics()) {
77  produces<edm::ValueMap<float> >("deltaR");
78  produces<edm::ValueMap<float> >("deltaEta");
79  produces<edm::ValueMap<float> >("deltaPhi");
80  produces<edm::ValueMap<float> >("deltaLocalPos");
81  produces<edm::ValueMap<float> >("deltaPtRel");
82  if (algo_.hasChi2()) {
83  produces<edm::ValueMap<float> >("chi2");
84  }
85  } else {
86  produces<edm::ValueMap<int> >("matched");
87  }
88 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
edm::EDGetTokenT< edm::View< reco::Candidate > > matchedToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
Labels for input collections.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
MatcherUsingTracksAlgorithm algo_
The real workhorse.
bool dontFailOnMissingInput_
Some extra configurables.
pat::MatcherUsingTracks::~MatcherUsingTracks ( )
inlineoverride

Definition at line 34 of file MatcherUsingTracks.cc.

References iEvent.

34 { }

Member Function Documentation

void pat::MatcherUsingTracks::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 91 of file MatcherUsingTracks.cc.

References algo_, vertices_cff::chi2, dontFailOnMissingInput_, edm::HandleBase::failedToGet(), edm::Event::getByToken(), iEvent, pat::UserData::make(), match(), electrons_cff::matched, matchedToken_, eostools::move(), TrackRefitter_38T_cff::src, srcToken_, and writeExtraPATOutput_.

91  {
92  using namespace edm;
93  using namespace std;
94 
95  algo_.init(iSetup);
96 
98 
99  iEvent.getByToken(srcToken_, src);
100  iEvent.getByToken(matchedToken_, matched);
101 
102  // declare loop variables and some intermediate stuff
104  int isrc, nsrc = src->size();
105 
106  // working and output variables
107  vector<int> match(nsrc, -1);
108  vector<float> deltaRs(nsrc, 999);
109  vector<float> deltaEtas(nsrc, 999);
110  vector<float> deltaPhis(nsrc, 999);
111  vector<float> deltaPtRel(nsrc, 999);
112  vector<float> deltaLocalPos(nsrc, 999);
113  vector<float> chi2(nsrc, 999999);
114 
115  // don't try matching if the input collection is missing and the module is configured to fail silently
116  if (!(matched.failedToGet() && dontFailOnMissingInput_)) {
117  // loop on the source collection, and request for the match
118  for (itsrc = src->begin(), edsrc = src->end(), isrc = 0; itsrc != edsrc; ++itsrc, ++isrc) {
119  match[isrc] = algo_.match(*itsrc, *matched, deltaRs[isrc], deltaEtas[isrc], deltaPhis[isrc], deltaLocalPos[isrc], deltaPtRel[isrc], chi2[isrc]);
120  }
121  }
122 
123  std::vector<reco::CandidatePtr> ptrs(nsrc);
124  for (isrc = 0; isrc < nsrc; ++isrc) {
125  if (match[isrc] != -1) {
126  ptrs[isrc] = matched->ptrAt(match[isrc]);
127  }
128  }
129  storeValueMap<reco::CandidatePtr>(iEvent, src, ptrs, "");
130 
131  if (writeExtraPATOutput_) {
132  auto outUDVect = std::make_unique<edm::OwnVector<pat::UserData> >();
133  std::vector<int> idxUD(nsrc, -1);
134  for (isrc = 0; isrc < nsrc; ++isrc) {
135  if (match[isrc] != -1) {
136  outUDVect->push_back(pat::UserData::make(ptrs[isrc]));
137  idxUD[isrc] = outUDVect->size() - 1;
138  }
139  }
140  edm::OrphanHandle<edm::OwnVector<pat::UserData> > doneUDVect = iEvent.put(std::move(outUDVect));
141  std::vector<edm::Ptr<pat::UserData> > ptrUD(nsrc);
142  for (isrc = 0; isrc < nsrc; ++isrc) {
143  if (idxUD[isrc] != -1) ptrUD[isrc] = edm::Ptr<pat::UserData>(doneUDVect, idxUD[isrc]);
144  }
145  storeValueMap<edm::Ptr<pat::UserData> >(iEvent, src, ptrUD, "");
146  }
147 
148  if (algo_.hasMetrics()) {
149  storeValueMap<float>(iEvent, src, deltaRs, "deltaR");
150  storeValueMap<float>(iEvent, src, deltaEtas, "deltaEta");
151  storeValueMap<float>(iEvent, src, deltaPhis, "deltaPhi");
152  storeValueMap<float>(iEvent, src, deltaLocalPos, "deltaLocalPos");
153  storeValueMap<float>(iEvent, src, deltaPtRel, "deltaPtRel");
154  if (algo_.hasChi2()) {
155  storeValueMap<float>(iEvent, src, chi2, "chi2");
156  }
157  } else {
158  std::vector<int> ismatched(nsrc, 0);
159  for (isrc = 0; isrc < nsrc; ++isrc) {
160  ismatched[isrc] = (match[isrc] != -1);
161  }
162  storeValueMap<int>(iEvent, src, ismatched, "matched");
163  }
164 }
edm::EDGetTokenT< edm::View< reco::Candidate > > matchedToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
Labels for input collections.
static std::unique_ptr< UserData > make(const T &value, bool transientOnly=false)
MatcherUsingTracksAlgorithm algo_
The real workhorse.
int iEvent
Definition: GenABIO.cc:230
bool failedToGet() const
Definition: HandleBase.h:78
bool dontFailOnMissingInput_
Some extra configurables.
HLT enums.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
def move(src, dest)
Definition: eostools.py:510
template<typename T >
void pat::MatcherUsingTracks::storeValueMap ( edm::Event iEvent,
const edm::Handle< edm::View< reco::Candidate > > &  handle,
const std::vector< T > &  values,
const std::string &  label 
) const
private

Store extra information in a ValueMap.

Definition at line 168 of file MatcherUsingTracks.cc.

References DEFINE_FWK_MODULE, edm::helper::Filler< Map >::fill(), objects.autophobj::filler, cmsBatch::handle, edm::helper::Filler< Map >::insert(), eostools::move(), and edm::Event::put().

171  {
172  using namespace edm; using namespace std;
173  unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
174  typename edm::ValueMap<T>::Filler filler(*valMap);
175  filler.insert(handle, values.begin(), values.end());
176  filler.fill();
177  iEvent.put(std::move(valMap), label);
178 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
HLT enums.
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

MatcherUsingTracksAlgorithm pat::MatcherUsingTracks::algo_
private

The real workhorse.

Definition at line 44 of file MatcherUsingTracks.cc.

Referenced by MatcherUsingTracks(), and produce().

bool pat::MatcherUsingTracks::dontFailOnMissingInput_
private

Some extra configurables.

Definition at line 47 of file MatcherUsingTracks.cc.

Referenced by produce().

edm::EDGetTokenT<edm::View<reco::Candidate> > pat::MatcherUsingTracks::matchedToken_
private

Definition at line 41 of file MatcherUsingTracks.cc.

Referenced by produce().

edm::EDGetTokenT<edm::View<reco::Candidate> > pat::MatcherUsingTracks::srcToken_
private

Labels for input collections.

Definition at line 40 of file MatcherUsingTracks.cc.

Referenced by produce().

bool pat::MatcherUsingTracks::writeExtraPATOutput_
private

Definition at line 48 of file MatcherUsingTracks.cc.

Referenced by MatcherUsingTracks(), and produce().