CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HLTL1MuonMatcher.cc
Go to the documentation of this file.
1 //
2 //
3 
15 
18 
23 
26 
28 
30 
31 namespace pat {
32 
34  public:
36  ~HLTL1MuonMatcher() override {}
37 
38  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
39 
41  bool operator()(const pat::TriggerObjectStandAlone &l1) const {
42  if (resolveAmbiguities_ && (std::find(lockedItems_.begin(), lockedItems_.end(), &l1) != lockedItems_.end()))
43  return false;
44  return selector_(l1);
45  }
46 
47  private:
51 
53 
57 
61 
64 
67 
69  template <typename Hand, typename T>
71  const Hand &handle,
72  const std::vector<T> &values,
73  const std::string &label) const;
74 
75  // for ambiguity resolution
76  std::vector<const pat::TriggerObjectStandAlone *> lockedItems_;
77  };
78 
79 } // namespace pat
80 
82  : matcher_(iConfig, consumesCollector()),
83  recoToken_(consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("src"))),
84  l1Token_(consumes<PATPrimitiveCollection>(iConfig.getParameter<edm::InputTag>("matched"))),
85  selector_{iConfig.getParameter<std::string>("matchedCuts")},
86  resolveAmbiguities_(iConfig.getParameter<bool>("resolveAmbiguities")),
87  labelProp_(iConfig.getParameter<std::string>("setPropLabel")),
88  writeExtraInfo_(iConfig.existsAs<bool>("writeExtraInfo") ? iConfig.getParameter<bool>("writeExtraInfo") : false) {
89  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
90  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
91  produces<PATTriggerAssociation>(); // asso reco to l1
92  if (writeExtraInfo_) {
93  produces<edm::ValueMap<float> >("deltaR");
94  produces<edm::ValueMap<float> >("deltaPhi");
95  }
96 }
97 
99  using namespace edm;
100  using namespace std;
101 
102  matcher_.init(iSetup);
103 
106 
107  iEvent.getByToken(recoToken_, reco);
108  iEvent.getByToken(l1Token_, l1s);
109 
110  unique_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
111  vector<int> propMatches(reco->size(), -1);
112  vector<int> fullMatches(reco->size(), -1);
113  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
114  lockedItems_.clear();
115  for (int i = 0, n = reco->size(); i < n; ++i) {
116  TrajectoryStateOnSurface propagated;
117  const reco::Candidate &mu = (*reco)[i];
118  int match = matcher_.matchGeneric(mu, *l1s, *this, deltaRs[i], deltaPhis[i], propagated);
119  if (propagated.isValid()) {
120  GlobalPoint pos = propagated.globalPosition();
121  propMatches[i] = propOut->size();
122  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
123  propOut->back().addFilterLabel(labelProp_);
124  propOut->back().setCharge(mu.charge());
125  }
126  fullMatches[i] = match;
127  if (match != -1) {
128  lockedItems_.push_back(&(*l1s)[match]);
129  }
130  }
131  lockedItems_.clear();
132 
133  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(std::move(propOut), "propagatedReco");
134 
135  unique_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
136  PATTriggerAssociation::Filler propFiller(*propAss);
137  propFiller.insert(reco, propMatches.begin(), propMatches.end());
138  propFiller.fill();
139  iEvent.put(std::move(propAss), "propagatedReco");
140 
141  unique_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation(l1s));
142  PATTriggerAssociation::Filler fullFiller(*fullAss);
143  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
144  fullFiller.fill();
145  iEvent.put(std::move(fullAss));
146 
147  if (writeExtraInfo_) {
148  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
149  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
150  }
151 }
152 
153 template <typename Hand, typename T>
155  const Hand &handle,
156  const std::vector<T> &values,
157  const std::string &label) const {
158  using namespace edm;
159  using namespace std;
160  unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
161  typename edm::ValueMap<T>::Filler filler(*valMap);
162  filler.insert(handle, values.begin(), values.end());
163  filler.fill();
164  iEvent.put(std::move(valMap), label);
165 }
166 
168 using namespace pat;
void init(const edm::EventSetup &iSetup)
Call this method at the beginning of each run, to initialize geometry, magnetic field and propagators...
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual double mass() const =0
mass
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
GlobalPoint globalPosition() const
L1MuonMatcherAlgo matcher_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< const pat::TriggerObjectStandAlone * > lockedItems_
edm::EDGetTokenT< edm::View< reco::Candidate > > recoToken_
Tokens for input collections.
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
char const * label
int iEvent
Definition: GenABIO.cc:224
pat::TriggerObjectStandAlone PATPrimitive
def move
Definition: eostools.py:511
pat::TriggerObjectStandAloneCollection PATPrimitiveCollection
tuple handle
Definition: patZpeak.py:25
virtual int charge() const =0
electric charge
const int mu
Definition: Constants.h:22
bool writeExtraInfo_
Write out additional info as ValueMaps.
void storeExtraInfo(edm::Event &iEvent, const Hand &handle, const std::vector< T > &values, const std::string &label) const
Store extra information in a ValueMap.
StringCutObjectSelector< PATPrimitive > selector_
Select HLT objects.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int matchGeneric(const reco::Track &tk, const Collection &l1, const Selector &sel, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
T eta() const
Definition: PV3DBase.h:73
HLTL1MuonMatcher(const edm::ParameterSet &iConfig)
Matcher of reconstructed objects to L1 Muons.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::string labelProp_
Labels to set as filter names in the output.
bool operator()(const pat::TriggerObjectStandAlone &l1) const
select L1s with patName_ and filterLabel_ (public, so it can be used by L1MuonMatcherAlgo) ...
edm::EDGetTokenT< PATPrimitiveCollection > l1Token_
pat::TriggerObjectStandAloneMatch PATTriggerAssociation
Analysis-level trigger object class (stand-alone)