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 
50 
53 
56 
58  template<typename Hand, typename T>
60  const Hand & handle,
61  const std::vector<T> & values,
62  const std::string & label) const ;
63  };
64 
65 } // namespace
66 
68  matcher_(iConfig),
69  reco_(iConfig.getParameter<edm::InputTag>("src")),
70  l1_(iConfig.getParameter<edm::InputTag>("matched")),
71  labelL1_(iConfig.getParameter<std::string>( "setL1Label")),
72  labelProp_(iConfig.getParameter<std::string>("setPropLabel")),
73  writeExtraInfo_(iConfig.getParameter<bool>("writeExtraInfo"))
74 {
75  produces<PATPrimitiveCollection>("l1muons"); // l1 in PAT format
76  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
77  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
78  produces<PATTriggerAssociation>(); // asso reco to l1
79  if (writeExtraInfo_) {
80  produces<edm::ValueMap<float> >("deltaR");
81  produces<edm::ValueMap<float> >("deltaPhi");
82  produces<edm::ValueMap<int> >("quality");
83  produces<edm::ValueMap<int> >("bx");
84  produces<edm::ValueMap<int> >("isolated");
85  produces<edm::ValueMap<reco::CandidatePtr> >();
86  produces<edm::ValueMap<reco::CandidatePtr> >("l1ToReco");
87  }
88 }
89 
90 void
92  using namespace edm;
93  using namespace std;
94 
97 
98  iEvent.getByLabel(reco_, reco);
99  iEvent.getByLabel(l1_, l1s);
100 
101  auto_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
102  auto_ptr<PATPrimitiveCollection> l1Out(new PATPrimitiveCollection());
103  std::vector<edm::Ptr<reco::Candidate> > l1rawMatches(reco->size());
104  vector<int> isSelected(l1s->size(), -1);
105  std::vector<edm::Ptr<reco::Candidate> > whichRecoMatch(l1s->size());
106  vector<int> propMatches(reco->size(), -1);
107  vector<int> fullMatches(reco->size(), -1);
108  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
109  vector<int> quality(reco->size(), 0), bx(reco->size(), -999), isolated(reco->size(), -999);
110  for (int i = 0, n = reco->size(); i < n; ++i) {
111  TrajectoryStateOnSurface propagated;
112  const reco::Candidate &mu = (*reco)[i];
113  int match = matcher_.match(mu, *l1s, deltaRs[i], deltaPhis[i], propagated);
114  if (propagated.isValid()) {
115  GlobalPoint pos = propagated.globalPosition();
116  propMatches[i] = propOut->size();
117  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
118  propOut->back().addFilterLabel(labelProp_);
119  propOut->back().setCharge(mu.charge());
120  }
121  if (match != -1) {
122  const l1extra::L1MuonParticle & l1 = (*l1s)[match];
123  whichRecoMatch[match] = reco->ptrAt(i);
124  if (isSelected[match] == -1) { // copy to output if needed
125  isSelected[match] = l1Out->size();
126  l1Out->push_back(PATPrimitive(l1.polarP4()));
127  l1Out->back().addFilterLabel(labelL1_);
128  l1Out->back().setCharge(l1.charge());
129  }
130  fullMatches[i] = isSelected[match]; // index in the output collection
131  const L1MuGMTCand & gmt = l1.gmtMuonCand();
132  quality[i] = gmt.quality();
133  bx[i] = gmt.bx();
134  isolated[i] = gmt.isol();
135  l1rawMatches[i] = edm::Ptr<reco::Candidate>(l1s, size_t(match));
136  }
137  }
138 
139  OrphanHandle<PATPrimitiveCollection> l1Done = iEvent.put(l1Out, "l1muons");
140  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(propOut, "propagatedReco");
141 
142  auto_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
143  PATTriggerAssociation::Filler propFiller(*propAss);
144  propFiller.insert(reco, propMatches.begin(), propMatches.end());
145  propFiller.fill();
146  iEvent.put(propAss, "propagatedReco");
147 
148  auto_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation( l1Done));
149  PATTriggerAssociation::Filler fullFiller(*fullAss);
150  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
151  fullFiller.fill();
152  iEvent.put(fullAss);
153 
154  if (writeExtraInfo_) {
155  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
156  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
157  storeExtraInfo(iEvent, reco, bx, "bx");
158  storeExtraInfo(iEvent, reco, isolated, "isolated");
159  storeExtraInfo(iEvent, reco, quality, "quality");
160  storeExtraInfo(iEvent, reco, l1rawMatches, "");
161  storeExtraInfo(iEvent, l1s, whichRecoMatch, "l1ToReco");
162  }
163 }
164 
165 template<typename Hand, typename T>
166 void
168  const Hand & handle,
169  const std::vector<T> & values,
170  const std::string & label) const {
171  using namespace edm; using namespace std;
172  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
173  typename edm::ValueMap<T>::Filler filler(*valMap);
174  filler.insert(handle, values.begin(), values.end());
175  filler.fill();
176  iEvent.put(valMap, label);
177 }
178 
179 
180 void
182  matcher_.init(iSetup);
183 }
184 
185 
187 using namespace pat;
int i
Definition: DBlmapReader.cc:9
virtual float mass() const =0
mass
bool writeExtraInfo_
Write out additional info as ValueMaps.
#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 ~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
std::string labelL1_
Labels to set as filter names in the output.
virtual float pt() const =0
transverse momentum
int iEvent
Definition: GenABIO.cc:243
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:116
pat::TriggerObjectStandAloneMatch PATTriggerAssociation
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
unsigned int quality() const
get quality
Definition: L1MuGMTCand.h:93
virtual const PolarLorentzVector & polarP4() const GCC11_FINAL
four-momentum Lorentz vector
virtual int charge() const GCC11_FINAL
electric charge
T eta() const
Definition: PV3DBase.h:76
const L1MuGMTExtendedCand & gmtMuonCand() const
edm::InputTag reco_
Labels for input collections.
std::string labelProp_
edm::InputTag l1_
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:6
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: Run.h:41
Analysis-level trigger object class (stand-alone)