CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 reco::GenParticleCollection *genParticles)
 
GenMuonPair findGenMuFromRes (const edm::HepMCProduct *evtMC)
 
std::pair< lorentzVector,
lorentzVector
findSimMuFromRes (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 ( 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.

41  : muonLabel_(muonLabel),
42  muonType_(muonType),
44  resfind_(resfind),
45  speedup_(speedup),
46  genParticlesName_(genParticlesName),
47  compareToSimTracks_(compareToSimTracks),
48  simTracksCollectionName_(simTracksCollectionName),
49  sherpa_(sherpa),
50  debug_(debug) {}
const std::string genParticlesName_
const edm::InputTag muonLabel_
#define debug
Definition: HDRShower.cc:19
const edm::InputTag simTracksCollectionName_
const std::vector< int > resfind_
MuScleFitMuonSelector::~MuScleFitMuonSelector ( )
inline

Definition at line 51 of file MuScleFitMuonSelector.h.

51 {}

Member Function Documentation

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.

References gather_cfg::cout, debug_, mMu2, RPCpg::mu, HLT_FULL_cff::muon, patZpeak::muons, mathSSE::sqrt(), and HLT_FULL_cff::track.

Referenced by selectMuons().

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  }
auto const & tracks
cannot be loose
static const double mMu2
T sqrt(T t)
Definition: SSEVec.h:19
const int mu
Definition: Constants.h:22
tuple muons
Definition: patZpeak.py:39
tuple cout
Definition: gather_cfg.py:144
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Analysis-level muon class.
Definition: Muon.h:51
GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const reco::GenParticleCollection genParticles)
protected

Definition at line 397 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons().

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 }
int ires[2]
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
tuple cout
Definition: gather_cfg.py:144
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
GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const edm::HepMCProduct evtMC)
protected

Definition at line 355 of file MuScleFitMuonSelector.cc.

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

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 }
int ires[2]
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
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.

References funct::abs(), GenParticle::GenParticle, runTauDisplay::gp, ires, motherPdgIdArray, resfind_, and cscDigiValidation_cfi::simTrack.

Referenced by selectSimulatedMuons().

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 }
int ires[2]
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 std::vector< int > resfind_
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.
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.
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.

References gather_cfg::cout, debug_, MuScleFitPlotter::fillGen(), edm::Ref< C, T, F >::get(), edm::Ref< C, T, F >::isAvailable(), and trackerHitRTTI::isMatched().

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 }
bool isAvailable() const
Definition: Ref.h:537
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
bool isMatched(TrackingRecHit const &hit)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
void fillGen(const reco::GenParticleCollection &genParticles, bool=false)
tuple cout
Definition: gather_cfg.py:144
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.

References gather_cfg::cout, debug_, MuScleFitPlotter::fillGen(), findGenMuFromRes(), genParticleCandidates2GenParticles_cfi::genParticles, genParticlesName_, edm::HandleBase::isValid(), edm::Handle< T >::product(), selectSimulatedMuons(), and sherpa_.

Referenced by selectMuons().

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 }
const std::string genParticlesName_
void selectSimulatedMuons(const edm::Event &event, const bool ifHepMC, edm::Handle< edm::HepMCProduct > evtMC, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
bool isValid() const
Definition: HandleBase.h:70
T const * product() const
Definition: Handle.h:70
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
void fillGen(const reco::GenParticleCollection &genParticles, bool=false)
tuple cout
Definition: gather_cfg.py:144
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, reco::LeafCandidate::charge(), gather_cfg::cout, reco::CompositeCandidate::daughter(), fillMuonCollection(), MuScleFitPlotter::fillRec(), pat::Muon::innerTrack(), reco::Muon::isGlobalMuon(), reco::Muon::isTrackerMuon(), edm::HandleBase::isValid(), HLT_FULL_cff::muon, muonLabel_, muonType_, PATmuons_, selectGenSimMuons(), selGlobalMuon(), selTrackerMuon(), speedup_, takeSelectedMuonType(), tracks, and pat::PATObject< ObjectType >::userFloat().

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  }
178  muons = fillMuonCollection(tracks);
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
186  muons = fillMuonCollection(*allMuons);
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;
190  takeSelectedMuonType(muon, tracks);
191  }
192  muons = fillMuonCollection(tracks);
193  }
194  } else {
196  event.getByLabel(muonLabel_, allMuons);
197  if (muonType_ == 0) {
198  // Take directly the muon
199  muons = fillMuonCollection(*allMuons);
200  } else {
201  for (std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
202  takeSelectedMuonType(muon, tracks);
203  }
204  muons = fillMuonCollection(tracks);
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  }
214  muons = fillMuonCollection(tracks);
215  }
216 
217  else if (muonType_ == 5) { // Inner tracker tracks
219  event.getByLabel(muonLabel_, tracks);
220  muons = fillMuonCollection(*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 }
Analysis-level particle class.
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
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.
auto const & tracks
cannot be loose
bool isTrackerMuon() const override
Definition: Muon.h:300
float userFloat(const std::string &key) const
Definition: PATObject.h:871
const edm::InputTag muonLabel_
void fillRec(std::vector< MuScleFitMuon > &muons)
Used when running on the root tree containing preselected muon pairs.
tuple allMuons
Definition: allMuons_cfi.py:3
bool isValid() const
Definition: HandleBase.h:70
void selectGenSimMuons(const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
tuple muons
Definition: patZpeak.py:39
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
tuple cout
Definition: gather_cfg.py:144
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
Analysis-level muon class.
Definition: Muon.h:51
bool isGlobalMuon() const override
Definition: Muon.h:299
int charge() const final
electric charge
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.

References gather_cfg::cout, MuScleFitPlotter::fillGenSim(), MuScleFitPlotter::fillSim(), findSimMuFromRes(), edm::HandleBase::isValid(), and simTracksCollectionName_.

Referenced by selectGenSimMuons().

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 }
std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
void fillGenSim(edm::Handle< edm::HepMCProduct > evtMC, edm::Handle< edm::SimTrackContainer > simTracks)
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
void fillSim(edm::Handle< edm::SimTrackContainer > simTracks)
bool isValid() const
Definition: HandleBase.h:70
const edm::InputTag simTracksCollectionName_
tuple cout
Definition: gather_cfg.py:144
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(), reco::HitPattern::numberOfValidMuonHits(), AlCaHLTBitMon_ParallelJobs::p, reco::HitPattern::pixelLayersWithMeasurement(), 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 }
bool muonID(const std::string &name) const
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:500
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
int numberOfValidMuonHits() const
Definition: HitPattern.h:817
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(), AlCaHLTBitMon_ParallelJobs::p, and reco::HitPattern::pixelLayersWithMeasurement().

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 }
bool muonID(const std::string &name) const
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:500
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
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.

References muonType_.

Referenced by selectMuons().

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  }
auto const & tracks
cannot be loose

Member Data Documentation

const bool MuScleFitMuonSelector::compareToSimTracks_
protected

Definition at line 155 of file MuScleFitMuonSelector.h.

const bool MuScleFitMuonSelector::debug_
protected
const std::string MuScleFitMuonSelector::genParticlesName_
protected

Definition at line 154 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

const double MuScleFitMuonSelector::mMu2 = 0.011163612
staticprotected

Definition at line 159 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

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().

const edm::InputTag MuScleFitMuonSelector::muonLabel_
protected

Definition at line 149 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

const int MuScleFitMuonSelector::muonType_
protected

Definition at line 150 of file MuScleFitMuonSelector.h.

Referenced by selectMuons(), and takeSelectedMuonType().

const bool MuScleFitMuonSelector::PATmuons_
protected

Definition at line 151 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

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

Definition at line 152 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const bool MuScleFitMuonSelector::sherpa_
protected

Definition at line 157 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and selectGenSimMuons().

const edm::InputTag MuScleFitMuonSelector::simTracksCollectionName_
protected

Definition at line 156 of file MuScleFitMuonSelector.h.

Referenced by selectSimulatedMuons().

const bool MuScleFitMuonSelector::speedup_
protected

Definition at line 153 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().