Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:14

0001 
0002 /* ///////////////////////////////////////////////////////////////////////
0003  Example usages:
0004 
0005 
0006  ///////////////////////////////////////////////////////////////////////  
0007 */
0008 
0009 
0010 
0011 void  dumpScaleFactorTables() {
0012 
0013 // dumpScaleFactorTables("efficiency-data-GsfElectronToId.root", "efficiency-mc-GsfElectronToId.root", "GsfElectronToId", "WP90");
0014 // dumpScaleFactorTables("efficiency-data-GsfElectronToId.root", "efficiency-mc-GsfElectronToId.root", "GsfElectronToId", "WP85");
0015 // dumpScaleFactorTables("efficiency-data-GsfElectronToId.root", "efficiency-mc-GsfElectronToId.root", "GsfElectronToId", "WP80");
0016 
0017 // dumpScaleFactorTables("efficiency-data-GsfElectronToId.root", "efficiency-mc-GsfElectronToId.root", "GsfElectronToId", "CicLoose");
0018 // dumpScaleFactorTables("efficiency-data-GsfElectronToId.root", "efficiency-mc-GsfElectronToId.root", "GsfElectronToId", "CicTight");
0019 // dumpScaleFactorTables("efficiency-data-GsfElectronToId.root", "efficiency-mc-GsfElectronToId.root", "GsfElectronToId", "CicSuperTight");
0020 // dumpScaleFactorTables("efficiency-data-GsfElectronToId.root", "efficiency-mc-GsfElectronToId.root", "GsfElectronToId", "CicHyperTight1");
0021 
0022 // dumpScaleFactorTables("efficiency-data-SCToGsfElectron.root", "efficiency-mc-SCToGsfElectron.root", "SuperClusterToGsfElectron", "efficiency");
0023  dumpScaleFactorTables("Eff-defaultBin-data/efficiency-data-WP90ToHLT.root", "efficiency-mc-WP90ToHLT.root", "WP90ToHLT", "efficiency");
0024  dumpScaleFactorTables("Eff-defaultBin-data/efficiency-data-WP85ToHLT.root", "efficiency-mc-WP85ToHLT.root", "WP85ToHLT", "efficiency");
0025  dumpScaleFactorTables("Eff-defaultBin-data/efficiency-data-WP80ToHLT.root", "efficiency-mc-WP80ToHLT.root", "WP80ToHLT", "efficiency");
0026  dumpScaleFactorTables("Eff-defaultBin-data/efficiency-data-CicLooseToHLT.root", "efficiency-mc-CicLooseToHLT.root", "CicLooseToHLT", "efficiency");
0027  dumpScaleFactorTables("Eff-defaultBin-data/efficiency-data-CicTightToHLT.root", "efficiency-mc-CicTightToHLT.root", "CicTightToHLT", "efficiency");
0028 }
0029 
0030 
0031 void  dumpScaleFactorTables( char* dataFileName,
0032                  char* mcFileName,
0033                  char* dir="GsfElectronToId", 
0034                  char* subdir="WP90") {
0035 
0036   char temp[50];
0037   char* canvasname = "probe_sc_et_probe_sc_eta_PLOT";
0038   if(dir=="SuperClusterToGsfElectron") canvasname = "probe_et_probe_eta_PLOT";
0039 
0040 
0041   TFile* fData = new TFile(dataFileName);
0042   TFile* fMC = new TFile(mcFileName);
0043   TH2F* hData;
0044   TH2F* hMC;
0045   TCanvas* c;
0046 
0047 
0048   sprintf(temp, "%s/%s/fit_eff_plots/", dir, subdir);
0049   if(TString(temp).Contains("ToHLT")) 
0050     sprintf(temp, "%s/%s/cnt_eff_plots/", dir, subdir);
0051   fData->cd(temp);
0052 
0053   c = (TCanvas*) gDirectory->Get( canvasname );
0054   if(c==0) continue; // do nothing if the canvas doesn't exist
0055   TH2F* hData = (TH2F*) c->FindObject(canvasname );
0056   if( hData==0 ) continue; 
0057 
0058 
0059 
0060   sprintf(temp, "%s/%s/cnt_eff_plots/", dir, subdir);
0061   fMC->cd(temp);
0062   c = (TCanvas*) gDirectory->Get( canvasname );
0063   if(c==0) continue; // do nothing if the canvas doesn't exist
0064   TH2F* hMC = (TH2F*) c->FindObject(canvasname );
0065   if( hMC==0 ) continue; 
0066 
0067 
0068   sprintf(temp, "ScaleFactor_%s_%s.txt", dir, subdir);
0069   hData->Divide(hMC);
0070   makeTable( hData, temp);
0071  
0072   fData->Close();
0073   fMC->Close();
0074   delete fData;
0075   delete fMC;
0076 
0077 }
0078 
0079 
0080 
0081 // generic method to make a efficiency table
0082 void makeTable(TH2F* h, char* tablefilename)
0083 {
0084 
0085   int nX = h->GetNbinsX();
0086   int nY = h->GetNbinsY();
0087 
0088 
0089   FILE *file = fopen(tablefilename,"w+");
0090 
0091 
0092   for(int i=1; i<=nX; ++i) {
0093   
0094     Double_t pT0 = h->GetXaxis()->GetBinLowEdge(i);
0095     Double_t pT1 = h->GetXaxis()->GetBinLowEdge(i+1);
0096 
0097     for(int j=1; j<=nY; ++j) {
0098       Double_t x = h->GetBinContent(i,j);
0099       Double_t dx = h->GetBinError(i,j);
0100       Double_t eta0 = h->GetYaxis()->GetBinLowEdge(j);
0101       Double_t eta1 = h->GetYaxis()->GetBinLowEdge(j+1);
0102 
0103       fprintf( file ,"%4.1f  %4.1f   %+6.4f   %+6.4f  %6.4f   %6.4f \n", 
0104            pT0, pT1, eta0, eta1, x, dx);
0105     }
0106   }
0107 
0108   fclose(file);
0109 }