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  std::string mvaTrainingFile = iConfig.getParameter<std::string>("mvaTrainingFile");
65  // xml training file
66  edm::FileInPath fip(mvaTrainingFile);
67  float mvaDrMax = iConfig.getParameter<double>("mvaDrMax");
68  muonMvaEstimator_ = std::make_unique<MuonMvaEstimator>(fip.fullPath(), mvaDrMax);
69  }
70 
71  if (iConfig.getParameter<bool>("computeSoftMuonMVA")) {
72  std::string softMvaTrainingFile = iConfig.getParameter<std::string>("softMvaTrainingFile");
73  // xml soft mva training file
74  edm::FileInPath softfip(softMvaTrainingFile);
75  softMuonMvaEstimator_ = std::make_unique<SoftMuonMvaEstimator>(softfip.fullPath());
76  }
77 }
78 
80  relMiniIsoPUCorrected_(0),
81  useUserData_(iConfig.exists("userData")),
82  computeMuonMVA_(false),
83  computeSoftMuonMVA_(false),
84  recomputeBasicSelectors_(false),
85  mvaUseJec_(false),
86  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false)
87 {
88  // input source
89  muonToken_ = consumes<edm::View<reco::Muon> >(iConfig.getParameter<edm::InputTag>( "muonSource" ));
90  // embedding of tracks
91  embedBestTrack_ = iConfig.getParameter<bool>( "embedMuonBestTrack" );
92  embedTunePBestTrack_ = iConfig.getParameter<bool>( "embedTunePMuonBestTrack" );
93  forceEmbedBestTrack_ = iConfig.getParameter<bool>( "forceBestTrackEmbedding" );
94  embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
95  embedCombinedMuon_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
96  embedStandAloneMuon_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
97  // embedding of muon MET correction information
98  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs" );
99  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs" );
100  caloMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs" ));
101  tcMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs" ));
102  // pflow specific configurables
103  useParticleFlow_ = iConfig.getParameter<bool>( "useParticleFlow" );
104  embedPFCandidate_ = iConfig.getParameter<bool>( "embedPFCandidate" );
105  pfMuonToken_ = mayConsume<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>( "pfMuonSource" ));
106  embedPfEcalEnergy_ = iConfig.getParameter<bool>( "embedPfEcalEnergy" );
107  // embedding of tracks from TeV refit
108  embedPickyMuon_ = iConfig.getParameter<bool>( "embedPickyMuon" );
109  embedTpfmsMuon_ = iConfig.getParameter<bool>( "embedTpfmsMuon" );
110  embedDytMuon_ = iConfig.getParameter<bool>( "embedDytMuon" );
111  // Monte Carlo matching
112  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
113  if (addGenMatch_) {
114  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
115  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
116  genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection> >(iConfig.getParameter<edm::InputTag>( "genParticleMatch" )));
117  }
118  else {
119  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
120  }
121  }
122  // efficiencies
123  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
124  if(addEfficiencies_){
125  efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
126  }
127  // resolutions
128  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
129  if (addResolutions_) {
131  }
132  // puppi
133  addPuppiIsolation_ = iConfig.getParameter<bool>("addPuppiIsolation");
134  if(addPuppiIsolation_){
135  PUPPIIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
136  PUPPIIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
137  PUPPIIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
138  //puppiNoLeptons
139  PUPPINoLeptonsIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons"));
140  PUPPINoLeptonsIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons"));
141  PUPPINoLeptonsIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationPhotons"));
142  }
143  // read isoDeposit labels, for direct embedding
144  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
145  // read isolation value labels, for direct embedding
147  // check to see if the user wants to add user data
148  if( useUserData_ ){
149  userDataHelper_ = PATUserDataHelper<Muon>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
150  }
151  // embed high level selection variables
152  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
153  if ( embedHighLevelSelection_ ) {
154  beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"));
155  pvToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("pvSrc"));
156  }
157 
158  //for mini-isolation calculation
159  computeMiniIso_ = iConfig.getParameter<bool>("computeMiniIso");
160 
161  miniIsoParams_ = iConfig.getParameter<std::vector<double> >("miniIsoParams");
162  if(computeMiniIso_ && miniIsoParams_.size() != 9){
163  throw cms::Exception("ParameterError") << "miniIsoParams must have exactly 9 elements.\n";
164  }
165  if(computeMiniIso_)
166  pcToken_ = consumes<pat::PackedCandidateCollection >(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
167 
168  // standard selectors
169  recomputeBasicSelectors_ = iConfig.getParameter<bool>("recomputeBasicSelectors");
170  computeMuonMVA_ = iConfig.getParameter<bool>("computeMuonMVA");
171  if (computeMuonMVA_ and not computeMiniIso_)
172  throw cms::Exception("ConfigurationError") << "MiniIso is needed for Muon MVA calculation.\n";
173 
174  if (computeMuonMVA_) {
175  // pfCombinedInclusiveSecondaryVertexV2BJetTags
176  mvaBTagCollectionTag_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("mvaJetTag"));
177  mvaL1Corrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1Corrector"));
178  mvaL1L2L3ResCorrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1L2L3ResCorrector"));
179  rho_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
180  mvaUseJec_ = iConfig.getParameter<bool>("mvaUseJec");
181  }
182 
183  computeSoftMuonMVA_ = iConfig.getParameter<bool>("computeSoftMuonMVA");
184 
185  // MC info
186  simInfo_ = consumes<edm::ValueMap<reco::MuonSimInfo> >(iConfig.getParameter<edm::InputTag>("muonSimInfo"));
187 
188  addTriggerMatching_ = iConfig.getParameter<bool>("addTriggerMatching");
189  if ( addTriggerMatching_ ){
190  triggerObjects_ = consumes<std::vector<pat::TriggerObjectStandAlone>>(iConfig.getParameter<edm::InputTag>("triggerObjects"));
191  triggerResults_ = consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("triggerResults"));
192  }
193  hltCollectionFilters_ = iConfig.getParameter<std::vector<std::string>>("hltCollectionFilters");
194 
195  // produces vector of muons
196  produces<std::vector<Muon> >();
197 }
198 
199 
201 {
202 }
203 
204 std::unique_ptr<GlobalPoint> PATMuonProducer::getMuonDirection(const reco::MuonChamberMatch& chamberMatch,
206  const DetId& chamberId)
207 {
208  const GeomDet* chamberGeometry = geometry->idToDet( chamberId );
209  if (chamberGeometry){
210  LocalPoint localPosition(chamberMatch.x, chamberMatch.y, 0);
211  return std::unique_ptr<GlobalPoint>(new GlobalPoint(chamberGeometry->toGlobal(localPosition)));
212  }
213  return std::unique_ptr<GlobalPoint>();
214 
215 }
216 
217 
219  edm::Handle<std::vector<pat::TriggerObjectStandAlone> >& triggerObjects,
220  const edm::TriggerNames & names,
222 {
223  // L1 trigger object parameters are defined at MB2/ME2. Use the muon
224  // chamber matching information to get the local direction of the
225  // muon trajectory and convert it to a global direction to match the
226  // trigger objects
227 
228  std::unique_ptr<GlobalPoint> muonPosition;
229  // Loop over chambers
230  // initialize muonPosition with any available match, just in case
231  // the second station is missing - it's better folling back to
232  // dR matching at IP
233  for ( const auto& chamberMatch: aMuon.matches() ) {
234  if ( chamberMatch.id.subdetId() == MuonSubdetId::DT) {
235  DTChamberId detId(chamberMatch.id.rawId());
236  if (abs(detId.station())>3) continue;
237  muonPosition = std::move(getMuonDirection(chamberMatch, geometry, detId));
238  if (abs(detId.station())==2) break;
239  }
240  if ( chamberMatch.id.subdetId() == MuonSubdetId::CSC) {
241  CSCDetId detId(chamberMatch.id.rawId());
242  if (abs(detId.station())>3) continue;
243  muonPosition = std::move(getMuonDirection(chamberMatch, geometry, detId));
244  if (abs(detId.station())==2) break;
245  }
246  }
247  if (not muonPosition) return;
248  for (const auto& triggerObject: *triggerObjects){
249  if (triggerObject.hasTriggerObjectType(trigger::TriggerL1Mu)){
250  if (fabs(triggerObject.eta())<0.001){
251  // L1 is defined in X-Y plain
252  if (deltaPhi(triggerObject.phi(),muonPosition->phi())>0.1) continue;
253  } else {
254  // 3D L1
255  if (deltaR(triggerObject.p4(),*muonPosition)>0.15) continue;
256  }
257  pat::TriggerObjectStandAlone obj(triggerObject);
258  obj.unpackPathNames(names);
259  aMuon.addTriggerObjectMatch(obj);
260  }
261  }
262 }
263 
265  edm::Handle<std::vector<pat::TriggerObjectStandAlone> >& triggerObjects,
266  const edm::TriggerNames & names,
267  const std::vector<std::string>& collection_filter_names)
268 {
269  // WARNING: in a case of close-by muons the dR matching may select both muons.
270  // It's better to select the best match for a given collection.
271  for (const auto& triggerObject: *triggerObjects){
272  if (triggerObject.hasTriggerObjectType(trigger::TriggerMuon)){
273  bool keepIt = false;
274  for (const auto& name: collection_filter_names){
275  if (triggerObject.hasCollection(name)){
276  keepIt = true;
277  break;
278  }
279  }
280  if (not keepIt) continue;
281  if ( deltaR(triggerObject.p4(),muon)>0.1 ) continue;
282  pat::TriggerObjectStandAlone obj(triggerObject);
283  obj.unpackPathNames(names);
284  muon.addTriggerObjectMatch(obj);
285  }
286  }
287 }
288 
289 
291 {
292  // get the tracking Geometry
294  iSetup.get<GlobalTrackingGeometryRecord>().get(geometry);
295  if ( ! geometry.isValid() )
296  throw cms::Exception("FatalError") << "Unable to find GlobalTrackingGeometryRecord in event!\n";
297 
298  // switch off embedding (in unschedules mode)
299  if (iEvent.isRealData()){
300  addGenMatch_ = false;
301  embedGenMatch_ = false;
302  }
303 
305  iEvent.getByToken(muonToken_, muons);
306 
307 
309  if(computeMiniIso_)
310  iEvent.getByToken(pcToken_, pc);
311 
312  // get the ESHandle for the transient track builder,
313  // if needed for high level selection embedding
315 
316  if(isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
318  if(resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
319 
321  for (size_t j = 0; j<isoDepositTokens_.size(); ++j) {
322  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
323  }
324 
326  for (size_t j = 0; j<isolationValueTokens_.size(); ++j) {
328  }
329 
330  //value maps for puppi isolation
331  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
332  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
333  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
334  //value maps for puppiNoLeptons isolation
335  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons;
336  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons;
337  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons;
338  if(addPuppiIsolation_){
339  //puppi
340  iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
341  iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
342  iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
343  //puppiNoLeptons
344  iEvent.getByToken(PUPPINoLeptonsIsolation_charged_hadrons_, PUPPINoLeptonsIsolation_charged_hadrons);
345  iEvent.getByToken(PUPPINoLeptonsIsolation_neutral_hadrons_, PUPPINoLeptonsIsolation_neutral_hadrons);
346  iEvent.getByToken(PUPPINoLeptonsIsolation_photons_, PUPPINoLeptonsIsolation_photons);
347  }
348 
349  // inputs for muon mva
350  edm::Handle<reco::JetTagCollection> mvaBTagCollectionTag;
353  if (computeMuonMVA_) {
354  iEvent.getByToken(mvaBTagCollectionTag_,mvaBTagCollectionTag);
355  iEvent.getByToken(mvaL1Corrector_,mvaL1Corrector);
356  iEvent.getByToken(mvaL1L2L3ResCorrector_,mvaL1L2L3ResCorrector);
357  }
358 
359  // prepare the MC genMatchTokens_
360  GenAssociations genMatches(genMatchTokens_.size());
361  if (addGenMatch_) {
362  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
363  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
364  }
365  }
366 
367  // prepare the high level selection: needs beamline
368  // OR primary vertex, depending on user selection
371  bool beamSpotIsValid = false;
372  bool primaryVertexIsValid = false;
373  if ( embedHighLevelSelection_ ) {
374  // get the beamspot
375  edm::Handle<reco::BeamSpot> beamSpotHandle;
376  iEvent.getByToken(beamLineToken_, beamSpotHandle);
377 
378  // get the primary vertex
380  iEvent.getByToken( pvToken_, pvHandle );
381 
382  if( beamSpotHandle.isValid() ){
383  beamSpot = *beamSpotHandle;
384  beamSpotIsValid = true;
385  } else{
386  edm::LogError("DataNotAvailable")
387  << "No beam spot available from EventSetup, not adding high level selection \n";
388  }
389  if( pvHandle.isValid() && !pvHandle->empty() ) {
390  primaryVertex = pvHandle->at(0);
391  primaryVertexIsValid = true;
392  } else {
393  edm::LogError("DataNotAvailable")
394  << "No primary vertex available from EventSetup, not adding high level selection \n";
395  }
396  // this is needed by the IPTools methods from the tracking group
397  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
398  }
399 
400  // MC info
402  bool simInfoIsAvailalbe = iEvent.getByToken(simInfo_,simInfo);
403 
404  // this will be the new object collection
405  std::vector<Muon> * patMuons = new std::vector<Muon>();
406 
408  if( useParticleFlow_ ){
409  // get the PFCandidates of type muons
410  iEvent.getByToken(pfMuonToken_, pfMuons);
411 
412  unsigned index=0;
413  for( reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
414  const reco::PFCandidate& pfmu = *i;
415  //const reco::IsolaPFCandidate& pfmu = *i;
416  const reco::MuonRef& muonRef = pfmu.muonRef();
417  assert( muonRef.isNonnull() );
418 
419  MuonBaseRef muonBaseRef(muonRef);
420  Muon aMuon(muonBaseRef);
421 
422  if ( useUserData_ ) {
423  userDataHelper_.add( aMuon, iEvent, iSetup );
424  }
425 
426  // embed high level selection
427  if ( embedHighLevelSelection_ ) {
428  // get the tracks
429  reco::TrackRef innerTrack = muonBaseRef->innerTrack();
430  reco::TrackRef globalTrack= muonBaseRef->globalTrack();
431  reco::TrackRef bestTrack = muonBaseRef->muonBestTrack();
432  reco::TrackRef chosenTrack = innerTrack;
433  // Make sure the collection it points to is there
434  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
435  chosenTrack = bestTrack;
436 
437  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
438  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
439  aMuon.setNumberOfValidHits( nhits );
440 
441  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
442  embedHighLevel( aMuon,
443  chosenTrack,
444  tt,
445  primaryVertex,
446  primaryVertexIsValid,
447  beamSpot,
448  beamSpotIsValid );
449 
450  }
451 
452  if ( globalTrack.isNonnull() && globalTrack.isAvailable() && !embedCombinedMuon_) {
453  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
454  aMuon.setNormChi2( norm_chi2 );
455  }
456  }
457  reco::PFCandidateRef pfRef(pfMuons,index);
458  //reco::PFCandidatePtr ptrToMother(pfMuons,index);
459  reco::CandidateBaseRef pfBaseRef( pfRef );
460 
461  aMuon.setPFCandidateRef( pfRef );
462  if( embedPFCandidate_ ) aMuon.embedPFCandidate();
463  fillMuon( aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues );
464 
465  if(computeMiniIso_)
466  setMuonMiniIso(aMuon, pc.product());
467 
468  if (addPuppiIsolation_) {
469  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonBaseRef],
470  (*PUPPIIsolation_neutral_hadrons)[muonBaseRef],
471  (*PUPPIIsolation_photons)[muonBaseRef]);
472 
473  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonBaseRef],
474  (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonBaseRef],
475  (*PUPPINoLeptonsIsolation_photons)[muonBaseRef]);
476  }
477  else {
478  aMuon.setIsolationPUPPI(-999., -999.,-999.);
479  aMuon.setIsolationPUPPINoLeptons(-999., -999.,-999.);
480  }
481 
482  if (embedPfEcalEnergy_) {
483  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
484  }
485 
486  patMuons->push_back(aMuon);
487  }
488  }
489  else {
491  iEvent.getByToken(muonToken_, muons);
492 
493  // embedding of muon MET corrections
495  //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
497  iEvent.getByToken(caloMETMuonCorrsToken_, caloMETMuonCorrs);
498  //caloMETmuCorValueMap = *caloMETmuCorValueMap_h;
499  }
501  //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
503  iEvent.getByToken(tcMETMuonCorrsToken_, tcMETMuonCorrs);
504  //tcMETmuCorValueMap = *tcMETmuCorValueMap_h;
505  }
506 
507  if (embedPfEcalEnergy_) {
508  // get the PFCandidates of type muons
509  iEvent.getByToken(pfMuonToken_, pfMuons);
510  }
511 
512  for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
513  // construct the Muon from the ref -> save ref to original object
514  unsigned int idx = itMuon - muons->begin();
515  MuonBaseRef muonRef = muons->refAt(idx);
516  reco::CandidateBaseRef muonBaseRef( muonRef );
517 
518  Muon aMuon(muonRef);
519  fillMuon( aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);
520  if(computeMiniIso_)
521  setMuonMiniIso(aMuon, pc.product());
522  if (addPuppiIsolation_) {
523  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonRef], (*PUPPIIsolation_neutral_hadrons)[muonRef], (*PUPPIIsolation_photons)[muonRef]);
524  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_photons)[muonRef]);
525  }
526  else {
527  aMuon.setIsolationPUPPI(-999., -999.,-999.);
528  aMuon.setIsolationPUPPINoLeptons(-999., -999.,-999.);
529  }
530 
531  // Isolation
532  if (isolator_.enabled()) {
533  //reco::CandidatePtr mother = ptrToMother->sourceCandidatePtr(0);
534  isolator_.fill(*muons, idx, isolatorTmpStorage_);
535  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
536  // better to loop backwards, so the vector is resized less times
537  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
538  aMuon.setIsolation(it->first, it->second);
539  }
540  }
541 
542  // for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
543  // aMuon.setIsoDeposit(isoDepositLabels_[j].first,
544  // (*deposits[j])[muonRef]);
545  // }
546 
547  // add sel to selected
548  edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
549  if ( useUserData_ ) {
550  userDataHelper_.add( aMuon, iEvent, iSetup );
551  }
552 
553  // embed high level selection
554  if ( embedHighLevelSelection_ ) {
555  // get the tracks
556  reco::TrackRef innerTrack = itMuon->innerTrack();
557  reco::TrackRef globalTrack= itMuon->globalTrack();
558  reco::TrackRef bestTrack = itMuon->muonBestTrack();
559  reco::TrackRef chosenTrack = innerTrack;
560  // Make sure the collection it points to is there
561  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
562  chosenTrack = bestTrack;
563  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
564  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
565  aMuon.setNumberOfValidHits( nhits );
566 
567  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
568  embedHighLevel( aMuon,
569  chosenTrack,
570  tt,
571  primaryVertex,
572  primaryVertexIsValid,
573  beamSpot,
574  beamSpotIsValid );
575 
576  }
577 
578  if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
579  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
580  aMuon.setNormChi2( norm_chi2 );
581  }
582  }
583 
584  // embed MET muon corrections
585  if( embedCaloMETMuonCorrs_ ) aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
586  if( embedTcMETMuonCorrs_ ) aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs )[muonRef]);
587 
588  if (embedPfEcalEnergy_) {
589  aMuon.setPfEcalEnergy(-99.0);
590  for (const reco::PFCandidate &pfmu : *pfMuons) {
591  if (pfmu.muonRef().isNonnull()) {
592  if (pfmu.muonRef().id() != muonRef.id()) throw cms::Exception("Configuration") << "Muon reference within PF candidates does not point to the muon collection." << std::endl;
593  if (pfmu.muonRef().key() == muonRef.key()) {
594  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
595  }
596  }
597  }
598  }
599  // MC info
600  aMuon.initSimInfo();
601  if (simInfoIsAvailalbe){
602  const auto& msi = (*simInfo)[muonBaseRef];
603  aMuon.setSimType(msi.primaryClass);
604  aMuon.setExtSimType(msi.extendedClass);
605  aMuon.setSimFlavour(msi.flavour);
606  aMuon.setSimHeaviestMotherFlavour(msi.heaviestMotherFlavour);
607  aMuon.setSimPdgId(msi.pdgId);
608  aMuon.setSimMotherPdgId(msi.motherPdgId);
609  aMuon.setSimBX(msi.tpBX);
610  aMuon.setSimProdRho(msi.vertex.Rho());
611  aMuon.setSimProdZ(msi.vertex.Z());
612  aMuon.setSimPt(msi.p4.pt());
613  aMuon.setSimEta(msi.p4.eta());
614  aMuon.setSimPhi(msi.p4.phi());
615  }
616  patMuons->push_back(aMuon);
617  }
618  }
619 
620  // sort muons in pt
621  std::sort(patMuons->begin(), patMuons->end(), pTComparator_);
622 
623  // Store standard muon selection decisions and jet related
624  // quantaties.
625  // Need a separate loop over muons to have all inputs properly
626  // computed and stored in the object.
628  if (computeMuonMVA_) iEvent.getByToken(rho_,rho);
629  const reco::Vertex* pv(nullptr);
630  if (primaryVertexIsValid) pv = &primaryVertex;
631 
634  bool triggerObjectsAvailable = false;
635  bool triggerResultsAvailable = false;
636  if (addTriggerMatching_){
637  triggerObjectsAvailable = iEvent.getByToken(triggerObjects_, triggerObjects);
638  triggerResultsAvailable = iEvent.getByToken(triggerResults_, triggerResults);
639  }
640 
641  for(auto& muon: *patMuons){
642  // trigger info
643  if (addTriggerMatching_ and triggerObjectsAvailable and triggerResultsAvailable){
644  const edm::TriggerNames & triggerNames(iEvent.triggerNames( *triggerResults ));
645  fillL1TriggerInfo(muon,triggerObjects,triggerNames,geometry);
646  fillHltTriggerInfo(muon,triggerObjects,triggerNames,hltCollectionFilters_);
647  }
648 
650  muon.setSelectors(0);
651  bool isRun2016BCDEF = (272728 <= iEvent.run() && iEvent.run() <= 278808);
652  muon::setCutBasedSelectorFlags(muon, pv, isRun2016BCDEF);
653  }
654  double miniIsoValue = -1;
655  if (computeMiniIso_){
656  // MiniIsolation working points
657  double miniIsoValue = getRelMiniIsoPUCorrected(muon,*rho);
658  muon.setSelector(reco::Muon::MiniIsoLoose, miniIsoValue<0.40);
659  muon.setSelector(reco::Muon::MiniIsoMedium, miniIsoValue<0.20);
660  muon.setSelector(reco::Muon::MiniIsoTight, miniIsoValue<0.10);
661  muon.setSelector(reco::Muon::MiniIsoVeryTight, miniIsoValue<0.05);
662  }
663  float jetPtRatio = 0.0;
664  float jetPtRel = 0.0;
665  float mva = 0.0;
666  if (computeMuonMVA_ && primaryVertexIsValid){
667  if (mvaUseJec_)
668  mva = globalCache()->muonMvaEstimator()->computeMva(muon,
669  primaryVertex,
670  *(mvaBTagCollectionTag.product()),
671  jetPtRatio,
672  jetPtRel,
673  &*mvaL1Corrector,
674  &*mvaL1L2L3ResCorrector);
675  else
676  mva = globalCache()->muonMvaEstimator()->computeMva(muon,
677  primaryVertex,
678  *(mvaBTagCollectionTag.product()),
679  jetPtRatio,
680  jetPtRel);
681 
682  muon.setMvaValue(mva);
683  muon.setJetPtRatio(jetPtRatio);
684  muon.setJetPtRel(jetPtRel);
685 
686  // multi-isolation
687  if (computeMiniIso_){
688  muon.setSelector(reco::Muon::MultiIsoLoose, miniIsoValue<0.40 && (muon.jetPtRatio() > 0.80 || muon.jetPtRel() > 7.2) );
689  muon.setSelector(reco::Muon::MultiIsoMedium, miniIsoValue<0.16 && (muon.jetPtRatio() > 0.76 || muon.jetPtRel() > 7.2) );
690  }
691 
692  // MVA working points
693  // https://twiki.cern.ch/twiki/bin/viewauth/CMS/LeptonMVA
694  double dB2D = fabs(muon.dB(pat::Muon::BS2D));
695  double dB3D = fabs(muon.dB(pat::Muon::PV3D));
696  double edB3D = fabs(muon.edB(pat::Muon::PV3D));
697  double sip3D = edB3D>0?dB3D/edB3D:0.0;
698  double dz = fabs(muon.muonBestTrack()->dz(primaryVertex.position()));
699 
700  // muon preselection
701  if (muon.pt()>5 and muon.isLooseMuon() and
702  muon.passed(reco::Muon::MiniIsoLoose) and
703  sip3D<8.0 and dB2D<0.05 and dz<0.1){
704  muon.setSelector(reco::Muon::MvaLoose, muon.mvaValue()>-0.60);
705  muon.setSelector(reco::Muon::MvaMedium, muon.mvaValue()>-0.20);
706  muon.setSelector(reco::Muon::MvaTight, muon.mvaValue()> 0.15);
707  }
708  }
709 
710  //SOFT MVA
711  if (computeSoftMuonMVA_){
712  float mva = globalCache()->softMuonMvaEstimator()->computeMva(muon);
713  muon.setSoftMvaValue(mva);
714  //preselection in SoftMuonMvaEstimator.cc
715  muon.setSelector(reco::Muon::SoftMvaId, muon.softMvaValue() > 0.58 ); //WP choose for bmm4
716 
717  }
718  }
719 
720  // put products in Event
721  std::unique_ptr<std::vector<Muon> > ptr(patMuons);
722  iEvent.put(std::move(ptr));
723 
725 }
726 
727 
728 void PATMuonProducer::fillMuon( Muon& aMuon, const MuonBaseRef& muonRef, const reco::CandidateBaseRef& baseRef, const GenAssociations& genMatches, const IsoDepositMaps& deposits, const IsolationValueMaps& isolationValues ) const
729 {
730  // in the particle flow algorithm,
731  // the muon momentum is recomputed.
732  // the new value is stored as the momentum of the
733  // resulting PFCandidate of type Muon, and choosen
734  // as the pat::Muon momentum
735  if (useParticleFlow_)
736  aMuon.setP4( aMuon.pfCandidateRef()->p4() );
737  if (embedTrack_) aMuon.embedTrack();
740 
741  // embed the TeV refit track refs (only available for globalMuons)
742  if (aMuon.isGlobalMuon()) {
744  aMuon.embedPickyMuon();
746  aMuon.embedTpfmsMuon();
748  aMuon.embedDytMuon();
749  }
750 
751  // embed best tracks (at the end, so unless forceEmbedBestTrack_ is true we can save some space not embedding them twice)
754 
755  // store the match to the generated final state muons
756  if (addGenMatch_) {
757  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
758  reco::GenParticleRef genMuon = (*genMatches[i])[baseRef];
759  aMuon.addGenParticleRef(genMuon);
760  }
761  if (embedGenMatch_) aMuon.embedGenParticle();
762  }
763  if (efficiencyLoader_.enabled()) {
764  efficiencyLoader_.setEfficiencies( aMuon, muonRef );
765  }
766 
767  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
768  if(useParticleFlow_) {
769  if (deposits[j]->contains(baseRef.id())) {
770  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
771  } else if (deposits[j]->contains(muonRef.id())){
772  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
773  } else {
774  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
775  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
776  }
777  }
778  else{
779  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
780  }
781  }
782 
783  for (size_t j = 0; j<isolationValues.size(); ++j) {
784  if(useParticleFlow_) {
785  if (isolationValues[j]->contains(baseRef.id())) {
786  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
787  } else if (isolationValues[j]->contains(muonRef.id())) {
788  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
789  } else {
790  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
791  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
792  }
793  }
794  else{
795  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
796  }
797  }
798 
799  if (resolutionLoader_.enabled()) {
801  }
802 }
803 
805 {
806  pat::PFIsolation miniiso = pat::getMiniPFIsolation(pc, aMuon.p4(),
807  miniIsoParams_[0], miniIsoParams_[1], miniIsoParams_[2],
808  miniIsoParams_[3], miniIsoParams_[4], miniIsoParams_[5],
809  miniIsoParams_[6], miniIsoParams_[7], miniIsoParams_[8]);
810  aMuon.setMiniPFIsolation(miniiso);
811 }
812 
814 {
815  float mindr(miniIsoParams_[0]);
816  float maxdr(miniIsoParams_[1]);
817  float kt_scale(miniIsoParams_[2]);
818  float drcut = pat::miniIsoDr(muon.p4(),mindr,maxdr,kt_scale);
819  return pat::muonRelMiniIsoPUCorrected(muon.miniPFIsolation(), muon.p4(), drcut, rho);
820 }
821 
822 // ParameterSet description for module
824 {
826  iDesc.setComment("PAT muon producer module");
827 
828  // input source
829  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("no default"))->setComment("input collection");
830 
831  // embedding
832  iDesc.add<bool>("embedMuonBestTrack", true)->setComment("embed muon best track (global pflow)");
833  iDesc.add<bool>("embedTunePMuonBestTrack", true)->setComment("embed muon best track (muon only)");
834  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");
835  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
836  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
837  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
838  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky track");
839  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms track");
840  iDesc.add<bool>("embedDytMuon", false)->setComment("embed external dyt track ");
841 
842  // embedding of MET muon corrections
843  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
844  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for caloMET");
845  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
846  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for tcMET");
847 
848  // pf specific parameters
849  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->setComment("particle flow input collection");
850  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
851  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
852  iDesc.add<bool>("embedPfEcalEnergy", true)->setComment("add ecal energy as reconstructed by PF");
853 
854  // MC matching configurables
855  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
856  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
857  std::vector<edm::InputTag> emptySourceVector;
858  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
859  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
860  )->setComment("input with MC match information");
861 
862  // mini-iso
863  iDesc.add<bool>("computeMiniIso", false)->setComment("whether or not to compute and store electron mini-isolation");
864  iDesc.add<edm::InputTag>("pfCandsForMiniIso", edm::InputTag("packedPFCandidates"))->setComment("collection to use to compute mini-iso");
865  iDesc.add<std::vector<double> >("miniIsoParams", std::vector<double>())->setComment("mini-iso parameters to use for muons");
866 
867  iDesc.add<bool>("addTriggerMatching", false)->setComment("add L1 and HLT matching to offline muon");
868 
870 
871  // IsoDeposit configurables
872  edm::ParameterSetDescription isoDepositsPSet;
873  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
874  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
875  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
876  isoDepositsPSet.addOptional<edm::InputTag>("particle");
877  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
878  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
879  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
880  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
881  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
882  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
883  iDesc.addOptional("isoDeposits", isoDepositsPSet);
884 
885  // isolation values configurables
886  edm::ParameterSetDescription isolationValuesPSet;
887  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
888  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
889  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
890  isolationValuesPSet.addOptional<edm::InputTag>("particle");
891  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
892  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
893  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
894  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
895  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
896  iDesc.addOptional("isolationValues", isolationValuesPSet);
897 
898  iDesc.ifValue(edm::ParameterDescription<bool>("addPuppiIsolation", false, true),
899  true >> (edm::ParameterDescription<edm::InputTag>("puppiIsolationChargedHadrons", edm::InputTag("muonPUPPIIsolation","h+-DR030-ThresholdVeto000-ConeVeto000"), true) and
900  edm::ParameterDescription<edm::InputTag>("puppiIsolationNeutralHadrons", edm::InputTag("muonPUPPIIsolation","h0-DR030-ThresholdVeto000-ConeVeto001"), true) and
901  edm::ParameterDescription<edm::InputTag>("puppiIsolationPhotons", edm::InputTag("muonPUPPIIsolation","gamma-DR030-ThresholdVeto000-ConeVeto001"), true) and
902  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons", edm::InputTag("muonPUPPINoLeptonsIsolation","h+-DR030-ThresholdVeto000-ConeVeto000"), true) and
903  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons", edm::InputTag("muonPUPPINoLeptonsIsolation","h0-DR030-ThresholdVeto000-ConeVeto001"), true) and
904  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationPhotons", edm::InputTag("muonPUPPINoLeptonsIsolation","gamma-DR030-ThresholdVeto000-ConeVeto001"), true)) or
905  false >> edm::EmptyGroupDescription());
906 
907  // Efficiency configurables
908  edm::ParameterSetDescription efficienciesPSet;
909  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
910  iDesc.add("efficiencies", efficienciesPSet);
911  iDesc.add<bool>("addEfficiencies", false);
912 
913  // Check to see if the user wants to add user data
914  edm::ParameterSetDescription userDataPSet;
916  iDesc.addOptional("userData", userDataPSet);
917 
918  edm::ParameterSetDescription isolationPSet;
919  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
920  iDesc.add("userIsolation", isolationPSet);
921 
922  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
923  edm::ParameterSetDescription highLevelPSet;
924  highLevelPSet.setAllowAnything();
925  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
926  )->setComment("input with high level selection");
928  )->setComment("input with high level selection");
929 
930  //descriptions.add("PATMuonProducer", iDesc);
931 }
932 
933 
934 
935 // embed various impact parameters with errors
936 // embed high level selection
941  bool primaryVertexIsValid,
943  bool beamspotIsValid
944  )
945 {
946  // Correct to PV
947 
948  // PV2D
949  std::pair<bool,Measurement1D> result =
951  GlobalVector(track->px(),
952  track->py(),
953  track->pz()),
954  primaryVertex);
955  double d0_corr = result.second.value();
956  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
957  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV2D);
958 
959 
960  // PV3D
961  result =
963  GlobalVector(track->px(),
964  track->py(),
965  track->pz()),
966  primaryVertex);
967  d0_corr = result.second.value();
968  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
969  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV3D);
970 
971 
972  // Correct to beam spot
973  // make a fake vertex out of beam spot
974  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
975 
976  // BS2D
977  result =
979  GlobalVector(track->px(),
980  track->py(),
981  track->pz()),
982  vBeamspot);
983  d0_corr = result.second.value();
984  d0_err = beamspotIsValid ? result.second.error() : -1.0;
985  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS2D);
986 
987  // BS3D
988  result =
990  GlobalVector(track->px(),
991  track->py(),
992  track->pz()),
993  vBeamspot);
994  d0_corr = result.second.value();
995  d0_err = beamspotIsValid ? result.second.error() : -1.0;
996  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS3D);
997 
998 
999  // PVDZ
1000  aMuon.setDB( track->dz(primaryVertex.position()), std::hypot(track->dzError(), primaryVertex.zError()), pat::Muon::PVDZ );
1001 }
1002 
1004 
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:186
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
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
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:6
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:41
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:63
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:47
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
std::unique_ptr< GlobalPoint > getMuonDirection(const reco::MuonChamberMatch &chamberMatch, const edm::ESHandle< GlobalTrackingGeometry > &geometry, const DetId &chamberId)
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:43
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:510
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