CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuonMatcher.cc
Go to the documentation of this file.
1 //
2 //
3 
16 
19 
24 
26 
28 
30 
31 namespace pat {
32 
33  class L1MuonMatcher : public edm::EDProducer {
34  public:
35  explicit L1MuonMatcher(const edm::ParameterSet & iConfig);
36  virtual ~L1MuonMatcher() { }
37 
38  virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
39 
40  virtual void beginRun(const edm::Run & iRun, const edm::EventSetup& iSetup) override;
41  private:
45 
47 
51 
54 
57 
59  template<typename Hand, typename T>
61  const Hand & handle,
62  const std::vector<T> & values,
63  const std::string & label) const ;
64  };
65 
66 } // namespace
67 
69  matcher_(iConfig),
70  recoToken_(consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("src"))),
71  l1Token_(consumes<std::vector<l1extra::L1MuonParticle> >(iConfig.getParameter<edm::InputTag>("matched"))),
72  labelL1_(iConfig.getParameter<std::string>( "setL1Label")),
73  labelProp_(iConfig.getParameter<std::string>("setPropLabel")),
74  writeExtraInfo_(iConfig.getParameter<bool>("writeExtraInfo"))
75 {
76  produces<PATPrimitiveCollection>("l1muons"); // l1 in PAT format
77  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
78  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
79  produces<PATTriggerAssociation>(); // asso reco to l1
80  if (writeExtraInfo_) {
81  produces<edm::ValueMap<float> >("deltaR");
82  produces<edm::ValueMap<float> >("deltaPhi");
83  produces<edm::ValueMap<int> >("quality");
84  produces<edm::ValueMap<int> >("bx");
85  produces<edm::ValueMap<int> >("isolated");
86  produces<edm::ValueMap<reco::CandidatePtr> >();
87  produces<edm::ValueMap<reco::CandidatePtr> >("l1ToReco");
88  }
89 }
90 
91 void
93  using namespace edm;
94  using namespace std;
95 
98 
99  iEvent.getByToken(recoToken_, reco);
100  iEvent.getByToken(l1Token_, l1s);
101 
102  auto_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
103  auto_ptr<PATPrimitiveCollection> l1Out(new PATPrimitiveCollection());
104  std::vector<edm::Ptr<reco::Candidate> > l1rawMatches(reco->size());
105  vector<int> isSelected(l1s->size(), -1);
106  std::vector<edm::Ptr<reco::Candidate> > whichRecoMatch(l1s->size());
107  vector<int> propMatches(reco->size(), -1);
108  vector<int> fullMatches(reco->size(), -1);
109  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
110  vector<int> quality(reco->size(), 0), bx(reco->size(), -999), isolated(reco->size(), -999);
111  for (int i = 0, n = reco->size(); i < n; ++i) {
112  TrajectoryStateOnSurface propagated;
113  const reco::Candidate &mu = (*reco)[i];
114  int match = matcher_.match(mu, *l1s, deltaRs[i], deltaPhis[i], propagated);
115  if (propagated.isValid()) {
116  GlobalPoint pos = propagated.globalPosition();
117  propMatches[i] = propOut->size();
118  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
119  propOut->back().addFilterLabel(labelProp_);
120  propOut->back().setCharge(mu.charge());
121  }
122  if (match != -1) {
123  const l1extra::L1MuonParticle & l1 = (*l1s)[match];
124  whichRecoMatch[match] = reco->ptrAt(i);
125  if (isSelected[match] == -1) { // copy to output if needed
126  isSelected[match] = l1Out->size();
127  l1Out->push_back(PATPrimitive(l1.polarP4()));
128  l1Out->back().addFilterLabel(labelL1_);
129  l1Out->back().setCharge(l1.charge());
130  }
131  fullMatches[i] = isSelected[match]; // index in the output collection
132  const L1MuGMTCand & gmt = l1.gmtMuonCand();
133  quality[i] = gmt.quality();
134  bx[i] = gmt.bx();
135  isolated[i] = gmt.isol();
136  l1rawMatches[i] = edm::Ptr<reco::Candidate>(l1s, size_t(match));
137  }
138  }
139 
140  OrphanHandle<PATPrimitiveCollection> l1Done = iEvent.put(l1Out, "l1muons");
141  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(propOut, "propagatedReco");
142 
143  auto_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
144  PATTriggerAssociation::Filler propFiller(*propAss);
145  propFiller.insert(reco, propMatches.begin(), propMatches.end());
146  propFiller.fill();
147  iEvent.put(propAss, "propagatedReco");
148 
149  auto_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation( l1Done));
150  PATTriggerAssociation::Filler fullFiller(*fullAss);
151  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
152  fullFiller.fill();
153  iEvent.put(fullAss);
154 
155  if (writeExtraInfo_) {
156  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
157  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
158  storeExtraInfo(iEvent, reco, bx, "bx");
159  storeExtraInfo(iEvent, reco, isolated, "isolated");
160  storeExtraInfo(iEvent, reco, quality, "quality");
161  storeExtraInfo(iEvent, reco, l1rawMatches, "");
162  storeExtraInfo(iEvent, l1s, whichRecoMatch, "l1ToReco");
163  }
164 }
165 
166 template<typename Hand, typename T>
167 void
169  const Hand & handle,
170  const std::vector<T> & values,
171  const std::string & label) const {
172  using namespace edm; using namespace std;
173  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
174  typename edm::ValueMap<T>::Filler filler(*valMap);
175  filler.insert(handle, values.begin(), values.end());
176  filler.fill();
177  iEvent.put(valMap, label);
178 }
179 
180 
181 void
183  matcher_.init(iSetup);
184 }
185 
186 
188 using namespace pat;
int i
Definition: DBlmapReader.cc:9
bool writeExtraInfo_
Write out additional info as ValueMaps.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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 mass() const =0
mass
virtual ~L1MuonMatcher()
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
L1MuonMatcher(const edm::ParameterSet &iConfig)
GlobalPoint globalPosition() const
pat::TriggerObjectStandAloneCollection PATPrimitiveCollection
L1MuonMatcherAlgo matcher_
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
pat::TriggerObjectStandAlone PATPrimitive
bool isol() const
get isolation
Definition: L1MuGMTCand.h:114
virtual void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
edm::EDGetTokenT< std::vector< l1extra::L1MuonParticle > > l1Token_
std::string labelL1_
Labels to set as filter names in the output.
int iEvent
Definition: GenABIO.cc:230
int bx() const
get bunch crossing identifier
Definition: L1MuGMTCand.h:120
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
pat::TriggerObjectStandAloneMatch PATTriggerAssociation
virtual int charge() const
electric charge
Definition: LeafCandidate.h:91
tuple handle
Definition: patZpeak.py:22
Matcher of reconstructed objects to L1 Muons.
virtual int charge() const =0
electric charge
const int mu
Definition: Constants.h:22
unsigned int quality() const
get quality
Definition: L1MuGMTCand.h:93
edm::EDGetTokenT< edm::View< reco::Candidate > > recoToken_
Tokens for input collections.
T eta() const
Definition: PV3DBase.h:76
const L1MuGMTExtendedCand & gmtMuonCand() const
virtual const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
std::string labelProp_
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
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: Run.h:41
Analysis-level trigger object class (stand-alone)