CMS 3D CMS Logo

MatcherUsingTracks.cc
Go to the documentation of this file.
1 //
2 //
3 
15 
18 
20 
22 
24 
25 // template-related workaround for bug in OwnVector+Ptr
26 namespace edm {
27  using std::advance;
28 }
29 
30 namespace pat {
31 
33  public:
34  explicit MatcherUsingTracks(const edm::ParameterSet &iConfig);
35  ~MatcherUsingTracks() override {}
36 
37  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
38 
39  private:
43 
46 
50 
52  template <typename T>
55  const std::vector<T> &values,
56  const std::string &label) const;
57  };
58 
59 } // namespace pat
60 
62  : srcToken_(consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("src"))),
63  matchedToken_(consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("matched"))),
64  algo_(iConfig),
65  dontFailOnMissingInput_(iConfig.existsAs<bool>("dontFailOnMissingInput")
66  ? iConfig.getParameter<bool>("dontFailOnMissingInput")
67  : false),
68  writeExtraPATOutput_(
69  iConfig.existsAs<bool>("writeExtraPATOutput") ? iConfig.getParameter<bool>("writeExtraPATOutput") : false) {
70  // this is the basic output (edm::Association is not generic)
71  produces<edm::ValueMap<reco::CandidatePtr> >();
73  // this is the crazy stuff to get the same with UserData
74  produces<edm::OwnVector<pat::UserData> >();
75  produces<edm::ValueMap<edm::Ptr<pat::UserData> > >();
76  }
77  // this is the extra stuff
78  if (algo_.hasMetrics()) {
79  produces<edm::ValueMap<float> >("deltaR");
80  produces<edm::ValueMap<float> >("deltaEta");
81  produces<edm::ValueMap<float> >("deltaPhi");
82  produces<edm::ValueMap<float> >("deltaLocalPos");
83  produces<edm::ValueMap<float> >("deltaPtRel");
84  if (algo_.hasChi2()) {
85  produces<edm::ValueMap<float> >("chi2");
86  }
87  } else {
88  produces<edm::ValueMap<int> >("matched");
89  }
90 }
91 
93  using namespace edm;
94  using namespace std;
95 
96  algo_.init(iSetup);
97 
99 
100  iEvent.getByToken(srcToken_, src);
101  iEvent.getByToken(matchedToken_, matched);
102 
103  // declare loop variables and some intermediate stuff
105  int isrc, nsrc = src->size();
106 
107  // working and output variables
108  vector<int> match(nsrc, -1);
109  vector<float> deltaRs(nsrc, 999);
110  vector<float> deltaEtas(nsrc, 999);
111  vector<float> deltaPhis(nsrc, 999);
112  vector<float> deltaPtRel(nsrc, 999);
113  vector<float> deltaLocalPos(nsrc, 999);
114  vector<float> chi2(nsrc, 999999);
115 
116  // don't try matching if the input collection is missing and the module is configured to fail silently
117  if (!(matched.failedToGet() && dontFailOnMissingInput_)) {
118  // loop on the source collection, and request for the match
119  for (itsrc = src->begin(), edsrc = src->end(), isrc = 0; itsrc != edsrc; ++itsrc, ++isrc) {
120  match[isrc] = algo_.match(*itsrc,
121  *matched,
122  deltaRs[isrc],
123  deltaEtas[isrc],
124  deltaPhis[isrc],
125  deltaLocalPos[isrc],
126  deltaPtRel[isrc],
127  chi2[isrc]);
128  }
129  }
130 
131  std::vector<reco::CandidatePtr> ptrs(nsrc);
132  for (isrc = 0; isrc < nsrc; ++isrc) {
133  if (match[isrc] != -1) {
134  ptrs[isrc] = matched->ptrAt(match[isrc]);
135  }
136  }
137  storeValueMap<reco::CandidatePtr>(iEvent, src, ptrs, "");
138 
139  if (writeExtraPATOutput_) {
140  auto outUDVect = std::make_unique<edm::OwnVector<pat::UserData> >();
141  std::vector<int> idxUD(nsrc, -1);
142  for (isrc = 0; isrc < nsrc; ++isrc) {
143  if (match[isrc] != -1) {
144  outUDVect->push_back(pat::UserData::make(ptrs[isrc]));
145  idxUD[isrc] = outUDVect->size() - 1;
146  }
147  }
149  std::vector<edm::Ptr<pat::UserData> > ptrUD(nsrc);
150  for (isrc = 0; isrc < nsrc; ++isrc) {
151  if (idxUD[isrc] != -1)
152  ptrUD[isrc] = edm::Ptr<pat::UserData>(doneUDVect, idxUD[isrc]);
153  }
154  storeValueMap<edm::Ptr<pat::UserData> >(iEvent, src, ptrUD, "");
155  }
156 
157  if (algo_.hasMetrics()) {
158  storeValueMap<float>(iEvent, src, deltaRs, "deltaR");
159  storeValueMap<float>(iEvent, src, deltaEtas, "deltaEta");
160  storeValueMap<float>(iEvent, src, deltaPhis, "deltaPhi");
161  storeValueMap<float>(iEvent, src, deltaLocalPos, "deltaLocalPos");
162  storeValueMap<float>(iEvent, src, deltaPtRel, "deltaPtRel");
163  if (algo_.hasChi2()) {
164  storeValueMap<float>(iEvent, src, chi2, "chi2");
165  }
166  } else {
167  std::vector<int> ismatched(nsrc, 0);
168  for (isrc = 0; isrc < nsrc; ++isrc) {
169  ismatched[isrc] = (match[isrc] != -1);
170  }
171  storeValueMap<int>(iEvent, src, ismatched, "matched");
172  }
173 }
174 
175 template <typename T>
178  const std::vector<T> &values,
179  const std::string &label) const {
180  using namespace edm;
181  using namespace std;
182  unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
183  typename edm::ValueMap<T>::Filler filler(*valMap);
184  filler.insert(handle, values.begin(), values.end());
185  filler.fill();
186  iEvent.put(std::move(valMap), label);
187 }
188 
190 using namespace pat;
muonTagProbeFilters_cff.matched
matched
Definition: muonTagProbeFilters_cff.py:62
pat::MatcherUsingTracks::dontFailOnMissingInput_
bool dontFailOnMissingInput_
Some extra configurables.
Definition: MatcherUsingTracks.cc:48
electrons_cff.bool
bool
Definition: electrons_cff.py:372
pat::MatcherUsingTracks::~MatcherUsingTracks
~MatcherUsingTracks() override
Definition: MatcherUsingTracks.cc:35
funct::false
false
Definition: Factorize.h:34
configurableAnalysis::Candidate
char Candidate[]
Definition: modules.cc:20
EDProducer.h
sistrip::View
View
Definition: ConstantsForView.h:26
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::MatcherUsingTracks::srcToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
Labels for input collections.
Definition: MatcherUsingTracks.cc:41
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
Association.h
MatcherUsingTracksAlgorithm.h
edm::Handle
Definition: AssociativeIterator.h:50
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
pat::MatcherUsingTracks::algo_
MatcherUsingTracksAlgorithm algo_
The real workhorse.
Definition: MatcherUsingTracks.cc:45
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View
Definition: CaloClusterFwd.h:14
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
pat::MatcherUsingTracks::writeExtraPATOutput_
bool writeExtraPATOutput_
Definition: MatcherUsingTracks.cc:49
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
UserData.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
MatcherUsingTracksAlgorithm
Matcher of reconstructed objects to other reconstructed objects using the tracks inside them.
pat::MatcherUsingTracks::MatcherUsingTracks
MatcherUsingTracks(const edm::ParameterSet &iConfig)
Definition: MatcherUsingTracks.cc:61
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::MatcherUsingTracks::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: MatcherUsingTracks.cc:92
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
InputTag.h
edm::Ptr
Definition: AssociationVector.h:31
ValueMap.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
pat::UserData::make
static std::unique_ptr< UserData > make(const T &value, bool transientOnly=false)
edm::ValueMap
Definition: ValueMap.h:107
pat::MatcherUsingTracks::storeValueMap
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.
Definition: MatcherUsingTracks.cc:176
pat::MatcherUsingTracks::matchedToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > matchedToken_
Definition: MatcherUsingTracks.cc:42
edm::EDProducer
Definition: EDProducer.h:36
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
Candidate.h
edm::helper::Filler
Definition: ValueMap.h:22
edm::Event
Definition: Event.h:73
pat::MatcherUsingTracks
Matcher of reconstructed objects to other reconstructed objects using the tracks inside them.
Definition: MatcherUsingTracks.cc:32
label
const char * label
Definition: PFTauDecayModeTools.cc:11