Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:41

0001 
0002 /*
0003  *  See header file for a description of this class.
0004  *
0005  *  \author G. Mila - INFN Torino
0006  */
0007 
0008 #include <DQMOffline/Muon/interface/MuonRecoTest.h>
0009 
0010 // Framework
0011 #include <FWCore/Framework/interface/Event.h>
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include <FWCore/Framework/interface/ESHandle.h>
0014 #include <FWCore/Framework/interface/MakerMacros.h>
0015 #include <FWCore/Framework/interface/EventSetup.h>
0016 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0017 
0018 #include "DQMServices/Core/interface/DQMStore.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "FWCore/Framework/interface/Run.h"
0021 
0022 #include <iostream>
0023 #include <cstdio>
0024 #include <string>
0025 #include <cmath>
0026 #include "TF1.h"
0027 
0028 using namespace edm;
0029 using namespace std;
0030 
0031 MuonRecoTest::MuonRecoTest(const edm::ParameterSet& ps) {
0032   parameters = ps;
0033 
0034   prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
0035 
0036   // Parameters
0037   etaBin = parameters.getParameter<int>("etaBin");
0038   etaMin = parameters.getParameter<double>("etaMin");
0039   etaMax = parameters.getParameter<double>("etaMax");
0040 
0041   phiBin = parameters.getParameter<int>("phiBin");
0042   phiMin = parameters.getParameter<double>("phiMin");
0043   phiMax = parameters.getParameter<double>("phiMax");
0044 
0045   EfficiencyCriterionName = parameters.getUntrackedParameter<string>("efficiencyTestName", "EfficiencyInRange");
0046 }
0047 
0048 void MuonRecoTest::dqmEndRun(DQMStore::IBooker& ibooker,
0049                              DQMStore::IGetter& igetter,
0050                              edm::Run const&,
0051                              edm::EventSetup const&) {
0052   // efficiency plot
0053   ibooker.setCurrentFolder("Muons/Tests/muonRecoTest");
0054   etaEfficiency = ibooker.book1D("etaEfficiency_staMuon", "#eta_{STA} efficiency", etaBin, etaMin, etaMax);
0055   phiEfficiency = ibooker.book1D("phiEfficiency_staMuon", "#phi_{STA} efficiency", phiBin, phiMin, phiMax);
0056 
0057   /// GETTING PREVIOUS HISTOS AND DO SOME OPERATIONS
0058   string path = "Muons/MuonRecoAnalyzer/StaEta_ifCombinedAlso";
0059   MonitorElement* staEtaIfComb_histo = igetter.get(path);
0060   path = "Muons/MuonRecoAnalyzer/StaEta";
0061   MonitorElement* staEta_histo = igetter.get(path);
0062 
0063   if (staEtaIfComb_histo && staEta_histo) {
0064     TH1F* staEtaIfComb_root = staEtaIfComb_histo->getTH1F();
0065     TH1F* staEta_root = staEta_histo->getTH1F();
0066 
0067     if (staEtaIfComb_root->GetXaxis()->GetNbins() != etaBin || staEtaIfComb_root->GetXaxis()->GetXmax() != etaMax ||
0068         staEtaIfComb_root->GetXaxis()->GetXmin() != etaMin) {
0069       LogTrace(metname) << "[MuonRecoTest] wrong histo binning on eta histograms";
0070       return;
0071     }
0072 
0073     for (int i = 1; i <= etaBin; i++) {
0074       if (staEta_root->GetBinContent(i) != 0) {
0075         double efficiency = double(staEtaIfComb_root->GetBinContent(i)) / double(staEta_root->GetBinContent(i));
0076         etaEfficiency->setBinContent(i, efficiency);
0077       }
0078     }
0079   }
0080 
0081   path = "Muons/MuonRecoAnalyzer/StaPhi_ifCombinedAlso";
0082   MonitorElement* staPhiIfComb_histo = igetter.get(path);
0083   path = "Muons/MuonRecoAnalyzer/StaPhi";
0084   MonitorElement* staPhi_histo = igetter.get(path);
0085 
0086   if (staPhiIfComb_histo && staPhi_histo) {
0087     TH1F* staPhiIfComb_root = staPhiIfComb_histo->getTH1F();
0088     TH1F* staPhi_root = staPhi_histo->getTH1F();
0089 
0090     if (staPhiIfComb_root->GetXaxis()->GetNbins() != phiBin || staPhiIfComb_root->GetXaxis()->GetXmax() != phiMax ||
0091         staPhiIfComb_root->GetXaxis()->GetXmin() != phiMin) {
0092       LogTrace(metname) << "[MuonRecoTest] wrong histo binning on phi histograms";
0093       return;
0094     }
0095 
0096     for (int i = 1; i <= etaBin; i++) {
0097       if (staPhi_root->GetBinContent(i) != 0) {
0098         double efficiency = double(staPhiIfComb_root->GetBinContent(i)) / double(staPhi_root->GetBinContent(i));
0099         phiEfficiency->setBinContent(i, efficiency);
0100       }
0101     }
0102   }
0103 }
0104 
0105 void MuonRecoTest::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0106   /// BOOKING NEW HISTOGRAMS
0107   ibooker.setCurrentFolder("Muons/Tests/muonRecoTest");
0108   // alignment plots
0109   globalRotation.push_back(ibooker.book1D(
0110       "muVStkSytemRotation_posMu_profile", "pT_{TK} / pT_{GLB} vs pT_{GLB} profile for #mu^{+}", 50, 0, 200));
0111   globalRotation.push_back(ibooker.book1D(
0112       "muVStkSytemRotation_negMu_profile", "pT_{TK} / pT_{GLB} vs pT_{GLB} profile for #mu^{-}", 50, 0, 200));
0113   globalRotation.push_back(ibooker.book1D(
0114       "muVStkSytemRotation_profile", "pT_{TK} / pT_{GLB} vs pT_{GLB} profile for #mu^{+}-#mu^{-}", 50, 0, 200));
0115 
0116   // efficiency test
0117 
0118   // eta efficiency
0119   const QReport* theEtaQReport = etaEfficiency->getQReport(EfficiencyCriterionName);
0120   if (theEtaQReport) {
0121     vector<dqm::me_util::Channel> badChannels = theEtaQReport->getBadChannels();
0122     for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0123          channel++) {
0124       LogTrace(metname) << "[etaEfficiency test] bad ranges: " << (*channel).getBin()
0125                         << "  Contents : " << (*channel).getContents() << endl;
0126     }
0127     LogTrace(metname) << "-------- type: [etaEfficiency]  " << theEtaQReport->getMessage() << " ------- "
0128                       << theEtaQReport->getStatus() << endl;
0129   }
0130   // phi efficiency
0131   const QReport* thePhiQReport = phiEfficiency->getQReport(EfficiencyCriterionName);
0132   if (thePhiQReport) {
0133     vector<dqm::me_util::Channel> badChannels = thePhiQReport->getBadChannels();
0134     for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0135          channel++) {
0136       LogTrace(metname) << "[phiEfficiency test] bad ranges: " << (*channel).getBin()
0137                         << "  Contents : " << (*channel).getContents() << endl;
0138     }
0139     LogTrace(metname) << "-------- type: [phiEfficiency]  " << thePhiQReport->getMessage() << " ------- "
0140                       << thePhiQReport->getStatus() << endl;
0141   }
0142 
0143   //alignment plot
0144   string pathPos = "Muons/MuonRecoAnalyzer/muVStkSytemRotation_posMu";
0145   MonitorElement* muVStkSytemRotation_posMu_histo = igetter.get(pathPos);
0146   string pathNeg = "Muons/MuonRecoAnalyzer/muVStkSytemRotation_negMu";
0147   MonitorElement* muVStkSytemRotation_negMu_histo = igetter.get(pathNeg);
0148   if (muVStkSytemRotation_posMu_histo && muVStkSytemRotation_negMu_histo) {
0149     TH2F* muVStkSytemRotation_posMu_root = muVStkSytemRotation_posMu_histo->getTH2F();
0150     TProfile* muVStkSytemRotation_posMu_profile = muVStkSytemRotation_posMu_root->ProfileX("", 1, 100);
0151     TH2F* muVStkSytemRotation_negMu_root = muVStkSytemRotation_negMu_histo->getTH2F();
0152     TProfile* muVStkSytemRotation_negMu_profile = muVStkSytemRotation_negMu_root->ProfileX("", 1, 100);
0153 
0154     for (int x = 1; x < 50; x++) {
0155       globalRotation[0]->Fill((x * 4) - 1, muVStkSytemRotation_posMu_profile->GetBinContent(x));
0156       globalRotation[0]->setBinError(x, muVStkSytemRotation_posMu_profile->GetBinError(x));
0157       globalRotation[1]->Fill((x * 4) - 1, muVStkSytemRotation_negMu_profile->GetBinContent(x));
0158       globalRotation[1]->setBinError(x, muVStkSytemRotation_negMu_profile->GetBinError(x));
0159       globalRotation[2]->Fill(
0160           (x * 4) - 1,
0161           muVStkSytemRotation_posMu_profile->GetBinContent(x) - muVStkSytemRotation_negMu_profile->GetBinContent(x));
0162       globalRotation[2]->setBinError(
0163           x,
0164           sqrt(
0165               (muVStkSytemRotation_posMu_profile->GetBinError(x) * muVStkSytemRotation_posMu_profile->GetBinError(x)) +
0166               (muVStkSytemRotation_negMu_profile->GetBinError(x) * muVStkSytemRotation_negMu_profile->GetBinError(x))));
0167     }
0168   }
0169 }