CMS 3D CMS Logo

PATMuonProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
5 
9 
13 
15 
19 
22 
24 
27 
31 
36 
37 #include "TMath.h"
38 
40 
45 
50 
53 
54 #include <vector>
55 #include <memory>
56 
57 
58 using namespace pat;
59 using namespace std;
60 
62 
63  if (iConfig.getParameter<bool>("computeMuonMVA")) {
64  edm::FileInPath mvaTrainingFile = iConfig.getParameter<edm::FileInPath>("mvaTrainingFile");
65  float mvaDrMax = iConfig.getParameter<double>("mvaDrMax");
66  muonMvaEstimator_ = std::make_unique<MuonMvaEstimator>(mvaTrainingFile, mvaDrMax);
67  }
68 
69  if (iConfig.getParameter<bool>("computeSoftMuonMVA")) {
70  edm::FileInPath softMvaTrainingFile = iConfig.getParameter<edm::FileInPath>("softMvaTrainingFile");
71  softMuonMvaEstimator_ = std::make_unique<SoftMuonMvaEstimator>(softMvaTrainingFile);
72  }
73 }
74 
76  relMiniIsoPUCorrected_(0),
77  useUserData_(iConfig.exists("userData")),
78  computeMuonMVA_(false),
79  computeSoftMuonMVA_(false),
80  recomputeBasicSelectors_(false),
81  mvaUseJec_(false),
82  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false)
83 {
84  // input source
85  muonToken_ = consumes<edm::View<reco::Muon> >(iConfig.getParameter<edm::InputTag>( "muonSource" ));
86  // embedding of tracks
87  embedBestTrack_ = iConfig.getParameter<bool>( "embedMuonBestTrack" );
88  embedTunePBestTrack_ = iConfig.getParameter<bool>( "embedTunePMuonBestTrack" );
89  forceEmbedBestTrack_ = iConfig.getParameter<bool>( "forceBestTrackEmbedding" );
90  embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
91  embedCombinedMuon_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
92  embedStandAloneMuon_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
93  // embedding of muon MET correction information
94  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs" );
95  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs" );
96  caloMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs" ));
97  tcMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs" ));
98  // pflow specific configurables
99  useParticleFlow_ = iConfig.getParameter<bool>( "useParticleFlow" );
100  embedPFCandidate_ = iConfig.getParameter<bool>( "embedPFCandidate" );
101  pfMuonToken_ = mayConsume<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>( "pfMuonSource" ));
102  embedPfEcalEnergy_ = iConfig.getParameter<bool>( "embedPfEcalEnergy" );
103  // embedding of tracks from TeV refit
104  embedPickyMuon_ = iConfig.getParameter<bool>( "embedPickyMuon" );
105  embedTpfmsMuon_ = iConfig.getParameter<bool>( "embedTpfmsMuon" );
106  embedDytMuon_ = iConfig.getParameter<bool>( "embedDytMuon" );
107  // Monte Carlo matching
108  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
109  if (addGenMatch_) {
110  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
111  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
112  genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection> >(iConfig.getParameter<edm::InputTag>( "genParticleMatch" )));
113  }
114  else {
115  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
116  }
117  }
118  // efficiencies
119  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
120  if(addEfficiencies_){
121  efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
122  }
123  // resolutions
124  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
125  if (addResolutions_) {
127  }
128  // puppi
129  addPuppiIsolation_ = iConfig.getParameter<bool>("addPuppiIsolation");
130  if(addPuppiIsolation_){
131  PUPPIIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
132  PUPPIIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
133  PUPPIIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
134  //puppiNoLeptons
135  PUPPINoLeptonsIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons"));
136  PUPPINoLeptonsIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons"));
137  PUPPINoLeptonsIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationPhotons"));
138  }
139  // read isoDeposit labels, for direct embedding
140  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
141  // read isolation value labels, for direct embedding
143  // check to see if the user wants to add user data
144  if( useUserData_ ){
145  userDataHelper_ = PATUserDataHelper<Muon>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
146  }
147  // embed high level selection variables
148  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
149  if ( embedHighLevelSelection_ ) {
150  beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"));
151  pvToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("pvSrc"));
152  }
153 
154  //for mini-isolation calculation
155  computeMiniIso_ = iConfig.getParameter<bool>("computeMiniIso");
156 
157  miniIsoParams_ = iConfig.getParameter<std::vector<double> >("miniIsoParams");
158  if(computeMiniIso_ && miniIsoParams_.size() != 9){
159  throw cms::Exception("ParameterError") << "miniIsoParams must have exactly 9 elements.\n";
160  }
161  if(computeMiniIso_)
162  pcToken_ = consumes<pat::PackedCandidateCollection >(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
163 
164  // standard selectors
165  recomputeBasicSelectors_ = iConfig.getParameter<bool>("recomputeBasicSelectors");
166  computeMuonMVA_ = iConfig.getParameter<bool>("computeMuonMVA");
167  if (computeMuonMVA_ and not computeMiniIso_)
168  throw cms::Exception("ConfigurationError") << "MiniIso is needed for Muon MVA calculation.\n";
169 
170  if (computeMuonMVA_) {
171  // pfCombinedInclusiveSecondaryVertexV2BJetTags
172  mvaBTagCollectionTag_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("mvaJetTag"));
173  mvaL1Corrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1Corrector"));
174  mvaL1L2L3ResCorrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1L2L3ResCorrector"));
175  rho_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
176  mvaUseJec_ = iConfig.getParameter<bool>("mvaUseJec");
177  }
178 
179  computeSoftMuonMVA_ = iConfig.getParameter<bool>("computeSoftMuonMVA");
180 
181  // MC info
182  simInfo_ = consumes<edm::ValueMap<reco::MuonSimInfo> >(iConfig.getParameter<edm::InputTag>("muonSimInfo"));
183 
184  addTriggerMatching_ = iConfig.getParameter<bool>("addTriggerMatching");
185  if ( addTriggerMatching_ ){
186  triggerObjects_ = consumes<std::vector<pat::TriggerObjectStandAlone>>(iConfig.getParameter<edm::InputTag>("triggerObjects"));
187  triggerResults_ = consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("triggerResults"));
188  }
189  hltCollectionFilters_ = iConfig.getParameter<std::vector<std::string>>("hltCollectionFilters");
190 
191  // produces vector of muons
192  produces<std::vector<Muon> >();
193 }
194 
195 
197 {
198 }
199 
200 std::optional<GlobalPoint> PATMuonProducer::getMuonDirection(const reco::MuonChamberMatch& chamberMatch,
202  const DetId& chamberId)
203 {
204  const GeomDet* chamberGeometry = geometry->idToDet( chamberId );
205  if (chamberGeometry){
206  LocalPoint localPosition(chamberMatch.x, chamberMatch.y, 0);
207  return std::optional<GlobalPoint>(std::in_place, chamberGeometry->toGlobal(localPosition));
208  }
209  return std::optional<GlobalPoint>();
210 
211 }
212 
213 
215  edm::Handle<std::vector<pat::TriggerObjectStandAlone> >& triggerObjects,
216  const edm::TriggerNames & names,
218 {
219  // L1 trigger object parameters are defined at MB2/ME2. Use the muon
220  // chamber matching information to get the local direction of the
221  // muon trajectory and convert it to a global direction to match the
222  // trigger objects
223 
224  std::optional<GlobalPoint> muonPosition;
225  // Loop over chambers
226  // initialize muonPosition with any available match, just in case
227  // the second station is missing - it's better folling back to
228  // dR matching at IP
229  for ( const auto& chamberMatch: aMuon.matches() ) {
230  if ( chamberMatch.id.subdetId() == MuonSubdetId::DT) {
231  DTChamberId detId(chamberMatch.id.rawId());
232  if (abs(detId.station())>3) continue;
233  muonPosition = getMuonDirection(chamberMatch, geometry, detId);
234  if (abs(detId.station())==2) break;
235  }
236  if ( chamberMatch.id.subdetId() == MuonSubdetId::CSC) {
237  CSCDetId detId(chamberMatch.id.rawId());
238  if (abs(detId.station())>3) continue;
239  muonPosition = getMuonDirection(chamberMatch, geometry, detId);
240  if (abs(detId.station())==2) break;
241  }
242  }
243  if (not muonPosition) return;
244  for (const auto& triggerObject: *triggerObjects){
245  if (triggerObject.hasTriggerObjectType(trigger::TriggerL1Mu)){
246  if (fabs(triggerObject.eta())<0.001){
247  // L1 is defined in X-Y plain
248  if (deltaPhi(triggerObject.phi(),muonPosition->phi())>0.1) continue;
249  } else {
250  // 3D L1
251  if (deltaR(triggerObject.p4(),*muonPosition)>0.15) continue;
252  }
253  pat::TriggerObjectStandAlone obj(triggerObject);
254  obj.unpackPathNames(names);
255  aMuon.addTriggerObjectMatch(obj);
256  }
257  }
258 }
259 
261  edm::Handle<std::vector<pat::TriggerObjectStandAlone> >& triggerObjects,
262  const edm::TriggerNames & names,
263  const std::vector<std::string>& collection_filter_names)
264 {
265  // WARNING: in a case of close-by muons the dR matching may select both muons.
266  // It's better to select the best match for a given collection.
267  for (const auto& triggerObject: *triggerObjects){
268  if (triggerObject.hasTriggerObjectType(trigger::TriggerMuon)){
269  bool keepIt = false;
270  for (const auto& name: collection_filter_names){
271  if (triggerObject.hasCollection(name)){
272  keepIt = true;
273  break;
274  }
275  }
276  if (not keepIt) continue;
277  if ( deltaR(triggerObject.p4(),muon)>0.1 ) continue;
278  pat::TriggerObjectStandAlone obj(triggerObject);
279  obj.unpackPathNames(names);
280  muon.addTriggerObjectMatch(obj);
281  }
282  }
283 }
284 
285 
287 {
288  // get the tracking Geometry
290  iSetup.get<GlobalTrackingGeometryRecord>().get(geometry);
291  if ( ! geometry.isValid() )
292  throw cms::Exception("FatalError") << "Unable to find GlobalTrackingGeometryRecord in event!\n";
293 
294  // switch off embedding (in unschedules mode)
295  if (iEvent.isRealData()){
296  addGenMatch_ = false;
297  embedGenMatch_ = false;
298  }
299 
301  iEvent.getByToken(muonToken_, muons);
302 
303 
305  if(computeMiniIso_)
306  iEvent.getByToken(pcToken_, pc);
307 
308  // get the ESHandle for the transient track builder,
309  // if needed for high level selection embedding
311 
312  if(isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
314  if(resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
315 
317  for (size_t j = 0; j<isoDepositTokens_.size(); ++j) {
318  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
319  }
320 
322  for (size_t j = 0; j<isolationValueTokens_.size(); ++j) {
324  }
325 
326  //value maps for puppi isolation
327  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
328  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
329  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
330  //value maps for puppiNoLeptons isolation
331  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons;
332  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons;
333  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons;
334  if(addPuppiIsolation_){
335  //puppi
336  iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
337  iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
338  iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
339  //puppiNoLeptons
340  iEvent.getByToken(PUPPINoLeptonsIsolation_charged_hadrons_, PUPPINoLeptonsIsolation_charged_hadrons);
341  iEvent.getByToken(PUPPINoLeptonsIsolation_neutral_hadrons_, PUPPINoLeptonsIsolation_neutral_hadrons);
342  iEvent.getByToken(PUPPINoLeptonsIsolation_photons_, PUPPINoLeptonsIsolation_photons);
343  }
344 
345  // inputs for muon mva
346  edm::Handle<reco::JetTagCollection> mvaBTagCollectionTag;
349  if (computeMuonMVA_) {
350  iEvent.getByToken(mvaBTagCollectionTag_,mvaBTagCollectionTag);
351  iEvent.getByToken(mvaL1Corrector_,mvaL1Corrector);
352  iEvent.getByToken(mvaL1L2L3ResCorrector_,mvaL1L2L3ResCorrector);
353  }
354 
355  // prepare the MC genMatchTokens_
356  GenAssociations genMatches(genMatchTokens_.size());
357  if (addGenMatch_) {
358  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
359  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
360  }
361  }
362 
363  // prepare the high level selection: needs beamline
364  // OR primary vertex, depending on user selection
367  bool beamSpotIsValid = false;
368  bool primaryVertexIsValid = false;
369  if ( embedHighLevelSelection_ ) {
370  // get the beamspot
371  edm::Handle<reco::BeamSpot> beamSpotHandle;
372  iEvent.getByToken(beamLineToken_, beamSpotHandle);
373 
374  // get the primary vertex
376  iEvent.getByToken( pvToken_, pvHandle );
377 
378  if( beamSpotHandle.isValid() ){
379  beamSpot = *beamSpotHandle;
380  beamSpotIsValid = true;
381  } else{
382  edm::LogError("DataNotAvailable")
383  << "No beam spot available from EventSetup, not adding high level selection \n";
384  }
385  if( pvHandle.isValid() && !pvHandle->empty() ) {
386  primaryVertex = pvHandle->at(0);
387  primaryVertexIsValid = true;
388  } else {
389  edm::LogError("DataNotAvailable")
390  << "No primary vertex available from EventSetup, not adding high level selection \n";
391  }
392  // this is needed by the IPTools methods from the tracking group
393  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
394  }
395 
396  // MC info
398  bool simInfoIsAvailalbe = iEvent.getByToken(simInfo_,simInfo);
399 
400  // this will be the new object collection
401  std::vector<Muon> * patMuons = new std::vector<Muon>();
402 
404  if( useParticleFlow_ ){
405  // get the PFCandidates of type muons
406  iEvent.getByToken(pfMuonToken_, pfMuons);
407 
408  unsigned index=0;
409  for( reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
410  const reco::PFCandidate& pfmu = *i;
411  //const reco::IsolaPFCandidate& pfmu = *i;
412  const reco::MuonRef& muonRef = pfmu.muonRef();
413  assert( muonRef.isNonnull() );
414 
415  MuonBaseRef muonBaseRef(muonRef);
416  Muon aMuon(muonBaseRef);
417 
418  if ( useUserData_ ) {
419  userDataHelper_.add( aMuon, iEvent, iSetup );
420  }
421 
422  // embed high level selection
423  if ( embedHighLevelSelection_ ) {
424  // get the tracks
425  reco::TrackRef innerTrack = muonBaseRef->innerTrack();
426  reco::TrackRef globalTrack= muonBaseRef->globalTrack();
427  reco::TrackRef bestTrack = muonBaseRef->muonBestTrack();
428  reco::TrackRef chosenTrack = innerTrack;
429  // Make sure the collection it points to is there
430  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
431  chosenTrack = bestTrack;
432 
433  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
434  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
435  aMuon.setNumberOfValidHits( nhits );
436 
437  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
438  embedHighLevel( aMuon,
439  chosenTrack,
440  tt,
441  primaryVertex,
442  primaryVertexIsValid,
443  beamSpot,
444  beamSpotIsValid );
445 
446  }
447 
448  if ( globalTrack.isNonnull() && globalTrack.isAvailable() && !embedCombinedMuon_) {
449  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
450  aMuon.setNormChi2( norm_chi2 );
451  }
452  }
453  reco::PFCandidateRef pfRef(pfMuons,index);
454  //reco::PFCandidatePtr ptrToMother(pfMuons,index);
455  reco::CandidateBaseRef pfBaseRef( pfRef );
456 
457  aMuon.setPFCandidateRef( pfRef );
458  if( embedPFCandidate_ ) aMuon.embedPFCandidate();
459  fillMuon( aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues );
460 
461  if(computeMiniIso_)
462  setMuonMiniIso(aMuon, pc.product());
463 
464  if (addPuppiIsolation_) {
465  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonBaseRef],
466  (*PUPPIIsolation_neutral_hadrons)[muonBaseRef],
467  (*PUPPIIsolation_photons)[muonBaseRef]);
468 
469  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonBaseRef],
470  (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonBaseRef],
471  (*PUPPINoLeptonsIsolation_photons)[muonBaseRef]);
472  }
473  else {
474  aMuon.setIsolationPUPPI(-999., -999.,-999.);
475  aMuon.setIsolationPUPPINoLeptons(-999., -999.,-999.);
476  }
477 
478  if (embedPfEcalEnergy_) {
479  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
480  }
481 
482  patMuons->push_back(aMuon);
483  }
484  }
485  else {
487  iEvent.getByToken(muonToken_, muons);
488 
489  // embedding of muon MET corrections
491  //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
493  iEvent.getByToken(caloMETMuonCorrsToken_, caloMETMuonCorrs);
494  //caloMETmuCorValueMap = *caloMETmuCorValueMap_h;
495  }
497  //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
499  iEvent.getByToken(tcMETMuonCorrsToken_, tcMETMuonCorrs);
500  //tcMETmuCorValueMap = *tcMETmuCorValueMap_h;
501  }
502 
503  if (embedPfEcalEnergy_) {
504  // get the PFCandidates of type muons
505  iEvent.getByToken(pfMuonToken_, pfMuons);
506  }
507 
508  for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
509  // construct the Muon from the ref -> save ref to original object
510  unsigned int idx = itMuon - muons->begin();
511  MuonBaseRef muonRef = muons->refAt(idx);
512  reco::CandidateBaseRef muonBaseRef( muonRef );
513 
514  Muon aMuon(muonRef);
515  fillMuon( aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);
516  if(computeMiniIso_)
517  setMuonMiniIso(aMuon, pc.product());
518  if (addPuppiIsolation_) {
519  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonRef], (*PUPPIIsolation_neutral_hadrons)[muonRef], (*PUPPIIsolation_photons)[muonRef]);
520  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_photons)[muonRef]);
521  }
522  else {
523  aMuon.setIsolationPUPPI(-999., -999.,-999.);
524  aMuon.setIsolationPUPPINoLeptons(-999., -999.,-999.);
525  }
526 
527  // Isolation
528  if (isolator_.enabled()) {
529  //reco::CandidatePtr mother = ptrToMother->sourceCandidatePtr(0);
530  isolator_.fill(*muons, idx, isolatorTmpStorage_);
531  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
532  // better to loop backwards, so the vector is resized less times
533  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
534  aMuon.setIsolation(it->first, it->second);
535  }
536  }
537 
538  // for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
539  // aMuon.setIsoDeposit(isoDepositLabels_[j].first,
540  // (*deposits[j])[muonRef]);
541  // }
542 
543  // add sel to selected
544  edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
545  if ( useUserData_ ) {
546  userDataHelper_.add( aMuon, iEvent, iSetup );
547  }
548 
549  // embed high level selection
550  if ( embedHighLevelSelection_ ) {
551  // get the tracks
552  reco::TrackRef innerTrack = itMuon->innerTrack();
553  reco::TrackRef globalTrack= itMuon->globalTrack();
554  reco::TrackRef bestTrack = itMuon->muonBestTrack();
555  reco::TrackRef chosenTrack = innerTrack;
556  // Make sure the collection it points to is there
557  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
558  chosenTrack = bestTrack;
559  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
560  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
561  aMuon.setNumberOfValidHits( nhits );
562 
563  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
564  embedHighLevel( aMuon,
565  chosenTrack,
566  tt,
567  primaryVertex,
568  primaryVertexIsValid,
569  beamSpot,
570  beamSpotIsValid );
571 
572  }
573 
574  if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
575  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
576  aMuon.setNormChi2( norm_chi2 );
577  }
578  }
579 
580  // embed MET muon corrections
581  if( embedCaloMETMuonCorrs_ ) aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
582  if( embedTcMETMuonCorrs_ ) aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs )[muonRef]);
583 
584  if (embedPfEcalEnergy_) {
585  aMuon.setPfEcalEnergy(-99.0);
586  for (const reco::PFCandidate &pfmu : *pfMuons) {
587  if (pfmu.muonRef().isNonnull()) {
588  if (pfmu.muonRef().id() != muonRef.id()) throw cms::Exception("Configuration") << "Muon reference within PF candidates does not point to the muon collection." << std::endl;
589  if (pfmu.muonRef().key() == muonRef.key()) {
590  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
591  }
592  }
593  }
594  }
595  // MC info
596  aMuon.initSimInfo();
597  if (simInfoIsAvailalbe){
598  const auto& msi = (*simInfo)[muonBaseRef];
599  aMuon.setSimType(msi.primaryClass);
600  aMuon.setExtSimType(msi.extendedClass);
601  aMuon.setSimFlavour(msi.flavour);
602  aMuon.setSimHeaviestMotherFlavour(msi.heaviestMotherFlavour);
603  aMuon.setSimPdgId(msi.pdgId);
604  aMuon.setSimMotherPdgId(msi.motherPdgId);
605  aMuon.setSimBX(msi.tpBX);
606  aMuon.setSimProdRho(msi.vertex.Rho());
607  aMuon.setSimProdZ(msi.vertex.Z());
608  aMuon.setSimPt(msi.p4.pt());
609  aMuon.setSimEta(msi.p4.eta());
610  aMuon.setSimPhi(msi.p4.phi());
611  }
612  patMuons->push_back(aMuon);
613  }
614  }
615 
616  // sort muons in pt
617  std::sort(patMuons->begin(), patMuons->end(), pTComparator_);
618 
619  // Store standard muon selection decisions and jet related
620  // quantaties.
621  // Need a separate loop over muons to have all inputs properly
622  // computed and stored in the object.
624  if (computeMuonMVA_) iEvent.getByToken(rho_,rho);
625  const reco::Vertex* pv(nullptr);
626  if (primaryVertexIsValid) pv = &primaryVertex;
627 
630  bool triggerObjectsAvailable = false;
631  bool triggerResultsAvailable = false;
632  if (addTriggerMatching_){
633  triggerObjectsAvailable = iEvent.getByToken(triggerObjects_, triggerObjects);
634  triggerResultsAvailable = iEvent.getByToken(triggerResults_, triggerResults);
635  }
636 
637  for(auto& muon: *patMuons){
638  // trigger info
639  if (addTriggerMatching_ and triggerObjectsAvailable and triggerResultsAvailable){
640  const edm::TriggerNames & triggerNames(iEvent.triggerNames( *triggerResults ));
641  fillL1TriggerInfo(muon,triggerObjects,triggerNames,geometry);
642  fillHltTriggerInfo(muon,triggerObjects,triggerNames,hltCollectionFilters_);
643  }
644 
646  muon.setSelectors(0);
647  bool isRun2016BCDEF = (272728 <= iEvent.run() && iEvent.run() <= 278808);
648  muon::setCutBasedSelectorFlags(muon, pv, isRun2016BCDEF);
649  }
650  double miniIsoValue = -1;
651  if (computeMiniIso_){
652  // MiniIsolation working points
653  double miniIsoValue = getRelMiniIsoPUCorrected(muon,*rho);
654  muon.setSelector(reco::Muon::MiniIsoLoose, miniIsoValue<0.40);
655  muon.setSelector(reco::Muon::MiniIsoMedium, miniIsoValue<0.20);
656  muon.setSelector(reco::Muon::MiniIsoTight, miniIsoValue<0.10);
657  muon.setSelector(reco::Muon::MiniIsoVeryTight, miniIsoValue<0.05);
658  }
659  float jetPtRatio = 0.0;
660  float jetPtRel = 0.0;
661  float mva = 0.0;
662  if (computeMuonMVA_ && primaryVertexIsValid){
663  if (mvaUseJec_)
664  mva = globalCache()->muonMvaEstimator()->computeMva(muon,
665  primaryVertex,
666  *(mvaBTagCollectionTag.product()),
667  jetPtRatio,
668  jetPtRel,
669  &*mvaL1Corrector,
670  &*mvaL1L2L3ResCorrector);
671  else
672  mva = globalCache()->muonMvaEstimator()->computeMva(muon,
673  primaryVertex,
674  *(mvaBTagCollectionTag.product()),
675  jetPtRatio,
676  jetPtRel);
677 
678  muon.setMvaValue(mva);
679  muon.setJetPtRatio(jetPtRatio);
680  muon.setJetPtRel(jetPtRel);
681 
682  // multi-isolation
683  if (computeMiniIso_){
684  muon.setSelector(reco::Muon::MultiIsoLoose, miniIsoValue<0.40 && (muon.jetPtRatio() > 0.80 || muon.jetPtRel() > 7.2) );
685  muon.setSelector(reco::Muon::MultiIsoMedium, miniIsoValue<0.16 && (muon.jetPtRatio() > 0.76 || muon.jetPtRel() > 7.2) );
686  }
687 
688  // MVA working points
689  // https://twiki.cern.ch/twiki/bin/viewauth/CMS/LeptonMVA
690  double dB2D = fabs(muon.dB(pat::Muon::BS2D));
691  double dB3D = fabs(muon.dB(pat::Muon::PV3D));
692  double edB3D = fabs(muon.edB(pat::Muon::PV3D));
693  double sip3D = edB3D>0?dB3D/edB3D:0.0;
694  double dz = fabs(muon.muonBestTrack()->dz(primaryVertex.position()));
695 
696  // muon preselection
697  if (muon.pt()>5 and muon.isLooseMuon() and
698  muon.passed(reco::Muon::MiniIsoLoose) and
699  sip3D<8.0 and dB2D<0.05 and dz<0.1){
700  muon.setSelector(reco::Muon::MvaLoose, muon.mvaValue()>-0.60);
701  muon.setSelector(reco::Muon::MvaMedium, muon.mvaValue()>-0.20);
702  muon.setSelector(reco::Muon::MvaTight, muon.mvaValue()> 0.15);
703  }
704  }
705 
706  //SOFT MVA
707  if (computeSoftMuonMVA_){
708  float mva = globalCache()->softMuonMvaEstimator()->computeMva(muon);
709  muon.setSoftMvaValue(mva);
710  //preselection in SoftMuonMvaEstimator.cc
711  muon.setSelector(reco::Muon::SoftMvaId, muon.softMvaValue() > 0.58 ); //WP choose for bmm4
712 
713  }
714  }
715 
716  // put products in Event
717  std::unique_ptr<std::vector<Muon> > ptr(patMuons);
718  iEvent.put(std::move(ptr));
719 
721 }
722 
723 
724 void PATMuonProducer::fillMuon( Muon& aMuon, const MuonBaseRef& muonRef, const reco::CandidateBaseRef& baseRef, const GenAssociations& genMatches, const IsoDepositMaps& deposits, const IsolationValueMaps& isolationValues ) const
725 {
726  // in the particle flow algorithm,
727  // the muon momentum is recomputed.
728  // the new value is stored as the momentum of the
729  // resulting PFCandidate of type Muon, and choosen
730  // as the pat::Muon momentum
731  if (useParticleFlow_)
732  aMuon.setP4( aMuon.pfCandidateRef()->p4() );
733  if (embedTrack_) aMuon.embedTrack();
736 
737  // embed the TeV refit track refs (only available for globalMuons)
738  if (aMuon.isGlobalMuon()) {
740  aMuon.embedPickyMuon();
742  aMuon.embedTpfmsMuon();
744  aMuon.embedDytMuon();
745  }
746 
747  // embed best tracks (at the end, so unless forceEmbedBestTrack_ is true we can save some space not embedding them twice)
750 
751  // store the match to the generated final state muons
752  if (addGenMatch_) {
753  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
754  reco::GenParticleRef genMuon = (*genMatches[i])[baseRef];
755  aMuon.addGenParticleRef(genMuon);
756  }
757  if (embedGenMatch_) aMuon.embedGenParticle();
758  }
759  if (efficiencyLoader_.enabled()) {
760  efficiencyLoader_.setEfficiencies( aMuon, muonRef );
761  }
762 
763  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
764  if(useParticleFlow_) {
765  if (deposits[j]->contains(baseRef.id())) {
766  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
767  } else if (deposits[j]->contains(muonRef.id())){
768  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
769  } else {
770  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
771  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
772  }
773  }
774  else{
775  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
776  }
777  }
778 
779  for (size_t j = 0; j<isolationValues.size(); ++j) {
780  if(useParticleFlow_) {
781  if (isolationValues[j]->contains(baseRef.id())) {
782  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
783  } else if (isolationValues[j]->contains(muonRef.id())) {
784  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
785  } else {
786  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
787  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
788  }
789  }
790  else{
791  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
792  }
793  }
794 
795  if (resolutionLoader_.enabled()) {
797  }
798 }
799 
801 {
802  pat::PFIsolation miniiso = pat::getMiniPFIsolation(pc, aMuon.p4(),
803  miniIsoParams_[0], miniIsoParams_[1], miniIsoParams_[2],
804  miniIsoParams_[3], miniIsoParams_[4], miniIsoParams_[5],
805  miniIsoParams_[6], miniIsoParams_[7], miniIsoParams_[8]);
806  aMuon.setMiniPFIsolation(miniiso);
807 }
808 
810 {
811  float mindr(miniIsoParams_[0]);
812  float maxdr(miniIsoParams_[1]);
813  float kt_scale(miniIsoParams_[2]);
814  float drcut = pat::miniIsoDr(muon.p4(),mindr,maxdr,kt_scale);
815  return pat::muonRelMiniIsoPUCorrected(muon.miniPFIsolation(), muon.p4(), drcut, rho);
816 }
817 
818 // ParameterSet description for module
820 {
822  iDesc.setComment("PAT muon producer module");
823 
824  // input source
825  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("no default"))->setComment("input collection");
826 
827  // embedding
828  iDesc.add<bool>("embedMuonBestTrack", true)->setComment("embed muon best track (global pflow)");
829  iDesc.add<bool>("embedTunePMuonBestTrack", true)->setComment("embed muon best track (muon only)");
830  iDesc.add<bool>("forceBestTrackEmbedding", true)->setComment("force embedding separately the best tracks even if they're already embedded e.g. as tracker or global tracks");
831  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
832  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
833  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
834  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky track");
835  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms track");
836  iDesc.add<bool>("embedDytMuon", false)->setComment("embed external dyt track ");
837 
838  // embedding of MET muon corrections
839  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
840  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for caloMET");
841  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
842  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for tcMET");
843 
844  // pf specific parameters
845  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->setComment("particle flow input collection");
846  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
847  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
848  iDesc.add<bool>("embedPfEcalEnergy", true)->setComment("add ecal energy as reconstructed by PF");
849 
850  // MC matching configurables
851  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
852  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
853  std::vector<edm::InputTag> emptySourceVector;
854  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
855  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
856  )->setComment("input with MC match information");
857 
858  // mini-iso
859  iDesc.add<bool>("computeMiniIso", false)->setComment("whether or not to compute and store electron mini-isolation");
860  iDesc.add<edm::InputTag>("pfCandsForMiniIso", edm::InputTag("packedPFCandidates"))->setComment("collection to use to compute mini-iso");
861  iDesc.add<std::vector<double> >("miniIsoParams", std::vector<double>())->setComment("mini-iso parameters to use for muons");
862 
863  iDesc.add<bool>("addTriggerMatching", false)->setComment("add L1 and HLT matching to offline muon");
864 
866 
867  // IsoDeposit configurables
868  edm::ParameterSetDescription isoDepositsPSet;
869  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
870  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
871  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
872  isoDepositsPSet.addOptional<edm::InputTag>("particle");
873  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
874  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
875  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
876  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
877  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
878  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
879  iDesc.addOptional("isoDeposits", isoDepositsPSet);
880 
881  // isolation values configurables
882  edm::ParameterSetDescription isolationValuesPSet;
883  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
884  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
885  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
886  isolationValuesPSet.addOptional<edm::InputTag>("particle");
887  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
888  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
889  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
890  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
891  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
892  iDesc.addOptional("isolationValues", isolationValuesPSet);
893 
894  iDesc.ifValue(edm::ParameterDescription<bool>("addPuppiIsolation", false, true),
895  true >> (edm::ParameterDescription<edm::InputTag>("puppiIsolationChargedHadrons", edm::InputTag("muonPUPPIIsolation","h+-DR030-ThresholdVeto000-ConeVeto000"), true) and
896  edm::ParameterDescription<edm::InputTag>("puppiIsolationNeutralHadrons", edm::InputTag("muonPUPPIIsolation","h0-DR030-ThresholdVeto000-ConeVeto001"), true) and
897  edm::ParameterDescription<edm::InputTag>("puppiIsolationPhotons", edm::InputTag("muonPUPPIIsolation","gamma-DR030-ThresholdVeto000-ConeVeto001"), true) and
898  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons", edm::InputTag("muonPUPPINoLeptonsIsolation","h+-DR030-ThresholdVeto000-ConeVeto000"), true) and
899  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons", edm::InputTag("muonPUPPINoLeptonsIsolation","h0-DR030-ThresholdVeto000-ConeVeto001"), true) and
900  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationPhotons", edm::InputTag("muonPUPPINoLeptonsIsolation","gamma-DR030-ThresholdVeto000-ConeVeto001"), true)) or
901  false >> edm::EmptyGroupDescription());
902 
903  // Efficiency configurables
904  edm::ParameterSetDescription efficienciesPSet;
905  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
906  iDesc.add("efficiencies", efficienciesPSet);
907  iDesc.add<bool>("addEfficiencies", false);
908 
909  // Check to see if the user wants to add user data
910  edm::ParameterSetDescription userDataPSet;
912  iDesc.addOptional("userData", userDataPSet);
913 
914  edm::ParameterSetDescription isolationPSet;
915  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
916  iDesc.add("userIsolation", isolationPSet);
917 
918  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
919  edm::ParameterSetDescription highLevelPSet;
920  highLevelPSet.setAllowAnything();
921  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
922  )->setComment("input with high level selection");
924  )->setComment("input with high level selection");
925 
926  //descriptions.add("PATMuonProducer", iDesc);
927 }
928 
929 
930 
931 // embed various impact parameters with errors
932 // embed high level selection
937  bool primaryVertexIsValid,
939  bool beamspotIsValid
940  )
941 {
942  // Correct to PV
943 
944  // PV2D
945  std::pair<bool,Measurement1D> result =
947  GlobalVector(track->px(),
948  track->py(),
949  track->pz()),
950  primaryVertex);
951  double d0_corr = result.second.value();
952  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
953  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV2D);
954 
955 
956  // PV3D
957  result =
959  GlobalVector(track->px(),
960  track->py(),
961  track->pz()),
962  primaryVertex);
963  d0_corr = result.second.value();
964  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
965  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV3D);
966 
967 
968  // Correct to beam spot
969  // make a fake vertex out of beam spot
970  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
971 
972  // BS2D
973  result =
975  GlobalVector(track->px(),
976  track->py(),
977  track->pz()),
978  vBeamspot);
979  d0_corr = result.second.value();
980  d0_err = beamspotIsValid ? result.second.error() : -1.0;
981  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS2D);
982 
983  // BS3D
984  result =
986  GlobalVector(track->px(),
987  track->py(),
988  track->pz()),
989  vBeamspot);
990  d0_corr = result.second.value();
991  d0_err = beamspotIsValid ? result.second.error() : -1.0;
992  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS3D);
993 
994 
995  // PVDZ
996  aMuon.setDB( track->dz(primaryVertex.position()), std::hypot(track->dzError(), primaryVertex.zError()), pat::Muon::PVDZ );
997 }
998 
1000 
bool embedTpfmsMuon_
embed track from tpfms muon fit into the muon
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_charged_hadrons_
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
bool useUserData_
add user data to the muon (this will be data members of th muon even w/o embedding) ...
bool isAvailable() const
Definition: Ref.h:577
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_photons_
T getParameter(std::string const &) const
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:222
void setComment(std::string const &value)
Assists in assimilating all pat::UserData into pat objects.
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
bool addPuppiIsolation_
add puppi isolation
void embedDytMuon()
embed reference to the above dyt Track
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
void embedTpfmsMuon()
embed reference to the above tpfms Track
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > tcMETMuonCorrsToken_
source of tcMET muon corrections
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:99
bool embedTcMETMuonCorrs_
embed muon MET correction info for tcMET into the muon
class definition
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
void embedTcMETMuonCorrs(const reco::MuonMETCorrectionData &t)
edm::EDGetTokenT< std::vector< reco::Vertex > > pvToken_
input source of the primary vertex
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_photons_
void embedCombinedMuon()
set reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon...
edm::EDGetTokenT< double > rho_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
input source
void embedTunePMuonBestTrack(bool force=false)
bool addEfficiencies_
add efficiencies to the muon (this will be data members of th muon even w/o embedding) ...
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > caloMETMuonCorrsToken_
source of caloMET muon corrections
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
enum start value shifted to 81 so as to avoid clashes with PDG codes
void setAllowAnything()
allow any parameter label/value pairs
double zError() const
error on z
Definition: Vertex.h:123
void setSimFlavour(int f)
Definition: Muon.h:304
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
bool embedCaloMETMuonCorrs_
embed muon MET correction info for caloMET into the muon
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
~PATMuonProducer() override
default destructur
float muonRelMiniIsoPUCorrected(const PFIsolation &iso, const math::XYZTLorentzVector &p4, float dr, float rho)
edm::EDGetTokenT< edm::ValueMap< reco::MuonSimInfo > > simInfo_
MC info.
void embedMuonBestTrack(bool force=false)
std::vector< pat::PackedCandidate > PackedCandidateCollection
void setIsolationPUPPINoLeptons(float chargedhadrons, float neutralhadrons, float photons)
sets PUPPINoLeptons isolations
Definition: Muon.h:200
void setMuonMiniIso(pat::Muon &aMuon, const pat::PackedCandidateCollection *pc)
reco::TransientTrack build(const reco::Track *p) const
PATMuonProducer(const edm::ParameterSet &iConfig, PATMuonHeavyObjectCache const *)
default constructir
bool addTriggerMatching_
Trigger.
void setSimBX(int bx)
Definition: Muon.h:308
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
bool embedBestTrack_
embed the track from best muon measurement (global pflow)
edm::EDGetTokenT< reco::JetCorrector > mvaL1Corrector_
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
void setCutBasedSelectorFlags(reco::Muon &muon, const reco::Vertex *vertex=0, bool run2016_hip_mitigation=false)
bool addResolutions_
add resolutions to the muon (this will be data members of th muon even w/o embedding) ...
void unpackPathNames(const edm::TriggerNames &names)
unpack trigger names into indices
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_charged_hadrons_
std::vector< double > miniIsoParams_
void setSimPhi(float phi)
Definition: Muon.h:313
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
void setSimProdRho(float rho)
Definition: Muon.h:309
void setSimHeaviestMotherFlavour(int id)
Definition: Muon.h:305
void setPFCandidateRef(const reco::PFCandidateRef &ref)
add a reference to the source IsolatedPFCandidate
Definition: Muon.h:133
bool isRealData() const
Definition: EventBase.h:64
const Point & position() const
position
Definition: Vertex.h:109
void embedHighLevel(pat::Muon &aMuon, reco::TrackRef track, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
ProductID id() const
Definition: RefToBase.h:242
const std::string names[nVars_]
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_neutral_hadrons_
void setSimType(reco::MuonSimType type)
Definition: Muon.h:302
void embedStandAloneMuon()
set reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
edm::EDGetTokenT< reco::JetTagCollection > mvaBTagCollectionTag_
edm::EDGetTokenT< reco::PFCandidateCollection > pfMuonToken_
input source pfCandidates that will be to be transformed into pat::Muons, when using PF2PAT ...
void setIsolationPUPPI(float chargedhadrons, float neutralhadrons, float photons)
sets PUPPI isolations
Definition: Muon.h:193
pat::helper::MultiIsolator isolator_
helper class to add userdefined isolation values to the muon
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: Lepton.h:176
Definition: HeavyIon.h:7
void embedTrack()
set reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
static void fillDescription(edm::ParameterSetDescription &iDesc)
const PFIsolation & miniPFIsolation() const
Definition: Lepton.h:196
edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
input source of the primary vertex/beamspot
bool useParticleFlow_
switch to use particle flow (PF2PAT) or not
pat::PATUserDataHelper< pat::Muon > userDataHelper_
helper class to add userData to the muon
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:50
bool embedStandAloneMuon_
embed track from muon system into the muon
void setComment(std::string const &value)
edm::EDGetTokenT< edm::TriggerResults > triggerResults_
int iEvent
Definition: GenABIO.cc:230
static const int CSC
Definition: MuonSubdetId.h:13
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
GreaterByPt< Muon > pTComparator_
bool embedTrack_
embed the track from inner tracker into the muon
void setDB(double dB, double edB, IPTYPE type=PV2D)
Definition: Muon.h:244
bool addGenMatch_
add generator match information
PATMuonHeavyObjectCache(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
description of config file parameters
Definition: Muon.py:1
void fillHltTriggerInfo(pat::Muon &muon, edm::Handle< std::vector< pat::TriggerObjectStandAlone > > &triggerObjects, const edm::TriggerNames &names, const std::vector< std::string > &collection_names)
bool isGlobalMuon() const override
Definition: Muon.h:276
bool embedPfEcalEnergy_
add ecal PF energy
void embedGenParticle()
Definition: PATObject.h:694
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
void embedPFCandidate()
embed the IsolatedPFCandidate pointed to by pfCandidateRef_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
everything that needs to be done during the event loop
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T > > cases)
reco::PFCandidateRef pfCandidateRef() const
RunNumber_t run() const
Definition: Event.h:109
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double getRelMiniIsoPUCorrected(const pat::Muon &muon, float rho)
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
void fillL1TriggerInfo(pat::Muon &muon, edm::Handle< std::vector< pat::TriggerObjectStandAlone > > &triggerObjects, const edm::TriggerNames &names, const edm::ESHandle< GlobalTrackingGeometry > &geometry)
static std::string const triggerResults
Definition: EdmProvDump.cc:42
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
std::vector< std::string > hltCollectionFilters_
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
edm::EDGetTokenT< pat::PackedCandidateCollection > pcToken_
Definition: DetId.h:18
bool isAValidMuonTrack(const MuonTrackType &type) const
void initSimInfo(void)
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:678
void setPfEcalEnergy(float pfEcalEnergy)
Definition: Muon.h:267
bool embedTunePBestTrack_
embed the track from best muon measurement (muon only)
T const * product() const
Definition: Handle.h:81
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
void setSimMotherPdgId(int id)
Definition: Muon.h:307
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
void addTriggerObjectMatch(const TriggerObjectStandAlone &trigObj)
add a trigger match
Definition: PATObject.h:204
void setExtSimType(reco::ExtendedMuonSimType type)
Definition: Muon.h:303
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:144
void setMiniPFIsolation(PFIsolation const &iso)
Definition: Lepton.h:197
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
edm::EDGetTokenT< reco::JetCorrector > mvaL1L2L3ResCorrector_
void fillMuon(Muon &aMuon, const MuonBaseRef &muonRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
common muon filling, for both the standard and PF2PAT case
ESHandle< TrackerGeometry > geometry
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:16
void setSimProdZ(float z)
Definition: Muon.h:310
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
pat::helper::EfficiencyLoader efficiencyLoader_
helper class to add efficiencies to the muon
HLT enums.
bool embedPickyMuon_
embed track from picky muon fit into the muon
void setNormChi2(double normChi2)
Definition: Muon.h:255
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
bool embedDytMuon_
embed track from DYT muon fit into the muon
void embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData &t)
PFIsolation getMiniPFIsolation(const pat::PackedCandidateCollection *pfcands, const math::XYZTLorentzVector &p4, float mindr=0.05, float maxdr=0.2, float kt_scale=10.0, float ptthresh=0.5, float deadcone_ch=0.0001, float deadcone_pu=0.01, float deadcone_ph=0.01, float deadcone_nh=0.01, float dZ_cut=0.0)
void setSimPdgId(int id)
Definition: Muon.h:306
T get() const
Definition: EventSetup.h:68
void setSimPt(float pt)
Definition: Muon.h:311
const GeomDet * idToDet(DetId) const override
float miniIsoDr(const math::XYZTLorentzVector &p4, float mindr, float maxdr, float kt_scale)
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
isolation value pair for temporary storage before being folded into the muon
edm::EDGetTokenT< std::vector< pat::TriggerObjectStandAlone > > triggerObjects_
bool embedGenMatch_
embed the gen match information into the muon
const Point & position() const
position
Definition: BeamSpot.h:62
static const int DT
Definition: MuonSubdetId.h:12
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels, std::vector< edm::EDGetTokenT< edm::ValueMap< T > > > &tokens)
IsolationLabels isoDepositLabels_
input source for isoDeposits
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
input tags for generator match information
Covariance3DMatrix rotatedCovariance3D() const
Definition: BeamSpot.cc:78
IsolationLabels isolationValueLabels_
input source isolation value maps
bool isValid() const
Definition: ESHandle.h:45
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
void embedPickyMuon()
embed reference to the above picky Track
bool forceEmbedBestTrack_
force separate embed of the best track even if already embedded
bool embedPFCandidate_
embed pfCandidates into the muon
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
void setNumberOfValidHits(unsigned int numberOfValidHits)
Definition: Muon.h:250
bool computeMuonMVA_
standard muon selectors
void setSimEta(float eta)
Definition: Muon.h:312
bool embedCombinedMuon_
embed track of the combined fit into the muon
Analysis-level muon class.
Definition: Muon.h:50
pat::helper::KinResolutionsLoader resolutionLoader_
helper class to add resolutions to the muon
static std::string const source
Definition: EdmProvDump.cc:44
void setP4(const LorentzVector &p4) final
set 4-momentum
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:301
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_neutral_hadrons_
def move(src, dest)
Definition: eostools.py:511
std::optional< GlobalPoint > getMuonDirection(const reco::MuonChamberMatch &chamberMatch, const edm::ESHandle< GlobalTrackingGeometry > &geometry, const DetId &chamberId)
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Analysis-level trigger object class (stand-alone)
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:82
bool embedHighLevelSelection_
embed high level selection variables