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 // $Id: PATMuonProducer.cc,v 1.43 2011/06/27 15:57:48 bellan Exp $
3 //
4 
6 
10 
13 
15 
18 
21 
23 
26 
27 
30 
35 
36 
37 #include "TMath.h"
38 
39 #include <vector>
40 #include <memory>
41 
42 
43 using namespace pat;
44 using namespace std;
45 
46 
47 PATMuonProducer::PATMuonProducer(const edm::ParameterSet & iConfig) : useUserData_(iConfig.exists("userData")),
48  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), false)
49 {
50  // input source
51  muonSrc_ = iConfig.getParameter<edm::InputTag>( "muonSource" );
52  // embedding of tracks
53  embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
54  embedCombinedMuon_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
55  embedStandAloneMuon_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
56 
57  // embedding of muon MET correction information
58  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs" );
59  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs" );
60  caloMETMuonCorrs_ = iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs" );
61  tcMETMuonCorrs_ = iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs" );
62 
63  // pflow specific configurables
64  useParticleFlow_ = iConfig.getParameter<bool>( "useParticleFlow" );
65  linkToPFSource_ = iConfig.getParameter<edm::InputTag>( "linkToPFSource" ); //SAK
66  embedPFCandidate_ = iConfig.getParameter<bool>( "embedPFCandidate" );
67  pfMuonSrc_ = iConfig.getParameter<edm::InputTag>( "pfMuonSource" );
68 
69  // TeV track refits
70  addTeVRefits_ = iConfig.getParameter<bool>("addTeVRefits");
71  if(addTeVRefits_){
72  pickySrc_ = iConfig.getParameter<edm::InputTag>("pickySrc");
73  tpfmsSrc_ = iConfig.getParameter<edm::InputTag>("tpfmsSrc");
74  }
75  // embedding of tracks from TeV refit
76  embedPickyMuon_ = iConfig.getParameter<bool>( "embedPickyMuon" );
77  embedTpfmsMuon_ = iConfig.getParameter<bool>( "embedTpfmsMuon" );
78 
79  // Monte Carlo matching
80  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
81  if(addGenMatch_){
82  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
83  if(iConfig.existsAs<edm::InputTag>("genParticleMatch")){
84  genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
85  } else {
86  genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
87  }
88  }
89 
90  // efficiencies
91  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
92  if(addEfficiencies_){
94  }
95 
96  // resolutions
97  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
98  if (addResolutions_) {
100  }
101 
102  // read isoDeposit labels, for direct embedding
103  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_);
104  // read isolation value labels, for direct embedding
105  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_);
106 
107  // check to see if the user wants to add user data
108  if( useUserData_ ){
110  }
111 
112  // embed high level selection variables
113  usePV_ = true;
114  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
115  if ( embedHighLevelSelection_ ) {
116  beamLineSrc_ = iConfig.getParameter<edm::InputTag>("beamLineSrc");
117  usePV_ = iConfig.getParameter<bool>("usePV");
118  pvSrc_ = iConfig.getParameter<edm::InputTag>("pvSrc");
119  }
120 
121  // produces vector of muons
122  produces<std::vector<Muon> >();
123 }
124 
125 
127 {
128 }
129 
131 {
133  iEvent.getByLabel(muonSrc_, muons);
134 
135  if (iEvent.isRealData()){
136  addGenMatch_ = false;
137  embedGenMatch_ = false;
138  }
139 
140  // get the ESHandle for the transient track builder,
141  // if needed for high level selection embedding
143 
144  if(isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
146  if(resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
147 
148  IsoDepositMaps deposits(isoDepositLabels_.size());
149  for (size_t j = 0; j<isoDepositLabels_.size(); ++j) {
150  iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]);
151  }
152 
153  IsolationValueMaps isolationValues(isolationValueLabels_.size());
154  for (size_t j = 0; j<isolationValueLabels_.size(); ++j) {
155  iEvent.getByLabel(isolationValueLabels_[j].second, isolationValues[j]);
156  }
157 
158  // prepare the MC matching
159  GenAssociations genMatches(genMatchSrc_.size());
160  if (addGenMatch_) {
161  for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
162  iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
163  }
164  }
165 
166  // prepare the high level selection: needs beamline
167  // OR primary vertex, depending on user selection
168  reco::TrackBase::Point beamPoint(0,0,0);
169  reco::Vertex primaryVertex;
170  reco::BeamSpot beamSpot;
171  bool beamSpotIsValid = false;
172  bool primaryVertexIsValid = false;
173  if ( embedHighLevelSelection_ ) {
174  // get the beamspot
175  edm::Handle<reco::BeamSpot> beamSpotHandle;
176  iEvent.getByLabel(beamLineSrc_, beamSpotHandle);
177 
178  // get the primary vertex
180  iEvent.getByLabel( pvSrc_, pvHandle );
181 
182  if( beamSpotHandle.isValid() ){
183  beamSpot = *beamSpotHandle;
184  beamSpotIsValid = true;
185  } else{
186  edm::LogError("DataNotAvailable")
187  << "No beam spot available from EventSetup, not adding high level selection \n";
188  }
189  beamPoint = reco::TrackBase::Point ( beamSpot.x0(), beamSpot.y0(), beamSpot.z0() );
190  if( pvHandle.isValid() && !pvHandle->empty() ) {
191  primaryVertex = pvHandle->at(0);
192  primaryVertexIsValid = true;
193  } else {
194  edm::LogError("DataNotAvailable")
195  << "No primary vertex available from EventSetup, not adding high level selection \n";
196  }
197  // this is needed by the IPTools methods from the tracking group
198  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
199  }
200 
201  // this will be the new object collection
202  std::vector<Muon> * patMuons = new std::vector<Muon>();
203 
204  if( useParticleFlow_ ){
205  // get the PFCandidates of type muons
207  iEvent.getByLabel(pfMuonSrc_, pfMuons);
208  //-- SAK ------------------------------------------------------------------
210  if (linkToPFSource_.label().length())
211  iEvent.getByLabel(linkToPFSource_, pfForLinking);
212  //-- SAK ------------------------------------------------------------------
213 
214  unsigned index=0;
215  for( reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
216  const reco::PFCandidate& pfmu = *i;
217  //const reco::IsolaPFCandidate& pfmu = *i;
218  const reco::MuonRef& muonRef = pfmu.muonRef();
219  assert( muonRef.isNonnull() );
220 
221  MuonBaseRef muonBaseRef(muonRef);
222  Muon aMuon(muonBaseRef);
223 
224  if ( useUserData_ ) {
225  userDataHelper_.add( aMuon, iEvent, iSetup );
226  }
227 
228  // embed high level selection
229  if ( embedHighLevelSelection_ ) {
230  // get the tracks
231  reco::TrackRef innerTrack = muonBaseRef->innerTrack();
232  reco::TrackRef globalTrack= muonBaseRef->globalTrack();
233  // Make sure the collection it points to is there
234  if ( innerTrack.isNonnull() && innerTrack.isAvailable() ) {
235  unsigned int nhits = innerTrack->numberOfValidHits();
236  aMuon.setNumberOfValidHits( nhits );
237 
238  reco::TransientTrack tt = trackBuilder->build(innerTrack);
239  embedHighLevel( aMuon,
240  innerTrack,
241  tt,
242  primaryVertex,
243  primaryVertexIsValid,
244  beamSpot,
245  beamSpotIsValid );
246 
247  // Correct to PV, or beam spot
248  if ( !usePV_ ) {
249  double corr_d0 = -1.0 * innerTrack->dxy( beamPoint );
250  aMuon.setDB( corr_d0, -1.0 );
251  } else {
252  std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
253  double d0_corr = result.second.value();
254  double d0_err = result.second.error();
255  aMuon.setDB( d0_corr, d0_err );
256  }
257  }
258 
259  if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
260  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
261  aMuon.setNormChi2( norm_chi2 );
262  }
263  }
264  reco::PFCandidateRef pfRef(pfMuons,index);
265  //reco::PFCandidatePtr ptrToMother(pfMuons,index);
266  reco::CandidateBaseRef pfBaseRef( pfRef );
267 
268  aMuon.setPFCandidateRef( pfRef );
269  if( embedPFCandidate_ ) aMuon.embedPFCandidate();
270  fillMuon( aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues );
271 
272  //-- SAK ----------------------------------------------------------------
273  if (linkToPFSource_.label().length() && aMuon.pfCandidateRef().id() != pfForLinking.id()) {
274  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
275  while (source.id() != pfForLinking.id()) {
276  source = source->sourceCandidatePtr(0);
277  if (source.isNull())
278  throw cms::Exception("InputSource", "Object in "+pfMuonSrc_.encode()+" does not link back to "+linkToPFSource_.encode());
279  } // end loop over inheritance chain
280  aMuon.setPFCandidateRef(reco::PFCandidateRef(pfForLinking, source.key()));
281  }
282  //-- SAK ----------------------------------------------------------------
283  patMuons->push_back(aMuon);
284  }
285  }
286  else {
288  iEvent.getByLabel(muonSrc_, muons);
289 
290  // prepare the TeV refit track retrieval
291  edm::Handle<reco::TrackToTrackMap> pickyMap, tpfmsMap;
292  if (addTeVRefits_) {
293  iEvent.getByLabel(pickySrc_, pickyMap);
294  iEvent.getByLabel(tpfmsSrc_, tpfmsMap);
295  }
296 
297  // embedding of muon MET corrections
299  //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
301  iEvent.getByLabel(caloMETMuonCorrs_, caloMETMuonCorrs);
302  //caloMETmuCorValueMap = *caloMETmuCorValueMap_h;
303  }
305  //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
307  iEvent.getByLabel(tcMETMuonCorrs_, tcMETMuonCorrs);
308  //tcMETmuCorValueMap = *tcMETmuCorValueMap_h;
309  }
310  for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
311  // construct the Muon from the ref -> save ref to original object
312  unsigned int idx = itMuon - muons->begin();
313  MuonBaseRef muonRef = muons->refAt(idx);
314  reco::CandidateBaseRef muonBaseRef( muonRef );
315 
316  Muon aMuon(muonRef);
317  fillMuon( aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);
318 
319  // store the TeV refit track refs (only available for globalMuons)
320  if (addTeVRefits_ && itMuon->isGlobalMuon()) {
322  const reco::TrackRef& globalTrack = itMuon->globalTrack();
323 
324  // If the getByLabel calls failed above (i.e. if the TeV refit
325  // maps/collections were not in the event), then the TrackRefs
326  // in the Muon object will remain null.
327  if (!pickyMap.failedToGet()) {
328  it = pickyMap->find(globalTrack);
329  if (it != pickyMap->end()) aMuon.setPickyMuon(it->val);
330  if (embedPickyMuon_) aMuon.embedPickyMuon();
331  }
332 
333  if (!tpfmsMap.failedToGet()) {
334  it = tpfmsMap->find(globalTrack);
335  if (it != tpfmsMap->end()) aMuon.setTpfmsMuon(it->val);
336  if (embedTpfmsMuon_) aMuon.embedTpfmsMuon();
337  }
338  }
339 
340  // Isolation
341  if (isolator_.enabled()) {
342  //reco::CandidatePtr mother = ptrToMother->sourceCandidatePtr(0);
343  isolator_.fill(*muons, idx, isolatorTmpStorage_);
344  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
345  // better to loop backwards, so the vector is resized less times
346  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
347  aMuon.setIsolation(it->first, it->second);
348  }
349  }
350 
351  // for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
352  // aMuon.setIsoDeposit(isoDepositLabels_[j].first,
353  // (*deposits[j])[muonRef]);
354  // }
355 
356  // add sel to selected
357  edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
358  if ( useUserData_ ) {
359  userDataHelper_.add( aMuon, iEvent, iSetup );
360  }
361 
362  // embed high level selection
363  if ( embedHighLevelSelection_ ) {
364  // get the tracks
365  reco::TrackRef innerTrack = itMuon->innerTrack();
366  reco::TrackRef globalTrack= itMuon->globalTrack();
367  // Make sure the collection it points to is there
368  if ( innerTrack.isNonnull() && innerTrack.isAvailable() ) {
369  unsigned int nhits = innerTrack->numberOfValidHits();
370  aMuon.setNumberOfValidHits( nhits );
371 
372  reco::TransientTrack tt = trackBuilder->build(innerTrack);
373  embedHighLevel( aMuon,
374  innerTrack,
375  tt,
376  primaryVertex,
377  primaryVertexIsValid,
378  beamSpot,
379  beamSpotIsValid );
380 
381  // Correct to PV, or beam spot
382  if ( !usePV_ ) {
383  double corr_d0 = -1.0 * innerTrack->dxy( beamPoint );
384  aMuon.setDB( corr_d0, -1.0 );
385  } else {
386  std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
387  double d0_corr = result.second.value();
388  double d0_err = result.second.error();
389  aMuon.setDB( d0_corr, d0_err );
390  }
391  }
392 
393  if ( globalTrack.isNonnull() && globalTrack.isAvailable() ) {
394  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
395  aMuon.setNormChi2( norm_chi2 );
396  }
397  }
398 
399  // embed MET muon corrections
400  if( embedCaloMETMuonCorrs_ ) aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
401  if( embedTcMETMuonCorrs_ ) aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs )[muonRef]);
402 
403  patMuons->push_back(aMuon);
404  }
405  }
406 
407  // sort muons in pt
408  std::sort(patMuons->begin(), patMuons->end(), pTComparator_);
409 
410  // put genEvt object in Event
411  std::auto_ptr<std::vector<Muon> > ptr(patMuons);
412  iEvent.put(ptr);
413 
415 }
416 
417 
418 void PATMuonProducer::fillMuon( Muon& aMuon, const MuonBaseRef& muonRef, const reco::CandidateBaseRef& baseRef, const GenAssociations& genMatches, const IsoDepositMaps& deposits, const IsolationValueMaps& isolationValues ) const
419 {
420  // in the particle flow algorithm,
421  // the muon momentum is recomputed.
422  // the new value is stored as the momentum of the
423  // resulting PFCandidate of type Muon, and choosen
424  // as the pat::Muon momentum
425  if (useParticleFlow_)
426  aMuon.setP4( aMuon.pfCandidateRef()->p4() );
427  if (embedTrack_) aMuon.embedTrack();
430 
431  // store the match to the generated final state muons
432  if (addGenMatch_) {
433  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
434  reco::GenParticleRef genMuon = (*genMatches[i])[baseRef];
435  aMuon.addGenParticleRef(genMuon);
436  }
437  if (embedGenMatch_) aMuon.embedGenParticle();
438  }
439  if (efficiencyLoader_.enabled()) {
440  efficiencyLoader_.setEfficiencies( aMuon, muonRef );
441  }
442 
443  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
444  if(useParticleFlow_) {
445  if (deposits[j]->contains(baseRef.id()))
446  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
447  else {
448  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
449  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
450  }
451  }
452  else{
453  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
454  }
455  }
456 
457  for (size_t j = 0; j<isolationValues.size(); ++j) {
458  if(useParticleFlow_) {
459  if (isolationValues[j]->contains(baseRef.id()))
460  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
461  else {
462  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
463  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
464  }
465  }
466  else{
467  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
468  }
469  }
470 
471  if (resolutionLoader_.enabled()) {
473  }
474 }
475 
476 // ParameterSet description for module
478 {
480  iDesc.setComment("PAT muon producer module");
481 
482  // input source
483  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("no default"))->setComment("input collection");
484 
485  // embedding
486  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
487  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
488  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
489  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky muon");
490  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms muon");
491 
492  // embedding of MET muon corrections
493  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
494  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for caloMET");
495  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
496  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer" , "muCorrData"))->setComment("source of MET muon corrections for tcMET");
497 
498  // pf specific parameters
499  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->setComment("particle flow input collection");
500  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
501  iDesc.add<edm::InputTag>("linkToPFSource", edm::InputTag())->setComment("alternative PF collection to link to (pfCandidateRef) -- traverses inheritance chain up to this");
502  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
503 
504  // TeV refit
505  iDesc.ifValue( edm::ParameterDescription<bool>("addTeVRefits", true, true),
506  true >> (edm::ParameterDescription<edm::InputTag>("pickySrc", edm::InputTag(), true) and
508  )->setComment("If TeV refits are added, their sources need to be specified");
509 
510  // MC matching configurables
511  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
512  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
513  std::vector<edm::InputTag> emptySourceVector;
514  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
515  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
516  )->setComment("input with MC match information");
517 
519 
520  // IsoDeposit configurables
521  edm::ParameterSetDescription isoDepositsPSet;
522  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
523  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
524  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
525  isoDepositsPSet.addOptional<edm::InputTag>("particle");
526  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
527  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
528  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
529  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
530  iDesc.addOptional("isoDeposits", isoDepositsPSet);
531 
532  // isolation values configurables
533  edm::ParameterSetDescription isolationValuesPSet;
534  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
535  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
536  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
537  isolationValuesPSet.addOptional<edm::InputTag>("particle");
538  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
539  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
540  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
541  iDesc.addOptional("isolationValues", isolationValuesPSet);
542 
543  // Efficiency configurables
544  edm::ParameterSetDescription efficienciesPSet;
545  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
546  iDesc.add("efficiencies", efficienciesPSet);
547  iDesc.add<bool>("addEfficiencies", false);
548 
549  // Check to see if the user wants to add user data
550  edm::ParameterSetDescription userDataPSet;
552  iDesc.addOptional("userData", userDataPSet);
553 
554  edm::ParameterSetDescription isolationPSet;
555  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
556  iDesc.add("userIsolation", isolationPSet);
557 
558  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
559  edm::ParameterSetDescription highLevelPSet;
560  highLevelPSet.setAllowAnything();
561  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
562  )->setComment("input with high level selection");
564  )->setComment("input with high level selection");
565  iDesc.addNode( edm::ParameterDescription<bool>("usePV", bool(), true)
566  )->setComment("input with high level selection, use primary vertex (true) or beam line (false)");
567 
568  //descriptions.add("PATMuonProducer", iDesc);
569 }
570 
571 
572 void PATMuonProducer::readIsolationLabels( const edm::ParameterSet & iConfig, const char* psetName, IsolationLabels& labels)
573 {
574  labels.clear();
575 
576  if (iConfig.exists( psetName )) {
577  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>(psetName);
578 
579  if (depconf.exists("tracker")) labels.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
580  if (depconf.exists("ecal")) labels.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
581  if (depconf.exists("hcal")) labels.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
582  if (depconf.exists("pfAllParticles")) {
583  labels.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
584  }
585  if (depconf.exists("pfChargedHadrons")) {
586  labels.push_back(std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons")));
587  }
588  if (depconf.exists("pfNeutralHadrons")) {
589  labels.push_back(std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons")));
590  }
591  if (depconf.exists("pfPhotons")) {
592  labels.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons")));
593  }
594  if (depconf.exists("user")) {
595  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
596  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
597  int key = UserBaseIso;
598  for ( ; it != ed; ++it, ++key) {
599  labels.push_back(std::make_pair(IsolationKeys(key), *it));
600  }
601  }
602  }
603 }
604 
605 
606 
607 // embed various impact parameters with errors
608 // embed high level selection
612  reco::Vertex & primaryVertex,
613  bool primaryVertexIsValid,
614  reco::BeamSpot & beamspot,
615  bool beamspotIsValid
616  )
617 {
618  // Correct to PV
619 
620  // PV2D
621  std::pair<bool,Measurement1D> result =
623  GlobalVector(innerTrack->px(),
624  innerTrack->py(),
625  innerTrack->pz()),
626  primaryVertex);
627  double d0_corr = result.second.value();
628  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
629  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV2D);
630 
631 
632  // PV3D
633  result =
635  GlobalVector(innerTrack->px(),
636  innerTrack->py(),
637  innerTrack->pz()),
638  primaryVertex);
639  d0_corr = result.second.value();
640  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
641  aMuon.setDB( d0_corr, d0_err, pat::Muon::PV3D);
642 
643 
644  // Correct to beam spot
645  // make a fake vertex out of beam spot
646  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
647 
648  // BS2D
649  result =
651  GlobalVector(innerTrack->px(),
652  innerTrack->py(),
653  innerTrack->pz()),
654  vBeamspot);
655  d0_corr = result.second.value();
656  d0_err = beamspotIsValid ? result.second.error() : -1.0;
657  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS2D);
658 
659  // BS3D
660  result =
662  GlobalVector(innerTrack->px(),
663  innerTrack->py(),
664  innerTrack->pz()),
665  vBeamspot);
666  d0_corr = result.second.value();
667  d0_err = beamspotIsValid ? result.second.error() : -1.0;
668  aMuon.setDB( d0_corr, d0_err, pat::Muon::BS3D);
669 }
670 
672 
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) ...
T getParameter(std::string const &) const
void setComment(std::string const &value)
double z0() const
z coordinate
Definition: BeamSpot.h:69
Assists in assimilating all pat::UserData into pat objects.
bool usePV_
use the primary vertex or the beamspot
int i
Definition: DBlmapReader.cc:9
void embedStandAloneMuon()
set reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
Definition: Muon.cc:221
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
edm::InputTag pickySrc_
input tag for picky muon refit
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:181
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
void embedPFCandidate()
embed the IsolatedPFCandidate pointed to by pfCandidateRef_
Definition: Muon.cc:272
ProductID id() const
Definition: HandleBase.cc:15
bool addEfficiencies_
add efficiencies to the muon (this will be data members of th muon even w/o embedding) ...
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag tpfmsSrc_
input tag for tpfms muon refit
bool embedCaloMETMuonCorrs_
embed muon MET correction info for caloMET into the muon
edm::InputTag pvSrc_
input source of the primary vertex
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
bool exists(std::string const &parameterName) const
checks if a parameter exists
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
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
edm::InputTag tcMETMuonCorrs_
source of tcMET muon corrections
edm::InputTag pfMuonSrc_
input source pfCandidates that will be to be transformed into pat::Muons, when using PF2PAT ...
bool addResolutions_
add resolutions to the muon (this will be data members of th muon even w/o embedding) ...
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
bool isAvailable() const
Definition: Ref.h:275
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
ProductID id() const
Definition: RefToBase.h:220
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:115
bool isRealData() const
Definition: EventBase.h:60
std::string encode() const
Definition: InputTag.cc:72
void embedPickyMuon()
embed reference to the above picky Track
Definition: Muon.cc:254
PATMuonProducer(const edm::ParameterSet &iConfig)
default constructir
pat::helper::MultiIsolator isolator_
helper class to add userdefined isolation values to the muon
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:173
void embedCombinedMuon()
set reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon...
Definition: Muon.cc:231
static void fillDescription(edm::ParameterSetDescription &iDesc)
std::vector< IsolationLabel > IsolationLabels
U second(std::pair< T, U > const &p)
void embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData &t)
embed the MuonMETCorrectionData for muon corrected caloMET
Definition: Muon.cc:240
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 isNonnull() const
Checks for non-null.
Definition: Ref.h:249
bool embedStandAloneMuon_
embed track from muon system into the muon
void setComment(std::string const &value)
~PATMuonProducer()
default destructur
reco::PFCandidateRef pfCandidateRef() const
reference to the source IsolatedPFCandidates
Definition: Muon.cc:193
int iEvent
Definition: GenABIO.cc:243
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
edm::InputTag beamLineSrc_
input source of the primary vertex/beamspot
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
void embedGenParticle()
Definition: PATObject.h:669
void embedTrack()
set reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.cc:211
void embedTcMETMuonCorrs(const reco::MuonMETCorrectionData &t)
embed the MuonMETCorrectionData for tcMET
Definition: Muon.cc:247
void embedHighLevel(pat::Muon &aMuon, reco::TrackRef innerTrack, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:169
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
everything that needs to be done during the event loop
void setTpfmsMuon(const reco::TrackRef &t)
Definition: Muon.h:104
math::XYZPoint Point
point in the space
Definition: TrackBase.h:76
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool first
Definition: L1TdeRCT.cc:79
bool isValid() const
Definition: HandleBase.h:76
std::vector< edm::InputTag > genMatchSrc_
input tags for generator match information
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:347
tuple labels
Definition: L1TDQM_cfg.py:62
bool failedToGet() const
Definition: HandleBase.h:80
void embedTpfmsMuon()
embed reference to the above tpfms Track
Definition: Muon.cc:263
key_type key() const
Definition: Ptr.h:174
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:653
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::auto_ptr< ParameterDescriptionCases< T > > cases)
edm::InputTag muonSrc_
input source
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels)
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
const T & get() const
Definition: EventSetup.h:55
bool addTeVRefits_
add TeV track refits for the muon
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::InputTag caloMETMuonCorrs_
source of caloMET muon corrections
edm::InputTag linkToPFSource_
std::pair< bool, Measurement1D > absoluteTransverseImpactParameter(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:43
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
std::string const & label() const
Definition: InputTag.h:25
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
bool isNull() const
Checks for null.
Definition: Ptr.h:153
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:33
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:203
list key
Definition: combine.py:13
tuple muons
Definition: patZpeak.py:38
double y0() const
y coordinate
Definition: BeamSpot.h:67
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:63
IsolationLabels isoDepositLabels_
input source for isoDeposits
ProductID id() const
Accessor for product ID.
Definition: Ref.h:255
Covariance3DMatrix rotatedCovariance3D() const
Definition: BeamSpot.cc:79
IsolationLabels isolationValueLabels_
input source isolation value maps
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
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.
void setNumberOfValidHits(unsigned int numberOfValidHits)
Definition: Muon.h:198
bool embedCombinedMuon_
embed track of the combined fit into the muon
Analysis-level muon class.
Definition: Muon.h:51
pat::helper::KinResolutionsLoader resolutionLoader_
helper class to add resolutions to the muon
void setPickyMuon(const reco::TrackRef &t)
Definition: Muon.h:101
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.
void setDB(double dB, double edB, IpType type=None)
Definition: Muon.h:188
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:82
double x0() const
x coordinate
Definition: BeamSpot.h:65
bool embedHighLevelSelection_
embed high level selection variables