CMS 3D CMS Logo

HLTL1MuonMatcher.cc
Go to the documentation of this file.
1 //
2 //
3 
15 
18 
23 
26 
28 
30 
31 namespace pat {
32 
34  public:
35  explicit HLTL1MuonMatcher(const edm::ParameterSet &iConfig);
36  ~HLTL1MuonMatcher() override {}
37 
38  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
39 
40  void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override;
41 
43  bool operator()(const pat::TriggerObjectStandAlone &l1) const {
44  if (resolveAmbiguities_ && (std::find(lockedItems_.begin(), lockedItems_.end(), &l1) != lockedItems_.end()))
45  return false;
46  return selector_(false, l1);
47  }
48 
49  private:
53 
55 
59 
64 
67 
70 
72  template <typename Hand, typename T>
73  void storeExtraInfo(edm::Event &iEvent,
74  const Hand &handle,
75  const std::vector<T> &values,
76  const std::string &label) const;
77 
78  // for ambiguity resolution
79  std::vector<const pat::TriggerObjectStandAlone *> lockedItems_;
80  };
81 
82 } // namespace pat
83 
85  : matcher_(iConfig),
86  recoToken_(consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("src"))),
87  l1Token_(consumes<PATPrimitiveCollection>(iConfig.getParameter<edm::InputTag>("matched"))),
88  selector_(iConfig),
89  resolveAmbiguities_(iConfig.getParameter<bool>("resolveAmbiguities")),
90  labelProp_(iConfig.getParameter<std::string>("setPropLabel")),
91  writeExtraInfo_(iConfig.existsAs<bool>("writeExtraInfo") ? iConfig.getParameter<bool>("writeExtraInfo") : false) {
92  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
93  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
94  produces<PATTriggerAssociation>(); // asso reco to l1
95  if (writeExtraInfo_) {
96  produces<edm::ValueMap<float> >("deltaR");
97  produces<edm::ValueMap<float> >("deltaPhi");
98  }
99 }
100 
102  using namespace edm;
103  using namespace std;
104 
107 
108  iEvent.getByToken(recoToken_, reco);
109  iEvent.getByToken(l1Token_, l1s);
110 
111  unique_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
112  vector<int> propMatches(reco->size(), -1);
113  vector<int> fullMatches(reco->size(), -1);
114  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
115  lockedItems_.clear();
116  for (int i = 0, n = reco->size(); i < n; ++i) {
117  TrajectoryStateOnSurface propagated;
118  const reco::Candidate &mu = (*reco)[i];
119  int match = matcher_.matchGeneric(mu, *l1s, *this, deltaRs[i], deltaPhis[i], propagated);
120  if (propagated.isValid()) {
121  GlobalPoint pos = propagated.globalPosition();
122  propMatches[i] = propOut->size();
123  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
124  propOut->back().addFilterLabel(labelProp_);
125  propOut->back().setCharge(mu.charge());
126  }
127  fullMatches[i] = match;
128  if (match != -1) {
129  lockedItems_.push_back(&(*l1s)[match]);
130  }
131  }
132  lockedItems_.clear();
133 
134  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(std::move(propOut), "propagatedReco");
135 
136  unique_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
137  PATTriggerAssociation::Filler propFiller(*propAss);
138  propFiller.insert(reco, propMatches.begin(), propMatches.end());
139  propFiller.fill();
140  iEvent.put(std::move(propAss), "propagatedReco");
141 
142  unique_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation(l1s));
143  PATTriggerAssociation::Filler fullFiller(*fullAss);
144  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
145  fullFiller.fill();
146  iEvent.put(std::move(fullAss));
147 
148  if (writeExtraInfo_) {
149  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
150  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
151  }
152 }
153 
154 template <typename Hand, typename T>
156  const Hand &handle,
157  const std::vector<T> &values,
158  const std::string &label) const {
159  using namespace edm;
160  using namespace std;
161  unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
162  typename edm::ValueMap<T>::Filler filler(*valMap);
163  filler.insert(handle, values.begin(), values.end());
164  filler.fill();
165  iEvent.put(std::move(valMap), label);
166 }
167 
168 void pat::HLTL1MuonMatcher::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) { matcher_.init(iSetup); }
169 
171 using namespace pat;
void init(const edm::EventSetup &iSetup)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
pat::PATTriggerMatchSelector< bool, PATPrimitive > selector_
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_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::TriggerObjectStandAlone PATPrimitive
pat::TriggerObjectStandAloneCollection PATPrimitiveCollection
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.
virtual double pt() const =0
transverse momentum
virtual double mass() const =0
mass
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
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
virtual int charge() const =0
electric charge
fixed size matrix
HLT enums.
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) ...
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< PATPrimitiveCollection > l1Token_
pat::TriggerObjectStandAloneMatch PATTriggerAssociation
Definition: Run.h:45
Analysis-level trigger object class (stand-alone)