CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
MuScleFitMuonSelector Class Reference

#include <MuScleFitMuonSelector.h>

Public Member Functions

const reco::CandidategetStatus1Muon (const reco::Candidate *status3Muon)
 
const reco::CandidategetStatus3Muon (const reco::Candidate *status3Muon)
 
 MuScleFitMuonSelector (const edm::InputTag &muonLabel, const int muonType, const bool PATmuons, const std::vector< int > &resfind, const bool speedup, const std::string &genParticlesName, const bool compareToSimTracks, const edm::InputTag &simTracksCollectionName, const bool sherpa, const bool debug)
 
void selectMuons (const edm::Event &event, std::vector< MuScleFitMuon > &muons, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
 Main method used to select muons of type specified by muonType_ from the collection specified by muonLabel_ and PATmuons_. More...
 
 ~MuScleFitMuonSelector ()
 

Protected Member Functions

template<typename T >
std::vector< MuScleFitMuonfillMuonCollection (const std::vector< T > &tracks)
 Template function used to convert the muon collection to a vector of reco::LeafCandidate. More...
 
GenMuonPair findGenMuFromRes (const edm::HepMCProduct *evtMC)
 
GenMuonPair findGenMuFromRes (const reco::GenParticleCollection *genParticles)
 
std::pair< lorentzVector, lorentzVectorfindSimMuFromRes (const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
 
void selectGeneratedMuons (const edm::Handle< pat::CompositeCandidateCollection > &collAll, const std::vector< const pat::Muon * > &collMuSel, std::vector< GenMuonPair > &genPair, MuScleFitPlotter *plotter)
 For PATmuons the generator information is read directly from the PAT object. More...
 
void selectGenSimMuons (const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
 
void selectSimulatedMuons (const edm::Event &event, const bool ifHepMC, edm::Handle< edm::HepMCProduct > evtMC, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
 
bool selGlobalMuon (const pat::Muon *aMuon)
 Apply the Onia cuts to select globalMuons. More...
 
bool selTrackerMuon (const pat::Muon *aMuon)
 Apply the Onia cuts to select trackerMuons. More...
 
template<typename T >
void takeSelectedMuonType (const T &muon, std::vector< reco::Track > &tracks)
 Template function used to extract the selected muon type from the muon collection. More...
 

Protected Attributes

const bool compareToSimTracks_
 
const bool debug_
 
const std::string genParticlesName_
 
const edm::InputTag muonLabel_
 
const int muonType_
 
const bool PATmuons_
 
const std::vector< int > resfind_
 
const bool sherpa_
 
const edm::InputTag simTracksCollectionName_
 
const bool speedup_
 

Static Protected Attributes

static const double mMu2 = 0.011163612
 
static const unsigned int motherPdgIdArray [6] = {23, 100553, 100553, 553, 100443, 443}
 

Detailed Description

Definition at line 29 of file MuScleFitMuonSelector.h.

Constructor & Destructor Documentation

◆ MuScleFitMuonSelector()

MuScleFitMuonSelector::MuScleFitMuonSelector ( const edm::InputTag muonLabel,
const int  muonType,
const bool  PATmuons,
const std::vector< int > &  resfind,
const bool  speedup,
const std::string &  genParticlesName,
const bool  compareToSimTracks,
const edm::InputTag simTracksCollectionName,
const bool  sherpa,
const bool  debug 
)
inline

Definition at line 31 of file MuScleFitMuonSelector.h.

42  muonType_(muonType),
45  speedup_(speedup),
46  genParticlesName_(genParticlesName),
47  compareToSimTracks_(compareToSimTracks),
48  simTracksCollectionName_(simTracksCollectionName),
49  sherpa_(sherpa),
50  debug_(debug) {}

◆ ~MuScleFitMuonSelector()

MuScleFitMuonSelector::~MuScleFitMuonSelector ( )
inline

Definition at line 51 of file MuScleFitMuonSelector.h.

51 {}

Member Function Documentation

◆ fillMuonCollection()

template<typename T >
std::vector<MuScleFitMuon> MuScleFitMuonSelector::fillMuonCollection ( const std::vector< T > &  tracks)
inlineprotected

Template function used to convert the muon collection to a vector of reco::LeafCandidate.

Definition at line 94 of file MuScleFitMuonSelector.h.

94  {
95  std::vector<MuScleFitMuon> muons;
96  typename std::vector<T>::const_iterator track;
97  for (track = tracks.begin(); track != tracks.end(); ++track) {
99  mu = reco::Particle::LorentzVector(track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + mMu2));
100 
101  Double_t hitsTk(0), hitsMuon(0), ptError(0);
102  if (const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track))) {
103  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
104  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
105  ptError = myMu->innerTrack()->ptError();
106  } else if (const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track))) {
107  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
108  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
109  ptError = myMu->innerTrack()->ptError();
110  } else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))) {
111  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
112  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
113  ptError = myMu->ptError();
114  }
115 
116  MuScleFitMuon muon(mu, track->charge(), ptError, hitsTk, hitsMuon);
117 
118  if (debug_ > 0) {
119  std::cout << "[MuScleFitMuonSelector::fillMuonCollection] after MuScleFitMuon initialization" << std::endl;
120  std::cout << " muon = " << muon << std::endl;
121  }
122 
123  muons.push_back(muon);
124  }
125  return muons;
126  }

References gather_cfg::cout, debug_, mMu2, amptDefaultParameters_cff::mu, HLT_FULL_cff::muon, PDWG_BPHSkim_cff::muons, mathSSE::sqrt(), HLT_FULL_cff::track, and tracks.

Referenced by selectMuons().

◆ findGenMuFromRes() [1/2]

GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const edm::HepMCProduct evtMC)
protected

Definition at line 355 of file MuScleFitMuonSelector.cc.

355  {
356  const HepMC::GenEvent* Evt = evtMC->GetEvent();
357  GenMuonPair muFromRes;
358  //Loop on generated particles
359  for (HepMC::GenEvent::particle_const_iterator part = Evt->particles_begin(); part != Evt->particles_end(); part++) {
360  if (std::abs((*part)->pdg_id()) == 13 && (*part)->status() == 1) {
361  bool fromRes = false;
362  unsigned int motherPdgId = 0;
363  for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
364  mother != (*part)->production_vertex()->particles_end(HepMC::ancestors);
365  ++mother) {
366  motherPdgId = (*mother)->pdg_id();
367 
368  // For sherpa the resonance is not saved. The muons from the resonance can be identified
369  // by having as mother a muon of status 3.
370  if (sherpa_) {
371  if (motherPdgId == 13 && (*mother)->status() == 3)
372  fromRes = true;
373  } else {
374  for (int ires = 0; ires < 6; ++ires) {
375  if (motherPdgId == motherPdgIdArray[ires] && resfind_[ires])
376  fromRes = true;
377  }
378  }
379  }
380  if (fromRes) {
381  if ((*part)->pdg_id() == 13) {
382  // muFromRes.first = (*part)->momentum();
383  muFromRes.mu1 = (lorentzVector(
384  (*part)->momentum().px(), (*part)->momentum().py(), (*part)->momentum().pz(), (*part)->momentum().e()));
385  } else {
386  muFromRes.mu2 = (lorentzVector(
387  (*part)->momentum().px(), (*part)->momentum().py(), (*part)->momentum().pz(), (*part)->momentum().e()));
388  }
389  muFromRes.motherId = motherPdgId;
390  }
391  }
392  }
393  return muFromRes;
394 }

References funct::abs(), edm::HepMCProduct::GetEvent(), ires, GenMuonPair::motherId, motherPdgIdArray, GenMuonPair::mu1, GenMuonPair::mu2, resfind_, and sherpa_.

◆ findGenMuFromRes() [2/2]

GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const reco::GenParticleCollection genParticles)
protected

Definition at line 397 of file MuScleFitMuonSelector.cc.

397  {
398  // std::pair<lorentzVector,lorentzVector> muFromRes;
399  GenMuonPair muFromRes;
400 
401  //Loop on generated particles
402  if (debug_ > 0)
403  std::cout << "Starting loop on " << genParticles->size() << " genParticles" << std::endl;
404  for (reco::GenParticleCollection::const_iterator part = genParticles->begin(); part != genParticles->end(); ++part) {
405  if (debug_ > 0)
406  std::cout << "genParticle has pdgId = " << std::abs(part->pdgId()) << " and status = " << part->status()
407  << std::endl;
408  if (std::abs(part->pdgId()) == 13) { // && part->status()==3) {
409  bool fromRes = false;
410  unsigned int motherPdgId = part->mother()->pdgId();
411  if (debug_ > 0) {
412  std::cout << "Found a muon with mother: " << motherPdgId << std::endl;
413  }
414  for (int ires = 0; ires < 6; ++ires) {
415  // if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true; // changed by EM 2015.07.30
416  // begin of comment
417  // the list of resonances motherPdgIdArray does not contain the photon (PdgId = 21) while ~1% of the
418  // mu+mu- events in the range [50,120] GeV has a photon as the mother.
419  // It needs to be fixed without spoiling the logic of the selection of different resonances
420  // e.g. mixing up onia etc.
421  // end of comment
422  if ((motherPdgId == motherPdgIdArray[ires] && resfind_[ires]) || motherPdgId == 21)
423  fromRes = true;
424  }
425  if (fromRes) {
426  if (debug_ > 0)
427  std::cout << "fromRes = true, motherPdgId = " << motherPdgId << std::endl;
428  const reco::Candidate* status3Muon = &(*part);
429  const reco::Candidate* status1Muon = getStatus1Muon(status3Muon);
430  if (part->pdgId() == 13) {
431  if (status1Muon->p4().pt() != 0)
432  muFromRes.mu1 = MuScleFitMuon(status1Muon->p4(), -1);
433  else
434  muFromRes.mu1 = MuScleFitMuon(status3Muon->p4(), -1);
435  if (debug_ > 0)
436  std::cout << "Found a genMuon - : " << muFromRes.mu1 << std::endl;
437  // muFromRes.first = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
438  // status1Muon->p4().pz(),status1Muon->p4().e()));
439  } else {
440  if (status1Muon->p4().pt() != 0)
441  muFromRes.mu2 = MuScleFitMuon(status1Muon->p4(), +1);
442  else
443  muFromRes.mu2 = MuScleFitMuon(status3Muon->p4(), +1);
444  if (debug_ > 0)
445  std::cout << "Found a genMuon + : " << muFromRes.mu2 << std::endl;
446  // muFromRes.second = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
447  // status1Muon->p4().pz(),status1Muon->p4().e()));
448  }
449  muFromRes.motherId = motherPdgId;
450  }
451  }
452  }
453  return muFromRes;
454 }

References funct::abs(), gather_cfg::cout, debug_, genParticles2HepMC_cfi::genParticles, getStatus1Muon(), ires, GenMuonPair::motherId, motherPdgIdArray, GenMuonPair::mu1, GenMuonPair::mu2, reco::Candidate::p4(), and resfind_.

Referenced by selectGenSimMuons().

◆ findSimMuFromRes()

std::pair< lorentzVector, lorentzVector > MuScleFitMuonSelector::findSimMuFromRes ( const edm::Handle< edm::HepMCProduct > &  evtMC,
const edm::Handle< edm::SimTrackContainer > &  simTracks 
)
protected

Definition at line 456 of file MuScleFitMuonSelector.cc.

457  {
458  //Loop on simulated tracks
459  std::pair<lorentzVector, lorentzVector> simMuFromRes;
460  for (edm::SimTrackContainer::const_iterator simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack) {
461  //Chose muons
462  if (std::abs((*simTrack).type()) == 13) {
463  //If tracks from IP than find mother
464  if ((*simTrack).genpartIndex() > 0) {
465  HepMC::GenParticle* gp = evtMC->GetEvent()->barcode_to_particle((*simTrack).genpartIndex());
466  if (gp != nullptr) {
467  for (HepMC::GenVertex::particle_iterator mother = gp->production_vertex()->particles_begin(HepMC::ancestors);
468  mother != gp->production_vertex()->particles_end(HepMC::ancestors);
469  ++mother) {
470  bool fromRes = false;
471  unsigned int motherPdgId = (*mother)->pdg_id();
472  for (int ires = 0; ires < 6; ++ires) {
473  if ((motherPdgId == motherPdgIdArray[ires] && resfind_[ires]) || motherPdgId == 21)
474  fromRes = true;
475  }
476  if (fromRes) {
477  if (gp->pdg_id() == 13)
478  simMuFromRes.first = lorentzVector(simTrack->momentum().px(),
479  simTrack->momentum().py(),
480  simTrack->momentum().pz(),
481  simTrack->momentum().e());
482  else
483  simMuFromRes.second = lorentzVector(simTrack->momentum().px(),
484  simTrack->momentum().py(),
485  simTrack->momentum().pz(),
486  simTrack->momentum().e());
487  }
488  }
489  }
490  // else LogDebug("MuScleFitUtils") << "WARNING: no matching genParticle found for simTrack" << std::endl;
491  }
492  }
493  }
494  return simMuFromRes;
495 }

References funct::abs(), GenParticle::GenParticle, edm::HepMCProduct::GetEvent(), runTauDisplay::gp, ires, motherPdgIdArray, resfind_, cscDigiValidation_cfi::simTrack, and TrackCandidateProducer_cfi::simTracks.

Referenced by selectSimulatedMuons().

◆ getStatus1Muon()

const reco::Candidate * MuScleFitMuonSelector::getStatus1Muon ( const reco::Candidate status3Muon)

Definition at line 9 of file MuScleFitMuonSelector.cc.

9  {
10  const reco::Candidate* tempMuon = status3Muon;
11  // bool lastCopy = (static_cast<const reco::GenParticle*>(tempMuon))->isLastCopy(); // isLastCopy() likely not enough robust
12  bool isPromptFinalState = static_cast<const reco::GenParticle*>(tempMuon)
13  ->isPromptFinalState(); // pre-CMSSW_74X code: int status = tempStatus1Muon->status();
14  while (tempMuon == nullptr || tempMuon->numberOfDaughters() != 0) {
15  if (isPromptFinalState)
16  break; // pre-CMSSW_74X code: if (status == 1) break;
17  //std::vector<const reco::Candidate*> daughters;
18  for (unsigned int i = 0; i < tempMuon->numberOfDaughters(); ++i) {
19  if (tempMuon->daughter(i)->pdgId() == tempMuon->pdgId()) {
20  tempMuon = tempMuon->daughter(i);
21  isPromptFinalState = static_cast<const reco::GenParticle*>(tempMuon)
22  ->isPromptFinalState(); // pre-CMSSW_74X code: status = tempStatus1Muon->status();
23  break;
24  } else
25  continue;
26  } //for loop
27  } //while loop
28 
29  return tempMuon;
30 }

References reco::Candidate::daughter(), mps_fire::i, reco::Candidate::numberOfDaughters(), and reco::Candidate::pdgId().

Referenced by findGenMuFromRes().

◆ getStatus3Muon()

const reco::Candidate * MuScleFitMuonSelector::getStatus3Muon ( const reco::Candidate status3Muon)

Definition at line 32 of file MuScleFitMuonSelector.cc.

32  {
33  const reco::Candidate* tempMuon = status3Muon;
34  bool lastCopy = static_cast<const reco::GenParticle*>(tempMuon)
35  ->isLastCopyBeforeFSR(); // pre-CMSSW_74X code: int status = tempStatus1Muon->status();
36  while (tempMuon == nullptr || tempMuon->numberOfDaughters() != 0) {
37  if (lastCopy)
38  break; // pre-CMSSW_74X code: if (status == 3) break;
39  //std::vector<const reco::Candidate*> daughters;
40  for (unsigned int i = 0; i < tempMuon->numberOfDaughters(); ++i) {
41  if (tempMuon->daughter(i)->pdgId() == tempMuon->pdgId()) {
42  tempMuon = tempMuon->daughter(i);
43  lastCopy = static_cast<const reco::GenParticle*>(tempMuon)
44  ->isLastCopyBeforeFSR(); // pre-CMSSW_74X code: status = tempStatus1Muon->status();
45  break;
46  } else
47  continue;
48  } //for loop
49  } //while loop
50 
51  return tempMuon;
52 }

References reco::Candidate::daughter(), mps_fire::i, reco::Candidate::numberOfDaughters(), and reco::Candidate::pdgId().

◆ selectGeneratedMuons()

void MuScleFitMuonSelector::selectGeneratedMuons ( const edm::Handle< pat::CompositeCandidateCollection > &  collAll,
const std::vector< const pat::Muon * > &  collMuSel,
std::vector< GenMuonPair > &  genPair,
MuScleFitPlotter plotter 
)
protected

For PATmuons the generator information is read directly from the PAT object.

Definition at line 237 of file MuScleFitMuonSelector.cc.

240  {
241  reco::GenParticleCollection genPatParticles{};
242 
243  //explicitly for JPsi but can be adapted!!!!!
244  for (std::vector<pat::CompositeCandidate>::const_iterator it = collAll->begin(); it != collAll->end(); ++it) {
245  reco::GenParticleRef genJpsi = it->genParticleRef();
246  bool isMatched = (genJpsi.isAvailable() && genJpsi->pdgId() == 443);
247  if (isMatched) {
248  genPatParticles.push_back(*genJpsi.get());
249  }
250  }
251 
252  if (collMuSel.size() == 2) {
253  reco::GenParticleRef genMu1 = collMuSel[0]->genParticleRef();
254  reco::GenParticleRef genMu2 = collMuSel[1]->genParticleRef();
255  bool isMuMatched = (genMu1.isAvailable() && genMu2.isAvailable() && genMu1->pdgId() * genMu2->pdgId() == -169);
256  if (isMuMatched) {
257  genPatParticles.push_back(*genMu1.get());
258  genPatParticles.push_back(*genMu2.get());
259 
260  unsigned int motherId = 0;
261  if (genMu1->mother() != nullptr) {
262  motherId = genMu1->mother()->pdgId();
263  }
264  if (genMu1->pdgId() == 13)
265  genPair.push_back(GenMuonPair(genMu1.get()->p4(), genMu2.get()->p4(), motherId));
266  else
267  // genPair.push_back(std::make_pair(genMu2.get()->p4(),genMu1.get()->p4()) );
268  genPair.push_back(GenMuonPair(genMu2.get()->p4(), genMu1.get()->p4(), motherId));
269 
270  plotter->fillGen(genPatParticles, true);
271 
272  if (debug_ > 0)
273  std::cout << "Found genParticles in PAT" << std::endl;
274  } else {
275  std::cout << "No recomuon selected so no access to generated info" << std::endl;
276  // Fill it in any case, otherwise it will not be in sync with the event number
277  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
278  genPair.push_back(GenMuonPair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.), 0));
279  }
280  } else {
281  std::cout << "No recomuon selected so no access to generated info" << std::endl;
282  // Fill it in any case, otherwise it will not be in sync with the event number
283  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
284  genPair.push_back(GenMuonPair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.), 0));
285  }
286  if (debug_ > 0) {
287  std::cout << "genParticles:" << std::endl;
288  // std::cout << genPair.back().first << " , " << genPair.back().second << std::endl;
289  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
290  }
291 }

References gather_cfg::cout, debug_, edm::Ref< C, T, F >::get(), edm::Ref< C, T, F >::isAvailable(), trackerHitRTTI::isMatched(), objects.autophobj::motherId, and trackingPlots::plotter.

◆ selectGenSimMuons()

void MuScleFitMuonSelector::selectGenSimMuons ( const edm::Event event,
std::vector< GenMuonPair > &  genPair,
std::vector< std::pair< lorentzVector, lorentzVector > > &  simPair,
MuScleFitPlotter plotter 
)
protected

Definition at line 293 of file MuScleFitMuonSelector.cc.

296  {
297  // Find and store in histograms the generated and simulated resonance and muons
298  // ----------------------------------------------------------------------------
301 
302  // Fill gen information only in the first loop
303  bool ifHepMC = false;
304 
305  event.getByLabel(genParticlesName_, evtMC);
306  event.getByLabel(genParticlesName_, genParticles);
307  if (evtMC.isValid()) {
308  genPair.push_back(findGenMuFromRes(evtMC.product()));
309  plotter->fillGen(*evtMC, sherpa_);
310  ifHepMC = true;
311  if (debug_ > 0)
312  std::cout << "Found hepMC" << std::endl;
313  } else if (genParticles.isValid()) {
314  genPair.push_back(findGenMuFromRes(genParticles.product()));
315  plotter->fillGen(*genParticles);
316  if (debug_ > 0)
317  std::cout << "Found genParticles" << std::endl;
318  } else {
319  std::cout << "ERROR "
320  << "non generation info and speedup true!!!!!!!!!!!!" << std::endl;
321  // Fill it in any case, otherwise it will not be in sync with the event number
322  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
323  genPair.push_back(GenMuonPair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.), 0));
324  }
325  if (debug_ > 0) {
326  std::cout << "genParticles:" << std::endl;
327  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
328  }
329  selectSimulatedMuons(event, ifHepMC, evtMC, simPair, plotter);
330 }

References gather_cfg::cout, debug_, findGenMuFromRes(), genParticles2HepMC_cfi::genParticles, genParticlesName_, edm::HandleBase::isValid(), trackingPlots::plotter, edm::Handle< T >::product(), selectSimulatedMuons(), and sherpa_.

Referenced by selectMuons().

◆ selectMuons()

void MuScleFitMuonSelector::selectMuons ( const edm::Event event,
std::vector< MuScleFitMuon > &  muons,
std::vector< GenMuonPair > &  genPair,
std::vector< std::pair< lorentzVector, lorentzVector > > &  simPair,
MuScleFitPlotter plotter 
)

Main method used to select muons of type specified by muonType_ from the collection specified by muonLabel_ and PATmuons_.

Definition at line 85 of file MuScleFitMuonSelector.cc.

89  {
91  event.getByLabel("onia2MuMuPatTrkTrk", collAll);
92  if (!collAll.isValid()) {
93  edm::LogWarning("MuScleFitUtils") << "J/psi not present in event!";
94  }
95  std::vector<const pat::Muon*> collMuSel;
96 
97  //================onia cuts===========================/
98 
99  if (muonType_ <= -1 && PATmuons_) {
100  std::vector<const pat::CompositeCandidate*> collSelGG;
101  std::vector<const pat::CompositeCandidate*> collSelGT;
102  std::vector<const pat::CompositeCandidate*> collSelTT;
103  if (collAll.isValid()) {
104  for (std::vector<pat::CompositeCandidate>::const_iterator it = collAll->begin(); it != collAll->end(); ++it) {
105  const pat::CompositeCandidate* cand = &(*it);
106  // cout << "Now checking candidate of type " << theJpsiCat << " with pt = " << cand->pt() << endl;
107  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(cand->daughter("muon1"));
108  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(cand->daughter("muon2"));
109 
110  if ((muon1->charge() * muon2->charge()) > 0)
111  continue;
112  // global + global?
113  if (muon1->isGlobalMuon() && muon2->isGlobalMuon()) {
114  if (selGlobalMuon(muon1) && selGlobalMuon(muon2) && cand->userFloat("vProb") > 0.001) {
115  collSelGG.push_back(cand);
116  continue;
117  }
118  }
119  // global + tracker? (x2)
120  if (muon1->isGlobalMuon() && muon2->isTrackerMuon()) {
121  if (selGlobalMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
122  collSelGT.push_back(cand);
123  continue;
124  }
125  }
126  if (muon2->isGlobalMuon() && muon1->isTrackerMuon()) {
127  if (selGlobalMuon(muon2) && selTrackerMuon(muon1) && cand->userFloat("vProb") > 0.001) {
128  collSelGT.push_back(cand);
129  continue;
130  }
131  }
132  // tracker + tracker?
133  if (muon1->isTrackerMuon() && muon2->isTrackerMuon()) {
134  if (selTrackerMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
135  collSelTT.push_back(cand);
136  continue;
137  }
138  }
139  }
140  }
141  // Split them in independent collections if using muonType_ == -2, -3 or -4. Take them all if muonType_ == -1.
142  std::vector<reco::Track> tracks;
143  if (!collSelGG.empty()) {
144  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
145  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon1"));
146  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon2"));
147  if (muonType_ == -1 || muonType_ == -2) {
148  tracks.push_back(*(muon1->innerTrack()));
149  tracks.push_back(*(muon2->innerTrack()));
150  collMuSel.push_back(muon1);
151  collMuSel.push_back(muon2);
152  }
153  } else if (collSelGG.empty() && !collSelGT.empty()) {
154  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
155  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon1"));
156  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon2"));
157  if (muonType_ == -1 || muonType_ == -3) {
158  tracks.push_back(*(muon1->innerTrack()));
159  tracks.push_back(*(muon2->innerTrack()));
160  collMuSel.push_back(muon1);
161  collMuSel.push_back(muon2);
162  }
163  } else if (collSelGG.empty() && collSelGT.empty() && !collSelTT.empty()) {
164  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
165  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon1"));
166  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon2"));
167  if (muonType_ == -1 || muonType_ == -4) {
168  tracks.push_back(*(muon1->innerTrack()));
169  tracks.push_back(*(muon2->innerTrack()));
170  collMuSel.push_back(muon1);
171  collMuSel.push_back(muon2);
172  }
173  }
174  if (tracks.size() != 2 && !tracks.empty()) {
175  std::cout << "ERROR strange number of muons selected by onia cuts!" << std::endl;
176  abort();
177  }
179  } else if ((muonType_ < 4 && muonType_ >= 0) || muonType_ >= 10) { // Muons (glb,sta,trk)
180  std::vector<reco::Track> tracks;
181  if (PATmuons_ == true) {
183  event.getByLabel(muonLabel_, allMuons);
184  if (muonType_ == 0) {
185  // Take directly the muon
187  } else {
188  for (std::vector<pat::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
189  //std::cout<<"pat muon is global "<<muon->isGlobalMuon()<<std::endl;
191  }
193  }
194  } else {
196  event.getByLabel(muonLabel_, allMuons);
197  if (muonType_ == 0) {
198  // Take directly the muon
200  } else {
201  for (std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
203  }
205  }
206  }
207  } else if (muonType_ == 4) { //CaloMuons
209  event.getByLabel(muonLabel_, caloMuons);
210  std::vector<reco::Track> tracks;
211  for (std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon != caloMuons->end(); ++muon) {
212  tracks.push_back(*(muon->track()));
213  }
215  }
216 
217  else if (muonType_ == 5) { // Inner tracker tracks
219  event.getByLabel(muonLabel_, tracks);
221  }
222  plotter->fillRec(muons);
223 
224  // Generation and simulation part
225  if (speedup_ == false) {
226  if (PATmuons_) {
227  // EM 2015.04.02 temporary fix to run on MINIAODSIM (which contains PAT muons) but not the "onia2MuMuPatTrkTrk" collection
228  // selectGeneratedMuons(collAll, collMuSel, genPair, plotter);
229  selectGenSimMuons(event, genPair, simPair, plotter);
230  } else {
231  selectGenSimMuons(event, genPair, simPair, plotter);
232  }
233  }
234 }

References allMuons_cfi::allMuons, mergedMuons_cfi::caloMuons, reco::LeafCandidate::charge(), gather_cfg::cout, fillMuonCollection(), pat::Muon::innerTrack(), reco::Muon::isGlobalMuon(), reco::Muon::isTrackerMuon(), edm::HandleBase::isValid(), HLT_FULL_cff::muon, muonLabel_, PDWG_BPHSkim_cff::muons, muonType_, PATmuons_, trackingPlots::plotter, selectGenSimMuons(), selGlobalMuon(), selTrackerMuon(), speedup_, takeSelectedMuonType(), and tracks.

◆ selectSimulatedMuons()

void MuScleFitMuonSelector::selectSimulatedMuons ( const edm::Event event,
const bool  ifHepMC,
edm::Handle< edm::HepMCProduct evtMC,
std::vector< std::pair< lorentzVector, lorentzVector > > &  simPair,
MuScleFitPlotter plotter 
)
protected

Definition at line 332 of file MuScleFitMuonSelector.cc.

336  {
338  bool simTracksFound = false;
339  event.getByLabel(simTracksCollectionName_, simTracks);
340  if (simTracks.isValid()) {
341  plotter->fillSim(simTracks);
342  if (ifHepMC) {
343  simPair.push_back(findSimMuFromRes(evtMC, simTracks));
344  simTracksFound = true;
345  plotter->fillGenSim(evtMC, simTracks);
346  }
347  } else {
348  std::cout << "SimTracks not existent" << std::endl;
349  }
350  if (!simTracksFound) {
351  simPair.push_back(std::make_pair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.)));
352  }
353 }

References gather_cfg::cout, findSimMuFromRes(), trackingPlots::plotter, TrackCandidateProducer_cfi::simTracks, and simTracksCollectionName_.

Referenced by selectGenSimMuons().

◆ selGlobalMuon()

bool MuScleFitMuonSelector::selGlobalMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select globalMuons.

Definition at line 54 of file MuScleFitMuonSelector.cc.

54  {
55  reco::TrackRef iTrack = aMuon->innerTrack();
56  const reco::HitPattern& p = iTrack->hitPattern();
57 
58  reco::TrackRef gTrack = aMuon->globalTrack();
59  const reco::HitPattern& q = gTrack->hitPattern();
60 
61  return ( //isMuonInAccept(aMuon) &&// no acceptance cuts!
62  iTrack->found() > 11 && gTrack->chi2() / gTrack->ndof() < 20.0 && q.numberOfValidMuonHits() > 0 &&
63  iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->muonID("TrackerMuonArbitrated") &&
64  aMuon->muonID("TMLastStationAngTight") && p.pixelLayersWithMeasurement() > 1 &&
65  std::abs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
66  std::abs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
67  );
68 }

References funct::abs(), pat::Muon::globalTrack(), pat::Muon::innerTrack(), pat::Muon::muonID(), AlCaHLTBitMon_ParallelJobs::p, and submitPVResolutionJobs::q.

Referenced by selectMuons().

◆ selTrackerMuon()

bool MuScleFitMuonSelector::selTrackerMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select trackerMuons.

Definition at line 70 of file MuScleFitMuonSelector.cc.

70  {
71  reco::TrackRef iTrack = aMuon->innerTrack();
72  const reco::HitPattern& p = iTrack->hitPattern();
73 
74  return ( //isMuonInAccept(aMuon) // no acceptance cuts!
75  iTrack->found() > 11 && iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->muonID("TrackerMuonArbitrated") &&
76  aMuon->muonID("TMLastStationAngTight") && p.pixelLayersWithMeasurement() > 1 &&
77  std::abs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
78  std::abs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
79  );
80 }

References funct::abs(), pat::Muon::innerTrack(), pat::Muon::muonID(), and AlCaHLTBitMon_ParallelJobs::p.

Referenced by selectMuons().

◆ takeSelectedMuonType()

template<typename T >
void MuScleFitMuonSelector::takeSelectedMuonType ( const T muon,
std::vector< reco::Track > &  tracks 
)
inlineprotected

Template function used to extract the selected muon type from the muon collection.

Definition at line 130 of file MuScleFitMuonSelector.h.

130  {
131  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
132  //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
133  // to avoid double counting of the same muon
134  if (muon->isGlobalMuon() && muonType_ == 1)
135  tracks.push_back(*(muon->globalTrack()));
136  else if (muon->isStandAloneMuon() && muonType_ == 2)
137  tracks.push_back(*(muon->outerTrack()));
138  else if (muon->isTrackerMuon() && muonType_ == 3)
139  tracks.push_back(*(muon->innerTrack()));
140 
141  else if (muonType_ == 10 && !(muon->isStandAloneMuon())) //particular case!!
142  tracks.push_back(*(muon->innerTrack()));
143  else if (muonType_ == 11 && muon->isGlobalMuon())
144  tracks.push_back(*(muon->innerTrack()));
145  else if (muonType_ == 13 && muon->isTrackerMuon())
146  tracks.push_back(*(muon->innerTrack()));
147  }

References muonType_, and tracks.

Referenced by selectMuons().

Member Data Documentation

◆ compareToSimTracks_

const bool MuScleFitMuonSelector::compareToSimTracks_
protected

Definition at line 155 of file MuScleFitMuonSelector.h.

◆ debug_

const bool MuScleFitMuonSelector::debug_
protected

◆ genParticlesName_

const std::string MuScleFitMuonSelector::genParticlesName_
protected

Definition at line 154 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

◆ mMu2

const double MuScleFitMuonSelector::mMu2 = 0.011163612
staticprotected

Definition at line 159 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

◆ motherPdgIdArray

const unsigned int MuScleFitMuonSelector::motherPdgIdArray = {23, 100553, 100553, 553, 100443, 443}
staticprotected

Definition at line 160 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

◆ muonLabel_

const edm::InputTag MuScleFitMuonSelector::muonLabel_
protected

Definition at line 149 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ muonType_

const int MuScleFitMuonSelector::muonType_
protected

Definition at line 150 of file MuScleFitMuonSelector.h.

Referenced by selectMuons(), and takeSelectedMuonType().

◆ PATmuons_

const bool MuScleFitMuonSelector::PATmuons_
protected

Definition at line 151 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ resfind_

const std::vector<int> MuScleFitMuonSelector::resfind_
protected

Definition at line 152 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

◆ sherpa_

const bool MuScleFitMuonSelector::sherpa_
protected

Definition at line 157 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and selectGenSimMuons().

◆ simTracksCollectionName_

const edm::InputTag MuScleFitMuonSelector::simTracksCollectionName_
protected

Definition at line 156 of file MuScleFitMuonSelector.h.

Referenced by selectSimulatedMuons().

◆ speedup_

const bool MuScleFitMuonSelector::speedup_
protected

Definition at line 153 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

reco::Candidate::daughter
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
GenMuonPair::mu2
MuScleFitMuon mu2
Definition: GenMuonPair.h:52
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
cscDigiValidation_cfi.simTrack
simTrack
Definition: cscDigiValidation_cfi.py:29
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
genParticles2HepMC_cfi.genParticles
genParticles
Definition: genParticles2HepMC_cfi.py:4
edm::Handle::product
T const * product() const
Definition: Handle.h:70
MuScleFitMuonSelector::compareToSimTracks_
const bool compareToSimTracks_
Definition: MuScleFitMuonSelector.h:155
muon
Definition: MuonCocktails.h:17
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
MuScleFitMuonSelector::motherPdgIdArray
static const unsigned int motherPdgIdArray[6]
Definition: MuScleFitMuonSelector.h:160
edm::Ref::isAvailable
bool isAvailable() const
Definition: Ref.h:537
GenMuonPair
Definition: GenMuonPair.h:19
pat::CompositeCandidate
Analysis-level particle class.
Definition: CompositeCandidate.h:31
MuScleFitMuonSelector::findSimMuFromRes
std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
Definition: MuScleFitMuonSelector.cc:456
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MuScleFitMuonSelector::sherpa_
const bool sherpa_
Definition: MuScleFitMuonSelector.h:157
GenMuonPair::motherId
Int_t motherId
Definition: GenMuonPair.h:53
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
commonCuts_cff.muonLabel
muonLabel
Definition: commonCuts_cff.py:13
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
MuScleFit_cfi.PATmuons
PATmuons
Definition: MuScleFit_cfi.py:43
MuScleFitMuonSelector::muonType_
const int muonType_
Definition: MuScleFitMuonSelector.h:150
MuScleFitMuonSelector::findGenMuFromRes
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
Definition: MuScleFitMuonSelector.cc:397
TrackCandidateProducer_cfi.simTracks
simTracks
Definition: TrackCandidateProducer_cfi.py:15
MuScleFitMuon
Definition: Muon.h:14
MuScleFitMuonSelector::selTrackerMuon
bool selTrackerMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select trackerMuons.
Definition: MuScleFitMuonSelector.cc:70
MuScleFitMuonSelector::debug_
const bool debug_
Definition: MuScleFitMuonSelector.h:158
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
MuScleFitMuonSelector::muonLabel_
const edm::InputTag muonLabel_
Definition: MuScleFitMuonSelector.h:149
edm::Handle< edm::HepMCProduct >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
MuScleFitMuonSelector::selGlobalMuon
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
Definition: MuScleFitMuonSelector.cc:54
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
reco::Muon
Definition: Muon.h:27
edm::Ref< GenParticleCollection >
MuScleFitMuonSelector::PATmuons_
const bool PATmuons_
Definition: MuScleFitMuonSelector.h:151
GenMuonPair::mu1
MuScleFitMuon mu1
Definition: GenMuonPair.h:51
ires
int ires[2]
Definition: CascadeWrapper.h:19
reco::HitPattern
Definition: HitPattern.h:147
debug
#define debug
Definition: HDRShower.cc:19
part
part
Definition: HCALResponse.h:20
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11725
MuScleFitMuonSelector::resfind_
const std::vector< int > resfind_
Definition: MuScleFitMuonSelector.h:152
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MuScleFitGenFilter_cfi.resfind
resfind
Definition: MuScleFitGenFilter_cfi.py:11
reco::Track
Definition: Track.h:27
reco::Candidate::numberOfDaughters
virtual size_type numberOfDaughters() const =0
number of daughters
MuScleFitMuonSelector::genParticlesName_
const std::string genParticlesName_
Definition: MuScleFitMuonSelector.h:154
reco::Muon::isGlobalMuon
bool isGlobalMuon() const override
Definition: Muon.h:299
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
trackerHitRTTI::isMatched
bool isMatched(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:33
MuScleFitMuonSelector::selectSimulatedMuons
void selectSimulatedMuons(const edm::Event &event, const bool ifHepMC, edm::Handle< edm::HepMCProduct > evtMC, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
Definition: MuScleFitMuonSelector.cc:332
allMuons_cfi.allMuons
allMuons
Definition: allMuons_cfi.py:3
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
lorentzVector
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
MuScleFitMuonSelector::selectGenSimMuons
void selectGenSimMuons(const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
Definition: MuScleFitMuonSelector.cc:293
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:176
cand
Definition: decayParser.h:32
mergedMuons_cfi.caloMuons
caloMuons
Definition: mergedMuons_cfi.py:7
trackingPlots.plotter
plotter
Definition: trackingPlots.py:1298
reco::LeafCandidate::charge
int charge() const final
electric charge
Definition: LeafCandidate.h:106
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84
MuScleFitMuonSelector::simTracksCollectionName_
const edm::InputTag simTracksCollectionName_
Definition: MuScleFitMuonSelector.h:156
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
reco::Candidate::pdgId
virtual int pdgId() const =0
PDG identifier.
pat::Muon::globalTrack
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon)
Definition: Muon.h:80
reco::Candidate
Definition: Candidate.h:27
objects.autophobj.motherId
motherId
Definition: autophobj.py:237
MuScleFitMuonSelector::getStatus1Muon
const reco::Candidate * getStatus1Muon(const reco::Candidate *status3Muon)
Definition: MuScleFitMuonSelector.cc:9
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
reco::Muon::isTrackerMuon
bool isTrackerMuon() const override
Definition: Muon.h:300
MuScleFitMuonSelector::takeSelectedMuonType
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template function used to extract the selected muon type from the muon collection.
Definition: MuScleFitMuonSelector.h:130
MuScleFitMuonSelector::mMu2
static const double mMu2
Definition: MuScleFitMuonSelector.h:159
MuScleFitMuonSelector::fillMuonCollection
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
Template function used to convert the muon collection to a vector of reco::LeafCandidate.
Definition: MuScleFitMuonSelector.h:94
pat::Muon::muonID
bool muonID(const std::string &name) const
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MuScleFitMuonSelector::speedup_
const bool speedup_
Definition: MuScleFitMuonSelector.h:153
pat::Muon::innerTrack
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon)
Definition: Muon.h:72
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1