CMS 3D CMS Logo

L1MuonMatcher.cc
Go to the documentation of this file.
1 //
2 //
3 
15 
18 
23 
25 
27 
29 
30 namespace pat {
31 
32  class L1MuonMatcher : public edm::EDProducer {
33  public:
34  explicit L1MuonMatcher(const edm::ParameterSet &iConfig);
35  ~L1MuonMatcher() override {}
36 
37  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
38 
39  void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override;
40 
41  private:
45 
47 
52 
55 
58 
61 
63  int firstBX_;
64  int lastBX_;
65 
67  template <typename Hand, typename T>
69  const Hand &handle,
70  const std::vector<T> &values,
71  const std::string &label) const;
72  };
73 
74 } // namespace pat
75 
77  : matcher_(iConfig),
78  recoToken_(consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("src"))),
79  labelL1_(iConfig.getParameter<std::string>("setL1Label")),
80  labelProp_(iConfig.getParameter<std::string>("setPropLabel")),
81  writeExtraInfo_(iConfig.getParameter<bool>("writeExtraInfo")),
82  useStage2L1_(iConfig.getParameter<bool>("useStage2L1")),
83  firstBX_(iConfig.getParameter<int>("firstBX")),
84  lastBX_(iConfig.getParameter<int>("lastBX")) {
85  if (useStage2L1_) {
86  l1tToken_ = consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("matched"));
87  } else {
88  l1Token_ = consumes<std::vector<l1extra::L1MuonParticle> >(iConfig.getParameter<edm::InputTag>("matched"));
89  }
90  produces<PATPrimitiveCollection>("l1muons"); // l1 in PAT format
91  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
92  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
93  produces<PATTriggerAssociation>(); // asso reco to l1
94  if (writeExtraInfo_) {
95  produces<edm::ValueMap<float> >("deltaR");
96  produces<edm::ValueMap<float> >("deltaPhi");
97  produces<edm::ValueMap<int> >("quality");
98  produces<edm::ValueMap<int> >("bx");
99  if (useStage2L1_) {
100  produces<edm::ValueMap<int> >("iPhi");
101  produces<edm::ValueMap<int> >("tfIndex");
102  }
103  produces<edm::ValueMap<int> >("isolated");
104  produces<edm::ValueMap<reco::CandidatePtr> >();
105  produces<edm::ValueMap<reco::CandidatePtr> >("l1ToReco");
106  }
107 }
108 
110  using namespace edm;
111  using namespace std;
112 
116 
117  std::vector<l1t::Muon> l1ts;
118  std::vector<size_t> bxIdxs;
119 
120  int minBxIdx = 0;
121  size_t l1size = 0;
122 
123  iEvent.getByToken(recoToken_, reco);
124 
125  if (useStage2L1_) {
126  iEvent.getByToken(l1tToken_, l1tBX);
127  l1size = l1tBX->size();
128 
129  int minBX = max(firstBX_, l1tBX->getFirstBX());
130  int maxBX = min(lastBX_, l1tBX->getLastBX());
131 
132  minBxIdx = l1tBX->begin(minBX) - l1tBX->begin();
133  std::copy(l1tBX->begin(minBX), l1tBX->end(maxBX), std::back_inserter(l1ts));
134 
135  for (int ibx = l1tBX->getFirstBX(); ibx <= l1tBX->getLastBX(); ++ibx) {
136  bxIdxs.push_back(l1tBX->end(ibx) - l1tBX->begin());
137  }
138  } else {
139  iEvent.getByToken(l1Token_, l1s);
140  l1size = l1s->size();
141  }
142 
143  unique_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
144  unique_ptr<PATPrimitiveCollection> l1Out(new PATPrimitiveCollection());
145  std::vector<edm::Ptr<reco::Candidate> > l1rawMatches(reco->size());
146  vector<int> isSelected(l1size, -1);
147  std::vector<edm::Ptr<reco::Candidate> > whichRecoMatch(l1size);
148  vector<int> propMatches(reco->size(), -1);
149  vector<int> fullMatches(reco->size(), -1);
150  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
151  vector<int> quality(reco->size(), 0), bx(reco->size(), -999), isolated(reco->size(), -999);
152  vector<int> iPhi(reco->size(), 0), tfIndex(reco->size(), -999);
153  for (int i = 0, n = reco->size(); i < n; ++i) {
154  TrajectoryStateOnSurface propagated;
155  const reco::Candidate &mu = (*reco)[i];
156  int match = useStage2L1_ ? matcher_.match(mu, l1ts, deltaRs[i], deltaPhis[i], propagated)
157  : matcher_.match(mu, *l1s, deltaRs[i], deltaPhis[i], propagated);
158  if (propagated.isValid()) {
159  GlobalPoint pos = propagated.globalPosition();
160  propMatches[i] = propOut->size();
161  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
162  propOut->back().addFilterLabel(labelProp_);
163  propOut->back().setCharge(mu.charge());
164  }
165  if (match != -1) {
166  if (useStage2L1_) {
167  match += minBxIdx;
168  }
169 
170  whichRecoMatch[match] = reco->ptrAt(i);
171 
172  int charge = 0;
174 
175  if (useStage2L1_) {
176  const l1t::Muon &l1t = (*l1tBX)[match];
177  charge = l1t.charge();
178  p4 = l1t.polarP4();
179  } else {
180  const l1extra::L1MuonParticle &l1 = (*l1s)[match];
181  charge = l1.charge();
182  p4 = l1.polarP4();
183  }
184 
185  if (isSelected[match] == -1) { // copy to output if needed
186  isSelected[match] = l1Out->size();
187  l1Out->push_back(PATPrimitive(p4));
188  l1Out->back().addFilterLabel(labelL1_);
189  l1Out->back().setCharge(charge);
190  }
191 
192  fullMatches[i] = isSelected[match]; // index in the output collection
193 
194  if (useStage2L1_) {
195  const l1t::Muon &l1t = (*l1tBX)[match];
196  quality[i] = l1t.hwQual();
197  bx[i] = l1tBX->getFirstBX() + (std::upper_bound(bxIdxs.begin(), bxIdxs.end(), match) - bxIdxs.begin());
198  isolated[i] = l1t.hwIso();
199  l1rawMatches[i] = edm::Ptr<reco::Candidate>(l1tBX, size_t(match));
200  iPhi[i] = l1t.hwPhi();
201  tfIndex[i] = l1t.tfMuonIndex();
202  } else {
203  const L1MuGMTCand &gmt = (*l1s)[match].gmtMuonCand();
204  quality[i] = gmt.quality();
205  bx[i] = gmt.bx();
206  isolated[i] = gmt.isol();
207  l1rawMatches[i] = edm::Ptr<reco::Candidate>(l1s, size_t(match));
208  }
209  }
210  }
211 
212  OrphanHandle<PATPrimitiveCollection> l1Done = iEvent.put(std::move(l1Out), "l1muons");
213  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(std::move(propOut), "propagatedReco");
214 
215  unique_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
216  PATTriggerAssociation::Filler propFiller(*propAss);
217  propFiller.insert(reco, propMatches.begin(), propMatches.end());
218  propFiller.fill();
219  iEvent.put(std::move(propAss), "propagatedReco");
220 
221  unique_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation(l1Done));
222  PATTriggerAssociation::Filler fullFiller(*fullAss);
223  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
224  fullFiller.fill();
225  iEvent.put(std::move(fullAss));
226 
227  if (writeExtraInfo_) {
228  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
229  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
230  storeExtraInfo(iEvent, reco, bx, "bx");
231  storeExtraInfo(iEvent, reco, isolated, "isolated");
232  storeExtraInfo(iEvent, reco, quality, "quality");
233  storeExtraInfo(iEvent, reco, l1rawMatches, "");
234  if (useStage2L1_) {
235  storeExtraInfo(iEvent, l1tBX, whichRecoMatch, "l1ToReco");
236  storeExtraInfo(iEvent, reco, tfIndex, "tfIndex");
237  storeExtraInfo(iEvent, reco, iPhi, "iPhi");
238  } else {
239  storeExtraInfo(iEvent, l1s, whichRecoMatch, "l1ToReco");
240  }
241  }
242 }
243 
244 template <typename Hand, typename T>
246  const Hand &handle,
247  const std::vector<T> &values,
248  const std::string &label) const {
249  using namespace edm;
250  using namespace std;
251  unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
252  typename edm::ValueMap<T>::Filler filler(*valMap);
253  filler.insert(handle, values.begin(), values.end());
254  filler.fill();
255  iEvent.put(std::move(valMap), label);
256 }
257 
258 void pat::L1MuonMatcher::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) { matcher_.init(iSetup); }
259 
261 using namespace pat;
pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
simKBmtfStubs_cfi.minBX
minBX
Definition: simKBmtfStubs_cfi.py:9
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
mps_fire.i
i
Definition: mps_fire.py:428
pat::L1MuonMatcher::beginRun
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
Definition: L1MuonMatcher.cc:258
pat::L1MuonMatcher::L1MuonMatcher
L1MuonMatcher(const edm::ParameterSet &iConfig)
Definition: L1MuonMatcher.cc:76
GlobalTrackerMuonAlignment_cfi.isolated
isolated
Definition: GlobalTrackerMuonAlignment_cfi.py:4
MessageLogger.h
edm::Association::Filler
Definition: Association.h:78
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pat::L1MuonMatcher::labelL1_
std::string labelL1_
Labels to set as filter names in the output.
Definition: L1MuonMatcher.cc:54
configurableAnalysis::Candidate
char Candidate[]
Definition: modules.cc:20
EDProducer.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
sistrip::View
View
Definition: ConstantsForView.h:26
pat::L1MuonMatcher::useStage2L1_
bool useStage2L1_
Allow to run both on legacy or stage2 (2016) L1 Muon trigger output.
Definition: L1MuonMatcher.cc:60
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::Run
Definition: Run.h:45
min
T min(T a, T b)
Definition: MathUtil.h:58
deltaPhi.h
pat::TriggerObjectStandAlone
Analysis-level trigger object class (stand-alone)
Definition: TriggerObjectStandAlone.h:32
edm::EDGetTokenT
Definition: EDGetToken.h:33
pat::L1MuonMatcher::lastBX_
int lastBX_
Definition: L1MuonMatcher.cc:64
edm
HLT enums.
Definition: AlignableModifier.h:19
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
pos
Definition: PixelAliasList.h:18
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
Association.h
edm::Handle
Definition: AssociativeIterator.h:50
L1MuGMTCand
Definition: L1MuGMTCand.h:39
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:109
BXVector::getFirstBX
int getFirstBX() const
L1MuGMTCand::bx
int bx() const
get bunch crossing identifier
Definition: L1MuGMTCand.h:117
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
pat::L1MuonMatcher
Matcher of reconstructed objects to L1 Muons.
Definition: L1MuonMatcher.cc:32
L1Scalers_cfi.l1s
l1s
Definition: L1Scalers_cfi.py:5
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
pat::L1MuonMatcher::recoToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > recoToken_
Tokens for input collections.
Definition: L1MuonMatcher.cc:49
L1MuGMTCand::quality
unsigned int quality() const
get quality
Definition: L1MuGMTCand.h:90
pat::L1MuonMatcher::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: L1MuonMatcher.cc:109
L1MuonMatcherAlgo.h
Point3DBase< float, GlobalTag >
BXVector::begin
const_iterator begin(int bx) const
pat::L1MuonMatcher::l1tToken_
edm::EDGetTokenT< l1t::MuonBxCollection > l1tToken_
Definition: L1MuonMatcher.cc:51
pat::L1MuonMatcher::storeExtraInfo
void storeExtraInfo(edm::Event &iEvent, const Hand &handle, const std::vector< T > &values, const std::string &label) const
Store extra information in a ValueMap.
Definition: L1MuonMatcher.cc:245
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::L1MuonMatcher::firstBX_
int firstBX_
Skim stage2 BX vector.
Definition: L1MuonMatcher.cc:63
pat::L1MuonMatcher::PATPrimitive
pat::TriggerObjectStandAlone PATPrimitive
Definition: L1MuonMatcher.cc:42
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
BXVector::end
const_iterator end(int bx) const
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
deltaR.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
l1t
delete x;
Definition: CaloConfig.h:22
pat::L1MuonMatcher::writeExtraInfo_
bool writeExtraInfo_
Write out additional info as ValueMaps.
Definition: L1MuonMatcher.cc:57
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
Ptr.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::TriggerObjectStandAloneCollection
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
Definition: TriggerObjectStandAlone.h:219
p4
double p4[4]
Definition: TauolaWrapper.h:92
reco::LeafCandidate::charge
int charge() const final
electric charge
Definition: LeafCandidate.h:106
simKBmtfStubs_cfi.maxBX
maxBX
Definition: simKBmtfStubs_cfi.py:10
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
pat::L1MuonMatcher::l1Token_
edm::EDGetTokenT< std::vector< l1extra::L1MuonParticle > > l1Token_
Definition: L1MuonMatcher.cc:50
InputTag.h
edm::Ptr< reco::Candidate >
reco::Candidate
Definition: Candidate.h:27
ValueMap.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
l1s
Definition: L1Scalers.h:16
pat::L1MuonMatcher::matcher_
L1MuonMatcherAlgo matcher_
Definition: L1MuonMatcher.cc:46
edm::ValueMap
Definition: ValueMap.h:107
dt_dqm_sourceclient_common_cff.reco
reco
Definition: dt_dqm_sourceclient_common_cff.py:110
edm::EDProducer
Definition: EDProducer.h:35
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
BXVector::size
unsigned size(int bx) const
l1extra::L1MuonParticle
Definition: L1MuonParticle.h:27
math::PtEtaPhiMLorentzVector
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
edm::helper::Filler
Definition: ValueMap.h:22
reco::LeafCandidate::polarP4
const PolarLorentzVector & polarP4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:116
View.h
pat::L1MuonMatcher::labelProp_
std::string labelProp_
Definition: L1MuonMatcher.cc:54
l1t::Muon
Definition: Muon.h:21
edm::Event
Definition: Event.h:73
pat::L1MuonMatcher::PATPrimitiveCollection
pat::TriggerObjectStandAloneCollection PATPrimitiveCollection
Definition: L1MuonMatcher.cc:43
BXVector::getLastBX
int getLastBX() const
pat::L1MuonMatcher::PATTriggerAssociation
pat::TriggerObjectStandAloneMatch PATTriggerAssociation
Definition: L1MuonMatcher.cc:44
TriggerObjectStandAlone.h
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
L1MuGMTCand::isol
bool isol() const
get isolation
Definition: L1MuGMTCand.h:111
L1MuonMatcherAlgo
Matcher of reconstructed objects to L1 Muons.
Definition: L1MuonMatcherAlgo.h:26
pat::L1MuonMatcher::~L1MuonMatcher
~L1MuonMatcher() override
Definition: L1MuonMatcher.cc:35