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

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

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

Referenced by selectMuons().

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

Definition at line 370 of file MuScleFitMuonSelector.cc.

References gather_cfg::cout, debug_, motherPdgIdArray, GenMuonPair::mu1, GenMuonPair::mu2, and resfind_.

Referenced by selectGenSimMuons().

371 {
372  // std::pair<lorentzVector,lorentzVector> muFromRes;
373  GenMuonPair muFromRes;
374 
375  //Loop on generated particles
376  if( debug_>0 ) std::cout << "Starting loop on " << genParticles->size() << " genParticles" << std::endl;
377  for( reco::GenParticleCollection::const_iterator part=genParticles->begin(); part!=genParticles->end(); ++part ) {
378  if (fabs(part->pdgId())==13 && part->status()==1) {
379  bool fromRes = false;
380  unsigned int motherPdgId = part->mother()->pdgId();
381  if( debug_>0 ) {
382  std::cout << "Found a muon with mother: " << motherPdgId << std::endl;
383  }
384  for( int ires = 0; ires < 6; ++ires ) {
385  if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
386  }
387  if(fromRes){
388  if(part->pdgId()==13) {
389  muFromRes.mu1 = part->p4();
390  if( debug_>0 ) std::cout << "Found a genMuon + : " << muFromRes.mu1 << std::endl;
391  // muFromRes.first = (lorentzVector(part->p4().px(),part->p4().py(),
392  // part->p4().pz(),part->p4().e()));
393  }
394  else {
395  muFromRes.mu2 = part->p4();
396  if( debug_>0 ) std::cout << "Found a genMuon - : " << muFromRes.mu2 << std::endl;
397  // muFromRes.second = (lorentzVector(part->p4().px(),part->p4().py(),
398  // part->p4().pz(),part->p4().e()));
399  }
400  }
401  }
402  }
403  return muFromRes;
404 }
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:41
const std::vector< int > resfind_
GenMuonPair MuScleFitMuonSelector::findGenMuFromRes ( const edm::HepMCProduct evtMC)
protected

Definition at line 327 of file MuScleFitMuonSelector.cc.

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

328 {
329  const HepMC::GenEvent* Evt = evtMC->GetEvent();
330  GenMuonPair muFromRes;
331  //Loop on generated particles
332  for (HepMC::GenEvent::particle_const_iterator part=Evt->particles_begin();
333  part!=Evt->particles_end(); part++) {
334  if (fabs((*part)->pdg_id())==13 && (*part)->status()==1) {
335  bool fromRes = false;
336  unsigned int motherPdgId = 0;
337  for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
338  mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
339  motherPdgId = (*mother)->pdg_id();
340 
341  // For sherpa the resonance is not saved. The muons from the resonance can be identified
342  // by having as mother a muon of status 3.
343  if( sherpa_ ) {
344  if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes = true;
345  }
346  else {
347  for( int ires = 0; ires < 6; ++ires ) {
348  if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
349  }
350  }
351  }
352  if(fromRes){
353  if((*part)->pdg_id()==13) {
354  // muFromRes.first = (*part)->momentum();
355  muFromRes.mu1 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
356  (*part)->momentum().pz(),(*part)->momentum().e()));
357  }
358  else {
359  muFromRes.mu2 = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
360  (*part)->momentum().pz(),(*part)->momentum().e()));
361  }
362  muFromRes.motherId = motherPdgId;
363  }
364  }
365  }
366  return muFromRes;
367 }
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:34
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 406 of file MuScleFitMuonSelector.cc.

References configurableAnalysis::GenParticle, motherPdgIdArray, and resfind_.

Referenced by selectSimulatedMuons().

408 {
409  //Loop on simulated tracks
410  std::pair<lorentzVector, lorentzVector> simMuFromRes;
411  for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
412  //Chose muons
413  if (fabs((*simTrack).type())==13) {
414  //If tracks from IP than find mother
415  if ((*simTrack).genpartIndex()>0) {
416  HepMC::GenParticle* gp = evtMC->GetEvent()->barcode_to_particle ((*simTrack).genpartIndex());
417  if( gp != 0 ) {
418 
419  for (HepMC::GenVertex::particle_iterator mother = gp->production_vertex()->particles_begin(HepMC::ancestors);
420  mother!=gp->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
421 
422  bool fromRes = false;
423  unsigned int motherPdgId = (*mother)->pdg_id();
424  for( int ires = 0; ires < 6; ++ires ) {
425  if( motherPdgId == motherPdgIdArray[ires] && resfind_[ires] ) fromRes = true;
426  }
427  if( fromRes ) {
428  if(gp->pdg_id() == 13)
429  simMuFromRes.first = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
430  simTrack->momentum().pz(),simTrack->momentum().e());
431  else
432  simMuFromRes.second = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
433  simTrack->momentum().pz(),simTrack->momentum().e());
434  }
435  }
436  }
437  // else LogDebug("MuScleFitUtils") << "WARNING: no matching genParticle found for simTrack" << std::endl;
438  }
439  }
440  }
441  return simMuFromRes;
442 }
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
static const unsigned int motherPdgIdArray[6]
const std::vector< int > resfind_
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 202 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

206 {
208 
209  //explicitly for JPsi but can be adapted!!!!!
210  for(std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
211  it!=collAll->end();++it) {
212  reco::GenParticleRef genJpsi = it->genParticleRef();
213  bool isMatched = (genJpsi.isAvailable() && genJpsi->pdgId() == 443);
214  if (isMatched){
215  genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genJpsi.get())));
216  }
217  }
218 
219  if(collMuSel.size()==2) {
220  reco::GenParticleRef genMu1 = collMuSel[0]->genParticleRef();
221  reco::GenParticleRef genMu2 = collMuSel[1]->genParticleRef();
222  bool isMuMatched = (genMu1.isAvailable() && genMu2.isAvailable() &&
223  genMu1->pdgId()*genMu2->pdgId() == -169);
224  if (isMuMatched) {
225  genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genMu1.get())));
226  genPatParticles->push_back(*(const_cast<reco::GenParticle*>(genMu2.get())));
227 
228  unsigned int motherId = 0;
229  if( genMu1->mother() != 0 ) {
230  motherId = genMu1->mother()->pdgId();
231  }
232  if(genMu1->pdgId()==13)
233  genPair.push_back(GenMuonPair(genMu1.get()->p4(), genMu2.get()->p4(), motherId));
234  else
235  // genPair.push_back(std::make_pair(genMu2.get()->p4(),genMu1.get()->p4()) );
236  genPair.push_back(GenMuonPair(genMu2.get()->p4(), genMu1.get()->p4(), motherId));
237 
238  plotter->fillGen1(const_cast <reco::GenParticleCollection*> (genPatParticles), true);
239 
240  if (debug_>0) std::cout << "Found genParticles in PAT" << std::endl;
241  }
242  else {
243  std::cout << "No recomuon selected so no access to generated info"<<std::endl;
244  // Fill it in any case, otherwise it will not be in sync with the event number
245  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
246  genPair.push_back( GenMuonPair(lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
247  }
248  }
249  else{
250  std::cout << "No recomuon selected so no access to generated info"<<std::endl;
251  // Fill it in any case, otherwise it will not be in sync with the event number
252  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
253  genPair.push_back( GenMuonPair(lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
254  }
255  if(debug_>0) {
256  std::cout << "genParticles:" << std::endl;
257  // std::cout << genPair.back().first << " , " << genPair.back().second << std::endl;
258  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
259  }
260 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
bool isAvailable() const
Definition: Ref.h:275
void fillGen1(const reco::GenParticleCollection *genParticles, bool=false)
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
tuple cout
Definition: gather_cfg.py:41
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:241
void MuScleFitMuonSelector::selectGenSimMuons ( const edm::Event event,
std::vector< GenMuonPair > &  genPair,
std::vector< std::pair< lorentzVector, lorentzVector > > &  simPair,
MuScleFitPlotter plotter 
)
protected

Definition at line 262 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

266 {
267  // Find and store in histograms the generated and simulated resonance and muons
268  // ----------------------------------------------------------------------------
271 
272  // Fill gen information only in the first loop
273  bool ifHepMC=false;
274  bool ifGenPart=false;
275 
276  event.getByLabel( genParticlesName_, evtMC );
277  event.getByLabel( genParticlesName_, genParticles );
278  if( evtMC.isValid() ) {
279  genPair.push_back( findGenMuFromRes(evtMC.product()) );
280  plotter->fillGen2(evtMC.product(), sherpa_);
281  ifHepMC = true;
282  if (debug_>0) std::cout << "Found hepMC" << std::endl;
283  }
284  else if( genParticles.isValid() ) {
285  genPair.push_back( findGenMuFromRes(genParticles.product()) );
286  plotter->fillGen1(genParticles.product());
287  ifGenPart=true;
288  if (debug_>0) std::cout << "Found genParticles" << std::endl;
289  }
290  else {
291  std::cout<<"ERROR "<<"non generation info and speedup true!!!!!!!!!!!!"<<std::endl;
292  // Fill it in any case, otherwise it will not be in sync with the event number
293  // genPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
294  genPair.push_back( GenMuonPair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.), 0 ) );
295  }
296  if(debug_>0) {
297  std::cout << "genParticles:" << std::endl;
298  std::cout << genPair.back().mu1 << " , " << genPair.back().mu2 << std::endl;
299  }
300  selectSimulatedMuons(event, ifHepMC, evtMC, simPair, plotter);
301 }
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)
void fillGen1(const reco::GenParticleCollection *genParticles, bool=false)
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
bool isValid() const
Definition: HandleBase.h:76
void fillGen2(const edm::HepMCProduct *evtMC, bool shepaFlag_)
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
T const * product() const
Definition: Handle.h:74
tuple cout
Definition: gather_cfg.py:41
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 48 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().

52 {
54  try {event.getByLabel("onia2MuMuPatTrkTrk",collAll);}
55  catch (...) {std::cout << "J/psi not present in event!" << std::endl;}
56  std::vector<const pat::Muon*> collMuSel;
57 
58  //================onia cuts===========================/
59 
60  if( muonType_ <= -1 && PATmuons_) {
61  std::vector<const pat::CompositeCandidate*> collSelGG;
62  std::vector<const pat::CompositeCandidate*> collSelGT;
63  std::vector<const pat::CompositeCandidate*> collSelTT;
64  if (collAll.isValid()) {
65 
66  for(std::vector<pat::CompositeCandidate>::const_iterator it=collAll->begin();
67  it!=collAll->end();++it) {
68 
69  const pat::CompositeCandidate* cand = &(*it);
70  // cout << "Now checking candidate of type " << theJpsiCat << " with pt = " << cand->pt() << endl;
71  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(cand->daughter("muon1"));
72  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(cand->daughter("muon2"));
73 
74  if((muon1->charge() * muon2->charge())>0)
75  continue;
76  // global + global?
77  if (muon1->isGlobalMuon() && muon2->isGlobalMuon() ) {
78  if (selGlobalMuon(muon1) && selGlobalMuon(muon2) && cand->userFloat("vProb") > 0.001 ) {
79  collSelGG.push_back(cand);
80  continue;
81  }
82  }
83  // global + tracker? (x2)
84  if (muon1->isGlobalMuon() && muon2->isTrackerMuon() ) {
85  if (selGlobalMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001 ) {
86  collSelGT.push_back(cand);
87  continue;
88  }
89  }
90  if (muon2->isGlobalMuon() && muon1->isTrackerMuon() ) {
91  if (selGlobalMuon(muon2) && selTrackerMuon(muon1) && cand->userFloat("vProb") > 0.001) {
92  collSelGT.push_back(cand);
93  continue;
94  }
95  }
96  // tracker + tracker?
97  if (muon1->isTrackerMuon() && muon2->isTrackerMuon() ) {
98  if (selTrackerMuon(muon1) && selTrackerMuon(muon2) && cand->userFloat("vProb") > 0.001) {
99  collSelTT.push_back(cand);
100  continue;
101  }
102  }
103  }
104  }
105  // Split them in independent collections if using muonType_ == -2, -3 or -4. Take them all if muonType_ == -1.
106  std::vector<reco::Track> tracks;
107  if(collSelGG.size()){
108  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
109  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon1"));
110  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGG[0]->daughter("muon2"));
111  if( muonType_ == -1 || muonType_ == -2 ) {
112  tracks.push_back(*(muon1->innerTrack()));
113  tracks.push_back(*(muon2->innerTrack()));
114  collMuSel.push_back(muon1);
115  collMuSel.push_back(muon2);
116  }
117  }
118  else if(!collSelGG.size() && collSelGT.size()){
119  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
120  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon1"));
121  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelGT[0]->daughter("muon2"));
122  if( muonType_ == -1 || muonType_ == -3 ) {
123  tracks.push_back(*(muon1->innerTrack()));
124  tracks.push_back(*(muon2->innerTrack()));
125  collMuSel.push_back(muon1);
126  collMuSel.push_back(muon2);
127  }
128  }
129  else if(!collSelGG.size() && !collSelGT.size() && collSelTT.size()){
130  //CHECK THAT THEY ARE ORDERED BY PT !!!!!!!!!!!!!!!!!!!!!!!
131  const pat::Muon* muon1 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon1"));
132  const pat::Muon* muon2 = dynamic_cast<const pat::Muon*>(collSelTT[0]->daughter("muon2"));
133  if( muonType_ == -1 || muonType_ == -4 ) {
134  tracks.push_back(*(muon1->innerTrack()));
135  tracks.push_back(*(muon2->innerTrack()));
136  collMuSel.push_back(muon1);
137  collMuSel.push_back(muon2);
138  }
139  }
140  if (tracks.size() != 2 && tracks.size() != 0){
141  std::cout<<"ERROR strange number of muons selected by onia cuts!"<<std::endl;
142  abort();
143  }
144  muons = fillMuonCollection(tracks);
145  }
146  else if( (muonType_<4 && muonType_>0) || muonType_>=10 ) { // Muons (glb,sta,trk)
147  std::vector<reco::Track> tracks;
148  if( PATmuons_ == true ) {
150  event.getByLabel( muonLabel_, allMuons );
151  for( std::vector<pat::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
152  //std::cout<<"pat muon is global "<<muon->isGlobalMuon()<<std::endl;
153  takeSelectedMuonType(muon, tracks);
154  }
155  muons = fillMuonCollection(tracks);
156  }
157  else {
159  event.getByLabel (muonLabel_, allMuons);
160  if( muonType_ == 0 ) {
161  // Take directly the muon
162  muons = fillMuonCollection(*allMuons);
163  }
164  else {
165  for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
166  takeSelectedMuonType(muon, tracks);
167  }
168  muons = fillMuonCollection(tracks);
169  }
170  }
171  }
172  else if(muonType_==4){ //CaloMuons
174  event.getByLabel (muonLabel_, caloMuons);
175  std::vector<reco::Track> tracks;
176  for (std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon != caloMuons->end(); ++muon){
177  tracks.push_back(*(muon->track()));
178  }
179  muons = fillMuonCollection(tracks);
180  }
181 
182  else if (muonType_==5) { // Inner tracker tracks
184  event.getByLabel (muonLabel_, tracks);
185  muons = fillMuonCollection(*tracks);
186  }
187  plotter->fillRec(muons);
188 
189  // Generation and simulation part
190  if( speedup_ == false )
191  {
192  if( PATmuons_ ) {
193  selectGeneratedMuons(collAll, collMuSel, genPair, plotter);
194  }
195  else {
196  selectGenSimMuons(event, genPair, simPair, plotter);
197  }
198  }
199 }
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:149
bool selTrackerMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select trackerMuons.
bool isGlobalMuon() const
Definition: Muon.h:148
float userFloat(const std::string &key) const
Definition: PATObject.h:747
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:41
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 303 of file MuScleFitMuonSelector.cc.

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

Referenced by selectGenSimMuons().

307 {
309  bool simTracksFound = false;
310  event.getByLabel(simTracksCollectionName_, simTracks);
311  if( simTracks.isValid() ) {
312  plotter->fillSim(simTracks);
313  if(ifHepMC) {
314  simPair.push_back( findSimMuFromRes(evtMC, simTracks) );
315  simTracksFound = true;
316  plotter->fillGenSim(evtMC,simTracks);
317  }
318  }
319  else {
320  std::cout << "SimTracks not existent" << std::endl;
321  }
322  if( !simTracksFound ) {
323  simPair.push_back( std::make_pair( lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.) ) );
324  }
325 }
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:41
bool MuScleFitMuonSelector::selGlobalMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select globalMuons.

Definition at line 8 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

9 {
10  reco::TrackRef iTrack = aMuon->innerTrack();
11  const reco::HitPattern& p = iTrack->hitPattern();
12 
13  reco::TrackRef gTrack = aMuon->globalTrack();
14  const reco::HitPattern& q = gTrack->hitPattern();
15 
16  return (//isMuonInAccept(aMuon) &&// no acceptance cuts!
17  iTrack->found() > 11 &&
18  gTrack->chi2()/gTrack->ndof() < 20.0 &&
19  q.numberOfValidMuonHits() > 0 &&
20  iTrack->chi2()/iTrack->ndof() < 4.0 &&
21  aMuon->muonID("TrackerMuonArbitrated") &&
22  aMuon->muonID("TMLastStationAngTight") &&
24  fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
25  fabs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
26  );
27 }
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:280
int numberOfValidMuonHits() const
Definition: HitPattern.cc:346
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:888
reco::TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:82
bool MuScleFitMuonSelector::selTrackerMuon ( const pat::Muon aMuon)
protected

Apply the Onia cuts to select trackerMuons.

Definition at line 29 of file MuScleFitMuonSelector.cc.

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

Referenced by selectMuons().

30 {
31  reco::TrackRef iTrack = aMuon->innerTrack();
32  const reco::HitPattern& p = iTrack->hitPattern();
33 
34  return (//isMuonInAccept(aMuon) // no acceptance cuts!
35  iTrack->found() > 11 &&
36  iTrack->chi2()/iTrack->ndof() < 4.0 &&
37  aMuon->muonID("TrackerMuonArbitrated") &&
38  aMuon->muonID("TMLastStationAngTight") &&
40  fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
41  fabs(iTrack->dz()) < 15.0 //should be done w.r.t. PV!
42  );
43 }
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:280
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:888
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 98 of file MuScleFitMuonSelector.h.

References muonType_.

Referenced by selectMuons().

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

Member Data Documentation

const bool MuScleFitMuonSelector::compareToSimTracks_
protected

Definition at line 124 of file MuScleFitMuonSelector.h.

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

Definition at line 123 of file MuScleFitMuonSelector.h.

Referenced by selectGenSimMuons().

const double MuScleFitMuonSelector::mMu2 = 0.011163612
staticprotected

Definition at line 128 of file MuScleFitMuonSelector.h.

Referenced by fillMuonCollection().

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

Definition at line 129 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const edm::InputTag MuScleFitMuonSelector::muonLabel_
protected

Definition at line 118 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

const int MuScleFitMuonSelector::muonType_
protected

Definition at line 119 of file MuScleFitMuonSelector.h.

Referenced by selectMuons(), and takeSelectedMuonType().

const bool MuScleFitMuonSelector::PATmuons_
protected

Definition at line 120 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().

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

Definition at line 121 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and findSimMuFromRes().

const bool MuScleFitMuonSelector::sherpa_
protected

Definition at line 126 of file MuScleFitMuonSelector.h.

Referenced by findGenMuFromRes(), and selectGenSimMuons().

const edm::InputTag MuScleFitMuonSelector::simTracksCollectionName_
protected

Definition at line 125 of file MuScleFitMuonSelector.h.

Referenced by selectSimulatedMuons().

const bool MuScleFitMuonSelector::speedup_
protected

Definition at line 122 of file MuScleFitMuonSelector.h.

Referenced by selectMuons().