CMS 3D CMS Logo

PATMuonProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
5 
9 
12 
14 
18 
21 
23 
26 
30 
35 
36 #include "TMath.h"
37 
39 
41 
42 #include <vector>
43 #include <memory>
44 
45 
46 using namespace pat;
47 using namespace std;
48 
49 
50 PATMuonProducer::PATMuonProducer(const edm::ParameterSet & iConfig) : useUserData_(iConfig.exists("userData")),
51  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false)
52 {
53  // input source
54  muonToken_ = consumes<edm::View<reco::Muon> >(iConfig.getParameter<edm::InputTag>( "muonSource" ));
55  // embedding of tracks
56  embedBestTrack_ = iConfig.getParameter<bool>( "embedMuonBestTrack" );
57  embedTunePBestTrack_ = iConfig.getParameter<bool>( "embedTunePMuonBestTrack" );
58  forceEmbedBestTrack_ = iConfig.getParameter<bool>( "forceBestTrackEmbedding" );
59  embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
60  embedCombinedMuon_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
61  embedStandAloneMuon_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
62  // embedding of muon MET correction information
63  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs" );
64  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs" );
65  caloMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs" ));
66  tcMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs" ));
67  // pflow specific configurables
68  useParticleFlow_ = iConfig.getParameter<bool>( "useParticleFlow" );
69  embedPFCandidate_ = iConfig.getParameter<bool>( "embedPFCandidate" );
70  pfMuonToken_ = mayConsume<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>( "pfMuonSource" ));
71  embedPfEcalEnergy_ = iConfig.getParameter<bool>( "embedPfEcalEnergy" );
72  // embedding of tracks from TeV refit
73  embedPickyMuon_ = iConfig.getParameter<bool>( "embedPickyMuon" );
74  embedTpfmsMuon_ = iConfig.getParameter<bool>( "embedTpfmsMuon" );
75  embedDytMuon_ = iConfig.getParameter<bool>( "embedDytMuon" );
76  // Monte Carlo matching
77  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
78  if (addGenMatch_) {
79  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
80  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
82  }
83  else {
84  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
85  }
86  }
87  // efficiencies
88  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
89  if(addEfficiencies_){
91  }
92  // resolutions
93  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
94  if (addResolutions_) {
96  }
97  // puppi
98  addPuppiIsolation_ = iConfig.getParameter<bool>("addPuppiIsolation");
100  PUPPIIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
101  PUPPIIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
102  PUPPIIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
103  //puppiNoLeptons
104  PUPPINoLeptonsIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons"));
105  PUPPINoLeptonsIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons"));
106  PUPPINoLeptonsIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationPhotons"));
107  }
108  // read isoDeposit labels, for direct embedding
109  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
110  // read isolation value labels, for direct embedding
112  // check to see if the user wants to add user data
113  if( useUserData_ ){
115  }
116  // embed high level selection variables
117  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
118  if ( embedHighLevelSelection_ ) {
119  beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"));
120  pvToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("pvSrc"));
121  }
122 
123  //for mini-isolation calculation
124  computeMiniIso_ = iConfig.getParameter<bool>("computeMiniIso");
125  miniIsoParams_ = iConfig.getParameter<std::vector<double> >("miniIsoParams");
126  if(computeMiniIso_ && miniIsoParams_.size() != 9){
127  throw cms::Exception("ParameterError") << "miniIsoParams must have exactly 9 elements.\n";
128  }
129  if(computeMiniIso_)
130  pcToken_ = consumes<pat::PackedCandidateCollection >(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
131 
132  // produces vector of muons
133  produces<std::vector<Muon> >();
134 }
135 
136 
138 {
139 }
140 
142 {
143  // switch off embedding (in unschedules mode)
144  if (iEvent.isRealData()){
145  addGenMatch_ = false;
146  embedGenMatch_ = false;
147  }
148 
150  iEvent.getByToken(muonToken_, muons);
151 
152 
154  if(computeMiniIso_)
155  iEvent.getByToken(pcToken_, pc);
156 
157  // get the ESHandle for the transient track builder,
158  // if needed for high level selection embedding
160 
161  if(isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
163  if(resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
164 
166  for (size_t j = 0; j<isoDepositTokens_.size(); ++j) {
167  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
168  }
169 
171  for (size_t j = 0; j<isolationValueTokens_.size(); ++j) {
173  }
174 
175  //value maps for puppi isolation
176  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
177  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
178  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
179  //value maps for puppiNoLeptons isolation
180  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons;
181  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons;
182  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons;
183  if(addPuppiIsolation_){
184  //puppi
185  iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
186  iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
187  iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
188  //puppiNoLeptons
189  iEvent.getByToken(PUPPINoLeptonsIsolation_charged_hadrons_, PUPPINoLeptonsIsolation_charged_hadrons);
190  iEvent.getByToken(PUPPINoLeptonsIsolation_neutral_hadrons_, PUPPINoLeptonsIsolation_neutral_hadrons);
191  iEvent.getByToken(PUPPINoLeptonsIsolation_photons_, PUPPINoLeptonsIsolation_photons);
192  }
193 
194  // prepare the MC genMatchTokens_
195  GenAssociations genMatches(genMatchTokens_.size());
196  if (addGenMatch_) {
197  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
198  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
199  }
200  }
201 
202  // prepare the high level selection: needs beamline
203  // OR primary vertex, depending on user selection
206  bool beamSpotIsValid = false;
207  bool primaryVertexIsValid = false;
208  if ( embedHighLevelSelection_ ) {
209  // get the beamspot
210  edm::Handle<reco::BeamSpot> beamSpotHandle;
211  iEvent.getByToken(beamLineToken_, beamSpotHandle);
212 
213  // get the primary vertex
215  iEvent.getByToken( pvToken_, pvHandle );
216 
217  if( beamSpotHandle.isValid() ){
218  beamSpot = *beamSpotHandle;
219  beamSpotIsValid = true;
220  } else{
221  edm::LogError("DataNotAvailable")
222  << "No beam spot available from EventSetup, not adding high level selection \n";
223  }
224  if( pvHandle.isValid() && !pvHandle->empty() ) {
225  primaryVertex = pvHandle->at(0);
226  primaryVertexIsValid = true;
227  } else {
228  edm::LogError("DataNotAvailable")
229  << "No primary vertex available from EventSetup, not adding high level selection \n";
230  }
231  // this is needed by the IPTools methods from the tracking group
232  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
233  }
234 
235  // this will be the new object collection
236  std::vector<Muon> * patMuons = new std::vector<Muon>();
237 
239  if( useParticleFlow_ ){
240  // get the PFCandidates of type muons
241  iEvent.getByToken(pfMuonToken_, pfMuons);
242 
243  unsigned index=0;
244  for( reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
245  const reco::PFCandidate& pfmu = *i;
246  //const reco::IsolaPFCandidate& pfmu = *i;
247  const reco::MuonRef& muonRef = pfmu.muonRef();
248  assert( muonRef.isNonnull() );
249 
250  MuonBaseRef muonBaseRef(muonRef);
251  Muon aMuon(muonBaseRef);
252 
253  if ( useUserData_ ) {
254  userDataHelper_.add( aMuon, iEvent, iSetup );
255  }
256 
257  // embed high level selection
258  if ( embedHighLevelSelection_ ) {
259  // get the tracks
260  reco::TrackRef innerTrack = muonBaseRef->innerTrack();
261  reco::TrackRef globalTrack= muonBaseRef->globalTrack();
262  reco::TrackRef bestTrack = muonBaseRef->muonBestTrack();
263  reco::TrackRef chosenTrack = innerTrack;
264  // Make sure the collection it points to is there
265  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
266  chosenTrack = bestTrack;
267 
268  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
269  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
270  aMuon.setNumberOfValidHits( nhits );
271 
272  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
273  embedHighLevel( aMuon,
274  chosenTrack,
275  tt,
276  primaryVertex,
277  primaryVertexIsValid,
278  beamSpot,
279  beamSpotIsValid );
280 
281  }
282 
283  if ( globalTrack.isNonnull() && globalTrack.isAvailable() && !embedCombinedMuon_) {
284  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
285  aMuon.setNormChi2( norm_chi2 );
286  }
287  }
288  reco::PFCandidateRef pfRef(pfMuons,index);
289  //reco::PFCandidatePtr ptrToMother(pfMuons,index);
290  reco::CandidateBaseRef pfBaseRef( pfRef );
291 
292  aMuon.setPFCandidateRef( pfRef );
293  if( embedPFCandidate_ ) aMuon.embedPFCandidate();
294  fillMuon( aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues );
295 
296  if(computeMiniIso_)
297  setMuonMiniIso(aMuon, pc.product());
298 
299  if (addPuppiIsolation_) {
300  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonBaseRef],
301  (*PUPPIIsolation_neutral_hadrons)[muonBaseRef],
302  (*PUPPIIsolation_photons)[muonBaseRef]);
303 
304  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonBaseRef],
305  (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonBaseRef],
306  (*PUPPINoLeptonsIsolation_photons)[muonBaseRef]);
307  }
308  else {
309  aMuon.setIsolationPUPPI(-999., -999.,-999.);
310  aMuon.setIsolationPUPPINoLeptons(-999., -999.,-999.);
311  }
312 
313  if (embedPfEcalEnergy_) {
314  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
315  }
316 
317  patMuons->push_back(aMuon);
318  }
319  }
320  else {
322  iEvent.getByToken(muonToken_, muons);
323 
324  // embedding of muon MET corrections
326  //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
328  iEvent.getByToken(caloMETMuonCorrsToken_, caloMETMuonCorrs);
329  //caloMETmuCorValueMap = *caloMETmuCorValueMap_h;
330  }
332  //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
334  iEvent.getByToken(tcMETMuonCorrsToken_, tcMETMuonCorrs);
335  //tcMETmuCorValueMap = *tcMETmuCorValueMap_h;
336  }
337 
338  if (embedPfEcalEnergy_) {
339  // get the PFCandidates of type muons
340  iEvent.getByToken(pfMuonToken_, pfMuons);
341  }
342 
343  for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
344  // construct the Muon from the ref -> save ref to original object
345  unsigned int idx = itMuon - muons->begin();
346  MuonBaseRef muonRef = muons->refAt(idx);
347  reco::CandidateBaseRef muonBaseRef( muonRef );
348 
349  Muon aMuon(muonRef);
350  fillMuon( aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);
351  if(computeMiniIso_)
352  setMuonMiniIso(aMuon, pc.product());
353  if (addPuppiIsolation_) {
354  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonRef], (*PUPPIIsolation_neutral_hadrons)[muonRef], (*PUPPIIsolation_photons)[muonRef]);
355  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_photons)[muonRef]);
356  }
357  else {
358  aMuon.setIsolationPUPPI(-999., -999.,-999.);
359  aMuon.setIsolationPUPPINoLeptons(-999., -999.,-999.);
360  }
361 
362  // Isolation
363  if (isolator_.enabled()) {
364  //reco::CandidatePtr mother = ptrToMother->sourceCandidatePtr(0);
365  isolator_.fill(*muons, idx, isolatorTmpStorage_);
366  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
367  // better to loop backwards, so the vector is resized less times
368  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
369  aMuon.setIsolation(it->first, it->second);
370  }
371  }
372 
373  // for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
374  // aMuon.setIsoDeposit(isoDepositLabels_[j].first,
375  // (*deposits[j])[muonRef]);
376  // }
377 
378  // add sel to selected
379  edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
380  if ( useUserData_ ) {
381  userDataHelper_.add( aMuon, iEvent, iSetup );
382  }
383 
384  // embed high level selection
385  if ( embedHighLevelSelection_ ) {
386  // get the tracks
387  reco::TrackRef innerTrack = itMuon->innerTrack();
388  reco::TrackRef globalTrack= itMuon->globalTrack();
389  reco::TrackRef bestTrack = itMuon->muonBestTrack();
390  reco::TrackRef chosenTrack = innerTrack;
391  // Make sure the collection it points to is there
392  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
393  chosenTrack = bestTrack;
394  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
395  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
396  aMuon.setNumberOfValidHits( nhits );
397 
398  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
399  embedHighLevel( aMuon,
400  chosenTrack,
401  tt,
402  primaryVertex,
403  primaryVertexIsValid,
404  beamSpot,
405  beamSpotIsValid );
406 
407  }
408 
409  if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
410  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
411  aMuon.setNormChi2( norm_chi2 );
412  }
413  }
414 
415  // embed MET muon corrections
416  if( embedCaloMETMuonCorrs_ ) aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
417  if( embedTcMETMuonCorrs_ ) aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs )[muonRef]);
418 
419  if (embedPfEcalEnergy_) {
420  aMuon.setPfEcalEnergy(-99.0);
421  for (const reco::PFCandidate &pfmu : *pfMuons) {
422  if (pfmu.muonRef().isNonnull()) {
423  if (pfmu.muonRef().id() != muonRef.id()) throw cms::Exception("Configuration") << "Muon reference within PF candidates does not point to the muon collection." << std::endl;
424  if (pfmu.muonRef().key() == muonRef.key()) {
425  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
426  }
427  }
428  }
429  }
430 
431  patMuons->push_back(aMuon);
432  }
433  }
434 
435  // sort muons in pt
436  std::sort(patMuons->begin(), patMuons->end(), pTComparator_);
437 
438  // put genEvt object in Event
439  std::unique_ptr<std::vector<Muon> > ptr(patMuons);
440  iEvent.put(std::move(ptr));
441 
443 }
444 
445 
446 void PATMuonProducer::fillMuon( Muon& aMuon, const MuonBaseRef& muonRef, const reco::CandidateBaseRef& baseRef, const GenAssociations& genMatches, const IsoDepositMaps& deposits, const IsolationValueMaps& isolationValues ) const
447 {
448  // in the particle flow algorithm,
449  // the muon momentum is recomputed.
450  // the new value is stored as the momentum of the
451  // resulting PFCandidate of type Muon, and choosen
452  // as the pat::Muon momentum
453  if (useParticleFlow_)
454  aMuon.setP4( aMuon.pfCandidateRef()->p4() );
455  if (embedTrack_) aMuon.embedTrack();
458 
459  // embed the TeV refit track refs (only available for globalMuons)
460  if (aMuon.isGlobalMuon()) {
462  aMuon.embedPickyMuon();
464  aMuon.embedTpfmsMuon();
466  aMuon.embedDytMuon();
467  }
468 
469  // embed best tracks (at the end, so unless forceEmbedBestTrack_ is true we can save some space not embedding them twice)
472 
473  // store the match to the generated final state muons
474  if (addGenMatch_) {
475  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
476  reco::GenParticleRef genMuon = (*genMatches[i])[baseRef];
477  aMuon.addGenParticleRef(genMuon);
478  }
479  if (embedGenMatch_) aMuon.embedGenParticle();
480  }
481  if (efficiencyLoader_.enabled()) {
482  efficiencyLoader_.setEfficiencies( aMuon, muonRef );
483  }
484 
485  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
486  if(useParticleFlow_) {
487  if (deposits[j]->contains(baseRef.id())) {
488  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
489  } else if (deposits[j]->contains(muonRef.id())){
490  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
491  } else {
492  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
493  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
494  }
495  }
496  else{
497  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
498  }
499  }
500 
501  for (size_t j = 0; j<isolationValues.size(); ++j) {
502  if(useParticleFlow_) {
503  if (isolationValues[j]->contains(baseRef.id())) {
504  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
505  } else if (isolationValues[j]->contains(muonRef.id())) {
506  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
507  } else {
508  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
509  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
510  }
511  }
512  else{
513  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
514  }
515  }
516 
517  if (resolutionLoader_.enabled()) {
519  }
520 }
521 
523 {
524  pat::PFIsolation miniiso = pat::getMiniPFIsolation(pc, aMuon.p4(),
525  miniIsoParams_[0], miniIsoParams_[1], miniIsoParams_[2],
526  miniIsoParams_[3], miniIsoParams_[4], miniIsoParams_[5],
527  miniIsoParams_[6], miniIsoParams_[7], miniIsoParams_[8]);
528  aMuon.setMiniPFIsolation(miniiso);
529 }
530 
531 // ParameterSet description for module
533 {
535  iDesc.setComment("PAT muon producer module");
536 
537  // input source
538  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("no default"))->setComment("input collection");
539 
540  // embedding
541  iDesc.add<bool>("embedMuonBestTrack", true)->setComment("embed muon best track (global pflow)");
542  iDesc.add<bool>("embedTunePMuonBestTrack", true)->setComment("embed muon best track (muon only)");
543  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");
544  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
545  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
546  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
547  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky track");
548  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms track");
549  iDesc.add<bool>("embedDytMuon", false)->setComment("embed external dyt track ");
550 
551  // embedding of MET muon corrections
552  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
553  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for caloMET");
554  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
555  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for tcMET");
556 
557  // pf specific parameters
558  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->setComment("particle flow input collection");
559  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
560  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
561  iDesc.add<bool>("embedPfEcalEnergy", true)->setComment("add ecal energy as reconstructed by PF");
562 
563  // MC matching configurables
564  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
565  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
566  std::vector<edm::InputTag> emptySourceVector;
567  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
568  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
569  )->setComment("input with MC match information");
570 
571  // mini-iso
572  iDesc.add<bool>("computeMiniIso", false)->setComment("whether or not to compute and store electron mini-isolation");
573  iDesc.add<edm::InputTag>("pfCandsForMiniIso", edm::InputTag("packedPFCandidates"))->setComment("collection to use to compute mini-iso");
574  iDesc.add<std::vector<double> >("miniIsoParams", std::vector<double>())->setComment("mini-iso parameters to use for muons");
575 
577 
578  // IsoDeposit configurables
579  edm::ParameterSetDescription isoDepositsPSet;
580  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
581  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
582  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
583  isoDepositsPSet.addOptional<edm::InputTag>("particle");
584  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
585  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
586  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
587  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
588  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
589  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
590  iDesc.addOptional("isoDeposits", isoDepositsPSet);
591 
592  // isolation values configurables
593  edm::ParameterSetDescription isolationValuesPSet;
594  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
595  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
596  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
597  isolationValuesPSet.addOptional<edm::InputTag>("particle");
598  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
599  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
600  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
601  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
602  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
603  iDesc.addOptional("isolationValues", isolationValuesPSet);
604 
605  iDesc.ifValue(edm::ParameterDescription<bool>("addPuppiIsolation", false, true),
606  true >> (edm::ParameterDescription<edm::InputTag>("puppiIsolationChargedHadrons", edm::InputTag("muonPUPPIIsolation","h+-DR030-ThresholdVeto000-ConeVeto000"), true) and
607  edm::ParameterDescription<edm::InputTag>("puppiIsolationNeutralHadrons", edm::InputTag("muonPUPPIIsolation","h0-DR030-ThresholdVeto000-ConeVeto001"), true) and
608  edm::ParameterDescription<edm::InputTag>("puppiIsolationPhotons", edm::InputTag("muonPUPPIIsolation","gamma-DR030-ThresholdVeto000-ConeVeto001"), true) and
609  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons", edm::InputTag("muonPUPPINoLeptonsIsolation","h+-DR030-ThresholdVeto000-ConeVeto000"), true) and
610  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons", edm::InputTag("muonPUPPINoLeptonsIsolation","h0-DR030-ThresholdVeto000-ConeVeto001"), true) and
611  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationPhotons", edm::InputTag("muonPUPPINoLeptonsIsolation","gamma-DR030-ThresholdVeto000-ConeVeto001"), true)) or
612  false >> edm::EmptyGroupDescription());
613 
614  // Efficiency configurables
615  edm::ParameterSetDescription efficienciesPSet;
616  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
617  iDesc.add("efficiencies", efficienciesPSet);
618  iDesc.add<bool>("addEfficiencies", false);
619 
620  // Check to see if the user wants to add user data
621  edm::ParameterSetDescription userDataPSet;
623  iDesc.addOptional("userData", userDataPSet);
624 
625  edm::ParameterSetDescription isolationPSet;
626  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
627  iDesc.add("userIsolation", isolationPSet);
628 
629  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
630  edm::ParameterSetDescription highLevelPSet;
631  highLevelPSet.setAllowAnything();
632  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
633  )->setComment("input with high level selection");
635  )->setComment("input with high level selection");
636 
637  //descriptions.add("PATMuonProducer", iDesc);
638 }
639 
640 
641 
642 // embed various impact parameters with errors
643 // embed high level selection
648  bool primaryVertexIsValid,
650  bool beamspotIsValid
651  )
652 {
653  // Correct to PV
654 
655  // PV2D
656  std::pair<bool,Measurement1D> result =
658  GlobalVector(track->px(),
659  track->py(),
660  track->pz()),
661  primaryVertex);
662  double d0_corr = result.second.value();
663  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
664  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV2D);
665 
666 
667  // PV3D
668  result =
670  GlobalVector(track->px(),
671  track->py(),
672  track->pz()),
673  primaryVertex);
674  d0_corr = result.second.value();
675  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
676  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV3D);
677 
678 
679  // Correct to beam spot
680  // make a fake vertex out of beam spot
681  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
682 
683  // BS2D
684  result =
686  GlobalVector(track->px(),
687  track->py(),
688  track->pz()),
689  vBeamspot);
690  d0_corr = result.second.value();
691  d0_err = beamspotIsValid ? result.second.error() : -1.0;
692  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS2D);
693 
694  // BS3D
695  result =
697  GlobalVector(track->px(),
698  track->py(),
699  track->pz()),
700  vBeamspot);
701  d0_corr = result.second.value();
702  d0_err = beamspotIsValid ? result.second.error() : -1.0;
703  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS3D);
704 }
705 
707 
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:221
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:122
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< 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:460
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
void embedMuonBestTrack(bool force=false)
std::vector< pat::PackedCandidate > PackedCandidateCollection
void setIsolationPUPPINoLeptons(float chargedhadrons, float neutralhadrons, float photons)
sets PUPPINoLeptons isolations
Definition: Muon.h:199
void setMuonMiniIso(pat::Muon &aMuon, const pat::PackedCandidateCollection *pc)
reco::TransientTrack build(const reco::Track *p) const
bool isGlobalMuon() const
Definition: Muon.h:225
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
bool embedBestTrack_
embed the track from best muon measurement (global pflow)
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
bool addResolutions_
add resolutions to the muon (this will be data members of th muon even w/o embedding) ...
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_charged_hadrons_
std::vector< double > miniIsoParams_
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 setPFCandidateRef(const reco::PFCandidateRef &ref)
add a reference to the source IsolatedPFCandidate
Definition: Muon.h:132
bool isRealData() const
Definition: EventBase.h:64
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
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_neutral_hadrons_
void embedStandAloneMuon()
set reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
PATMuonProducer(const edm::ParameterSet &iConfig)
default constructir
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:192
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
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)
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)
~PATMuonProducer()
default destructur
int iEvent
Definition: GenABIO.cc:230
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:243
bool addGenMatch_
add generator match information
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
description of config file parameters
Definition: Muon.py:1
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_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
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
virtual 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
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:455
edm::EDGetTokenT< pat::PackedCandidateCollection > pcToken_
bool isAValidMuonTrack(const MuonTrackType &type) const
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:678
void setPfEcalEnergy(float pfEcalEnergy)
Definition: Muon.h:266
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.
const T & get() const
Definition: EventSetup.h:55
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
void setMiniPFIsolation(PFIsolation const &iso)
Definition: Lepton.h:197
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
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
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:16
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
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:254
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)
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
bool embedGenMatch_
embed the gen match information into the muon
const Point & position() const
position
Definition: BeamSpot.h:62
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
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
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:249
bool embedCombinedMuon_
embed track of the combined fit into the muon
Analysis-level muon class.
Definition: Muon.h:49
pat::helper::KinResolutionsLoader resolutionLoader_
helper class to add resolutions to the muon
static std::string const source
Definition: EdmProvDump.cc:43
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_neutral_hadrons_
def move(src, dest)
Definition: eostools.py:510
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:82
bool embedHighLevelSelection_
embed high level selection variables