CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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)
 
 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< reco::LeafCandidate > &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< reco::LeafCandidatefillMuonCollection (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 28 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.

35  :
36  muonLabel_(muonLabel),
37  muonType_(muonType),
39  resfind_(resfind),
40  speedup_(speedup),
41  genParticlesName_(genParticlesName),
42  compareToSimTracks_(compareToSimTracks),
43  simTracksCollectionName_(simTracksCollectionName),
44  sherpa_(sherpa),
45  debug_(debug)
46  {}
const std::string genParticlesName_
const edm::InputTag muonLabel_
const edm::InputTag simTracksCollectionName_
#define debug
Definition: MEtoEDMFormat.h:34
const std::vector< int > resfind_
MuScleFitMuonSelector::~MuScleFitMuonSelector ( )
inline

Definition at line 47 of file MuScleFitMuonSelector.h.

47 {}

Member Function Documentation

template<typename T >
std::vector<reco::LeafCandidate> 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 85 of file MuScleFitMuonSelector.h.

References mMu2, RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().

Referenced by selectMuons().

86  {
87  std::vector<reco::LeafCandidate> muons;
88  typename std::vector<T>::const_iterator track;
89  for( track = tracks.begin(); track != tracks.end(); ++track ) {
91  mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
92  sqrt(track->p()*track->p() + mMu2));
93  reco::LeafCandidate muon(track->charge(),mu);
94  muons.push_back(muon);
95  }
96  return muons;
97  }
static const double mMu2
T sqrt(T t)
Definition: SSEVec.h:46
const int mu
Definition: Constants.h:23
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const reco::GenParticleCollection genParticles)
protected

Definition at line 394 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons().

395 {
396  // std::pair<lorentzVector,lorentzVector> muFromRes;
397  GenMuonPair muFromRes;
398 
399  //Loop on generated particles
400  if( debug_>0 ) std::cout << "Starting loop on " << genParticles->size() << " genParticles" << std::endl;
401  for( reco::GenParticleCollection::const_iterator part=genParticles->begin(); part!=genParticles->end(); ++part ) {
402  if (debug_>0) std::cout<<"genParticle has pdgId = "<<fabs(part->pdgId())<<" and status = "<<part->status()<<std::endl;
403  if (fabs(part->pdgId())==13){// && part->status()==3) {
404  bool fromRes = false;
405  unsigned int motherPdgId = part->mother()->pdgId();
406  if( debug_>0 ) {
407  std::cout << "Found a muon with mother: " << motherPdgId << std::endl;
408  }
409  for( int ires = 0; ires < 6; ++ires ) {
410  if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
411  }
412  if(fromRes){
413  if (debug_>0) std::cout<<"fromRes = true, motherPdgId = "<<motherPdgId<<std::endl;
414  const reco::Candidate* status3Muon = &(*part);
415  const reco::Candidate* status1Muon = getStatus1Muon(status3Muon);
416  if(part->pdgId()==13) {
417  muFromRes.mu1 = status1Muon->p4();
418  if( debug_>0 ) std::cout << "Found a genMuon - : " << muFromRes.mu1 << std::endl;
419  // muFromRes.first = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
420  // status1Muon->p4().pz(),status1Muon->p4().e()));
421  }
422  else {
423  muFromRes.mu2 = status1Muon->p4();
424  if( debug_>0 ) std::cout << "Found a genMuon + : " << muFromRes.mu2 << std::endl;
425  // muFromRes.second = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
426  // status1Muon->p4().pz(),status1Muon->p4().e()));
427  }
428  }
429  }
430  }
431  return muFromRes;
432 }
int ires[2]
static const unsigned int motherPdgIdArray[6]
lorentzVector mu1
Definition: GenMuonPair.h:48
lorentzVector mu2
Definition: GenMuonPair.h:49
part
Definition: HCALResponse.h:21
tuple cout
Definition: gather_cfg.py:121
const std::vector< int > resfind_
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 351 of file MuScleFitMuonSelector.cc.

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

352 {
353  const HepMC::GenEvent* Evt = evtMC->GetEvent();
354  GenMuonPair muFromRes;
355  //Loop on generated particles
356  for (HepMC::GenEvent::particle_const_iterator part=Evt->particles_begin();
357  part!=Evt->particles_end(); part++) {
358  if (fabs((*part)->pdg_id())==13 && (*part)->status()==1) {
359  bool fromRes = false;
360  unsigned int motherPdgId = 0;
361  for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
362  mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
363  motherPdgId = (*mother)->pdg_id();
364 
365  // For sherpa the resonance is not saved. The muons from the resonance can be identified
366  // by having as mother a muon of status 3.
367  if( sherpa_ ) {
368  if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes = true;
369  }
370  else {
371  for( int ires = 0; ires < 6; ++ires ) {
372  if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
373  }
374  }
375  }
376  if(fromRes){
377  if((*part)->pdg_id()==13) {
378  // muFromRes.first = (*part)->momentum();
379  muFromRes.mu1 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
380  (*part)->momentum().pz(),(*part)->momentum().e()));
381  }
382  else {
383  muFromRes.mu2 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
384  (*part)->momentum().pz(),(*part)->momentum().e()));
385  }
386  muFromRes.motherId = motherPdgId;
387  }
388  }
389  }
390  return muFromRes;
391 }
int ires[2]
Int_t motherId
Definition: GenMuonPair.h:50
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
static const unsigned int motherPdgIdArray[6]
lorentzVector mu1
Definition: GenMuonPair.h:48
lorentzVector mu2
Definition: GenMuonPair.h:49
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:35
part
Definition: HCALResponse.h:21
const std::vector< int > resfind_
std::pair< lorentzVector, lorentzVector > MuScleFitMuonSelector::findSimMuFromRes ( const edm::Handle< edm::HepMCProduct > &  evtMC,
const edm::Handle< edm::SimTrackContainer > &  simTracks 
)
protected

Definition at line 434 of file MuScleFitMuonSelector.cc.

References configurableAnalysis::GenParticle, ires, motherPdgIdArray, and resfind_.

Referenced by selectSimulatedMuons().

436 {
437  //Loop on simulated tracks
438  std::pair<lorentzVector, lorentzVector> simMuFromRes;
439  for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
440  //Chose muons
441  if (fabs((*simTrack).type())==13) {
442  //If tracks from IP than find mother
443  if ((*simTrack).genpartIndex()>0) {
444  HepMC::GenParticle* gp = evtMC->GetEvent()->barcode_to_particle ((*simTrack).genpartIndex());
445  if( gp != 0 ) {
446 
447  for (HepMC::GenVertex::particle_iterator mother = gp->production_vertex()->particles_begin(HepMC::ancestors);
448  mother!=gp->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
449 
450  bool fromRes = false;
451  unsigned int motherPdgId = (*mother)->pdg_id();
452  for( int ires = 0; ires < 6; ++ires ) {
453  if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
454  }
455  if( fromRes ) {
456  if(gp->pdg_id() == 13)
457  simMuFromRes.first = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
458  simTrack->momentum().pz(),simTrack->momentum().e());
459  else
460  simMuFromRes.second = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
461  simTrack->momentum().pz(),simTrack->momentum().e());
462  }
463  }
464  }
465  // else LogDebug("MuScleFitUtils") << "WARNING: no matching genParticle found for simTrack" << std::endl;
466  }
467  }
468  }
469  return simMuFromRes;
470 }
int ires[2]
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
static const unsigned int motherPdgIdArray[6]
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(), i, reco::Candidate::numberOfDaughters(), reco::Candidate::pdgId(), reco::Candidate::status(), and ntuplemaker::status.

Referenced by findGenMuFromRes().

9  {
10  const reco::Candidate* tempStatus1Muon = status3Muon;
11  int status = tempStatus1Muon->status();
12  while(tempStatus1Muon == 0 || tempStatus1Muon->numberOfDaughters()!=0){
13  if (status == 1) break;
14  //std::vector<const reco::Candidate*> daughters;
15  for (unsigned int i=0; i<tempStatus1Muon->numberOfDaughters(); ++i){
16  if ( tempStatus1Muon->daughter(i)->pdgId()==tempStatus1Muon->pdgId() ){
17  tempStatus1Muon = tempStatus1Muon->daughter(i);
18  status = tempStatus1Muon->status();
19  break;
20  }else continue;
21  }//for loop
22  }//while loop
23 
24  return tempStatus1Muon;
25 }
int i
Definition: DBlmapReader.cc:9
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual int status() const =0
status word
virtual size_type numberOfDaughters() const =0
number of daughters
virtual int pdgId() const =0
PDG identifier.
tuple status
Definition: ntuplemaker.py:245
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 228 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().

Referenced by selectMuons().

232 {
234 
235  //explicitly for JPsi but can be adapted!!!!!
236  for(std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
237  it!=collAll->end();++it) {
238  reco::GenParticleRef genJpsi = it->genParticleRef();
239  bool isMatched = (genJpsi.isAvailable() && genJpsi->pdgId() == 443);
240  if (isMatched){
241  genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genJpsi.get())));
242  }
243  }
244 
245  if(collMuSel.size()==2) {
246  reco::GenParticleRef genMu1 = collMuSel[0]->genParticleRef();
247  reco::GenParticleRef genMu2 = collMuSel[1]->genParticleRef();
248  bool isMuMatched = (genMu1.isAvailable() && genMu2.isAvailable() &&
249  genMu1->pdgId()*genMu2->pdgId() == -169);
250  if (isMuMatched) {
251  genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genMu1.get())));
252  genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genMu2.get())));
253 
254  unsigned int motherId = 0;
255  if( genMu1->mother() != 0 ) {
256  motherId = genMu1->mother()->pdgId();
257  }
258  if(genMu1->pdgId()==13)
259  genPair.push_back(GenMuonPair(genMu1.get()->p4(), genMu2.get()->p4(), motherId));
260  else
261  // genPair.push_back(std::make_pair(genMu2.get()->p4(),genMu1.get()->p4()) );
262  genPair.push_back(GenMuonPair(genMu2.get()->p4(), genMu1.get()->p4(), motherId));
263 
264  plotter->fillGen(const_cast <reco::GenParticleCollection*> (genPatParticles), true);
265 
266  if (debug_>0) std::cout << "Found genParticles in PAT" << std::endl;
267  }
268  else {
269  std::cout << "No recomuon selected so no access to generated info"<<std::endl;
270  // Fill it in any case, otherwise it will not be in sync with the event number
271  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
272  genPair.push_back( GenMuonPair(lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
273  }
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
bool isAvailable() const
Definition: Ref.h:276
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
bool isMatched(TrackingRecHit const &hit)
void fillGen(const reco::GenParticleCollection *genParticles, bool=false)
tuple cout
Definition: gather_cfg.py:121
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
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_, MuScleFitPlotter::fillGen(), findGenMuFromRes(), genParticleCandidates2GenParticles_cfi::genParticles, genParticlesName_, edm::HandleBase::isValid(), edm::Handle< T >::product(), selectSimulatedMuons(), and sherpa_.

Referenced by selectMuons().

292 {
293  // Find and store in histograms the generated and simulated resonance and muons
294  // ----------------------------------------------------------------------------
297 
298  // Fill gen information only in the first loop
299  bool ifHepMC=false;
300 
301  event.getByLabel( genParticlesName_, evtMC );
302  event.getByLabel( genParticlesName_, genParticles );
303  if( evtMC.isValid() ) {
304  genPair.push_back( findGenMuFromRes(evtMC.product()) );
305  plotter->fillGen(evtMC.product(), sherpa_);
306  ifHepMC = true;
307  if (debug_>0) std::cout << "Found hepMC" << std::endl;
308  }
309  else if( genParticles.isValid() ) {
310  genPair.push_back( findGenMuFromRes(genParticles.product()) );
311  plotter->fillGen(genParticles.product());
312  if (debug_>0) std::cout << "Found genParticles" << std::endl;
313  }
314  else {
315  std::cout<<"ERROR "<<"non generation info and speedup true!!!!!!!!!!!!"<<std::endl;
316  // Fill it in any case, otherwise it will not be in sync with the event number
317  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
318  genPair.push_back( GenMuonPair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
319  }
320  if(debug_>0) {
321  std::cout << "genParticles:" << std::endl;
322  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
323  }
324  selectSimulatedMuons(event, ifHepMC, evtMC, simPair, plotter);
325 }
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:8
bool isValid() const
Definition: HandleBase.h:76
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
T const * product() const
Definition: Handle.h:74
void fillGen(const reco::GenParticleCollection *genParticles, bool=false)
tuple cout
Definition: gather_cfg.py:121
void MuScleFitMuonSelector::selectMuons ( const edm::Event event,
std::vector< reco::LeafCandidate > &  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 68 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(), metsig::muon, muonLabel_, muonType_, PATmuons_, selectGeneratedMuons(), selectGenSimMuons(), selGlobalMuon(), selTrackerMuon(), speedup_, takeSelectedMuonType(), testEve_cfg::tracks, and pat::PATObject< ObjectType >::userFloat().

72 {
74  try {event.getByLabel("onia2MuMuPatTrkTrk",collAll);}
75  catch (...) {std::cout << "J/psi not present in event!" << std::endl;}
76  std::vector<const pat::Muon*> collMuSel;
77 
78  //================onia cuts===========================/
79 
80  if( muonType_ <= -1 && PATmuons_) {
81  std::vector<const pat::CompositeCandidate*> collSelGG;
82  std::vector<const pat::CompositeCandidate*> collSelGT;
83  std::vector<const pat::CompositeCandidate*> collSelTT;
84  if (collAll.isValid()) {
85 
86  for(std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
87  it!=collAll->end();++it) {
88 
89  const pat::CompositeCandidate* cand = &(*it);
90  // cout << "Now checking candidate of type " << theJpsiCat << " with pt = " << cand->pt() << endl;
91  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(cand->daughter("muon1"));
92  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(cand->daughter("muon2"));
93 
94  if((muon1->charge() * muon2->charge())>0)
95  continue;
96  // global + global?
97  if (muon1->isGlobalMuon() && muon2->isGlobalMuon() ) {
98  if (selGlobalMuon(muon1) && selGlobalMuon(muon2) && cand->userFloat("vProb") > 0.001 ) {
99  collSelGG.push_back(cand);
100  continue;
101  }
102  }
103  // global + tracker? (x2)
104  if (muon1->isGlobalMuon() && muon2->isTrackerMuon() ) {
105  if (selGlobalMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001 ) {
106  collSelGT.push_back(cand);
107  continue;
108  }
109  }
110  if (muon2->isGlobalMuon() && muon1->isTrackerMuon() ) {
111  if (selGlobalMuon(muon2) && selTrackerMuon(muon1) && cand->userFloat("vProb") > 0.001) {
112  collSelGT.push_back(cand);
113  continue;
114  }
115  }
116  // tracker + tracker?
117  if (muon1->isTrackerMuon() && muon2->isTrackerMuon() ) {
118  if (selTrackerMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
119  collSelTT.push_back(cand);
120  continue;
121  }
122  }
123  }
124  }
125  // Split them in independent collections if using muonType_ == -2, -3 or -4. Take them all if muonType_ == -1.
126  std::vector<reco::Track> tracks;
127  if(collSelGG.size()){
128  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
129  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon1"));
130  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon2"));
131  if( muonType_ == -1 || muonType_ == -2 ) {
132  tracks.push_back(*(muon1->innerTrack()));
133  tracks.push_back(*(muon2->innerTrack()));
134  collMuSel.push_back(muon1);
135  collMuSel.push_back(muon2);
136  }
137  }
138  else if(!collSelGG.size() && collSelGT.size()){
139  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
140  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon1"));
141  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon2"));
142  if( muonType_ == -1 || muonType_ == -3 ) {
143  tracks.push_back(*(muon1->innerTrack()));
144  tracks.push_back(*(muon2->innerTrack()));
145  collMuSel.push_back(muon1);
146  collMuSel.push_back(muon2);
147  }
148  }
149  else if(!collSelGG.size() && !collSelGT.size() && collSelTT.size()){
150  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
151  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon1"));
152  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon2"));
153  if( muonType_ == -1 || muonType_ == -4 ) {
154  tracks.push_back(*(muon1->innerTrack()));
155  tracks.push_back(*(muon2->innerTrack()));
156  collMuSel.push_back(muon1);
157  collMuSel.push_back(muon2);
158  }
159  }
160  if (tracks.size() != 2 && tracks.size() != 0){
161  std::cout<<"ERROR strange number of muons selected by onia cuts!"<<std::endl;
162  abort();
163  }
164  muons = fillMuonCollection(tracks);
165  }
166  else if( (muonType_<4 && muonType_>=0) || muonType_>=10 ) { // Muons (glb,sta,trk)
167  std::vector<reco::Track> tracks;
168  if( PATmuons_ == true ) {
170  event.getByLabel( muonLabel_, allMuons );
171  if( muonType_ == 0 ) {
172  // Take directly the muon
173  muons = fillMuonCollection(*allMuons);
174  }
175  else {
176  for( std::vector<pat::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
177  //std::cout<<"pat muon is global "<<muon->isGlobalMuon()<<std::endl;
178  takeSelectedMuonType(muon, tracks);
179  }
180  muons = fillMuonCollection(tracks);
181  }
182  }
183  else {
185  event.getByLabel (muonLabel_, allMuons);
186  if( muonType_ == 0 ) {
187  // Take directly the muon
188  muons = fillMuonCollection(*allMuons);
189  }
190  else {
191  for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
192  takeSelectedMuonType(muon, tracks);
193  }
194  muons = fillMuonCollection(tracks);
195  }
196  }
197  }
198  else if(muonType_==4){ //CaloMuons
200  event.getByLabel (muonLabel_, caloMuons);
201  std::vector<reco::Track> tracks;
202  for (std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon != caloMuons->end(); ++muon){
203  tracks.push_back(*(muon->track()));
204  }
205  muons = fillMuonCollection(tracks);
206  }
207 
208  else if (muonType_==5) { // Inner tracker tracks
210  event.getByLabel (muonLabel_, tracks);
211  muons = fillMuonCollection(*tracks);
212  }
213  plotter->fillRec(muons);
214 
215  // Generation and simulation part
216  if( speedup_ == false )
217  {
218  if( PATmuons_ ) {
219  selectGeneratedMuons(collAll, collMuSel, genPair, plotter);
220  }
221  else {
222  selectGenSimMuons(event, genPair, simPair, plotter);
223  }
224  }
225 }
Analysis-level particle class.
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.
reco::TrackRef innerTrack() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:74
void fillRec(std::vector< reco::LeafCandidate > &muons)
bool isTrackerMuon() const
Definition: Muon.h:212
bool selTrackerMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select trackerMuons.
bool isGlobalMuon() const
Definition: Muon.h:211
float userFloat(const std::string &key) const
Definition: PATObject.h:753
const edm::InputTag muonLabel_
virtual int charge() const
electric charge
tuple allMuons
Definition: allMuons_cfi.py:3
bool isValid() const
Definition: HandleBase.h:76
tuple tracks
Definition: testEve_cfg.py:39
void selectGenSimMuons(const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
Template function used to convert the muon collection to a vector of reco::LeafCandidate.
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
tuple muons
Definition: patZpeak.py:38
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
tuple cout
Definition: gather_cfg.py:121
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:51
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 327 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons().

331 {
333  bool simTracksFound = false;
334  event.getByLabel(simTracksCollectionName_, simTracks);
335  if( simTracks.isValid() ) {
336  plotter->fillSim(simTracks);
337  if(ifHepMC) {
338  simPair.push_back( findSimMuFromRes(evtMC, simTracks) );
339  simTracksFound = true;
340  plotter->fillGenSim(evtMC,simTracks);
341  }
342  }
343  else {
344  std::cout << "SimTracks not existent" << std::endl;
345  }
346  if( !simTracksFound ) {
347  simPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
348  }
349 }
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:8
void fillSim(edm::Handle< edm::SimTrackContainer > simTracks)
bool isValid() const
Definition: HandleBase.h:76
const edm::InputTag simTracksCollectionName_
tuple cout
Definition: gather_cfg.py:121
bool MuScleFitMuonSelector::selGlobalMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select globalMuons.

Definition at line 28 of file MuScleFitMuonSelector.cc.

References pat::Muon::globalTrack(), pat::Muon::innerTrack(), pat::Muon::muonID(), reco::HitPattern::numberOfValidMuonHits(), AlCaHLTBitMon_ParallelJobs::p, reco::HitPattern::pixelLayersWithMeasurement(), and lumiQueryAPI::q.

Referenced by selectMuons().

29 {
30  reco::TrackRef iTrack = aMuon->innerTrack();
31  const reco::HitPattern& p = iTrack->hitPattern();
32 
33  reco::TrackRef gTrack = aMuon->globalTrack();
34  const reco::HitPattern& q = gTrack->hitPattern();
35 
36  return (//isMuonInAccept(aMuon) &&// no acceptance cuts!
37  iTrack->found() > 11 &&
38  gTrack->chi2()/gTrack->ndof() < 20.0 &&
39  q.numberOfValidMuonHits() > 0 &&
40  iTrack->chi2()/iTrack->ndof() < 4.0 &&
41  aMuon->muonID("TrackerMuonArbitrated") &&
42  aMuon->muonID("TMLastStationAngTight") &&
44  fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
45  fabs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
46  );
47 }
reco::TrackRef innerTrack() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:74
bool muonID(const std::string &name) const
Definition: Muon.cc:353
int pixelLayersWithMeasurement() const
Definition: HitPattern.h:710
reco::TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:82
int numberOfValidMuonHits() const
Definition: HitPattern.h:562
bool MuScleFitMuonSelector::selTrackerMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select trackerMuons.

Definition at line 49 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

50 {
51  reco::TrackRef iTrack = aMuon->innerTrack();
52  const reco::HitPattern& p = iTrack->hitPattern();
53 
54  return (//isMuonInAccept(aMuon) // no acceptance cuts!
55  iTrack->found() > 11 &&
56  iTrack->chi2()/iTrack->ndof() < 4.0 &&
57  aMuon->muonID("TrackerMuonArbitrated") &&
58  aMuon->muonID("TMLastStationAngTight") &&
60  fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
61  fabs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
62  );
63 }
reco::TrackRef innerTrack() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:74
bool muonID(const std::string &name) const
Definition: Muon.cc:353
int pixelLayersWithMeasurement() const
Definition: HitPattern.h:710
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 101 of file MuScleFitMuonSelector.h.

References muonType_.

Referenced by selectMuons().

102  {
103  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
104  //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
105  // to avoid double counting of the same muon
106  if(muon->isGlobalMuon() && muonType_==1)
107  tracks.push_back(*(muon->globalTrack()));
108  else if(muon->isStandAloneMuon() && muonType_==2)
109  tracks.push_back(*(muon->outerTrack()));
110  else if(muon->isTrackerMuon() && muonType_==3)
111  tracks.push_back(*(muon->innerTrack()));
112 
113  else if( muonType_ == 10 && !(muon->isStandAloneMuon()) ) //particular case!!
114  tracks.push_back(*(muon->innerTrack()));
115  else if( muonType_ == 11 && muon->isGlobalMuon() )
116  tracks.push_back(*(muon->innerTrack()));
117  else if( muonType_ == 13 && muon->isTrackerMuon() )
118  tracks.push_back(*(muon->innerTrack()));
119  }
tuple tracks
Definition: testEve_cfg.py:39

Member Data Documentation

const bool MuScleFitMuonSelector::compareToSimTracks_
protected

Definition at line 127 of file MuScleFitMuonSelector.h.

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

Definition at line 126 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

const double MuScleFitMuonSelector::mMu2 = 0.011163612
staticprotected

Definition at line 131 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

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

Definition at line 132 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const edm::InputTag MuScleFitMuonSelector::muonLabel_
protected

Definition at line 121 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

const int MuScleFitMuonSelector::muonType_
protected

Definition at line 122 of file MuScleFitMuonSelector.h.

Referenced by selectMuons(), and takeSelectedMuonType().

const bool MuScleFitMuonSelector::PATmuons_
protected

Definition at line 123 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

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

Definition at line 124 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const bool MuScleFitMuonSelector::sherpa_
protected

Definition at line 129 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and selectGenSimMuons().

const edm::InputTag MuScleFitMuonSelector::simTracksCollectionName_
protected

Definition at line 128 of file MuScleFitMuonSelector.h.

Referenced by selectSimulatedMuons().

const bool MuScleFitMuonSelector::speedup_
protected

Definition at line 125 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().