CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
virtual ~MatcherUsingTracks ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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::InputTag matched_
 
edm::InputTag src_
 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
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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 60 of file MatcherUsingTracks.cc.

References algo_, and writeExtraPATOutput_.

60  :
61  src_(iConfig.getParameter<edm::InputTag>("src")),
62  matched_(iConfig.getParameter<edm::InputTag>("matched")),
63  algo_(iConfig),
64  dontFailOnMissingInput_(iConfig.existsAs<bool>("dontFailOnMissingInput") ? iConfig.getParameter<bool>("dontFailOnMissingInput") : false),
65  writeExtraPATOutput_(iConfig.existsAs<bool>("writeExtraPATOutput") ? iConfig.getParameter<bool>("writeExtraPATOutput") : false)
66 {
67  // this is the basic output (edm::Association is not generic)
68  produces<edm::ValueMap<reco::CandidatePtr> >();
70  // this is the crazy stuff to get the same with UserData
71  produces<edm::OwnVector<pat::UserData> >();
72  produces<edm::ValueMap<edm::Ptr<pat::UserData> > >();
73  }
74  // this is the extra stuff
75  if (algo_.hasMetrics()) {
76  produces<edm::ValueMap<float> >("deltaR");
77  produces<edm::ValueMap<float> >("deltaEta");
78  produces<edm::ValueMap<float> >("deltaPhi");
79  produces<edm::ValueMap<float> >("deltaLocalPos");
80  produces<edm::ValueMap<float> >("deltaPtRel");
81  if (algo_.hasChi2()) {
82  produces<edm::ValueMap<float> >("chi2");
83  }
84  } else {
85  produces<edm::ValueMap<int> >("matched");
86  }
87 }
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:184
edm::InputTag src_
Labels for input collections.
MatcherUsingTracksAlgorithm algo_
The real workhorse.
bool dontFailOnMissingInput_
Some extra configurables.
virtual pat::MatcherUsingTracks::~MatcherUsingTracks ( )
inlinevirtual

Definition at line 34 of file MatcherUsingTracks.cc.

34 { }

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 90 of file MatcherUsingTracks.cc.

References edm::Event::getByLabel(), iEvent, pat::UserData::make(), match(), edm::Event::put(), and alcazmumu_cfi::src.

90  {
91  using namespace edm;
92  using namespace std;
93 
94  algo_.init(iSetup);
95 
97 
98  iEvent.getByLabel(src_, src);
99  iEvent.getByLabel(matched_, matched);
100 
101  // declare loop variables and some intermediate stuff
103  int isrc, nsrc = src->size();
104 
105  // working and output variables
106  vector<int> match(nsrc, -1);
107  vector<float> deltaRs(nsrc, 999);
108  vector<float> deltaEtas(nsrc, 999);
109  vector<float> deltaPhis(nsrc, 999);
110  vector<float> deltaPtRel(nsrc, 999);
111  vector<float> deltaLocalPos(nsrc, 999);
112  vector<float> chi2(nsrc, 999999);
113 
114  // don't try matching if the input collection is missing and the module is configured to fail silently
115  if (!(matched.failedToGet() && dontFailOnMissingInput_)) {
116  // loop on the source collection, and request for the match
117  for (itsrc = src->begin(), edsrc = src->end(), isrc = 0; itsrc != edsrc; ++itsrc, ++isrc) {
118  match[isrc] = algo_.match(*itsrc, *matched, deltaRs[isrc], deltaEtas[isrc], deltaPhis[isrc], deltaLocalPos[isrc], deltaPtRel[isrc], chi2[isrc]);
119  }
120  }
121 
122  std::vector<reco::CandidatePtr> ptrs(nsrc);
123  for (isrc = 0; isrc < nsrc; ++isrc) {
124  if (match[isrc] != -1) {
125  ptrs[isrc] = matched->ptrAt(match[isrc]);
126  }
127  }
128  storeValueMap<reco::CandidatePtr>(iEvent, src, ptrs, "");
129 
130  if (writeExtraPATOutput_) {
131  std::auto_ptr<edm::OwnVector<pat::UserData> > outUDVect(new edm::OwnVector<pat::UserData>());
132  std::vector<int> idxUD(nsrc, -1);
133  for (isrc = 0; isrc < nsrc; ++isrc) {
134  if (match[isrc] != -1) {
135  outUDVect->push_back(pat::UserData::make(ptrs[isrc]));
136  idxUD[isrc] = outUDVect->size() - 1;
137  }
138  }
139  edm::OrphanHandle<edm::OwnVector<pat::UserData> > doneUDVect = iEvent.put(outUDVect);
140  std::vector<edm::Ptr<pat::UserData> > ptrUD(nsrc);
141  for (isrc = 0; isrc < nsrc; ++isrc) {
142  if (idxUD[isrc] != -1) ptrUD[isrc] = edm::Ptr<pat::UserData>(doneUDVect, idxUD[isrc]);
143  }
144  storeValueMap<edm::Ptr<pat::UserData> >(iEvent, src, ptrUD, "");
145  }
146 
147  if (algo_.hasMetrics()) {
148  storeValueMap<float>(iEvent, src, deltaRs, "deltaR");
149  storeValueMap<float>(iEvent, src, deltaEtas, "deltaEta");
150  storeValueMap<float>(iEvent, src, deltaPhis, "deltaPhi");
151  storeValueMap<float>(iEvent, src, deltaLocalPos, "deltaLocalPos");
152  storeValueMap<float>(iEvent, src, deltaPtRel, "deltaPtRel");
153  if (algo_.hasChi2()) {
154  storeValueMap<float>(iEvent, src, chi2, "chi2");
155  }
156  } else {
157  std::vector<int> ismatched(nsrc, 0);
158  for (isrc = 0; isrc < nsrc; ++isrc) {
159  ismatched[isrc] = (match[isrc] != -1);
160  }
161  storeValueMap<int>(iEvent, src, ismatched, "matched");
162  }
163 }
static std::auto_ptr< UserData > make(const T &value, bool transientOnly=false)
edm::InputTag src_
Labels for input collections.
MatcherUsingTracksAlgorithm algo_
The real workhorse.
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
bool dontFailOnMissingInput_
Some extra configurables.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
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 167 of file MatcherUsingTracks.cc.

References edm::helper::Filler< Map >::fill(), patZpeak::handle, edm::helper::Filler< Map >::insert(), and edm::Event::put().

170  {
171  using namespace edm; using namespace std;
172  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
173  typename edm::ValueMap<T>::Filler filler(*valMap);
174  filler.insert(handle, values.begin(), values.end());
175  filler.fill();
176  iEvent.put(valMap, label);
177 }
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116

Member Data Documentation

MatcherUsingTracksAlgorithm pat::MatcherUsingTracks::algo_
private

The real workhorse.

Definition at line 43 of file MatcherUsingTracks.cc.

Referenced by MatcherUsingTracks().

bool pat::MatcherUsingTracks::dontFailOnMissingInput_
private

Some extra configurables.

Definition at line 46 of file MatcherUsingTracks.cc.

edm::InputTag pat::MatcherUsingTracks::matched_
private

Definition at line 40 of file MatcherUsingTracks.cc.

edm::InputTag pat::MatcherUsingTracks::src_
private

Labels for input collections.

Definition at line 40 of file MatcherUsingTracks.cc.

bool pat::MatcherUsingTracks::writeExtraPATOutput_
private

Definition at line 47 of file MatcherUsingTracks.cc.

Referenced by MatcherUsingTracks().