CMS 3D CMS Logo

Classes | Public Member Functions | Protected Attributes | Private Attributes

RecoMuonValidator Class Reference

#include <RecoMuonValidator.h>

Inheritance diagram for RecoMuonValidator:
edm::EDAnalyzer

List of all members.

Classes

struct  CommonME
struct  MuonME

Public Member Functions

virtual void analyze (const edm::Event &event, const edm::EventSetup &eventSetup)
virtual void beginRun (const edm::Run &, const edm::EventSetup &eventSetup)
virtual int countMuonHits (const reco::Track &track) const
virtual int countTrackerHits (const reco::Track &track) const
virtual void endRun ()
 RecoMuonValidator (const edm::ParameterSet &pset)
 ~RecoMuonValidator ()

Protected Attributes

const MuonAssociatorByHitsassoByHits
edm::InputTag beamspotLabel_
CommonMEcommonME_
bool doAbsEta_
bool doAssoc_
edm::InputTag muAssocLabel_
edm::InputTag muonLabel_
MuonMEmuonME_
std::string muonSelection_
std::string outputFileName_
edm::InputTag primvertexLabel_
edm::InputTag simLabel_
std::string subDir_
DQMStoretheDQM
MuonServiceProxytheMuonService
TrackingParticleSelector tpSelector_
MuonAssociatorByHits::MuonTrackType trackType_
bool usePFMuon_
unsigned int verbose_

Private Attributes

StringCutObjectSelector
< reco::Muon
selector_
bool wantTightMuon_

Detailed Description

Definition at line 25 of file RecoMuonValidator.h.


Constructor & Destructor Documentation

RecoMuonValidator::RecoMuonValidator ( const edm::ParameterSet pset)

Definition at line 469 of file RecoMuonValidator.cc.

References beamspotLabel_, DQMStore::book1D(), DQMStore::book2D(), RecoMuonValidator::MuonME::bookHistograms(), DQMStore::cd(), commonME_, doAbsEta_, doAssoc_, Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), MuonAssociatorByHits::GlobalTk, RecoMuonValidator::CommonME::hMuonAllEta_, RecoMuonValidator::CommonME::hMuonAllP_, RecoMuonValidator::CommonME::hMuonAllPhi_, RecoMuonValidator::CommonME::hMuonAllPt_, RecoMuonValidator::CommonME::hMuonEta_, RecoMuonValidator::CommonME::hMuonP_, RecoMuonValidator::CommonME::hMuonPhi_, RecoMuonValidator::CommonME::hMuonPt_, RecoMuonValidator::CommonME::hMuonTrackDxy_, RecoMuonValidator::CommonME::hMuonTrackDz_, RecoMuonValidator::CommonME::hMuonTrackEta_, RecoMuonValidator::CommonME::hMuonTrackP_, RecoMuonValidator::CommonME::hMuonTrackPhi_, RecoMuonValidator::CommonME::hMuonTrackPt_, RecoMuonValidator::CommonME::hNDeltaInvalidHitsHitPattern_, RecoMuonValidator::CommonME::hNInvalidHitsGTHitPattern_, RecoMuonValidator::CommonME::hNInvalidHitsITHitPattern_, RecoMuonValidator::CommonME::hNInvalidHitsOTHitPattern_, RecoMuonValidator::CommonME::hStaToGlbDiffNMuonHits_, RecoMuonValidator::CommonME::hStaToGlbDiffNMuonHitsEta_, RecoMuonValidator::CommonME::hStaToGlbDiffNMuonHitsPt_, RecoMuonValidator::CommonME::hTrkToGlbDiffNTrackerHits_, RecoMuonValidator::CommonME::hTrkToGlbDiffNTrackerHitsEta_, RecoMuonValidator::CommonME::hTrkToGlbDiffNTrackerHitsPt_, MuonAssociatorByHits::InnerTk, muAssocLabel_, muonLabel_, muonME_, MuonServiceProxy_cff::MuonServiceProxy, HistoDimensions::nBinP, cmsCodeRules::cppFunctionSkipper::operator, MuonAssociatorByHits::OuterTk, outputFileName_, Pi, primvertexLabel_, MuonAssociatorByHits::Segments, DQMStore::setCurrentFolder(), DQMStore::showDirStructure(), simLabel_, subDir_, theDQM, theMuonService, tpSelector_, trackType_, usePFMuon_, verbose_, and wantTightMuon_.

                                                            :
    selector_(pset.getParameter<std::string>("selection"))
{

  verbose_ = pset.getUntrackedParameter<unsigned int>("verbose", 0);

  outputFileName_ = pset.getUntrackedParameter<string>("outputFileName", "");

  wantTightMuon_ = pset.getParameter<bool>("wantTightMuon");
  beamspotLabel_ = pset.getParameter< edm::InputTag >("beamSpot");
  primvertexLabel_ = pset.getParameter< edm::InputTag >("primaryVertex");

  // Set histogram dimensions from config
  HistoDimensions hDim;
  
  hDim.nBinP = pset.getUntrackedParameter<unsigned int>("nBinP");
  hDim.minP = pset.getUntrackedParameter<double>("minP");
  hDim.maxP = pset.getUntrackedParameter<double>("maxP");

  hDim.nBinPt = pset.getUntrackedParameter<unsigned int>("nBinPt");
  hDim.minPt = pset.getUntrackedParameter<double>("minPt");
  hDim.maxPt = pset.getUntrackedParameter<double>("maxPt");

  doAbsEta_ = pset.getUntrackedParameter<bool>("doAbsEta");
  hDim.doAbsEta = doAbsEta_;
  hDim.nBinEta  = pset.getUntrackedParameter<unsigned int>("nBinEta");
  hDim.minEta = pset.getUntrackedParameter<double>("minEta");
  hDim.maxEta = pset.getUntrackedParameter<double>("maxEta");

  hDim.nBinDxy  = pset.getUntrackedParameter<unsigned int>("nBinDxy");
  hDim.minDxy = pset.getUntrackedParameter<double>("minDxy");
  hDim.maxDxy = pset.getUntrackedParameter<double>("maxDxy");

  hDim.nBinDz  = pset.getUntrackedParameter<unsigned int>("nBinDz");
  hDim.minDz = pset.getUntrackedParameter<double>("minDz");
  hDim.maxDz = pset.getUntrackedParameter<double>("maxDz");

  hDim.nBinPhi  = pset.getUntrackedParameter<unsigned int>("nBinPhi");
  hDim.minPhi = pset.getUntrackedParameter<double>("minPhi", -TMath::Pi());
  hDim.maxPhi = pset.getUntrackedParameter<double>("maxPhi",  TMath::Pi());

  hDim.nBinErr  = pset.getUntrackedParameter<unsigned int>("nBinErr");
  hDim.nBinPull = pset.getUntrackedParameter<unsigned int>("nBinPull");

  hDim.wPull = pset.getUntrackedParameter<double>("wPull");

  hDim.minErrP = pset.getUntrackedParameter<double>("minErrP");
  hDim.maxErrP = pset.getUntrackedParameter<double>("maxErrP");

  hDim.minErrPt = pset.getUntrackedParameter<double>("minErrPt");
  hDim.maxErrPt = pset.getUntrackedParameter<double>("maxErrPt");

  hDim.minErrQPt = pset.getUntrackedParameter<double>("minErrQPt");
  hDim.maxErrQPt = pset.getUntrackedParameter<double>("maxErrQPt");

  hDim.minErrEta = pset.getUntrackedParameter<double>("minErrEta");
  hDim.maxErrEta = pset.getUntrackedParameter<double>("maxErrEta");

  hDim.minErrPhi = pset.getUntrackedParameter<double>("minErrPhi");
  hDim.maxErrPhi = pset.getUntrackedParameter<double>("maxErrPhi");

  hDim.minErrDxy = pset.getUntrackedParameter<double>("minErrDxy");
  hDim.maxErrDxy = pset.getUntrackedParameter<double>("maxErrDxy");

  hDim.minErrDz  = pset.getUntrackedParameter<double>("minErrDz" );
  hDim.maxErrDz  = pset.getUntrackedParameter<double>("maxErrDz" );

  hDim.nTrks = pset.getUntrackedParameter<unsigned int>("nTrks");
  hDim.nAssoc = pset.getUntrackedParameter<unsigned int>("nAssoc");
  hDim.nDof = pset.getUntrackedParameter<unsigned int>("nDof", 55);

  // Labels for simulation and reconstruction tracks
  simLabel_  = pset.getParameter<InputTag>("simLabel" );
  muonLabel_ = pset.getParameter<InputTag>("muonLabel");

  // Labels for sim-reco association
  doAssoc_ = pset.getUntrackedParameter<bool>("doAssoc", true);
  muAssocLabel_ = pset.getParameter<InputTag>("muAssocLabel");

  // Different momentum assignment and additional histos in case of PF muons
  usePFMuon_ = pset.getUntrackedParameter<bool>("usePFMuon");
  hDim.usePFMuon = usePFMuon_;

  //type of track
  std::string trackType = pset.getParameter< std::string >("trackType");
  if (trackType == "inner") trackType_ = MuonAssociatorByHits::InnerTk;
  else if (trackType == "outer") trackType_ = MuonAssociatorByHits::OuterTk;
  else if (trackType == "global") trackType_ = MuonAssociatorByHits::GlobalTk;
  else if (trackType == "segments") trackType_ = MuonAssociatorByHits::Segments;
  else throw cms::Exception("Configuration") << "Track type '" << trackType << "' not supported.\n";

//  seedPropagatorName_ = pset.getParameter<string>("SeedPropagator");

  ParameterSet tpset = pset.getParameter<ParameterSet>("tpSelector");
  tpSelector_ = TrackingParticleSelector(tpset.getParameter<double>("ptMin"),
                                         tpset.getParameter<double>("minRapidity"),
                                         tpset.getParameter<double>("maxRapidity"),
                                         tpset.getParameter<double>("tip"),
                                         tpset.getParameter<double>("lip"),
                                         tpset.getParameter<int>("minHit"),
                                         tpset.getParameter<bool>("signalOnly"),
                                         tpset.getParameter<bool>("chargedOnly"),
                                         tpset.getParameter<bool>("stableOnly"),
                                         tpset.getParameter<std::vector<int> >("pdgId"));

  // the service parameters
  ParameterSet serviceParameters 
    = pset.getParameter<ParameterSet>("ServiceParameters");
  theMuonService = new MuonServiceProxy(serviceParameters);

  // retrieve the instance of DQMService
  theDQM = 0;
  theDQM = Service<DQMStore>().operator->();

  if ( ! theDQM ) {
    LogError("RecoMuonValidator") << "DQMService not initialized\n";
    return;
  }

  subDir_ = pset.getUntrackedParameter<string>("subDir");
  if ( subDir_.empty() ) subDir_ = "RecoMuonV";
  if ( subDir_[subDir_.size()-1] == '/' ) subDir_.erase(subDir_.size()-1);

  // book histograms
  theDQM->cd();

  theDQM->setCurrentFolder(subDir_);

  commonME_ = new CommonME;
  muonME_  = new MuonME;

  //commonME
  const int nHits = 100;

  // - diffs
  commonME_->hTrkToGlbDiffNTrackerHits_ = theDQM->book1D("TrkGlbDiffNTrackerHits", "Difference of number of tracker hits (tkMuon - globalMuon)", 2*nHits+1, -nHits-0.5, nHits+0.5);
  commonME_->hStaToGlbDiffNMuonHits_ = theDQM->book1D("StaGlbDiffNMuonHits", "Difference of number of muon hits (staMuon - globalMuon)", 2*nHits+1, -nHits-0.5, nHits+0.5);

  commonME_->hTrkToGlbDiffNTrackerHitsEta_ = theDQM->book2D("TrkGlbDiffNTrackerHitsEta", "Difference of number of tracker hits (tkMuon - globalMuon)", hDim.nBinEta, hDim.minEta, hDim.maxEta,2*nHits+1, -nHits-0.5, nHits+0.5);
  commonME_->hStaToGlbDiffNMuonHitsEta_ = theDQM->book2D("StaGlbDiffNMuonHitsEta", "Difference of number of muon hits (staMuon - globalMuon)", hDim.nBinEta, hDim.minEta, hDim.maxEta,2*nHits+1, -nHits-0.5, nHits+0.5);

  commonME_->hTrkToGlbDiffNTrackerHitsPt_ = theDQM->book2D("TrkGlbDiffNTrackerHitsPt", "Difference of number of tracker hits (tkMuon - globalMuon)", hDim.nBinPt, hDim.minPt, hDim.maxPt,2*nHits+1, -nHits-0.5, nHits+0.5);
  commonME_->hStaToGlbDiffNMuonHitsPt_ = theDQM->book2D("StaGlbDiffNMuonHitsPt", "Difference of number of muon hits (staMuon - globalMuon)", hDim.nBinPt, hDim.minPt, hDim.maxPt,2*nHits+1, -nHits-0.5, nHits+0.5);

  // -global muon hit pattern
  commonME_->hNInvalidHitsGTHitPattern_ = theDQM->book1D("NInvalidHitsGTHitPattern", "Number of invalid hits on a global track", nHits+1, -0.5, nHits+0.5);
  commonME_->hNInvalidHitsITHitPattern_ = theDQM->book1D("NInvalidHitsITHitPattern", "Number of invalid hits on an inner track", nHits+1, -0.5, nHits+0.5);
  commonME_->hNInvalidHitsOTHitPattern_ = theDQM->book1D("NInvalidHitsOTHitPattern", "Number of invalid hits on an outer track", nHits+1, -0.5, nHits+0.5);
  commonME_->hNDeltaInvalidHitsHitPattern_ = theDQM->book1D("hNDeltaInvalidHitsHitPattern", "The discrepancy for Number of invalid hits on an global track and inner and outer tracks", 2*nHits+1, -nHits-0.5, nHits+0.5);

  //muon based kinematics
  commonME_->hMuonP_   = theDQM->book1D("PMuon"  , "p of muon"    , hDim.nBinP  , hDim.minP  , hDim.maxP  );
  commonME_->hMuonPt_  = theDQM->book1D("PtMuon" , "p_{T} of muon", hDim.nBinPt , hDim.minPt , hDim.maxPt );
  commonME_->hMuonEta_ = theDQM->book1D("EtaMuon", "#eta of muon" , hDim.nBinEta, hDim.minEta, hDim.maxEta);
  commonME_->hMuonPhi_ = theDQM->book1D("PhiMuon", "#phi of muon" , hDim.nBinPhi, hDim.minPhi, hDim.maxPhi);
  //track based kinematics
  commonME_->hMuonTrackP_   = theDQM->book1D("PMuonTrack"  , "p of reco muon track"    , hDim.nBinP  , hDim.minP  , hDim.maxP  );
  commonME_->hMuonTrackPt_  = theDQM->book1D("PtMuonTrack" , "p_{T} of reco muon track", hDim.nBinPt , hDim.minPt , hDim.maxPt );
  commonME_->hMuonTrackEta_ = theDQM->book1D("EtaMuonTrack", "#eta of reco muon track" , hDim.nBinEta, hDim.minEta, hDim.maxEta);
  commonME_->hMuonTrackPhi_ = theDQM->book1D("PhiMuonTrack", "#phi of reco muon track" , hDim.nBinPhi, hDim.minPhi, hDim.maxPhi);
  commonME_->hMuonTrackDxy_ = theDQM->book1D("DxyMuonTrack", "Dxy of reco muon track" , hDim.nBinDxy, hDim.minDxy, hDim.maxDxy);
  commonME_->hMuonTrackDz_ = theDQM->book1D("DzMuonTrack", "Dz of reco muon track" , hDim.nBinDz, hDim.minDz, hDim.maxDz);

  //histograms for fractions
  commonME_->hMuonAllP_   = theDQM->book1D("PMuonAll"  , "p of muons of all types"    , hDim.nBinP  , hDim.minP  , hDim.maxP  );
  commonME_->hMuonAllPt_  = theDQM->book1D("PtMuonAll" , "p_{T} of muon of all types", hDim.nBinPt , hDim.minPt , hDim.maxPt );
  commonME_->hMuonAllEta_ = theDQM->book1D("EtaMuonAll", "#eta of muon of all types" , hDim.nBinEta, hDim.minEta, hDim.maxEta);
  commonME_->hMuonAllPhi_ = theDQM->book1D("PhiMuonAll", "#phi of muon of all types" , hDim.nBinPhi, hDim.minPhi, hDim.maxPhi);

  muonME_->bookHistograms(theDQM, subDir_, hDim);

  if ( verbose_ > 0 ) theDQM->showDirStructure();
}
RecoMuonValidator::~RecoMuonValidator ( )

Definition at line 646 of file RecoMuonValidator.cc.

References theMuonService.

{
  if ( theMuonService ) delete theMuonService;
}

Member Function Documentation

void RecoMuonValidator::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 678 of file RecoMuonValidator.cc.

References assoByHits, MuonAssociatorByHits::associateMuons(), beamspotLabel_, reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthY(), edm::View< T >::begin(), commonME_, funct::cos(), countMuonHits(), countTrackerHits(), doAbsEta_, doAssoc_, edm::View< T >::end(), error, MonitorElement::Fill(), RecoMuonValidator::MuonME::fill(), edm::Ref< C, T, F >::get(), RecoMuonValidator::CommonME::hMuonAllEta_, RecoMuonValidator::CommonME::hMuonAllP_, RecoMuonValidator::CommonME::hMuonAllPhi_, RecoMuonValidator::CommonME::hMuonAllPt_, RecoMuonValidator::CommonME::hMuonEta_, RecoMuonValidator::CommonME::hMuonP_, RecoMuonValidator::CommonME::hMuonPhi_, RecoMuonValidator::CommonME::hMuonPt_, RecoMuonValidator::CommonME::hMuonTrackDxy_, RecoMuonValidator::CommonME::hMuonTrackDz_, RecoMuonValidator::CommonME::hMuonTrackEta_, RecoMuonValidator::CommonME::hMuonTrackP_, RecoMuonValidator::CommonME::hMuonTrackPhi_, RecoMuonValidator::CommonME::hMuonTrackPt_, RecoMuonValidator::CommonME::hNDeltaInvalidHitsHitPattern_, RecoMuonValidator::CommonME::hNInvalidHitsGTHitPattern_, RecoMuonValidator::CommonME::hNInvalidHitsITHitPattern_, RecoMuonValidator::CommonME::hNInvalidHitsOTHitPattern_, RecoMuonValidator::MuonME::hNMuon_, RecoMuonValidator::MuonME::hNMuonHits_, RecoMuonValidator::MuonME::hNMuonHits_vs_Eta_, RecoMuonValidator::MuonME::hNMuonHits_vs_Pt_, RecoMuonValidator::MuonME::hNSim_, RecoMuonValidator::MuonME::hNSimHits_, RecoMuonValidator::MuonME::hNSimToReco_, RecoMuonValidator::MuonME::hNTrackerHits_, RecoMuonValidator::MuonME::hNTrackerHits_vs_Eta_, RecoMuonValidator::MuonME::hNTrackerHits_vs_Pt_, RecoMuonValidator::MuonME::hNTrksEta_, RecoMuonValidator::MuonME::hNTrksPt_, RecoMuonValidator::MuonME::hSimDxy_, RecoMuonValidator::MuonME::hSimDz_, RecoMuonValidator::MuonME::hSimEta_, RecoMuonValidator::MuonME::hSimP_, RecoMuonValidator::MuonME::hSimPhi_, RecoMuonValidator::MuonME::hSimPt_, RecoMuonValidator::CommonME::hStaToGlbDiffNMuonHits_, RecoMuonValidator::CommonME::hStaToGlbDiffNMuonHitsEta_, RecoMuonValidator::CommonME::hStaToGlbDiffNMuonHitsPt_, RecoMuonValidator::CommonME::hTrkToGlbDiffNTrackerHits_, RecoMuonValidator::CommonME::hTrkToGlbDiffNTrackerHitsEta_, RecoMuonValidator::CommonME::hTrkToGlbDiffNTrackerHitsPt_, i, edm::Ref< C, T, F >::isNonnull(), muon::isTightMuon(), Mu, PatBasicFWLiteAnalyzer::muonEta, muonLabel_, muonME_, PatBasicFWLiteAnalyzer::muonPhi, PatBasicFWLiteAnalyzer::muonPt, position, reco::BeamSpot::position(), primvertexLabel_, edm::Handle< T >::product(), edm::RefVector< C, T, F >::push_back(), selector_, reco::BeamSpot::sigmaZ(), simLabel_, funct::sin(), edm::View< T >::size(), theDQM, tpSelector_, trackType_, usePFMuon_, wantTightMuon_, and PV3DBase< T, PVType, FrameType >::x().

{
  if ( ! theDQM ) {
    LogError("RecoMuonValidator") << "DQMService not initialized\n";
    return;
  }

  // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
  reco::Vertex::Point posVtx;
  reco::Vertex::Error errVtx;
  edm::Handle<reco::VertexCollection> recVtxs;
  event.getByLabel(primvertexLabel_,recVtxs);
  unsigned int theIndexOfThePrimaryVertex = 999.;
  for (unsigned int ind=0; ind<recVtxs->size(); ++ind) {
    if ( (*recVtxs)[ind].isValid() && !((*recVtxs)[ind].isFake()) ) {
      theIndexOfThePrimaryVertex = ind;
      break;
    }
  }
  if (theIndexOfThePrimaryVertex<100) {
    posVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).position();
    errVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).error();
  }
  else {
    LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
    edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
    event.getByLabel(beamspotLabel_,recoBeamSpotHandle);
    reco::BeamSpot bs = *recoBeamSpotHandle;
    posVtx = bs.position();
    errVtx(0,0) = bs.BeamWidthX();
    errVtx(1,1) = bs.BeamWidthY();
    errVtx(2,2) = bs.sigmaZ();
  }
  const reco::Vertex thePrimaryVertex(posVtx,errVtx);


  // Get TrackingParticles
  Handle<TrackingParticleCollection> simHandle;
  event.getByLabel(simLabel_, simHandle);
  const TrackingParticleCollection simColl = *(simHandle.product());

  // Get Muons
  Handle<View<Muon> > muonHandle;
  event.getByLabel(muonLabel_, muonHandle);
  View<Muon> muonColl = *(muonHandle.product());

  const TrackingParticleCollection::size_type nSim = simColl.size();

  edm::RefToBaseVector<reco::Muon> Muons;
  Muons = muonHandle->refVector();

  edm::RefVector<TrackingParticleCollection> allTPs;
  for (size_t i = 0; i < nSim; ++i) {
      allTPs.push_back(TrackingParticleRef(simHandle,i));
  }

  muonME_->hNSim_->Fill(nSim);
  muonME_->hNMuon_->Fill(muonColl.size());

  MuonAssociatorByHits::MuonToSimCollection muonToSimColl;
  MuonAssociatorByHits::SimToMuonCollection simToMuonColl;

  if ( doAssoc_ ) {
  assoByHits->associateMuons(muonToSimColl, simToMuonColl, Muons, trackType_, allTPs, &event, &eventSetup);
  } else {
/*
    // SimToMuon associations
    Handle<reco::RecoToSimCollection> simToTrkMuHandle;
    event.getByLabel(trkMuAssocLabel_, simToTrkMuHandle);
    trkSimRecColl = *(simToTrkMuHandle.product());

    Handle<reco::RecoToSimCollection> simToStaMuHandle;
    event.getByLabel(staMuAssocLabel_, simToStaMuHandle);
    staSimRecColl = *(simToStaMuHandle.product());

    Handle<reco::RecoToSimCollection> simToGlbMuHandle;
    event.getByLabel(glbMuAssocLabel_, simToGlbMuHandle);
    glbSimRecColl = *(simToGlbMuHandle.product());

    // MuonToSim associations
    Handle<reco::SimToRecoCollection> trkMuToSimHandle;
    event.getByLabel(trkMuAssocLabel_, trkMuToSimHandle);
    trkRecSimColl = *(trkMuToSimHandle.product());

    Handle<reco::SimToRecoCollection> staMuToSimHandle;
    event.getByLabel(staMuAssocLabel_, staMuToSimHandle);
    staRecSimColl = *(staMuToSimHandle.product());

    Handle<reco::SimToRecoCollection> glbMuToSimHandle;
    event.getByLabel(glbMuAssocLabel_, glbMuToSimHandle);
    glbRecSimColl = *(glbMuToSimHandle.product());
*/
  }

  int glbNTrackerHits = 0; int trkNTrackerHits = 0;
  int glbNMuonHits = 0; int staNMuonHits = 0;
  int NTrackerHits = 0; int NMuonHits = 0;
  
  // Analyzer reco::Muon  
  for(View<Muon>::const_iterator iMuon = muonColl.begin();
      iMuon != muonColl.end(); ++iMuon) {
      
    double muonP, muonPt, muonEta, muonPhi;
    if (usePFMuon_) {
      muonP   = iMuon->pfP4().P();
      muonPt  = iMuon->pfP4().Pt();
      muonEta = iMuon->pfP4().Eta(); 
      muonPhi = iMuon->pfP4().Phi();
    }
    else {
      muonP   = iMuon->p(); 
      muonPt  = iMuon->pt();
      muonEta = iMuon->eta();
      muonPhi = iMuon->phi();
    }

    //histograms for fractions
    commonME_->hMuonAllP_->Fill(muonP);
    commonME_->hMuonAllPt_->Fill(muonPt);
    commonME_->hMuonAllEta_->Fill(muonEta);
    commonME_->hMuonAllPhi_->Fill(muonPhi);

    if (!selector_(*iMuon)) continue;
    if (wantTightMuon_)
      {
        if (!muon::isTightMuon(*iMuon, thePrimaryVertex)) continue;
      }

    TrackRef Track = iMuon->track();

    if (Track.isNonnull()) {
      commonME_->hMuonTrackP_->Fill(Track->p());
      commonME_->hMuonTrackPt_->Fill(Track->pt());
      commonME_->hMuonTrackEta_->Fill(Track->eta());
      commonME_->hMuonTrackPhi_->Fill(Track->phi());
      
      //ip histograms
      commonME_->hMuonTrackDxy_->Fill(Track->dxy());
      commonME_->hMuonTrackDz_->Fill(Track->dz());
    }
    
    if (iMuon->isGlobalMuon()) {
      Track = iMuon->combinedMuon();
      glbNTrackerHits = countTrackerHits(*Track);
      glbNMuonHits = countMuonHits(*Track);
    } else if (iMuon->isTrackerMuon()) {
      Track = iMuon->track();
      trkNTrackerHits = countTrackerHits(*Track);
    } else {
      Track = iMuon->standAloneMuon();
    } 
    
    NTrackerHits = countTrackerHits(*Track);
    muonME_->hNTrackerHits_->Fill(NTrackerHits);
    muonME_->hNTrackerHits_vs_Pt_->Fill(Track->pt(), NTrackerHits);
    muonME_->hNTrackerHits_vs_Eta_->Fill(Track->eta(), NTrackerHits);

    NMuonHits = countMuonHits(*Track);
    muonME_->hNMuonHits_->Fill(NMuonHits);
    muonME_->hNMuonHits_vs_Pt_->Fill(Track->pt(), NMuonHits);
    muonME_->hNMuonHits_vs_Eta_->Fill(Track->eta(), NMuonHits);

//list of histos for each type

//      muonME_->hNTrks_->Fill();
    muonME_->hNTrksEta_->Fill(Track->eta());
    muonME_->hNTrksPt_->Fill(Track->pt());

    commonME_->hMuonP_->Fill(muonP);
    commonME_->hMuonPt_->Fill(muonPt);
    commonME_->hMuonEta_->Fill(muonEta);
    commonME_->hMuonPhi_->Fill(muonPhi);

    if (iMuon->isGlobalMuon()) {
      double gtHitPat = iMuon->globalTrack()->hitPattern().numberOfHits() - iMuon->globalTrack()->hitPattern().numberOfValidHits();
      double itHitPat = iMuon->innerTrack()->hitPattern().numberOfHits() - iMuon->innerTrack()->hitPattern().numberOfValidHits();
      double otHitPat = iMuon->outerTrack()->hitPattern().numberOfHits() - iMuon->outerTrack()->hitPattern().numberOfValidHits();
      
      commonME_->hNInvalidHitsGTHitPattern_->Fill(gtHitPat);
      commonME_->hNInvalidHitsITHitPattern_->Fill(itHitPat);
      commonME_->hNInvalidHitsOTHitPattern_->Fill(otHitPat);
      commonME_->hNDeltaInvalidHitsHitPattern_->Fill(gtHitPat - itHitPat - otHitPat);

      //must be global and standalone
      if (iMuon->isStandAloneMuon()) { 
        commonME_->hStaToGlbDiffNMuonHitsEta_->Fill(Track->eta(),staNMuonHits-glbNMuonHits);
        commonME_->hStaToGlbDiffNMuonHitsPt_->Fill(Track->pt(),staNMuonHits-glbNMuonHits);
        commonME_->hStaToGlbDiffNMuonHits_->Fill(staNMuonHits-glbNMuonHits);
      }
      
      //must be global and tracker
      if (iMuon->isTrackerMuon()) {
        commonME_->hTrkToGlbDiffNTrackerHitsEta_->Fill(Track->eta(),trkNTrackerHits-glbNTrackerHits);
        commonME_->hTrkToGlbDiffNTrackerHitsPt_->Fill(Track->pt(),trkNTrackerHits-glbNTrackerHits);
        commonME_->hTrkToGlbDiffNTrackerHits_->Fill(trkNTrackerHits-glbNTrackerHits);
      }
    }

  }//end of reco muon loop

  // Associate by hits
  for(TrackingParticleCollection::size_type i=0; i<nSim; i++) {
    TrackingParticleRef simRef(simHandle, i);
    const TrackingParticle* simTP = simRef.get();
    if ( ! tpSelector_(*simTP) ) continue;

    //denominators for efficiency plots
    const double simP   = simRef->p();
    const double simPt  = simRef->pt();
    const double simEta = doAbsEta_ ? fabs(simRef->eta()) : simRef->eta();
    const double simPhi = simRef->phi();
    
    GlobalPoint  simVtx(simRef->vertex().x(), simRef->vertex().y(), simRef->vertex().z());
    GlobalVector simMom(simRef->momentum().x(), simRef->momentum().y(), simRef->momentum().z());
    const double simDxy = -simVtx.x()*sin(simPhi)+simVtx.y()*cos(simPhi);
    const double simDz  = simVtx.z() - (simVtx.x()*simMom.x()+simVtx.y()*simMom.y())*simMom.z()/simMom.perp2();
    
    const unsigned int nSimHits = simRef->pSimHit_end() - simRef->pSimHit_begin();

    muonME_->hSimP_  ->Fill(simP  );
    muonME_->hSimPt_ ->Fill(simPt );
    muonME_->hSimEta_->Fill(simEta);
    muonME_->hSimPhi_->Fill(simPhi);
    muonME_->hSimDxy_->Fill(simDxy);
    muonME_->hSimDz_->Fill(simDz);
    muonME_->hNSimHits_->Fill(nSimHits);

    // Get sim-reco association for a simRef
    vector<pair<RefToBase<Muon>, double> > MuRefV;
    if ( simToMuonColl.find(simRef) != simToMuonColl.end() ) {
      MuRefV = simToMuonColl[simRef];

      if ( !MuRefV.empty()) {
        muonME_->hNSimToReco_->Fill(MuRefV.size());
        const Muon* Mu = MuRefV.begin()->first.get();
        if (!selector_(*Mu)) continue;
        if (wantTightMuon_)
          {
            if (!muon::isTightMuon(*Mu, thePrimaryVertex)) continue;
          }

        muonME_->fill(&*simTP, Mu); 
      }
    }
  }
}
void RecoMuonValidator::beginRun ( const edm::Run ,
const edm::EventSetup eventSetup 
) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 654 of file RecoMuonValidator.cc.

References assoByHits, doAssoc_, Exception, edm::EventSetup::get(), edm::InputTag::label(), muAssocLabel_, edm::ESHandle< T >::product(), and theMuonService.

{
  if ( theMuonService ) theMuonService->update(eventSetup);

  if ( doAssoc_ ) {
    edm::ESHandle<TrackAssociatorBase> associatorBase;
    eventSetup.get<TrackAssociatorRecord>().get(muAssocLabel_.label(), associatorBase);
    assoByHits = dynamic_cast<const MuonAssociatorByHits *>(associatorBase.product());
    if (assoByHits == 0) throw cms::Exception("Configuration") << "The Track Associator with label '" << muAssocLabel_.label() << "' is not a MuonAssociatorByHits.\n";
    }

}
int RecoMuonValidator::countMuonHits ( const reco::Track track) const [virtual]

Definition at line 926 of file RecoMuonValidator.cc.

References prof2calltree::count, DetId::det(), DetId::Muon, reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), and query::result.

Referenced by analyze().

                                                             {
  TransientTrackingRecHit::ConstRecHitContainer result;
  
  int count = 0;

  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
    if((*hit)->isValid()) {
      DetId recoid = (*hit)->geographicalId();
      if ( recoid.det() == DetId::Muon ) count++;
    }
  }
  return count;
}
int RecoMuonValidator::countTrackerHits ( const reco::Track track) const [virtual]

Definition at line 941 of file RecoMuonValidator.cc.

References prof2calltree::count, DetId::det(), reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), query::result, and align::Tracker.

Referenced by analyze().

                                                                {
  TransientTrackingRecHit::ConstRecHitContainer result;
  
  int count = 0;

  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
    if((*hit)->isValid()) {
      DetId recoid = (*hit)->geographicalId();
      if ( recoid.det() == DetId::Tracker ) count++;
    }
  }
  return count;
}
void RecoMuonValidator::endRun ( void  ) [virtual]

Definition at line 670 of file RecoMuonValidator.cc.

References outputFileName_, DQMStore::save(), and theDQM.

{
  if ( theDQM && ! outputFileName_.empty() ) theDQM->save(outputFileName_);
}

Member Data Documentation

Definition at line 45 of file RecoMuonValidator.h.

Referenced by analyze(), and beginRun().

Definition at line 47 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

Definition at line 68 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

bool RecoMuonValidator::doAbsEta_ [protected]

Definition at line 56 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

bool RecoMuonValidator::doAssoc_ [protected]

Definition at line 57 of file RecoMuonValidator.h.

Referenced by analyze(), beginRun(), and RecoMuonValidator().

Definition at line 44 of file RecoMuonValidator.h.

Referenced by beginRun(), and RecoMuonValidator().

Definition at line 41 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

Definition at line 65 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

std::string RecoMuonValidator::muonSelection_ [protected]

Definition at line 42 of file RecoMuonValidator.h.

std::string RecoMuonValidator::outputFileName_ [protected]

Definition at line 50 of file RecoMuonValidator.h.

Referenced by endRun(), and RecoMuonValidator().

Definition at line 48 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

Definition at line 72 of file RecoMuonValidator.h.

Referenced by analyze().

Definition at line 40 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

std::string RecoMuonValidator::subDir_ [protected]

Definition at line 51 of file RecoMuonValidator.h.

Referenced by RecoMuonValidator().

Definition at line 54 of file RecoMuonValidator.h.

Referenced by analyze(), endRun(), and RecoMuonValidator().

Definition at line 53 of file RecoMuonValidator.h.

Referenced by beginRun(), RecoMuonValidator(), and ~RecoMuonValidator().

Definition at line 60 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

Definition at line 63 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

Definition at line 58 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().

unsigned int RecoMuonValidator::verbose_ [protected]

Definition at line 38 of file RecoMuonValidator.h.

Referenced by RecoMuonValidator().

Definition at line 73 of file RecoMuonValidator.h.

Referenced by analyze(), and RecoMuonValidator().