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 (edm::ConsumesCollector &iC, 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 ()=default
 

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 reco::GenParticleCollection *genParticles)
 
GenMuonPair findGenMuFromRes (const edm::HepMCProduct *evtMC)
 
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 edm::EDGetTokenT< reco::CaloMuonCollectioncaloMuonToken_
 
const bool compareToSimTracks_
 
const bool debug_
 
const edm::EDGetTokenT< edm::HepMCProductevtMCToken_
 
const std::string genParticlesName_
 
const edm::EDGetTokenT< reco::GenParticleCollectiongenParticleToken_
 
const edm::InputTag muonLabel_
 
const int muonType_
 
const edm::EDGetTokenT< pat::CompositeCandidateCollectiononia2MuMuToken_
 
const bool PATmuons_
 
const edm::EDGetTokenT< pat::MuonCollectionpatMuonToken_
 
const edm::EDGetTokenT< reco::MuonCollectionrecoMuonToken_
 
const std::vector< int > resfind_
 
const bool sherpa_
 
const edm::InputTag simTracksCollectionName_
 
const edm::EDGetTokenT< edm::SimTrackContainersimTrackToken_
 
const bool speedup_
 
const edm::EDGetTokenT< reco::TrackCollectiontrackCollectionToken_
 

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 30 of file MuScleFitMuonSelector.h.

Constructor & Destructor Documentation

◆ MuScleFitMuonSelector()

MuScleFitMuonSelector::MuScleFitMuonSelector ( edm::ConsumesCollector iC,
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 32 of file MuScleFitMuonSelector.h.

44  muonType_(muonType),
48  genParticlesName_(genParticlesName),
49  compareToSimTracks_(compareToSimTracks),
50  simTracksCollectionName_(simTracksCollectionName),
51  sherpa_(sherpa),
52  debug_(debug),
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
const std::string genParticlesName_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< CaloMuon > CaloMuonCollection
collection of Muon objects
Definition: MuonFwd.h:27
const edm::EDGetTokenT< edm::HepMCProduct > evtMCToken_
const edm::EDGetTokenT< reco::CaloMuonCollection > caloMuonToken_
const edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const edm::EDGetTokenT< pat::MuonCollection > patMuonToken_
const edm::InputTag muonLabel_
const edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken_
#define debug
Definition: HDRShower.cc:19
std::vector< CompositeCandidate > CompositeCandidateCollection
std::vector< Muon > MuonCollection
Definition: Muon.h:35
const edm::InputTag simTracksCollectionName_
const edm::EDGetTokenT< reco::MuonCollection > recoMuonToken_
const edm::EDGetTokenT< pat::CompositeCandidateCollection > onia2MuMuToken_
const std::vector< int > resfind_
std::vector< SimTrack > SimTrackContainer
const edm::EDGetTokenT< reco::TrackCollection > trackCollectionToken_

◆ ~MuScleFitMuonSelector()

MuScleFitMuonSelector::~MuScleFitMuonSelector ( )
default

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 104 of file MuScleFitMuonSelector.h.

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

Referenced by selectMuons().

104  {
105  std::vector<MuScleFitMuon> muons;
106  typename std::vector<T>::const_iterator track;
107  for (track = tracks.begin(); track != tracks.end(); ++track) {
109  mu = reco::Particle::LorentzVector(track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + mMu2));
110 
111  Double_t hitsTk(0), hitsMuon(0), ptError(0);
112  if (const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track))) {
113  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
114  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
115  ptError = myMu->innerTrack()->ptError();
116  } else if (const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track))) {
117  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
118  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
119  ptError = myMu->innerTrack()->ptError();
120  } else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))) {
121  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
122  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
123  ptError = myMu->ptError();
124  }
125 
126  MuScleFitMuon muon(mu, track->charge(), ptError, hitsTk, hitsMuon);
127 
128  if (debug_ > 0) {
129  std::cout << "[MuScleFitMuonSelector::fillMuonCollection] after MuScleFitMuon initialization" << std::endl;
130  std::cout << " muon = " << muon << std::endl;
131  }
132 
133  muons.push_back(muon);
134  }
135  return muons;
136  }
static const double mMu2
T sqrt(T t)
Definition: SSEVec.h:19
auto const & tracks
cannot be loose
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Analysis-level muon class.
Definition: Muon.h:51

◆ findGenMuFromRes() [1/2]

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

Definition at line 388 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons().

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

◆ findGenMuFromRes() [2/2]

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

Definition at line 346 of file MuScleFitMuonSelector.cc.

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

346  {
347  const HepMC::GenEvent* Evt = evtMC->GetEvent();
348  GenMuonPair muFromRes;
349  //Loop on generated particles
350  for (HepMC::GenEvent::particle_const_iterator part = Evt->particles_begin(); part != Evt->particles_end(); part++) {
351  if (std::abs((*part)->pdg_id()) == 13 && (*part)->status() == 1) {
352  bool fromRes = false;
353  unsigned int motherPdgId = 0;
354  for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
355  mother != (*part)->production_vertex()->particles_end(HepMC::ancestors);
356  ++mother) {
357  motherPdgId = (*mother)->pdg_id();
358 
359  // For sherpa the resonance is not saved. The muons from the resonance can be identified
360  // by having as mother a muon of status 3.
361  if (sherpa_) {
362  if (motherPdgId == 13 && (*mother)->status() == 3)
363  fromRes = true;
364  } else {
365  for (int ires = 0; ires < 6; ++ires) {
366  if (motherPdgId == motherPdgIdArray[ires] && resfind_[ires])
367  fromRes = true;
368  }
369  }
370  }
371  if (fromRes) {
372  if ((*part)->pdg_id() == 13) {
373  // muFromRes.first = (*part)->momentum();
374  muFromRes.mu1 = (lorentzVector(
375  (*part)->momentum().px(), (*part)->momentum().py(), (*part)->momentum().pz(), (*part)->momentum().e()));
376  } else {
377  muFromRes.mu2 = (lorentzVector(
378  (*part)->momentum().px(), (*part)->momentum().py(), (*part)->momentum().pz(), (*part)->momentum().e()));
379  }
380  muFromRes.motherId = motherPdgId;
381  }
382  }
383  }
384  return muFromRes;
385 }
MuScleFitMuon mu1
Definition: GenMuonPair.h:51
Int_t motherId
Definition: GenMuonPair.h:53
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
static const unsigned int motherPdgIdArray[6]
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
part
Definition: HCALResponse.h:20
const std::vector< int > resfind_
MuScleFitMuon mu2
Definition: GenMuonPair.h:52

◆ findSimMuFromRes()

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

Definition at line 447 of file MuScleFitMuonSelector.cc.

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

Referenced by selectSimulatedMuons().

448  {
449  //Loop on simulated tracks
450  std::pair<lorentzVector, lorentzVector> simMuFromRes;
451  for (edm::SimTrackContainer::const_iterator simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack) {
452  //Chose muons
453  if (std::abs((*simTrack).type()) == 13) {
454  //If tracks from IP than find mother
455  if ((*simTrack).genpartIndex() > 0) {
456  HepMC::GenParticle* gp = evtMC->GetEvent()->barcode_to_particle((*simTrack).genpartIndex());
457  if (gp != nullptr) {
458  for (HepMC::GenVertex::particle_iterator mother = gp->production_vertex()->particles_begin(HepMC::ancestors);
459  mother != gp->production_vertex()->particles_end(HepMC::ancestors);
460  ++mother) {
461  bool fromRes = false;
462  unsigned int motherPdgId = (*mother)->pdg_id();
463  for (int ires = 0; ires < 6; ++ires) {
464  if ((motherPdgId == motherPdgIdArray[ires] && resfind_[ires]) || motherPdgId == 21)
465  fromRes = true;
466  }
467  if (fromRes) {
468  if (gp->pdg_id() == 13)
469  simMuFromRes.first = lorentzVector(simTrack->momentum().px(),
470  simTrack->momentum().py(),
471  simTrack->momentum().pz(),
472  simTrack->momentum().e());
473  else
474  simMuFromRes.second = lorentzVector(simTrack->momentum().px(),
475  simTrack->momentum().py(),
476  simTrack->momentum().pz(),
477  simTrack->momentum().e());
478  }
479  }
480  }
481  // else LogDebug("MuScleFitUtils") << "WARNING: no matching genParticle found for simTrack" << std::endl;
482  }
483  }
484  }
485  return simMuFromRes;
486 }
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
static const unsigned int motherPdgIdArray[6]
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
const std::vector< int > resfind_

◆ getStatus1Muon()

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

Definition at line 9 of file MuScleFitMuonSelector.cc.

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

Referenced by findGenMuFromRes().

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 }
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual size_type numberOfDaughters() const =0
number of daughters
virtual int pdgId() const =0
PDG identifier.

◆ getStatus3Muon()

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

Definition at line 32 of file MuScleFitMuonSelector.cc.

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

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 }
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual size_type numberOfDaughters() const =0
number of daughters
virtual int pdgId() const =0
PDG identifier.

◆ 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 232 of file MuScleFitMuonSelector.cc.

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.

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

◆ 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 288 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

291  {
292  // Find and store in histograms the generated and simulated resonance and muons
293  // ----------------------------------------------------------------------------
294  edm::Handle<edm::HepMCProduct> evtMC = event.getHandle(evtMCToken_);
296 
297  // Fill gen information only in the first loop
298  bool ifHepMC = false;
299  if (evtMC.isValid()) {
300  genPair.push_back(findGenMuFromRes(evtMC.product()));
301  plotter->fillGen(*evtMC, sherpa_);
302  ifHepMC = true;
303  if (debug_ > 0)
304  std::cout << "Found hepMC" << std::endl;
305  } else if (genParticles.isValid()) {
306  genPair.push_back(findGenMuFromRes(genParticles.product()));
307  plotter->fillGen(*genParticles);
308  if (debug_ > 0)
309  std::cout << "Found genParticles" << std::endl;
310  } else {
311  std::cout << "ERROR "
312  << "non generation info and speedup true!!!!!!!!!!!!" << std::endl;
313  // Fill it in any case, otherwise it will not be in sync with the event number
314  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
315  genPair.push_back(GenMuonPair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.), 0));
316  }
317  if (debug_ > 0) {
318  std::cout << "genParticles:" << std::endl;
319  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
320  }
321  selectSimulatedMuons(event, ifHepMC, evtMC, simPair, plotter);
322 }
T const * product() const
Definition: Handle.h:70
const edm::EDGetTokenT< edm::HepMCProduct > evtMCToken_
void selectSimulatedMuons(const edm::Event &event, const bool ifHepMC, edm::Handle< edm::HepMCProduct > evtMC, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
const edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
bool isValid() const
Definition: HandleBase.h:70
Definition: event.py:1

◆ 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.

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

89  {
91  if (!collAll.isValid()) {
92  edm::LogWarning("MuScleFitUtils") << "J/psi not present in event!";
93  }
94  std::vector<const pat::Muon*> collMuSel;
95 
96  //================onia cuts===========================/
97 
98  if (muonType_ <= -1 && PATmuons_) {
99  std::vector<const pat::CompositeCandidate*> collSelGG;
100  std::vector<const pat::CompositeCandidate*> collSelGT;
101  std::vector<const pat::CompositeCandidate*> collSelTT;
102  if (collAll.isValid()) {
103  for (std::vector<pat::CompositeCandidate>::const_iterator it = collAll->begin(); it != collAll->end(); ++it) {
104  const pat::CompositeCandidate* cand = &(*it);
105  // cout << "Now checking candidate of type " << theJpsiCat << " with pt = " << cand->pt() << endl;
106  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(cand->daughter("muon1"));
107  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(cand->daughter("muon2"));
108 
109  if ((muon1->charge() * muon2->charge()) > 0)
110  continue;
111  // global + global?
112  if (muon1->isGlobalMuon() && muon2->isGlobalMuon()) {
113  if (selGlobalMuon(muon1) && selGlobalMuon(muon2) && cand->userFloat("vProb") > 0.001) {
114  collSelGG.push_back(cand);
115  continue;
116  }
117  }
118  // global + tracker? (x2)
119  if (muon1->isGlobalMuon() && muon2->isTrackerMuon()) {
120  if (selGlobalMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
121  collSelGT.push_back(cand);
122  continue;
123  }
124  }
125  if (muon2->isGlobalMuon() && muon1->isTrackerMuon()) {
126  if (selGlobalMuon(muon2) && selTrackerMuon(muon1) && cand->userFloat("vProb") > 0.001) {
127  collSelGT.push_back(cand);
128  continue;
129  }
130  }
131  // tracker + tracker?
132  if (muon1->isTrackerMuon() && muon2->isTrackerMuon()) {
133  if (selTrackerMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
134  collSelTT.push_back(cand);
135  continue;
136  }
137  }
138  }
139  }
140  // Split them in independent collections if using muonType_ == -2, -3 or -4. Take them all if muonType_ == -1.
141  std::vector<reco::Track> tracks;
142  if (!collSelGG.empty()) {
143  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
144  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon1"));
145  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon2"));
146  if (muonType_ == -1 || muonType_ == -2) {
147  tracks.push_back(*(muon1->innerTrack()));
148  tracks.push_back(*(muon2->innerTrack()));
149  collMuSel.push_back(muon1);
150  collMuSel.push_back(muon2);
151  }
152  } else if (collSelGG.empty() && !collSelGT.empty()) {
153  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
154  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon1"));
155  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon2"));
156  if (muonType_ == -1 || muonType_ == -3) {
157  tracks.push_back(*(muon1->innerTrack()));
158  tracks.push_back(*(muon2->innerTrack()));
159  collMuSel.push_back(muon1);
160  collMuSel.push_back(muon2);
161  }
162  } else if (collSelGG.empty() && collSelGT.empty() && !collSelTT.empty()) {
163  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
164  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon1"));
165  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon2"));
166  if (muonType_ == -1 || muonType_ == -4) {
167  tracks.push_back(*(muon1->innerTrack()));
168  tracks.push_back(*(muon2->innerTrack()));
169  collMuSel.push_back(muon1);
170  collMuSel.push_back(muon2);
171  }
172  }
173  if (tracks.size() != 2 && !tracks.empty()) {
174  std::cout << "ERROR strange number of muons selected by onia cuts!" << std::endl;
175  abort();
176  }
178  } else if ((muonType_ < 4 && muonType_ >= 0) || muonType_ >= 10) { // Muons (glb,sta,trk)
179  std::vector<reco::Track> tracks;
180  if (PATmuons_ == true) {
182  if (muonType_ == 0) {
183  // Take directly the muon
185  } else {
186  for (std::vector<pat::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
187  //std::cout<<"pat muon is global "<<muon->isGlobalMuon()<<std::endl;
189  }
191  }
192  } else {
194  if (muonType_ == 0) {
195  // Take directly the muon
197  } else {
198  for (std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
200  }
202  }
203  }
204  } else if (muonType_ == 4) { //CaloMuons
206  std::vector<reco::Track> tracks;
207  for (std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon != caloMuons->end(); ++muon) {
208  tracks.push_back(*(muon->track()));
209  }
211  }
212 
213  else if (muonType_ == 5) { // Inner tracker tracks
216  }
217  plotter->fillRec(muons);
218 
219  // Generation and simulation part
220  if (speedup_ == false) {
221  if (PATmuons_) {
222  // EM 2015.04.02 temporary fix to run on MINIAODSIM (which contains PAT muons) but not the "onia2MuMuPatTrkTrk" collection
223  // selectGeneratedMuons(collAll, collMuSel, genPair, plotter);
224  selectGenSimMuons(event, genPair, simPair, plotter);
225  } else {
226  selectGenSimMuons(event, genPair, simPair, plotter);
227  }
228  }
229 }
Analysis-level particle class.
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
Template function used to convert the muon collection to a vector of reco::LeafCandidate.
bool selTrackerMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select trackerMuons.
const edm::EDGetTokenT< reco::CaloMuonCollection > caloMuonToken_
bool isTrackerMuon() const override
Definition: Muon.h:303
const edm::EDGetTokenT< pat::MuonCollection > patMuonToken_
auto const & tracks
cannot be loose
void selectGenSimMuons(const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
bool isValid() const
Definition: HandleBase.h:70
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
const edm::EDGetTokenT< reco::MuonCollection > recoMuonToken_
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template function used to extract the selected muon type from the muon collection.
Log< level::Warning, false > LogWarning
const edm::EDGetTokenT< pat::CompositeCandidateCollection > onia2MuMuToken_
Analysis-level muon class.
Definition: Muon.h:51
const edm::EDGetTokenT< reco::TrackCollection > trackCollectionToken_
bool isGlobalMuon() const override
Definition: Muon.h:302
Definition: event.py:1
int charge() const final
electric charge

◆ 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 324 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons().

328  {
330  bool simTracksFound = false;
331  if (simTracks.isValid()) {
332  plotter->fillSim(simTracks);
333  if (ifHepMC) {
334  simPair.push_back(findSimMuFromRes(evtMC, simTracks));
335  simTracksFound = true;
336  plotter->fillGenSim(evtMC, simTracks);
337  }
338  } else {
339  std::cout << "SimTracks not existent" << std::endl;
340  }
341  if (!simTracksFound) {
342  simPair.push_back(std::make_pair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.)));
343  }
344 }
std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
const edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken_

◆ selGlobalMuon()

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

Apply the Onia cuts to select globalMuons.

Definition at line 54 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

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 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:80
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
bool muonID(const std::string &name) const

◆ selTrackerMuon()

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

Apply the Onia cuts to select trackerMuons.

Definition at line 70 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

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 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
bool muonID(const std::string &name) const

◆ 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 140 of file MuScleFitMuonSelector.h.

References muonType_, and tracks.

Referenced by selectMuons().

140  {
141  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
142  //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
143  // to avoid double counting of the same muon
144  if (muon->isGlobalMuon() && muonType_ == 1)
145  tracks.push_back(*(muon->globalTrack()));
146  else if (muon->isStandAloneMuon() && muonType_ == 2)
147  tracks.push_back(*(muon->outerTrack()));
148  else if (muon->isTrackerMuon() && muonType_ == 3)
149  tracks.push_back(*(muon->innerTrack()));
150 
151  else if (muonType_ == 10 && !(muon->isStandAloneMuon())) //particular case!!
152  tracks.push_back(*(muon->innerTrack()));
153  else if (muonType_ == 11 && muon->isGlobalMuon())
154  tracks.push_back(*(muon->innerTrack()));
155  else if (muonType_ == 13 && muon->isTrackerMuon())
156  tracks.push_back(*(muon->innerTrack()));
157  }
auto const & tracks
cannot be loose

Member Data Documentation

◆ caloMuonToken_

const edm::EDGetTokenT<reco::CaloMuonCollection> MuScleFitMuonSelector::caloMuonToken_
protected

Definition at line 174 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ compareToSimTracks_

const bool MuScleFitMuonSelector::compareToSimTracks_
protected

Definition at line 165 of file MuScleFitMuonSelector.h.

◆ debug_

const bool MuScleFitMuonSelector::debug_
protected

◆ evtMCToken_

const edm::EDGetTokenT<edm::HepMCProduct> MuScleFitMuonSelector::evtMCToken_
protected

Definition at line 175 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

◆ genParticlesName_

const std::string MuScleFitMuonSelector::genParticlesName_
protected

Definition at line 164 of file MuScleFitMuonSelector.h.

◆ genParticleToken_

const edm::EDGetTokenT<reco::GenParticleCollection> MuScleFitMuonSelector::genParticleToken_
protected

Definition at line 176 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

◆ mMu2

const double MuScleFitMuonSelector::mMu2 = 0.011163612
staticprotected

Definition at line 179 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

◆ motherPdgIdArray

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

Definition at line 180 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

◆ muonLabel_

const edm::InputTag MuScleFitMuonSelector::muonLabel_
protected

Definition at line 159 of file MuScleFitMuonSelector.h.

◆ muonType_

const int MuScleFitMuonSelector::muonType_
protected

Definition at line 160 of file MuScleFitMuonSelector.h.

Referenced by selectMuons(), and takeSelectedMuonType().

◆ onia2MuMuToken_

const edm::EDGetTokenT<pat::CompositeCandidateCollection> MuScleFitMuonSelector::onia2MuMuToken_
protected

Definition at line 170 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ PATmuons_

const bool MuScleFitMuonSelector::PATmuons_
protected

Definition at line 161 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ patMuonToken_

const edm::EDGetTokenT<pat::MuonCollection> MuScleFitMuonSelector::patMuonToken_
protected

Definition at line 172 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ recoMuonToken_

const edm::EDGetTokenT<reco::MuonCollection> MuScleFitMuonSelector::recoMuonToken_
protected

Definition at line 173 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ resfind_

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

Definition at line 162 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

◆ sherpa_

const bool MuScleFitMuonSelector::sherpa_
protected

Definition at line 167 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and selectGenSimMuons().

◆ simTracksCollectionName_

const edm::InputTag MuScleFitMuonSelector::simTracksCollectionName_
protected

Definition at line 166 of file MuScleFitMuonSelector.h.

◆ simTrackToken_

const edm::EDGetTokenT<edm::SimTrackContainer> MuScleFitMuonSelector::simTrackToken_
protected

Definition at line 177 of file MuScleFitMuonSelector.h.

Referenced by selectSimulatedMuons().

◆ speedup_

const bool MuScleFitMuonSelector::speedup_
protected

Definition at line 163 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

◆ trackCollectionToken_

const edm::EDGetTokenT<reco::TrackCollection> MuScleFitMuonSelector::trackCollectionToken_
protected

Definition at line 171 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().