CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes

MuScleFitMuonSelector Class Reference

#include <MuScleFitMuonSelector.h>

List of all members.

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_.
 ~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.
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.
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.
bool selTrackerMuon (const pat::Muon *aMuon)
 Apply the Onia cuts to select trackerMuons.
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.

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.

                                                             :
    muonLabel_(muonLabel),
    muonType_(muonType),
    PATmuons_(PATmuons),
    resfind_(resfind),
    speedup_(speedup),
    genParticlesName_(genParticlesName),
    compareToSimTracks_(compareToSimTracks),
    simTracksCollectionName_(simTracksCollectionName),
    sherpa_(sherpa),
    debug_(debug)
  {}
MuScleFitMuonSelector::~MuScleFitMuonSelector ( ) [inline]

Definition at line 47 of file MuScleFitMuonSelector.h.

{}

Member Function Documentation

template<typename T >
std::vector<reco::LeafCandidate> MuScleFitMuonSelector::fillMuonCollection ( const std::vector< T > &  tracks) [inline, protected]

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

  {
    std::vector<reco::LeafCandidate> muons;
    typename std::vector<T>::const_iterator track;
    for( track = tracks.begin(); track != tracks.end(); ++track ) {
      reco::Particle::LorentzVector mu;
      mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
                                         sqrt(track->p()*track->p() + mMu2));
      reco::LeafCandidate muon(track->charge(),mu);
      muons.push_back(muon);
    }
    return muons;
  }
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().

{
  // std::pair<lorentzVector,lorentzVector> muFromRes;
  GenMuonPair muFromRes;

  //Loop on generated particles
  if( debug_>0 ) std::cout << "Starting loop on " << genParticles->size() << " genParticles" << std::endl;
  for( reco::GenParticleCollection::const_iterator part=genParticles->begin(); part!=genParticles->end(); ++part ) {
    if (debug_>0) std::cout<<"genParticle has pdgId = "<<fabs(part->pdgId())<<" and status = "<<part->status()<<std::endl;
    if (fabs(part->pdgId())==13){// && part->status()==3) {
      bool fromRes = false;
      unsigned int motherPdgId = part->mother()->pdgId();
      if( debug_>0 ) {
        std::cout << "Found a muon with mother: " << motherPdgId << std::endl;
      }
      for( int ires = 0; ires < 6; ++ires ) {
        if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
      }
      if(fromRes){
        if (debug_>0) std::cout<<"fromRes = true, motherPdgId = "<<motherPdgId<<std::endl;
        const reco::Candidate* status3Muon = &(*part);
        const reco::Candidate* status1Muon = getStatus1Muon(status3Muon);
        if(part->pdgId()==13) {
          muFromRes.mu1 = status1Muon->p4();
          if( debug_>0 ) std::cout << "Found a genMuon - : " << muFromRes.mu1 << std::endl;
          //      muFromRes.first = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
          //                                       status1Muon->p4().pz(),status1Muon->p4().e()));
        }
        else {
          muFromRes.mu2 = status1Muon->p4();
          if( debug_>0 ) std::cout << "Found a genMuon + : " << muFromRes.mu2 << std::endl;
          //      muFromRes.second = (lorentzVector(status1Muon->p4().px(),status1Muon->p4().py(),
          //                                        status1Muon->p4().pz(),status1Muon->p4().e()));
        }
      }
    }
  }
  return muFromRes;
}
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_.

{
  const HepMC::GenEvent* Evt = evtMC->GetEvent();
  GenMuonPair muFromRes;
  //Loop on generated particles
  for (HepMC::GenEvent::particle_const_iterator part=Evt->particles_begin();
       part!=Evt->particles_end(); part++) {
    if (fabs((*part)->pdg_id())==13 && (*part)->status()==1) {
      bool fromRes = false;
      unsigned int motherPdgId = 0;
      for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
           mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
        motherPdgId = (*mother)->pdg_id();

        // For sherpa the resonance is not saved. The muons from the resonance can be identified
        // by having as mother a muon of status 3.
        if( sherpa_ ) {
          if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes = true;
        }
        else {
          for( int ires = 0; ires < 6; ++ires ) {
            if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
          }
        }
      }
      if(fromRes){
        if((*part)->pdg_id()==13) {
          //   muFromRes.first = (*part)->momentum();
          muFromRes.mu1 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
                                         (*part)->momentum().pz(),(*part)->momentum().e()));
        }
        else {
          muFromRes.mu2 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
                                         (*part)->momentum().pz(),(*part)->momentum().e()));
        }
        muFromRes.motherId = motherPdgId;
      }
    }
  }
  return muFromRes;
}
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().

{
  //Loop on simulated tracks
  std::pair<lorentzVector, lorentzVector> simMuFromRes;
  for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
    //Chose muons
    if (fabs((*simTrack).type())==13) {
      //If tracks from IP than find mother
      if ((*simTrack).genpartIndex()>0) {
        HepMC::GenParticle* gp = evtMC->GetEvent()->barcode_to_particle ((*simTrack).genpartIndex());
        if( gp != 0 ) {

          for (HepMC::GenVertex::particle_iterator mother = gp->production_vertex()->particles_begin(HepMC::ancestors);
               mother!=gp->production_vertex()->particles_end(HepMC::ancestors); ++mother) {

            bool fromRes = false;
            unsigned int motherPdgId = (*mother)->pdg_id();
            for( int ires = 0; ires < 6; ++ires ) {
              if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
            }
            if( fromRes ) {
              if(gp->pdg_id() == 13)
                simMuFromRes.first = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
                                                   simTrack->momentum().pz(),simTrack->momentum().e());
              else
                simMuFromRes.second = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
                                                    simTrack->momentum().pz(),simTrack->momentum().e());
            }
          }
        }
        // else LogDebug("MuScleFitUtils") << "WARNING: no matching genParticle found for simTrack" << std::endl;
      }
    }
  }
  return simMuFromRes;
}
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(), ntuplemaker::status, and reco::Candidate::status().

Referenced by findGenMuFromRes().

                                                                     {
  const reco::Candidate* tempStatus1Muon = status3Muon;
  int status = tempStatus1Muon->status();
  while(tempStatus1Muon == 0 || tempStatus1Muon->numberOfDaughters()!=0){
    if (status == 1) break;
    //std::vector<const reco::Candidate*> daughters;
    for (unsigned int i=0; i<tempStatus1Muon->numberOfDaughters(); ++i){
      if ( tempStatus1Muon->daughter(i)->pdgId()==tempStatus1Muon->pdgId() ){
        tempStatus1Muon = tempStatus1Muon->daughter(i);
        status = tempStatus1Muon->status();
        break;
      }else continue;
    }//for loop
  }//while loop
  
  return tempStatus1Muon;
}
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().

{
  reco::GenParticleCollection* genPatParticles = new reco::GenParticleCollection;

  //explicitly for JPsi but can be adapted!!!!!
  for(std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
      it!=collAll->end();++it) {
    reco::GenParticleRef genJpsi = it->genParticleRef();
    bool isMatched = (genJpsi.isAvailable() && genJpsi->pdgId() == 443);  
    if (isMatched){
      genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genJpsi.get())));
    }
  }

  if(collMuSel.size()==2) {
    reco::GenParticleRef genMu1 = collMuSel[0]->genParticleRef();
    reco::GenParticleRef genMu2 = collMuSel[1]->genParticleRef();
    bool isMuMatched = (genMu1.isAvailable() && genMu2.isAvailable() && 
                        genMu1->pdgId()*genMu2->pdgId() == -169);
    if (isMuMatched) {
      genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genMu1.get())));
      genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genMu2.get())));

      unsigned int motherId = 0;
      if( genMu1->mother() != 0 ) {
         motherId = genMu1->mother()->pdgId();
      }
      if(genMu1->pdgId()==13)
        genPair.push_back(GenMuonPair(genMu1.get()->p4(), genMu2.get()->p4(), motherId));
      else
        // genPair.push_back(std::make_pair(genMu2.get()->p4(),genMu1.get()->p4()) );
        genPair.push_back(GenMuonPair(genMu2.get()->p4(), genMu1.get()->p4(), motherId));

      plotter->fillGen(const_cast <reco::GenParticleCollection*> (genPatParticles), true);

      if (debug_>0) std::cout << "Found genParticles in PAT" << std::endl;
    }
    else {
      std::cout << "No recomuon selected so no access to generated info"<<std::endl;
      // Fill it in any case, otherwise it will not be in sync with the event number
      // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );    
      genPair.push_back( GenMuonPair(lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );    
    }
  }
  else{
    std::cout << "No recomuon selected so no access to generated info"<<std::endl;
    // Fill it in any case, otherwise it will not be in sync with the event number
    // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
    genPair.push_back( GenMuonPair(lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );    
  }
  if(debug_>0) {
    std::cout << "genParticles:" << std::endl;
    // std::cout << genPair.back().first << " , " << genPair.back().second << std::endl;
    std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
  }
}
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().

{  
  // Find and store in histograms the generated and simulated resonance and muons
  // ----------------------------------------------------------------------------
  edm::Handle<edm::HepMCProduct> evtMC;
  edm::Handle<reco::GenParticleCollection> genParticles;

  // Fill gen information only in the first loop
  bool ifHepMC=false;

  event.getByLabel( genParticlesName_, evtMC );
  event.getByLabel( genParticlesName_, genParticles );
  if( evtMC.isValid() ) {
    genPair.push_back( findGenMuFromRes(evtMC.product()) );
    plotter->fillGen(evtMC.product(), sherpa_);
    ifHepMC = true;
    if (debug_>0) std::cout << "Found hepMC" << std::endl;
  }
  else if( genParticles.isValid() ) {
    genPair.push_back( findGenMuFromRes(genParticles.product()) );
    plotter->fillGen(genParticles.product());
    if (debug_>0) std::cout << "Found genParticles" << std::endl;
  }
  else {
    std::cout<<"ERROR "<<"non generation info and speedup true!!!!!!!!!!!!"<<std::endl;
    // Fill it in any case, otherwise it will not be in sync with the event number
    // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
    genPair.push_back( GenMuonPair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
  }
  if(debug_>0) {
    std::cout << "genParticles:" << std::endl;
    std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
  }
  selectSimulatedMuons(event, ifHepMC, evtMC, simPair, plotter);
}
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().

{
  edm::Handle<pat::CompositeCandidateCollection > collAll;
  try {event.getByLabel("onia2MuMuPatTrkTrk",collAll);}
  catch (...) {std::cout << "J/psi not present in event!" << std::endl;}
  std::vector<const pat::Muon*> collMuSel;

  //================onia cuts===========================/

  if( muonType_ <= -1 && PATmuons_) {
    std::vector<const pat::CompositeCandidate*> collSelGG;
    std::vector<const pat::CompositeCandidate*> collSelGT;
    std::vector<const pat::CompositeCandidate*> collSelTT;
    if (collAll.isValid()) {

      for(std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
          it!=collAll->end();++it) {
      
        const pat::CompositeCandidate* cand = &(*it);   
        // cout << "Now checking candidate of type " << theJpsiCat << " with pt = " << cand->pt() << endl;
        const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(cand->daughter("muon1"));
        const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(cand->daughter("muon2"));
      
        if((muon1->charge() * muon2->charge())>0)
          continue;
        // global + global?
        if (muon1->isGlobalMuon() && muon2->isGlobalMuon() ) {
          if (selGlobalMuon(muon1) && selGlobalMuon(muon2) && cand->userFloat("vProb") > 0.001 ) {
            collSelGG.push_back(cand);
            continue;
          }
        }
        // global + tracker? (x2)    
        if (muon1->isGlobalMuon() && muon2->isTrackerMuon() ) {
          if (selGlobalMuon(muon1) &&  selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001 ) {
            collSelGT.push_back(cand);
            continue;
          }
        }
        if (muon2->isGlobalMuon() && muon1->isTrackerMuon() ) {
          if (selGlobalMuon(muon2) && selTrackerMuon(muon1) && cand->userFloat("vProb") > 0.001) {
            collSelGT.push_back(cand);
            continue;
          }
        }
        // tracker + tracker?  
        if (muon1->isTrackerMuon() && muon2->isTrackerMuon() ) {
          if (selTrackerMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
            collSelTT.push_back(cand);
            continue;
          }
        }
      }
    }
    // Split them in independent collections if using muonType_ == -2, -3 or -4. Take them all if muonType_ == -1.
    std::vector<reco::Track> tracks;
    if(collSelGG.size()){
      //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
      const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon1"));
      const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon2"));
      if( muonType_ == -1 || muonType_ == -2 ) {
        tracks.push_back(*(muon1->innerTrack()));
        tracks.push_back(*(muon2->innerTrack()));  
        collMuSel.push_back(muon1);
        collMuSel.push_back(muon2);
      }
    }
    else if(!collSelGG.size() && collSelGT.size()){
      //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
      const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon1"));
      const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon2"));
      if( muonType_ == -1 || muonType_ == -3 ) {
        tracks.push_back(*(muon1->innerTrack()));
        tracks.push_back(*(muon2->innerTrack()));   
        collMuSel.push_back(muon1);
        collMuSel.push_back(muon2);
     }
    }
    else if(!collSelGG.size() && !collSelGT.size() && collSelTT.size()){
      //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
      const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon1"));
      const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon2"));
      if( muonType_ == -1 || muonType_ == -4 ) {
        tracks.push_back(*(muon1->innerTrack()));
        tracks.push_back(*(muon2->innerTrack()));   
        collMuSel.push_back(muon1);
        collMuSel.push_back(muon2);
      }
    }
    if (tracks.size() != 2 && tracks.size() != 0){
      std::cout<<"ERROR strange number of muons selected by onia cuts!"<<std::endl;
      abort();
    }
    muons = fillMuonCollection(tracks); 
  }
  else if( (muonType_<4 && muonType_>=0) || muonType_>=10 ) { // Muons (glb,sta,trk)
    std::vector<reco::Track> tracks;
    if( PATmuons_ == true ) {
      edm::Handle<pat::MuonCollection> allMuons;
      event.getByLabel( muonLabel_, allMuons );
      if( muonType_ == 0 ) {
        // Take directly the muon
        muons = fillMuonCollection(*allMuons);
      }
      else {
        for( std::vector<pat::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
          //std::cout<<"pat muon is global "<<muon->isGlobalMuon()<<std::endl;
          takeSelectedMuonType(muon, tracks);
        }
        muons = fillMuonCollection(tracks);
      }
    }
    else {
      edm::Handle<reco::MuonCollection> allMuons;
      event.getByLabel (muonLabel_, allMuons);
      if( muonType_ == 0 ) {
        // Take directly the muon
        muons = fillMuonCollection(*allMuons);
      }
      else {
        for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
          takeSelectedMuonType(muon, tracks);
        }
        muons = fillMuonCollection(tracks);
      }
    }
  }
  else if(muonType_==4){  //CaloMuons
    edm::Handle<reco::CaloMuonCollection> caloMuons;
    event.getByLabel (muonLabel_, caloMuons);
    std::vector<reco::Track> tracks;
    for (std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon != caloMuons->end(); ++muon){
      tracks.push_back(*(muon->track()));
    }
    muons = fillMuonCollection(tracks);
  }

  else if (muonType_==5) { // Inner tracker tracks
    edm::Handle<reco::TrackCollection> tracks;
    event.getByLabel (muonLabel_, tracks);
    muons = fillMuonCollection(*tracks);
  }
  plotter->fillRec(muons);

  // Generation and simulation part
  if( speedup_ == false )
  {
    if( PATmuons_ ) {
      selectGeneratedMuons(collAll, collMuSel, genPair, plotter);
    }
    else {
      selectGenSimMuons(event, genPair, simPair, plotter);
    }
  }
}
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().

{
  edm::Handle<edm::SimTrackContainer> simTracks;
  bool simTracksFound = false;
  event.getByLabel(simTracksCollectionName_, simTracks);
  if( simTracks.isValid() ) {
    plotter->fillSim(simTracks);
    if(ifHepMC) {
      simPair.push_back( findSimMuFromRes(evtMC, simTracks) );
      simTracksFound = true;
      plotter->fillGenSim(evtMC,simTracks);
    }
  }
  else {
    std::cout << "SimTracks not existent" << std::endl;
  }
  if( !simTracksFound ) {
    simPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
  }
}
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().

{
  reco::TrackRef iTrack = aMuon->innerTrack();
  const reco::HitPattern& p = iTrack->hitPattern();

  reco::TrackRef gTrack = aMuon->globalTrack();
  const reco::HitPattern& q = gTrack->hitPattern();

  return (//isMuonInAccept(aMuon) &&// no acceptance cuts!
    iTrack->found() > 11 &&
    gTrack->chi2()/gTrack->ndof() < 20.0 &&
    q.numberOfValidMuonHits() > 0 &&
    iTrack->chi2()/iTrack->ndof() < 4.0 &&
    aMuon->muonID("TrackerMuonArbitrated") &&
    aMuon->muonID("TMLastStationAngTight") &&
    p.pixelLayersWithMeasurement() > 1 &&
    fabs(iTrack->dxy()) < 3.0 &&  //should be done w.r.t. PV!
    fabs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
  );
}
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().

{
  reco::TrackRef iTrack = aMuon->innerTrack();
  const reco::HitPattern& p = iTrack->hitPattern();

  return (//isMuonInAccept(aMuon) // no acceptance cuts!
    iTrack->found() > 11 &&
    iTrack->chi2()/iTrack->ndof() < 4.0 &&
    aMuon->muonID("TrackerMuonArbitrated") &&
    aMuon->muonID("TMLastStationAngTight") &&
    p.pixelLayersWithMeasurement() > 1 &&
    fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
    fabs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
  );
}
template<typename T >
void MuScleFitMuonSelector::takeSelectedMuonType ( const T muon,
std::vector< reco::Track > &  tracks 
) [inline, protected]

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

  {
    // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
    //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
    // to avoid double counting of the same muon
    if(muon->isGlobalMuon() && muonType_==1)
      tracks.push_back(*(muon->globalTrack()));
    else if(muon->isStandAloneMuon() && muonType_==2)
      tracks.push_back(*(muon->outerTrack()));
    else if(muon->isTrackerMuon() && muonType_==3)
      tracks.push_back(*(muon->innerTrack()));

    else if( muonType_ == 10 && !(muon->isStandAloneMuon()) ) //particular case!!
      tracks.push_back(*(muon->innerTrack()));
    else if( muonType_ == 11 && muon->isGlobalMuon() )
      tracks.push_back(*(muon->innerTrack()));
    else if( muonType_ == 13 && muon->isTrackerMuon() )
      tracks.push_back(*(muon->innerTrack()));
  }

Member Data Documentation

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 [static, protected]

Definition at line 131 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

const unsigned int MuScleFitMuonSelector::motherPdgIdArray = {23, 100553, 100553, 553, 100443, 443} [static, protected]

Definition at line 132 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

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

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