CMS 3D CMS Logo

HLTL1MuonMatcher.cc
Go to the documentation of this file.
1 //
2 //
3 
16 
19 
24 
27 
29 
31 
32 namespace pat {
33 
35  public:
36  explicit HLTL1MuonMatcher(const edm::ParameterSet & iConfig);
37  ~HLTL1MuonMatcher() override { }
38 
39  void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
40 
41  void beginRun(const edm::Run & iRun, const edm::EventSetup& iSetup) override;
42 
43 
45  bool operator()(const pat::TriggerObjectStandAlone &l1) const {
46  if (resolveAmbiguities_ && (std::find(lockedItems_.begin(), lockedItems_.end(), &l1) != lockedItems_.end())) return false;
47  return selector_(false,l1);
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
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 {
93  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
94  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
95  produces<PATTriggerAssociation>(); // asso reco to l1
96  if (writeExtraInfo_) {
97  produces<edm::ValueMap<float> >("deltaR");
98  produces<edm::ValueMap<float> >("deltaPhi");
99  }
100 }
101 
102 void
104  using namespace edm;
105  using namespace std;
106 
109 
110  iEvent.getByToken(recoToken_, reco);
111  iEvent.getByToken(l1Token_, l1s);
112 
113  unique_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
114  vector<int> propMatches(reco->size(), -1);
115  vector<int> fullMatches(reco->size(), -1);
116  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
117  lockedItems_.clear();
118  for (int i = 0, n = reco->size(); i < n; ++i) {
119  TrajectoryStateOnSurface propagated;
120  const reco::Candidate &mu = (*reco)[i];
121  int match = matcher_.matchGeneric(mu, *l1s, *this, deltaRs[i], deltaPhis[i], propagated);
122  if (propagated.isValid()) {
123  GlobalPoint pos = propagated.globalPosition();
124  propMatches[i] = propOut->size();
125  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
126  propOut->back().addFilterLabel(labelProp_);
127  propOut->back().setCharge(mu.charge());
128  }
129  fullMatches[i] = match;
130  if (match != -1) {
131  lockedItems_.push_back(&(*l1s)[match]);
132  }
133  }
134  lockedItems_.clear();
135 
136  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(std::move(propOut), "propagatedReco");
137 
138  unique_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
139  PATTriggerAssociation::Filler propFiller(*propAss);
140  propFiller.insert(reco, propMatches.begin(), propMatches.end());
141  propFiller.fill();
142  iEvent.put(std::move(propAss), "propagatedReco");
143 
144  unique_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation(l1s));
145  PATTriggerAssociation::Filler fullFiller(*fullAss);
146  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
147  fullFiller.fill();
148  iEvent.put(std::move(fullAss));
149 
150  if (writeExtraInfo_) {
151  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
152  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
153  }
154 }
155 
156 template<typename Hand, typename T>
157 void
159  const Hand & handle,
160  const std::vector<T> & values,
161  const std::string & label) const {
162  using namespace edm; using namespace std;
163  unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
164  typename edm::ValueMap<T>::Filler filler(*valMap);
165  filler.insert(handle, values.begin(), values.end());
166  filler.fill();
167  iEvent.put(std::move(valMap), label);
168 }
169 
170 
171 void
173  matcher_.init(iSetup);
174 }
175 
176 
178 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:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
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_
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
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
int iEvent
Definition: GenABIO.cc:230
pat::TriggerObjectStandAlone PATPrimitive
pat::TriggerObjectStandAloneCollection PATPrimitiveCollection
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.
virtual double pt() const =0
transverse momentum
virtual double mass() const =0
mass
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
pat::PATTriggerMatchSelector< bool, PATPrimitive > selector_
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:76
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:510
edm::EDGetTokenT< PATPrimitiveCollection > l1Token_
pat::TriggerObjectStandAloneMatch PATTriggerAssociation
Definition: Run.h:43
Analysis-level trigger object class (stand-alone)