CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMOffline/Muon/src/MuonKinVsEtaAnalyzer.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2012/09/09 16:58:38 $
00005  *  $Revision: 1.8 $
00006  *  \author S. Goy Lopez, CIEMAT 
00007  */
00008 
00009 #include "DQMOffline/Muon/src/MuonKinVsEtaAnalyzer.h"
00010 
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "DataFormats/MuonReco/interface/Muon.h"
00013 #include "DataFormats/MuonReco/interface/MuonFwd.h" 
00014 #include "DataFormats/MuonReco/interface/MuonEnergy.h"
00015 
00016 #include "DataFormats/TrackReco/interface/Track.h"
00017 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00018 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00019 #include "DataFormats/VertexReco/interface/Vertex.h"
00020 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00021 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
00022 
00023 
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 
00026 #include <string>
00027 #include <TMath.h>
00028 using namespace std;
00029 using namespace edm;
00030 
00031 
00032 
00033 MuonKinVsEtaAnalyzer::MuonKinVsEtaAnalyzer(const edm::ParameterSet& pSet, MuonServiceProxy *theService):MuonAnalyzerBase(theService){  parameters = pSet;
00034 }
00035 
00036 
00037 MuonKinVsEtaAnalyzer::~MuonKinVsEtaAnalyzer() { }
00038 
00039 
00040 void MuonKinVsEtaAnalyzer::beginJob(DQMStore * dbe) {
00041 
00042   metname = "muonKinVsEta";
00043 
00044   LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] Parameters initialization";
00045   dbe->setCurrentFolder("Muons/MuonKinVsEtaAnalyzer");
00046 
00047   vertexTag  = parameters.getParameter<edm::InputTag>("vertexLabel");
00048   bsTag  = parameters.getParameter<edm::InputTag>("bsLabel");
00049 
00050   etaBin = parameters.getParameter<int>("etaBin");
00051   etaMin = parameters.getParameter<double>("etaMin");
00052   etaMax = parameters.getParameter<double>("etaMax");
00053 
00054   phiBin = parameters.getParameter<int>("phiBin");
00055   phiMin = parameters.getParameter<double>("phiMin");
00056   phiMax = parameters.getParameter<double>("phiMax");
00057 
00058   pBin = parameters.getParameter<int>("pBin");
00059   pMin = parameters.getParameter<double>("pMin");
00060   pMax = parameters.getParameter<double>("pMax");
00061 
00062   ptBin = parameters.getParameter<int>("ptBin");
00063   ptMin = parameters.getParameter<double>("ptMin");
00064   ptMax = parameters.getParameter<double>("ptMax");
00065 
00066   chiBin = parameters.getParameter<int>("chiBin");
00067   chiMin = parameters.getParameter<double>("chiMin");
00068   chiMax = parameters.getParameter<double>("chiMax");
00069   chiprobMin = parameters.getParameter<double>("chiprobMin");
00070   chiprobMax = parameters.getParameter<double>("chiprobMax");
00071 
00072 
00073   etaBMin = parameters.getParameter<double>("etaBMin");
00074   etaBMax = parameters.getParameter<double>("etaBMax");
00075   etaECMin = parameters.getParameter<double>("etaECMin");
00076   etaECMax = parameters.getParameter<double>("etaECMax");
00077   etaOvlpMin = parameters.getParameter<double>("etaOvlpMin");
00078   etaOvlpMax = parameters.getParameter<double>("etaOvlpMax");
00079 
00080   std::string EtaName;
00081   for(unsigned int iEtaRegion=0;iEtaRegion<4;iEtaRegion++){
00082     if (iEtaRegion==0) EtaName = "Barrel";   
00083     if (iEtaRegion==1) EtaName = "EndCap";   
00084     if (iEtaRegion==2) EtaName = "Overlap";
00085     if (iEtaRegion==3) EtaName = "";
00086 
00087     // monitoring of eta parameter
00088     etaGlbTrack.push_back(dbe->book1D("GlbMuon_eta_"+EtaName, "#eta_{GLB} "+EtaName, etaBin, etaMin, etaMax));
00089     etaTrack.push_back(dbe->book1D("TkMuon_eta_"+EtaName, "#eta_{TK} "+EtaName, etaBin, etaMin, etaMax));
00090     etaStaTrack.push_back(dbe->book1D("StaMuon_eta_"+EtaName, "#eta_{STA} "+EtaName, etaBin, etaMin, etaMax));
00091     etaTightTrack.push_back(dbe->book1D("TightMuon_eta_"+EtaName, "#eta_{Tight} "+EtaName, etaBin, etaMin, etaMax));
00092     etaLooseTrack.push_back(dbe->book1D("LooseMuon_eta_"+EtaName, "#eta_{Loose} "+EtaName, etaBin, etaMin, etaMax));
00093     etaSoftTrack.push_back(dbe->book1D("SoftMuon_eta_"+EtaName, "#eta_{Soft} "+EtaName, etaBin, etaMin, etaMax));
00094     etaHighPtTrack.push_back(dbe->book1D("HighPtMuon_eta_"+EtaName, "#eta_{HighPt} "+EtaName, etaBin, etaMin, etaMax));
00095     
00096     // monitoring of phi paramater
00097     phiGlbTrack.push_back(dbe->book1D("GlbMuon_phi_"+EtaName, "#phi_{GLB} "+EtaName+ "(rad)", phiBin, phiMin, phiMax));
00098     phiTrack.push_back(dbe->book1D("TkMuon_phi_"+EtaName, "#phi_{TK}" +EtaName +"(rad)", phiBin, phiMin, phiMax));
00099     phiStaTrack.push_back(dbe->book1D("StaMuon_phi_"+EtaName, "#phi_{STA}"+EtaName+" (rad)", phiBin, phiMin, phiMax));
00100     phiTightTrack.push_back(dbe->book1D("TightMuon_phi_"+EtaName, "#phi_{Tight}_"+EtaName, phiBin, phiMin, phiMax));
00101    phiLooseTrack.push_back(dbe->book1D("LooseMuon_phi_"+EtaName, "#phi_{Loose}_"+EtaName, phiBin, phiMin, phiMax));
00102    phiSoftTrack.push_back(dbe->book1D("SoftMuon_phi_"+EtaName, "#phi_{Soft}_"+EtaName, phiBin, phiMin, phiMax));
00103    phiHighPtTrack.push_back(dbe->book1D("HighPtMuon_phi_"+EtaName, "#phi_{HighPt}_"+EtaName, phiBin, phiMin, phiMax));
00104    
00105    // monitoring of the momentum
00106     pGlbTrack.push_back(dbe->book1D("GlbMuon_p_"+EtaName, "p_{GLB} "+EtaName, pBin, pMin, pMax));
00107     pTrack.push_back(dbe->book1D("TkMuon_p"+EtaName, "p_{TK} "+EtaName, pBin, pMin, pMax));
00108     pStaTrack.push_back(dbe->book1D("StaMuon_p"+EtaName, "p_{STA} "+EtaName, pBin, pMin, pMax));
00109     pTightTrack.push_back(dbe->book1D("TightMuon_p_"+EtaName, "p_{Tight} "+EtaName, pBin, pMin, pMax));
00110     pLooseTrack.push_back(dbe->book1D("LooseMuon_p_"+EtaName, "p_{Loose} "+EtaName, pBin, pMin, pMax));
00111     pSoftTrack.push_back(dbe->book1D("SoftMuon_p_"+EtaName, "p_{Soft} "+EtaName, pBin, pMin, pMax));
00112     pHighPtTrack.push_back(dbe->book1D("HighPtMuon_p_"+EtaName, "p_{HighPt} "+EtaName, pBin, pMin, pMax));
00113 
00114     // monitoring of the transverse momentum
00115     ptGlbTrack.push_back(dbe->book1D("GlbMuon_pt_" +EtaName, "pt_{GLB} "+EtaName, ptBin, ptMin, ptMax));
00116     ptTrack.push_back(dbe->book1D("TkMuon_pt_"+EtaName, "pt_{TK} "+EtaName, ptBin, ptMin, ptMax));
00117     ptStaTrack.push_back(dbe->book1D("StaMuon_pt_"+EtaName, "pt_{STA} "+EtaName, ptBin, ptMin, pMax));
00118     ptTightTrack.push_back(dbe->book1D("TightMuon_pt_"+EtaName, "pt_{Tight} "+EtaName, ptBin, ptMin, ptMax));
00119     ptLooseTrack.push_back(dbe->book1D("LooseMuon_pt_"+EtaName, "pt_{Loose} "+EtaName, ptBin, ptMin, ptMax));
00120     ptSoftTrack.push_back(dbe->book1D("SoftMuon_pt_"+EtaName, "pt_{Soft} "+EtaName, ptBin, ptMin, ptMax));
00121     ptHighPtTrack.push_back(dbe->book1D("HighPtMuon_pt_"+EtaName, "pt_{HighPt} "+EtaName, ptBin, ptMin, ptMax));
00122 
00123     // monitoring chi2 and Prob.Chi2
00124     chi2GlbTrack.push_back(dbe->book1D("GlbMuon_chi2_"+EtaName, "#chi^{2}_{GLB} " + EtaName, chiBin, chiMin, chiMax));
00125     chi2probGlbTrack.push_back(dbe->book1D("GlbMuon_chi2prob_"+EtaName, "#chi^{2}_{GLB} prob." + EtaName, chiBin, chiprobMin, chiprobMax));
00126     chi2Track.push_back(dbe->book1D("TkMuon_chi2_"+EtaName, "#chi^{2}_{TK} " + EtaName, chiBin, chiMin, chiMax));
00127     chi2probTrack.push_back(dbe->book1D("TkMuon_chi2prob_"+EtaName, "#chi^{2}_{TK} prob." + EtaName, chiBin, chiprobMin, chiprobMax));
00128     chi2StaTrack.push_back(dbe->book1D("StaMuon_chi2_"+EtaName, "#chi^{2}_{STA} " + EtaName, chiBin, chiMin, chiMax));
00129     chi2probStaTrack.push_back(dbe->book1D("StaMuon_chi2prob_"+EtaName, "#chi^{2}_{STA} prob." + EtaName, chiBin, chiprobMin, chiprobMax));
00130     chi2TightTrack.push_back(dbe->book1D("TightMuon_chi2_"+EtaName, "#chi^{2}_{Tight} " + EtaName, chiBin, chiMin, chiMax));
00131     chi2probTightTrack.push_back(dbe->book1D("TightMuon_chi2prob_"+EtaName, "#chi^{2}_{Tight} prob." + EtaName, chiBin, chiprobMin, chiprobMax));
00132     chi2LooseTrack.push_back(dbe->book1D("LooseMuon_chi2_"+EtaName, "#chi^{2}_{Loose} " + EtaName, chiBin, chiMin, chiMax));
00133     chi2probLooseTrack.push_back(dbe->book1D("LooseMuon_chi2prob_"+EtaName, "#chi^{2}_{Loose} prob." + EtaName, chiBin, chiprobMin, chiprobMax));
00134     chi2SoftTrack.push_back(dbe->book1D("SoftMuon_chi2_"+EtaName, "#chi^{2}_{Soft} " + EtaName, chiBin, chiMin, chiMax));
00135     chi2probSoftTrack.push_back(dbe->book1D("SoftMuon_chi2prob_"+EtaName, "#chi^{2}_{Soft} prob." + EtaName, chiBin, chiprobMin, chiprobMax));
00136     chi2HighPtTrack.push_back(dbe->book1D("HighPtMuon_chi2_"+EtaName, "#chi^{2}_{HighPt} " + EtaName, chiBin, chiMin, chiMax));
00137     chi2probHighPtTrack.push_back(dbe->book1D("HighPtMuon_chi2prob_"+EtaName, "#chi^{2}_{HighPt} prob." + EtaName, chiBin, chiprobMin, chiprobMax));
00138 
00139 
00140  }
00141 }
00142 
00143 
00144 
00145 
00146 void MuonKinVsEtaAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup, const reco::Muon& recoMu) {
00147 
00148   // ==========================================================
00149   // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
00150 
00151   reco::Vertex::Point posVtx;
00152   reco::Vertex::Error errVtx;
00153  
00154   unsigned int theIndexOfThePrimaryVertex = 999.;
00155  
00156   edm::Handle<reco::VertexCollection> vertex;
00157   iEvent.getByLabel(vertexTag, vertex);
00158 
00159   if (vertex.isValid()){
00160 
00161     for (unsigned int ind=0; ind<vertex->size(); ++ind) {
00162       if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
00163         theIndexOfThePrimaryVertex = ind;
00164         break;
00165       }
00166     }
00167   }
00168 
00169   if (theIndexOfThePrimaryVertex<100) {
00170     posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
00171     errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
00172   }   else {
00173     LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
00174   
00175     edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00176     iEvent.getByLabel(bsTag,recoBeamSpotHandle);
00177     
00178     reco::BeamSpot bs = *recoBeamSpotHandle;
00179     
00180     posVtx = bs.position();
00181     errVtx(0,0) = bs.BeamWidthX();
00182     errVtx(1,1) = bs.BeamWidthY();
00183     errVtx(2,2) = bs.sigmaZ();
00184   }
00185   const reco::Vertex thePrimaryVertex(posVtx,errVtx);
00186 
00187   // ==========================================================
00188 
00189   
00190   reco::BeamSpot beamSpot;
00191   Handle<reco::BeamSpot> beamSpotHandle;
00192   iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
00193   beamSpot = *beamSpotHandle;
00194   
00195   LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] Analyze the mu in different eta regions";
00196 
00197   for(unsigned int iEtaRegion=0;iEtaRegion<4;iEtaRegion++){
00198     if (iEtaRegion==0) {EtaCutMin= etaBMin; EtaCutMax=etaBMax;}
00199     if (iEtaRegion==1) {EtaCutMin= etaECMin; EtaCutMax=etaECMax;}
00200     if (iEtaRegion==2) {EtaCutMin= etaOvlpMin; EtaCutMax=etaOvlpMax;} 
00201     if (iEtaRegion==3) {EtaCutMin= etaBMin; EtaCutMax=etaECMax;}
00202     
00203     if(recoMu.isGlobalMuon()) {
00204       LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] The mu is global - filling the histos";
00205       reco::TrackRef recoCombinedGlbTrack = recoMu.combinedMuon();
00206       // get the track combinig the information from both the glb fit"
00207       if(fabs(recoCombinedGlbTrack->eta())>EtaCutMin && fabs(recoCombinedGlbTrack->eta())<EtaCutMax){
00208         etaGlbTrack[iEtaRegion]->Fill(recoCombinedGlbTrack->eta());
00209         phiGlbTrack[iEtaRegion]->Fill(recoCombinedGlbTrack->phi());
00210         pGlbTrack[iEtaRegion]->Fill(recoCombinedGlbTrack->p());
00211         ptGlbTrack[iEtaRegion]->Fill(recoCombinedGlbTrack->pt());
00212         chi2GlbTrack[iEtaRegion]->Fill(recoCombinedGlbTrack->normalizedChi2());
00213         chi2probGlbTrack[iEtaRegion]->Fill(TMath::Prob(recoCombinedGlbTrack->normalizedChi2(),recoCombinedGlbTrack->ndof()));
00214       }
00215     }
00216 
00217     if(recoMu.isTrackerMuon()) {
00218       LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] The mu is tracker - filling the histos";
00219       // get the track using only the tracker data
00220       reco::TrackRef recoTrack = recoMu.track();
00221       if(fabs(recoTrack->eta())>EtaCutMin && fabs(recoTrack->eta())<EtaCutMax){
00222         etaTrack[iEtaRegion]->Fill(recoTrack->eta());
00223         phiTrack[iEtaRegion]->Fill(recoTrack->phi());
00224         pTrack[iEtaRegion]->Fill(recoTrack->p());
00225         ptTrack[iEtaRegion]->Fill(recoTrack->pt());
00226         chi2Track[iEtaRegion]->Fill(recoTrack->normalizedChi2());
00227         chi2probTrack[iEtaRegion]->Fill(TMath::Prob(recoTrack->normalizedChi2(),recoTrack->ndof()));
00228       }
00229     }
00230 
00231     if(recoMu.isStandAloneMuon()) {
00232       LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] The mu is standalone - filling the histos";
00233       // get the track using only the mu spectrometer data
00234       reco::TrackRef recoStaTrack = recoMu.standAloneMuon();
00235       if(fabs(recoStaTrack->eta())>EtaCutMin && fabs(recoStaTrack->eta())<EtaCutMax){
00236         etaStaTrack[iEtaRegion]->Fill(recoStaTrack->eta());
00237         phiStaTrack[iEtaRegion]->Fill(recoStaTrack->phi());
00238         pStaTrack[iEtaRegion]->Fill(recoStaTrack->p());
00239         ptStaTrack[iEtaRegion]->Fill(recoStaTrack->pt());
00240         chi2StaTrack[iEtaRegion]->Fill(recoStaTrack->normalizedChi2());
00241         chi2probStaTrack[iEtaRegion]->Fill(TMath::Prob(recoStaTrack->normalizedChi2(),recoStaTrack->ndof()));
00242       }
00243     }
00244 
00245     if ( muon::isTightMuon(recoMu, thePrimaryVertex) ) {
00246       LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] The mu is Tight - filling the histos";
00247       reco::TrackRef recoTightTrack = recoMu.combinedMuon();
00248       if(fabs(recoTightTrack->eta())>EtaCutMin && fabs(recoTightTrack->eta())<EtaCutMax){
00249         etaTightTrack[iEtaRegion]->Fill(recoTightTrack->eta());
00250         phiTightTrack[iEtaRegion]->Fill(recoTightTrack->phi());
00251         pTightTrack[iEtaRegion]->Fill(recoTightTrack->p());
00252         ptTightTrack[iEtaRegion]->Fill(recoTightTrack->pt());
00253         chi2TightTrack[iEtaRegion]->Fill(recoTightTrack->normalizedChi2());
00254         chi2probTightTrack[iEtaRegion]->Fill(TMath::Prob(recoTightTrack->normalizedChi2(),recoTightTrack->ndof()));
00255       }
00256     }
00257 
00258 
00259     if ( muon::isLooseMuon(recoMu) ) {
00260       LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] The mu is Loose - filling the histos";
00261       reco::TrackRef recoLooseTrack; 
00262 
00263       if ( recoMu.isGlobalMuon()) recoLooseTrack = recoMu.combinedMuon();
00264       else recoLooseTrack = recoMu.track();
00265 
00266       if(fabs(recoLooseTrack->eta())>EtaCutMin && fabs(recoLooseTrack->eta())<EtaCutMax){
00267         etaLooseTrack[iEtaRegion]->Fill(recoLooseTrack->eta());
00268         phiLooseTrack[iEtaRegion]->Fill(recoLooseTrack->phi());
00269         pLooseTrack[iEtaRegion]->Fill(recoLooseTrack->p());
00270         ptLooseTrack[iEtaRegion]->Fill(recoLooseTrack->pt());
00271         chi2LooseTrack[iEtaRegion]->Fill(recoLooseTrack->normalizedChi2());
00272         chi2probLooseTrack[iEtaRegion]->Fill(TMath::Prob(recoLooseTrack->normalizedChi2(),recoLooseTrack->ndof()));
00273       }
00274     }
00275 
00276     if ( muon::isSoftMuon(recoMu, thePrimaryVertex) ) {
00277       LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] The mu is Soft - filling the histos";
00278       reco::TrackRef recoSoftTrack = recoMu.track();
00279       if(fabs(recoSoftTrack->eta())>EtaCutMin && fabs(recoSoftTrack->eta())<EtaCutMax){
00280         etaSoftTrack[iEtaRegion]->Fill(recoSoftTrack->eta());
00281         phiSoftTrack[iEtaRegion]->Fill(recoSoftTrack->phi());
00282         pSoftTrack[iEtaRegion]->Fill(recoSoftTrack->p());
00283         ptSoftTrack[iEtaRegion]->Fill(recoSoftTrack->pt());
00284         chi2SoftTrack[iEtaRegion]->Fill(recoSoftTrack->normalizedChi2());
00285         chi2probSoftTrack[iEtaRegion]->Fill(TMath::Prob(recoSoftTrack->normalizedChi2(),recoSoftTrack->ndof()));
00286       }
00287     }
00288 
00289     if ( muon::isHighPtMuon(recoMu, thePrimaryVertex) ) {
00290       LogTrace(metname)<<"[MuonKinVsEtaAnalyzer] The mu is HightPt - filling the histos";
00291       reco::TrackRef recoHighPtTrack = recoMu.combinedMuon();
00292       if(fabs(recoHighPtTrack->eta())>EtaCutMin && fabs(recoHighPtTrack->eta())<EtaCutMax){
00293         etaHighPtTrack[iEtaRegion]->Fill(recoHighPtTrack->eta());
00294         phiHighPtTrack[iEtaRegion]->Fill(recoHighPtTrack->phi());
00295         pHighPtTrack[iEtaRegion]->Fill(recoHighPtTrack->p());
00296         ptHighPtTrack[iEtaRegion]->Fill(recoHighPtTrack->pt());
00297         chi2HighPtTrack[iEtaRegion]->Fill(recoHighPtTrack->normalizedChi2());
00298         chi2probHighPtTrack[iEtaRegion]->Fill(TMath::Prob(recoHighPtTrack->normalizedChi2(),recoHighPtTrack->ndof()));
00299       }
00300       }
00301 
00302   }
00303 }