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

36  :
37  muonLabel_(muonLabel),
38  muonType_(muonType),
39  PATmuons_(PATmuons),
40  resfind_(resfind),
41  speedup_(speedup),
42  genParticlesName_(genParticlesName),
43  compareToSimTracks_(compareToSimTracks),
44  simTracksCollectionName_(simTracksCollectionName),
45  sherpa_(sherpa),
46  debug_(debug)
47  {}
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

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

References gather_cfg::cout, debug_, mMu2, RPCpg::mu, metsig::muon, extraflags_cff::muons, mathSSE::sqrt(), and HiIsolationCommonParameters_cff::track.

Referenced by selectMuons().

91  {
92  std::vector<MuScleFitMuon> muons;
93  typename std::vector<T>::const_iterator track;
94  for( track = tracks.begin(); track != tracks.end(); ++track ) {
96  mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
97  sqrt(track->p()*track->p() + mMu2));
98 
99  Double_t hitsTk(0), hitsMuon(0), ptError(0);
100  if ( const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track)) ){
101  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
102  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
103  ptError = myMu->innerTrack()->ptError();
104  }
105  else if ( const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track)) ) {
106  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
107  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
108  ptError = myMu->innerTrack()->ptError();
109  }
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  }
static const double mMu2
T sqrt(T t)
Definition: SSEVec.h:18
const int mu
Definition: Constants.h:22
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Analysis-level muon class.
Definition: Muon.h:50
GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const reco::GenParticleCollection genParticles)
protected

Definition at line 420 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(), and ~MuScleFitMuonSelector().

421 {
422  // std::pair<lorentzVector,lorentzVector> muFromRes;
423  GenMuonPair muFromRes;
424 
425  //Loop on generated particles
426  if( debug_>0 ) std::cout << "Starting loop on " << genParticles->size() << " genParticles" << std::endl;
427  for( reco::GenParticleCollection::const_iterator part=genParticles->begin(); part!=genParticles->end(); ++part ) {
428  if (debug_>0) std::cout<<"genParticle has pdgId = "<<std::abs(part->pdgId())<<" and status = "<<part->status()<<std::endl;
429  if (std::abs(part->pdgId())==13){// && part->status()==3) {
430  bool fromRes = false;
431  unsigned int motherPdgId = part->mother()->pdgId();
432  if( debug_>0 ) {
433  std::cout << "Found a muon with mother: " << motherPdgId << std::endl;
434  }
435  for( int ires = 0; ires < 6; ++ires ) {
436  // if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true; // changed by EM 2015.07.30
437  // begin of comment
438  // the list of resonances motherPdgIdArray does not contain the photon (PdgId = 21) while ~1% of the
439  // mu+mu- events in the range [50,120] GeV has a photon as the mother.
440  // It needs to be fixed without spoiling the logic of the selection of different resonances
441  // e.g. mixing up onia etc.
442  // end of comment
443  if( ( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) || motherPdgId == 21 ) fromRes = true;
444  }
445  if(fromRes){
446  if (debug_>0) std::cout<<"fromRes = true, motherPdgId = "<<motherPdgId<<std::endl;
447  const reco::Candidate* status3Muon = &(*part);
448  const reco::Candidate* status1Muon = getStatus1Muon(status3Muon);
449  if(part->pdgId()==13) {
450  if (status1Muon->p4().pt()!=0) muFromRes.mu1 = MuScleFitMuon(status1Muon->p4(),-1);
451  else muFromRes.mu1 = MuScleFitMuon(status3Muon->p4(),-1);
452  if( debug_>0 ) std::cout << "Found a genMuon - : " << muFromRes.mu1 << std::endl;
453  // muFromRes.first = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
454  // status1Muon->p4().pz(),status1Muon->p4().e()));
455  }
456  else {
457  if (status1Muon->p4().pt()!=0) muFromRes.mu2 = MuScleFitMuon(status1Muon->p4(),+1);
458  else muFromRes.mu2 = MuScleFitMuon(status3Muon->p4(),+1);
459  if( debug_>0 ) std::cout << "Found a genMuon + : " << muFromRes.mu2 << std::endl;
460  // muFromRes.second = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
461  // status1Muon->p4().pz(),status1Muon->p4().e()));
462  }
463  muFromRes.motherId = motherPdgId;
464  }
465  }
466  }
467  return muFromRes;
468 }
int ires[2]
MuScleFitMuon mu1
Definition: GenMuonPair.h:54
Int_t motherId
Definition: GenMuonPair.h:56
static const unsigned int motherPdgIdArray[6]
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
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:55
const reco::Candidate * getStatus1Muon(const reco::Candidate *status3Muon)
GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const edm::HepMCProduct evtMC)
protected

Definition at line 377 of file MuScleFitMuonSelector.cc.

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

378 {
379  const HepMC::GenEvent* Evt = evtMC->GetEvent();
380  GenMuonPair muFromRes;
381  //Loop on generated particles
382  for (HepMC::GenEvent::particle_const_iterator part=Evt->particles_begin();
383  part!=Evt->particles_end(); part++) {
384  if (std::abs((*part)->pdg_id())==13 && (*part)->status()==1) {
385  bool fromRes = false;
386  unsigned int motherPdgId = 0;
387  for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
388  mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
389  motherPdgId = (*mother)->pdg_id();
390 
391  // For sherpa the resonance is not saved. The muons from the resonance can be identified
392  // by having as mother a muon of status 3.
393  if( sherpa_ ) {
394  if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes = true;
395  }
396  else {
397  for( int ires = 0; ires < 6; ++ires ) {
398  if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
399  }
400  }
401  }
402  if(fromRes){
403  if((*part)->pdg_id()==13) {
404  // muFromRes.first = (*part)->momentum();
405  muFromRes.mu1 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
406  (*part)->momentum().pz(),(*part)->momentum().e()));
407  }
408  else {
409  muFromRes.mu2 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
410  (*part)->momentum().pz(),(*part)->momentum().e()));
411  }
412  muFromRes.motherId = motherPdgId;
413  }
414  }
415  }
416  return muFromRes;
417 }
int ires[2]
MuScleFitMuon mu1
Definition: GenMuonPair.h:54
Int_t motherId
Definition: GenMuonPair.h:56
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:38
part
Definition: HCALResponse.h:20
const std::vector< int > resfind_
MuScleFitMuon mu2
Definition: GenMuonPair.h:55
std::pair< lorentzVector, lorentzVector > MuScleFitMuonSelector::findSimMuFromRes ( const edm::Handle< edm::HepMCProduct > &  evtMC,
const edm::Handle< edm::SimTrackContainer > &  simTracks 
)
protected

Definition at line 470 of file MuScleFitMuonSelector.cc.

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

Referenced by selectSimulatedMuons(), and ~MuScleFitMuonSelector().

472 {
473  //Loop on simulated tracks
474  std::pair<lorentzVector, lorentzVector> simMuFromRes;
475  for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
476  //Chose muons
477  if (std::abs((*simTrack).type())==13) {
478  //If tracks from IP than find mother
479  if ((*simTrack).genpartIndex()>0) {
480  HepMC::GenParticle* gp = evtMC->GetEvent()->barcode_to_particle ((*simTrack).genpartIndex());
481  if( gp != nullptr ) {
482 
483  for (HepMC::GenVertex::particle_iterator mother = gp->production_vertex()->particles_begin(HepMC::ancestors);
484  mother!=gp->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
485 
486  bool fromRes = false;
487  unsigned int motherPdgId = (*mother)->pdg_id();
488  for( int ires = 0; ires < 6; ++ires ) {
489  if( ( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) || motherPdgId == 21 ) fromRes = true;
490  }
491  if( fromRes ) {
492  if(gp->pdg_id() == 13)
493  simMuFromRes.first = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
494  simTrack->momentum().pz(),simTrack->momentum().e());
495  else
496  simMuFromRes.second = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
497  simTrack->momentum().pz(),simTrack->momentum().e());
498  }
499  }
500  }
501  // else LogDebug("MuScleFitUtils") << "WARNING: no matching genParticle found for simTrack" << std::endl;
502  }
503  }
504  }
505  return simMuFromRes;
506 }
int ires[2]
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
static const unsigned int motherPdgIdArray[6]
simTrack
per collection params
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
const std::vector< int > resfind_
const reco::Candidate * MuScleFitMuonSelector::getStatus1Muon ( const reco::Candidate status3Muon)

Definition at line 10 of file MuScleFitMuonSelector.cc.

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

Referenced by findGenMuFromRes(), and ~MuScleFitMuonSelector().

10  {
11  const reco::Candidate* tempMuon = status3Muon;
12  // bool lastCopy = (static_cast<const reco::GenParticle*>(tempMuon))->isLastCopy(); // isLastCopy() likely not enough robust
13  bool isPromptFinalState = static_cast<const reco::GenParticle*>(tempMuon)->isPromptFinalState(); // pre-CMSSW_74X code: int status = tempStatus1Muon->status();
14  while(tempMuon == nullptr || tempMuon->numberOfDaughters()!=0){
15  if ( isPromptFinalState ) break; // pre-CMSSW_74X code: if (status == 1) break;
16  //std::vector<const reco::Candidate*> daughters;
17  for (unsigned int i=0; i<tempMuon->numberOfDaughters(); ++i){
18  if ( tempMuon->daughter(i)->pdgId()==tempMuon->pdgId() ){
19  tempMuon = tempMuon->daughter(i);
20  isPromptFinalState = static_cast<const reco::GenParticle*>(tempMuon)->isPromptFinalState(); // pre-CMSSW_74X code: status = tempStatus1Muon->status();
21  break;
22  }else continue;
23  }//for loop
24  }//while loop
25 
26  return tempMuon;
27 }
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual int pdgId() const =0
PDG identifier.
virtual size_type numberOfDaughters() const =0
number of daughters
const reco::Candidate * MuScleFitMuonSelector::getStatus3Muon ( const reco::Candidate status3Muon)

Definition at line 30 of file MuScleFitMuonSelector.cc.

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

Referenced by ~MuScleFitMuonSelector().

30  {
31  const reco::Candidate* tempMuon = status3Muon;
32  bool lastCopy = static_cast<const reco::GenParticle*>(tempMuon)->isLastCopyBeforeFSR(); // pre-CMSSW_74X code: int status = tempStatus1Muon->status();
33  while(tempMuon == nullptr || tempMuon->numberOfDaughters()!=0){
34  if ( lastCopy ) break; // pre-CMSSW_74X code: if (status == 3) break;
35  //std::vector<const reco::Candidate*> daughters;
36  for (unsigned int i=0; i<tempMuon->numberOfDaughters(); ++i){
37  if ( tempMuon->daughter(i)->pdgId()==tempMuon->pdgId() ){
38  tempMuon = tempMuon->daughter(i);
39  lastCopy = static_cast<const reco::GenParticle*>(tempMuon)->isLastCopyBeforeFSR(); // pre-CMSSW_74X code: status = tempStatus1Muon->status();
40  break;
41  }else continue;
42  }//for loop
43  }//while loop
44 
45  return tempMuon;
46 }
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual int pdgId() const =0
PDG identifier.
virtual size_type numberOfDaughters() const =0
number of daughters
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 254 of file MuScleFitMuonSelector.cc.

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

Referenced by ~MuScleFitMuonSelector().

258 {
259  reco::GenParticleCollection genPatParticles{};
260 
261  //explicitly for JPsi but can be adapted!!!!!
262  for(std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
263  it!=collAll->end();++it) {
264  reco::GenParticleRef genJpsi = it->genParticleRef();
265  bool isMatched = (genJpsi.isAvailable() && genJpsi->pdgId() == 443);
266  if (isMatched){
267  genPatParticles.push_back(*genJpsi.get());
268  }
269  }
270 
271  if(collMuSel.size()==2) {
272  reco::GenParticleRef genMu1 = collMuSel[0]->genParticleRef();
273  reco::GenParticleRef genMu2 = collMuSel[1]->genParticleRef();
274  bool isMuMatched = (genMu1.isAvailable() && genMu2.isAvailable() &&
275  genMu1->pdgId()*genMu2->pdgId() == -169);
276  if (isMuMatched) {
277  genPatParticles.push_back(*genMu1.get());
278  genPatParticles.push_back(*genMu2.get());
279 
280  unsigned int motherId = 0;
281  if( genMu1->mother() != nullptr ) {
282  motherId = genMu1->mother()->pdgId();
283  }
284  if(genMu1->pdgId()==13)
285  genPair.push_back(GenMuonPair(genMu1.get()->p4(), genMu2.get()->p4(), motherId));
286  else
287  // genPair.push_back(std::make_pair(genMu2.get()->p4(),genMu1.get()->p4()) );
288  genPair.push_back(GenMuonPair(genMu2.get()->p4(), genMu1.get()->p4(), motherId));
289 
290  plotter->fillGen(genPatParticles, true);
291 
292  if (debug_>0) std::cout << "Found genParticles in PAT" << std::endl;
293  }
294  else {
295  std::cout << "No recomuon selected so no access to generated info"<<std::endl;
296  // Fill it in any case, otherwise it will not be in sync with the event number
297  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
298  genPair.push_back( GenMuonPair(lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
299  }
300  }
301  else{
302  std::cout << "No recomuon selected so no access to generated info"<<std::endl;
303  // Fill it in any case, otherwise it will not be in sync with the event number
304  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
305  genPair.push_back( GenMuonPair(lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
306  }
307  if(debug_>0) {
308  std::cout << "genParticles:" << std::endl;
309  // std::cout << genPair.back().first << " , " << genPair.back().second << std::endl;
310  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
311  }
312 }
bool isAvailable() const
Definition: Ref.h:575
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
#define nullptr
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:243
void fillGen(const reco::GenParticleCollection &genParticles, bool=false)
void MuScleFitMuonSelector::selectGenSimMuons ( const edm::Event event,
std::vector< GenMuonPair > &  genPair,
std::vector< std::pair< lorentzVector, lorentzVector > > &  simPair,
MuScleFitPlotter plotter 
)
protected

Definition at line 314 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons(), and ~MuScleFitMuonSelector().

318 {
319  // Find and store in histograms the generated and simulated resonance and muons
320  // ----------------------------------------------------------------------------
323 
324  // Fill gen information only in the first loop
325  bool ifHepMC=false;
326 
327  event.getByLabel( genParticlesName_, evtMC );
328  event.getByLabel( genParticlesName_, genParticles );
329  if( evtMC.isValid() ) {
330  genPair.push_back( findGenMuFromRes(evtMC.product()) );
331  plotter->fillGen(*evtMC, sherpa_);
332  ifHepMC = true;
333  if (debug_>0) std::cout << "Found hepMC" << std::endl;
334  }
335  else if( genParticles.isValid() ) {
336  genPair.push_back( findGenMuFromRes(genParticles.product()) );
337  plotter->fillGen(*genParticles);
338  if (debug_>0) std::cout << "Found genParticles" << std::endl;
339  }
340  else {
341  std::cout<<"ERROR "<<"non generation info and speedup true!!!!!!!!!!!!"<<std::endl;
342  // Fill it in any case, otherwise it will not be in sync with the event number
343  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
344  genPair.push_back( GenMuonPair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
345  }
346  if(debug_>0) {
347  std::cout << "genParticles:" << std::endl;
348  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
349  }
350  selectSimulatedMuons(event, ifHepMC, evtMC, simPair, plotter);
351 }
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:74
T const * product() const
Definition: Handle.h:81
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
void fillGen(const reco::GenParticleCollection &genParticles, bool=false)
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 90 of file MuScleFitMuonSelector.cc.

References allMuons_cfi::allMuons, mergedMuons_cfi::caloMuons, reco::LeafCandidate::charge(), gather_cfg::cout, reco::CompositeCandidate::daughter(), fillMuonCollection(), MuScleFitPlotter::fillRec(), pat::Muon::innerTrack(), reco::Muon::isGlobalMuon(), reco::Muon::isTrackerMuon(), edm::HandleBase::isValid(), metsig::muon, muonLabel_, muonType_, PATmuons_, selectGenSimMuons(), selGlobalMuon(), selTrackerMuon(), speedup_, takeSelectedMuonType(), l1t::tracks, and pat::PATObject< ObjectType >::userFloat().

Referenced by ~MuScleFitMuonSelector().

94 {
96  event.getByLabel("onia2MuMuPatTrkTrk", collAll);
97  if(!collAll.isValid()) {
98  edm::LogWarning("MuScleFitUtils") << "J/psi not present in event!";
99  }
100  std::vector<const pat::Muon*> collMuSel;
101 
102  //================onia cuts===========================/
103 
104  if (muonType_ <= -1 && PATmuons_) {
105  std::vector<const pat::CompositeCandidate*> collSelGG;
106  std::vector<const pat::CompositeCandidate*> collSelGT;
107  std::vector<const pat::CompositeCandidate*> collSelTT;
108  if (collAll.isValid()) {
109 
110  for (std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
111  it!=collAll->end(); ++it) {
112 
113  const pat::CompositeCandidate* cand = &(*it);
114  // cout << "Now checking candidate of type " << theJpsiCat << " with pt = " << cand->pt() << endl;
115  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(cand->daughter("muon1"));
116  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(cand->daughter("muon2"));
117 
118  if ((muon1->charge() * muon2->charge())>0)
119  continue;
120  // global + global?
121  if (muon1->isGlobalMuon() && muon2->isGlobalMuon()) {
122  if (selGlobalMuon(muon1) && selGlobalMuon(muon2) && cand->userFloat("vProb") > 0.001) {
123  collSelGG.push_back(cand);
124  continue;
125  }
126  }
127  // global + tracker? (x2)
128  if (muon1->isGlobalMuon() && muon2->isTrackerMuon()) {
129  if (selGlobalMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
130  collSelGT.push_back(cand);
131  continue;
132  }
133  }
134  if (muon2->isGlobalMuon() && muon1->isTrackerMuon()) {
135  if (selGlobalMuon(muon2) && selTrackerMuon(muon1) && cand->userFloat("vProb") > 0.001) {
136  collSelGT.push_back(cand);
137  continue;
138  }
139  }
140  // tracker + tracker?
141  if (muon1->isTrackerMuon() && muon2->isTrackerMuon()) {
142  if (selTrackerMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
143  collSelTT.push_back(cand);
144  continue;
145  }
146  }
147  }
148  }
149  // Split them in independent collections if using muonType_ == -2, -3 or -4. Take them all if muonType_ == -1.
150  std::vector<reco::Track> tracks;
151  if (!collSelGG.empty()){
152  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
153  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon1"));
154  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon2"));
155  if (muonType_ == -1 || muonType_ == -2) {
156  tracks.push_back(*(muon1->innerTrack()));
157  tracks.push_back(*(muon2->innerTrack()));
158  collMuSel.push_back(muon1);
159  collMuSel.push_back(muon2);
160  }
161  }
162  else if (collSelGG.empty() && !collSelGT.empty()){
163  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
164  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon1"));
165  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon2"));
166  if (muonType_ == -1 || muonType_ == -3) {
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  else if (collSelGG.empty() && collSelGT.empty() && !collSelTT.empty()){
174  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
175  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon1"));
176  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon2"));
177  if (muonType_ == -1 || muonType_ == -4) {
178  tracks.push_back(*(muon1->innerTrack()));
179  tracks.push_back(*(muon2->innerTrack()));
180  collMuSel.push_back(muon1);
181  collMuSel.push_back(muon2);
182  }
183  }
184  if (tracks.size() != 2 && !tracks.empty()){
185  std::cout<<"ERROR strange number of muons selected by onia cuts!"<<std::endl;
186  abort();
187  }
188  muons = fillMuonCollection(tracks);
189  }
190  else if ((muonType_<4 && muonType_>=0) || muonType_>=10) { // Muons (glb,sta,trk)
191  std::vector<reco::Track> tracks;
192  if (PATmuons_ == true) {
194  event.getByLabel(muonLabel_, allMuons);
195  if (muonType_ == 0) {
196  // Take directly the muon
197  muons = fillMuonCollection(*allMuons);
198  }
199  else {
200  for (std::vector<pat::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
201  //std::cout<<"pat muon is global "<<muon->isGlobalMuon()<<std::endl;
202  takeSelectedMuonType(muon, tracks);
203  }
204  muons = fillMuonCollection(tracks);
205  }
206  }
207  else {
209  event.getByLabel(muonLabel_, allMuons);
210  if (muonType_ == 0) {
211  // Take directly the muon
212  muons = fillMuonCollection(*allMuons);
213  }
214  else {
215  for (std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
216  takeSelectedMuonType(muon, tracks);
217  }
218  muons = fillMuonCollection(tracks);
219  }
220  }
221  }
222  else if (muonType_==4){ //CaloMuons
224  event.getByLabel(muonLabel_, caloMuons);
225  std::vector<reco::Track> tracks;
226  for (std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon != caloMuons->end(); ++muon){
227  tracks.push_back(*(muon->track()));
228  }
229  muons = fillMuonCollection(tracks);
230  }
231 
232  else if (muonType_==5) { // Inner tracker tracks
234  event.getByLabel(muonLabel_, tracks);
235  muons = fillMuonCollection(*tracks);
236  }
237  plotter->fillRec(muons);
238 
239  // Generation and simulation part
240  if (speedup_ == false)
241  {
242  if (PATmuons_) {
243  // EM 2015.04.02 temporary fix to run on MINIAODSIM (which contains PAT muons) but not the "onia2MuMuPatTrkTrk" collection
244  // selectGeneratedMuons(collAll, collMuSel, genPair, plotter);
245  selectGenSimMuons(event, genPair, simPair, plotter);
246  }
247  else {
248  selectGenSimMuons(event, genPair, simPair, plotter);
249  }
250  }
251 }
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.
int charge() const final
electric charge
Definition: LeafCandidate.h:91
float userFloat(const std::string &key) const
Definition: PATObject.h:791
bool isTrackerMuon() const override
Definition: Muon.h:277
const edm::InputTag muonLabel_
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
void fillRec(std::vector< MuScleFitMuon > &muons)
Used when running on the root tree containing preselected muon pairs.
bool isGlobalMuon() const override
Definition: Muon.h:276
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
bool isValid() const
Definition: HandleBase.h:74
void selectGenSimMuons(const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template function used to extract the selected muon type from the muon collection.
Analysis-level muon class.
Definition: Muon.h:50
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 353 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons(), and ~MuScleFitMuonSelector().

357 {
359  bool simTracksFound = false;
360  event.getByLabel(simTracksCollectionName_, simTracks);
361  if( simTracks.isValid() ) {
362  plotter->fillSim(simTracks);
363  if(ifHepMC) {
364  simPair.push_back( findSimMuFromRes(evtMC, simTracks) );
365  simTracksFound = true;
366  plotter->fillGenSim(evtMC,simTracks);
367  }
368  }
369  else {
370  std::cout << "SimTracks not existent" << std::endl;
371  }
372  if( !simTracksFound ) {
373  simPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
374  }
375 }
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:74
const edm::InputTag simTracksCollectionName_
bool MuScleFitMuonSelector::selGlobalMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select globalMuons.

Definition at line 50 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 lumiQueryAPI::q.

Referenced by selectMuons(), and ~MuScleFitMuonSelector().

51 {
52  reco::TrackRef iTrack = aMuon->innerTrack();
53  const reco::HitPattern& p = iTrack->hitPattern();
54 
55  reco::TrackRef gTrack = aMuon->globalTrack();
56  const reco::HitPattern& q = gTrack->hitPattern();
57 
58  return (//isMuonInAccept(aMuon) &&// no acceptance cuts!
59  iTrack->found() > 11 &&
60  gTrack->chi2()/gTrack->ndof() < 20.0 &&
61  q.numberOfValidMuonHits() > 0 &&
62  iTrack->chi2()/iTrack->ndof() < 4.0 &&
63  aMuon->muonID("TrackerMuonArbitrated") &&
64  aMuon->muonID("TMLastStationAngTight") &&
66  std::abs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
67  std::abs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
68  );
69 }
bool muonID(const std::string &name) const
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:538
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
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:81
int numberOfValidMuonHits() const
Definition: HitPattern.h:898
bool MuScleFitMuonSelector::selTrackerMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select trackerMuons.

Definition at line 71 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons(), and ~MuScleFitMuonSelector().

72 {
73  reco::TrackRef iTrack = aMuon->innerTrack();
74  const reco::HitPattern& p = iTrack->hitPattern();
75 
76  return (//isMuonInAccept(aMuon) // no acceptance cuts!
77  iTrack->found() > 11 &&
78  iTrack->chi2()/iTrack->ndof() < 4.0 &&
79  aMuon->muonID("TrackerMuonArbitrated") &&
80  aMuon->muonID("TMLastStationAngTight") &&
82  std::abs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
83  std::abs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
84  );
85 }
bool muonID(const std::string &name) const
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:538
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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().

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

Member Data Documentation

const bool MuScleFitMuonSelector::compareToSimTracks_
protected

Definition at line 156 of file MuScleFitMuonSelector.h.

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

Definition at line 155 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

const double MuScleFitMuonSelector::mMu2 = 0.011163612
staticprotected

Definition at line 160 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

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

Definition at line 161 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const edm::InputTag MuScleFitMuonSelector::muonLabel_
protected

Definition at line 150 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

const int MuScleFitMuonSelector::muonType_
protected

Definition at line 151 of file MuScleFitMuonSelector.h.

Referenced by selectMuons(), and takeSelectedMuonType().

const bool MuScleFitMuonSelector::PATmuons_
protected

Definition at line 152 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

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

Definition at line 153 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const bool MuScleFitMuonSelector::sherpa_
protected

Definition at line 158 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and selectGenSimMuons().

const edm::InputTag MuScleFitMuonSelector::simTracksCollectionName_
protected

Definition at line 157 of file MuScleFitMuonSelector.h.

Referenced by selectSimulatedMuons().

const bool MuScleFitMuonSelector::speedup_
protected

Definition at line 154 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().