-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlottingNCellEffi_Methods.cxx
2041 lines (1576 loc) · 89 KB
/
PlottingNCellEffi_Methods.cxx
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
#include "Plotting_Header.h"
// #include "/home/joshua/PCG_Software/Plotting/Plotting_Class.h"
#include "TGraphErrors.h"
using std::cout;
using std::endl;
// Fit to describe the NCellEffi
Double_t func1(Double_t *x, Double_t *par)
{
Double_t a = par[0];
Double_t b = par[1];
Double_t c = par[2];
Double_t res1 = TMath::Exp(a - TMath::Power((x[0]-b)/c,2));
Double_t res = 1-par[3]*TMath::Exp(- res1);
return res;
}
class Effi{
public:
Effi();
Effi(TString input, TString Period = "13TeV", TString suffix ="png");
~Effi();
void FillHistos();
void SetAddition(TString tmp) {fMethod = tmp;};
void SetSpecialName(TString tmp) {fSpecialName = tmp; };
float calcErr(float Emc, float Errmc, float Edata, float Errdata);
void GetEffiHists(TH2F *hdata2d, TH2F *hMC2d, TH1D *&hEffiData, TH1D *&hEffiMC, TH1D *&hRatio, TH1D *&hCorr, bool doSmooth = false);
void GetTrueHists(TH2F* h2, TH1D *&h, TString name = "h");
void FillCorrHistos();
void LoadTB();
void GetHistReweighted();
void SetOtherHistos();
void DoSBSubtraction();
void SetPurityHistosAfterSBSub();
TH2F* SubtractSidebandBack(TH2F* hMInv, TH2F* hMInvBack, TH2F* hNCellSB, TH2F* hNCell);
TH2F* SubtractHadronsFromMC(TH2F* hMInv, TH2F* hMInvBack, TH2F* hNCellSB, TH2F* hNCell);
void SetPlotting();
// Effi Plots
void PlotEffi_TB(); // Effi Plot with all clusters from P2
void PlotEffi_AllClusAndTB(); // Effi Plot with all clusters from P2
void PlotEffi_AllClusAndTBAndTrueGamma(); // Effi Plot with all clusters from P2 and true gammas
void PlotEffi_Wide(); // Effi Plot with clusters in pi0 mass range
void PlotEffi_WideWithTrue(); // Effi Plot with clusters in pi0 mass range with true gammas
void PlotEffi_WideWithRW(); // Effi Plot with clusters in pi0 mass range with true gammas
void PlotEffi_WideWithRWSBSub(); // Effi Plot with clusters in pi0 mass range with true gammas
void PlotEffi_TrueVsRecE(); // Effi Plot with clusters in pi0 mass range with true gammas
// Ratio Plots
void PlotRatio_Wide(); // Plot ratio with TB + wide clusters with and without RW and SB sub
void PlotRatio_TBAndAll(); // Plot ratio with TB + all clus
void PlotRatio_ConvMod(); // Plot ratio with TB + wide clusters with and without RW and SB sub
// Corr Plots
void PlotCorr_Wide(); // Plot correction factor with TB + all clusters + gammas (right) + gammas (right) reweighted
void PlotCorr_TBAndAll(); // Plot correction factor with TB + all clusters
// Fitting of CorrPlots
void FitCorr_GammasWide(); // Fitting of correction with
void PlotMCClosure(); // Fitting of correction with
void PlotDataClosure(); // Fitting of correction with
void PlotTrueVsRecE();
// Purity
void PlotPurity();
// ExampleBin
void PlotExampleBin();
void PlotNCellVsE();
void PlotEffiSources();
void ScaleTo(TH1D *h, TH1D *& h2, float down = 0.2, float up = 0.3);
void WriteToFile();
TFile* fcontrolOut = nullptr;
private:
TFile* fdata = nullptr;
TFile *fMassPos = nullptr;
TString fPeriod = "";
TString fMethod = "";
TString fSpecialName = "";
TString fsuffix = "png";
float PlotenergyHigh = 8.;
TString sEnergy = "pp, #sqrt{s} = 13 TeV";
TString StrSelectedGamma(){
if(fMethod.Contains("Low")) return "lower clus. selected";
if(fMethod.Contains("High")) return "higher clus. selected";
else return "both clus. selected";
}
TString StrSelectedRange(){
if(fMethod.Contains("Wide")) return "0.09 < M_{inv} < 0.17 GeV/#it{c}^{2}";
if(fMethod.Contains("Left")) return "M_{#pi^{0}} - 0.05 < M_{inv} < M_{#pi^{0}} GeV/#it{c}^{2}";
if(fMethod.Contains("Right")) return "M_{#pi^{0}} < M_{inv} < M_{#pi^{0}} + 0.02 GeV/#it{c}^{2}";
else return "0.09 < M_{inv} < 0.17 GeV/#it{c}^{2}";
}
std::array<double, 2> getRangeSignal(float pT = 0){
if(!fMassPos) fMassPos = TFile::Open("fMassPos.root");
TF1 *func = (TF1*) fMassPos->Get(Form("MassPos%s_func", fPeriod.Data()));
if(fMethod.Contains("Right")){
return {func->Eval(pT), func->Eval(pT) + 0.02};
}
else if(fMethod.Contains("Left")){
return {func->Eval(pT) - 0.05, func->Eval(pT)};
}
return {0.09, 0.17};
}
// Test Beam
TGraphErrors *grTB_data = nullptr;
TGraphErrors *grTB_MC = nullptr;
TGraphErrors *grTB_Ratio = nullptr;
TGraphErrors *grTB_Corr = nullptr;
// All clusters
TH2F* hNCellVsETMNL_data = nullptr;
TH2F* hNCellVsETMNL_MC = nullptr;
TH2F* hNCellVsEGammasNLTrue_TrueE_MC = nullptr;
TH2F* hNCellVsEGammasNLTrue_RecE_MC = nullptr;
// Gammas Wide
TH2F* hNCellVsEGammasNL_data = nullptr;
TH2F* hNCellVsEGammasNL_MC = nullptr;
TH2F* hNCellVsETrueGammasNL_MC = nullptr;
TH2F* hNCellVsEGammasNLTrueElec_MC = nullptr;
TH2F* hNCellVsEGammasNLTrueHadrons_MC = nullptr;
// Gammas Wide sideband subtracted
TH2F* hNCellVsEGammasNL_SBSub_data = nullptr;
TH2F* hNCellVsEGammasNL_SBSub_MC = nullptr;
TH2F* hNCellVsETrueGammasNL_SBSub_MC = nullptr;
TH2F* hNCellVsEGammasNLTrueElec_SBSub_MC = nullptr;
// MC sideband subtracted
TH2F* hNCellVsEGammasNL_MCSBSub_data = nullptr;
TH2F* hNCellVsEGammasNL_MCSBSub_MC = nullptr;
// MC sideband subtracted and reweighted
TH2F* hNCellVsEGammasNL_MCSBSub_RW_data = nullptr;
TH2F* hNCellVsEGammasNL_MCSBSub_RW_MC = nullptr;
// Gammas Wide reweighted
TH2F* hNCellVsEGammasNL_RW_data = nullptr;
TH2F* hNCellVsEGammasNL_RW_MC = nullptr;
// Gammas Wide reweighted but 10% different conversion probability
TH2F* hNCellVsEGammasNL_RW_ConvMod10_data = nullptr;
// Gammas Wide RW + sideband subtracted
TH2F* hNCellVsEGammasNL_RW_SBSub_data = nullptr;
TH2F* hNCellVsEGammasNL_RW_MCSBSub_data = nullptr;
TH2F* hNCellVsEGammasNL_RW_SBSub_MC = nullptr;
// Gammas SideBand
TH2F* hNCellVsEGammasNLSB_data = nullptr;
TH2F* hNCellVsEGammasNLSB_MC = nullptr;
TH2F* hNCellVsETrueGammasNLSB_MC = nullptr;
TH2F* hNCellVsEGammasNLTrueElecSB_MC = nullptr;
// conversions only
TH2F* hNCellVsEConversionsNL_RW_data = nullptr;
TH2F* hNCellVsEConversionsNL_RW_MC = nullptr;
// TH2F* hNCellVsTrueEelecNL_data = nullptr;
// all clusters
TH1D* hNCell_AllClus_Effi_data = nullptr;
TH1D* hNCell_AllClus_Effi_MC = nullptr;
TH1D* hNCell_AllClus_Effi_Ratio = nullptr;
TH1D* hNCell_AllClus_Effi_Corr = nullptr;
TH1D* hNCell_TrueGammas_TrueE_Effi_data = nullptr;
TH1D* hNCell_TrueGammas_TrueE_Effi_MC = nullptr;
TH1D* hNCell_TrueGammas_TrueE_Effi_Ratio = nullptr;
TH1D* hNCell_TrueGammas_TrueE_Effi_Corr = nullptr;
TH1D* hNCell_TrueGammas_RecE_Effi_data = nullptr;
TH1D* hNCell_TrueGammas_RecE_Effi_MC = nullptr;
TH1D* hNCell_TrueGammas_RecE_Effi_Ratio = nullptr;
TH1D* hNCell_TrueGammas_RecE_Effi_Corr = nullptr;
// gammas wide
TH1D* hNCell_Gammas_Effi_data = nullptr;
TH1D* hNCell_Gammas_Effi_MC = nullptr;
TH1D* hNCell_Gammas_Effi_Ratio = nullptr;
TH1D* hNCell_Gammas_Effi_Corr = nullptr;
// True gammas wide
TH1D* hNCell_TrueGammas_data = nullptr;
TH1D* hNCell_TrueGammas_MC = nullptr;
TH1D* hNCell_TrueGammas_Ratio = nullptr;
TH1D* hNCell_TrueGammas_Corr = nullptr;
// True gammas Sideband
TH1D* hNCell_TrueGammasSB_data = nullptr;
TH1D* hNCell_TrueGammasSB_MC = nullptr;
TH1D* hNCell_TrueGammasSB_Ratio = nullptr;
TH1D* hNCell_TrueGammasSB_Corr = nullptr;
// gammas reweighted wide
TH1D* hNCell_Gammas_RW_Effi_data = nullptr;
TH1D* hNCell_Gammas_RW_Effi_MC = nullptr;
TH1D* hNCell_Gammas_RW_Effi_Ratio = nullptr;
TH1D* hNCell_Gammas_RW_Effi_Corr = nullptr;
// gammas SB sub wide
TH1D* hNCell_Gammas_SBSub_Effi_data = nullptr;
TH1D* hNCell_Gammas_SBSub_Effi_MC = nullptr;
TH1D* hNCell_Gammas_SBSub_Effi_Ratio = nullptr;
TH1D* hNCell_Gammas_SBSub_Effi_Corr = nullptr;
// gammas reweighted SB sub wide
TH1D* hNCell_Gammas_RW_SBSub_Effi_data = nullptr;
TH1D* hNCell_Gammas_RW_SBSub_Effi_MC = nullptr;
TH1D* hNCell_Gammas_RW_SBSub_Effi_Ratio = nullptr;
TH1D* hNCell_Gammas_RW_SBSub_Effi_Corr = nullptr;
// gammas reweighted MC hadrons sub wide
TH1D* hNCell_Gammas_RW_MCHadSub_Effi_data = nullptr;
TH1D* hNCell_Gammas_RW_MCHadSub_Effi_MC = nullptr;
TH1D* hNCell_Gammas_RW_MCHadSub_Effi_Ratio = nullptr;
TH1D* hNCell_Gammas_RW_MCHadSub_Effi_Corr = nullptr;
// gammas reweighted wide 10% diff conv. probability
TH1D* hNCell_Gammas_RW_ConvMod10_Effi_data = nullptr;
TH1D* hNCell_Gammas_RW_ConvMod10_Effi_MC = nullptr;
TH1D* hNCell_Gammas_RW_ConvMod10_Effi_Ratio = nullptr;
TH1D* hNCell_Gammas_RW_ConvMod10_Effi_Corr = nullptr;
TH2F* hNCellVsEAllClusTrueGamma = nullptr;
TH2F* hNCellVsEAllClusTrueElec = nullptr;
TH2F* hNCellVsEAllClusTrueHadrons = nullptr;
// for those histos, low is loaded and high added to result in wide
TH2F* hInvMassVsClusterPt_MC = nullptr;
TH2F* hInvMassVsClusterPt_data = nullptr;
TH2F* hInvMassVsPtGamma_MC = nullptr;
TH2F* hInvMassVsPtElec_MC = nullptr;
TH2F* hInvMassVsClusterPtBack_data = nullptr;
TH2F* hInvMassVsClusterPtBack_MC = nullptr;
TH1D* hGammaPurity = nullptr;
TH1D* hGammaPuritySB = nullptr;
TH1D* hGammaPuritySBSub = nullptr;
TH1D* hElecPurity = nullptr;
TH1D* hElecPuritySB = nullptr;
TH1D* hElecPuritySBSub = nullptr;
TH1D* hUnPurity = nullptr;
TH1D* hUnPuritySB = nullptr;
TH1D* hUnPuritySBSub = nullptr;
TH1D* hTrueGammas = nullptr;
TH1D* hTrueElec = nullptr;
TH1D* hTrueGammasSB = nullptr;
TH1D* hTrueElecSB = nullptr;
// PlottingHists
TH2F* hDummyEffi = nullptr;
TH2F* hDummyRatio = nullptr;
TH2F* hDummyCorr = nullptr;
TH2F* hDummyPurity = nullptr;
TH2F* hDummyMInv = nullptr;
TH2F* hDummyMInvRatio = nullptr;
TH2F* hDummyMassPos = nullptr;
TH2F* hDummyMCClosure = nullptr;
TH2F* hDummyNCellRatio = nullptr;
TH2F* hDummyNCellFraction = nullptr;
TH2F* hDummyERecVsETrue = nullptr;
TH2F* hDummyERecVsETrue2 = nullptr;
TH2F* hDummyFraction = nullptr;
TH2F* hRecDivTrueE = nullptr;
TH2F* hRecDivTrueEOneCell = nullptr;
TH2F* hRecDivTrueETwoCell = nullptr;
TH2F* hRecDivTrueEThreeCell = nullptr;
TCanvas* hDummyCan = nullptr;
TCanvas* hDummyCan2d = nullptr;
Float_t textSizeSinglePad = 0.044;
Float_t textSizeLabelsRel = 0.044;
// const int nBinsE = 20;
// Double_t arrEbins[21] = {0.0, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0,
// 2.4, 2.8, 3.2, 3.6, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0,
// 10.};
};
//----------------------------
Effi::Effi(){
}
//----------------------------
Effi::~Effi(){
}
//----------------------------
Effi::Effi(TString input, TString Period, TString suffix){
fdata = TFile::Open(input);
fPeriod = Period;
fsuffix = suffix;
fcontrolOut = new TFile("fcontrolOut.root", "Recreate");
}
void Effi::LoadTB(){
TFile TB("Fig35right.root");
grTB_data = (TGraphErrors*) TB.Get("gData");
TGraph* tmpTBMC = (TGraph*) TB.Get("gG3");
// double *xData = tmpTBData->GetX();
// double *yData = tmpTBData->GetY();
double *xMC = tmpTBMC->GetX();
double *yMC = tmpTBMC->GetY();
// Double_t ey[8] = {0.04, 0.03, 0.03, 0.02, 0.015, 0.007, 0.001, 0.001};
Double_t ex[8] = {0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001};
Double_t eMC[8] = {0.00001, 0.00001, 0.00001, 0.00001, 0.00001, 0.00001, 0.00001, 0.00001};
// grTB_data = new TGraphErrors(8, xData, yData, ex, ey);
grTB_MC = new TGraphErrors(8, xMC, yMC, eMC, eMC);
for(int i = 0; i < grTB_MC->GetN(); ++i){
grTB_MC->SetPointError(i, 0.001, eMC[i]);
}
grTB_Ratio = (TGraphErrors*) grTB_MC->Clone("grTBRatio");
// SetPointError
for(int i = 0; i < grTB_Ratio->GetN(); ++i){
grTB_Ratio->SetPointY(i, grTB_data->Eval(grTB_MC->GetPointX(i)) / grTB_MC->GetPointY(i));
grTB_Ratio->SetPointError(i, 0.001, grTB_data->GetErrorY(i)/grTB_MC->GetPointY(i));
}
grTB_Corr = (TGraphErrors*) grTB_MC->Clone("grTBEffi");
for(int i = 0; i < grTB_data->GetN(); ++i){
float CF = -1;
float CFerr = 0.001;
if(grTB_MC->GetPointY(i) < 1){
CF = 1 - (( 1 - grTB_data->Eval(grTB_MC->GetPointX(i)))/(1 - grTB_MC->GetPointY(i)));
CFerr = grTB_data->GetErrorY(i)/(1-grTB_MC->GetPointY(i));
} else{
CF = -1;
CFerr = 0.001;
}
grTB_Corr->SetPointY(i, CF);
grTB_Corr->SetPointError(i, 0.0001, CFerr);
}
}
void Effi::FillHistos(){
hNCellVsETMNL_data = (TH2F*) fdata->Get("hNCellVsETMNL_data");
hNCellVsETMNL_data ->Sumw2();
hNCellVsETMNL_data ->SetDirectory(0);
hNCellVsETMNL_MC = (TH2F*) fdata->Get("hNCellVsETMNL_MC");
hNCellVsETMNL_MC->Sumw2();
hNCellVsETMNL_MC->SetDirectory(0);
hNCellVsEGammasNL_data = (TH2F*) fdata->Get(Form("hNCellVsEGammasNL%s_data", fMethod.Data()));
hNCellVsEGammasNL_data ->Sumw2();
hNCellVsEGammasNL_data ->SetDirectory(0);
hNCellVsEGammasNL_MC = (TH2F*) fdata->Get(Form("hNCellVsEGammasNL%s_MC", fMethod.Data()));
hNCellVsEGammasNL_MC->Sumw2();
hNCellVsEGammasNL_MC->SetDirectory(0);
hNCellVsETrueGammasNL_MC = (TH2F*) fdata->Get(Form("hNCellVsETrueGammasNL%s_MC", fMethod.Data()));
hNCellVsETrueGammasNL_MC ->Sumw2();
hNCellVsETrueGammasNL_MC ->SetDirectory(0);
hNCellVsEGammasNLTrueElec_MC = (TH2F*) fdata->Get(Form("hNCellVsEGammasNLTrueElec%s_MC", fMethod.Data()));
hNCellVsEGammasNLTrueElec_MC ->Sumw2();
hNCellVsEGammasNLTrueElec_MC ->SetDirectory(0);
hNCellVsEGammasNLTrueHadrons_MC = (TH2F*) hNCellVsEGammasNL_MC->Clone("hNCellVsEGammasNLTrueHadrons_MC");
hNCellVsEGammasNLTrueHadrons_MC->Add(hNCellVsETrueGammasNL_MC, -1);
hNCellVsEGammasNLTrueHadrons_MC->Add(hNCellVsEGammasNLTrueElec_MC, -1);
hNCellVsEGammasNLTrueHadrons_MC->Sumw2();
TString isHighLow = "";
if(fMethod.Contains("High")) isHighLow = "High";
else if(fMethod.Contains("Low")) isHighLow = "Low";
hNCellVsEGammasNLSB_data = (TH2F*) fdata->Get(Form("hNCellVsEGammasNLSideBand%s_data", isHighLow.Data()));
hNCellVsEGammasNLSB_data ->Sumw2();
hNCellVsEGammasNLSB_data ->SetDirectory(0);
hNCellVsEGammasNLSB_MC = (TH2F*) fdata->Get(Form("hNCellVsEGammasNLSideBand%s_MC", isHighLow.Data()));
hNCellVsEGammasNLSB_MC ->Sumw2();
hNCellVsEGammasNLSB_MC ->SetDirectory(0);
hNCellVsETrueGammasNLSB_MC = (TH2F*) fdata->Get(Form("hNCellVsETrueGammasNLSideBand%s_MC", isHighLow.Data()));
hNCellVsETrueGammasNLSB_MC ->Sumw2();
hNCellVsETrueGammasNLSB_MC ->SetDirectory(0);
hNCellVsEGammasNLTrueElecSB_MC = (TH2F*) fdata->Get(Form("hNCellVsEGammasNLTrueElecSideBand%s_MC", isHighLow.Data()));
hNCellVsEGammasNLTrueElecSB_MC->Sumw2();
hNCellVsEGammasNLTrueElecSB_MC->SetDirectory(0);
hRecDivTrueE = (TH2F*) fdata->Get("hRecDivTrueE_MC");
hRecDivTrueEOneCell = (TH2F*) fdata->Get("hRecDivTrueEOneCell_MC");
hRecDivTrueETwoCell = (TH2F*) fdata->Get("hRecDivTrueETwoCell_MC");
hRecDivTrueEThreeCell = (TH2F*) fdata->Get("hRecDivTrueEThreeCell_MC");
// true gammas, electrons, hadrons
hNCellVsEAllClusTrueGamma = (TH2F*) fdata->Get("hNCellVsETrueGamma_MC");
hNCellVsEAllClusTrueElec = (TH2F*) fdata->Get("hNCellVsETrueElec_MC");
hNCellVsEAllClusTrueHadrons = (TH2F*) fdata->Get("hNCellVsETrueHadr_MC");
}
// -------------------------------------------------
// Steering Efficiency histos calculation
// -------------------------------------------------
void Effi::FillCorrHistos(){
// all clusters
GetEffiHists(hNCellVsETMNL_data, hNCellVsETMNL_MC, hNCell_AllClus_Effi_data, hNCell_AllClus_Effi_MC, hNCell_AllClus_Effi_Ratio, hNCell_AllClus_Effi_Corr);
// wide clusters
GetEffiHists(hNCellVsEGammasNL_data, hNCellVsEGammasNL_MC, hNCell_Gammas_Effi_data, hNCell_Gammas_Effi_MC, hNCell_Gammas_Effi_Ratio, hNCell_Gammas_Effi_Corr);
// wide reweighted
GetEffiHists(hNCellVsEGammasNL_RW_data, hNCellVsEGammasNL_RW_MC, hNCell_Gammas_RW_Effi_data, hNCell_Gammas_RW_Effi_MC, hNCell_Gammas_RW_Effi_Ratio, hNCell_Gammas_RW_Effi_Corr);
// wide SB subtracted
GetEffiHists(hNCellVsEGammasNL_SBSub_data, hNCellVsEGammasNL_SBSub_MC, hNCell_Gammas_SBSub_Effi_data, hNCell_Gammas_SBSub_Effi_MC, hNCell_Gammas_SBSub_Effi_Ratio, hNCell_Gammas_SBSub_Effi_Corr);
// wide SB subtracted + RW
cout<<"here it comes \n";
GetEffiHists(hNCellVsEGammasNL_RW_SBSub_data, hNCellVsEGammasNL_RW_SBSub_MC, hNCell_Gammas_RW_SBSub_Effi_data, hNCell_Gammas_RW_SBSub_Effi_MC, hNCell_Gammas_RW_SBSub_Effi_Ratio, hNCell_Gammas_RW_SBSub_Effi_Corr);
// hadrons from MC subtracted and reweighted
GetEffiHists(hNCellVsEGammasNL_MCSBSub_RW_data, hNCellVsEGammasNL_MCSBSub_RW_MC, hNCell_Gammas_RW_MCHadSub_Effi_data, hNCell_Gammas_RW_MCHadSub_Effi_MC, hNCell_Gammas_RW_MCHadSub_Effi_Ratio, hNCell_Gammas_RW_MCHadSub_Effi_Corr);
// true photons
GetEffiHists(hNCellVsETrueGammasNL_MC, hNCellVsETrueGammasNL_MC, hNCell_TrueGammas_data, hNCell_TrueGammas_MC, hNCell_TrueGammas_Ratio, hNCell_TrueGammas_Corr);
// true photons Sideband
GetEffiHists(hNCellVsETrueGammasNLSB_MC, hNCellVsETrueGammasNLSB_MC, hNCell_TrueGammasSB_data, hNCell_TrueGammasSB_MC, hNCell_TrueGammasSB_Ratio, hNCell_TrueGammasSB_Corr);
// wide reweighted conv. mod 10%
GetEffiHists(hNCellVsEGammasNL_RW_ConvMod10_data, hNCellVsEGammasNL_RW_MC, hNCell_Gammas_RW_ConvMod10_Effi_data, hNCell_Gammas_RW_ConvMod10_Effi_MC, hNCell_Gammas_RW_ConvMod10_Effi_Ratio, hNCell_Gammas_RW_ConvMod10_Effi_Corr);
// true photons vs true energy
GetEffiHists(hNCellVsEGammasNLTrue_TrueE_MC, hNCellVsEGammasNLTrue_TrueE_MC, hNCell_TrueGammas_TrueE_Effi_data, hNCell_TrueGammas_TrueE_Effi_MC, hNCell_TrueGammas_TrueE_Effi_Ratio, hNCell_TrueGammas_TrueE_Effi_Corr);
// true photons vs rec energy
GetEffiHists(hNCellVsEGammasNLTrue_RecE_MC, hNCellVsEGammasNLTrue_RecE_MC, hNCell_TrueGammas_RecE_Effi_data, hNCell_TrueGammas_RecE_Effi_MC, hNCell_TrueGammas_RecE_Effi_Ratio, hNCell_TrueGammas_RecE_Effi_Corr);
}
// -------------------------------------------------
// Steering for sideband subtraction
// -------------------------------------------------
void Effi::DoSBSubtraction(){
// data wide gamma
hNCellVsEGammasNL_SBSub_data = SubtractSidebandBack( hInvMassVsClusterPt_data, hInvMassVsClusterPtBack_data , hNCellVsEGammasNLSB_data , hNCellVsEGammasNL_data);
// MC wide gamma
hNCellVsEGammasNL_SBSub_MC = SubtractSidebandBack( hInvMassVsClusterPt_MC, hInvMassVsClusterPtBack_MC , hNCellVsEGammasNLSB_MC , hNCellVsEGammasNL_MC);
// true electrons
hNCellVsEGammasNLTrueElec_SBSub_MC = SubtractSidebandBack( hInvMassVsClusterPt_MC, hInvMassVsClusterPtBack_MC , hNCellVsEGammasNLTrueElecSB_MC , hNCellVsEGammasNLTrueElec_MC);
// true photons
hNCellVsETrueGammasNL_SBSub_MC = SubtractSidebandBack( hInvMassVsClusterPt_MC, hInvMassVsClusterPtBack_MC , hNCellVsETrueGammasNLSB_MC , hNCellVsETrueGammasNL_MC);
// MC true hadron subtraction
hNCellVsEGammasNL_MCSBSub_data = SubtractHadronsFromMC(hInvMassVsClusterPtBack_data, hInvMassVsClusterPtBack_MC, hNCellVsEGammasNLTrueHadrons_MC, hNCellVsEGammasNL_data);
// MC true hadron subtraction on MC
cout<<"MC only"<<endl;
hNCellVsEGammasNL_MCSBSub_MC = SubtractHadronsFromMC(hInvMassVsClusterPtBack_MC, hInvMassVsClusterPtBack_MC, hNCellVsEGammasNLTrueHadrons_MC, hNCellVsEGammasNL_MC);
}
// -------------------------------------------------
// SUBTRACT SIDEBAND FROM SIGNAL REGION
// Make Sure the sideband and the peak use the same method or gamma selection!
// -------------------------------------------------
TH2F* Effi::SubtractSidebandBack(TH2F* hMInv_tmp, TH2F* hMInvBack_tmp, TH2F* hNCellSB_tmp, TH2F* hNCell_tmp){
TH2F* hMInv = (TH2F*) hMInv_tmp->Clone("hMInv");
TH2F* hMInvBack = (TH2F*) hMInvBack_tmp->Clone("hMInvBack");
TH2F* hNCellSB = (TH2F*) hNCellSB_tmp->Clone("hNCellSB");
TH2F* hNCell = (TH2F*) hNCell_tmp->Clone("hNCell");
// STrategy:
// Fill a histo with a pT dependent scaling factors
// this only works if the inv mass histo is only filled with the pT of the higher photon!
TH2F* hScale = (TH2F*) hNCell->Clone("hScale");
hScale->Reset();
// loop over energy bins
for(int i = 1; i <= hNCell->GetNbinsX(); ++i){
float xValLow = hNCell->GetXaxis()->GetBinLowEdge(i) + 0.001;
float xValUp = hNCell->GetXaxis()->GetBinUpEdge(i) - 0.001;
// get inv. mass distribution for signal and background
// scale background to same evt.
TH1D* hMInv_Proj = (TH1D*) hMInv->ProjectionX(Form("hMInv_Proj%i", i), hMInv->GetYaxis()->FindBin(xValLow), hMInv->GetYaxis()->FindBin(xValUp));
TH1D* hMInvBack_Proj = (TH1D*) hMInvBack->ProjectionX(Form("hMInvBack_Proj%i", i), hMInvBack->GetYaxis()->FindBin(xValLow), hMInvBack->GetYaxis()->FindBin(xValUp));
float scaleFac = hMInv_Proj->Integral(hMInv_Proj->FindBin(0.2), hMInv_Proj->FindBin(0.3)) / hMInvBack_Proj->Integral(hMInvBack_Proj->FindBin(0.2), hMInvBack_Proj->FindBin(0.3));
hMInvBack_Proj->Scale(scaleFac);
// ranges for background and signal
std::array<double, 2> rangeSB = {0.2, 0.3};
std::array<double, 2> rangeSignal = getRangeSignal((xValLow + xValUp)*0.5);
// calculate the integral of the background in signal range to estimate the amount of background
// Do the same for the same evt. in the sideband region
// calculate the ratio between the background and the sideband to later scale the sideband contribution
float backInt = hMInvBack_Proj->Integral(hMInvBack_Proj->FindBin(rangeSignal[0]), hMInvBack_Proj->FindBin(rangeSignal[1]));
float SBInt = hMInv_Proj->Integral(hMInv_Proj->FindBin(rangeSB[0]), hMInv_Proj->FindBin(rangeSB[1]));
// cout<<"hMInv_Proj: "<<hMInvBack_Proj->GetBinContent(20)<<endl;
// cout<<"backInt: "<<backInt<<" SBInt: "<<SBInt<<" backInt/SBInt: "<<backInt/SBInt<<endl;
// loop over ncell bins
for(int iy = 1; iy < hScale->GetNbinsY(); ++iy){
if(isnan(backInt/SBInt)){
hScale->SetBinContent(i, iy, 1);
}else {
hScale->SetBinContent(i, iy, backInt/SBInt);
}
}
}
// Scale background to same evt.
cout<<__LINE__<<endl;
// scale NCell vs E distribution in the sideband region to the Signal region
// this is now the scaled NCell vs. E sideband contribution that has to be subtracted from the NCell vs E distribution in the signal region
hNCellSB->Multiply(hScale);
cout<<"hNCellSB->Integral(): "<<hNCellSB->Integral()<<endl;
fcontrolOut->cd();
hScale->Write();
hScale->Write(Form("%s_hScale",hNCellSB->GetName()));
hNCellSB->Write(Form("%s_control",hNCellSB->GetName()));
// subtract SB NCell distribution from Signal NCell distribution
// This will also remove some photons!
TH2F* hSBSubtracted = (TH2F*) hNCell->Clone("hSBSubtracted");
hSBSubtracted->SetDirectory(0);
hSBSubtracted->Add(hNCellSB, -1);
cout<<__LINE__<<endl;
return hSBSubtracted;
}
// -------------------------------------------------
// SUBTRACT HADRON CONTRIBUTION WITH MC INFO FROM SIGNAL REGION
// Make Sure the sideband and the peak use the same method or gamma selection!
// -------------------------------------------------
TH2F* Effi::SubtractHadronsFromMC(TH2F* hMInvBack_tmp, TH2F* hMInvBackMC_tmp, TH2F* hNCell_TrueHadr, TH2F* hNCell_tmp){
TH2F* hNCell_TrueHadr_tmp = (TH2F*) hNCell_TrueHadr->Clone("hNCell_TrueHadr_tmp");
TH2F* hScale = (TH2F*) hNCell_TrueHadr->Clone("hScale");
hScale->Reset();
// loop over energy bins
for(int i = 1; i <= hNCell_TrueHadr->GetNbinsX(); ++i){
float xValLow = hNCell_TrueHadr->GetXaxis()->GetBinLowEdge(i) + 0.001;
float xValUp = hNCell_TrueHadr->GetXaxis()->GetBinUpEdge(i) - 0.001;
std::array<double, 2> rangeSignal = getRangeSignal((xValLow + xValUp)*0.5);
// get inv mass background for data and MC
// get a scale factor for the MC to fit the data
TH1D* hMInvBack_Proj = (TH1D*) hMInvBack_tmp->ProjectionX(Form("hMInvBack_Proj%i", i), hMInvBack_tmp->GetYaxis()->FindBin(xValLow), hMInvBack_tmp->GetYaxis()->FindBin(xValUp));
TH1D* hMInvBackMC_Proj = (TH1D*) hMInvBackMC_tmp->ProjectionX(Form("hMInvBackMC_Proj%i", i), hMInvBackMC_tmp->GetYaxis()->FindBin(xValLow), hMInvBackMC_tmp->GetYaxis()->FindBin(xValUp));
float intBackMC = hMInvBackMC_Proj->Integral(hMInvBackMC_Proj->FindBin(rangeSignal[0]), hMInvBackMC_Proj->FindBin(rangeSignal[1]));
float intBack = hMInvBack_Proj->Integral(hMInvBack_Proj->FindBin(rangeSignal[0]), hMInvBack_Proj->FindBin(rangeSignal[1]));
cout<<"intBackMC: "<<intBackMC<<" intBack: "<<intBack<<endl;
float scaleFac = (intBackMC != 0) ? intBack / intBackMC : 1;
cout<<"scaleFac: "<<scaleFac<<endl;
if(isnan(scaleFac)) scaleFac = 1;
for(int b = 1; b < hScale->GetNbinsY(); ++b){
hScale->SetBinContent(i, b, scaleFac);
}
}
// scale mc true ????
hNCell_TrueHadr_tmp->Multiply(hScale);
TH2F* hSBSubtracted = (TH2F*) hNCell_tmp->Clone("hSBSubtracted");
hSBSubtracted->SetDirectory(0);
hSBSubtracted->Add(hNCell_TrueHadr_tmp, -1);
return hSBSubtracted;
}
void Effi::SetOtherHistos(){
// both sides of peak
hGammaPurity = (TH1D*) hNCellVsETrueGammasNL_MC->ProjectionX("hGammaPurity");
hTrueGammas = (TH1D*) hNCellVsETrueGammasNL_MC->ProjectionX("hTrueGammas");
hTrueElec = (TH1D*) hNCellVsEGammasNLTrueElec_MC->ProjectionX("hTrueElec");
hElecPurity = (TH1D*) hNCellVsEGammasNLTrueElec_MC->ProjectionX("hElecPurity");
hGammaPurity->Divide(hTrueGammas, (TH1D*) hNCellVsEGammasNL_MC->ProjectionX("hGammasForPurity"), 1, 1, "B");
hElecPurity->Divide(hTrueElec, (TH1D*) hNCellVsEGammasNL_MC->ProjectionX("hElecForPurity"), 1, 1, "B");
hUnPurity = (TH1D*) hGammaPurity->Clone("hUnPurity");
hUnPurity->Add(hElecPurity);
for(int i = 1; i <= hUnPurity->GetNbinsX(); ++i){ hUnPurity->SetBinContent(i, 1- hUnPurity->GetBinContent(i));}
// Sideband, SB gamma
hGammaPuritySB = (TH1D*) hNCellVsETrueGammasNLSB_MC->ProjectionX("hGammaPuritySB");
hTrueGammasSB = (TH1D*) hNCellVsETrueGammasNLSB_MC->ProjectionX("hTrueGammasSB");
hTrueElecSB = (TH1D*) hNCellVsEGammasNLTrueElecSB_MC->ProjectionX("hTrueElecSB");
hElecPuritySB = (TH1D*) hNCellVsEGammasNLTrueElecSB_MC->ProjectionX("hElecPuritySB");
hGammaPuritySB->Divide(hTrueGammasSB, (TH1D*) hNCellVsEGammasNLSB_MC->ProjectionX("hGammasForPuritySB"), 1, 1, "B");
hElecPuritySB->Divide(hTrueElecSB, (TH1D*) hNCellVsEGammasNLSB_MC->ProjectionX("hElecForPuritySB"), 1, 1, "B");
hUnPuritySB = (TH1D*) hGammaPuritySB->Clone("hUnPuritySB");
hUnPuritySB->Add(hElecPuritySB);
for(int i = 1; i <= hUnPuritySB->GetNbinsX(); ++i){ hUnPuritySB->SetBinContent(i, 1- hUnPuritySB->GetBinContent(i));}
TString isHighLow = "Both";
if(fMethod.Contains("Low")) isHighLow = "Low";
if(fMethod.Contains("High")) isHighLow = "High";
hInvMassVsClusterPt_data = (TH2F*) fdata->Get(Form("hInvMassVsPt%s_data", isHighLow.Data()));
hInvMassVsClusterPt_data ->Sumw2();
hInvMassVsClusterPtBack_data = (TH2F*) fdata->Get(Form("hInvMassVsGammaPtBack%s_data", isHighLow.Data()));
hInvMassVsClusterPtBack_data->Sumw2();
hInvMassVsClusterPt_MC = (TH2F*) fdata->Get(Form("hInvMassVsPt%s_MC", isHighLow.Data()));
hInvMassVsClusterPt_MC ->Sumw2();
hInvMassVsClusterPtBack_MC = (TH2F*) fdata->Get(Form("hInvMassVsGammaPtBack%s_MC", isHighLow.Data()));
hInvMassVsClusterPtBack_MC->Sumw2();
// get MC information photons, electrons
hInvMassVsPtGamma_MC = (TH2F*) fdata->Get(Form("hInvMassVsPtGamma%s_MC", isHighLow.Data()));
hInvMassVsPtElec_MC = (TH2F*) fdata->Get(Form("hInvMassVsPtElec%s_MC", isHighLow.Data()));
// all true gammas for true energy
hNCellVsEGammasNLTrue_TrueE_MC = (TH2F*) fdata->Get(Form("hNCellVsEGammasNLTrue_TrueE_MC"));
// all true gammas for rec energy
hNCellVsEGammasNLTrue_RecE_MC = (TH2F*) fdata->Get(Form("hNCellVsEGammasNLTrue_RecE_MC"));
}
//---------------------------------------------
// Get purity histograms after SB subtraction
//---------------------------------------------
void Effi::SetPurityHistosAfterSBSub(){
if(!hNCellVsETrueGammasNL_SBSub_MC){
cout<<"Warning!! hNCellVsETrueGammasNL_SBSub_MC not there..."<<endl;
cout<<"Exit SetPurityHistosAfterSBSub, set these histos first!"<<endl;
return;
}
hGammaPuritySBSub = (TH1D*) hNCellVsETrueGammasNL_SBSub_MC->ProjectionX("hGammaPuritySBSub");
hElecPuritySBSub = (TH1D*) hNCellVsEGammasNLTrueElec_SBSub_MC->ProjectionX("hElecPuritySBSub");
TH1D* hTrueGammasSBSub = (TH1D*) hNCellVsETrueGammasNL_SBSub_MC->ProjectionX("hTrueGammasSBSub");
TH1D* hTrueElecSBSub = (TH1D*) hNCellVsEGammasNLTrueElec_SBSub_MC->ProjectionX("hTrueElecSBSub");
hGammaPuritySBSub->Divide(hTrueGammasSBSub, (TH1D*) hNCellVsEGammasNL_SBSub_MC->ProjectionX("hGammasForPuritySBSub"), 1, 1, "B");
hElecPuritySBSub->Divide(hTrueElecSBSub, (TH1D*) hNCellVsEGammasNL_SBSub_MC->ProjectionX("hGammasForPuritySBSub"), 1, 1, "B");
hUnPuritySBSub = (TH1D*) hGammaPuritySBSub->Clone("hUnPuritySBSub");
hUnPuritySBSub->Add(hElecPuritySBSub);
for(int i = 1; i <= hUnPuritySBSub->GetNbinsX(); ++i){ hUnPuritySBSub->SetBinContent(i, 1- hUnPuritySBSub->GetBinContent(i));}
}
// ------------------------------------------
// Get NCell efficiency hists from 2d NCellVs E distributions
// ------------------------------------------
void Effi::GetEffiHists(TH2F *hdata2d, TH2F *hMC2d, TH1D *&hEffiData, TH1D *&hEffiMC, TH1D *&hRatio, TH1D *&hCorr, bool doSmooth){
TH1D* hdataNCell1 = (TH1D*) hdata2d->ProjectionX("hdataNCell1", hdata2d->GetYaxis()->FindBin(1.), hdata2d->GetYaxis()->FindBin(19));
TH1D* hdataNCellOnly1 = (TH1D*) hdata2d->ProjectionX("hdataNCellOnly1", hdata2d->GetYaxis()->FindBin(1.), hdata2d->GetYaxis()->FindBin(1.));
TH1D* hdataNCell2 = (TH1D*) hdata2d->ProjectionX("hdataNCell2", hdata2d->GetYaxis()->FindBin(2.), hdata2d->GetYaxis()->FindBin(19));
TH1D* hMCNCell1 = (TH1D*) hMC2d->ProjectionX("hMCNCell1", hMC2d->GetYaxis()->FindBin(1.), hMC2d->GetYaxis()->FindBin(19));
TH1D* hMCNCellOnly1 = (TH1D*) hMC2d->ProjectionX("hMCNCellOnly1", hMC2d->GetYaxis()->FindBin(1.), hMC2d->GetYaxis()->FindBin(1.));
TH1D* hMCNCell2 = (TH1D*) hMC2d->ProjectionX("hMCNCell2", hMC2d->GetYaxis()->FindBin(2.), hMC2d->GetYaxis()->FindBin(19));
hEffiData = (TH1D*) hdataNCell2->Clone("hEffidata");
hEffiData->Divide(hdataNCell2, hdataNCell1, 1, 1, "B");
for(int i = 1; i <= hEffiData->GetNbinsX(); ++i){
if(isnan(hEffiData->GetBinContent(i))) hEffiData->SetBinContent(i, 1);
}
hEffiMC = (TH1D*) hMCNCell2->Clone("hEffiMC");
hEffiMC->Divide(hMCNCell2, hMCNCell1, 1, 1, "B");
for(int i = 1; i <= hEffiMC->GetNbinsX(); ++i){
if(isnan(hEffiMC->GetBinContent(i))) hEffiMC->SetBinContent(i, 1);
}
// smoothing on effi histos
if(doSmooth){
// logistisches wachstum
// TF1 * func = new TF1("func", "[2]/(1+exp(-[0]*(x - [1]))) - [2] + 1", 0.7, 3);
TF1 * func = new TF1("func", func1, 1., 8, 4);
func->SetParameter(0, 2.8);
func->SetParameter(1, 9.5);
func->SetParameter(2, 9.9);
func->SetParameter(3, 970);
hEffiData->Fit(func, "MR0");
// func->Write("func_data");
for(int i = 5; i <= hEffiData->GetNbinsX(); ++i){
hEffiData->SetBinContent(i, func->Eval(hEffiData->GetBinCenter(i)));
}
hEffiMC->Fit(func, "MR0");
// func->Write("func_MC");
for(int i = 5; i <= hEffiMC->GetNbinsX(); ++i){
hEffiMC->SetBinContent(i, func->Eval(hEffiMC->GetBinCenter(i)));
}
// outfile.Close();
}
hRatio = (TH1D*) hEffiData->Clone("hEffiRatio");
hRatio->Divide(hEffiMC);
// Calculate NCell Effi
hCorr = (TH1D*) hRatio->Clone("NCellEffi");
for(int i = 1; i <= hCorr->GetNbinsX(); ++i){
float CF = -1;
float err = 0;
if(hEffiMC->GetBinContent(i) < 1){
CF = 1 - (( 1 - hEffiData->GetBinContent(i))/(1 - hEffiMC->GetBinContent(i)));
err = calcErr(hEffiMC->GetBinContent(i), hEffiMC->GetBinError(i), hEffiData->GetBinContent(i), hEffiData->GetBinError(i));
}
cout<<CF<<endl;
hCorr->SetBinContent(i, CF);
hCorr->SetBinError(i, err);
}
}
// ------------------------------------------
// Error calculation using gaussian error propagation for NCell effi
// ------------------------------------------
float Effi::calcErr(float Emc, float Errmc, float Edata, float Errdata){
float err1 = Errmc / (1-Edata) ;
float err2 = ((1 - Emc) * Errdata ) / ((1-Edata)*(1-Edata) );
return sqrt(err1*err1 + err2*err2);
}
// ------------------------------------------
// GetTrueHists
// ------------------------------------------
void Effi::GetTrueHists(TH2F* h2, TH1D *&h, TString name ){
TH1D* hNCell1 = (TH1D*) h2->ProjectionX("hNCell1", h2->GetYaxis()->FindBin(1.), h2->GetYaxis()->FindBin(20));
TH1D* hNCell2 = (TH1D*) h2->ProjectionX("hNCell2", h2->GetYaxis()->FindBin(2.), h2->GetYaxis()->FindBin(20));
h = (TH1D*) hNCell2->Clone(name);
h->Divide(hNCell2, hNCell1, 1, 1, "B");
}
// ------------------------------------------
// Purity correction/Reweighting
// ------------------------------------------
void Effi::GetHistReweighted(){
hNCellVsEGammasNL_RW_data = (TH2F*) hNCellVsEGammasNL_data->Clone("hNCellVsEGammasNL_RW_data");
// get electron fraction
TH2F* hElecFracWide = (TH2F*) hNCellVsEGammasNLTrueElec_MC->Clone("hElecFracWide");
hElecFracWide->Divide(hNCellVsEGammasNL_MC);
hElecFracWide->Multiply(hNCellVsEGammasNL_data);
hNCellVsEGammasNL_RW_data->Add(hElecFracWide, -1);
hNCellVsEGammasNL_RW_MC = (TH2F*) hNCellVsEGammasNL_MC->Clone("hNCellVsEGammasNL_RW_MC");
hNCellVsEGammasNL_RW_MC->Add(hNCellVsEGammasNLTrueElec_MC, -1);
hNCellVsEGammasNL_RW_ConvMod10_data = (TH2F*) hNCellVsEGammasNL_data->Clone("hNCellVsEGammasNL_RW_ConvMod10_data");
// get electron fraction
TH2F* hElecFracWideConvMod10 = (TH2F*) hNCellVsEGammasNLTrueElec_MC->Clone("hElecFracWideConvMod10");
hElecFracWideConvMod10->Divide(hNCellVsEGammasNL_MC);
hElecFracWideConvMod10->Multiply(hNCellVsEGammasNL_data);
hNCellVsEGammasNL_RW_ConvMod10_data->Add(hElecFracWide, -0.9);
hNCellVsEGammasNL_RW_SBSub_data = (TH2F*) hNCellVsEGammasNL_SBSub_data->Clone("hNCellVsEGammasNL_RW_SBSub_data");
// get electron fraction
// was there from before
TH2F* hElecFracWide2 = (TH2F*) hNCellVsEGammasNLTrueElec_SBSub_MC->Clone("hElecFracWide2");
hElecFracWide2->Divide(hNCellVsEGammasNL_SBSub_MC);
hElecFracWide2->Multiply(hNCellVsEGammasNL_SBSub_data);
// hElecFracWide2->Scale(hNCellVsEGammasNL_SBSub_data->Integral()/hNCellVsEGammasNL_SBSub_MC->Integral());
hNCellVsEGammasNL_RW_SBSub_data->Add(hElecFracWide2, -1);
hNCellVsEGammasNL_RW_SBSub_MC = (TH2F*) hNCellVsEGammasNL_SBSub_MC->Clone("hNCellVsEGammasNL_RW_SBSub_MC");
// get electron fraction
TH2F* hElecFracWideMC = (TH2F*) hNCellVsEGammasNLTrueElec_SBSub_MC->Clone("hElecFracWideMC");
// hElecFracWideMC->Divide(hNCellVsEGammasNL_SBSub_MC);
// hElecFracWideMC->Multiply(hNCellVsEGammasNL_SBSub_MC);
hNCellVsEGammasNL_RW_SBSub_MC->Add(hElecFracWideMC, -1);
// reweight to get the conversion contribution
hNCellVsEConversionsNL_RW_data = (TH2F*) hNCellVsEGammasNL_data->Clone("hNCellVsEConversionsNL_RW_data");
// get photon fraction
TH2F* hGammaFracWide = (TH2F*) hNCellVsETrueGammasNL_MC->Clone("hGammaFracWide");
hGammaFracWide->Divide(hNCellVsEGammasNL_MC);
hGammaFracWide->Multiply(hNCellVsEGammasNL_data);
hNCellVsEConversionsNL_RW_data->Add(hGammaFracWide, -1);
// Reweight the MC hadron subtracted ones
hNCellVsEGammasNL_MCSBSub_RW_data = (TH2F*) hNCellVsEGammasNL_MCSBSub_data->Clone("hNCellVsEGammasNL_MCSBSub_RW_data");
TH2F* hElecFracWideMC3 = (TH2F*) hNCellVsEGammasNLTrueElec_MC->Clone("hElecFracWideMC3");
hElecFracWideMC3->Divide(hNCellVsEGammasNL_MCSBSub_MC);
hElecFracWideMC3->Multiply(hNCellVsEGammasNL_MCSBSub_data);
hNCellVsEGammasNL_MCSBSub_RW_data->Add(hElecFracWideMC3, -1);
hNCellVsEGammasNL_MCSBSub_RW_MC = (TH2F*) hNCellVsEGammasNL_MCSBSub_MC->Clone("hNCellVsEGammasNL_MCSBSub_RW_MC");
TH2F* hElecFracWideMC4 = (TH2F*) hNCellVsEGammasNLTrueElec_MC->Clone("hElecFracWideMC4");
hNCellVsEGammasNL_MCSBSub_RW_MC->Add(hElecFracWideMC4, -1);
}
void Effi::ScaleTo(TH1D *h, TH1D *& h2, float down, float up){
float inth2 = h2->Integral(h2->FindBin(down+ 0.0001), h2->FindBin(up - 0.0001));
float inth = h->Integral(h->FindBin(down+ 0.0001), h->FindBin(up - 0.0001));
h->Scale(inth2/inth);
}
// ------------------------------------------
// Plotting
// ------------------------------------------
void Effi::SetPlotting(){
gSystem->Exec(Form("mkdir -p %s_%s/%s/%s", fPeriod.Data(), fMethod.Data(), fSpecialName.Data(), fsuffix.Data()));
if(fPeriod.Contains("13TeV")) sEnergy = "pp, #sqrt{s} = 13 TeV";
if(fPeriod.Contains("8TeV")) sEnergy = "pp, #sqrt{s} = 8 TeV";
StyleSettingsPaper();
hDummyEffi = new TH2F("hDummyEffi","hDummyEffi",1000,0.5, PlotenergyHigh,1000,0.1, 1.31);
SetStyleHistoTH2ForGraphs(hDummyEffi, "#it{E} (GeV)","#nu", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyRatio = new TH2F("hDummyRatio","hDummyRatio",1000,0.5, PlotenergyHigh,1000,0.9, 1.39);
SetStyleHistoTH2ForGraphs(hDummyRatio, "#it{E} (GeV)","#nu_{MC}/#nu_{data}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyCorr = new TH2F("hDummyCorr","hDummyCorr",1000,0.5, PlotenergyHigh,1000,0., 1.39);
SetStyleHistoTH2ForGraphs(hDummyCorr, "#it{E} (GeV)","#rho", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyPurity = new TH2F("hDummyPurity","hDummyPurity",1000,0.5, PlotenergyHigh,1000,-0.05, 1.2);
SetStyleHistoTH2ForGraphs(hDummyPurity, "#it{E} (GeV)","P", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyMInv = new TH2F("hDummyMInv","hDummyMInv",1000,0.01, 0.4,1000,0., 50000);
SetStyleHistoTH2ForGraphs(hDummyMInv, "#it{M}_{inv} (GeV/c^{2})","counts", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyMInvRatio = new TH2F("hDummyMInvRatio","hDummyMInvRatio",1000,0.01, 0.4,1000,0., 20);
SetStyleHistoTH2ForGraphs(hDummyMInvRatio, "#it{M}_{inv} (GeV/c^{2})","ratio to rot. back.", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyMassPos = new TH2F("hDummyMassPos","hDummyMassPos",1000,0., 20,1000,0.8, 1.2);
SetStyleHistoTH2ForGraphs(hDummyMassPos, "E_{clus} (GeV)" ,"#it{M}_{inv}/#it{M}_{#pi^{0}}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyERecVsETrue = new TH2F("hDummyERecVsETrue","hDummyERecVsETrue",1000,0.8, 1.2,1000,0., 1.);
SetStyleHistoTH2ForGraphs(hDummyERecVsETrue, "#it{E}_{rec.}/#it{E}_{true}","normalized counts", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyERecVsETrue2 = new TH2F("hDummyERecVsETrue2","hDummyERecVsETrue2",1000,0., 10,1000,0.9, 1.15);
SetStyleHistoTH2ForGraphs(hDummyERecVsETrue2,"#it{E}_{rec} (GeV)", "#it{E}_{rec.}/#it{E}_{true}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyMCClosure = new TH2F("hDummyMCClosure","hDummyMCClosure",1000,0.5, PlotenergyHigh,1000, 0.8, 1.39);
SetStyleHistoTH2ForGraphs(hDummyMCClosure, "#it{E} (GeV)","MC_{rec.}/MC_{true}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyNCellRatio = new TH2F("hDummyNCellRatio","hDummyNCellRatio",1000,0.7, PlotenergyHigh,1000,0.75, 1.45);
SetStyleHistoTH2ForGraphs(hDummyNCellRatio, "#it{E}_{clus} (GeV)","N_{clus}^{data}/N_{clus}^{MC}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1.2, 510, 510);
hDummyNCellFraction = new TH2F("hDummyNCellFraction","hDummyNCellFraction",1000,0.4, PlotenergyHigh,1000,0., 1.);
SetStyleHistoTH2ForGraphs(hDummyNCellFraction, "#it{E}_{clus} (GeV)","N_{clus}^{Ncell = 1}/N_{clus}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1., 510, 510);
hDummyFraction = new TH2F("hDummyFraction","hDummyFraction",1000,0.4, PlotenergyHigh,1000,0., 1.);
SetStyleHistoTH2ForGraphs(hDummyFraction, "#it{E}_{clus} (GeV)","N_{clus}^{specie}/N_{clus}^{all}", 0.85*textSizeSinglePad,textSizeSinglePad, 0.85*textSizeSinglePad,textSizeSinglePad, 1.1,1., 510, 510);
// gPad->SetLogx();
hDummyCan = new TCanvas("Can", "", 1200, 1000);
DrawPaperCanvasSettings(hDummyCan, 0.1, 0.01, 0.01, 0.1);
hDummyCan2d = new TCanvas("hDummyCan2d", "", 1200, 1000);
DrawPaperCanvasSettings(hDummyCan2d, 0.11, 0.11, 0.003, 0.11);
DrawSetMarkerTGraphErr(grTB_data, 21, 1.5, kBlue + 2, kBlue + 2, 2);
DrawSetMarkerTGraphErr(grTB_MC, 25, 2.5, kBlue + 2, kBlue + 2, 2);
DrawSetMarkerTGraphErr(grTB_Ratio, 21, 1.5, kBlue + 2, kBlue + 2, 2);
DrawSetMarkerTGraphErr(grTB_Corr, 21, 1.5, kBlue + 2, kBlue + 2, 2);
Color_t colAllClus = kRed + 2;
DrawSetMarker(hNCell_AllClus_Effi_data, 20, 2, colAllClus, colAllClus);
DrawSetMarker(hNCell_AllClus_Effi_MC, 2, 3, colAllClus, colAllClus); //hNCell_Gammas_Effi_MC->SetFillColor(kGreen - 6);
DrawSetMarker(hNCell_AllClus_Effi_Ratio, 20, 2, colAllClus, colAllClus);
DrawSetMarker(hNCell_AllClus_Effi_Corr, 20, 2, colAllClus, colAllClus);
//
// // true gamma
DrawSetMarker(hNCell_TrueGammas_MC, 7, 2.8, kBlack, kBlack);
DrawSetMarker(hNCell_TrueGammasSB_MC, 7, 2.8, kRed + 7, kRed + 7);
DrawSetMarker(hNCell_TrueGammas_TrueE_Effi_MC, 7, 2.8, kOrange + 7, kOrange + 7);
DrawSetMarker(hNCell_TrueGammas_RecE_Effi_MC, 7, 2.8, kRed + 2, kRed + 2);
// // true elec
// DrawSetMarker(hNCell_TrueElec_Effi_MC, 2, 2.4, kSpring + 4, kSpring + 4);
//
Color_t colGammaWide = kGreen + 2;
DrawSetMarker(hNCell_Gammas_Effi_data, 34, 2, colGammaWide, colGammaWide);
DrawSetMarker(hNCell_Gammas_Effi_MC, 8, 3, colGammaWide, colGammaWide); //hNCell_Gammas_Effi_MC->SetFillColor(kGreen - 6);
DrawSetMarker(hNCell_Gammas_Effi_Ratio, 34, 2, colGammaWide, colGammaWide);
DrawSetMarker(hNCell_Gammas_Effi_Corr, 34, 2, colGammaWide, colGammaWide);
Color_t colGammaRWWideSBSub = kOrange + 2;
DrawSetMarker(hNCell_Gammas_RW_SBSub_Effi_data, 28, 2, colGammaRWWideSBSub, colGammaRWWideSBSub);
DrawSetMarker(hNCell_Gammas_RW_SBSub_Effi_MC, 8, 3, colGammaRWWideSBSub, colGammaRWWideSBSub); //hNCell_GammasLeft_Effi_MC->SetFillColor(kGreen - 6);
DrawSetMarker(hNCell_Gammas_RW_SBSub_Effi_Ratio, 28, 2, colGammaRWWideSBSub, colGammaRWWideSBSub);
DrawSetMarker(hNCell_Gammas_RW_SBSub_Effi_Corr, 28, 2, colGammaRWWideSBSub, colGammaRWWideSBSub);
Color_t colGammaRWWideHadronsSub = kGray + 2;
DrawSetMarker(hNCell_Gammas_RW_MCHadSub_Effi_data, 29, 2.5, colGammaRWWideHadronsSub, colGammaRWWideHadronsSub);
DrawSetMarker(hNCell_Gammas_RW_MCHadSub_Effi_MC, 9, 3, colGammaRWWideHadronsSub, colGammaRWWideHadronsSub); //hNCell_GammasLeft_Effi_MC->SetFillColor(kGreen - 6);
DrawSetMarker(hNCell_Gammas_RW_MCHadSub_Effi_Ratio, 29, 2.5, colGammaRWWideHadronsSub, colGammaRWWideHadronsSub);
DrawSetMarker(hNCell_Gammas_RW_MCHadSub_Effi_Corr, 29, 2.5, colGammaRWWideHadronsSub, colGammaRWWideHadronsSub);
Color_t colGammaRWWide = kPink + 2;
DrawSetMarker(hNCell_Gammas_RW_Effi_data, 33, 2.4, colGammaRWWide, colGammaRWWide);
DrawSetMarker(hNCell_Gammas_RW_Effi_MC, 7, 3.4, colGammaRWWide, colGammaRWWide); //hNCell_Gammas_RW_Effi_MC->SetFillColor(colGammaRW);
DrawSetMarker(hNCell_Gammas_RW_Effi_Ratio, 33, 2.4, colGammaRWWide, colGammaRWWide);
DrawSetMarker(hNCell_Gammas_RW_Effi_Corr, 33, 2.4, colGammaRWWide, colGammaRWWide);
Color_t colGammaSBWide = kCyan + 2;
DrawSetMarker(hNCell_Gammas_SBSub_Effi_data, 27, 2.4, colGammaSBWide, colGammaSBWide);
DrawSetMarker(hNCell_Gammas_SBSub_Effi_MC, 7, 3.4, colGammaSBWide, colGammaSBWide); //hNCell_Gammas_RW_Effi_MC->SetFillColor(colGammaRW);
DrawSetMarker(hNCell_Gammas_SBSub_Effi_Ratio, 27, 2.4, colGammaSBWide, colGammaSBWide);
DrawSetMarker(hNCell_Gammas_SBSub_Effi_Corr, 27, 2.4, colGammaSBWide, colGammaSBWide);
Color_t colGammaRWWideConvMod = kYellow + 2;
DrawSetMarker(hNCell_Gammas_RW_ConvMod10_Effi_data, 33, 2.4, colGammaRWWideConvMod, colGammaRWWideConvMod);
DrawSetMarker(hNCell_Gammas_RW_ConvMod10_Effi_MC, 7, 3.4, colGammaRWWideConvMod, colGammaRWWideConvMod); //hNCell_Gammas_RW_Effi_MC->SetFillColor(colGammaRW);
DrawSetMarker(hNCell_Gammas_RW_ConvMod10_Effi_Ratio, 33, 2.4, colGammaRWWideConvMod, colGammaRWWideConvMod);