File indexing completed on 2024-04-06 12:30:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 #include "TCanvas.h"
0169 #include "TDirectory.h"
0170 #include "TF1.h"
0171 #include "TFile.h"
0172 #include "TFitResult.h"
0173 #include "TGraph.h"
0174 #include "TGraphAsymmErrors.h"
0175 #include "TH1D.h"
0176 #include "TH2D.h"
0177 #include "THStack.h"
0178 #include "TLegend.h"
0179 #include "TMath.h"
0180 #include "TProfile.h"
0181 #include "TPaveStats.h"
0182 #include "TPaveText.h"
0183 #include "TROOT.h"
0184 #include "TString.h"
0185 #include "TStyle.h"
0186
0187 #include <iostream>
0188 #include <iomanip>
0189 #include <vector>
0190 #include <string>
0191
0192
0193
0194
0195
0196
0197 const int nmodelm=5, nmodelx=6, nmodels=3;
0198 int styles[7] = {20, 21, 24, 22, 23, 25, 33};
0199 int colors[7] = {1, 2, 4, 6, 7, 38, 3};
0200 std::string names[7] = {"All", "Quality", "okEcal", "EcalCharIso",
0201 "HcalCharIso", "EcalNeutIso", "HcalNeutIso"};
0202 std::string namefull[7]= {"All tracks", "Good quality tracks",
0203 "Tracks reaching ECAL", "Charge isolation in ECAL",
0204 "Charge isolation in HCAL", "Isolated in ECAL",
0205 "Isolated in HCAL"};
0206 std::string nameEta[4] = {"i#eta 1:6","i#eta 7:12","i#eta 13:16","i#eta 17:22"};
0207 std::string nameEtas[4]= {"|#eta| < 0.52", "0.52 < |#eta| < 1.04",
0208 "1.04 < |#eta| < 1.39", "1.39 < |#eta| < 2.01"};
0209 std::string namePV[5] = {"all PV","PV 1:1","PV 2:2","PV 3:5","PV > 5"};
0210 std::string varname[4] = {"p", "pt", "eta", "phi"};
0211 std::string vartitle[4]= {"p (GeV/c)", "p_{T} (GeV/c)", "#eta", "#phi"};
0212 std::string nameC[2] = {"Ecal", "Hcal"};
0213 std::string nameCF[2] = {"ECAL", "HCAL"};
0214 std::string varnameC[4]= {"maxNearP", "ediff", "ene1", "ene2"};
0215 std::string vartitlC[4]= {"Charge isolation energy",
0216 "Neutral isolation energy",
0217 "Energy in smaller cone",
0218 "Energy in larger cone"};
0219 const int NPT=10;
0220 double mom[NPT]={1.5,2.5,3.5,4.5,5.5,6.5,8.0,10.0,13.0,17.5};
0221 double dmom[NPT]={0.5,0.5,0.5,0.5,0.5,0.5,1.0,1.0,2.0,2.5};
0222 std::string varPs[NPT] = {"1:2","2:3","3:4","4:5","5:6","6:7","7:9",
0223 "9:11","11:15","15:20"};
0224 std::string varPs1[NPT] = {"1","2","3","4","5","6","7","9","11","15"};
0225 std::string varPPs[NPT] = {"1-2 GeV","2-3 GeV","3-4 GeV","4-5 GeV","5-6 GeV",
0226 "6-7 GeV","7-9 GeV","9-11 GeV","11-15 GeV",
0227 "15-20 GeV"};
0228 std::string varEta[4] = {"1:6", "7:12", "13:16", "17:23"};
0229 std::string varEta1[4]= {"1", "2", "3", "4"};
0230 std::string varEne[6] = {"E_{7x7}", "H_{3x3}", "(E_{7x7}+H_{3x3})",
0231 "E_{11x11}", "H_{5x5}", "(E_{11x11}+H_{5x5})"};
0232 std::string varEne1[6]= {"E7x7","H3x3","E7x7H3x3","E11x11","H5x5", "E11x11H5x5"};
0233 const int nbins=100;
0234 double xbins[nbins+1] = {0.00,0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,
0235 0.10,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,
0236 0.20,0.21,0.22,0.23,0.24,0.25,0.26,0.27,0.28,0.29,
0237 0.30,0.31,0.32,0.33,0.34,0.35,0.36,0.37,0.38,0.39,
0238 0.40,0.41,0.42,0.43,0.44,0.45,0.46,0.47,0.48,0.49,
0239 0.50,0.52,0.54,0.56,0.58,0.60,0.62,0.64,0.66,0.68,
0240 0.70,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,
0241 0.90,0.92,0.94,0.96,0.98,1.00,1.05,1.10,1.15,1.20,
0242 1.25,1.30,1.35,1.40,1.45,1.50,1.55,1.60,1.65,1.70,
0243 1.75,1.80,1.85,1.90,1.95,2.00,2.10,2.20,2.30,2.40,
0244 2.50};
0245 int ibins[nbins+1] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
0246 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
0247 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
0248 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
0249 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
0250 61, 63, 65, 67, 69, 71, 73, 75, 77, 79,
0251 81, 83, 85, 87, 89, 91, 93, 95, 97, 99,
0252 101,103,105,107,109,111,116,121,126,131,
0253 136,141,146,151,156,161,166,171,176,181,
0254 186,191,196,201,206,211,221,231,241,251,261};
0255
0256
0257
0258
0259 std::string files[nmodels]={"2017C_ZB.root","2017G_ZB.root","2017H_ZB.root"};
0260 std::string types[nmodels]={"Zero Bias (2017C)","Zero Bias (2017G)",
0261 "Zero Bias (2017H)"};
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
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
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385 std::string filem[nmodelm]={"pikp/QFB4p0vMixStudyHLT.root",
0386 "pikp/QFB4p3vMixStudyHLT.root",
0387 "pikp/QFB5r00vMixStudyHLT.root",
0388 "pikp/QFB5r05vMixStudyHLT.root",
0389 "pikp/QFB5r06vMixStudyHLT.root"};
0390 std::string typem[nmodelm]={"10.4 QGSP_FTFP_BERT_EML",
0391 "10.4.p03 QGSP_FTFP_BERT_EML",
0392 "10.5 QGSP_FTFP_BERT_EML",
0393 "10.5.ref05 QGSP_FTFP_BERT_EML",
0394 "10.5.ref06 QGSP_FTFP_BERT_EML"};
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
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
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539 std::string filex[nmodelx]={"AllDataStudyHLT.root",
0540 "pikp/QFB4p0vMixStudyHLT.root",
0541 "pikp/QFB4p3vMixStudyHLT.root",
0542 "pikp/QFB5r00vMixStudyHLT.root",
0543 "pikp/QFB5r05vMixStudyHLT.root",
0544 "pikp/QFB5r06vMixStudyHLT.root"};
0545 std::string typex[nmodelx]={"Data (2016B)",
0546 "10.4 QGSP_FTFP_BERT_EML",
0547 "10.4.p03 QGSP_FTFP_BERT_EML",
0548 "10.5 QGSP_FTFP_BERT_EML",
0549 "10.5.ref05 QGSP_FTFP_BERT_EML",
0550 "10.5.ref06 QGSP_FTFP_BERT_EML"};
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562 void plotAll(std::string fname="hlt.root", std::string HLT="All HLTs", int var=-1, int ien=-1, int eta=-1, bool varbin=false, int rebin=1, bool approve=true, bool logy=true, int pos=0, bool pv=false, int savePlot=-1);
0563 void plotEnergyAll(std::string fname="", std::string hlt="All HLTs", int models=15, int pv=0, int data=4, bool varbin=false, int rebin=5, bool approve=true, bool logy=true, int pos=0, int var=-1, int ene=-1, int eta=-1, int savePlot=-1);
0564 void plotEMeanAll(int data=4, int models=63, bool ratio=true, bool approve=true, std::string postfix="", int savePlot=-1);
0565 void plotEMean(std::string fname="", std::string hlt="All HLTs", int models=15, int var=0, int eta=0, int pv=0, int dataMC=1, bool raio=false, bool approve=true, std::string postfix="",int savePlot=-1);
0566 TCanvas* plotEMeanDraw(std::vector<std::string> fnames, std::vector<std::string> hlts, int var, int eta, int pv=0, bool approve=false, std::string dtype="Data", int coloff=0);
0567 TCanvas* plotEMeanRatioDraw(std::vector<std::string> fnames, std::vector<std::string> hlts, int var, int eta, int pv=0, bool approve=false, std::string dtype="Data", int coloff=0);
0568 TCanvas* plotEnergies(std::vector<std::string> fnames, std::vector<std::string> hlts, int var=0, int ien=0, int eta=0, int pv=0, bool varbin=false, int rebin=1, bool approve=false, std::string dtype="Data", bool logy=true, int pos=0, int coloff=0);
0569 TCanvas* plotEnergy(std::string fname="hlt.root", std::string HLT="All HLTs", int var=0, int ien=0, int eta=0, bool varbin=false, int rebin=1, bool approve=false, bool logy=true, int pos=0, int coloff=0);
0570 void plotEMeanPVAll(std::string fname="StudyHLT_ZeroBias_1PV.root", std::string HLT="Zero Bias", int var=-1, int eta=-1, bool approve=true);
0571 TCanvas* plotEMeanDrawPV(std::string fname="StudyHLT_ZeroBias_1PV.root", std::string HLT="Zero Bias", int var=0, int eta=0, bool approve=true);
0572 TCanvas* plotEnergyPV(std::string fnamee="StudyHLT_HLTZeroBias.root", std::string HLT="Zero Bias", int var=0, int ien=0, int eta=0, bool varbin=false, int rebin=1, bool approve=false, bool logy=true, int pos=0);
0573 TCanvas* plotTrack(std::string fname="hlt.root", std::string HLT="All HLTs", int var=0, bool varbin=false, int rebin=1, bool approve=false, bool logy=true, int pos=0);
0574 TCanvas* plotIsolation(std::string fname="hlt.root", std::string HLT="All HLTs", int var=0, bool varbin=false, int rebin=1, bool approve=false, bool logy=true, int pos=0);
0575 TCanvas* plotHLT(std::string fname="hlt.root", std::string HLT="All HLTs", int run=-1, bool varbin=false, int rebin=1, bool approve=false, bool logy=true, int pos=0);
0576 TCanvas* plotHisto(char* cname, std::string HLT, TObjArray& histArr, std::vector<std::string>& labels, std::vector<int>& color, char* name, double ymx0, bool logy, int pos, double yloff, double yhoff, double xmax=-1, bool varbin=false, int rebin=1, bool approve=false);
0577 void getHistStats(TH1D *h, int& entries, int& integral, double& mean, double& meanE, double& rms, double& rmsE, int& uflow, int& oflow);
0578 TFitResultPtr getHistFitStats(TH1F *h, const char* formula, double xlow, double xup, unsigned int& nPar, double* par, double* epar);
0579 void setHistAttr(TH1F *h, int icol, int lwid=1, int ltype=1);
0580 double getWeightedMean (int npt, int Start, std::vector<double>& mean, std::vector<double>& emean);
0581 TH1D* rebin(TH1D* histin, int);
0582
0583 void plotAll(std::string fname, std::string HLT, int var, int ien, int eta,
0584 bool varbin, int rebin, bool approve, bool logy, int pos, bool pv,
0585 int savePlot) {
0586 int varmin(0), varmax(5), enemin(0), enemax(9), etamin(0), etamax(3);
0587 if (var >= 0) varmin = varmax = var;
0588 if (ien >= 0) enemin = enemax = ien;
0589 if (eta >= 0) etamin = etamax = eta;
0590
0591
0592 for (int var=varmin; var<=varmax; ++var) {
0593 for (int ene=enemin; ene<=enemax; ++ene) {
0594 for (int eta=etamin; eta<=etamax; ++eta) {
0595 TCanvas *c(0);
0596 if (pv) {
0597 c = plotEnergyPV(fname, HLT, var, ene, eta, varbin, rebin, approve, logy, pos);
0598 } else {
0599 c = plotEnergy(fname, HLT, var, ene, eta, varbin, rebin, approve, logy, pos);
0600 }
0601 if (c != 0 && savePlot >= 0 && savePlot < 3) {
0602 std::string ext[3] = {"eps", "gif", "pdf"};
0603 char name[200];
0604 sprintf (name, "%s.%s", c->GetName(), ext[savePlot].c_str());
0605 c->Print(name);
0606 }
0607 }
0608 }
0609 }
0610 }
0611
0612 void plotEnergyAll(std::string fname, std::string hlt, int models, int pv,
0613 int data, bool varbin, int rebin, bool approve, bool logy,
0614 int pos, int var, int ene, int eta, int savePlot) {
0615
0616 std::vector<std::string> fnames, hlts;
0617 std::string dtype = (data == 1) ? "Data" : "MC";
0618 int modeluse(models);
0619 int coloff = (data == 4) ? 0 : 1;
0620 if (fname == "") {
0621 if (data == 1) {
0622 for (int i=0; i<nmodels; ++i) {
0623 if (modeluse%2 == 1) {
0624 fnames.push_back(files[i]); hlts.push_back(types[i]);
0625 }
0626 modeluse /= 2;
0627 }
0628 } else if (data == 4) {
0629 for (int i=0; i<nmodelx; ++i) {
0630 if (modeluse%2 == 1) {
0631 fnames.push_back(filex[i]); hlts.push_back(typex[i]);
0632 }
0633 modeluse /= 2;
0634 }
0635 } else {
0636 for (int i=0; i<nmodelm; ++i) {
0637 if (modeluse%2 == 1) {
0638 fnames.push_back(filem[i]); hlts.push_back(typem[i]);
0639 }
0640 modeluse /= 2;
0641 }
0642 }
0643 } else {
0644 fnames.push_back(fname); hlts.push_back(hlt);
0645 }
0646 int varmin(0), varmax(5), enemin(0), enemax(9), etamin(0), etamax(3);
0647 if (var >= varmin && var <= varmax) varmin = varmax = var;
0648 if (ene >= enemin && ene <= enemax) enemin = enemax = ene;
0649 if (eta >= etamin && eta <= etamax) etamin = etamax = eta;
0650
0651
0652 for (int var=varmin; var<=varmax; ++var) {
0653 for (int ene=enemin; ene<=enemax; ++ene) {
0654 for (int eta=etamin; eta<=etamax; ++eta) {
0655 TCanvas *c = plotEnergies(fnames, hlts, var, ene, eta, pv, varbin,
0656 rebin, approve, dtype, logy, pos, coloff);
0657 if (c != 0 && savePlot >= 0 && savePlot < 3) {
0658 std::string ext[3] = {"eps", "gif", "pdf"};
0659 char name[200];
0660 sprintf (name, "%s.%s", c->GetName(), ext[savePlot].c_str());
0661 c->Print(name);
0662 }
0663 }
0664 }
0665 }
0666 }
0667
0668 void plotEMeanAll(int data, int models, bool ratio, bool approve,
0669 std::string postfix, int savePlot){
0670 int varmin(0), varmax(5), pvmin(0), pvmax(0), etamin(0), etamax(3);
0671
0672
0673 for (int var=varmin; var<=varmax; ++var) {
0674 for (int eta=etamin; eta<=etamax; ++eta) {
0675 for (int pv=pvmin; pv<=pvmax; ++pv) {
0676 plotEMean("", "", models, var, eta, pv, data, ratio, approve, postfix,
0677 savePlot);
0678 }
0679 }
0680 }
0681 }
0682
0683 void plotEMean(std::string fname, std::string hlt, int models, int var, int eta,
0684 int pv, int data, bool ratio, bool approve, std::string postfix,
0685 int savePlot) {
0686
0687 std::vector<std::string> fnames, hlts;
0688 std::string dtype = (data == 1) ? "Data" : "MC";
0689 int modeluse(models);
0690 int coloff = (data == 4 || data == 3) ? 0 : 1;
0691 if (fname == "") {
0692 if (data == 1) {
0693 for (int i=0; i<nmodels; ++i) {
0694 if (modeluse%2 == 1) {
0695 fnames.push_back(files[i]); hlts.push_back(types[i]);
0696 }
0697 modeluse /= 2;
0698 }
0699 } else if (data == 4) {
0700 for (int i=0; i<nmodelx; ++i) {
0701 if (modeluse%2 == 1) {
0702 fnames.push_back(filex[i]); hlts.push_back(typex[i]);
0703 }
0704 modeluse /= 2;
0705 }
0706 } else if (data == 3) {
0707 for (int i=0; i<nmodelx; ++i) {
0708 if (modeluse%2 == 1) {
0709 fnames.push_back(filex[i]); hlts.push_back(typex[i]);
0710 }
0711 modeluse /= 2;
0712 }
0713 } else {
0714 for (int i=0; i<nmodelm; ++i) {
0715 if (modeluse%2 == 1) {
0716 fnames.push_back(filem[i]); hlts.push_back(typem[i]);
0717 }
0718 modeluse /= 2;
0719 }
0720 }
0721 } else {
0722 fnames.push_back(fname); hlts.push_back(hlt);
0723 }
0724 int varmin(0), varmax(5), etamin(0), etamax(3), pvmin(0), pvmax(4);
0725 if (var >= 0) varmin = varmax = var;
0726 if (eta >= 0) etamin = etamax = eta;
0727 if (pv >= 0) pvmin = pvmax = pv;
0728
0729
0730 for (int var=varmin; var<=varmax; ++var) {
0731 for (int eta=etamin; eta<=etamax; ++eta) {
0732 for (int pv=pvmin; pv<=pvmax; ++pv) {
0733 TCanvas* c(0);
0734 if (ratio) {
0735 c = plotEMeanRatioDraw(fnames, hlts, var, eta, pv, approve, dtype, coloff);
0736 } else {
0737 c = plotEMeanDraw(fnames, hlts, var, eta, pv, approve, dtype, coloff);
0738 }
0739 if (c != 0 && savePlot >= 0 && savePlot < 3) {
0740 std::string ext[3] = {"eps", "gif", "pdf"};
0741 char name[200];
0742 sprintf (name, "%s%s.%s", c->GetName(), postfix.c_str(),
0743 ext[savePlot].c_str());
0744 c->Print(name);
0745 }
0746 }
0747 }
0748 }
0749 }
0750
0751 TCanvas* plotEMeanDraw(std::vector<std::string> fnames,
0752 std::vector<std::string> hlts, int var, int eta, int pv,
0753 bool approve, std::string dtype, int coloff) {
0754
0755 bool debug(false);
0756 std::vector<TGraphAsymmErrors*> graphs;
0757 TLegend* legend = new TLegend(0.25, 0.80, 0.975, 0.95);
0758 legend->SetBorderSize(1); legend->SetFillColor(kWhite);
0759 legend->SetMargin(0.2);
0760 for (unsigned k=0; k<fnames.size(); ++k) {
0761 TFile *file = TFile::Open(fnames[k].c_str());
0762 double mean[NPT], dmean[NPT];
0763 for (int i=0; i<NPT; ++i) {
0764 char name[100];
0765 sprintf (name, "h_energy_%d_%d_%d_%d", pv+3, i, eta, var);
0766 TH1D *histo = (TH1D*) file->FindObjectAny(name);
0767 if (histo) {
0768 mean[i] = histo->GetMean();
0769 dmean[i]= histo->GetMeanError();
0770 } else {
0771 mean[i] = -100.;
0772 dmean[i]= 0;
0773 }
0774 }
0775 if (debug) {
0776 std::cout << "Get mean for " << NPT << " points" << std::endl;
0777 for (int i=0; i<NPT; ++i)
0778 std::cout << "[" << i << "]" << " Momentum " << mom[i] << " +- "
0779 << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
0780 << std::endl;
0781 }
0782 TGraphAsymmErrors *graph = new TGraphAsymmErrors(NPT, mom, mean, dmom,dmom, dmean,dmean);
0783 graph->SetMarkerStyle(styles[coloff+k]);
0784 graph->SetMarkerColor(colors[coloff+k]);
0785 graph->SetMarkerSize(1.6);
0786 graph->SetLineColor(colors[coloff+k]);
0787 graph->SetLineWidth(2);
0788 graphs.push_back(graph);
0789 legend->AddEntry(graph, hlts[k].c_str(), "lp");
0790 if (debug) std::cout << "Complete " << hlts[k] << std::endl;
0791 file->Close();
0792 }
0793
0794 char cname[100], name[200];
0795 sprintf (cname, "c_%s_%d_%d_%s", varEne1[var].c_str(), eta, pv, dtype.c_str());
0796 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0797 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
0798 gStyle->SetOptTitle(kFALSE); gStyle->SetPadBorderMode(0);
0799 gStyle->SetCanvasBorderMode(0);
0800 TCanvas *canvas = new TCanvas(cname, cname, 500, 400);
0801 gStyle->SetOptStat(0); gPad->SetTopMargin(0.05);
0802 gPad->SetLeftMargin(0.15); gPad->SetRightMargin(0.025);
0803 gPad->SetBottomMargin(0.20);
0804 TH1F *vFrame = canvas->DrawFrame(0.0, 0.01, 50.0, 0.5);
0805 vFrame->GetYaxis()->SetRangeUser(0.0,1.6);
0806 vFrame->GetXaxis()->SetLabelSize(0.06);
0807 vFrame->GetYaxis()->SetLabelSize(0.05);
0808 vFrame->GetXaxis()->SetTitleSize(0.06);
0809 vFrame->GetYaxis()->SetTitleSize(0.06);
0810 vFrame->GetYaxis()->SetTitleOffset(0.9);
0811 vFrame->GetXaxis()->SetRangeUser(1.0,20.0);
0812 if (approve) {
0813 sprintf (name, "Mean of %s/p_{Track}", varEne[var].c_str());
0814 } else {
0815 sprintf (name, "<%s/p_{Track}>", varEne[var].c_str());
0816 }
0817 vFrame->GetYaxis()->SetTitle(name);
0818 sprintf (name, "p_{Track} (GeV/c)");
0819 vFrame->GetXaxis()->SetTitle(name);
0820 for (unsigned int ii=0; ii<graphs.size(); ++ii) graphs[ii]->Draw("P");
0821 legend->Draw();
0822 TLine *line = new TLine(1.0, 1.0, 20.0, 1.0);
0823 line->SetLineStyle(2); line->SetLineWidth(2); line->SetLineColor(kRed);
0824 line->Draw();
0825 TPaveText* text = new TPaveText(0.25, 0.74, 0.55, 0.79, "brNDC");
0826 if (approve) {
0827 sprintf (name, "(%s)", nameEtas[eta].c_str());
0828 } else {
0829 sprintf (name, "(%s, %s)", nameEta[eta].c_str(), namePV[pv].c_str());
0830 }
0831 if (debug) std::cout << "Name " << name << " |" << std::endl;
0832 text->AddText(name);
0833 text->Draw("same");
0834 TPaveText* text2 = new TPaveText(0.55, 0.74, 0.97, 0.79, "brNDC");
0835
0836 sprintf (name, "CMS");
0837 text2->AddText(name);
0838 text2->Draw("same");
0839 return canvas;
0840 }
0841
0842 TCanvas* plotEMeanRatioDraw(std::vector<std::string> fnames,
0843 std::vector<std::string> hlts, int var, int eta,
0844 int pv, bool approve, std::string dtype,
0845 int coloff) {
0846
0847 bool debug(false);
0848 std::vector<TGraphAsymmErrors*> graphs;
0849 TLegend* legend = new TLegend(0.25, 0.80, 0.975, 0.95);
0850 legend->SetBorderSize(1); legend->SetFillColor(kWhite);
0851 legend->SetMargin(0.2);
0852 double mean0[NPT], dmean0[NPT];
0853 for (unsigned k=0; k<fnames.size(); ++k) {
0854 TFile *file = TFile::Open(fnames[k].c_str());
0855 double mean[NPT], dmean[NPT];
0856 for (int i=0; i<NPT; ++i) {
0857 char name[100];
0858 sprintf (name, "h_energy_%d_%d_%d_%d", pv+3, i, eta, var);
0859 TH1D *histo = (TH1D*) file->FindObjectAny(name);
0860 if (histo) {
0861 mean[i] = histo->GetMean();
0862 dmean[i]= histo->GetMeanError();
0863 } else {
0864 mean[i] = -100.;
0865 dmean[i]= 0;
0866 }
0867 }
0868 if (debug) {
0869 std::cout << "Get mean for " << NPT << " points" << std::endl;
0870 for (int i=0; i<NPT; ++i)
0871 std::cout << "[" << i << "]" << " Momentum " << mom[i] << " +- "
0872 << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
0873 << std::endl;
0874 }
0875 if (k == 0) {
0876 for (int i=0; i<NPT; ++i) {
0877 mean0[i] = mean[i];
0878 dmean0[i]= dmean[i];
0879 }
0880 } else {
0881 double sumNum(0), sumDen(0), sumNum1(0), sumDen1(0);
0882 for (int i=0; i<NPT; ++i) {
0883 if (dmean[i] > 0 && dmean0[i] > 0) {
0884 double er1 = dmean[i]/mean[i];
0885 double er2 = dmean0[i]/mean0[i];
0886 mean[i] = mean[i]/mean0[i];
0887 dmean[i]= mean[i]*sqrt(er1*er1+er2*er2);
0888 double temp1 = (mean[i]>1.0) ? 1.0/mean[i] : mean[i];
0889 double temp2 = (mean[i]>1.0) ? dmean[i]/(mean[i]*mean[i]) : dmean[i];
0890 if (i > 0) {
0891 sumNum += (fabs(1-temp1)/(temp2*temp2));
0892 sumDen += (1.0/(temp2*temp2));
0893 }
0894 sumNum1 += (fabs(1-temp1)/(temp2*temp2));
0895 sumDen1 += (1.0/(temp2*temp2));
0896 } else {
0897 mean[i] = -100.;
0898 dmean[i]= 0;
0899 }
0900 }
0901 sumNum = (sumDen>0) ? (sumNum/sumDen) : 0;
0902 sumDen = (sumDen>0) ? 1.0/sqrt(sumDen) : 0;
0903 sumNum1 = (sumDen1>0) ? (sumNum1/sumDen1) : 0;
0904 sumDen1 = (sumDen1>0) ? 1.0/sqrt(sumDen1) : 0;
0905 std::cout << "Get Ratio of mean for " << NPT << " points: Mean " << sumNum << " +- " << sumDen << " (" << sumNum1 << " +- " << sumDen1 << ") Input: " << fnames[k] << " var|eta|pv " << var << ":" << eta << ":" << pv << std::endl;
0906 if (debug) {
0907 std::cout << "Get Ratio of mean for " << NPT << " points: Mean "
0908 << sumNum << " +- " << sumDen << std::endl;
0909 for (int i=0; i<NPT; ++i)
0910 std::cout << "[" << i << "]" << " Momentum " << mom[i] << " +- "
0911 << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
0912 << std::endl;
0913 }
0914 TGraphAsymmErrors *graph = new TGraphAsymmErrors(NPT, mom, mean, dmom,dmom, dmean,dmean);
0915 graph->SetMarkerStyle(styles[coloff+k]);
0916 graph->SetMarkerColor(colors[coloff+k]);
0917 graph->SetMarkerSize(1.6);
0918 graph->SetLineColor(colors[coloff+k]);
0919 graph->SetLineWidth(2);
0920 graphs.push_back(graph);
0921 char text[100];
0922 if (approve) {
0923 sprintf (text,"%s", hlts[k].c_str());
0924 } else {
0925 sprintf (text,"%5.3f #pm %5.3f %s", sumNum, sumDen, hlts[k].c_str());
0926 }
0927 legend->AddEntry(graph, text, "lp");
0928 if (debug) std::cout << "Complete " << hlts[k] << std::endl;
0929 }
0930 file->Close();
0931 }
0932
0933 char cname[100], name[200];
0934 sprintf (cname, "cR_%s_%d_%d_%s", varEne1[var].c_str(), eta, pv, dtype.c_str());
0935 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0936 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
0937 gStyle->SetOptTitle(kFALSE); gStyle->SetPadBorderMode(0);
0938 gStyle->SetCanvasBorderMode(0);
0939 TCanvas *canvas = new TCanvas(cname, cname, 500, 400);
0940 gStyle->SetOptStat(0); gPad->SetTopMargin(0.05);
0941 gPad->SetLeftMargin(0.15); gPad->SetRightMargin(0.025);
0942 gPad->SetBottomMargin(0.20);
0943 TH1F *vFrame = canvas->DrawFrame(0.0, 0.01, 50.0, 0.5);
0944 vFrame->GetYaxis()->SetRangeUser(0.4,1.5);
0945 vFrame->GetXaxis()->SetLabelSize(0.06);
0946 vFrame->GetYaxis()->SetLabelSize(0.05);
0947 vFrame->GetXaxis()->SetTitleSize(0.06);
0948 vFrame->GetYaxis()->SetTitleSize(0.045);
0949 vFrame->GetYaxis()->SetTitleOffset(1.2);
0950 vFrame->GetXaxis()->SetRangeUser(1.0,20.0);
0951 if (approve) {
0952 sprintf (name, "%s/Data for mean of %s/p_{Track}", dtype.c_str(), varEne[var].c_str());
0953 } else {
0954 sprintf (name, "#frac{%s}{%s} for #frac{%s}{p_{Track}}", dtype.c_str(), hlts[0].c_str(), varEne[var].c_str());
0955 }
0956 vFrame->GetYaxis()->SetTitle(name);
0957 sprintf (name, "p_{Track} (GeV/c)");
0958 vFrame->GetXaxis()->SetTitle(name);
0959 for (unsigned int ii=0; ii<graphs.size(); ++ii) graphs[ii]->Draw("P");
0960 legend->Draw();
0961 TLine *line = new TLine(1.0, 1.0, 20.0, 1.0);
0962 line->SetLineStyle(2); line->SetLineWidth(2); line->SetLineColor(kRed);
0963 line->Draw();
0964 TPaveText* text = new TPaveText(0.55, 0.40, 0.95, 0.45, "brNDC");
0965 if (approve) {
0966 sprintf (name, "(%s)", nameEtas[eta].c_str());
0967 } else {
0968 sprintf (name, "(%s, %s)", nameEta[eta].c_str(), namePV[pv].c_str());
0969 }
0970 if (debug) std::cout << "Name " << name << " |" << std::endl;
0971 text->AddText(name);
0972 text->Draw("same");
0973 TPaveText* text2 = new TPaveText(0.55, 0.45, 0.95, 0.50, "brNDC");
0974
0975 sprintf (name, "CMS");
0976 text2->AddText(name);
0977 text2->Draw("same");
0978 return canvas;
0979 }
0980
0981 TCanvas* plotEnergies(std::vector<std::string> fnames,
0982 std::vector<std::string> hlts, int var, int ien, int eta,
0983 int pv, bool varbin, int rebin, bool approve,
0984 std::string dtype, bool logy, int pos, int coloff) {
0985
0986
0987 TLegend* legend = new TLegend(0.55, 0.70, 0.95, 0.85);
0988 legend->SetBorderSize(1); legend->SetFillColor(kWhite);
0989 legend->SetMargin(0.4);
0990 TObjArray histArr;
0991 char name[100];
0992 std::vector<std::string> labels;
0993 std::vector<int> color;
0994 double ymx0(0), ent0(0);
0995 sprintf (name, "h_energy_%d_%d_%d_%d", pv+3, ien, eta, var);
0996 for (unsigned k=0; k<fnames.size(); ++k) {
0997 TFile *file = TFile::Open(fnames[k].c_str());
0998 TH1D *histo = (TH1D*) file->FindObjectAny(name);
0999 if (histo) {
1000 if (k == 0) {
1001 ent0 = histo->GetEntries();
1002 } else {
1003 double scale = (histo->GetEntries() > 0) ? ent0/histo->GetEntries() : 1;
1004 histo->Scale(scale);
1005 }
1006 histArr.AddLast(histo);
1007 labels.push_back(hlts[k]);
1008 color.push_back(colors[coloff+k]);
1009 int ibin = histo->GetMaximumBin();
1010 if (histo->GetBinContent(ibin) > ymx0) ymx0 = histo->GetBinContent(ibin);
1011 }
1012 }
1013 TCanvas* c(0);
1014 if (histArr.GetEntries()>0) {
1015 sprintf (name, "p=%s, %s", varPPs[ien].c_str(), nameEtas[eta].c_str());
1016
1017
1018
1019
1020
1021
1022
1023 std::string clabel(name);
1024 char cname[50];
1025 sprintf (cname, "c_%s_%d_%d_%s", varEne1[var].c_str(), ien, eta, dtype.c_str());
1026 sprintf ( name, "%s/p", varEne[var].c_str());
1027 c = plotHisto(cname, clabel, histArr, labels, color, name, ymx0, logy, pos,
1028 0.10, 0.05, 2.5, varbin, rebin, approve);
1029 }
1030 return c;
1031 }
1032
1033 TCanvas* plotEnergy(std::string fname, std::string HLT, int var, int ien,
1034 int eta, bool varbin, int rebin, bool approve, bool logy,
1035 int pos, int coloff) {
1036
1037 TFile *file = TFile::Open(fname.c_str());
1038 char name[100];
1039 TObjArray histArr;
1040 std::vector<std::string> labels;
1041 std::vector<int> color;
1042 double ymx0(0);
1043 for (int i=0; i<4; ++i) {
1044 sprintf (name, "h_energy_%d_%d_%d_%d", i, ien, eta, var);
1045 TH1D *histo = (TH1D*) file->FindObjectAny(name);
1046 if (histo) {
1047 histArr.AddLast(histo);
1048 sprintf (name, "p=%s, #eta=%s %s", varPs[ien].c_str(), varEta[eta].c_str(), namefull[i+3].c_str());
1049 labels.push_back(name);
1050 color.push_back(colors[coloff+i]);
1051 int ibin = histo->GetMaximumBin();
1052 if (histo->GetBinContent(ibin) > ymx0) ymx0 = histo->GetBinContent(ibin);
1053 }
1054 }
1055 TCanvas* c(0);
1056 if (histArr.GetEntries()>0) {
1057 char cname[50];
1058 sprintf (cname, "c_%s_%d_%d", varEne1[var].c_str(), ien, eta);
1059 sprintf ( name, "%s/p", varEne[var].c_str());
1060 c = plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos, 0.10, 0.05, 2.5, varbin, rebin, approve);
1061 }
1062 return c;
1063 }
1064
1065 void plotEMeanPVAll(std::string fname, std::string HLT, int var, int eta,
1066 bool approve) {
1067
1068 int varmin(0), varmax(5), etamin(0), etamax(3);
1069 if (var >= 0) varmin = varmax = var;
1070 if (eta >= 0) etamin = etamax = eta;
1071 for (int var=varmin; var<=varmax; ++var) {
1072 for (int eta=etamin; eta<=etamax; ++eta) {
1073 plotEMeanDrawPV(fname, HLT, var, eta, approve);
1074 }
1075 }
1076 }
1077
1078 TCanvas* plotEMeanDrawPV(std::string fname, std::string HLT, int var, int eta,
1079 bool approve) {
1080
1081 bool debug(false);
1082 std::vector<TGraphAsymmErrors*> graphs;
1083 TLegend* legend = new TLegend(0.575, 0.80, 0.975, 0.95);
1084 legend->SetBorderSize(1); legend->SetFillColor(kWhite);
1085 legend->SetMargin(0.4);
1086 TFile *file = TFile::Open(fname.c_str());
1087 const int nPVBin=4;
1088 int pvBins[nPVBin+1] = {1, 2, 3, 5, 100};
1089 for (int k=0; k<nPVBin; ++k) {
1090 char name[100];
1091 double mean[NPT], dmean[NPT];
1092 for (int i=0; i<NPT; ++i) {
1093 sprintf (name, "h_energy_%d_%d_%d_%d", k, i, eta, var);
1094 TH1D *histo = (TH1D*) file->FindObjectAny(name);
1095 if (histo) {
1096 mean[i] = histo->GetMean();
1097 dmean[i]= histo->GetMeanError();
1098 } else {
1099 mean[i] = -100.;
1100 dmean[i]= 0;
1101 }
1102 }
1103 if (debug) {
1104 std::cout << "Get mean for " << NPT << " points" << std::endl;
1105 for (int i=0; i<NPT; ++i)
1106 std::cout << "[" << i << "]" << " Momentum " << mom[i] << " +- "
1107 << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
1108 << std::endl;
1109 }
1110 TGraphAsymmErrors *graph = new TGraphAsymmErrors(NPT, mom, mean, dmom,dmom, dmean,dmean);
1111 graph->SetMarkerStyle(styles[k]);
1112 graph->SetMarkerColor(colors[k]);
1113 graph->SetMarkerSize(1.6);
1114 graph->SetLineColor(colors[k]);
1115 graph->SetLineWidth(2);
1116 graphs.push_back(graph);
1117 sprintf (name, "PV=%d:%d", pvBins[k], pvBins[k+1]-1);
1118 legend->AddEntry(graph, name, "lp");
1119 if (debug) std::cout << "Complete " << name << std::endl;
1120 }
1121 file->Close();
1122
1123 char cname[100], name[200];
1124 sprintf (cname, "c_%s_PV_%d", varEne1[var].c_str(), eta);
1125 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
1126 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
1127 gStyle->SetOptTitle(kFALSE); gStyle->SetPadBorderMode(0);
1128 gStyle->SetCanvasBorderMode(0);
1129 TCanvas *canvas = new TCanvas(cname, cname, 500, 400);
1130 gStyle->SetOptStat(0); gPad->SetTopMargin(0.05);
1131 gPad->SetLeftMargin(0.15); gPad->SetRightMargin(0.025);
1132 gPad->SetBottomMargin(0.20);
1133 TH1F *vFrame = canvas->DrawFrame(0.0, 0.01, 50.0, 0.5);
1134 vFrame->GetYaxis()->SetRangeUser(0.0,1.5);
1135 vFrame->GetXaxis()->SetLabelSize(0.06);
1136 vFrame->GetYaxis()->SetLabelSize(0.05);
1137 vFrame->GetXaxis()->SetTitleSize(0.06);
1138 vFrame->GetYaxis()->SetTitleSize(0.06);
1139 vFrame->GetYaxis()->SetTitleOffset(0.9);
1140 vFrame->GetXaxis()->SetRangeUser(1.0,20.0);
1141 if (approve) {
1142 sprintf (name, "Mean of %s/p_{Track}", varEne[var].c_str());
1143 } else {
1144 sprintf (name, "<%s/p_{Track}>", varEne[var].c_str());
1145 }
1146 vFrame->GetYaxis()->SetTitle(name);
1147 sprintf (name, "p_{Track} (GeV/c)");
1148 vFrame->GetXaxis()->SetTitle(name);
1149 for (unsigned int ii=0; ii<graphs.size(); ++ii) graphs[ii]->Draw("P");
1150 legend->Draw();
1151 TLine *line = new TLine(1.0, 1.0, 20.0, 1.0);
1152 line->SetLineStyle(2); line->SetLineWidth(2); line->SetLineColor(kRed);
1153 line->Draw();
1154 TPaveText* text = new TPaveText(0.575, 0.75, 0.97, 0.79, "brNDC");
1155 sprintf (name, "%s (%s)", HLT.c_str(), nameEtas[eta].c_str());
1156 if (debug) std::cout << "Name " << name << " |" << std::endl;
1157 text->AddText(name);
1158 text->Draw("same");
1159 TPaveText* text2 = new TPaveText(0.575, 0.71, 0.97, 0.75, "brNDC");
1160
1161 sprintf (name, "CMS");
1162 text2->AddText(name);
1163 text2->Draw("same");
1164 return canvas;
1165 }
1166
1167 TCanvas* plotEnergyPV(std::string fname, std::string HLT, int var, int ien,
1168 int eta, bool varbin, int rebin, bool approve, bool logy,
1169 int pos) {
1170
1171 const int nPVBin=4;
1172 int pvBins[nPVBin+1] = {1, 2, 3, 5, 100};
1173 TFile *file = TFile::Open(fname.c_str());
1174 char name[100];
1175 TObjArray histArr;
1176 std::vector<std::string> labels;
1177 std::vector<int> color;
1178 double ymx0(0);
1179 for (int i=4; i<nPVBin+4; ++i) {
1180 sprintf (name, "h_energy_%d_%d_%d_%d", i, ien, eta, var);
1181 TH1D *histo = (TH1D*) file->FindObjectAny(name);
1182 if (histo) {
1183 histArr.AddLast(histo);
1184 sprintf (name, "p=%s, #eta=%s, PV=%d:%d (%s)", varPs[ien].c_str(), varEta[eta].c_str(), pvBins[i-4], pvBins[i-3]-1, namefull[6].c_str());
1185 labels.push_back(name);
1186 color.push_back(colors[i-4]);
1187 int ibin = histo->GetMaximumBin();
1188 if (histo->GetBinContent(ibin) > ymx0) ymx0 = histo->GetBinContent(ibin);
1189 }
1190 }
1191 TCanvas *c(0);
1192 if (histArr.GetEntries()>0) {
1193 char cname[50];
1194 sprintf (cname, "c_%s_%d_%d", varEne1[var].c_str(), ien, eta);
1195 sprintf ( name, "%s/p", varEne[var].c_str());
1196 c = plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos,
1197 0.10, 0.05, 2.5, varbin, rebin, approve);
1198 }
1199 return c;
1200 }
1201
1202 TCanvas* plotTrack(std::string fname, std::string HLT, int var, bool varbin,
1203 int rebin, bool approve, bool logy, int pos) {
1204
1205 TFile *file = TFile::Open(fname.c_str());
1206 char name[100];
1207 TObjArray histArr;
1208 std::vector<std::string> labels;
1209 std::vector<int> color;
1210 double ymx0(0);
1211 for (int i=0; i<7; ++i) {
1212 sprintf (name, "h_%s_%s", varname[var].c_str(), names[i].c_str());
1213 TH1D *histo = (TH1D*) file->FindObjectAny(name);
1214 if (histo) {
1215 histArr.AddLast(histo);
1216 labels.push_back(namefull[i]);
1217 color.push_back(colors[i]);
1218 int ibin = histo->GetMaximumBin();
1219 if (histo->GetBinContent(ibin) > ymx0) ymx0 = histo->GetBinContent(ibin);
1220 }
1221 }
1222 if (histArr.GetEntries()>0) {
1223 char cname[50];
1224 sprintf (cname, "c_%s", varname[var].c_str());
1225 sprintf ( name, "%s", vartitle[var].c_str());
1226 return plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos,
1227 0.10, 0.05, -1, varbin, rebin, approve);
1228 } else {
1229 return 0;
1230 }
1231 }
1232
1233 TCanvas* plotIsolation(std::string fname, std::string HLT, int var, bool varbin,
1234 int rebin, bool approve, bool logy, int pos) {
1235
1236 TFile *file = TFile::Open(fname.c_str());
1237 char name[100];
1238 TObjArray histArr;
1239 std::vector<std::string> labels;
1240 std::vector<int> color;
1241 double ymx0(0);
1242 for (int i=0; i<2; ++i) {
1243 sprintf (name, "h_%s_%s", varnameC[var].c_str(), nameC[i].c_str());
1244 TH1D *histo = (TH1D*) file->FindObjectAny(name);
1245 if (histo) {
1246 histArr.AddLast(histo);
1247 labels.push_back(nameCF[i]);
1248 color.push_back(colors[i]);
1249 int ibin = histo->GetMaximumBin();
1250 if (histo->GetBinContent(ibin) > ymx0) ymx0 = histo->GetBinContent(ibin);
1251 }
1252 }
1253 if (histArr.GetEntries()>0) {
1254 char cname[50];
1255 sprintf (cname, "c_%s", varnameC[var].c_str());
1256 sprintf ( name, "%s (GeV)", vartitlC[var].c_str());
1257 return plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos,
1258 0.10, 0.05, -1, varbin, rebin, approve);
1259 } else {
1260 return 0;
1261 }
1262 }
1263
1264 TCanvas* plotHLT(std::string fname, std::string HLT, int run, bool varbin,
1265 int rebin, bool approve, bool logy, int pos) {
1266
1267 TFile *file = TFile::Open(fname.c_str());
1268 char name[100];
1269 TObjArray histArr;
1270 std::vector<std::string> labels;
1271 std::vector<int> color;
1272 double ymx0(0);
1273 if (run > 0) sprintf (name, "h_HLTAccepts_%d", run);
1274 else sprintf (name, "h_HLTAccept");
1275 TH1D *histo = (TH1D*) file->FindObjectAny(name);
1276 if (histo) {
1277 histArr.AddLast(histo);
1278 labels.push_back(HLT);
1279 color.push_back(colors[3]);
1280 int ibin = histo->GetMaximumBin();
1281 ymx0 = histo->GetBinContent(ibin);
1282 }
1283 if (histArr.GetEntries()>0) {
1284 char cname[50], hname[50];
1285 if (run > 0) {sprintf (cname,"c_HLT_%d",run); sprintf (name,"Run %d",run);
1286 } else {sprintf (cname,"c_HLTs"); sprintf (name, "All runs");}
1287 sprintf (hname, " ");
1288 return plotHisto(cname, "", histArr, labels, color, hname, ymx0, logy, pos,
1289 0.40, 0.01, -1, varbin, rebin, approve);
1290 } else {
1291 return 0;
1292 }
1293 }
1294
1295 TCanvas* plotHisto(char* cname, std::string HLT, TObjArray& histArr,
1296 std::vector<std::string>& labels, std::vector<int>& color,
1297 char* name, double ymx0, bool logy, int pos, double yloff,
1298 double yhoff, double xmax, bool varbin, int rebin0,
1299 bool approve) {
1300
1301 int nentry = histArr.GetEntries();
1302 double ymax = 10.;
1303 for (int i=0; i<10; ++i) {
1304 if (ymx0 < ymax) break;
1305 ymax *= 10.;
1306 }
1307 double ystep = ymax*0.1;
1308 for (int i=0; i<9; ++i) {
1309 if (ymax-ystep < ymx0) break;
1310 ymax -= ystep;
1311 }
1312 double ymin(0);
1313 if (logy) ymin = 1;
1314
1315
1316 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
1317 gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite);
1318 gStyle->SetOptTitle(kFALSE); gStyle->SetPadBorderMode(0);
1319 gStyle->SetCanvasBorderMode(0);
1320 if (approve) gStyle->SetOptStat(0);
1321 else gStyle->SetOptStat(1110);
1322 TCanvas *canvas = new TCanvas(cname, cname, 500, 500);
1323 gPad->SetTopMargin(yhoff);
1324 gPad->SetLeftMargin(0.15); gPad->SetRightMargin(0.025);
1325 gPad->SetBottomMargin(yloff);
1326 if (logy) canvas->SetLogy();
1327 double height = 0.08;
1328 double dx = (nentry > 2) ? 0.50 : 0.30;
1329 double dy = (nentry > 2) ? 0.12 : 0.04;
1330 double dy2 = 0.035;
1331 double xmin1 = (pos > 1) ? 0.375 : 0.75-dx;
1332 double xmin2 = (pos > 1) ? 0.12 : 0.65;
1333 double xmin3 = (pos > 1) ? 0.15 : 0.75;
1334 double ymin1 = (pos%2 == 0) ? (1.0-yhoff-dy) : (yloff+0.02);
1335 double ymin2 = (pos%2 == 0) ? (0.96-yhoff-nentry*height) : (yloff+0.025+nentry*height);
1336 double ymin3 = (pos%2 == 0) ? (ymin2-dy2) : (ymin2+dy2);
1337 double dx2 = (approve) ? dx : 0.32;
1338 double dx3 = (approve) ? dx : 0.22;
1339 if (approve) {
1340 xmin1 = xmin2 = xmin3 = 0.975-dx;
1341 ymin1 = (1.0-yhoff-dy);
1342 ymin2 = ymin1-dy2-0.01;
1343 ymin3 = ymin2-dy2;
1344 }
1345
1346 TLegend *legend = new TLegend(xmin1, ymin1, xmin1+dx, ymin1+dy);
1347 TPaveText *text, *text2;
1348 if (varbin || rebin0 == 1) {
1349 text = new TPaveText(xmin2, ymin2, xmin2+dx2, ymin2+dy2, "brNDC");
1350 text2 = new TPaveText(xmin3, ymin3, xmin3+dx3, ymin3+dy2, "brNDC");
1351 } else {
1352 text = new TPaveText(0.10, 0.95, dx2+0.10, dy2+0.95, "brNDC");
1353 text2 = new TPaveText(dx2+0.10, 0.95, dx2+dx3+0.10, dy2+0.95, "brNDC");
1354 }
1355 legend->SetBorderSize(1); legend->SetFillColor(kWhite);
1356 char texts[200];
1357
1358 sprintf (texts, "CMS");
1359 text2->AddText(texts);
1360 THStack *Hs = new THStack("hs2"," ");
1361 for (int i=0; i<nentry; i++) {
1362 TH1D *h = (varbin) ? rebin((TH1D*)histArr[i], i) : (TH1D*)((TH1D*)histArr[i])->Rebin(rebin0);
1363 h->SetLineColor(color[i]);
1364 h->SetLineWidth(2);
1365 h->SetMarkerSize(0.8);
1366 double ymax0 = (varbin) ? ymax : rebin0*ymax;
1367 h->GetYaxis()->SetRangeUser(ymin,ymax0);
1368 if (xmax > 0 && (!varbin)) h->GetXaxis()->SetRangeUser(0,xmax);
1369 Hs->Add(h, "hist sames");
1370 legend->AddEntry(h,labels[i].c_str(),"l");
1371 }
1372 Hs->Draw("nostack");
1373 canvas->Update();
1374 Hs->GetHistogram()->GetXaxis()->SetTitle(name);
1375 Hs->GetHistogram()->GetXaxis()->SetLabelSize(0.035);
1376 Hs->GetHistogram()->GetYaxis()->SetTitleOffset(1.6);
1377 if (varbin) {
1378 Hs->GetHistogram()->GetYaxis()->SetTitle("Tracks/0.01");
1379 } else {
1380 Hs->GetHistogram()->GetYaxis()->SetTitle("Tracks");
1381 if (xmax > 0) Hs->GetHistogram()->GetXaxis()->SetRangeUser(0,xmax);
1382 }
1383 canvas->Modified();
1384
1385 canvas->Update();
1386 if (!approve) {
1387 for (int i=0; i<nentry; i++) {
1388 TH1D *h = (TH1D*)histArr[i];
1389 if (h != NULL) {
1390 TPaveStats* st1 = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
1391 if (st1 != NULL) {
1392 if (pos%2 == 0) {
1393 st1->SetY1NDC(1.0-yhoff-(i+1)*height); st1->SetY2NDC(1.0-yhoff-i*height);
1394 } else {
1395 st1->SetY1NDC(yloff+0.02+i*height); st1->SetY2NDC(yloff+0.02+(i+1)*height);
1396 }
1397 if (pos > 1) {
1398 st1->SetX1NDC(0.15); st1->SetX2NDC(.375);
1399 } else {
1400 st1->SetX1NDC(0.75); st1->SetX2NDC(.975);
1401 }
1402 st1->SetTextColor(colors[i]);
1403 }
1404 }
1405 }
1406 }
1407 legend->Draw("");
1408 if (HLT != "") {
1409 text->AddText(HLT.c_str());
1410 text->Draw("same");
1411 }
1412 text2->Draw("same");
1413
1414 return canvas;
1415 }
1416
1417 void getHistStats(TH1D *h, int& entries, int& integral, double& mean, double& meanE, double& rms, double& rmsE, int& uflow, int& oflow) {
1418 entries = h->GetEntries();
1419 integral = h->Integral();
1420 mean = h->GetMean();
1421 meanE = h->GetMeanError();
1422 rms = h->GetRMS();
1423 rmsE = h->GetRMSError();
1424 uflow = h->GetBinContent(0);
1425 oflow = h->GetBinContent( h->GetNbinsX()+1 );
1426 }
1427
1428 TFitResultPtr getHistFitStats(TH1F *h, const char* formula, double xlow,
1429 double xup, unsigned int& nPar, double* par,
1430 double* epar) {
1431
1432 TFitResultPtr fit = h->Fit(formula, "+qRB0", "", xlow, xup);
1433 nPar = fit->NPar();
1434 const std::vector<double> errors = fit->Errors();
1435 for (unsigned int i=0; i<nPar; i++) {
1436 par[i] = fit->Value(i);
1437 epar[i] = errors[i];
1438 }
1439 return fit;
1440 }
1441
1442 void setHistAttr(TH1F *h, int icol, int lwid, int ltype) {
1443 h->SetLineColor(icol);
1444 h->SetLineStyle(ltype);
1445 h->SetLineWidth(lwid);
1446 TF1 *f = h->GetFunction("gaus");
1447 if (!f->IsZombie()) {
1448 f->SetLineColor(icol);
1449 f->SetLineStyle(2);
1450 }
1451 }
1452
1453 double getWeightedMean (int npt, int Start, std::vector<double>& mean, std::vector<double>& emean) {
1454 double sumDen=0, sumNum=0;
1455 for (int i=Start; i<npt; i++){
1456 if (mean[i]==0.0 || emean[i]==0.0) {
1457 sumNum += 0;
1458 sumDen += 0;
1459 } else {
1460 sumNum += mean[i]/(emean[i]*emean[i]);
1461 sumDen += 1.0/(emean[i]*emean[i]);
1462 }
1463 }
1464 double WeightedMean = sumNum/sumDen;
1465 return WeightedMean;
1466 }
1467
1468 TH1D* rebin(TH1D* histin, int indx) {
1469
1470 std::string nameIn(histin->GetName());
1471 char name[200];
1472 sprintf (name, "%sRebin%d", nameIn.c_str(), indx);
1473 TH1D* hist = new TH1D(name,histin->GetXaxis()->GetTitle(),nbins,xbins);
1474 std::vector<double> cont;
1475 for (int i=1; i<=histin->GetNbinsX(); ++i) {
1476 double value = histin->GetBinContent(i);
1477 cont.push_back(value);
1478
1479 }
1480 for (int i=0; i<nbins; ++i) {
1481 double totl = 0;
1482 int kount= 0;
1483 int klow = ibins[i];
1484 int khigh= ibins[i+1];
1485
1486 for (int k=klow; k<khigh; ++k) {
1487 totl += cont[k-1];
1488 kount++;
1489
1490 }
1491 if (kount>0) totl /= kount;
1492
1493 hist->SetBinContent(i+1,totl);
1494 }
1495 return hist;
1496 }