-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathderiveL2ResNarrow.C
More file actions
1446 lines (1228 loc) · 50 KB
/
deriveL2ResNarrow.C
File metadata and controls
1446 lines (1228 loc) · 50 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Attempt to derive L2Res from single jet triggers
// as a by-product on inclusive jet cross section measurement
// Inputs from Hannu Siikonen
#include "TFile.h"
#include "TH3D.h"
#include "TH2D.h"
#include "TProfile.h"
#include "TCanvas.h"
#include "TF1.h"
#include "TMatrixD.h"
#include "TGraphErrors.h"
#include "TMinuit.h"
#include "TMath.h"
#include "tdrstyle_mod15.C"
#include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h"
#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
// Ugly global variables...
//const char *ct = "G";
//const char *ct = "BCDEFGH";
const char *ct = "H";
struct l2fit {
double chi2a, chi2b;
int ndfa, ndfb;
TF1 *f1a, *f1b;
TMatrixD *emata, *ematb;
l2fit(double chi2a_ = 0, int ndfa_ = 0, TF1 *f1a_ = 0, TMatrixD *emata_ = 0,
double chi2b_ = 0, int ndfb_ = 0, TF1 *f1b_ = 0, TMatrixD *ematb_ = 0) :
chi2a(chi2a_), ndfa(ndfa_), f1a(f1a_), emata(emata_),
chi2b(chi2b_), ndfb(ndfb_), f1b(f1b_), ematb(ematb_) { };
};
const double _xmin(30.), _xmax(3500.);
FactorizedJetCorrector *_jer_dt(0), *_jer_mc(0);
Double_t fJER(Double_t *x, Double_t *p) {
// Note: still need to implement quadratic averaging over
// eta and rho bins for |eta|<1.3 and all rho
// Where is the sqrt(2) compared to sigma(asymmetry)?
double pt = x[0];
double eta = p[0];
double eta0 = 0.65;
bool ismc = (p[1]==0);
double rho = 25.*1.0;//p[1];
if (!_jer_dt) {
const char *sd = "CondFormats/JetMETObjects/data";
const char *st = "Spring16_25nsV6_DATA";
const char *sa = "PtResolution_AK4PFchs";
const char *s = Form("%s/%s_%s.txt",sd,st,sa); cout << s << endl << flush;
JetCorrectorParameters *pjer = new JetCorrectorParameters(s);
vector<JetCorrectorParameters> v;
v.push_back(*pjer);
_jer_dt = new FactorizedJetCorrector(v);
}
if (!_jer_mc) {
const char *sd = "CondFormats/JetMETObjects/data";
const char *st = "Spring16_25nsV6_MC";
const char *sa = "PtResolution_AK4PFchs";
const char *s = Form("%s/%s_%s.txt",sd,st,sa); cout << s << endl << flush;
JetCorrectorParameters *pjer = new JetCorrectorParameters(s);
vector<JetCorrectorParameters> v;
v.push_back(*pjer);
_jer_mc = new FactorizedJetCorrector(v);
}
FactorizedJetCorrector *_jer = (ismc ? _jer_mc : _jer_dt);
_jer->setJetPt(pt);
_jer->setJetEta(eta);
_jer->setRho(rho);
double jer = _jer->getCorrection();
_jer->setJetPt(pt);
_jer->setJetEta(eta0);
_jer->setRho(rho);
double jer0 = _jer->getCorrection();
//return jer / sqrt(2.);
return sqrt(jer*jer +jer0*jer0) / 2.;
//return jer;
} // fJER
double _eta(2.0);
Double_t fXsec(Double_t *x, Double_t *p) {
double pt = x[0];
double xsec = p[0]*pow(pt,p[1])*pow(1-2*pt*cosh(_eta)/13000.,p[2]);
return xsec;
}
TF1 *_xsec(0);
Double_t deltaPtKernel2(Double_t *x, Double_t *p) {
double dpt = x[0];
double pTave = p[0];
double sigma1 = p[1];
double sigma2 = p[2];
double pTgen = p[3];
bool norm = (p[4]==0);
if (!_xsec) {
_xsec = new TF1("xsec",fXsec,_xmin,_xmax,3);
//_xsec->SetParameters(1.03331e+09, -4.27019e+00, 6.92540e+00); // pT,ave
_xsec->SetParameters(1.42389e+09, -4.29955e+00, 6.22351e+00); // pT,tag
}
// dpt = (pt2-pT1)/(2*pTave)
double s1 = TMath::Gaus(pTave-dpt*pTave-pTgen, 0, sigma1*pTave, kTRUE);
double s2 = TMath::Gaus(pTave+dpt*pTave-pTgen, 0, sigma2*pTave, kTRUE);
double xsec = _xsec->Eval(pTgen);
// Could the cross section fall steeper vs jet2 pT?
//xsec /= (1 - 2.*pTgen*cosh(_eta)/13000.,6.9254);
//xsec *= (1 - 2.*pTge*cosh(_eta)/13000.,6.9254);
return (norm ? s1*s2*xsec : dpt*s1*s2*xsec);
//return (norm ? s1*s2*xsec : fabs(dpt)*s1*s2*xsec); // does show large effect
} // deltaPtKernel2
TF1 *_fdpt2(0); // Integral over dpt
Double_t deltaPtKernel1(Double_t *x, Double_t *p) {
double pTgen = x[0];
double pTave = p[0];
double sigma1 = p[1];
double sigma2 = p[2];
double norm = p[3];
if (!_fdpt2)
_fdpt2 = new TF1("fdpt2",deltaPtKernel2,_xmin,_xmax,5);
double ksigma = 2.5;//3.5;
double sigma = sqrt(sigma1*sigma1 + sigma2*sigma2);
_fdpt2->SetParameters(pTave, sigma1, sigma2, pTgen, norm);
double Xdn = _fdpt2->Integral(-ksigma*sigma, +ksigma*sigma, 1e-4);
return Xdn; // dpt*dn or just dn
} // deltaPtKernel1
// Calculate deltaPt given pT,ave spectrum and JER
// Assume for simplicity pTgen1=pTgen=pTgen => pTave,gen=pTgen
// deltaPt = (pTreco2 - pTreco1) / 2
// double dpt = \integral_pTgen \integral_dpt dpt
// * JER(pTave+dpt-pTgen; sigma2) * JER(pTave-dpt-pTgen; sigma1)
// * f(pTgen) d(dpt) d(pTgen)
TF1 *_fdpt1(0); // Integral over pTgen
Double_t deltaPt(Double_t *x, Double_t *p) {
double pTave = x[0];
double eta1 = p[0];
double eta2 = p[1];
double isdt = p[2]; // 0==mc, 1==data
double p1[2] = {eta1,isdt};
double p2[2] = {eta2,isdt};
double ksigma = 2.5;//3.5;
double sigma1 = sqrt(2.)*fJER(&pTave, &p1[0]);
double sigma2 = sqrt(2.)*fJER(&pTave, &p2[0]);
if (!_fdpt1)
_fdpt1 = new TF1("fdpt1",deltaPtKernel1,_xmin,_xmax,4);
double sigma = sqrt(sigma1*sigma1 + sigma2*sigma2);
_fdpt1->SetParameters(pTave, sigma1, sigma2, 1);
double dptdn = _fdpt1->Integral(pTave*(1-ksigma*sigma),
pTave*(1+ksigma*sigma),1e-4);
_fdpt1->SetParameters(pTave, sigma1, sigma2, 0);
double dn = _fdpt1->Integral(pTave*(1-ksigma*sigma),
pTave*(1+ksigma*sigma),1e-4);
return (dptdn / dn);
} // deltaPt
double getErr(double x, TF1 *f1, TMatrixD *emat) {
int n = f1->GetNpar();
assert(emat->GetNcols()==n);
assert(emat->GetNrows()==n);
vector<double> df(n);
for (int i = 0; i != n; ++i) {
double p = f1->GetParameter(i);
double dp = f1->GetParError(i);
assert(dp!=0);
double y1 = f1->Eval(x);
f1->SetParameter(i, p+0.01*dp);
double y2 = f1->Eval(x);
f1->SetParameter(i, p);
df[i] = (y2-y1)/(0.01*dp);
}
double err2(0);
for (int i = 0; i != n; ++i) {
for (int j = 0; j != n; ++j) {
err2 += df[i]*df[j]*(*emat)[i][j];
}
} // for i
return sqrt(err2);
}
// Derive truncated RMS (and it's uncertainty) from histogram
// by finding smallest range that contains frac events
//double truncRMS(TH1D *h, double *err, double frac = 0.985) {
double truncRMS(TH1D *h, double frac = 0.985) {
//double truncRMS(TH1D *h, double frac = 0.975) {
//return h->GetRMS(); // TMP speedup
TH1D *htmp = (TH1D*)h->Clone("htmp");
//htmp->Clear();
//double sum = h->Integral();
double sum = h->Integral(1,h->GetNbinsX()); // avoid overflows
int imean = h->FindBin(h->GetMean());
int imin(-1), jmin(h->GetNbinsX()+1);
double dxmin(h->GetNbinsX()+1);
for (int i = 1; i != imean; ++i) {
//if (h->Integral(i, h->GetNbinsX()+1) < frac) continue;
for (int j = h->GetNbinsX(); j != imean; --j) {
int dx = j-i;
//if (h->Integral(i,j) / sum < frac) continue;
if (h->Integral(i,j) / sum >= frac && dx < dxmin) {
dxmin = dx;
imin = i;
jmin = j;
}
} // for j
} // for i
for (int i = 1; i != h->GetNbinsX()+1; ++i) {
if (i<imin || i > jmin) {
htmp->SetBinContent(i, 0);
htmp->SetBinError(i, 0);
}
} // for i
double rms = htmp->GetRMS();
//*err = htmp->GetRMS()/sqrt(h->GetEffectiveEntries());
delete htmp;
return rms;
} // truncRMS
// Clean out bins with only 1 entry from data-MC pair
void cleanPair(TH1D *h1, TH1D* h2) {
assert(h1);
assert(h2);
assert(h1->GetNbinsX()==h2->GetNbinsX());
for (int i = 1; i != h1->GetNbinsX()+1; ++i) {
if (h1->GetBinError(i)==0 || h2->GetBinError(i)==0) {
h1->SetBinContent(i, 0);
h1->SetBinError(i, 0);
h2->SetBinContent(i, 0);
h2->SetBinError(i, 0);
}
} // for i
} // cleanPair
l2fit deriveL2ResNarrow_x(double y1=2.0, double y2=2.5,
double alphamax=0.2, double xmax=2000.);
TH1D *_htrg(0);
// Main method (pTave, tag pT, probe pT)
string stp = "";//"tp";
const char *ctp = stp.c_str();//"tp";
// Cross-check method 1 (tag pT)
string stp2 = "tp";
const char *ctp2 = stp2.c_str();
// Cross-check method 2 (probe pT)
string stp3 = "pt";
const char *ctp3 = stp3.c_str();
void deriveL2ResNarrow() {
// For spectrum reconstruction
const int ntrg = 9; // 1st 74 (jet40)
//double trigpt[ntrg+1] = {0, 84, 114, 196, 272, 330, 395, 468, 548,3500};
double trigpt[ntrg+1] = {0, 84, 114, 174, 245, 330, 395, 468, 548,3500};
// Effective prescales for RunFLateG_rereco from Engin root tuple
//152728, 152655, 152261, 151443, 149893, 146976, 141570, 129504, 20007, 19543.2, 18588.5, 16868.2, 1986.39, 1902.99, 1758.02, 564.405, 511.402, 66.7384, 61.396, 22.0983, 20.2887, 7.31431, 6.60524,
//double trigpre[ntrg] = {152728, 129504, 20007, 1986, 564.4, 66.74, 22.10, 7.314, 1};
double trigpre[ntrg] = {152728, 50000, 20007, 1986, 564.4, 66.74, 22.10, 7.314, 1};
//double trigpre[ntrg] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
_htrg = new TH1D("htrg",";p_{T};prescale;",ntrg,trigpt);
for (int i = 1; i != _htrg->GetNbinsX()+1; ++i) {
_htrg->SetBinContent(i, trigpre[i-1]);
}
//double etas[] = {0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0,
// 3.2, 4.7};
//double xmax[] = {2000, 2000, 2000, 1500, 1200, 800, 500, 350};
// double etas[] = {0,0.261,0.522,0.783,1.044,1.305,
// 1.479,1.653,1.93,2.172,2.322,2.5,
// 2.65,2.853,2.964,3.139,3.489,3.839,
// 5.191};
// double xmax[] = {2000, 2000, 2000, 2000, 2000,
// 1780, 1600, 1400, 1100, 1000, 900,
// 800, 680, 630, 420, 290, 190,
// 133};
double etas[] = {0,0.261,0.522,0.783, 1.044,1.305,1.479,
1.653,1.93,2.172, 2.322,2.5,2.65,
2.853,2.964,3.139, 3.489,3.839,5.191};
double xmax[] = {2000,2000,2000, 1784,1684,1497, // min 1%, 5%/sqrt(N)->25
1410,1248,1032, 905,790,686, // same min 1%, N>25
638,507,468, 395,300,220}; // eyeballing limits, low stat
// SMP-J binning:
//28, 32, 37, 43, 49, 56, 64, 74, 84,
//97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468,
// 507, 548, 592, 638, 686, 737, 790, 846, 905, 967,
// 1032, 1101, 1172, 1248, 1327, 1410, 1497, 1588, 1684, 1784, 1890, 2000,
// Debug one bin first
// double etas[] = {2.5,3.0};//2.65};
// double xmax[] = {800};
const int neta = sizeof(etas)/sizeof(etas[0]) - 1;
assert(sizeof(xmax)/sizeof(xmax[0]) == neta);
//double alphamax = 0.3;
//double alphamax = 0.2;
//double alphamax = 0.1;
//double alphamax = 0.05;
//double alphamax = 0.025;
//double alphas[] = {0.025, 0.05, 0.1, 0.2, 0.3};
//double alphas[] = {0.2};
//double alphas[] = {0.05};
//double alphas[] = {0.10};
//double alphas[] = {0.20};
//double alphas[] = {0.30};
double alphas[] = {0.1, 0.15, 0.20, 0.30};
const int nalpha = sizeof(alphas)/sizeof(alphas[0]);
double pts[] = {60, 120, 240, 480};
int colorpt[] = {kBlack, kRed, kGreen+2, kBlue};
int markerpt[] = {0, kFullSquare, 0, 0};
const int npt = sizeof(pts)/sizeof(pts[0]);
vector<TH1D*> hptas(npt), hptbs(npt);
for (int ipt = 0; ipt != npt; ++ipt) {
hptas[ipt] = new TH1D(Form("hpt_%1.0f",pts[ipt]),
";|#eta|;Relative correction (DB)",
neta, &etas[0]);
hptbs[ipt] = new TH1D(Form("hpt_%1.0f",pts[ipt]),
";|#eta|;Relative correction (MPF)",
neta, &etas[0]);
}
for (int ialpha = 0; ialpha != nalpha; ++ialpha) {
const double alphamax = alphas[ialpha];
vector<l2fit> l2s(neta);
double maxchi2 = 5;
TGraphErrors *gchi2a = new TGraphErrors(neta);
TGraphErrors *gchi2b = new TGraphErrors(neta);
for (int ieta = 0; ieta != neta; ++ieta) {
double eta = 0.5*(etas[ieta] + etas[ieta+1]);
double deta = 0.5*(etas[ieta+1] - etas[ieta]);
l2s[ieta] = deriveL2ResNarrow_x(etas[ieta], etas[ieta+1],
alphamax, xmax[ieta]);
gchi2a->SetPoint(ieta, eta, min(l2s[ieta].chi2a/l2s[ieta].ndfa, maxchi2));
gchi2a->SetPointError(ieta, deta, 1. / sqrt(l2s[ieta].ndfa));
gchi2b->SetPoint(ieta, eta, min(l2s[ieta].chi2b/l2s[ieta].ndfb, maxchi2));
gchi2b->SetPointError(ieta, deta, 1. / sqrt(l2s[ieta].ndfb));
for (int ipt = 0; ipt != npt; ++ipt) {
double pt = pts[ipt];
double A = l2s[ieta].f1a->Eval(pt);
double Rrel_A = (1 + A) / (1 - A);
double B = l2s[ieta].f1b->Eval(pt);
double Rrel_B = (1 + B) / (1 - B);
if (pt*cosh(eta) < 6500.) {
hptas[ipt]->SetBinContent(ieta+1, 1./Rrel_A);
if (markerpt[ipt]!=0) {
double err = getErr(pt, l2s[ieta].f1a, l2s[ieta].emata);
hptas[ipt]->SetBinError(ieta+1, err);
}
hptbs[ipt]->SetBinContent(ieta+1, 1./Rrel_B);
if (markerpt[ipt]!=0) {
double err = getErr(pt, l2s[ieta].f1b, l2s[ieta].ematb);
hptbs[ipt]->SetBinError(ieta+1, err);
}
}
}
} // for ieta
TH1D *h1 = new TH1D("h1",";#eta;#chi^{2} / NDF",neta,&etas[0]);
h1->SetMinimum(0.);
//h1->SetMaximum(3);
h1->SetMaximum(maxchi2+1e-4);//5);
TCanvas *c1 = tdrCanvas("c1",h1,4,11,kSquare);
TLine *l1 = new TLine();
l1->SetLineStyle(kDashed);
l1->DrawLine(etas[0],1,etas[neta],1);
tdrDraw(gchi2a,"Pz",kFullCircle);//kFullCircle);
tdrDraw(gchi2b,"Pz",kOpenSquare);//kOpenCircle);
TLegend *leg = tdrLeg(0.60,0.78,0.80,0.90);
//leg->AddEntry(gchi2,"Log-lin","PL");
//leg->AddEntry(gchi2b,"Quad-log","PL");
leg->AddEntry(gchi2a,"DB quad-log","PL");
leg->AddEntry(gchi2b,"MPF quad-log","PL");
c1->SaveAs(Form("pdf/l2res/%s/deriveL2ResNarrow_chi2_amax%1.0f%s.pdf",
ct,alphamax*100,ctp));
TH1D *h2a = new TH1D("h2",";#eta;Relative correction (DB)",neta,&etas[0]);
h2a->SetMinimum(0.8);//0.98 - 0.03 - 0.05);
h2a->SetMaximum(1.3);//1.19-1e-4 - 0.03 + 0.05);
TCanvas *c2a = tdrCanvas("c2a",h2a,4,11,kSquare);
TLine *l2a = new TLine();
l2a->SetLineStyle(kDashed);
l2a->DrawLine(etas[0],1,etas[neta],1);
TLegend *leg2a = tdrLeg(0.17,0.48,0.47,0.78);
leg2a->SetHeader("p_{T}(jet)");
for (int ipt = 0; ipt != npt; ++ipt) {
tdrDraw(hptas[ipt], markerpt[ipt]!=0 ? "HP][" : "H][", markerpt[ipt],
colorpt[ipt],kSolid,colorpt[ipt],kNone,0);
hptas[ipt]->SetLineWidth(2);
leg2a->AddEntry(hptas[ipt],Form("%1.0f GeV",pts[ipt]),
markerpt[ipt]!=0 ? "LP" : "L");
}
gPad->RedrawAxis();
c2a->SaveAs(Form("pdf/l2res/%s/deriveL2ResNarrow_Fig15a_amax%1.0f%s.pdf",
ct,alphamax*100,ctp));
TH1D *h2b = new TH1D("h2",";#eta;Relative correction (MPF)",neta,&etas[0]);
h2b->SetMinimum(0.8);//0.98 - 0.03 - 0.05);
h2b->SetMaximum(1.3);//1.19-1e-4 - 0.03 + 0.05);
TCanvas *c2b = tdrCanvas("c2b",h2b,4,11,kSquare);
TLine *l2b = new TLine();
l2b->SetLineStyle(kDashed);
l2b->DrawLine(etas[0],1,etas[neta],1);
TLegend *leg2b = tdrLeg(0.17,0.48,0.47,0.78);
leg2b->SetHeader("p_{T}(jet)");
for (int ipt = 0; ipt != npt; ++ipt) {
tdrDraw(hptbs[ipt], markerpt[ipt]!=0 ? "HP][" : "H][", markerpt[ipt],
colorpt[ipt],kSolid,colorpt[ipt],kNone,0);
hptbs[ipt]->SetLineWidth(2);
leg2b->AddEntry(hptbs[ipt],Form("%1.0f GeV",pts[ipt]),
markerpt[ipt]!=0 ? "LP" : "L");
}
gPad->RedrawAxis();
c2b->SaveAs(Form("pdf/l2res/%s/deriveL2ResNarrow_Fig15b_amax%1.0f%s.pdf",
ct,alphamax*100,ctp));
if (ialpha!=nalpha-1) { // leave last ones open
delete h1;
delete h2a;
delete h2b;
}
} // for ialpha
}
l2fit deriveL2ResNarrow_x(double y1, double y2, double alphamax, double xmax) {
TDirectory *curdir = gDirectory;
//TFile *fd = new TFile(Form("rootfiles/exclusion_cmsweek/mikko/%s/output-DATA-2b.root",ct),"READ");
TFile *fd = new TFile(Form("rootfiles/output_Run%se/mikko/output-DATA-2b.root",ct),"READ");
//TFile *fd = new TFile("rootfiles/exclusion_cmsweek/mikko/GH/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/exclusion_cmsweek/mikko/G/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/exclusiontests/mikkofG/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/exclusiontests/normalfG/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/exclusiontests/normalH/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/output_RunFlateG_Feb03V0/nol2l3res/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/output_RunGV6x/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/output_RunGV6/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/output_RunGV6/output-DATA-2b-noL2Res.root",
// "READ");
//TFile *fd = new TFile("rootfiles/output_RunGV6/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/output_RunGV5/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/output_RunGV3/output-DATA-2b.root","READ");
//TFile *fd = new TFile("rootfiles/output_RunG_old/output-DATA-2b.root","READ");
assert(fd && !fd->IsZombie());
TFile *fm = new TFile(Form("rootfiles/exclusion_cmsweek/mc/%s/output-MC-2b.root",ct),"READ");
//TFile *fm = new TFile("rootfiles/exclusion_cmsweek/mc/GH/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/exclusion_cmsweek/mc/G/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/exclusiontests/normalMC_fG/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/output_RunFlateG_Feb03V0/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/output_RunGV6x/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/output_RunGV6/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/output_RunGV5/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/output_RunGV3/output-MC-2b.root","READ");
//TFile *fm = new TFile("rootfiles/output_RunG_old/output-MC-2b.root","READ");
assert(fm && !fm->IsZombie());
//TFile *fz = new TFile("rootfiles/L3res_mumu_Run2016FlateG.root","READ");
//TFile *fz = new TFile("rootfiles/L3res_mumu_inclusive.root","READ");
TFile *fz = new TFile(Form("rootfiles/L3res_mumu_Run2016%s.root",ct),"READ");
assert(fz && !fz->IsZombie());
curdir->cd();
// See: (pt-alpha-asymm/mpf)
// KEY: TH3D hdjasymm;1 => pT,ave
// KEY: TH3D hdjasymmtp;1 => pT,tag
// KEY: TH3D hdjmpf;1
// KEY: TH3D hdjmpftp;1
// Note: mpf here means the same as balance/B.
//const char *cd = "Standard";
//const char *ce0 = "Eta_0.0-1.3"; // Does this make a difference? Event counts?
//const char *cd = "FullEta";
const char *cd = "FullEta_Reco";
const char *ce0 = "";
//string se = Form("Eta_%1.1f-%1.1f",y1,y2);
string se = Form("Eta_%1.3f-%1.3f",y1,y2);
const char *ce = se.c_str();
string se2 = Form("Eta_%02.0f-%02.0f",10*y1,10*y2);
const char *ce2 = se2.c_str();
double xmin(30.);//60.);//, xmax(2000.);
double fitxmin(64.);
//const char *ca = "_a01";//Form("_a%");
const char *ca = TString(Form("_a%1.3g",alphamax)).ReplaceAll(".","").Data();
setTDRStyle();
// Tag-and-probe with pT,tag binning: ctp = "tp"
// Regular asymmetry with pT,ave binning: ctp = ""
TH3D *h3da = (TH3D*)fd->Get(Form("%s/%s/hdjasymm%s%s",cd,ce0,ctp,ca));
TH3D *h3db = (TH3D*)fd->Get(Form("%s/%s/hdjmpf%s%s",cd,ce0,ctp,ca));
TH3D *h3ma = (TH3D*)fm->Get(Form("%s/%s/hdjasymm%s%s",cd,ce0,ctp,ca));
TH3D *h3mb = (TH3D*)fm->Get(Form("%s/%s/hdjmpf%s%s",cd,ce0,ctp,ca));
assert(h3da);
assert(h3db);
assert(h3ma);
assert(h3mb);
TH3D *h3dav2 = (TH3D*)fd->Get(Form("%s/%s/hdjasymm%s%s",cd,ce0,ctp2,ca));
TH3D *h3dbv2 = (TH3D*)fd->Get(Form("%s/%s/hdjmpf%s%s",cd,ce0,ctp2,ca));
TH3D *h3mav2 = (TH3D*)fm->Get(Form("%s/%s/hdjasymm%s%s",cd,ce0,ctp2,ca));
TH3D *h3mbv2 = (TH3D*)fm->Get(Form("%s/%s/hdjmpf%s%s",cd,ce0,ctp2,ca));
assert(h3dav2);
assert(h3dbv2);
assert(h3mav2);
assert(h3mbv2);
TH3D *h3dav3 = (TH3D*)fd->Get(Form("%s/%s/hdjasymm%s%s",cd,ce0,ctp3,ca));
TH3D *h3dbv3 = (TH3D*)fd->Get(Form("%s/%s/hdjmpf%s%s",cd,ce0,ctp3,ca));
TH3D *h3mav3 = (TH3D*)fm->Get(Form("%s/%s/hdjasymm%s%s",cd,ce0,ctp3,ca));
TH3D *h3mbv3 = (TH3D*)fm->Get(Form("%s/%s/hdjmpf%s%s",cd,ce0,ctp3,ca));
assert(h3dav3);
assert(h3dbv3);
assert(h3mav3);
assert(h3mbv3);
// https://github.com/miquork/jetphys/blob/chs/fillHistos.C#L1941-L1944
// A = (P-T)/(T+P) => (1+A)*T = (1-A)*P => P/T = (1+A)/(1-A)
// B = (P-T)/((P+T)/2) => (1+B/2)*T = (1-B/2)*P => P/T = (1-B/2)/(1-B/2)
// => Scale B by 0.5 to get JEC 8 TeV paper definition, use A formula later
//
// B*pTave = METvec . unitVecTag = (-Pvec - Tvec) . unitTvec
// = -|P|*cos(pi) - |T|*cos(0) = P-T
// for DeltaPhi=pi, but otherwise P*(1-delta) - T
// First, look at mean and pT,ave spectrum
int ymin = h3da->GetYaxis()->FindBin(y1);
int ymax = h3da->GetYaxis()->FindBin(y2-1e-4);
h3da->Sumw2();
h3da->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2da = (TH2D*)h3da->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2da->Sumw2();
h2da->SetName("h2da");
TProfile *p1da = h2da->ProfileX("p1da",1,-1,"e");
//if (stp=="tp") p1da->Scale(0.5);
//p1da->Scale(0.5);
TH1D *h1da = p1da->ProjectionX("h1da", "e");
TH1D *hnda = h2da->ProjectionX("hnda",0,-1,"e");
//
h3ma->Sumw2();
h3ma->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2ma = (TH2D*)h3ma->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2ma->Sumw2();
h2ma->SetName("h2ma");
TProfile *p1ma = h2ma->ProfileX("p1ma",1,-1,"e");
//if (stp=="tp") p1ma->Scale(0.5);
//p1ma->Scale(0.5);
TH1D *h1ma = p1ma->ProjectionX("h1ma", "e");
TH1D *hnma = h2ma->ProjectionX("hnma",0,-1,"e");
h3db->Sumw2();
h3db->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2db = (TH2D*)h3db->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2db->Sumw2();
h2db->SetName("h2db");
TProfile *p1db = h2db->ProfileX("p1db",1,-1,"e");
//p1db->Scale(0.5); // Fixed for cmsweek
TH1D *h1db = p1db->ProjectionX("h1db", "e");
//
h3mb->Sumw2();
h3mb->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2mb = (TH2D*)h3mb->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2mb->Sumw2();
h2mb->SetName("h2mb");
TProfile *p1mb = h2mb->ProfileX("p1mb",1,-1,"e");
//p1mb->Scale(0.5); // Fixed for cmsweek
TH1D *h1mb = p1mb->ProjectionX("h1dmb", "e");
TH1D *h1ra = p1da->ProjectionX("h1ra","e");
cleanPair(h1da, h1ma);
h1ra->Add(h1da, h1ma, 1, -1);
TH1D *h1rb = p1db->ProjectionX("h1rb","e");
cleanPair(h1db, h1mb);
h1rb->Add(h1db, h1mb, 1, -1);
// Repeat for v2 DB and MPF
h3dav2->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2dav2 = (TH2D*)h3dav2->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2dav2->Sumw2();
h2dav2->SetName("h2dav2");
TProfile *p1dav2 = h2dav2->ProfileX("p1dav2",1,-1,"e");
//if (stp2=="tp") p1dav2->Scale(0.5);
//p1dav2->Scale(0.5);
TH1D *h1dav2 = p1dav2->ProjectionX("h1dav2", "e");
//
h3mav2->Sumw2();
h3mav2->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2mav2 = (TH2D*)h3mav2->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2mav2->Sumw2();
h2mav2->SetName("h2mav2");
TProfile *p1mav2 = h2mav2->ProfileX("p1mav2",1,-1,"e");
//if (stp2=="tp") p1mav2->Scale(0.5);
//p1mav2->Scale(0.5);
TH1D *h1mav2 = p1mav2->ProjectionX("h1mav2", "e");
h3dbv2->Sumw2();
h3dbv2->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2dbv2 = (TH2D*)h3dbv2->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2dbv2->Sumw2();
h2dbv2->SetName("h2dbv2");
TProfile *p1dbv2 = h2dbv2->ProfileX("p1dbv2",1,-1,"e");
//p1dbv2->Scale(0.5); // Fixed for cmsweek
TH1D *h1dbv2 = p1dbv2->ProjectionX("h1dbv2", "e");
//
h3mbv2->Sumw2();
h3mbv2->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2mbv2 = (TH2D*)h3mbv2->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2mbv2->Sumw2();
h2mbv2->SetName("h2mbv2");
TProfile *p1mbv2 = h2mbv2->ProfileX("p1mbv2",1,-1,"e");
//p1mbv2->Scale(0.5); // Fixed for cmsweek
TH1D *h1mbv2 = p1mbv2->ProjectionX("h1mbv2", "e");
TH1D *h1rav2 = p1dav2->ProjectionX("h1rav2","e");
cleanPair(h1dav2, h1mav2);
h1rav2->Add(h1dav2, h1mav2, 1, -1);
TH1D *h1rbv2 = p1dbv2->ProjectionX("h1rbv2","e");
cleanPair(h1dbv2, h1mbv2);
h1rbv2->Add(h1dbv2, h1mbv2, 1, -1);
// Repeat for v3 DB and MPF
h3dav3->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2dav3 = (TH2D*)h3dav3->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2dav3->Sumw2();
h2dav3->SetName("h2dav3");
TProfile *p1dav3 = h2dav3->ProfileX("p1dav3",1,-1,"e");
//if (stp3=="tp") p1dav3->Scale(0.5);
//p1dav3->Scale(0.5);
TH1D *h1dav3 = p1dav3->ProjectionX("h1dav3", "e");
//
h3mav3->Sumw2();
h3mav3->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2mav3 = (TH2D*)h3mav3->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2mav3->Sumw2();
h2mav3->SetName("h2mav3");
TProfile *p1mav3 = h2mav3->ProfileX("p1mav3",1,-1,"e");
//if (stp3=="tp") p1mav3->Scale(0.5);
//p1mav3->Scale(0.5);
TH1D *h1mav3 = p1mav3->ProjectionX("h1mav3", "e");
h3dbv3->Sumw2();
h3dbv3->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2dbv3 = (TH2D*)h3dbv3->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2dbv3->Sumw2();
h2dbv3->SetName("h2dbv3");
TProfile *p1dbv3 = h2dbv3->ProfileX("p1dbv3",1,-1,"e");
//p1dbv3->Scale(0.5); // Fixed for cmsweek
TH1D *h1dbv3 = p1dbv3->ProjectionX("h1dbv3", "e");
//
h3mbv3->Sumw2();
h3mbv3->GetYaxis()->SetRange(ymin,ymax);
TH2D *h2mbv3 = (TH2D*)h3mbv3->Project3D("zxe"); // X=pT,ave; Y=Asymmetry
h2mbv3->Sumw2();
h2mbv3->SetName("h2mbv3");
TProfile *p1mbv3 = h2mbv3->ProfileX("p1mbv3",1,-1,"e");
//p1mbv3->Scale(0.5); // Fixed for cmsweek
TH1D *h1mbv3 = p1mbv3->ProjectionX("h1mbv3", "e");
TH1D *h1rav3 = p1dav3->ProjectionX("h1rav3","e");
cleanPair(h1dav3, h1mav3);
h1rav3->Add(h1dav3, h1mav3, 1, -1);
TH1D *h1rbv3 = p1dbv3->ProjectionX("h1rbv3","e");
cleanPair(h1dbv3, h1mbv3);
h1rbv3->Add(h1dbv3, h1mbv3, 1, -1);
// Second, look at RMS / Gaussian sigma
TF1 *fga = new TF1("fga","gaus",-1,1);
TF1 *fgb = new TF1("fgb","gaus",-1,1);
// fit range [mean-ksigma*sigma, mean+ksigma*sigma]
const double ksigma = 1.5;
TH1D *h1das = p1da->ProjectionX("h1das","e"); h1das->Clear();
TH1D *h1mas = p1ma->ProjectionX("h1mas","e"); h1mas->Clear();
TH1D *h1dbs = p1db->ProjectionX("h1dbs","e"); h1dbs->Clear();
TH1D *h1mbs = p1mb->ProjectionX("h1mbs","e"); h1mbs->Clear();
for (int i = 1; i != h1das->GetNbinsX()+1; ++i) {
TH1D *htmpa = h2da->ProjectionY("htmpa",i,i,"e");
TH1D *htmpb = h2db->ProjectionY("htmpb",i,i,"e");
double rmsa = truncRMS(htmpa);
double rmsb = truncRMS(htmpb);
fga->SetRange(htmpa->GetMean() - rmsa*ksigma,
htmpa->GetMean() + rmsa*ksigma);
fgb->SetRange(htmpb->GetMean() - rmsb*ksigma,
htmpb->GetMean() + rmsb*ksigma);
fga->SetParameters(htmpa->Integral(),htmpa->GetMean(),htmpa->GetRMS());
fgb->SetParameters(htmpb->Integral(),htmpb->GetMean(),htmpb->GetRMS());
htmpa->Fit(fga,"QRN");
htmpb->Fit(fgb,"QRN");
if (htmpa->Integral()!=0.) {
h1das->SetBinContent(i, rmsa);
h1das->SetBinError(i, htmpa->GetRMS()/sqrt(htmpa->GetEffectiveEntries()));
h1dbs->SetBinContent(i, rmsb);
h1dbs->SetBinError(i, htmpb->GetRMS()/sqrt(htmpb->GetEffectiveEntries()));
//h1das->SetBinContent(i, (stp=="tp" ? 0.5 : 1)*rmsa);
//h1das->SetBinError(i, (stp=="tp" ? 0.5 : 1)*htmpa->GetRMS()/sqrt(htmpa->GetEffectiveEntries()));
//h1dbs->SetBinContent(i, 0.5*rmsb);
//h1dbs->SetBinError(i, 0.5*htmpb->GetRMS()/sqrt(htmpb->GetEffectiveEntries()));
}
delete htmpa;
delete htmpb;
// Use data fit as starting value for MC
htmpa = h2ma->ProjectionY("htmpa",i,i,"e");
htmpb = h2mb->ProjectionY("htmpb",i,i,"e");
rmsa = truncRMS(htmpa);
rmsb = truncRMS(htmpb);
fga->SetRange(htmpa->GetMean() - rmsa*ksigma,
htmpa->GetMean() + rmsa*ksigma);
fgb->SetRange(htmpb->GetMean() - rmsb*ksigma,
htmpb->GetMean() + rmsb*ksigma);
htmpa->Fit(fga,"QRN");
htmpb->Fit(fgb,"QRN");
if (htmpa->Integral()!=0.) {
h1mas->SetBinContent(i, rmsa);
h1mas->SetBinError(i, htmpa->GetRMS()/sqrt(htmpa->GetEffectiveEntries()));
h1mbs->SetBinContent(i, rmsb);
h1mbs->SetBinError(i, htmpb->GetRMS()/sqrt(htmpb->GetEffectiveEntries()));
//h1mas->SetBinContent(i, (stp=="tp" ? 0.5 : 1)*rmsa);
//h1mas->SetBinError(i, (stp=="tp" ? 0.5 : 1)*htmpa->GetRMS()/sqrt(htmpa->GetEffectiveEntries()));
//h1mbs->SetBinContent(i, 0.5*rmsb);
//h1mbs->SetBinError(i, 0.5*htmpb->GetRMS()/sqrt(htmpb->GetEffectiveEntries()));
}
delete htmpa;
delete htmpb;
}
curdir->cd();
TH1D *hup = new TH1D("hup",";p_{T,ave} (GeV);#LTAsymmetry#GT",
1970,30,2000);
hup->SetMaximum(+0.205);
hup->SetMinimum(-0.155);
TH1D *hdw = new TH1D("hdw",";p_{T,ave} (GeV);Data-MC",
1930,30,2000);
hdw->SetMaximum(+0.105);
hdw->SetMinimum(-0.105);
hdw->GetXaxis()->SetMoreLogLabels();
hdw->GetXaxis()->SetNoExponent();
if (stp=="tp") hdw->SetXTitle("p_{T,tag}");
//lumi_13TeV = "RunG";
lumi_13TeV = Form("Run%s 03FebV3, 7.5 fb^{-1}",ct); // string() if autoclean
//lumi_13TeV = "RunH 03FebV0, 8.8 fb^{-1}";
TCanvas *c2 = tdrDiCanvas("c2",hup,hdw,4,11);
c2->cd(1);
gPad->SetLogx();
// error bands from pT,tag, pT,probe binning
TH1D *h1dae = p1dav2->ProjectionX("h1dae");
TH1D *h1dbe = p1dbv2->ProjectionX("h1dbe");
for (int i = 1; i != h1dae->GetNbinsX()+1; ++i) {
if (p1dav2->GetBinContent(i)!=0 && p1dav2->GetBinError(i)!=0) {
double aup = max(h1dav3->GetBinContent(i),
h1mav3->GetBinContent(i));
double adw = min(h1dav2->GetBinContent(i),
h1mav2->GetBinContent(i));
double bup = max(h1dbv3->GetBinContent(i),
h1mbv3->GetBinContent(i));
double bdw = min(h1dbv2->GetBinContent(i),
h1mbv2->GetBinContent(i));
h1dae->SetBinContent(i, 0.5*(aup+adw));
h1dae->SetBinError(i, 0.5*(aup-adw));
h1dbe->SetBinContent(i, 0.5*(bup+bdw));
h1dbe->SetBinError(i, 0.5*(bup-bdw));
}
}
h1dae->GetXaxis()->SetRangeUser(xmin,xmax);
h1dbe->GetXaxis()->SetRangeUser(xmin,xmax);
tdrDraw(h1dae,"E3",kNone,kBlue-9,kSolid,-1,1001,kBlue-9);
h1dae->SetFillColorAlpha(kBlue-9, 0.35); // 35% transparent
tdrDraw(h1dbe,"E3",kNone,kRed-9,kSolid,-1,1001,kRed-9);
h1dbe->SetFillColorAlpha(kRed-9, 0.35); // 35% transparent
// pT,tag
h1dav2->GetXaxis()->SetRangeUser(xmin,xmax);
h1mav2->GetXaxis()->SetRangeUser(xmin,xmax);
h1dbv2->GetXaxis()->SetRangeUser(xmin,xmax);
h1mbv2->GetXaxis()->SetRangeUser(xmin,xmax);
tdrDraw(h1dav2,"HISTPL",kFullDiamond,kBlue-9,kSolid,-1,kNone);
tdrDraw(h1mav2,"HISTPL",kOpenDiamond,kBlue-9,kSolid,-1,kNone);
tdrDraw(h1dbv2,"HISTPL",kFullDiamond,kRed-9,kSolid,-1,kNone);
tdrDraw(h1mbv2,"HISTPL",kOpenDiamond,kRed-9,kSolid,-1,kNone);
h1dav2->SetMarkerSize(0.7);
h1mav2->SetMarkerSize(0.7);
h1dbv2->SetMarkerSize(0.7);
h1mbv2->SetMarkerSize(0.7);
// pT,probe
h1dav3->GetXaxis()->SetRangeUser(xmin,xmax);
h1mav3->GetXaxis()->SetRangeUser(xmin,xmax);
h1dbv3->GetXaxis()->SetRangeUser(xmin,xmax);
h1mbv3->GetXaxis()->SetRangeUser(xmin,xmax);
tdrDraw(h1dav3,"HISTPL",kFullDiamond,kAzure-9,kSolid,-1,kNone);
tdrDraw(h1mav3,"HISTPL",kOpenDiamond,kAzure-9,kSolid,-1,kNone);
tdrDraw(h1dbv3,"HISTPL",kFullDiamond,kOrange-9,kSolid,-1,kNone);
tdrDraw(h1mbv3,"HISTPL",kOpenDiamond,kOrange-9,kSolid,-1,kNone);
h1dav3->SetMarkerSize(0.7);
h1mav3->SetMarkerSize(0.7);
h1dbv3->SetMarkerSize(0.7);
h1mbv3->SetMarkerSize(0.7);
// pT,ave
h1da->GetXaxis()->SetRangeUser(xmin,xmax);
h1ma->GetXaxis()->SetRangeUser(xmin,xmax);
h1db->GetXaxis()->SetRangeUser(xmin,xmax);
h1mb->GetXaxis()->SetRangeUser(xmin,xmax);
tdrDraw(h1db,"P",kFullSquare,kRed);
tdrDraw(h1mb,"P",kOpenSquare,kRed);
tdrDraw(h1da,"P",kFullCircle,kBlue);
tdrDraw(h1ma,"P",kOpenCircle,kBlue);
// Add Z+jet
vector<string> zs;
zs.push_back("Data_MPF");
zs.push_back("MC_MPF");
zs.push_back("Ratio_MPF");
zs.push_back("Data_PtBal");
zs.push_back("MC_PtBal");
zs.push_back("Ratio_PtBal");
map<string, TGraphErrors*> gzs;
for (int iz = 0; iz != zs.size(); ++iz) {
string sz0 = Form("%s_CHS_a%d_eta_%04.0f_%04.0f_L1L2L3",
zs[iz].c_str(), int(alphamax*100+0.5), 1000.*0,1000.*1.3);
cout << sz0 << endl << flush;
TGraphErrors *gz0 = (TGraphErrors*)fz->Get(sz0.c_str());
assert(gz0);
string sz = Form("%s_CHS_a%d_eta_%04.0f_%04.0f_L1L2L3",
zs[iz].c_str(), int(alphamax*100+0.5), 1000.*y1,1000.*y2);
cout << sz << endl << flush;
TGraphErrors *gz = (TGraphErrors*)fz->Get(sz.c_str());
assert(gz);
for (int i = 0; i != gz->GetN(); ++i) {
double x = gz->GetX()[i];
double y = gz->GetY()[i];
int k(-1);
for (int j = 0; j != gz->GetN(); ++j) {
if (fabs(gz->GetX()[j] - x) < 0.03*x) {
assert(k==-1);
k = j;
}
} // for j
assert(k!=-1);
double y0 = gz0->GetY()[i];
gz->SetPoint(i, x, y / y0 - 1);
} // for i
gzs[zs[iz]] = gz;
} // for iz
// Z+jet
tdrDraw(gzs["Data_MPF"],"Pz",kFullSquare,kGreen+3);
gzs["Data_MPF"]->SetMarkerSize(0.7);
tdrDraw(gzs["MC_MPF"],"Pz",kOpenSquare,kGreen+3);
gzs["MC_MPF"]->SetMarkerSize(0.7);
tdrDraw(gzs["Data_PtBal"],"Pz",kFullCircle,kGreen+2);
gzs["Data_PtBal"]->SetMarkerSize(0.7);
tdrDraw(gzs["MC_PtBal"],"Pz",kOpenCircle,kGreen+2);
gzs["MC_PtBal"]->SetMarkerSize(0.7);
TF1 *f1da = new TF1("f1da","[0]+[1]*log(x)+[2]*log(x)*log(x)",fitxmin,xmax);
f1da->SetParameters(0,0.01,0.0001);
h1da->Fit(f1da,"QRN");
f1da->SetLineColor(kBlue);
f1da->Draw("SAME");
TF1 *f1ma = new TF1("f1ma","[0]+[1]*log(x)+[2]*log(x)*log(x)",fitxmin,xmax);
f1ma->SetParameters(0,0.01,0.0001);
h1ma->Fit(f1ma,"QRN");
f1ma->SetLineColor(kBlue);
f1ma->SetLineStyle(kDashed);
f1ma->Draw("SAME");
//
TF1 *f1db = new TF1("f1db","[0]+[1]*log(x)+[2]*log(x)*log(x)",fitxmin,xmax);
f1db->SetParameters(0,0.01,0.0001);
h1db->Fit(f1db,"QRN");
f1db->SetLineColor(kRed);
f1db->Draw("SAME");
TF1 *f1mb = new TF1("f1mb","[0]+[1]*log(x)+[2]*log(x)*log(x)",fitxmin,xmax);
f1mb->SetParameters(0,0.01,0.0001);
h1mb->Fit(f1mb,"QRN");
f1mb->SetLineColor(kRed);
f1mb->SetLineStyle(kDashed);
f1mb->Draw("SAME");
// Check estimated resolution bias
//TF1 *fddpt = new TF1("fddpt",deltaPt,fitxmin,xmax,3);
//fddpt->SetParameters(0.65,0.5*(y1+y2), 1);//0.0, 2.5, 1);
//fddpt->SetLineStyle(kDotted);
//fddpt->SetLineColor(kGreen+2);
//fddpt->SetLineWidth(2);
//fddpt->Draw("SAME");
//TF1 *fmdpt = new TF1("fmdpt",deltaPt,fitxmin,xmax,3);
//fmdpt->SetParameters(0.65, 0.5*(y1+y2), 0);//0.0, 2.5, 0);
//fmdpt->SetLineStyle(kDotted);
//fmdpt->SetLineColor(kMagenta+1);
//fmdpt->SetLineWidth(2);
//fmdpt->Draw("SAME");
TLatex *tex = new TLatex();
tex->SetTextSize(0.045);
tex->SetNDC();
tex->DrawLatex(0.40,0.85,ce);
tex->DrawLatex(0.40,0.75,Form("#alpha < %1.2f",alphamax));
if (stp=="tp") tex->DrawLatex(0.60,0.75,"(tp)");
TLegend *leg2up = tdrLeg(0.7,0.66,0.9,0.88);
leg2up->AddEntry(h1db,"#LTB#GT_{data}","PL");
leg2up->AddEntry(h1mb,"#LTB#GT_{MC}","PL");
leg2up->AddEntry(h1da,"#LTA#GT_{data}","PL");
leg2up->AddEntry(h1ma,"#LTA#GT_{MC}","PL");
TLegend *leg2up2 = tdrLeg(0.7,0.06,0.9,0.28);
leg2up2->AddEntry(h1dbv2,"#LTB#GT_{tag}","PL");
leg2up2->AddEntry(h1dbv3,"#LTB#GT_{probe}","PL");
leg2up2->AddEntry(h1dav2,"#LTA#GT_{tag}","PL");
leg2up2->AddEntry(h1dav3,"#LTA#GT_{probe}","PL");
c2->cd(2);
gPad->SetLogx();
// error bands from pT,tag, pT,probe binning
TH1D *h1rae = (TH1D*) h1rav2->Clone("h1rae");
TH1D *h1rbe = (TH1D*) h1rbv2->Clone("h1rbe");
for (int i = 1; i != h1rae->GetNbinsX()+1; ++i) {
if (h1rav2->GetBinContent(i)!=0 && h1rav2->GetBinError(i)!=0) {