CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATMuonProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
5 
9 
12 
14 
17 
20 
22 
25 
28 
33 
34 #include "TMath.h"
35 
37 
38 #include <vector>
39 #include <memory>
40 
41 
42 using namespace pat;
43 using namespace std;
44 
45 
46 PATMuonProducer::PATMuonProducer(const edm::ParameterSet & iConfig) : useUserData_(iConfig.exists("userData")),
47  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false)
48 {
49  // input source
50  muonToken_ = consumes<edm::View<reco::Muon> >(iConfig.getParameter<edm::InputTag>( "muonSource" ));
51  // embedding of tracks
52  embedBestTrack_ = iConfig.getParameter<bool>( "embedMuonBestTrack" );
53  embedTunePBestTrack_ = iConfig.getParameter<bool>( "embedTunePMuonBestTrack" );
54  forceEmbedBestTrack_ = iConfig.getParameter<bool>( "forceBestTrackEmbedding" );
55  embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
56  embedCombinedMuon_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
57  embedStandAloneMuon_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
58  // embedding of muon MET correction information
59  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs" );
60  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs" );
61  caloMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs" ));
62  tcMETMuonCorrsToken_ = mayConsume<edm::ValueMap<reco::MuonMETCorrectionData> >(iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs" ));
63  // pflow specific configurables
64  useParticleFlow_ = iConfig.getParameter<bool>( "useParticleFlow" );
65  embedPFCandidate_ = iConfig.getParameter<bool>( "embedPFCandidate" );
66  pfMuonToken_ = mayConsume<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>( "pfMuonSource" ));
67  embedPfEcalEnergy_ = iConfig.getParameter<bool>( "embedPfEcalEnergy" );
68  // embedding of tracks from TeV refit
69  embedPickyMuon_ = iConfig.getParameter<bool>( "embedPickyMuon" );
70  embedTpfmsMuon_ = iConfig.getParameter<bool>( "embedTpfmsMuon" );
71  embedDytMuon_ = iConfig.getParameter<bool>( "embedDytMuon" );
72  // Monte Carlo matching
73  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
74  if (addGenMatch_) {
75  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
76  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
78  }
79  else {
80  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
81  }
82  }
83  // efficiencies
84  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
85  if(addEfficiencies_){
86  efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
87  }
88  // resolutions
89  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
90  if (addResolutions_) {
91  resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
92  }
93  // read isoDeposit labels, for direct embedding
94  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
95  // read isolation value labels, for direct embedding
96  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_, isolationValueTokens_);
97  // check to see if the user wants to add user data
98  if( useUserData_ ){
99  userDataHelper_ = PATUserDataHelper<Muon>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
100  }
101  // embed high level selection variables
102  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
103  if ( embedHighLevelSelection_ ) {
104  beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"));
105  pvToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("pvSrc"));
106  }
107  // produces vector of muons
108  produces<std::vector<Muon> >();
109 }
110 
111 
112 PATMuonProducer::~PATMuonProducer()
113 {
114 }
115 
117 {
118  // switch off embedding (in unschedules mode)
119  if (iEvent.isRealData()){
120  addGenMatch_ = false;
121  embedGenMatch_ = false;
122  }
123 
125  iEvent.getByToken(muonToken_, muons);
126 
127  // get the ESHandle for the transient track builder,
128  // if needed for high level selection embedding
130 
131  if(isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
133  if(resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
134 
135  IsoDepositMaps deposits(isoDepositTokens_.size());
136  for (size_t j = 0; j<isoDepositTokens_.size(); ++j) {
137  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
138  }
139 
140  IsolationValueMaps isolationValues(isolationValueTokens_.size());
141  for (size_t j = 0; j<isolationValueTokens_.size(); ++j) {
142  iEvent.getByToken(isolationValueTokens_[j], isolationValues[j]);
143  }
144 
145  // prepare the MC genMatchTokens_
146  GenAssociations genMatches(genMatchTokens_.size());
147  if (addGenMatch_) {
148  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
149  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
150  }
151  }
152 
153  // prepare the high level selection: needs beamline
154  // OR primary vertex, depending on user selection
157  bool beamSpotIsValid = false;
158  bool primaryVertexIsValid = false;
159  if ( embedHighLevelSelection_ ) {
160  // get the beamspot
161  edm::Handle<reco::BeamSpot> beamSpotHandle;
162  iEvent.getByToken(beamLineToken_, beamSpotHandle);
163 
164  // get the primary vertex
166  iEvent.getByToken( pvToken_, pvHandle );
167 
168  if( beamSpotHandle.isValid() ){
169  beamSpot = *beamSpotHandle;
170  beamSpotIsValid = true;
171  } else{
172  edm::LogError("DataNotAvailable")
173  << "No beam spot available from EventSetup, not adding high level selection \n";
174  }
175  if( pvHandle.isValid() && !pvHandle->empty() ) {
176  primaryVertex = pvHandle->at(0);
177  primaryVertexIsValid = true;
178  } else {
179  edm::LogError("DataNotAvailable")
180  << "No primary vertex available from EventSetup, not adding high level selection \n";
181  }
182  // this is needed by the IPTools methods from the tracking group
183  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
184  }
185 
186  // this will be the new object collection
187  std::vector<Muon> * patMuons = new std::vector<Muon>();
188 
190  if( useParticleFlow_ ){
191  // get the PFCandidates of type muons
192  iEvent.getByToken(pfMuonToken_, pfMuons);
193 
194  unsigned index=0;
195  for( reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
196  const reco::PFCandidate& pfmu = *i;
197  //const reco::IsolaPFCandidate& pfmu = *i;
198  const reco::MuonRef& muonRef = pfmu.muonRef();
199  assert( muonRef.isNonnull() );
200 
201  MuonBaseRef muonBaseRef(muonRef);
202  Muon aMuon(muonBaseRef);
203 
204  if ( useUserData_ ) {
205  userDataHelper_.add( aMuon, iEvent, iSetup );
206  }
207 
208  // embed high level selection
209  if ( embedHighLevelSelection_ ) {
210  // get the tracks
211  reco::TrackRef innerTrack = muonBaseRef->innerTrack();
212  reco::TrackRef globalTrack= muonBaseRef->globalTrack();
213  reco::TrackRef bestTrack = muonBaseRef->muonBestTrack();
214  reco::TrackRef chosenTrack = innerTrack;
215  // Make sure the collection it points to is there
216  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
217  chosenTrack = bestTrack;
218 
219  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
220  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
221  aMuon.setNumberOfValidHits( nhits );
222 
223  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
224  embedHighLevel( aMuon,
225  chosenTrack,
226  tt,
227  primaryVertex,
228  primaryVertexIsValid,
229  beamSpot,
230  beamSpotIsValid );
231 
232  }
233 
234  if ( globalTrack.isNonnull() && globalTrack.isAvailable() && !embedCombinedMuon_) {
235  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
236  aMuon.setNormChi2( norm_chi2 );
237  }
238  }
239  reco::PFCandidateRef pfRef(pfMuons,index);
240  //reco::PFCandidatePtr ptrToMother(pfMuons,index);
241  reco::CandidateBaseRef pfBaseRef( pfRef );
242 
243  aMuon.setPFCandidateRef( pfRef );
244  if( embedPFCandidate_ ) aMuon.embedPFCandidate();
245  fillMuon( aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues );
246 
247  if (embedPfEcalEnergy_) {
248  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
249  }
250 
251  patMuons->push_back(aMuon);
252  }
253  }
254  else {
256  iEvent.getByToken(muonToken_, muons);
257 
258  // embedding of muon MET corrections
260  //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
262  iEvent.getByToken(caloMETMuonCorrsToken_, caloMETMuonCorrs);
263  //caloMETmuCorValueMap = *caloMETmuCorValueMap_h;
264  }
266  //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
268  iEvent.getByToken(tcMETMuonCorrsToken_, tcMETMuonCorrs);
269  //tcMETmuCorValueMap = *tcMETmuCorValueMap_h;
270  }
271 
272  if (embedPfEcalEnergy_) {
273  // get the PFCandidates of type muons
274  iEvent.getByToken(pfMuonToken_, pfMuons);
275  }
276 
277  for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
278  // construct the Muon from the ref -> save ref to original object
279  unsigned int idx = itMuon - muons->begin();
280  MuonBaseRef muonRef = muons->refAt(idx);
281  reco::CandidateBaseRef muonBaseRef( muonRef );
282 
283  Muon aMuon(muonRef);
284  fillMuon( aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);
285 
286  // Isolation
287  if (isolator_.enabled()) {
288  //reco::CandidatePtr mother = ptrToMother->sourceCandidatePtr(0);
289  isolator_.fill(*muons, idx, isolatorTmpStorage_);
290  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
291  // better to loop backwards, so the vector is resized less times
292  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
293  aMuon.setIsolation(it->first, it->second);
294  }
295  }
296 
297  // for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
298  // aMuon.setIsoDeposit(isoDepositLabels_[j].first,
299  // (*deposits[j])[muonRef]);
300  // }
301 
302  // add sel to selected
303  edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
304  if ( useUserData_ ) {
305  userDataHelper_.add( aMuon, iEvent, iSetup );
306  }
307 
308  // embed high level selection
309  if ( embedHighLevelSelection_ ) {
310  // get the tracks
311  reco::TrackRef innerTrack = itMuon->innerTrack();
312  reco::TrackRef globalTrack= itMuon->globalTrack();
313  reco::TrackRef bestTrack = itMuon->muonBestTrack();
314  reco::TrackRef chosenTrack = innerTrack;
315  // Make sure the collection it points to is there
316  if ( bestTrack.isNonnull() && bestTrack.isAvailable() )
317  chosenTrack = bestTrack;
318  if ( chosenTrack.isNonnull() && chosenTrack.isAvailable() ) {
319  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
320  aMuon.setNumberOfValidHits( nhits );
321 
322  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
323  embedHighLevel( aMuon,
324  chosenTrack,
325  tt,
326  primaryVertex,
327  primaryVertexIsValid,
328  beamSpot,
329  beamSpotIsValid );
330 
331  }
332 
333  if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
334  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
335  aMuon.setNormChi2( norm_chi2 );
336  }
337  }
338 
339  // embed MET muon corrections
340  if( embedCaloMETMuonCorrs_ ) aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
341  if( embedTcMETMuonCorrs_ ) aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs )[muonRef]);
342 
343  if (embedPfEcalEnergy_) {
344  aMuon.setPfEcalEnergy(-99.0);
345  for (const reco::PFCandidate &pfmu : *pfMuons) {
346  if (pfmu.muonRef().isNonnull()) {
347  if (pfmu.muonRef().id() != muonRef.id()) throw cms::Exception("Configuration") << "Muon reference within PF candidates does not point to the muon collection." << std::endl;
348  if (pfmu.muonRef().key() == muonRef.key()) {
349  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
350  }
351  }
352  }
353  }
354 
355  patMuons->push_back(aMuon);
356  }
357  }
358 
359  // sort muons in pt
360  std::sort(patMuons->begin(), patMuons->end(), pTComparator_);
361 
362  // put genEvt object in Event
363  std::auto_ptr<std::vector<Muon> > ptr(patMuons);
364  iEvent.put(ptr);
365 
367 }
368 
369 
370 void PATMuonProducer::fillMuon( Muon& aMuon, const MuonBaseRef& muonRef, const reco::CandidateBaseRef& baseRef, const GenAssociations& genMatches, const IsoDepositMaps& deposits, const IsolationValueMaps& isolationValues ) const
371 {
372  // in the particle flow algorithm,
373  // the muon momentum is recomputed.
374  // the new value is stored as the momentum of the
375  // resulting PFCandidate of type Muon, and choosen
376  // as the pat::Muon momentum
377  if (useParticleFlow_)
378  aMuon.setP4( aMuon.pfCandidateRef()->p4() );
379  if (embedTrack_) aMuon.embedTrack();
382 
383  // embed the TeV refit track refs (only available for globalMuons)
384  if (aMuon.isGlobalMuon()) {
386  aMuon.embedPickyMuon();
388  aMuon.embedTpfmsMuon();
390  aMuon.embedDytMuon();
391  }
392 
393  // embed best tracks (at the end, so unless forceEmbedBestTrack_ is true we can save some space not embedding them twice)
396 
397  // store the match to the generated final state muons
398  if (addGenMatch_) {
399  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
400  reco::GenParticleRef genMuon = (*genMatches[i])[baseRef];
401  aMuon.addGenParticleRef(genMuon);
402  }
403  if (embedGenMatch_) aMuon.embedGenParticle();
404  }
405  if (efficiencyLoader_.enabled()) {
406  efficiencyLoader_.setEfficiencies( aMuon, muonRef );
407  }
408 
409  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
410  if(useParticleFlow_) {
411  if (deposits[j]->contains(baseRef.id())) {
412  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
413  } else if (deposits[j]->contains(muonRef.id())){
414  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
415  } else {
416  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
417  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
418  }
419  }
420  else{
421  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
422  }
423  }
424 
425  for (size_t j = 0; j<isolationValues.size(); ++j) {
426  if(useParticleFlow_) {
427  if (isolationValues[j]->contains(baseRef.id())) {
428  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
429  } else if (isolationValues[j]->contains(muonRef.id())) {
430  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
431  } else {
432  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
433  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
434  }
435  }
436  else{
437  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
438  }
439  }
440 
441  if (resolutionLoader_.enabled()) {
443  }
444 }
445 
446 // ParameterSet description for module
448 {
450  iDesc.setComment("PAT muon producer module");
451 
452  // input source
453  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("no default"))->setComment("input collection");
454 
455  // embedding
456  iDesc.add<bool>("embedMuonBestTrack", true)->setComment("embed muon best track (global pflow)");
457  iDesc.add<bool>("embedTunePMuonBestTrack", true)->setComment("embed muon best track (muon only)");
458  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");
459  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
460  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
461  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
462  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky track");
463  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms track");
464  iDesc.add<bool>("embedDytMuon", false)->setComment("embed external dyt track ");
465 
466  // embedding of MET muon corrections
467  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
468  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for caloMET");
469  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
470  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for tcMET");
471 
472  // pf specific parameters
473  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->setComment("particle flow input collection");
474  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
475  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
476  iDesc.add<bool>("embedPfEcalEnergy", true)->setComment("add ecal energy as reconstructed by PF");
477 
478  // MC matching configurables
479  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
480  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
481  std::vector<edm::InputTag> emptySourceVector;
482  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
483  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
484  )->setComment("input with MC match information");
485 
487 
488  // IsoDeposit configurables
489  edm::ParameterSetDescription isoDepositsPSet;
490  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
491  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
492  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
493  isoDepositsPSet.addOptional<edm::InputTag>("particle");
494  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
495  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
496  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
497  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
498  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
499  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
500  iDesc.addOptional("isoDeposits", isoDepositsPSet);
501 
502  // isolation values configurables
503  edm::ParameterSetDescription isolationValuesPSet;
504  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
505  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
506  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
507  isolationValuesPSet.addOptional<edm::InputTag>("particle");
508  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
509  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
510  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
511  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
512  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
513  iDesc.addOptional("isolationValues", isolationValuesPSet);
514 
515  // Efficiency configurables
516  edm::ParameterSetDescription efficienciesPSet;
517  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
518  iDesc.add("efficiencies", efficienciesPSet);
519  iDesc.add<bool>("addEfficiencies", false);
520 
521  // Check to see if the user wants to add user data
522  edm::ParameterSetDescription userDataPSet;
524  iDesc.addOptional("userData", userDataPSet);
525 
526  edm::ParameterSetDescription isolationPSet;
527  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
528  iDesc.add("userIsolation", isolationPSet);
529 
530  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
531  edm::ParameterSetDescription highLevelPSet;
532  highLevelPSet.setAllowAnything();
533  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
534  )->setComment("input with high level selection");
536  )->setComment("input with high level selection");
537 
538  //descriptions.add("PATMuonProducer", iDesc);
539 }
540 
541 
542 
543 // embed various impact parameters with errors
544 // embed high level selection
546  reco::TrackRef track,
549  bool primaryVertexIsValid,
551  bool beamspotIsValid
552  )
553 {
554  // Correct to PV
555 
556  // PV2D
557  std::pair<bool,Measurement1D> result =
559  GlobalVector(track->px(),
560  track->py(),
561  track->pz()),
562  primaryVertex);
563  double d0_corr = result.second.value();
564  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
565  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV2D);
566 
567 
568  // PV3D
569  result =
571  GlobalVector(track->px(),
572  track->py(),
573  track->pz()),
574  primaryVertex);
575  d0_corr = result.second.value();
576  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
577  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV3D);
578 
579 
580  // Correct to beam spot
581  // make a fake vertex out of beam spot
582  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
583 
584  // BS2D
585  result =
587  GlobalVector(track->px(),
588  track->py(),
589  track->pz()),
590  vBeamspot);
591  d0_corr = result.second.value();
592  d0_err = beamspotIsValid ? result.second.error() : -1.0;
593  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS2D);
594 
595  // BS3D
596  result =
598  GlobalVector(track->px(),
599  track->py(),
600  track->pz()),
601  vBeamspot);
602  d0_corr = result.second.value();
603  d0_err = beamspotIsValid ? result.second.error() : -1.0;
604  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS3D);
605 }
606 
608 
bool embedTpfmsMuon_
embed track from tpfms muon fit into the muon
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:614
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.
int i
Definition: DBlmapReader.cc:9
void embedDytMuon()
embed reference to the above dyt Track
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
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:98
bool embedTcMETMuonCorrs_
embed muon MET correction info for tcMET into the muon
class definition
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
void embedTcMETMuonCorrs(const reco::MuonMETCorrectionData &t)
edm::EDGetTokenT< std::vector< reco::Vertex > > pvToken_
input source of the primary vertex
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
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)
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > caloMETMuonCorrsToken_
source of caloMET muon corrections
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setDB(double dB, double edB, IpType type=PV2D)
Definition: Muon.h:219
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
assert(m_qm.get())
void embedMuonBestTrack(bool force=false)
bool isGlobalMuon() const
Definition: Muon.h:218
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
virtual void setP4(const LorentzVector &p4)
set 4-momentum
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:220
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 ...
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:175
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)
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
bool addGenMatch_
add generator match information
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
description of config file parameters
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
bool embedPfEcalEnergy_
add ecal PF energy
void embedGenParticle()
Definition: PATObject.h:677
void embedPFCandidate()
embed the IsolatedPFCandidate pointed to by pfCandidateRef_
tuple result
Definition: query.py:137
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
everything that needs to be done during the event loop
reco::PFCandidateRef pfCandidateRef() const
int j
Definition: DBlmapReader.cc:9
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:75
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:450
bool isAValidMuonTrack(const MuonTrackType &type) const
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:661
void setPfEcalEnergy(float pfEcalEnergy)
Definition: Muon.h:242
bool embedTunePBestTrack_
embed the track from best muon measurement (muon only)
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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.
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
bool embedPickyMuon_
embed track from picky muon fit into the muon
void setNormChi2(double normChi2)
Definition: Muon.h:230
tuple muons
Definition: patZpeak.py:38
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool embedDytMuon_
embed track from DYT muon fit into the muon
void embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData &t)
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
IsolationLabels isoDepositLabels_
input source for isoDeposits
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
input tags for generator match information
volatile std::atomic< bool > shutdown_flag false
Covariance3DMatrix rotatedCovariance3D() const
Definition: BeamSpot.cc:78
IsolationLabels isolationValueLabels_
input source isolation value maps
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
void newEvent(const edm::Event &event, const edm::EventSetup &setup) const
To be called for each new event, reads in the EventSetup object.
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
void setNumberOfValidHits(unsigned int numberOfValidHits)
Definition: Muon.h:225
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:42
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:82
tuple pfMuons
Definition: pfMuons_cff.py:8
bool embedHighLevelSelection_
embed high level selection variables