-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdrawRunHistos.C
executable file
·2505 lines (2114 loc) · 77.3 KB
/
drawRunHistos.C
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
// Purpose: Draw reports of trigger rates and prescales by run
// Author: [email protected]
// Created: June 5, 2010
// Updated: June 5, 2010
#include "TFile.h"
#include "TDirectory.h"
#include "TList.h"
#include "TKey.h"
#include "TH1D.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TLatex.h"
#include "TLegend.h"
#include "TF1.h"
#include "TGraphErrors.h"
#include "TMultiGraph.h"
#include "TLine.h"
#include "TROOT.h"
#include "TEllipse.h"
#include "TArrow.h"
#include "TMath.h"
#include "TMinuit.h"
#include "TMatrixD.h"
#include "TMatrixDSym.h"
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <map>
#include "tools.h"
#include "tdrstyle_mod18.C"
#include "settings.h"
using namespace std;
// ranges for drawing
//#include "settings.h"
// for correcting jet rates for PU smearing, set _npv
#include "ptresolution.h"
// Ansatz Kernel
int cnt_a = 0;
Double_t smearedAnsatzKernel(Double_t *x, Double_t *p) {
if (++cnt_a%1000000==0) cout << "." << flush;
const double pt = x[0]; // true pT
const double ptmeas = p[0]; // measured pT
const double eta = p[1]; // rapidity
double res = res = ptresolution(pt, eta+1e-3) * pt; // PF
const double s = TMath::Gaus(ptmeas, pt, res, kTRUE);
const double f = p[2] * exp(p[3]/pt) * pow(pt, p[4])
* pow(1 - pt*cosh(eta) / 4000., p[5]);
return (f * s);
}
// Smeared Ansatz
double _epsilon = 1e-12;
TF1 *_kernel = 0; // global variable, not pretty but works
Double_t smearedAnsatz(Double_t *x, Double_t *p) {
if (!_kernel) _kernel = new TF1("_kernel",smearedAnsatzKernel,1.,1000.,6);
const double pt = x[0];
const double eta = p[0];
double res = ptresolution(pt, eta+1e-3) * pt;
const double sigma = min(res, 0.30);
double ptmin = pt / (1. + 4.*sigma); // xmin*(1+4*sigma)=x
ptmin = max(1.,ptmin); // safety check
double ptmax = pt / (1. - 2.*sigma); // xmax*(1-2*sigma)=x
ptmax = min(4000./cosh(eta),ptmax); // safety check
const double par[6] = {pt, eta, p[1], p[2], p[3], p[4]};
_kernel->SetParameters(&par[0]);
//if (p[5]>0 && p[5]<4000./cosh(eta)) ptmin = p[5]; // for smearing matrix
//if (p[6]>0 && p[6]<4000./cosh(eta)) ptmax = p[6]; // for smearing matrix
return ( _kernel->Integral(ptmin, ptmax, _epsilon) );
}
double unfold(double pt, double eta, double npv) {
// ansatz parameters
const int npar = 5;
double p[npar] = {0.00, 1.657e14, -17.86, -5.055, 9.480};
//_npv = npv;
double fs = smearedAnsatz(&pt, &p[0]);
double f = p[1] * exp(p[2]/pt) * pow(pt, p[3])
* pow(1 - pt*cosh(p[0]) / 4000., p[4]);
if (!(fs>0 && f>0)) {
cout << "fs: " << fs << ", f: " << f << endl;
assert(false);
}
return (f/fs);
}
void drawRunHistos(string type) {
TDirectory *curdir = gDirectory;
setTDRStyle();
gStyle->SetOptStat(0);
TFile *fin = new TFile(Form("output-%s-1.root",type.c_str()),"READ");
assert(fin && !fin->IsZombie());
ofstream fout("drawRunHistos.txt",ios::out);
vector<string> etas;
//etas.push_back("");
etas.push_back("Barrel");
//etas.push_back("Transition");
//etas.push_back("Endcap");
//etas.push_back("Endcap1");
//etas.push_back("Endcap2");
vector<string> types;
types.push_back("PF");
//types.push_back("Calo");
vector<string> trigs;
trigs.push_back("jt40");
trigs.push_back("jt60");
trigs.push_back("jt80");
trigs.push_back("jt140");
trigs.push_back("jt200");
trigs.push_back("jt260");
trigs.push_back("jt320");
trigs.push_back("jt400");
trigs.push_back("jt450");
map<string, double> thr;
thr["jt40"] = 49.;
thr["jt60"] = 74.;
thr["jt80"] = 97.;
thr["jt140"] = 174.;
thr["jt200"] = 245.;
thr["jt260"] = 330.;
thr["jt320"] = 430;
thr["jt400"] = 507.;
thr["jt450"] = 548.;
map<string, double> meanpt;
// from Eta_0.0-1.3 hselpt (upper limit also)
meanpt["jt40"] = 60;
meanpt["jt60"] = 80;
meanpt["jt80"] = 120;
meanpt["jt140"] = 210;
meanpt["jt200"] = 290;
meanpt["jt260"] = 370;
meanpt["jt320"] = 460;
meanpt["jt400"] = 530;
meanpt["jt450"] = 1100;
map<string, double> scale0;
scale0["jt40"] = 8.269e+06;
scale0["jt60"] = 8.269e+06;
scale0["jt80"] = 3.391e+05;
scale0["jt140"] = 1.535e+04;
scale0["jt200"] = 3229;
scale0["jt260"] = 1193;
scale0["jt320"] = 0.1*462.4;
scale0["jt400"] = 0.1*462.4;
scale0["jt450"] = 0.1*462.4;
///////////////////////////////////////////////////
map<string, map<string, map<string, double> > > scale;
if (string(jp::algo)=="AK4") {
/*9fb*/
scale["jt40"]["Barrel"]["PF"] = 5e7;
scale["jt60"]["Barrel"]["PF"] = 5e7;
scale["jt80"]["Barrel"]["PF"] = 2e7;
scale["jt140"]["Barrel"]["PF"] = 1e6;
scale["jt200"]["Barrel"]["PF"] = 1e6;
scale["jt260"]["Barrel"]["PF"] = 1e5;
scale["jt320"]["Barrel"]["PF"] = 1e5;
scale["jt400"]["Barrel"]["PF"] = 5e4;
scale["jt450"]["Barrel"]["PF"] = 1e4;
scale["jt40"]["Transition"]["PF"] = 3.918e+06;
scale["jt60"]["Transition"]["PF"] = 3.918e+06;
scale["jt80"]["Transition"]["PF"] = 1.748e+05;
scale["jt140"]["Transition"]["PF"] = 7379;
scale["jt200"]["Transition"]["PF"] = 1415;
scale["jt260"]["Transition"]["PF"] = 481.1;
scale["jt320"]["Transition"]["PF"] = 166;
scale["jt400"]["Transition"]["PF"] = 55.3;
scale["jt450"]["Transition"]["PF"] = 55.3;
scale["jt40"]["Endcap"]["PF"] = 1.948e+06;
scale["jt60"]["Endcap"]["PF"] = 1.948e+06;
scale["jt80"]["Endcap"]["PF"] = 6.93e+04;
scale["jt140"]["Endcap"]["PF"] = 1579;
scale["jt200"]["Endcap"]["PF"] = 162.9;
scale["jt260"]["Endcap"]["PF"] = 33.11;
scale["jt320"]["Endcap"]["PF"] = 6.235;
scale["jt400"]["Endcap"]["PF"] = 0.8653;
scale["jt450"]["Endcap"]["PF"] = 0.8653;
}
if (string(jp::algo)=="AK7") {
scale["jt40"]["Barrel"]["PF"] = 2.424e+06;
scale["jt60"]["Barrel"]["PF"] = 2.424e+06;
scale["jt80"]["Barrel"]["PF"] = 1.681e+05;
scale["jt140"]["Barrel"]["PF"] = 1.535e+04;
scale["jt200"]["Barrel"]["PF"] = 3229;
scale["jt260"]["Barrel"]["PF"] = 744.9;
scale["jt320"]["Barrel"]["PF"] = 181.4;
scale["jt400"]["Barrel"]["PF"] = 2.492;
scale["jt450"]["Barrel"]["PF"] = 2.492;
scale["jt40"]["Transition"]["PF"] = 6.453e+06;
scale["jt60"]["Transition"]["PF"] = 6.453e+06;
scale["jt80"]["Transition"]["PF"] = 2.323e+05;
scale["jt140"]["Transition"]["PF"] = 9107;
scale["jt200"]["Transition"]["PF"] = 1706;
scale["jt260"]["Transition"]["PF"] = 569.7;
scale["jt320"]["Transition"]["PF"] = 194.8;
scale["jt400"]["Transition"]["PF"] = 64.02;
scale["jt450"]["Transition"]["PF"] = 64.02;
scale["jt40"]["Endcap"]["PF"] = 2.884e+06;
scale["jt60"]["Endcap"]["PF"] = 2.884e+06;
scale["jt80"]["Endcap"]["PF"] = 8.321e+04;
scale["jt140"]["Endcap"]["PF"] = 1790;
scale["jt200"]["Endcap"]["PF"] = 183;
scale["jt260"]["Endcap"]["PF"] = 37.78;
scale["jt320"]["Endcap"]["PF"] = 6.933;
scale["jt400"]["Endcap"]["PF"] = 0.7181;
scale["jt450"]["Endcap"]["PF"] = 0.7181;
scale["jt40"]["Endcap1"]["PF"] = 1.753e+06;
scale["jt60"]["Endcap1"]["PF"] = 1.753e+06;
scale["jt80"]["Endcap1"]["PF"] = 5.691e+04;
scale["jt140"]["Endcap1"]["PF"] = 1487;
scale["jt200"]["Endcap1"]["PF"] = 168.3;
scale["jt260"]["Endcap1"]["PF"] = 36.51;
scale["jt320"]["Endcap1"]["PF"] = 6.858;
scale["jt400"]["Endcap1"]["PF"] = 0.7181;
scale["jt450"]["Endcap1"]["PF"] = 0.7181;
scale["jt40"]["Endcap2"]["PF"] = 1.117e+06;
scale["jt60"]["Endcap2"]["PF"] = 1.117e+06;
scale["jt80"]["Endcap2"]["PF"] = 2.57e+04;
scale["jt140"]["Endcap2"]["PF"] = 263.6;
scale["jt200"]["Endcap2"]["PF"] = 12.96;
scale["jt260"]["Endcap2"]["PF"] = 0.888;
scale["jt320"]["Endcap2"]["PF"] = 0.06549;
scale["jt400"]["Endcap2"]["PF"] = 0.01417;
scale["jt450"]["Endcap2"]["PF"] = 0.01417;
}
/////////////////////////////////////////////////
map<string, string> lab;
lab["jt40"] = "HLT_Jet40";
lab["jt60"] = "HLT_Jet60";
lab["jt80"] = "HLT_Jet80";
lab["jt140"] = "HLT_Jet140";
lab["jt200"] = "HLT_Jet200";
lab["jt260"] = "HLT_Jet260";
lab["jt320"] = "HLT_Jet320";
lab["jt400"] = "HLT_Jet400";
lab["jt450"] = "HLT_Jet450";
TCanvas *c1c = new TCanvas("c1c","c1c",600,600);
TCanvas *c1d = new TCanvas("c1d","c1d",600,600);
TCanvas *c1 = new TCanvas("c1","c1",1200,300);
c1->SetLogy();
// Adapt to very wide format
c1->SetLeftMargin(0.05);
c1->SetRightMargin(0.005);
TH1D *runs = (TH1D*)fin->Get(Form("Runs%s/runs",etas[0].c_str()));
assert(runs);
int nruns = runs->GetNbinsX();
float lumi;
assert(sscanf(runs->GetTitle(),"runs %f pb-1",&lumi)==1);
TH1D *h = new TH1D("h","",nruns,-0.5,nruns-0.5);
h->SetMinimum(1e-2);
h->SetMaximum(1e2);
h->GetYaxis()->SetTitle("Trigger rate per run");
h->GetYaxis()->SetTitleOffset(0.4);
vector<int> vrun(nruns);
for (int i = 1; i != nruns+1; ++i) {
//if (i%2==1) // Reduce overlap on run numbers
if (i%3==1) // Reduce overlap on run numbers
h->GetXaxis()->SetBinLabel(i, Form("%d",int(runs->GetBinContent(i)+0.5)));
vrun[i-1] = runs->GetBinContent(i);
if (i>1) assert(vrun[i-2]<vrun[i-1] || vrun[i-1]==0);
} // for i
for (int i = nruns+1; i < h->GetNbinsX()+1; ++i) {
h->GetXaxis()->SetBinLabel(i, " ");
}
int iCa = TMath::BinarySearch(nruns, &vrun[0], 246908); // 2015C first
int iDb = TMath::BinarySearch(nruns, &vrun[0], 260627); // 2015D last
int ifirst = iCa;
int i12b = 0.75*iCa+0.25*iDb;
int i12c = 0.50*iCa+0.50*iDb;
int i12d = 0.25*iCa+0.75*iDb;
int ilast = iDb;
cout << "ifirst = " << ifirst << endl;
cout << "i12b = " << i12b << endl;
cout << "i12c = " << i12c << endl;
cout << "i12d = " << i12d << endl;
cout << "ilast = " << ilast << endl;
map<string, pair<int,int> > ranges;
ranges["jt40"] = pair<int,int>(ifirst,ilast);
ranges["jt60"] = pair<int,int>(ifirst,ilast);
ranges["jt80"] = pair<int,int>(ifirst,ilast);
ranges["jt140"] = pair<int,int>(ifirst,ilast);
ranges["jt200"] = pair<int,int>(ifirst,ilast);
ranges["jt260"] = pair<int,int>(ifirst,ilast);
ranges["jt320"] = pair<int,int>(ifirst,ilast);
ranges["jt400"] = pair<int,int>(ifirst,ilast);
ranges["jt450"] = pair<int,int>(ifirst,ilast);
const int nc = 3;
int tricolor[nc] = {kCyan+1, kYellow+1, kMagenta+1};
const int runbins[] =
{iCa, i12b, i12c, i12d, ilast};
// 20/fb divisions, 572 runs, epoch firsts: 1, 63, 209, 389, (569=0)
//{/*A*/ 0, 31, /*B*/ 63, 111, 160, /*C*/ 209, 269, 329,
// /*D*/ 389, 449, 509, 569};//572};
const int nrunbins = sizeof(runbins)/sizeof(runbins[0])-1;
map<string, int> mcolor;
mcolor["jt40"] = kBlue+1;
mcolor["jt80"] = kGreen+1;
mcolor["jt140"] = kGreen+2;
mcolor["jt200"] = kYellow+2;
mcolor["jt260"] = kRed+1;
mcolor["jt320"] = kRed+2;
mcolor["jt400"] = kBlack;
//cmsPrel(lumi);
TLatex *tjet = new TLatex(0.19,0.19,"Anti-k_{T} R=0.5 PF, |y| < 3.0");
tjet->SetTextSize(0.045);
tjet->SetNDC();
tjet->Draw();
TArrow *arr = new TArrow(10,1.45,10,1.1,0.01);
arr->SetLineColor(kRed);
arr->SetLineWidth(2);
TArrow *arr2 = new TArrow(10,1.25,10,1.1,0.01);
arr2->SetLineColor(kMagenta+2);//kBlue);
arr2->SetLineWidth(2);
map<int, set<string> > mbadruns;
// maps for type, eta, trig, values
map<string, map<string, map<string, pair<double, double> > > > _rate;
map<string, map<string, map<string, pair<double, double> > > > _ratebefore;
map<string, map<string, map<string, pair<double, double> > > > _rateafter;
for (unsigned int itype = 0; itype != types.size(); ++itype) {
for (unsigned int ieta = 0; ieta != etas.size(); ++ieta) {
map<string, pair<double, double> > _norm;
string ttc = types[itype];
const char* tc = ttc.c_str();
string tte = etas[ieta];
const char* te = tte.c_str();
const char *sc = (ttc=="Calo" ? "c" : "");
TMultiGraph *mrun = new TMultiGraph();
vector<TGraphErrors*> vmrun(trigs.size());
c1c->cd();
TH1D *hc = new TH1D("hc",Form(";Run;Normalized rate in %s",te),
nruns,-0.5,nruns+0.5);
hc->SetMinimum(0.8);//tte=="Barrel" ? 0.9 : 0.8);
hc->SetMaximum(1.4);//tte=="Barrel" ? 1.2 : 1.4);
hc->DrawClone("AXIS");
c1d->cd();
hc->SetMaximum(1.2);
hc->DrawClone("AXIS");
c1->cd();
for (unsigned int j = 0; j != trigs.size(); ++j) {
// Load central values
assert(fin->cd(Form("Runs%s",etas[ieta].c_str())));
TDirectory *d = gDirectory;
string tt = trigs[j];
const char* t = tt.c_str();
TH1D *hn = (TH1D*)d->Get(Form("npvgood_%s",t)); assert(hn);
TH1D *r0 = (TH1D*)d->Get(Form("r0_%s%s","",t)); assert(r0); // no Calo
TH1D *r = (TH1D*)d->Get(Form("r_%s%s",sc,t)); assert(r);
// Correct rates for JER vs NPV
for (int i = 1; i != r->GetNbinsX()+1; ++i) {
double eta = 0.;
if (etas[ieta]=="Transition") eta = 1.0;
if (etas[ieta]=="Endcap") eta = 2.0;
if (etas[ieta]=="Endcap1") eta = 2.0;
if (etas[ieta]=="Endcap2") eta = 2.5;
double pt = meanpt[t];
double npv = hn->GetBinContent(i);
double y = r->GetBinContent(i);
double y0 = r0->GetBinContent(i);
_ak7 = (string(jp::algo)=="AK7"); // change PU smearing
double c = 1;//unfold(pt, eta, npv) / unfold(pt, eta, _npv0);
r->SetBinContent(i, c * y);
r0->SetBinContent(i, c * y0);
}
// Clone for marking deviating runs
TH1D *r1 = (TH1D*)r->Clone(Form("r1_%s%s",sc,t));
TH1D *r2 = (TH1D*)r->Clone(Form("r2_%s%s",sc,t));
r0->Scale(1./scale0[t]);//[te][tc]);
r->Scale(1./scale[t][te][tc]);
r1->Scale(1./scale[t][te][tc]);
r2->Scale(1./scale[t][te][tc]);
// Coarse grain vs run
TF1 *fit = new TF1("fit","[0]",0,350);
TGraphErrors *grun = new TGraphErrors(0);//nrunbins);
grun->SetName(Form("grun%s%s_%s",tc,te,t));
for (int irun = 0; irun != nrunbins; ++irun) {
double midrun = 0.5*(runbins[irun]+runbins[irun+1]-1);
double drun = 0.5*(runbins[irun+1]-runbins[irun]);
fit->SetRange(runbins[irun]-0.5, runbins[irun+1]-0.5);
r->Fit(fit,"QRN");
if (fit->GetParError(0)<0.10) {
int n = grun->GetN();
grun->SetPoint(n, midrun, fit->GetParameter(0));
grun->SetPointError(n, drun, fit->GetParError(0));
}
} // for irun
grun->SetMarkerStyle(kOpenCircle);
mrun->Add(grun);
vmrun[j] = grun;
delete fit;
c1c->cd();
if (!(ttc=="PF"
&&(tt=="jt320"||tt=="jt400"))) grun->SetMarkerSize(0);
else grun->SetMarkerSize(1.5);
grun->SetLineColor(mcolor[tt]);
grun->SetMarkerColor(mcolor[tt]);
grun->DrawClone("SAMEPz");
c1d->cd();
if (tt=="jt320") {
grun->DrawClone("SAMEPz");
//TF1 *f1d = new TF1("f1d","[0]",ifirst,its);
TF1 *f1d = new TF1("f1d","[0]",ifirst,i12b);
f1d->SetLineStyle(kDashed);
f1d->SetLineColor(grun->GetLineColor());
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
//f1d->SetRange(i12b,ijump);
f1d->SetRange(i12b,i12c);
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
//f1d->SetRange(ijump,i12c);
f1d->SetRange(i12c,i12d);
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
//f1d->SetRange(i12c,ilast);
f1d->SetRange(i12d,ilast);
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
}
c1->cd();
// Find bins that deviate from average
assert(r1->GetNbinsX()==nruns);
double ymax = 1.;
double ymin = 1.;
for (int k = 1; k != nruns+1; ++k) {
if (r1->GetBinContent(k) > ymax) ymax = r1->GetBinContent(k);
if (r1->GetBinContent(k) < ymin &&
r1->GetBinContent(k) > 0) ymin = r1->GetBinContent(k);
if (fabs(r1->GetBinContent(k)-1) < 3.*r1->GetBinError(k)
|| fabs(r1->GetBinContent(k)-1) < 0.05
) {
if (r->GetBinContent(k)!=0)
r->SetBinContent(k, max(0.51,min(1.49,r->GetBinContent(k))));
r1->SetBinContent(k, 0.);
r1->SetBinError(k, 0.);
}
else {
r->SetBinContent(k, 0.);
r->SetBinError(k, 0.);
if (r1->GetBinContent(k)!=0) {
int run = vrun[k-1];
cout << Form( "Run %d trigger %s rate is %1.3g+/-%1.2g"
" (%1.3g+/-%1.2g) times normal",
run, t,
r1->GetBinContent(k), r1->GetBinError(k),
r0->GetBinContent(k), r0->GetBinError(k)) << endl;
//if (!(string(t)=="mb" && run>137028) &&
//!(string(t)=="jt6u") &&
//!(string(t)=="jt15u" && run<136066) &&
//!(string(t)=="jt30u" && run<136066) &&
//!(string(t)=="jt50u" && run<136066)
//)
//mbadruns[run].insert(t);
}
}
// Get the really low stats out from cluttering the picture
double maxerr = 0.10;
if (r0->GetBinError(k)>maxerr) {
r0->SetBinContent(k, 0.);
r0->SetBinError(k, 0.);
}
if (r->GetBinError(k)>maxerr) {
r->SetBinContent(k, 0.);
r->SetBinError(k, 0.);
}
if (r1->GetBinError(k)>maxerr) {
r1->SetBinContent(k, 0.);
r1->SetBinError(k, 0.);
}
if (r2->GetBinError(k)>maxerr) {
r2->SetBinContent(k, 0.);
r2->SetBinError(k, 0.);
}
} // for k
cout << "ymax = " << ymax << " ymin = " << ymin << endl;
ymax = pow(10.,1+int(log10(ymax)));
ymin = pow(10.,-1+int(log10(ymin)));
cout << "ymax_round = " << ymax << " ymin_round = " << ymin << endl;
h->SetMaximum(ymax);
h->SetMinimum(ymin);
h->GetYaxis()->SetTitle(Form("%s normalized rate",lab[t].c_str()));
TF1 *f = new TF1("f","[0]",-1,nruns);
r->Fit(f,"QRN");
cout << Form("Normalization for %s: %1.4g",t,f->GetParameter(0)) << endl;
delete f;
TLegend *leg = new TLegend(0.73, 0.77, 0.93, 0.92, "", "brNDC");
leg->SetFillStyle(kNone);
leg->SetBorderSize(0);
leg->SetTextSize(0.045);
if (jp::debug) leg->AddEntry(r0,"Jet p_{t}>20 GeV","L");
leg->AddEntry(r,Form("Jet p_{T}>%1.0f GeV (%s)",thr[t],t),"L");
leg->AddEntry(r1,"Flagged runs","PL");
TH1D *haxis = (TH1D*)h->DrawClone("AXIS");
r0->SetLineWidth(2);
if (jp::debug) r0->Draw("SAME");
r->SetLineColor(kBlue);
r->Draw("SAME");
r1->SetLineColor(kRed);
r1->SetMarkerColor(kRed);
r1->DrawClone("SAME");
r1->SetMarkerStyle(kCircle);
r1->Draw("SAME");
leg->Draw();
//tjet->Draw();
tjet->DrawLatex(0.19,0.19,Form("Anti-k_{T} R=%1.1f PF, %s",
string(jp::algo)=="AK4" ? 0.4 : 0.7, te));
//cmsPrel(lumi);
if(jp::pdf) c1->SaveAs(Form("pdf/RunHistos_%s_%s_%s.pdf",tc,te,t));
// Same in linear scale
c1->SetLogy(0);
haxis->SetMaximum(1.5);
haxis->SetMinimum(0.5);
TLine *lup = new TLine(0,1.1,h->GetNbinsX()-1,1.1);
lup->SetLineColor(kGreen+2);
lup->SetLineStyle(kDashed);
lup->Draw();
TLine *lmid = new TLine(0,1,h->GetNbinsX()-1,1);
lmid->SetLineColor(kGreen+2);
lmid->Draw();
TLine *ldw = new TLine(0,0.9,h->GetNbinsX()-1,0.9);
ldw->SetLineColor(kGreen+2);
ldw->SetLineStyle(kDashed);
ldw->Draw();
// Rate before and after tech stop
TF1 *fpol0 = new TF1("fpol0","[0]",0,0.);
fpol0->SetParameter(0, 1.);
//
fpol0->SetRange(ranges[t].first-0.5, ranges[t].second+0.5);
r2->Fit(fpol0,"QRN");
double chi = sqrt(max(1., fpol0->GetChisquare()/fpol0->GetNDF()));
_rate[tc][te][t] =
pair<double, double>(fpol0->GetParameter(0),
chi*fpol0->GetParError(0));
_norm[t] =
pair<double, double>(fpol0->GetParameter(0),
chi*fpol0->GetParError(0));
//
fpol0->SetRange(ranges[t].first-0.5,
//min(ranges[t].second+0.5,its));
ranges[t].second+0.5);
r2->Fit(fpol0,"QRN");
chi = sqrt(max(1., fpol0->GetChisquare()/fpol0->GetNDF()));
_ratebefore[tc][te][t] =
pair<double, double>(fpol0->GetParameter(0),
chi*fpol0->GetParError(0));
fpol0->SetLineColor(kYellow+2);
//if (ranges[t].first<its) fpol0->DrawClone("SAME");
fpol0->DrawClone("SAME");
//
fpol0->SetRange(//max(its,ranges[t].first-0.5),
//min(ranges[t].second+0.5,nruns+0.5));
ranges[t].first-0.5,
ranges[t].second+0.5);
r2->Fit(fpol0,"QRN");
chi = sqrt(max(1., fpol0->GetChisquare()/fpol0->GetNDF()));
_rateafter[tc][te][t] =
pair<double, double>(fpol0->GetParameter(0),
chi*fpol0->GetParError(0));
fpol0->SetLineColor(kRed+1);
//if (ranges[t].second>its) fpol0->DrawClone("SAME");
fpol0->DrawClone("SAME");
int ic = -1;
//
fpol0->SetLineColor(kRed+1);
//fpol0->SetRange(ifirst, its);
fpol0->SetRange(ifirst, i12c);
r2->Fit(fpol0,"QRN");
fpol0->DrawClone("SAME");
//
//fpol0->SetRange(its, ilast);
fpol0->SetRange(i12c, ilast);
r2->Fit(fpol0,"QRN");
fpol0->DrawClone("SAME");
//
// Redraw markers on top
r->Draw("SAME");
r1->Draw("SAME");
//arr2->SetX1(its);
//arr2->SetX2(its);
//arr2->DrawClone();
arr2->SetX1(i12b);
arr2->SetX2(i12b);
arr2->DrawClone();
//arr2->SetX1(ijump);
//arr2->SetX2(ijump);
arr2->SetX1(i12c);
arr2->SetX2(i12c);
arr2->DrawClone();
arr2->SetX1(i12d);
arr2->SetX2(i12d);
arr2->DrawClone();
arr->SetX1(ranges[t].first);
arr->SetX2(ranges[t].first);
arr->DrawClone();
arr->SetX1(ranges[t].second);
arr->SetX2(ranges[t].second);
arr->DrawClone();
c1->Update();
if (jp::pdf) c1->SaveAs(Form("pdf/RunHistos_%s_%s_%s_lin.pdf",tc,te,t));
c1->SetLogy();
} // for j
// Coarse grain vs trigger (and run)
TF1 *fit = new TF1("mfit","[0]",0,350);
TGraphErrors *grun = new TGraphErrors(nrunbins);
for (int irun = 0; irun != nrunbins; ++irun) {
double midrun = 0.5*(runbins[irun]+runbins[irun+1]-1);
double drun = 0.5*(runbins[irun+1]-runbins[irun]);
//fit->SetRange(runbins[irun]+0.5, runbins[irun+1]+0.5);
fit->SetRange(runbins[irun]-0.5, runbins[irun+1]-0.5);
mrun->Fit(fit,"QRN");
double k = sqrt(fit->GetChisquare() / max(1,fit->GetNDF()));
grun->SetPoint(irun, midrun, fit->GetParameter(0));
grun->SetPointError(irun, drun, k*fit->GetParError(0));
} // for irun
c1c->cd();
TLine *lc = new TLine();
double y2 = hc->GetMaximum();
double y1 = hc->GetMinimum();
lc->SetLineStyle(kDashed);
//lc->DrawLine(its,y1,its,y2);
lc->DrawLine(i12b,y1,i12b,y2);
//lc->DrawLine(ijump,y1,ijump,y2);
lc->DrawLine(i12c,y1,i12c,y2);
lc->SetLineStyle(kDotted);
//lc->DrawLine(its,y1,its,y2);
//lc->DrawLine(ijump,y1,ijump,y2);
lc->DrawLine(i12d,y1,i12d,y2);
lc->SetLineStyle(kDotted);
lc->DrawLine(-0.5,1.00,nruns-0.5,1.00);
c1d->cd();
lc->SetLineStyle(kDashed);
//lc->DrawLine(its,y1,its,y2);
lc->DrawLine(i12b,y1,i12b,y2);
//lc->DrawLine(ijump,y1,ijump,y2);
lc->DrawLine(i12c,y1,i12c,y2);
lc->SetLineStyle(kDotted);
//lc->DrawLine(its,y1,its,y2);
//lc->DrawLine(ijump,y1,ijump,y2);
lc->DrawLine(i12d,y1,i12d,y2);
lc->SetLineStyle(kDotted);
lc->DrawLine(-0.5,1.00,nruns-0.5,1.00);
c1c->cd();
lc->SetLineColor(kRed);
lc->DrawLine(-0.5,1.05,nruns-0.5,1.05);
lc->DrawLine(-0.5,0.95,nruns-0.5,0.95);
grun->SetLineWidth(2);
grun->SetMarkerSize(1.5);
grun->SetLineColor(kBlack);
grun->SetMarkerColor(kBlack);
grun->SetMarkerStyle(kFullCircle);
grun->Draw("SAMEP");
bool hb = (tte=="Barrel");
TLatex *tex = new TLatex();
tex->SetTextSize(0.040);
//tex->DrawLatex( 5, 0.82, "2012A");
//tex->DrawLatex(100, 0.82, "2012B");
//tex->DrawLatex(220, 0.82, "2012C");
tex->DrawLatex(ifirst+5, 0.82, "A");
tex->DrawLatex(i12b+5, 0.82, "B");
tex->DrawLatex(i12c+5, 0.82, "C");
tex->DrawLatex(i12d+5, 0.82, "D");
c1d->cd();
grun->Draw("SAMEP");
//tex->DrawLatex( 5, 0.82, "2012A");
//tex->DrawLatex(100, 0.82, "2012B");
//tex->DrawLatex(220, 0.82, "2012C");
tex->DrawLatex(ifirst+5, 0.82, "A");
tex->DrawLatex(i12b+5, 0.82, "B");
tex->DrawLatex(i12c+5, 0.82, "C");
tex->DrawLatex(i12d+5, 0.82, "D");
//TF1 *f1d = new TF1("f1d2","[0]",ifirst,its);
TF1 *f1d = new TF1("f1d2","[0]",ifirst,i12b);
f1d->SetLineStyle(kDashed);
//f1d->SetLineColor(grun->GetLineColor());
f1d->SetLineColor(kMagenta+1);
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
//f1d->SetRange(its,i12b);
f1d->SetRange(i12b,i12c);
f1d->SetLineColor(kYellow+2);
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
//f1d->SetRange(i12b,ijump);
f1d->SetRange(i12c,i12d);
f1d->SetLineColor(kOrange+1);
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
//f1d->SetRange(ijump,i12c);
f1d->SetRange(i12d,ilast);
f1d->SetLineColor(kCyan+1);
grun->Fit(f1d,"QRN");
f1d->DrawClone("SAME");
//f1d->SetRange(i12c,ilast);
//grun->Fit(f1d,"QRN");
//f1d->DrawClone("SAME");
c1c->cd();
TF1 *fera = new TF1(Form("fera_%s",tte.c_str()),"1+[0]/100.",0,500);
fera->SetLineColor(kRed);
fera->SetLineWidth(2);
if (ttc=="PF") {// && tte=="Barrel") {
//cmsPrel(_lumi);
if (tte=="Barrel") tex->DrawLatex(350, 1.35,//hb ? 1.175 : 1.35,
"|#eta_{jet}| < 1.0");
if (tte=="Transition") tex->DrawLatex(350, 1.35,//hb ? 1.175 : 1.35,
"1 < |#eta_{jet}| < 2");
if (tte=="Endcap") tex->DrawLatex(350, 1.35,//1.175 : 1.35,
"2 < |#eta_{jet}| < 3");
if (tte=="Endcap1") tex->DrawLatex(350, 1.35,//1.175 : 1.35,
"2 < |#eta_{jet}| < 2.5");
if (tte=="Endcap2") tex->DrawLatex(350, 1.35,//1.175 : 1.35,
"2.5 < |#eta_{jet}| < 3");
c1d->cd();
//cmsPrel(_lumi);
tex->SetTextSize(0.045);
if (tte=="Barrel") tex->DrawLatex(350, 1.16,"|#eta_{jet}| < 1.0");
if (tte=="Transition") tex->DrawLatex(350, 1.16,"1 < |#eta_{jet}| < 2");
if (tte=="Endcap") tex->DrawLatex(350, 1.16,"2 < |#eta_{jet}| < 3");
if (tte=="Endcap1") tex->DrawLatex(350, 1.16,"2 < |#eta_{jet}| < 2.5");
if (tte=="Endcap2") tex->DrawLatex(350, 1.16,"2.5 < |#eta_{jet}| < 3");
TLegend *legd = new TLegend(0.18,0.80,0.38,0.92,"","brNDC");
legd->SetFillStyle(kNone);
legd->SetBorderSize(0);
legd->SetTextSize(0.040);
legd->AddEntry(grun, "Trigger average", "LP");
legd->AddEntry(vmrun[vmrun.size()-2], "HLT_PFJet320", "LP");
legd->Draw();
c1c->cd();
TLegend *leg = new TLegend(0.18,0.60,0.38,0.92,"","brNDC");
leg->SetFillStyle(kNone);
leg->SetBorderSize(0);
leg->SetTextSize(0.040);
//leg->SetHeader("|#eta_{jet}| < 1.0");
leg->AddEntry(grun, "Trigger average", "LP");
for (unsigned int itrig = 0; itrig != vmrun.size(); ++itrig) {
const char *t = trigs[itrig].c_str();
leg->AddEntry(vmrun[itrig], Form("%s", t), "LP");
if (string(t)=="jt370") {
tex->SetTextSize(0.030);
//fera->SetRange(ifirst, its);
fera->SetRange(ifirst, i12c);
vmrun[itrig]->Fit(fera, "QRN");
fera->DrawClone("SAME");
tex->DrawLatex( 40, hb ? 0.92 : 0.84,
Form("%+1.1f%%", fera->GetParameter(0)));
//fera->SetRange(its, ilast);
fera->SetRange(i12c, ilast);
vmrun[itrig]->Fit(fera, "QRN");
fera->DrawClone("SAME");
tex->DrawLatex(125, hb ? 0.92 : 0.84,
Form("%+1.1f%%", fera->GetParameter(0)));
fera->SetLineWidth(1);
fera->SetRange(ifirst, ilast); // full 2012
vmrun[itrig]->Fit(fera, "QRN");
fera->DrawClone("SAME");
tex->DrawLatex(320, hb ? 1.15 : 1.30,
Form("dL=%+1.1f%%", fera->GetParameter(0)));
tex->SetTextSize(0.040);
}
}
leg->Draw();
hc->GetYaxis()->SetTitle("Normalized inclusive jet rate");
}
if (jp::pdf) c1c->SaveAs(Form("pdf/RunHistos_%s_%s_lin.pdf",tc,te));
if (jp::pdf) c1d->SaveAs(Form("pdf/RunHistos_%s_%s_lin2.pdf",tc,te));
c1->cd();
cout << " Residual trigger rates normalization" << endl;
for (unsigned int j = 0; j != trigs.size(); ++j) {
const string& t = trigs[j];
cout << Form("%s: %1.3f +/- %1.3f\n", t.c_str(),
_norm[t].first, _norm[t].second);
} // for j
cout << " New trigger rate normalization" << endl;
for (unsigned int j = 0; j != trigs.size(); ++j) {
const string& t = trigs[j];
cout << Form("scale[\"%s\"][\"%s\"][\"%s\"] = %1.4g;\n",
t.c_str(),te,tc, scale[t][te][tc]*_norm[t].first);
fout << Form(" scale[\"%s\"][\"%s\"][\"%s\"] = %1.4g;\n",
t.c_str(),te,tc, scale[t][te][tc]*_norm[t].first);
} // for j
fout << endl;
} // for i
} // for itype
vector<vector<TGraphErrors*> > graphs(types.size());
for (unsigned int i = 0; i != graphs.size(); ++i) {
graphs[i].resize(etas.size());
for (unsigned int j = 0; j != graphs[i].size(); ++j) {
graphs[i][j] = new TGraphErrors(0);
}
}
cout << "*******************************" << endl;
cout << "Trigger rate before and after tech stop" << endl;
cout << "Trigger" << endl;
for (unsigned int ieta = 0; ieta != etas.size(); ++ieta) {
cout << " & " << etas[ieta];
}
cout << " \\\\" << endl;
for (unsigned int itrig = 0; itrig != trigs.size(); ++itrig) {
const string& t = trigs[itrig];
cout << t;
for (unsigned int itype = 0; itype != types.size(); ++itype) {
const string& tc = types[itype];
cout << (tc=="CALO" ? " (Calo)" : " (PF)");
for (unsigned int ieta = 0; ieta != etas.size(); ++ieta) {
const string& te = etas[ieta];
pair<double, double> const& af = _rateafter[tc][te][t];
pair<double, double> const& be = _ratebefore[tc][te][t];
double delta = af.first - be.first;
double err = tools::oplus(af.second, be.second);
cout << Form(" & %1.3f $\\pm$ %1.3f", delta, err);
TGraphErrors *g = graphs[itype][ieta]; assert(g);
int n = g->GetN();
g->SetPoint(n, thr[t]*(1+0.01*ieta-0.05*itype), 100.*delta);
g->SetPointError(n, 0., 100.*err);
} // for ieta
cout << " \\\\" << endl;
} // for itype
} // for itrig
{
TCanvas *c2 = new TCanvas("c2","c2",600,600);
c2->SetLogx();
double ptmin = 40;
double ptmax = 600;
TH1D *h = new TH1D("h2",";p_{T} threshold (GeV);"
"Rate change after tech stop (%)",
int(ptmax-ptmin), ptmin, ptmax);
h->GetXaxis()->SetMoreLogLabels();
h->GetXaxis()->SetNoExponent();
h->SetMinimum(-30+0.0001);
h->SetMaximum(+30-0.0001);
h->Draw("AXIS");
TLine *l = new TLine(ptmin, 0., ptmax, 0.);
l->SetLineStyle(kDashed);
l->Draw();
TLegend *leg = new TLegend(0.2,0.92-0.05*etas.size(),0.4,0.92,"","brNDC");
leg->SetBorderSize(0);
leg->SetFillStyle(kNone);
leg->SetTextSize(0.045);
leg->Draw("SAME");
TLegend *leg2 = new TLegend(0.5,0.92-0.05*2,0.7,0.92,"","brNDC");
leg2->SetBorderSize(0);
leg2->SetFillStyle(kNone);
leg2->SetTextSize(0.045);
if (types.size()!=1) leg2->Draw("SAME");
int colors[2] = {kBlack, kBlue};
int markers[4] = {kFullCircle, kOpenCircle, kOpenSquare, kOpenDiamond};
// Both overlaid
for (unsigned int i0 = 0; i0 != graphs.size(); ++i0) {
for (unsigned int j = 0; j != graphs[i0].size(); ++j) {
int i = graphs.size()-i0-1; // reverse PF and Calo
TGraphErrors *g = graphs[i][j]; assert(g);
g->SetMarkerStyle(markers[j%4]);
g->SetMarkerSize(2);
g->SetMarkerColor(colors[i%2]);
g->SetLineColor(colors[i%2]);
g->Draw("SAME P");
if (graphs.size()==2&& graphs[0].size()==1) {
if (j==0) leg2->AddEntry(g,types[i]=="" ? "PF":types[i].c_str(),"P");
}
else {
if (i==0) leg->AddEntry(g,etas[j].c_str(),"P");