File indexing completed on 2024-04-06 11:59:13
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
0169
0170
0171
0172
0173
0174
0175
0176 #include "TCanvas.h"
0177 #include "TDirectory.h"
0178 #include "TF1.h"
0179 #include "TFile.h"
0180 #include "TFitResult.h"
0181 #include "TGraph.h"
0182 #include "TGraphErrors.h"
0183 #include "TGraphAsymmErrors.h"
0184 #include "TH1D.h"
0185 #include "TH2D.h"
0186 #include "THStack.h"
0187 #include "TLegend.h"
0188 #include "TMath.h"
0189 #include "TPolyLine.h"
0190 #include "TProfile.h"
0191 #include "TPaveStats.h"
0192 #include "TPaveText.h"
0193 #include "TROOT.h"
0194 #include "TString.h"
0195 #include "TStyle.h"
0196
0197 #include <iostream>
0198 #include <iomanip>
0199 #include <vector>
0200 #include <string>
0201
0202
0203
0204
0205
0206
0207
0208 const int nmodelm = 5, nmodelx = 6, nmodels = 3;
0209 const int etaMax = 3;
0210
0211
0212 int styles[7] = {20, 23, 21, 22, 24, 25, 33};
0213 int colors[7] = {1, 2, 6, 4, 3, 7, 38};
0214 int lstyle[7] = {1, 2, 3, 4, 5, 6, 7};
0215 std::string names[7] = {"All", "Quality", "okEcal", "EcalCharIso", "HcalCharIso", "EcalNeutIso", "HcalNeutIso"};
0216 std::string namefull[7] = {"All tracks",
0217 "Good quality tracks",
0218 "Tracks reaching ECAL",
0219 "Charge isolation in ECAL",
0220 "Charge isolation in HCAL",
0221 "Isolated in ECAL",
0222 "Isolated in HCAL"};
0223 std::string nameEta[4] = {"i#eta 1:6", "i#eta 7:12", "i#eta 13:16", "i#eta 17:22"};
0224 std::string nameEtas[4] = {"|#eta| < 0.52", "0.52 < |#eta| < 1.04", "1.04 < |#eta| < 1.39", "1.39 < |#eta| < 2.01"};
0225 std::string namePV[5] = {"all PV", "PV 1:1", "PV 2:2", "PV 3:5", "PV > 5"};
0226 std::string varname[4] = {"p", "pt", "eta", "phi"};
0227 std::string vartitle[4] = {"p (GeV/c)", "p_{T} (GeV/c)", "#eta", "#phi"};
0228 std::string nameC[2] = {"Ecal", "Hcal"};
0229 std::string nameCF[2] = {"ECAL", "HCAL"};
0230 std::string varnameC[4] = {"maxNearP", "ediff", "ene1", "ene2"};
0231 std::string vartitlC[4] = {
0232 "Charge isolation energy", "Neutral isolation energy", "Energy in smaller cone", "Energy in larger cone"};
0233 std::string cmsP = "CMS Preliminary";
0234
0235 std::string fileData = "AllDataStudyHLT.root";
0236 const int NPT = 10;
0237 double mom[NPT] = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 8.0, 10.0, 13.0, 17.5};
0238 double dmom[NPT] = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0, 1.0, 2.0, 2.5};
0239 std::string varPs[NPT] = {"1:2", "2:3", "3:4", "4:5", "5:6", "6:7", "7:9", "9:11", "11:15", "15:20"};
0240 std::string varPs1[NPT] = {"1", "2", "3", "4", "5", "6", "7", "9", "11", "15"};
0241 std::string varPPs[NPT] = {
0242 "1-2 GeV", "2-3 GeV", "3-4 GeV", "4-5 GeV", "5-6 GeV", "6-7 GeV", "7-9 GeV", "9-11 GeV", "11-15 GeV", "15-20 GeV"};
0243 std::string varEta[4] = {"1:6", "7:12", "13:16", "17:23"};
0244 std::string varEta1[4] = {"1", "2", "3", "4"};
0245 std::string varEne[6] = {"E_{7x7}", "H_{3x3}", "(E_{7x7}+H_{3x3})", "E_{11x11}", "H_{5x5}", "(E_{11x11}+H_{5x5})"};
0246 std::string varEne1[6] = {"E7x7", "H3x3", "E7x7H3x3", "E11x11", "H5x5", "E11x11H5x5"};
0247 const int nbins = 100;
0248 double xbins[nbins + 1] = {0.00, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, 0.13, 0.14,
0249 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29,
0250 0.30, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.40, 0.41, 0.42, 0.43, 0.44,
0251 0.45, 0.46, 0.47, 0.48, 0.49, 0.50, 0.52, 0.54, 0.56, 0.58, 0.60, 0.62, 0.64, 0.66, 0.68,
0252 0.70, 0.72, 0.74, 0.76, 0.78, 0.80, 0.82, 0.84, 0.86, 0.88, 0.90, 0.92, 0.94, 0.96, 0.98,
0253 1.00, 1.05, 1.10, 1.15, 1.20, 1.25, 1.30, 1.35, 1.40, 1.45, 1.50, 1.55, 1.60, 1.65, 1.70,
0254 1.75, 1.80, 1.85, 1.90, 1.95, 2.00, 2.10, 2.20, 2.30, 2.40, 2.50};
0255 int ibins[nbins + 1] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
0256 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
0257 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0258 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95,
0259 97, 99, 101, 103, 105, 107, 109, 111, 116, 121, 126, 131, 136, 141, 146, 151, 156,
0260 161, 166, 171, 176, 181, 186, 191, 196, 201, 206, 211, 221, 231, 241, 251, 261};
0261
0262
0263
0264
0265 std::string files[nmodels] = {"2017C_ZB.root", "2017G_ZB.root", "2017H_ZB.root"};
0266 std::string types[nmodels] = {"Zero Bias (2017C)", "Zero Bias (2017G)", "Zero Bias (2017H)"};
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
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
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 std::string filem[nmodelm] = {"pikp/FBE4p3vMixStudyHLT.root",
0455 "pikp/FBE7p02vMixStudyHLT.root",
0456 "pikp/FBE110p01vMixStudyHLT.root",
0457 "pikp/FBE110r05MixStudyHLT.root",
0458 "pikp/FBE110r06vMixStudyHLT.root"};
0459 std::string typem[nmodelm] = {"10.4.p03 FTFP_BERT_EMM",
0460 "10.7.p02 FTFP_BERT_EMM + Birk C1 + #pi",
0461 "11.0.p01 FTFP_BERT_EMM + Birk C1 + #pi",
0462 "11.0.ref05 FTFP_BERT_EMM + Birk C1 + #pi",
0463 "11.0.ref06 FTFP_BERT_EMM + Birk C1 + #pi"};
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
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744 std::string filex[nmodelx] = {"AllDataStudyHLT.root",
0745 "pikp/QFB4p3vMixStudyHLT.root",
0746 "pikp/QFB7p02vMixStudyHLT.root",
0747 "pikp/QFB110p01vMixStudyHLT.root",
0748 "pikp/QFB110r05MixStudyHLT.root",
0749 "pikp/QFB110r06vMixStudyHLT.root"};
0750 std::string typex[nmodelx] = {"Data (2016B)",
0751 "10.4.p03 QGSP_FTFP_BERT_EML",
0752 "10.7.p02 QGSP_FTFP_BERT_EML",
0753 "11.0.p01 QGSP_FTFP_BERT_EML",
0754 "11.0.ref05 QGSP_FTFP_BERT_EML",
0755 "11.0.ref06 QGSP_FTFP_BERT_EML"};
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829 void plotAll(std::string fname = "",
0830 std::string HLT = "",
0831 int var = -1,
0832 int ien = -1,
0833 int eta = -1,
0834 bool varbin = false,
0835 int rebin = 1,
0836 bool approve = true,
0837 bool logy = true,
0838 int pos = 0,
0839 bool pv = false,
0840 int savePlot = -1);
0841 void plotEnergyAll(std::string fname = "",
0842 std::string hlt = "All HLTs",
0843 int models = 15,
0844 int pv = 0,
0845 int data = 4,
0846 bool varbin = false,
0847 int rebin = 5,
0848 bool approve = true,
0849 bool logy = true,
0850 int pos = 0,
0851 int var = -1,
0852 int ene = -1,
0853 int eta = -1,
0854 int savePlot = -1);
0855 void plotEMeanAll(
0856 int data = 4, int models = 63, bool ratio = true, bool approve = true, std::string postfix = "F", int savePlot = 2);
0857 void plotEMean(std::string fname = "",
0858 std::string hlt = "All HLTs",
0859 int models = 15,
0860 int var = 0,
0861 int eta = 0,
0862 int pv = 0,
0863 int dataMC = 1,
0864 bool raio = false,
0865 bool approve = true,
0866 std::string postfix = "",
0867 int savePlot = -1);
0868 TCanvas* plotEMeanDraw(std::vector<std::string> fnames,
0869 std::vector<std::string> hlts,
0870 int var,
0871 int eta,
0872 int pv = 0,
0873 bool approve = false,
0874 std::string dtype = "Data",
0875 int coloff = 0);
0876 TCanvas* plotEMeanRatioDraw(std::vector<std::string> fnames,
0877 std::vector<std::string> hlts,
0878 int var,
0879 int eta,
0880 int pv = 0,
0881 bool approve = false,
0882 std::string dtype = "Data",
0883 int coloff = 0);
0884 void plotEMeanRatioXAll(std::string fname = "pikp/FBE4p3vMixStudyHLT.root",
0885 std::string hlt = "10.4p03 FTFP_BERT_EMM",
0886 std::string postfix = "F",
0887 int savePlot = 2);
0888 TCanvas* plotEMeanRatioDrawX(std::string fname = "pikp/FBE4p3vMixStudyHLT.root",
0889 std::string hlt = "10.4p03 FTFP_BERT_EMM",
0890 int var = 0,
0891 int pv = 0);
0892 TCanvas* plotEnergies(std::vector<std::string> fnames,
0893 std::vector<std::string> hlts,
0894 int var = 0,
0895 int ien = 0,
0896 int eta = 0,
0897 int pv = 0,
0898 bool varbin = false,
0899 int rebin = 1,
0900 bool approve = false,
0901 std::string dtype = "Data",
0902 bool logy = true,
0903 int pos = 0,
0904 int coloff = 0);
0905 TCanvas* plotEnergy(std::string fname = "hlt.root",
0906 std::string HLT = "All HLTs",
0907 int var = 0,
0908 int ien = 0,
0909 int eta = 0,
0910 bool varbin = false,
0911 int rebin = 1,
0912 bool approve = false,
0913 bool logy = true,
0914 int pos = 0,
0915 int coloff = 0);
0916 void plotEMeanPVAll(std::string fname = "StudyHLT_ZeroBias_1PV.root",
0917 std::string HLT = "Zero Bias",
0918 int var = -1,
0919 int eta = -1,
0920 bool approve = true);
0921 TCanvas* plotEMeanDrawPV(std::string fname = "StudyHLT_ZeroBias_1PV.root",
0922 std::string HLT = "Zero Bias",
0923 int var = 0,
0924 int eta = 0,
0925 bool approve = true);
0926 TCanvas* plotEnergyPV(std::string fnamee = "StudyHLT_HLTZeroBias.root",
0927 std::string HLT = "Zero Bias",
0928 int var = 0,
0929 int ien = 0,
0930 int eta = 0,
0931 bool varbin = false,
0932 int rebin = 1,
0933 bool approve = false,
0934 bool logy = true,
0935 int pos = 0);
0936 TCanvas* plotTrack(std::string fname = "hlt.root",
0937 std::string HLT = "All HLTs",
0938 int var = 0,
0939 bool varbin = false,
0940 int rebin = 1,
0941 bool approve = false,
0942 bool logy = true,
0943 int pos = 0);
0944 TCanvas* plotIsolation(std::string fname = "hlt.root",
0945 std::string HLT = "All HLTs",
0946 int var = 0,
0947 bool varbin = false,
0948 int rebin = 1,
0949 bool approve = false,
0950 bool logy = true,
0951 int pos = 0);
0952 TCanvas* plotHLT(std::string fname = "hlt.root",
0953 std::string HLT = "All HLTs",
0954 int run = -1,
0955 bool varbin = false,
0956 int rebin = 1,
0957 bool approve = false,
0958 bool logy = true,
0959 int pos = 0);
0960 TCanvas* plotHisto(char* cname,
0961 std::string HLT,
0962 TObjArray& histArr,
0963 std::vector<std::string>& labels,
0964 std::vector<int>& color,
0965 char* name,
0966 double ymx0,
0967 bool logy,
0968 int pos,
0969 double yloff,
0970 double yhoff,
0971 double xmax = -1,
0972 bool varbin = false,
0973 int rebin = 1,
0974 bool approve = false);
0975 void getHistStats(TH1D* h,
0976 int& entries,
0977 int& integral,
0978 double& mean,
0979 double& meanE,
0980 double& rms,
0981 double& rmsE,
0982 int& uflow,
0983 int& oflow);
0984 TFitResultPtr getHistFitStats(
0985 TH1F* h, const char* formula, double xlow, double xup, unsigned int& nPar, double* par, double* epar);
0986 void setHistAttr(TH1F* h, int icol, int lwid = 1, int ltype = 1);
0987 double getWeightedMean(int npt, int Start, std::vector<double>& mean, std::vector<double>& emean);
0988 TH1D* rebin(TH1D* histin, int);
0989
0990 void plotAll(std::string fname,
0991 std::string HLT,
0992 int var,
0993 int ien,
0994 int eta,
0995 bool varbin,
0996 int rebin,
0997 bool approve,
0998 bool logy,
0999 int pos,
1000 bool pv,
1001 int savePlot) {
1002 int varmin(0), varmax(5), enemin(0), enemax(9), etamin(0), etamax(etaMax);
1003 if (var >= 0)
1004 varmin = varmax = var;
1005 if (ien >= 0)
1006 enemin = enemax = ien;
1007 if (eta >= 0)
1008 etamin = etamax = eta;
1009 for (int var = varmin; var <= varmax; ++var) {
1010 for (int ene = enemin; ene <= enemax; ++ene) {
1011 for (int eta = etamin; eta <= etamax; ++eta) {
1012 TCanvas* c(0);
1013 if (pv) {
1014 c = plotEnergyPV(fname, HLT, var, ene, eta, varbin, rebin, approve, logy, pos);
1015 } else {
1016 c = plotEnergy(fname, HLT, var, ene, eta, varbin, rebin, approve, logy, pos);
1017 }
1018 if (c != 0 && savePlot >= 0 && savePlot <= 3) {
1019 std::string ext[4] = {"eps", "gif", "pdf", "C"};
1020 char name[200];
1021 sprintf(name, "%s.%s", c->GetName(), ext[savePlot].c_str());
1022 c->Print(name);
1023 }
1024 }
1025 }
1026 }
1027 }
1028
1029 void plotEnergyAll(std::string fname,
1030 std::string hlt,
1031 int models,
1032 int pv,
1033 int data,
1034 bool varbin,
1035 int rebin,
1036 bool approve,
1037 bool logy,
1038 int pos,
1039 int var,
1040 int ene,
1041 int eta,
1042 int savePlot) {
1043 std::vector<std::string> fnames, hlts;
1044 std::string dtype = (data == 1) ? "Data" : "MC";
1045 int modeluse(models);
1046 int coloff = (data == 4) ? 0 : 1;
1047 if (fname == "") {
1048 if (data == 1) {
1049 for (int i = 0; i < nmodels; ++i) {
1050 if (modeluse % 2 == 1) {
1051 fnames.push_back(files[i]);
1052 hlts.push_back(types[i]);
1053 }
1054 modeluse /= 2;
1055 }
1056 } else if (data == 4) {
1057 for (int i = 0; i < nmodelx; ++i) {
1058 if (modeluse % 2 == 1) {
1059 fnames.push_back(filex[i]);
1060 hlts.push_back(typex[i]);
1061 }
1062 modeluse /= 2;
1063 }
1064 } else {
1065 for (int i = 0; i < nmodelm; ++i) {
1066 if (modeluse % 2 == 1) {
1067 fnames.push_back(filem[i]);
1068 hlts.push_back(typem[i]);
1069 }
1070 modeluse /= 2;
1071 }
1072 }
1073 } else {
1074 fnames.push_back(fname);
1075 hlts.push_back(hlt);
1076 }
1077 int varmin(0), varmax(5), enemin(0), enemax(9), etamin(0), etamax(etaMax);
1078 if (var >= varmin && var <= varmax)
1079 varmin = varmax = var;
1080 if (ene >= enemin && ene <= enemax)
1081 enemin = enemax = ene;
1082 if (eta >= etamin && eta <= etamax)
1083 etamin = etamax = eta;
1084 for (int var = varmin; var <= varmax; ++var) {
1085 for (int ene = enemin; ene <= enemax; ++ene) {
1086 for (int eta = etamin; eta <= etamax; ++eta) {
1087 TCanvas* c = plotEnergies(fnames, hlts, var, ene, eta, pv, varbin, rebin, approve, dtype, logy, pos, coloff);
1088 if (c != 0 && savePlot >= 0 && savePlot <= 3) {
1089 std::string ext[4] = {"eps", "gif", "pdf", "C"};
1090 char name[200];
1091 sprintf(name, "%s.%s", c->GetName(), ext[savePlot].c_str());
1092 c->Print(name);
1093 }
1094 }
1095 }
1096 }
1097 }
1098
1099 void plotEMeanAll(int data, int models, bool ratio, bool approve, std::string postfix, int savePlot) {
1100 int varmin(0), varmax(5), pvmin(0), pvmax(0), etamin(0), etamax(etaMax);
1101 for (int var = varmin; var <= varmax; ++var) {
1102 for (int eta = etamin; eta <= etamax; ++eta) {
1103 for (int pv = pvmin; pv <= pvmax; ++pv) {
1104 plotEMean("", "", models, var, eta, pv, data, ratio, approve, postfix, savePlot);
1105 }
1106 }
1107 }
1108 }
1109
1110 void plotEMean(std::string fname,
1111 std::string hlt,
1112 int models,
1113 int var,
1114 int eta,
1115 int pv,
1116 int data,
1117 bool ratio,
1118 bool approve,
1119 std::string postfix,
1120 int savePlot) {
1121 std::vector<std::string> fnames, hlts;
1122 std::string dtype = (data == 1) ? "Data" : "MC";
1123 int modeluse(models);
1124 int coloff = (data == 4 || data == 3) ? 0 : 1;
1125 if (fname == "") {
1126 if (data == 1) {
1127 for (int i = 0; i < nmodels; ++i) {
1128 if (modeluse % 2 == 1) {
1129 fnames.push_back(files[i]);
1130 hlts.push_back(types[i]);
1131 }
1132 modeluse /= 2;
1133 }
1134 } else if (data == 4) {
1135 for (int i = 0; i < nmodelx; ++i) {
1136 if (modeluse % 2 == 1) {
1137 fnames.push_back(filex[i]);
1138 hlts.push_back(typex[i]);
1139 }
1140 modeluse /= 2;
1141 }
1142 } else if (data == 3) {
1143 for (int i = 0; i < nmodelx; ++i) {
1144 if (modeluse % 2 == 1) {
1145 fnames.push_back(filex[i]);
1146 hlts.push_back(typex[i]);
1147 }
1148 modeluse /= 2;
1149 }
1150 } else {
1151 for (int i = 0; i < nmodelm; ++i) {
1152 if (modeluse % 2 == 1) {
1153 fnames.push_back(filem[i]);
1154 hlts.push_back(typem[i]);
1155 }
1156 modeluse /= 2;
1157 }
1158 }
1159 } else {
1160 fnames.push_back(fname);
1161 hlts.push_back(hlt);
1162 }
1163 int varmin(0), varmax(5), etamin(0), etamax(etaMax), pvmin(0), pvmax(4);
1164 if (var >= 0)
1165 varmin = varmax = var;
1166 if (eta >= 0)
1167 etamin = etamax = eta;
1168 if (pv >= 0)
1169 pvmin = pvmax = pv;
1170 for (int var = varmin; var <= varmax; ++var) {
1171 for (int eta = etamin; eta <= etamax; ++eta) {
1172 for (int pv = pvmin; pv <= pvmax; ++pv) {
1173 TCanvas* c = ((ratio) ? plotEMeanRatioDraw(fnames, hlts, var, eta, pv, approve, dtype, coloff)
1174 : plotEMeanDraw(fnames, hlts, var, eta, pv, approve, dtype, coloff));
1175 if (c != 0 && savePlot >= 0 && savePlot <= 3) {
1176 std::string ext[4] = {"eps", "gif", "pdf", "C"};
1177 char name[200];
1178 sprintf(name, "%s%s.%s", c->GetName(), postfix.c_str(), ext[savePlot].c_str());
1179 c->Print(name);
1180 }
1181 }
1182 }
1183 }
1184 }
1185
1186 TCanvas* plotEMeanDraw(std::vector<std::string> fnames,
1187 std::vector<std::string> hlts,
1188 int var,
1189 int eta,
1190 int pv,
1191 bool approve,
1192 std::string dtype,
1193 int coloff) {
1194 bool debug(false);
1195 std::vector<TGraphAsymmErrors*> graphs;
1196 double yminx = (fnames.size() < 3) ? 0.85 : 0.75;
1197 TLegend* legend = new TLegend(0.60, yminx, 0.975, 0.95);
1198 legend->SetBorderSize(1);
1199 legend->SetFillColor(kWhite);
1200 legend->SetMargin(0.2);
1201 for (unsigned int k = 0; k < fnames.size(); ++k) {
1202 TFile* file = TFile::Open(fnames[k].c_str());
1203 double mean[NPT], dmean[NPT];
1204 for (int i = 0; i < NPT; ++i) {
1205 char name[100];
1206 sprintf(name, "h_energy_%d_%d_%d_%d", pv + 3, i, eta, var);
1207 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1208 if (histo) {
1209 mean[i] = histo->GetMean();
1210 dmean[i] = histo->GetMeanError();
1211 } else {
1212 mean[i] = -100.;
1213 dmean[i] = 0;
1214 }
1215 }
1216 if (debug) {
1217 std::cout << "Get mean for " << NPT << " points" << std::endl;
1218 for (int i = 0; i < NPT; ++i)
1219 std::cout << "[" << i << "]"
1220 << " Momentum " << mom[i] << " +- " << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
1221 << std::endl;
1222 }
1223 TGraphAsymmErrors* graph = new TGraphAsymmErrors(NPT, mom, mean, dmom, dmom, dmean, dmean);
1224 graph->SetMarkerStyle(styles[coloff + k]);
1225 graph->SetMarkerColor(colors[coloff + k]);
1226 graph->SetMarkerSize(1.2);
1227 graph->SetLineColor(colors[coloff + k]);
1228 graph->SetLineWidth(2);
1229 graphs.push_back(graph);
1230 legend->AddEntry(graph, hlts[k].c_str(), "lp");
1231 if (debug)
1232 std::cout << "Complete " << hlts[k] << std::endl;
1233 file->Close();
1234 }
1235
1236 char cname[100], name[200];
1237 sprintf(cname, "c_%s_%d_%d_%s", varEne1[var].c_str(), eta, pv, dtype.c_str());
1238 gStyle->SetCanvasBorderMode(0);
1239 gStyle->SetCanvasColor(kWhite);
1240 gStyle->SetPadColor(kWhite);
1241 gStyle->SetFillColor(kWhite);
1242 gStyle->SetOptTitle(kFALSE);
1243 gStyle->SetPadBorderMode(0);
1244 gStyle->SetCanvasBorderMode(0);
1245 TCanvas* canvas = new TCanvas(cname, cname, 500, 400);
1246 gStyle->SetOptStat(0);
1247 gPad->SetTopMargin(0.05);
1248 gPad->SetLeftMargin(0.15);
1249 gPad->SetRightMargin(0.025);
1250 gPad->SetBottomMargin(0.20);
1251 TH1F* vFrame = canvas->DrawFrame(0.0, 0.01, 50.0, 0.5);
1252 vFrame->GetYaxis()->SetRangeUser(0.0, 1.6);
1253 vFrame->GetXaxis()->SetLabelSize(0.06);
1254 vFrame->GetYaxis()->SetLabelSize(0.05);
1255 vFrame->GetXaxis()->SetTitleSize(0.06);
1256 vFrame->GetYaxis()->SetTitleSize(0.06);
1257 vFrame->GetYaxis()->SetTitleOffset(0.9);
1258 vFrame->GetXaxis()->SetRangeUser(1.0, 20.0);
1259 if (approve) {
1260 sprintf(name, "Mean of %s/p_{Track}", varEne[var].c_str());
1261 } else {
1262 sprintf(name, "<%s/p_{Track}>", varEne[var].c_str());
1263 }
1264 vFrame->GetYaxis()->SetTitle(name);
1265 sprintf(name, "p_{Track} (GeV/c)");
1266 vFrame->GetXaxis()->SetTitle(name);
1267 for (unsigned int ii = 0; ii < graphs.size(); ++ii)
1268 graphs[ii]->Draw("P");
1269 legend->Draw();
1270 TLine* line = new TLine(1.0, 1.0, 20.0, 1.0);
1271 line->SetLineStyle(2);
1272 line->SetLineWidth(2);
1273 line->SetLineColor(kRed);
1274 line->Draw();
1275 TPaveText* text = new TPaveText(0.25, 0.74, 0.55, 0.79, "brNDC");
1276 if (approve) {
1277 sprintf(name, "(%s)", nameEtas[eta].c_str());
1278 } else {
1279 sprintf(name, "(%s, %s)", nameEta[eta].c_str(), namePV[pv].c_str());
1280 }
1281 if (debug)
1282 std::cout << "Name " << name << " |" << std::endl;
1283 text->AddText(name);
1284 text->Draw("same");
1285 TPaveText* text2 = new TPaveText(0.55, yminx - 0.06, 0.97, yminx - 0.01, "brNDC");
1286 sprintf(name, cmsP.c_str());
1287 text2->AddText(name);
1288 text2->Draw("same");
1289 return canvas;
1290 }
1291
1292 TCanvas* plotEMeanRatioDraw(std::vector<std::string> fnames,
1293 std::vector<std::string> hlts,
1294 int var,
1295 int eta,
1296 int pv,
1297 bool approve,
1298 std::string dtype,
1299 int coloff) {
1300 bool debug(false);
1301 std::vector<TGraphAsymmErrors*> graphs;
1302 double yminx = (fnames.size() < 3) ? 0.88 : 0.80;
1303 TLegend* legend = new TLegend(0.60, yminx, 0.975, 0.95);
1304 legend->SetBorderSize(1);
1305 legend->SetFillColor(kWhite);
1306 legend->SetMargin(0.2);
1307 const int NPT2 = 2 * NPT + 2;
1308 double mean0[NPT], dmean0[NPT], ones[NPT];
1309 double pmom1[NPT2 + 1], dmean1[NPT2 + 1];
1310 for (unsigned int k = 0; k < fnames.size(); ++k) {
1311 TFile* file = TFile::Open(fnames[k].c_str());
1312 double mean[NPT], dmean[NPT];
1313 for (int i = 0; i < NPT; ++i) {
1314 char name[100];
1315 sprintf(name, "h_energy_%d_%d_%d_%d", pv + 3, i, eta, var);
1316 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1317 if (histo) {
1318 mean[i] = histo->GetMean();
1319 dmean[i] = histo->GetMeanError();
1320 } else {
1321 mean[i] = -100.;
1322 dmean[i] = 0;
1323 }
1324 }
1325 if (debug) {
1326 std::cout << "Get mean for " << NPT << " points" << std::endl;
1327 for (int i = 0; i < NPT; ++i)
1328 std::cout << "[" << i << "]"
1329 << " Momentum " << mom[i] << " +- " << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
1330 << std::endl;
1331 }
1332 if (k == 0) {
1333 for (int i = 0; i < NPT; ++i) {
1334 ones[i] = 1.0;
1335 mean0[i] = mean[i];
1336 dmean0[i] = dmean[i];
1337 pmom1[i] = mom[i] - dmom[i];
1338 pmom1[NPT2 - i - 1] = pmom1[i];
1339 dmean1[i] = (mean[i] > 0) ? dmean[i] / mean[i] : 0.0;
1340 dmean1[NPT2 - i - 1] = -dmean1[i];
1341 }
1342 pmom1[NPT + 1] = pmom1[NPT] = mom[NPT - 1] + dmom[NPT - 1];
1343 dmean1[NPT] = dmean1[NPT - 1];
1344 dmean1[NPT + 1] = -dmean1[NPT];
1345 pmom1[NPT2] = pmom1[0];
1346 dmean1[NPT2] = dmean1[0];
1347 if (debug)
1348 for (int k = 0; k < NPT2 + 1; ++k)
1349 std::cout << "[" << k << "] " << pmom1[k] << " " << dmean1[k] << "\n";
1350 } else {
1351 double sumNum(0), sumDen(0), sumNum1(0), sumDen1(0);
1352 for (int i = 0; i < NPT; ++i) {
1353 if (dmean[i] > 0 && dmean0[i] > 0) {
1354 double er1 = dmean[i] / mean[i];
1355 double er2 = dmean0[i] / mean0[i];
1356 mean[i] = mean[i] / mean0[i];
1357 dmean[i] = mean[i] * sqrt(er1 * er1 + er2 * er2);
1358 double temp1 = (mean[i] > 1.0) ? 1.0 / mean[i] : mean[i];
1359 double temp2 = (mean[i] > 1.0) ? dmean[i] / (mean[i] * mean[i]) : dmean[i];
1360 if (i > 0) {
1361 sumNum += (fabs(1 - temp1) / (temp2 * temp2));
1362 sumDen += (1.0 / (temp2 * temp2));
1363 }
1364 sumNum1 += (fabs(1 - temp1) / (temp2 * temp2));
1365 sumDen1 += (1.0 / (temp2 * temp2));
1366 } else {
1367 mean[i] = -100.;
1368 dmean[i] = 0;
1369 }
1370 }
1371 sumNum = (sumDen > 0) ? (sumNum / sumDen) : 0;
1372 sumDen = (sumDen > 0) ? 1.0 / sqrt(sumDen) : 0;
1373 sumNum1 = (sumDen1 > 0) ? (sumNum1 / sumDen1) : 0;
1374 sumDen1 = (sumDen1 > 0) ? 1.0 / sqrt(sumDen1) : 0;
1375 std::cout << "Get Ratio of mean for " << NPT << " points: Mean " << sumNum << " +- " << sumDen << " (" << sumNum1
1376 << " +- " << sumDen1 << ") Input: " << fnames[k] << " var|eta|pv " << var << ":" << eta << ":" << pv
1377 << std::endl;
1378 if (debug) {
1379 std::cout << "Get Ratio of mean for " << NPT << " points: Mean " << sumNum << " +- " << sumDen << std::endl;
1380 for (int i = 0; i < NPT; ++i)
1381 std::cout << "[" << i << "]"
1382 << " Momentum " << mom[i] << " +- " << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
1383 << std::endl;
1384 }
1385 TGraphAsymmErrors* graph = new TGraphAsymmErrors(NPT, mom, mean, dmom, dmom, dmean, dmean);
1386 graph->SetMarkerStyle(styles[coloff + k]);
1387 graph->SetMarkerColor(colors[coloff + k]);
1388 graph->SetMarkerSize(1.2);
1389 graph->SetLineColor(colors[coloff + k]);
1390 graph->SetLineWidth(2);
1391 graphs.push_back(graph);
1392 char text[100];
1393 if (approve) {
1394 sprintf(text, "%s", hlts[k].c_str());
1395 } else {
1396 sprintf(text, "%5.3f #pm %5.3f %s", sumNum, sumDen, hlts[k].c_str());
1397 }
1398 legend->AddEntry(graph, text, "lp");
1399 if (debug)
1400 std::cout << "Complete " << hlts[k] << std::endl;
1401 }
1402 file->Close();
1403 }
1404 TGraphErrors* graph = new TGraphErrors(NPT, mom, ones, dmean1);
1405 graph->SetFillColor(4);
1406 graph->SetFillStyle(3005);
1407 TPolyLine* pline = new TPolyLine(NPT2 + 1, pmom1, dmean1);
1408 pline->SetFillColor(5);
1409 pline->SetLineColor(6);
1410 pline->SetLineWidth(2);
1411
1412 char cname[100], name[200];
1413 sprintf(cname, "cR_%s_%d_%d_%s", varEne1[var].c_str(), eta, pv, dtype.c_str());
1414 gStyle->SetCanvasBorderMode(0);
1415 gStyle->SetCanvasColor(kWhite);
1416 gStyle->SetPadColor(kWhite);
1417 gStyle->SetFillColor(kWhite);
1418 gStyle->SetOptTitle(kFALSE);
1419 gStyle->SetPadBorderMode(0);
1420 gStyle->SetCanvasBorderMode(0);
1421 TCanvas* canvas = new TCanvas(cname, cname, 500, 400);
1422 gStyle->SetOptStat(0);
1423 gPad->SetTopMargin(0.05);
1424 gPad->SetLeftMargin(0.15);
1425 gPad->SetRightMargin(0.025);
1426 gPad->SetBottomMargin(0.20);
1427 TH1F* vFrame = canvas->DrawFrame(0.0, 0.01, 50.0, 0.5);
1428 vFrame->GetYaxis()->SetRangeUser(0.4, 1.5);
1429 vFrame->GetXaxis()->SetLabelSize(0.06);
1430 vFrame->GetYaxis()->SetLabelSize(0.05);
1431 vFrame->GetXaxis()->SetTitleSize(0.06);
1432 vFrame->GetYaxis()->SetTitleSize(0.045);
1433 vFrame->GetYaxis()->SetTitleOffset(1.2);
1434 vFrame->GetXaxis()->SetRangeUser(1.0, 20.0);
1435 if (approve) {
1436 sprintf(name, "%s/Data for mean of %s/p_{Track}", dtype.c_str(), varEne[var].c_str());
1437 } else {
1438 sprintf(name, "#frac{%s}{%s} for #frac{%s}{p_{Track}}", dtype.c_str(), hlts[0].c_str(), varEne[var].c_str());
1439 }
1440 vFrame->GetYaxis()->SetTitle(name);
1441 sprintf(name, "p_{Track} (GeV/c)");
1442 vFrame->GetXaxis()->SetTitle(name);
1443 for (unsigned int ii = 0; ii < graphs.size(); ++ii)
1444 graphs[ii]->Draw("P");
1445 graph->Draw("3");
1446 legend->Draw();
1447 TLine* line = new TLine(1.0, 1.0, 20.0, 1.0);
1448 line->SetLineStyle(2);
1449 line->SetLineWidth(2);
1450 line->SetLineColor(kRed);
1451 line->Draw();
1452 pline->Draw("f L SAME");
1453 TPaveText* text = new TPaveText(0.55, 0.40, 0.95, 0.45, "brNDC");
1454 if (approve) {
1455 sprintf(name, "(%s)", nameEtas[eta].c_str());
1456 } else {
1457 sprintf(name, "(%s, %s)", nameEta[eta].c_str(), namePV[pv].c_str());
1458 }
1459 if (debug)
1460 std::cout << "Name " << name << " |" << std::endl;
1461 text->AddText(name);
1462 text->Draw("same");
1463 TPaveText* text2 = new TPaveText(0.55, 0.45, 0.95, 0.50, "brNDC");
1464 sprintf(name, cmsP.c_str());
1465 text2->AddText(name);
1466 text2->Draw("same");
1467 return canvas;
1468 }
1469
1470 void plotEMeanRatioXAll(std::string fname, std::string hlt, std::string postfix, int savePlot) {
1471 int varmin(0), varmax(5), pvmin(0), pvmax(0);
1472 for (int var = varmin; var <= varmax; ++var) {
1473 for (int pv = pvmin; pv <= pvmax; ++pv) {
1474 TCanvas* c = plotEMeanRatioDrawX(fname, hlt, var, pv);
1475 if (savePlot >= 0 && savePlot <= 3) {
1476 std::string ext[4] = {"eps", "gif", "pdf", "C"};
1477 char name[200];
1478 sprintf(name, "%s%s.%s", c->GetName(), postfix.c_str(), ext[savePlot].c_str());
1479 c->Print(name);
1480 }
1481 }
1482 }
1483 }
1484
1485 TCanvas* plotEMeanRatioDrawX(std::string fname, std::string hlt, int var, int pv) {
1486 bool debug(false);
1487 std::vector<TGraphAsymmErrors*> graphs;
1488 double yminx = 0.80;
1489 TLegend* legend = new TLegend(0.60, yminx, 0.975, 0.95);
1490 legend->SetBorderSize(1);
1491 legend->SetFillColor(kWhite);
1492 legend->SetMargin(0.2);
1493 double mean0[NPT], dmean0[NPT], mean[NPT], dmean[NPT];
1494 char name[200], cname[100];
1495 for (int eta = 0; eta <= etaMax; ++eta) {
1496
1497 TFile* file = TFile::Open(fileData.c_str());
1498 for (int i = 0; i < NPT; ++i) {
1499 sprintf(name, "h_energy_%d_%d_%d_%d", pv + 3, i, eta, var);
1500 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1501 if (histo) {
1502 mean0[i] = histo->GetMean();
1503 dmean0[i] = histo->GetMeanError();
1504 } else {
1505 mean0[i] = -100.;
1506 dmean0[i] = 0;
1507 }
1508 }
1509 file->Close();
1510
1511 file = TFile::Open(fname.c_str());
1512 for (int i = 0; i < NPT; ++i) {
1513 sprintf(name, "h_energy_%d_%d_%d_%d", pv + 3, i, eta, var);
1514 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1515 if (histo) {
1516 mean[i] = histo->GetMean();
1517 dmean[i] = histo->GetMeanError();
1518 } else {
1519 mean[i] = -100.;
1520 dmean[i] = 0;
1521 }
1522 }
1523 file->Close();
1524 if (debug) {
1525 std::cout << "Get mean for " << NPT << " points" << std::endl;
1526 for (int i = 0; i < NPT; ++i)
1527 std::cout << "[" << i << "]"
1528 << " Momentum " << mom[i] << " +- " << dmom[i] << " Data:Mean " << mean0[i] << " +- " << dmean0[i]
1529 << " MC:Mean " << mean[i] << " +- " << dmean[i] << std::endl;
1530 }
1531 double sumNum(0), sumDen(0), sumNum1(0), sumDen1(0);
1532 for (int i = 0; i < NPT; ++i) {
1533 if (dmean[i] > 0 && dmean0[i] > 0) {
1534 double er1 = dmean[i] / mean[i];
1535 double er2 = dmean0[i] / mean0[i];
1536 mean[i] = mean[i] / mean0[i];
1537 dmean[i] = mean[i] * sqrt(er1 * er1 + er2 * er2);
1538 double temp1 = (mean[i] > 1.0) ? 1.0 / mean[i] : mean[i];
1539 double temp2 = (mean[i] > 1.0) ? dmean[i] / (mean[i] * mean[i]) : dmean[i];
1540 if (i > 0) {
1541 sumNum += (fabs(1 - temp1) / (temp2 * temp2));
1542 sumDen += (1.0 / (temp2 * temp2));
1543 }
1544 sumNum1 += (fabs(1 - temp1) / (temp2 * temp2));
1545 sumDen1 += (1.0 / (temp2 * temp2));
1546 } else {
1547 mean[i] = -100.;
1548 dmean[i] = 0;
1549 }
1550 }
1551 sumNum = (sumDen > 0) ? (sumNum / sumDen) : 0;
1552 sumDen = (sumDen > 0) ? 1.0 / sqrt(sumDen) : 0;
1553 sumNum1 = (sumDen1 > 0) ? (sumNum1 / sumDen1) : 0;
1554 sumDen1 = (sumDen1 > 0) ? 1.0 / sqrt(sumDen1) : 0;
1555 std::cout << "Get Ratio of mean for " << NPT << " points: Mean " << sumNum << " +- " << sumDen << " (" << sumNum1
1556 << " +- " << sumDen1 << ") Input: " << fname << " var|eta|pv " << var << ":" << eta << ":" << pv
1557 << std::endl;
1558 if (debug) {
1559 std::cout << "Get Ratio of mean for " << NPT << " points: Mean " << sumNum << " +- " << sumDen << std::endl;
1560 for (int i = 0; i < NPT; ++i)
1561 std::cout << "[" << i << "]"
1562 << " Momentum " << mom[i] << " +- " << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
1563 << std::endl;
1564 }
1565 TGraphAsymmErrors* graph = new TGraphAsymmErrors(NPT, mom, mean, dmom, dmom, dmean, dmean);
1566 graph->SetMarkerStyle(styles[eta]);
1567 graph->SetMarkerColor(colors[eta]);
1568 graph->SetMarkerSize(1.2);
1569 graph->SetLineColor(colors[eta]);
1570 graph->SetLineWidth(2);
1571 graphs.push_back(graph);
1572 sprintf(cname, "%s", nameEtas[eta].c_str());
1573 legend->AddEntry(graph, cname, "lp");
1574 }
1575
1576 sprintf(cname, "cR_%s_%d", varEne1[var].c_str(), pv);
1577 gStyle->SetCanvasBorderMode(0);
1578 gStyle->SetCanvasColor(kWhite);
1579 gStyle->SetPadColor(kWhite);
1580 gStyle->SetFillColor(kWhite);
1581 gStyle->SetOptTitle(kFALSE);
1582 gStyle->SetPadBorderMode(0);
1583 gStyle->SetCanvasBorderMode(0);
1584 TCanvas* canvas = new TCanvas(cname, cname, 750, 600);
1585 gStyle->SetOptStat(0);
1586 gPad->SetTopMargin(0.05);
1587 gPad->SetLeftMargin(0.15);
1588 gPad->SetRightMargin(0.025);
1589 gPad->SetBottomMargin(0.20);
1590 TH1F* vFrame = canvas->DrawFrame(0.0, 0.01, 50.0, 0.5);
1591 vFrame->GetYaxis()->SetRangeUser(0.4, 1.5);
1592 vFrame->GetXaxis()->SetLabelSize(0.06);
1593 vFrame->GetYaxis()->SetLabelSize(0.05);
1594 vFrame->GetXaxis()->SetTitleSize(0.06);
1595 vFrame->GetYaxis()->SetTitleSize(0.045);
1596 vFrame->GetYaxis()->SetTitleOffset(1.2);
1597 vFrame->GetXaxis()->SetRangeUser(1.0, 20.0);
1598 sprintf(name, "MC/Data for mean of %s/p_{Track}", varEne[var].c_str());
1599 vFrame->GetYaxis()->SetTitle(name);
1600 sprintf(name, "p_{Track} (GeV/c)");
1601 vFrame->GetXaxis()->SetTitle(name);
1602 for (unsigned int ii = 0; ii < graphs.size(); ++ii)
1603 graphs[ii]->Draw("P");
1604 legend->Draw();
1605 TLine* line = new TLine(1.0, 1.0, 20.0, 1.0);
1606 line->SetLineStyle(2);
1607 line->SetLineWidth(2);
1608 line->SetLineColor(kRed);
1609 line->Draw();
1610 TPaveText* text = new TPaveText(0.60, 0.40, 0.92, 0.45, "brNDC");
1611 sprintf(name, "%s", hlt.c_str());
1612 text->AddText(name);
1613 text->Draw("same");
1614 TPaveText* text2 = new TPaveText(0.55, 0.45, 0.95, 0.50, "brNDC");
1615 sprintf(name, "%s", cmsP.c_str());
1616 text2->AddText(name);
1617 text2->Draw("same");
1618 return canvas;
1619 }
1620
1621 TCanvas* plotEnergies(std::vector<std::string> fnames,
1622 std::vector<std::string> hlts,
1623 int var,
1624 int ien,
1625 int eta,
1626 int pv,
1627 bool varbin,
1628 int rebin,
1629 bool approve,
1630 std::string dtype,
1631 bool logy,
1632 int pos,
1633 int coloff) {
1634 TLegend* legend = new TLegend(0.55, 0.70, 0.95, 0.85);
1635 legend->SetBorderSize(1);
1636 legend->SetFillColor(kWhite);
1637 legend->SetMargin(0.4);
1638 TObjArray histArr;
1639 char name[100];
1640 std::vector<std::string> labels;
1641 std::vector<int> color;
1642 double ymx0(0), ent0(0);
1643 sprintf(name, "h_energy_%d_%d_%d_%d", pv + 3, ien, eta, var);
1644 for (unsigned int k = 0; k < fnames.size(); ++k) {
1645 TFile* file = TFile::Open(fnames[k].c_str());
1646 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1647 if (histo) {
1648 if (k == 0) {
1649 ent0 = histo->GetEntries();
1650 } else {
1651 double scale = (histo->GetEntries() > 0) ? ent0 / histo->GetEntries() : 1;
1652 histo->Scale(scale);
1653 }
1654 histArr.AddLast(histo);
1655 labels.push_back(hlts[k]);
1656 color.push_back(colors[coloff + k]);
1657 int ibin = histo->GetMaximumBin();
1658 if (histo->GetBinContent(ibin) > ymx0)
1659 ymx0 = histo->GetBinContent(ibin);
1660 }
1661 }
1662 TCanvas* c(0);
1663 if (histArr.GetEntries() > 0) {
1664 sprintf(name, "p=%s, %s", varPPs[ien].c_str(), nameEtas[eta].c_str());
1665
1666
1667
1668
1669
1670
1671
1672 std::string clabel(name);
1673 char cname[50];
1674 sprintf(cname, "c_%s_%d_%d_%s", varEne1[var].c_str(), ien, eta, dtype.c_str());
1675 sprintf(name, "%s/p", varEne[var].c_str());
1676 c = plotHisto(
1677 cname, clabel, histArr, labels, color, name, ymx0, logy, pos, 0.10, 0.05, 2.5, varbin, rebin, approve);
1678 }
1679 return c;
1680 }
1681
1682 TCanvas* plotEnergy(std::string fname,
1683 std::string HLT,
1684 int var,
1685 int ien,
1686 int eta,
1687 bool varbin,
1688 int rebin,
1689 bool approve,
1690 bool logy,
1691 int pos,
1692 int coloff) {
1693 TFile* file = TFile::Open(fname.c_str());
1694 char name[100];
1695 TObjArray histArr;
1696 std::vector<std::string> labels;
1697 std::vector<int> color;
1698 double ymx0(0);
1699 for (int i = 0; i < 4; ++i) {
1700 sprintf(name, "h_energy_%d_%d_%d_%d", i, ien, eta, var);
1701 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1702 if (histo) {
1703 histArr.AddLast(histo);
1704 sprintf(name, "p=%s, #eta=%s %s", varPs[ien].c_str(), varEta[eta].c_str(), namefull[i + 3].c_str());
1705 labels.push_back(name);
1706 color.push_back(colors[coloff + i]);
1707 int ibin = histo->GetMaximumBin();
1708 if (histo->GetBinContent(ibin) > ymx0)
1709 ymx0 = histo->GetBinContent(ibin);
1710 }
1711 }
1712 TCanvas* c(0);
1713 if (histArr.GetEntries() > 0) {
1714 char cname[50];
1715 sprintf(cname, "c_%s_%d_%d", varEne1[var].c_str(), ien, eta);
1716 sprintf(name, "%s/p", varEne[var].c_str());
1717 c = plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos, 0.10, 0.05, 2.5, varbin, rebin, approve);
1718 }
1719 return c;
1720 }
1721
1722 void plotEMeanPVAll(std::string fname, std::string HLT, int var, int eta, bool approve) {
1723 int varmin(0), varmax(5), etamin(0), etamax(etaMax);
1724 if (var >= 0)
1725 varmin = varmax = var;
1726 if (eta >= 0)
1727 etamin = etamax = eta;
1728 for (int var = varmin; var <= varmax; ++var) {
1729 for (int eta = etamin; eta <= etamax; ++eta) {
1730 plotEMeanDrawPV(fname, HLT, var, eta, approve);
1731 }
1732 }
1733 }
1734
1735 TCanvas* plotEMeanDrawPV(std::string fname, std::string HLT, int var, int eta, bool approve) {
1736 bool debug(false);
1737 std::vector<TGraphAsymmErrors*> graphs;
1738 TLegend* legend = new TLegend(0.575, 0.80, 0.975, 0.95);
1739 legend->SetBorderSize(1);
1740 legend->SetFillColor(kWhite);
1741 legend->SetMargin(0.4);
1742 TFile* file = TFile::Open(fname.c_str());
1743 const int nPVBin = 4;
1744 int pvBins[nPVBin + 1] = {1, 2, 3, 5, 100};
1745 for (int k = 0; k < nPVBin; ++k) {
1746 char name[100];
1747 double mean[NPT], dmean[NPT];
1748 for (int i = 0; i < NPT; ++i) {
1749 sprintf(name, "h_energy_%d_%d_%d_%d", k, i, eta, var);
1750 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1751 if (histo) {
1752 mean[i] = histo->GetMean();
1753 dmean[i] = histo->GetMeanError();
1754 } else {
1755 mean[i] = -100.;
1756 dmean[i] = 0;
1757 }
1758 }
1759 if (debug) {
1760 std::cout << "Get mean for " << NPT << " points" << std::endl;
1761 for (int i = 0; i < NPT; ++i)
1762 std::cout << "[" << i << "]"
1763 << " Momentum " << mom[i] << " +- " << dmom[i] << " Mean " << mean[i] << " +- " << dmean[i]
1764 << std::endl;
1765 }
1766 TGraphAsymmErrors* graph = new TGraphAsymmErrors(NPT, mom, mean, dmom, dmom, dmean, dmean);
1767 graph->SetMarkerStyle(styles[k]);
1768 graph->SetMarkerColor(colors[k]);
1769 graph->SetMarkerSize(1.2);
1770 graph->SetLineColor(colors[k]);
1771 graph->SetLineWidth(2);
1772 graphs.push_back(graph);
1773 sprintf(name, "PV=%d:%d", pvBins[k], pvBins[k + 1] - 1);
1774 legend->AddEntry(graph, name, "lp");
1775 if (debug)
1776 std::cout << "Complete " << name << std::endl;
1777 }
1778 file->Close();
1779
1780 char cname[100], name[200];
1781 sprintf(cname, "c_%s_PV_%d", varEne1[var].c_str(), eta);
1782 gStyle->SetCanvasBorderMode(0);
1783 gStyle->SetCanvasColor(kWhite);
1784 gStyle->SetPadColor(kWhite);
1785 gStyle->SetFillColor(kWhite);
1786 gStyle->SetOptTitle(kFALSE);
1787 gStyle->SetPadBorderMode(0);
1788 gStyle->SetCanvasBorderMode(0);
1789 TCanvas* canvas = new TCanvas(cname, cname, 500, 400);
1790 gStyle->SetOptStat(0);
1791 gPad->SetTopMargin(0.05);
1792 gPad->SetLeftMargin(0.15);
1793 gPad->SetRightMargin(0.025);
1794 gPad->SetBottomMargin(0.20);
1795 TH1F* vFrame = canvas->DrawFrame(0.0, 0.01, 50.0, 0.5);
1796 vFrame->GetYaxis()->SetRangeUser(0.0, 1.5);
1797 vFrame->GetXaxis()->SetLabelSize(0.06);
1798 vFrame->GetYaxis()->SetLabelSize(0.05);
1799 vFrame->GetXaxis()->SetTitleSize(0.06);
1800 vFrame->GetYaxis()->SetTitleSize(0.06);
1801 vFrame->GetYaxis()->SetTitleOffset(0.9);
1802 vFrame->GetXaxis()->SetRangeUser(1.0, 20.0);
1803 if (approve) {
1804 sprintf(name, "Mean of %s/p_{Track}", varEne[var].c_str());
1805 } else {
1806 sprintf(name, "<%s/p_{Track}>", varEne[var].c_str());
1807 }
1808 vFrame->GetYaxis()->SetTitle(name);
1809 sprintf(name, "p_{Track} (GeV/c)");
1810 vFrame->GetXaxis()->SetTitle(name);
1811 for (unsigned int ii = 0; ii < graphs.size(); ++ii)
1812 graphs[ii]->Draw("P");
1813 legend->Draw();
1814 TLine* line = new TLine(1.0, 1.0, 20.0, 1.0);
1815 line->SetLineStyle(2);
1816 line->SetLineWidth(2);
1817 line->SetLineColor(kRed);
1818 line->Draw();
1819 TPaveText* text = new TPaveText(0.575, 0.75, 0.97, 0.79, "brNDC");
1820 sprintf(name, "%s (%s)", HLT.c_str(), nameEtas[eta].c_str());
1821 if (debug)
1822 std::cout << "Name " << name << " |" << std::endl;
1823 text->AddText(name);
1824 text->Draw("same");
1825 TPaveText* text2 = new TPaveText(0.575, 0.71, 0.97, 0.75, "brNDC");
1826 sprintf(name, cmsP.c_str());
1827 text2->AddText(name);
1828 text2->Draw("same");
1829 return canvas;
1830 }
1831
1832 TCanvas* plotEnergyPV(std::string fname,
1833 std::string HLT,
1834 int var,
1835 int ien,
1836 int eta,
1837 bool varbin,
1838 int rebin,
1839 bool approve,
1840 bool logy,
1841 int pos) {
1842 const int nPVBin = 4;
1843 int pvBins[nPVBin + 1] = {1, 2, 3, 5, 100};
1844 TFile* file = TFile::Open(fname.c_str());
1845 char name[100];
1846 TObjArray histArr;
1847 std::vector<std::string> labels;
1848 std::vector<int> color;
1849 double ymx0(0);
1850 for (int i = 4; i < nPVBin + 4; ++i) {
1851 sprintf(name, "h_energy_%d_%d_%d_%d", i, ien, eta, var);
1852 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1853 if (histo) {
1854 histArr.AddLast(histo);
1855 sprintf(name,
1856 "p=%s, #eta=%s, PV=%d:%d (%s)",
1857 varPs[ien].c_str(),
1858 varEta[eta].c_str(),
1859 pvBins[i - 4],
1860 pvBins[i - 3] - 1,
1861 namefull[6].c_str());
1862 labels.push_back(name);
1863 color.push_back(colors[i - 4]);
1864 int ibin = histo->GetMaximumBin();
1865 if (histo->GetBinContent(ibin) > ymx0)
1866 ymx0 = histo->GetBinContent(ibin);
1867 }
1868 }
1869 TCanvas* c(0);
1870 if (histArr.GetEntries() > 0) {
1871 char cname[50];
1872 sprintf(cname, "c_%s_%d_%d", varEne1[var].c_str(), ien, eta);
1873 sprintf(name, "%s/p", varEne[var].c_str());
1874 c = plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos, 0.10, 0.05, 2.5, varbin, rebin, approve);
1875 }
1876 return c;
1877 }
1878
1879 TCanvas* plotTrack(
1880 std::string fname, std::string HLT, int var, bool varbin, int rebin, bool approve, bool logy, int pos) {
1881 TFile* file = TFile::Open(fname.c_str());
1882 char name[100];
1883 TObjArray histArr;
1884 std::vector<std::string> labels;
1885 std::vector<int> color;
1886 double ymx0(0);
1887 for (int i = 0; i < 7; ++i) {
1888 sprintf(name, "h_%s_%s", varname[var].c_str(), names[i].c_str());
1889 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1890 if (histo) {
1891 histArr.AddLast(histo);
1892 labels.push_back(namefull[i]);
1893 color.push_back(colors[i]);
1894 int ibin = histo->GetMaximumBin();
1895 if (histo->GetBinContent(ibin) > ymx0)
1896 ymx0 = histo->GetBinContent(ibin);
1897 }
1898 }
1899 if (histArr.GetEntries() > 0) {
1900 char cname[50];
1901 sprintf(cname, "c_%s", varname[var].c_str());
1902 sprintf(name, "%s", vartitle[var].c_str());
1903 return plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos, 0.10, 0.05, -1, varbin, rebin, approve);
1904 } else {
1905 return 0;
1906 }
1907 }
1908
1909 TCanvas* plotIsolation(
1910 std::string fname, std::string HLT, int var, bool varbin, int rebin, bool approve, bool logy, int pos) {
1911 TFile* file = TFile::Open(fname.c_str());
1912 char name[100];
1913 TObjArray histArr;
1914 std::vector<std::string> labels;
1915 std::vector<int> color;
1916 double ymx0(0);
1917 for (int i = 0; i < 2; ++i) {
1918 sprintf(name, "h_%s_%s", varnameC[var].c_str(), nameC[i].c_str());
1919 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1920 if (histo) {
1921 histArr.AddLast(histo);
1922 labels.push_back(nameCF[i]);
1923 color.push_back(colors[i]);
1924 int ibin = histo->GetMaximumBin();
1925 if (histo->GetBinContent(ibin) > ymx0)
1926 ymx0 = histo->GetBinContent(ibin);
1927 }
1928 }
1929 if (histArr.GetEntries() > 0) {
1930 char cname[50];
1931 sprintf(cname, "c_%s", varnameC[var].c_str());
1932 sprintf(name, "%s (GeV)", vartitlC[var].c_str());
1933 return plotHisto(cname, HLT, histArr, labels, color, name, ymx0, logy, pos, 0.10, 0.05, -1, varbin, rebin, approve);
1934 } else {
1935 return 0;
1936 }
1937 }
1938
1939 TCanvas* plotHLT(std::string fname, std::string HLT, int run, bool varbin, int rebin, bool approve, bool logy, int pos) {
1940 TFile* file = TFile::Open(fname.c_str());
1941 char name[100];
1942 TObjArray histArr;
1943 std::vector<std::string> labels;
1944 std::vector<int> color;
1945 double ymx0(0);
1946 if (run > 0)
1947 sprintf(name, "h_HLTAccepts_%d", run);
1948 else
1949 sprintf(name, "h_HLTAccept");
1950 TH1D* histo = (TH1D*)file->FindObjectAny(name);
1951 if (histo) {
1952 histArr.AddLast(histo);
1953 labels.push_back(HLT);
1954 color.push_back(colors[3]);
1955 int ibin = histo->GetMaximumBin();
1956 ymx0 = histo->GetBinContent(ibin);
1957 }
1958 if (histArr.GetEntries() > 0) {
1959 char cname[50], hname[50];
1960 if (run > 0) {
1961 sprintf(cname, "c_HLT_%d", run);
1962 sprintf(name, "Run %d", run);
1963 } else {
1964 sprintf(cname, "c_HLTs");
1965 sprintf(name, "All runs");
1966 }
1967 sprintf(hname, " ");
1968 return plotHisto(cname, "", histArr, labels, color, hname, ymx0, logy, pos, 0.40, 0.01, -1, varbin, rebin, approve);
1969 } else {
1970 return 0;
1971 }
1972 }
1973
1974 TCanvas* plotHisto(char* cname,
1975 std::string HLT,
1976 TObjArray& histArr,
1977 std::vector<std::string>& labels,
1978 std::vector<int>& color,
1979 char* name,
1980 double ymx0,
1981 bool logy,
1982 int pos,
1983 double yloff,
1984 double yhoff,
1985 double xmax,
1986 bool varbin,
1987 int rebin0,
1988 bool approve) {
1989 int nentry = histArr.GetEntries();
1990 double ymax = 10.;
1991 for (int i = 0; i < 10; ++i) {
1992 if (ymx0 < ymax)
1993 break;
1994 ymax *= 10.;
1995 }
1996 double ystep = ymax * 0.1;
1997 for (int i = 0; i < 9; ++i) {
1998 if (ymax - ystep < ymx0)
1999 break;
2000 ymax -= ystep;
2001 }
2002 double ymin(0);
2003 if (logy)
2004 ymin = 1;
2005
2006 gStyle->SetCanvasBorderMode(0);
2007 gStyle->SetCanvasColor(kWhite);
2008 gStyle->SetPadColor(kWhite);
2009 gStyle->SetFillColor(kWhite);
2010 gStyle->SetOptTitle(kFALSE);
2011 gStyle->SetPadBorderMode(0);
2012 gStyle->SetCanvasBorderMode(0);
2013 if (approve)
2014 gStyle->SetOptStat(0);
2015 else
2016 gStyle->SetOptStat(1110);
2017 TCanvas* canvas = new TCanvas(cname, cname, 500, 500);
2018 gPad->SetTopMargin(yhoff);
2019 gPad->SetLeftMargin(0.15);
2020 gPad->SetRightMargin(0.025);
2021 gPad->SetBottomMargin(yloff);
2022 if (logy)
2023 canvas->SetLogy();
2024 double height = 0.08;
2025 double dx = (nentry > 2) ? 0.50 : 0.30;
2026 double dy = (nentry > 2) ? 0.12 : 0.04;
2027 double dy2 = 0.035;
2028 double xmin1 = (pos > 1) ? 0.375 : 0.75 - dx;
2029 double xmin2 = (pos > 1) ? 0.12 : 0.65;
2030 double xmin3 = (pos > 1) ? 0.15 : 0.75;
2031 double ymin1 = (pos % 2 == 0) ? (1.0 - yhoff - dy) : (yloff + 0.02);
2032 double ymin2 = (pos % 2 == 0) ? (0.96 - yhoff - nentry * height) : (yloff + 0.025 + nentry * height);
2033 double ymin3 = (pos % 2 == 0) ? (ymin2 - dy2) : (ymin2 + dy2);
2034 double dx2 = (approve) ? dx : 0.32;
2035 double dx3 = (approve) ? dx : 0.22;
2036 if (approve) {
2037 xmin1 = xmin2 = xmin3 = 0.975 - dx;
2038 ymin1 = (1.0 - yhoff - dy);
2039 ymin2 = ymin1 - dy2 - 0.01;
2040 ymin3 = ymin2 - dy2;
2041 }
2042 TLegend* legend = new TLegend(xmin1, ymin1, xmin1 + dx, ymin1 + dy);
2043 TPaveText *text, *text2;
2044 if (varbin || rebin0 == 1) {
2045 text = new TPaveText(xmin2, ymin2, xmin2 + dx2, ymin2 + dy2, "brNDC");
2046 text2 = new TPaveText(xmin3, ymin3, xmin3 + dx3, ymin3 + dy2, "brNDC");
2047 } else {
2048 text = new TPaveText(0.10, 0.95, dx2 + 0.10, dy2 + 0.95, "brNDC");
2049 text2 = new TPaveText(dx2 + 0.10, 0.95, dx2 + dx3 + 0.10, dy2 + 0.95, "brNDC");
2050 }
2051 legend->SetBorderSize(1);
2052 legend->SetFillColor(kWhite);
2053 char texts[200];
2054 sprintf(texts, cmsP.c_str());
2055 text2->AddText(texts);
2056 THStack* Hs = new THStack("hs2", " ");
2057 for (int i = 0; i < nentry; i++) {
2058 TH1D* h = (varbin) ? rebin((TH1D*)histArr[i], i) : (TH1D*)((TH1D*)histArr[i])->Rebin(rebin0);
2059 h->SetLineColor(color[i]);
2060 h->SetLineStyle(lstyle[i]);
2061 h->SetLineWidth(2);
2062 h->SetMarkerSize(1.0);
2063 double ymax0 = (varbin) ? ymax : rebin0 * ymax;
2064 h->GetYaxis()->SetRangeUser(ymin, ymax0);
2065 if (xmax > 0 && (!varbin))
2066 h->GetXaxis()->SetRangeUser(0, xmax);
2067 Hs->Add(h, "hist sames");
2068 legend->AddEntry(h, labels[i].c_str(), "l");
2069 }
2070 Hs->Draw("nostack");
2071 canvas->Update();
2072 Hs->GetHistogram()->GetXaxis()->SetTitle(name);
2073 Hs->GetHistogram()->GetXaxis()->SetLabelSize(0.035);
2074 Hs->GetHistogram()->GetYaxis()->SetTitleOffset(1.6);
2075 if (varbin) {
2076 Hs->GetHistogram()->GetYaxis()->SetTitle("Tracks/0.01");
2077 } else {
2078 Hs->GetHistogram()->GetYaxis()->SetTitle("Tracks");
2079 if (xmax > 0)
2080 Hs->GetHistogram()->GetXaxis()->SetRangeUser(0, xmax);
2081 }
2082 canvas->Modified();
2083
2084 canvas->Update();
2085 if (!approve) {
2086 for (int i = 0; i < nentry; i++) {
2087 TH1D* h = (TH1D*)histArr[i];
2088 if (h != NULL) {
2089 TPaveStats* st1 = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
2090 if (st1 != NULL) {
2091 if (pos % 2 == 0) {
2092 st1->SetY1NDC(1.0 - yhoff - (i + 1) * height);
2093 st1->SetY2NDC(1.0 - yhoff - i * height);
2094 } else {
2095 st1->SetY1NDC(yloff + 0.02 + i * height);
2096 st1->SetY2NDC(yloff + 0.02 + (i + 1) * height);
2097 }
2098 if (pos > 1) {
2099 st1->SetX1NDC(0.15);
2100 st1->SetX2NDC(.375);
2101 } else {
2102 st1->SetX1NDC(0.75);
2103 st1->SetX2NDC(.975);
2104 }
2105 st1->SetTextColor(colors[i]);
2106 }
2107 }
2108 }
2109 }
2110 legend->Draw("");
2111 if (HLT != "") {
2112 text->AddText(HLT.c_str());
2113 text->Draw("same");
2114 }
2115 text2->Draw("same");
2116
2117 return canvas;
2118 }
2119
2120 void getHistStats(TH1D* h,
2121 int& entries,
2122 int& integral,
2123 double& mean,
2124 double& meanE,
2125 double& rms,
2126 double& rmsE,
2127 int& uflow,
2128 int& oflow) {
2129 entries = h->GetEntries();
2130 integral = h->Integral();
2131 mean = h->GetMean();
2132 meanE = h->GetMeanError();
2133 rms = h->GetRMS();
2134 rmsE = h->GetRMSError();
2135 uflow = h->GetBinContent(0);
2136 oflow = h->GetBinContent(h->GetNbinsX() + 1);
2137 }
2138
2139 TFitResultPtr getHistFitStats(
2140 TH1F* h, const char* formula, double xlow, double xup, unsigned int& nPar, double* par, double* epar) {
2141 TFitResultPtr fit = h->Fit(formula, "+qRB0", "", xlow, xup);
2142 nPar = fit->NPar();
2143 const std::vector<double> errors = fit->Errors();
2144 for (unsigned int i = 0; i < nPar; i++) {
2145 par[i] = fit->Value(i);
2146 epar[i] = errors[i];
2147 }
2148 return fit;
2149 }
2150
2151 void setHistAttr(TH1F* h, int icol, int lwid, int ltype) {
2152 h->SetLineColor(icol);
2153 h->SetLineStyle(ltype);
2154 h->SetLineWidth(lwid);
2155 TF1* f = h->GetFunction("gaus");
2156 if (!f->IsZombie()) {
2157 f->SetLineColor(icol);
2158 f->SetLineStyle(2);
2159 }
2160 }
2161
2162 double getWeightedMean(int npt, int Start, std::vector<double>& mean, std::vector<double>& emean) {
2163 double sumDen = 0, sumNum = 0;
2164 for (int i = Start; i < npt; i++) {
2165 if (mean[i] == 0.0 || emean[i] == 0.0) {
2166 sumNum += 0;
2167 sumDen += 0;
2168 } else {
2169 sumNum += mean[i] / (emean[i] * emean[i]);
2170 sumDen += 1.0 / (emean[i] * emean[i]);
2171 }
2172 }
2173 double WeightedMean = sumNum / sumDen;
2174 return WeightedMean;
2175 }
2176
2177 TH1D* rebin(TH1D* histin, int indx) {
2178 std::string nameIn(histin->GetName());
2179 char name[200];
2180 sprintf(name, "%sRebin%d", nameIn.c_str(), indx);
2181 TH1D* hist = new TH1D(name, histin->GetXaxis()->GetTitle(), nbins, xbins);
2182 std::vector<double> cont;
2183 for (int i = 1; i <= histin->GetNbinsX(); ++i) {
2184 double value = histin->GetBinContent(i);
2185 cont.push_back(value);
2186 }
2187 for (int i = 0; i < nbins; ++i) {
2188 double totl = 0;
2189 int kount = 0;
2190 int klow = ibins[i];
2191 int khigh = ibins[i + 1];
2192 for (int k = klow; k < khigh; ++k) {
2193 totl += cont[k - 1];
2194 kount++;
2195 }
2196 if (kount > 0)
2197 totl /= kount;
2198 hist->SetBinContent(i + 1, totl);
2199 }
2200 return hist;
2201 }