CMS 3D CMS Logo

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