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

36  :
37  muonLabel_(muonLabel),
38  muonType_(muonType),
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

Definition at line 48 of file MuScleFitMuonSelector.h.

48 {}

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

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

Referenced by selectMuons().

88  {
89  std::vector<MuScleFitMuon> muons;
90  typename std::vector<T>::const_iterator track;
91  for( track = tracks.begin(); track != tracks.end(); ++track ) {
93  mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
94  sqrt(track->p()*track->p() + mMu2));
95 
96  Double_t hitsTk(0), hitsMuon(0), ptError(0);
97  if ( const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track)) ){
98  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
99  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
100  ptError = myMu->innerTrack()->ptError();
101  }
102  else if ( const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track)) ) {
103  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
104  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
105  ptError = myMu->innerTrack()->ptError();
106  }
107  else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))){
108  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
109  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
110  ptError = myMu->ptError();
111  }
112 
113  MuScleFitMuon muon(mu,track->charge(),ptError,hitsTk,hitsMuon);
114 
115  if (debug_>0) {
116  std::cout<<"[MuScleFitMuonSelector::fillMuonCollection] after MuScleFitMuon initialization"<<std::endl;
117  std::cout<<" muon = "<<muon<<std::endl;
118  }
119 
120  muons.push_back(muon);
121  }
122  return muons;
123  }
static const double mMu2
T sqrt(T t)
Definition: SSEVec.h:48
const int mu
Definition: Constants.h:22
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
tuple cout
Definition: gather_cfg.py:121
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Analysis-level muon class.
Definition: Muon.h:49
GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const reco::GenParticleCollection genParticles)
protected

Definition at line 395 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons().

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

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

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

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

Referenced by selectSimulatedMuons().

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

Referenced by findGenMuFromRes().

10  {
11  const reco::Candidate* tempStatus1Muon = status3Muon;
12  int status = tempStatus1Muon->status();
13  while(tempStatus1Muon == 0 || tempStatus1Muon->numberOfDaughters()!=0){
14  if (status == 1) break;
15  //std::vector<const reco::Candidate*> daughters;
16  for (unsigned int i=0; i<tempStatus1Muon->numberOfDaughters(); ++i){
17  if ( tempStatus1Muon->daughter(i)->pdgId()==tempStatus1Muon->pdgId() ){
18  tempStatus1Muon = tempStatus1Muon->daughter(i);
19  status = tempStatus1Muon->status();
20  break;
21  }else continue;
22  }//for loop
23  }//while loop
24 
25  return tempStatus1Muon;
26 }
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 229 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().

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

Definition at line 289 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().

293 {
294  // Find and store in histograms the generated and simulated resonance and muons
295  // ----------------------------------------------------------------------------
298 
299  // Fill gen information only in the first loop
300  bool ifHepMC=false;
301 
302  event.getByLabel( genParticlesName_, evtMC );
303  event.getByLabel( genParticlesName_, genParticles );
304  if( evtMC.isValid() ) {
305  genPair.push_back( findGenMuFromRes(evtMC.product()) );
306  plotter->fillGen(evtMC.product(), sherpa_);
307  ifHepMC = true;
308  if (debug_>0) std::cout << "Found hepMC" << std::endl;
309  }
310  else if( genParticles.isValid() ) {
311  genPair.push_back( findGenMuFromRes(genParticles.product()) );
312  plotter->fillGen(genParticles.product());
313  if (debug_>0) std::cout << "Found genParticles" << std::endl;
314  }
315  else {
316  std::cout<<"ERROR "<<"non generation info and speedup true!!!!!!!!!!!!"<<std::endl;
317  // Fill it in any case, otherwise it will not be in sync with the event number
318  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
319  genPair.push_back( GenMuonPair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
320  }
321  if(debug_>0) {
322  std::cout << "genParticles:" << std::endl;
323  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
324  }
325  selectSimulatedMuons(event, ifHepMC, evtMC, simPair, plotter);
326 }
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:75
T const * product() const
Definition: Handle.h:81
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
void fillGen(const reco::GenParticleCollection *genParticles, bool=false)
tuple cout
Definition: gather_cfg.py:121
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 69 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().

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

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

Referenced by selectGenSimMuons().

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

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

Apply the Onia cuts to select trackerMuons.

Definition at line 50 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

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

References muonType_.

Referenced by selectMuons().

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

Member Data Documentation

const bool MuScleFitMuonSelector::compareToSimTracks_
protected

Definition at line 153 of file MuScleFitMuonSelector.h.

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

Definition at line 152 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

const double MuScleFitMuonSelector::mMu2 = 0.011163612
staticprotected

Definition at line 157 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

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

Definition at line 158 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const edm::InputTag MuScleFitMuonSelector::muonLabel_
protected

Definition at line 147 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

const int MuScleFitMuonSelector::muonType_
protected

Definition at line 148 of file MuScleFitMuonSelector.h.

Referenced by selectMuons(), and takeSelectedMuonType().

const bool MuScleFitMuonSelector::PATmuons_
protected

Definition at line 149 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

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

Definition at line 150 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const bool MuScleFitMuonSelector::sherpa_
protected

Definition at line 155 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and selectGenSimMuons().

const edm::InputTag MuScleFitMuonSelector::simTracksCollectionName_
protected

Definition at line 154 of file MuScleFitMuonSelector.h.

Referenced by selectSimulatedMuons().

const bool MuScleFitMuonSelector::speedup_
protected

Definition at line 151 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().