Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:33:21

0001 #include "TCanvas.h"
0002 #include "TDirectoryFile.h"
0003 #include "TFile.h"
0004 #include "TH1F.h"
0005 #include "TLegend.h"
0006 #include "TObjString.h"
0007 #include "TROOT.h"
0008 #include "TString.h"
0009 #include "TStyle.h"
0010 #include <iostream>
0011 
0012 void effic(char* filename1, char* filename2 = 0) {
0013     TFile* f1 = TFile::Open(filename1);
0014     if (! f1) {
0015         std::cout << "Error: unable to open " << filename1 << std::endl;
0016         return;
0017     }
0018     TDirectoryFile* d1 = (TDirectoryFile*)f1->FindObjectAny("MuonIdVal");
0019     if (! d1)
0020         if (f1->cd("/DQMData/Run 1/MuonIdentificationV/Run summary"))
0021             d1 = (TDirectoryFile*)gDirectory;
0022     if (! d1)
0023         if (f1->cd("/DQMData/Run 1/Muons/Run summary/MuonIdentificationV"))
0024             d1 = (TDirectoryFile*)gDirectory;
0025     if (! d1) {
0026         std::cout << "Error: MuonIdVal/MuonIdentificationV not found in " << filename1 << std::endl;
0027         return;
0028     }
0029 
0030     TFile* f2 = 0;
0031     TDirectoryFile* d2 = 0;
0032     if (filename2) {
0033         f2 = TFile::Open(filename2);
0034         if (! f2) {
0035             std::cout << "Error: unable to open " << filename2 << std::endl;
0036             return;
0037         }
0038         d2 = (TDirectoryFile*)f2->FindObjectAny("MuonIdVal");
0039         if (! d2)
0040             if (f2->cd("/DQMData/Run 1/MuonIdentificationV/Run summary"))
0041                 d2 = (TDirectoryFile*)gDirectory;
0042         if (! d2)
0043             if (f2->cd("/DQMData/Run 1/Muons/Run summary/MuonIdentificationV"))
0044                 d2 = (TDirectoryFile*)gDirectory;
0045         if (! d2) {
0046             std::cout << "Error: MuonIdVal/MuonIdentificationV not found in " << filename2 << std::endl;
0047             return;
0048         }
0049     }
0050 
0051     gROOT->ForceStyle();
0052     gStyle->SetOptStat(0);
0053 
0054     // Retrieve CMSSW versions for TLegend
0055     TString version1 = ((TObjString*)f1->GetListOfKeys()->At(0))->GetString().Remove(TString::kLeading, '"').Remove(TString::kTrailing, '"');
0056     TString version2 = "";
0057     if (f2)
0058         version2 = ((TObjString*)f2->GetListOfKeys()->At(0))->GetString().Remove(TString::kLeading, '"').Remove(TString::kTrailing, '"');
0059     //std::cout << "version1: " << version1.Data() << std::endl;
0060     //std::cout << "version2: " << version2.Data() << std::endl;
0061 
0062     TDirectoryFile* tmd1 = (TDirectoryFile*)d1->Get("TrackerMuons");
0063     TDirectoryFile* gmd1 = (TDirectoryFile*)d1->Get("GlobalMuons");
0064     TDirectoryFile* tmd2 = 0;
0065     TDirectoryFile* gmd2 = 0;
0066     if (d2) {
0067         tmd2 = (TDirectoryFile*)d2->Get("TrackerMuons");
0068         gmd2 = (TDirectoryFile*)d2->Get("GlobalMuons");
0069     }
0070 
0071     TCanvas* c = new TCanvas("c");
0072     c->Draw();
0073     TLegend* leg = 0;
0074 
0075     // Access histograms in three different locations:
0076     //   d1 -> MuonIdVal
0077     // tmd1 -> MuonIdVal/TrackerMuons
0078     // gmd1 -> MuonIdVal/GlobalMuons
0079     char pfx[2][4] = {"tm_", "gm_"};
0080     char det[2][4] = {"DT", "CSC"};
0081 
0082     TH1F* eff1 = 0;
0083     TH1F* num1 = 0;
0084     TH1F* den1 = 0;
0085     TH1F* eff2 = 0;
0086     TH1F* num2 = 0;
0087     TH1F* den2 = 0;
0088 
0089     for(unsigned int i = 0; i < 2; i++) {
0090         if (i == 0 && tmd1) { d1 = tmd1; d2 = tmd2; }
0091         else if (i == 1 && gmd1) { d1 = gmd1; d2 = gmd2; }
0092         else continue;
0093 
0094         for(unsigned int j = 0; j < 2; j++) { // detector
0095             eff1 = (TH1F*)d1->Get(Form("h%s1DistWithSegment", det[j]))->Clone(Form("%sh%sDistEffic1", pfx[i], det[j]));
0096             eff1->Reset();
0097             num1 = (TH1F*)eff1->Clone(Form("%sh%sDistNum1", pfx[i], det[j]));
0098             den1 = (TH1F*)eff1->Clone(Form("%sh%sDistDen1", pfx[i], det[j]));
0099             eff1->Sumw2();
0100             num1->Sumw2();
0101             den1->Sumw2();
0102 
0103             if (d2) {
0104                 eff2 = (TH1F*)eff1->Clone(Form("%sh%sDistEffic2", pfx[i], det[j]));
0105                 num2 = (TH1F*)eff1->Clone(Form("%sh%sDistNum2", pfx[i], det[j]));
0106                 den2 = (TH1F*)eff1->Clone(Form("%sh%sDistDen2", pfx[i], det[j]));
0107                 if (eff2 && num2 && den2) {
0108                     eff2->Sumw2();
0109                     num2->Sumw2();
0110                     den2->Sumw2();
0111                 } else
0112                     eff2 = 0;
0113             }
0114 
0115             for (int k = 1; k <= 4; k++) { // station
0116                 num1->Add((TH1F*)d1->Get(Form("h%s%iDistWithSegment", det[j], k)));
0117                 den1->Add((TH1F*)d1->Get(Form("h%s%iDistWithSegment", det[j], k)));
0118                 den1->Add((TH1F*)d1->Get(Form("h%s%iDistWithNoSegment", det[j], k)));
0119                 if (eff2) {
0120                     num2->Add((TH1F*)d2->Get(Form("h%s%iDistWithSegment", det[j], k)));
0121                     den2->Add((TH1F*)d2->Get(Form("h%s%iDistWithSegment", det[j], k)));
0122                     den2->Add((TH1F*)d2->Get(Form("h%s%iDistWithNoSegment", det[j], k)));
0123                 }
0124             }
0125 
0126             eff1->SetTitle("");
0127             eff1->GetXaxis()->SetTitle("distance to nearest chamber edge [cm]");
0128             eff1->GetYaxis()->SetTitle("efficiency");
0129             eff1->GetYaxis()->SetTitleOffset(1.1);
0130             eff1->Divide(num1, den1, 1., 1., "B");
0131             eff1->SetLineColor(1);
0132             eff1->SetLineStyle(1);
0133             eff1->Draw("histe");
0134             eff1->SetMaximum(1.1);
0135             if (eff2) {
0136                 eff2->Divide(num2, den2, 1., 1., "B");
0137                 eff2->SetLineColor(2);
0138                 eff2->SetLineStyle(2);
0139                 eff2->Draw("histesame");
0140                 double ks = eff1->KolmogorovTest(eff2);
0141                 eff1->SetTitle(Form("KS: %f", ks));
0142             }
0143 
0144             leg = 0;
0145             leg = new TLegend(0., 0., .22, .06);
0146             leg->SetFillColor(0);
0147             leg->AddEntry(eff1, version1.Data(), "l");
0148             if (eff2)
0149                leg->AddEntry(eff2, version2.Data(), "l");
0150             leg->Draw();
0151             c->Update();
0152             c->Print(Form("%sh%sDistEffic.png", pfx[i], det[j]));
0153         } // for unsigned int j
0154     } // for unsigned int i
0155 } // void effic