Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //-------------------------------
0002 // Usage: .L plot_jets_data_vs_MC.C
0003 //        plot_METDQM("DQM_V0001_R000123575__JetMET__CMSSW_3_3_4__Harvesting.root",
0004 //                    "DQM_reference.root",
0005 //                    123575,
0006 //                    "path-to-web-space",
0007 //                    "png");
0008 //-------------------------------
0009 #include <stdio.h>
0010 #include <stdlib.h>
0011 
0012 int plot_jets_data_vs_MC(std::string filename, std::string reffile, int run, std::string outdir, std::string imgformat="png") {
0013 
0014   //-------------------------------
0015 
0016   gStyle->SetCanvasBorderMode(0);
0017   gStyle->SetPadBorderMode(0);
0018   gStyle->SetCanvasColor(0);
0019   gStyle->SetFrameLineWidth(2);
0020   gStyle->SetPadColor(0);
0021   gStyle->SetTitleFillColor(0);
0022   gStyle->SetStatColor(0);
0023   
0024   gStyle->SetOptStat(111110);
0025   gStyle->SetOptFit(1100);
0026   
0027   gStyle->SetStatX(0.92);
0028   gStyle->SetStatY(0.86);
0029   gStyle->SetStatW(0.60);
0030   gStyle->SetStatH(0.20);
0031 
0032   gStyle->SetTitleX(0.15);
0033   gStyle->SetTitleY(0.98);
0034   gStyle->SetTitleW(0.5);
0035   gStyle->SetTitleH(0.06);
0036 
0037   //-------------------------------
0038 
0039   TFile *f1, *f2, *h;
0040 
0041   TCanvas* Pt = new TCanvas("Pt", "Pt", 1200, 900);
0042   TCanvas* Eta = new TCanvas("Eta", "Eta", 1200, 900);
0043   TCanvas* Phi = new TCanvas("Phi", "Phi", 1200, 900);
0044   TCanvas* Mass = new TCanvas("Mass", "Mass", 1200, 900);
0045   TCanvas* resEMF = new TCanvas("resEMF", "resEMF", 1200, 900);
0046   TCanvas* fHPD = new TCanvas("fHPD", "fHPD", 1200, 900);
0047   TCanvas* N90Hits = new TCanvas("N90Hits", "N90Hits", 1200, 900);
0048   TCanvas* Constituents = new TCanvas("Constituents", "Constituents", 1200, 900);
0049 
0050   //-----
0051   char cprefix[3000];
0052   sprintf(cprefix,"DQMData/Run %d/JetMET/Run summary",run);
0053   printf("%s\n",cprefix);
0054   char cprefixRef[3000];
0055   sprintf(cprefixRef,"DQMData/Run 1/JetMET/Run summary");
0056   printf("%s\n",cprefixRef);
0057   char ctitle[3000];
0058   char ctitleRef[3000];
0059   char cjpgname[3000];
0060   //-----
0061 
0062   Pt->Divide(1,1);
0063   Eta->Divide(1,1);
0064   Phi->Divide(1,1);
0065   Mass->Divide(1,1);
0066   resEMF->Divide(1,1);
0067   fHPD->Divide(1,1);
0068   N90Hits->Divide(1,1);
0069   Constituents->Divide(1,1);
0070 
0071   std::cout << filename << std::endl;
0072   f1 = new TFile(filename.c_str());
0073   f2 = new TFile(reffile.c_str());
0074   
0075   h = new TFile( "result.root", "RECREATE");
0076 
0077   //
0078   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/Pt",cprefix);
0079   sprintf(ctitleRef,"%s/Jet/AntiKtJets/Pt",cprefixRef);
0080   TH1D *hDpT = f1->Get(ctitle);
0081   TH1D *hMpT = f2->Get(ctitleRef);
0082   //
0083   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/Eta",cprefix);
0084   sprintf(ctitleRef,"%s/Jet/AntiKtJets/Eta",cprefixRef);
0085   TH1D *hDEta = f1->Get(ctitle);
0086   TH1D *hMEta = f2->Get(ctitleRef);
0087   //
0088   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/Phi",cprefix);
0089   sprintf(ctitleRef,"%s/Jet/AntiKtJets/Phi",cprefixRef);
0090   TH1D *hDPhi = f1->Get(ctitle);
0091   TH1D *hMPhi = f2->Get(ctitleRef);
0092   //
0093   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/Mass",cprefix);
0094   sprintf(ctitleRef,"%s/Jet/AntiKtJets/Mass",cprefixRef);
0095   TH1D *hDMass = f1->Get(ctitle);
0096   TH1D *hMMass = f2->Get(ctitleRef);
0097   //
0098   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/resEMF",cprefix);
0099   sprintf(ctitleRef,"%s/Jet/AntiKtJets/resEMF",cprefixRef);
0100   TH1D *hDresEMF = f1->Get(ctitle);
0101   TH1D *hMresEMF = f2->Get(ctitleRef);
0102   //
0103   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/fHPD",cprefix);
0104   sprintf(ctitleRef,"%s/Jet/AntiKtJets/fHPD",cprefixRef);
0105   TH1D *hDfHPD = f1->Get(ctitle);
0106   TH1D *hMfHPD = f2->Get(ctitleRef);
0107   //
0108   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/N90Hits",cprefix);
0109   sprintf(ctitleRef,"%s/Jet/AntiKtJets/N90Hits",cprefixRef);
0110   TH1D *hDN90Hits = f1->Get(ctitle);
0111   TH1D *hMN90Hits = f2->Get(ctitleRef);
0112   //
0113   sprintf(ctitle,"%s/Jet/CleanedAntiKtJets/Constituents",cprefix);
0114   sprintf(ctitleRef,"%s/Jet/AntiKtJets/Constituents",cprefixRef);
0115   TH1D *hDConstituents = f1->Get(ctitle);
0116   TH1D *hMConstituents = f2->Get(ctitleRef);
0117   //
0118 
0119   h->Write();
0120 
0121   //---------------
0122   Pt->cd(1);
0123   hMpT->SetLineColor(2);
0124   hMpT->SetFillColor(2);
0125   hMpT->SetLineWidth(3);
0126   hDpT->SetLineWidth(3);
0127   hDpT->SetMarkerStyle(20);
0128   if (hMpT->GetEntries()>0) 
0129     hMpT->Scale((hDpT->GetEntries())/(hMpT->GetEntries()));
0130   else 
0131     hMpT->Scale(1);
0132   hMpT->SetStats(kFALSE);
0133 
0134   THStack * hpT = new THStack( "hs", "jet pT");
0135 
0136   hpT->Add( hMpT, "hist");
0137   hpT->Add( hDpT, "e");
0138 
0139   hpT->Draw("nostack");
0140 //  if (hDpT->GetMaximum()>hMpT->GetMaximum()) { hDpT->Draw(""); hMpT->Draw("Sames");}
0141 //  else if { hMpT->Draw(""); hDpT->Draw("sames");}
0142 
0143   //---------------
0144   Eta->cd(1);
0145   hMEta->SetLineColor(2);
0146   hMEta->SetFillColor(2);
0147   hMEta->SetLineWidth(3);
0148   hDEta->SetLineWidth(3);
0149   hDEta->SetMarkerStyle(20);
0150   if (hMEta->GetEntries()>0) 
0151     hMEta->Scale((hDEta->GetEntries())/(hMEta->GetEntries()));
0152   else 
0153     hMEta->Scale(1)
0154   hMEta->SetStats(kFALSE);
0155 
0156   THStack * hEta = new THStack( "hs", "jet eta");
0157 
0158   hEta->Add( hMEta, "hist");
0159   hEta->Add( hDEta, "e"); 
0160   hEta->Draw("nostack");
0161 
0162   //---------------
0163   Phi->cd(1);
0164   hMPhi->SetLineColor(2);
0165   hMPhi->SetFillColor(2);
0166   hMPhi->SetLineWidth(3);
0167   hDPhi->SetLineWidth(3);
0168   hDPhi->SetMarkerStyle(20);
0169   if (hMPhi->GetEntries()>0) 
0170     hMPhi->Scale((hDPhi->GetEntries())/(hMPhi->GetEntries()));
0171   else 
0172     hMPhi->Scale(1)
0173   hMPhi->SetStats(kFALSE);
0174 
0175   THStack * hPhi = new THStack( "hs", "jet phi");
0176 
0177   hPhi->Add( hMPhi, "hist");
0178   hPhi->Add( hDPhi, "e");
0179 
0180   hPhi->Draw("nostack");
0181 
0182   //---------------
0183   Mass->cd(1);
0184   hMMass->SetLineColor(2);
0185   hMMass->SetFillColor(2);
0186   hMMass->SetLineWidth(3);
0187   hDMass->SetLineWidth(3);
0188   hDMass->SetMarkerStyle(20);
0189   if (hMMass->GetEntries()>0) 
0190     hMMass->Scale((hDMass->GetEntries())/(hMMass->GetEntries()));
0191   else 
0192     hMMass->Scale(1)
0193   hMMass->SetStats(kFALSE);
0194 
0195   THStack * hMass = new THStack( "hs", "jet mass");
0196 
0197   hMass->Add( hMMass, "hist");
0198   hMass->Add( hDMass, "e");
0199 
0200   hMass->Draw("nostack");
0201 
0202   //---------------
0203   resEMF->cd(1);
0204   hMresEMF->SetLineColor(2);
0205   hMresEMF->SetFillColor(2);
0206   hMresEMF->SetLineWidth(3);
0207   hDresEMF->SetLineWidth(3);
0208   hDresEMF->SetMarkerStyle(20);
0209   if (hMresEMF->GetEntries()>0) 
0210     hMresEMF->Scale((hDresEMF->GetEntries())/(hMresEMF->GetEntries()));
0211   else 
0212     hMresEMF->Scale(1)
0213   hMresEMF->SetStats(kFALSE);
0214 
0215   THStack * hresEMF = new THStack( "hs", "restricted EMF");
0216 
0217   hresEMF->Add( hMresEMF, "hist");
0218   hresEMF->Add( hDresEMF, "e");
0219 
0220   hresEMF->Draw("nostack");
0221 
0222   //---------------
0223   fHPD->cd(1);
0224   hMfHPD->SetLineColor(2);
0225   hMfHPD->SetFillColor(2);
0226   hMfHPD->SetLineWidth(3);
0227   hDfHPD->SetLineWidth(3);
0228   hDfHPD->SetMarkerStyle(20);
0229   if (hMfHPD->GetEntries()>0) 
0230     hMfHPD->Scale((hDfHPD->GetEntries())/(hMfHPD->GetEntries()));
0231   else 
0232     hMfHPD->Scale(1)
0233   hMfHPD->SetStats(kFALSE);
0234 
0235   THStack * hfHPD = new THStack( "hs", "fHPD");
0236 
0237   hfHPD->Add( hMfHPD, "hist");
0238   hfHPD->Add( hDfHPD, "e");
0239 
0240   hfHPD->Draw("nostack");
0241 
0242   //---------------
0243   N90Hits->cd(1);
0244   hMN90Hits->SetLineColor(2);
0245   hMN90Hits->SetFillColor(2);
0246   hMN90Hits->SetLineWidth(3);
0247   hDN90Hits->SetLineWidth(3);
0248   hDN90Hits->SetMarkerStyle(20);
0249   if (hMN90Hits->GetEntries()>0) 
0250     hMN90Hits->Scale((hDN90Hits->GetEntries())/(hMN90Hits->GetEntries()));
0251   else 
0252     hMN90Hits->Scale(1)
0253   hMN90Hits->SetStats(kFALSE);
0254 
0255   THStack * hN90Hits = new THStack( "hs", "N90Hits");
0256 
0257   hN90Hits->Add( hMN90Hits, "hist");
0258   hN90Hits->Add( hDN90Hits, "e");
0259 
0260   hN90Hits->Draw("nostack");
0261 
0262   //---------------
0263   Constituents->cd(1);
0264   hMConstituents->SetLineColor(2);
0265   hMConstituents->SetFillColor(2);
0266   hMConstituents->SetLineWidth(3);
0267   hDConstituents->SetLineWidth(3);
0268   hDConstituents->SetMarkerStyle(20);
0269   if (hMConstituents->GetEntries()>0) 
0270     hMConstituents->Scale((hDConstituents->GetEntries())/(hMConstituents->GetEntries()));
0271   else 
0272     hMConstituents->Scale(1)
0273   hMConstituents->SetStats(kFALSE);
0274 
0275   THStack * hConstituents = new THStack( "hs", "# of Constituents");
0276 
0277   hConstituents->Add( hMConstituents, "hist");
0278   hConstituents->Add( hDConstituents, "e");
0279 
0280   hConstituents->Draw("nostack");
0281 
0282   //---------------
0283   Pt->Update();
0284   Eta->Update();
0285   Phi->Update();
0286   Mass->Update();
0287   resEMF->Update();
0288   fHPD->Update();
0289   N90Hits->Update();
0290   Constituents->Update();
0291 
0292   //---------------
0293   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/pt.%s",outdir.c_str(),run,imgformat.c_str());
0294   Pt->SaveAs(cjpgname);
0295   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/Eta.%s",outdir.c_str(),run,imgformat.c_str());
0296   Eta->SaveAs(cjpgname);
0297   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/Phi.%s",outdir.c_str(),run,imgformat.c_str());
0298   Phi->SaveAs(cjpgname);
0299   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/Mass.%s",outdir.c_str(),run,imgformat.c_str());
0300   Mass->SaveAs(cjpgname);
0301   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/resEMF.%s",outdir.c_str(),run,imgformat.c_str());
0302   resEMF->SaveAs(cjpgname);
0303   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/fHPD.%s",outdir.c_str(),run,imgformat.c_str());
0304   fHPD->SaveAs(cjpgname);
0305   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/N90Hits.%s",outdir.c_str(),run,imgformat.c_str());
0306   N90Hits->SaveAs(cjpgname);
0307   sprintf(cjpgname,"%s%d/JetDQM/CaloJetAntiKt/Constituents.%s",outdir.c_str(),run,imgformat.c_str());
0308   Constituents->SaveAs(cjpgname);
0309 
0310   h->Close();
0311 
0312 }
0313