File indexing completed on 2024-04-06 12:22:43
0001
0002
0003
0004
0005
0006
0007
0008 #include <iostream>
0009 #include <vector>
0010 #include "Gtypes.h"
0011 #include "TROOT.h"
0012 #include "TStyle.h"
0013 #include "TString.h"
0014 #include "TPaveText.h"
0015 #include "TFile.h"
0016 #include "TH1.h"
0017 #include "TH2.h"
0018 #include "TLegend.h"
0019 #include "TCanvas.h"
0020 #include "TList.h"
0021 #include "TMath.h"
0022 #include "RooPlot.h"
0023 #include "TAttMarker.h"
0024
0025 const Color_t colorlist[7]={kRed,kBlack,kBlack,kGreen,kMagenta,kCyan,kTeal};
0026 const Int_t linestylelist[7]={1,1,1,1,1,1,1};
0027 const Int_t stylelist[7]={1,1,1,1,1,1,1};
0028 const Style_t markerstylelist[7]={kFullSquare,kFullCircle,kOpenCircle,kOpenTriangleUp,kOpenCircle,kOpenTriangleUp,kOpenCircle};
0029
0030 void MultiHistoOverlap(TString namesandlabels, Int_t nOfFiles, const TString& outDir="./"){
0031
0032 gROOT->Reset();
0033 gROOT->ProcessLine(".L tdrstyle.C");
0034 gROOT->ProcessLine("setTDRStyle()");
0035
0036
0037
0038
0039 TPaveText *cmsprel = new TPaveText(0.19, 0.95, 0.95, 0.99, "NDC");
0040 cmsprel->SetTextSize(0.03);
0041 cmsprel->SetTextFont(42);
0042 cmsprel->SetFillColor(0);
0043 cmsprel->SetBorderSize(0);
0044 cmsprel->SetMargin(0.01);
0045 cmsprel->SetTextAlign(12);
0046 TString text = "CMS Preliminary 2011";
0047 cmsprel->AddText(0.0, 0.5,text);
0048 TString text2 = "#sqrt{s} = 7 TeV |#eta_{#mu}|<2.4";
0049 cmsprel->AddText(0.8, 0.5, text2);
0050
0051
0052 TList* FileList = new TList();
0053 TList* LabelList = new TList();
0054 TObjArray *nameandlabelpairs = namesandlabels.Tokenize(",");
0055 for (Int_t i = 0; i < nameandlabelpairs->GetEntries(); ++i) {
0056 TObjArray *aFileLegPair = TString(nameandlabelpairs->At(i)->GetName()).Tokenize("=");
0057 if(aFileLegPair->GetEntries() == 2) {
0058 FileList->Add( TFile::Open(aFileLegPair->At(0)->GetName()) );
0059 LabelList->Add( aFileLegPair->At(1) );
0060 } else {
0061 std::cout << "Please give file name and legend entry in the following form:\n" << " filename1=legendentry1,filename2=legendentry2\n";
0062 }
0063 }
0064
0065
0066 Int_t NOfFiles = FileList->GetSize();
0067 if ( NOfFiles!=nOfFiles ){
0068 std::cout<<"&MSG-e: NOfFiles = "<<nOfFiles<<std::endl;
0069 return;
0070 }
0071
0072
0073 std::vector<TString> LegLabels;
0074 LegLabels.reserve(nOfFiles);
0075 for(Int_t j=0; j < nOfFiles; j++) {
0076 TObjString* legend = (TObjString*)LabelList->At(j);
0077 LegLabels.push_back(legend->String());
0078 std::cout<<"LegLabels["<<j<<"]"<<LegLabels[j]<<std::endl;
0079 }
0080
0081 TLegend *leg=0;
0082
0083 TCanvas* c0 = new TCanvas("c0", "c0",50, 20, 800,600);
0084 TCanvas* c1 = new TCanvas("c1", "c1",50, 20, 800,600);
0085 TCanvas* c2 = new TCanvas("c2", "c2",50, 20, 800,600);
0086 TCanvas* c3 = new TCanvas("c3", "c3",50, 20, 800,600);
0087 TCanvas* c4 = new TCanvas("c4", "c4",50, 20, 800,600);
0088 TCanvas* c5 = new TCanvas("c5", "c5",50, 20, 1200,800);
0089 TCanvas* c6 = new TCanvas("c6", "c6",50, 20, 1200,800);
0090
0091 TCanvas* c0s = new TCanvas("c0s", "c0s",50, 20, 800,600);
0092 TCanvas* c1s = new TCanvas("c1s", "c1s",50, 20, 800,600);
0093 TCanvas* c2s = new TCanvas("c2s", "c2s",50, 20, 800,600);
0094 TCanvas* c3s = new TCanvas("c3s", "c3s",50, 20, 800,600);
0095
0096 TCanvas* cFit = new TCanvas("cFit", "cFit",50, 20, 1600, 800);
0097
0098
0099
0100 c0->SetFillColor(0);
0101 c0->cd();
0102
0103 leg = new TLegend(0.50,0.25,0.90,0.40);
0104 leg->SetBorderSize(1);
0105 leg->SetFillColor(0);
0106 leg->SetTextFont(42);
0107
0108
0109 TH1D *histoMassVsPhiPlus[nOfFiles];
0110 for(Int_t j=0; j < nOfFiles; j++) {
0111
0112 TFile *fin = (TFile*)FileList->At(j);
0113 if (( histoMassVsPhiPlus[j] = (TH1D*)fin->Get("MassVsPhiPlus/allHistos/meanHisto"))){
0114 histoMassVsPhiPlus[j]->SetLineStyle(linestylelist[j]);
0115 histoMassVsPhiPlus[j]->SetMarkerColor(colorlist[j]);
0116 histoMassVsPhiPlus[j]->SetLineColor(colorlist[j]);
0117 histoMassVsPhiPlus[j]->SetMarkerStyle(markerstylelist[j]);
0118
0119 if ( j == 0 ) {
0120 histoMassVsPhiPlus[j]->GetXaxis()->SetTitle("positive muon #phi (rad)");
0121 histoMassVsPhiPlus[j]->GetYaxis()->SetTitle("M_{#mu#mu} (GeV)");
0122
0123 histoMassVsPhiPlus[j]->GetYaxis()->SetRangeUser(90.0,91.5);
0124 histoMassVsPhiPlus[j]->GetXaxis()->SetRangeUser(-3.14,3.14);
0125 histoMassVsPhiPlus[j]->Draw();
0126 } else {
0127 histoMassVsPhiPlus[j]->Draw("SAME");
0128 }
0129 leg->AddEntry(histoMassVsPhiPlus[j],LegLabels[j],"PL");
0130 }
0131 }
0132
0133 leg->Draw("same");
0134 c0->SaveAs(outDir+"MassVsPhiPlus.png");
0135
0136
0137
0138 c1->SetFillColor(0);
0139 c1->cd();
0140
0141 leg = new TLegend(0.50,0.25,0.90,0.40);
0142 leg->SetBorderSize(1);
0143 leg->SetFillColor(0);
0144 leg->SetTextFont(42);
0145
0146
0147 TH1D *histoMassVsEtaPlus[nOfFiles];
0148 for(Int_t j=0; j < nOfFiles; j++) {
0149
0150 TFile *fin = (TFile*)FileList->At(j);
0151 if (( histoMassVsEtaPlus[j] = (TH1D*)fin->Get("MassVsEtaPlus/allHistos/meanHisto"))){
0152 histoMassVsEtaPlus[j]->SetLineStyle(linestylelist[j]);
0153 histoMassVsEtaPlus[j]->SetMarkerColor(colorlist[j]);
0154 histoMassVsEtaPlus[j]->SetLineColor(colorlist[j]);
0155 histoMassVsEtaPlus[j]->SetMarkerStyle(markerstylelist[j]);
0156
0157 if ( j == 0 ) {
0158 histoMassVsEtaPlus[j]->GetXaxis()->SetTitle("positive muon #eta");
0159 histoMassVsEtaPlus[j]->GetYaxis()->SetTitle("M_{#mu#mu} (GeV)");
0160
0161 histoMassVsEtaPlus[j]->GetYaxis()->SetRangeUser(90.0,91.5);
0162 histoMassVsEtaPlus[j]->GetXaxis()->SetRangeUser(-2.41,2.41);
0163 histoMassVsEtaPlus[j]->Draw();
0164 } else {
0165 histoMassVsEtaPlus[j]->Draw("SAME");
0166 }
0167 leg->AddEntry(histoMassVsEtaPlus[j],LegLabels[j],"PL");
0168 }
0169 }
0170
0171 leg->Draw("same");
0172 c1->SaveAs(outDir+"MassVsEtaPlus.png");
0173
0174
0175
0176 c2->SetFillColor(0);
0177 c2->cd();
0178
0179 leg = new TLegend(0.50,0.25,0.90,0.40);
0180 leg->SetBorderSize(1);
0181 leg->SetFillColor(0);
0182 leg->SetTextFont(42);
0183
0184
0185 TH1D *histoMassVsEtaPlusMinusDiff[nOfFiles];
0186 for(Int_t j=0; j < nOfFiles; j++) {
0187
0188 TFile *fin = (TFile*)FileList->At(j);
0189 if (( histoMassVsEtaPlusMinusDiff[j] = (TH1D*)fin->Get("MassVsEtaPlusMinusDiff/allHistos/meanHisto"))){
0190 histoMassVsEtaPlusMinusDiff[j]->SetLineStyle(linestylelist[j]);
0191 histoMassVsEtaPlusMinusDiff[j]->SetMarkerColor(colorlist[j]);
0192 histoMassVsEtaPlusMinusDiff[j]->SetLineColor(colorlist[j]);
0193 histoMassVsEtaPlusMinusDiff[j]->SetMarkerStyle(markerstylelist[j]);
0194
0195 if ( j == 0 ) {
0196 histoMassVsEtaPlusMinusDiff[j]->GetXaxis()->SetTitle("#eta pos. muon #eta neg. muon");
0197 histoMassVsEtaPlusMinusDiff[j]->GetYaxis()->SetTitle("M_{#mu#mu} (GeV)");
0198
0199 histoMassVsEtaPlusMinusDiff[j]->GetYaxis()->SetRangeUser(90.0,91.5);
0200 histoMassVsEtaPlusMinusDiff[j]->GetXaxis()->SetRangeUser(-3,3);
0201 histoMassVsEtaPlusMinusDiff[j]->Draw();
0202 } else {
0203 histoMassVsEtaPlusMinusDiff[j]->Draw("SAME");
0204 }
0205 leg->AddEntry(histoMassVsEtaPlusMinusDiff[j],LegLabels[j],"PL");
0206 }
0207 }
0208
0209 leg->Draw("same");
0210 c2->SaveAs(outDir+"MassVsEtaPlusMinusDiff.png");
0211
0212
0213 c3->SetFillColor(0);
0214 c3->cd();
0215
0216 leg = new TLegend(0.50,0.25,0.90,0.40);
0217 leg->SetBorderSize(1);
0218 leg->SetFillColor(0);
0219 leg->SetTextFont(42);
0220
0221
0222 TH1D *histoMassVsPhiMinus[nOfFiles];
0223 for(Int_t j=0; j < nOfFiles; j++) {
0224
0225 TFile *fin = (TFile*)FileList->At(j);
0226 if (( histoMassVsPhiMinus[j] = (TH1D*)fin->Get("MassVsPhiMinus/allHistos/meanHisto"))){
0227 histoMassVsPhiMinus[j]->SetLineStyle(linestylelist[j]);
0228 histoMassVsPhiMinus[j]->SetMarkerColor(colorlist[j]);
0229 histoMassVsPhiMinus[j]->SetLineColor(colorlist[j]);
0230 histoMassVsPhiMinus[j]->SetMarkerStyle(markerstylelist[j]);
0231
0232 if ( j == 0 ) {
0233 histoMassVsPhiMinus[j]->GetXaxis()->SetTitle("negative muon #phi (rad)");
0234 histoMassVsPhiMinus[j]->GetYaxis()->SetTitle("M_{#mu#mu} (GeV)");
0235
0236 histoMassVsPhiMinus[j]->GetYaxis()->SetRangeUser(90.0,91.5);
0237 histoMassVsPhiMinus[j]->GetXaxis()->SetRangeUser(-3.14,3.14);
0238 histoMassVsPhiMinus[j]->Draw();
0239 } else {
0240 histoMassVsPhiMinus[j]->Draw("SAME");
0241 }
0242 leg->AddEntry(histoMassVsPhiMinus[j],LegLabels[j],"PL");
0243 }
0244 }
0245
0246 leg->Draw("same");
0247 c3->SaveAs(outDir+"MassVsPhiMinus.png");
0248
0249
0250
0251 c4->SetFillColor(0);
0252 c4->cd();
0253
0254 leg = new TLegend(0.50,0.25,0.90,0.40);
0255 leg->SetBorderSize(1);
0256 leg->SetFillColor(0);
0257 leg->SetTextFont(42);
0258
0259
0260 TH1D *histoMassVsEtaMinus[nOfFiles];
0261 for(Int_t j=0; j < nOfFiles; j++) {
0262
0263 TFile *fin = (TFile*)FileList->At(j);
0264 if (( histoMassVsEtaMinus[j] = (TH1D*)fin->Get("MassVsEtaMinus/allHistos/meanHisto"))){
0265 histoMassVsEtaMinus[j]->SetLineStyle(linestylelist[j]);
0266 histoMassVsEtaMinus[j]->SetMarkerColor(colorlist[j]);
0267 histoMassVsEtaMinus[j]->SetLineColor(colorlist[j]);
0268 histoMassVsEtaMinus[j]->SetMarkerStyle(markerstylelist[j]);
0269
0270 if ( j == 0 ) {
0271 histoMassVsEtaMinus[j]->GetXaxis()->SetTitle("negative muon #eta");
0272 histoMassVsEtaMinus[j]->GetYaxis()->SetTitle("M_{#mu#mu} (GeV)");
0273
0274 histoMassVsEtaMinus[j]->GetYaxis()->SetRangeUser(90.0,91.5);
0275 histoMassVsEtaMinus[j]->GetXaxis()->SetRangeUser(-2.41,2.41);
0276 histoMassVsEtaMinus[j]->Draw();
0277 } else {
0278 histoMassVsEtaMinus[j]->Draw("SAME");
0279 }
0280 leg->AddEntry(histoMassVsEtaMinus[j],LegLabels[j],"PL");
0281 }
0282 }
0283
0284 leg->Draw("same");
0285 c4->SaveAs(outDir+"MassVsEtaMinus.png");
0286
0287
0288 c5->SetFillColor(0);
0289 c5->cd();
0290
0291 leg = new TLegend(0.50,0.25,0.90,0.40);
0292 leg->SetBorderSize(1);
0293 leg->SetFillColor(0);
0294 leg->SetTextFont(42);
0295
0296
0297 TH2D *histoMassVsEtaPhiPlus[nOfFiles];
0298
0299 TStyle *newStyle;
0300 newStyle->SetPalette(1);
0301
0302
0303 Double_t zMin(82.);
0304 Double_t zMax(96.);
0305 for(Int_t j=0; j < nOfFiles; j++) {
0306
0307 TFile *fin = (TFile*)FileList->At(j);
0308 if (( histoMassVsEtaPhiPlus[j] = (TH2D*)fin->Get("MassVsEtaPhiPlus/allHistos/meanHisto"))){
0309 if ( j == 0 ) {
0310 histoMassVsEtaPhiPlus[j]->SetTitle(LegLabels[j]);
0311 histoMassVsEtaPhiPlus[j]->GetXaxis()->SetTitle("positive muon #phi (rad)");
0312 histoMassVsEtaPhiPlus[j]->GetYaxis()->SetTitle("positive muon #eta");
0313 zMin = histoMassVsEtaPhiPlus[j]->GetMinimum();
0314 zMax = histoMassVsEtaPhiPlus[j]->GetMaximum();
0315 histoMassVsEtaPhiPlus[j]->Draw("COLZ");
0316 c5->SaveAs(outDir+"MassVsEtaPhiPlus_file0.png");
0317 } else {
0318 histoMassVsEtaPhiPlus[j]->SetTitle(LegLabels[j]);
0319 histoMassVsEtaPhiPlus[j]->SetMinimum(zMin);
0320 histoMassVsEtaPhiPlus[j]->SetMaximum(zMax);
0321 histoMassVsEtaPhiPlus[j]->Draw("COLZ");
0322 c5->SaveAs(outDir+"MassVsEtaPhiPlus_file"+(TString)Form("%d",(Int_t)j)+".png");
0323 }
0324
0325 }
0326 }
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365 const Color_t colorlist_resol[7]={kBlack,kGreen,kBlue,kMagenta,kCyan,kTeal,kRed};
0366 const Int_t linestylelist_resol[7]={1,1,1,1,1,1,1};
0367 const Int_t stylelist_resol[7]={1,1,1,1,1,1,1};
0368 const Style_t markerstylelist_resol[7]={kOpenCircle,kOpenTriangleUp,kOpenTriangleUp,kOpenCircle,kOpenTriangleUp,kOpenCircle,kOpenTriangleUp};
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410 c1s->SetFillColor(0);
0411 c1s->cd();
0412
0413 leg = new TLegend(0.50,0.25,0.90,0.40);
0414 leg->SetBorderSize(1);
0415 leg->SetFillColor(0);
0416 leg->SetTextFont(42);
0417
0418
0419
0420 TH1D *histoSigmaVsEtaPlus[nOfFiles];
0421 for(Int_t j=0; j < nOfFiles; j++) {
0422
0423 TFile *fin = (TFile*)FileList->At(j);
0424 if (( histoSigmaVsEtaPlus[j] = (TH1D*)fin->Get("MassVsEtaPlus/allHistos/sigmaHisto"))){
0425 histoSigmaVsEtaPlus[j]->SetLineStyle(linestylelist_resol[j]);
0426 histoSigmaVsEtaPlus[j]->SetMarkerColor(colorlist_resol[j]);
0427 histoSigmaVsEtaPlus[j]->SetLineColor(colorlist_resol[j]);
0428 histoSigmaVsEtaPlus[j]->SetMarkerStyle(markerstylelist_resol[j]);
0429
0430 if ( j == 0 ) {
0431 histoSigmaVsEtaPlus[j]->GetXaxis()->SetTitle("positive muon #eta");
0432 histoSigmaVsEtaPlus[j]->GetYaxis()->SetTitle("#sigma(M_{#mu#mu}) (GeV)");
0433
0434 histoSigmaVsEtaPlus[j]->GetYaxis()->SetRangeUser(0.,3.);
0435 histoSigmaVsEtaPlus[j]->GetXaxis()->SetRangeUser(-2.41,2.41);
0436 histoSigmaVsEtaPlus[j]->Draw();
0437 } else {
0438 histoSigmaVsEtaPlus[j]->Draw("SAME");
0439 }
0440 leg->AddEntry(histoSigmaVsEtaPlus[j],LegLabels[j],"PL");
0441 }
0442 }
0443
0444 leg->Draw("same");
0445 c1s->SaveAs(outDir+"SigmaVsEtaPlus.png");
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526 cFit->SetFillColor(0);
0527 cFit->cd();
0528 Float_t nN = TMath::Sqrt(nOfFiles);
0529 Int_t nX = (Int_t)nN;
0530 if ( nN-nX > 0.5 ) nX++;
0531 Int_t nY = (Int_t)(nOfFiles/nX);
0532 std::cout << nX << " ," << nY << std::endl;
0533 cFit->Divide(nOfFiles,1);
0534
0535
0536 TFile *ZFitFile = new TFile("ZFitFile.root","RECREATE");
0537 RooPlot *histoLineShape[nOfFiles];
0538 for(Int_t j=0; j < nOfFiles; j++) {
0539
0540 TFile *fin = (TFile*)FileList->At(j);
0541 if (( histoLineShape[j] = (RooPlot*)fin->Get("hRecBestResAllEvents_Mass_frame"))){
0542 std::cout<<"Writing fit histogrem file n. "<<j<<std::endl;
0543 histoLineShape[j]->Write();
0544 cFit->cd(j+1);
0545 histoLineShape[j]->SetTitle(LegLabels[j]);
0546 histoLineShape[j]->Draw();
0547 histoLineShape[j]->GetXaxis()->SetTitle("M_{#mu#mu} (GeV)");
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557 }
0558 }
0559 ZFitFile->Close();
0560
0561 cFit->SaveAs("ZFitFile.root");
0562
0563
0564
0565 return;
0566 };