-
Notifications
You must be signed in to change notification settings - Fork 2
/
bmm4validation.cc
2057 lines (1671 loc) · 84.4 KB
/
bmm4validation.cc
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 "bmm4common.h"
// ----------------------------------------------------
// Extract the BDT distribution from MC and estimate the corresponding eff for given BDT, or
// find the proper BDT threshold for the given eff
// available options:
// bsmm - build B->mumu resolution model
// bupsik - build B->J/psi K+ resolution model
//
// NOTE: the "target_cat" can be exactly the category ID (e.g. 2016BFs01_0_0), or the inclusive name of era (2016BFs01).
//
double EffBDTConvertion(TString opt = "bsmm", TString target_cat = "2016BFs01", double alter_BDT = -2., double alter_eff = -2.)
{
cout << ">>> EffBDTConvertion() start" << endl;
TString tag, treename;
if (opt.Contains("bsmm")) {
tag = "bsmm";
treename = "bsmmMc";
}else if (opt.Contains("bupsik")) {
tag = "bupsik";
treename = "bupsikMc";
}else {
cout << ">>> Undefined option: " << opt << endl;
return -1.;
}
TString target_era = target_cat;
for (auto& cat: CatMan.cats)
if (cat.id == target_cat) target_era = cat.era; // retreive the era name if the given target_cat is exactly the category ID
// load the corresponding MC sample
TString filename = Form("input/bmm4/small%s-%s.root",target_era.Data(),treename.Data());
TChain *events = new TChain(treename);
exist_protection(filename);
events->Add(filename);
cout << ">>> Loading from " << filename << ", with " << events->GetEntries() << " entries." << endl;
double m_t, me_t, pt_t, tau_t, taue_t, gtau_t, bdt_t;
int chan_t;
bool muid_t, cnc_t;
events->SetBranchAddress("m", &m_t);
events->SetBranchAddress("me", &me_t);
events->SetBranchAddress("pt", &pt_t);
events->SetBranchAddress("tau", &tau_t);
events->SetBranchAddress("taue", &taue_t);
events->SetBranchAddress("gtau", >au_t);
events->SetBranchAddress("bdt", &bdt_t);
events->SetBranchAddress("chan", &chan_t);
events->SetBranchAddress("muid", &muid_t);
events->SetBranchAddress("cnc", &cnc_t);
vector<double> vec_bdt;
for (int evt=0; evt<events->GetEntries();evt++) {
events->GetEntry(evt);
if (m_t < Mass_bound[0] || m_t > Mass_bound[1] || !muid_t) continue;
if (me_t/m_t < ReducedMassRes_bound[0] || me_t/m_t > ReducedMassRes_bound[1]) continue;
if (bdt_t < -1.) continue;
if (target_cat!=target_era) { // exclusive category ID selection
bool selected = false;
for (auto& cat: CatMan.cats) {
if (cat.id != target_cat) continue;
if (cat.region == chan_t) selected = true;
}
if (!selected) continue;
}
if (tau_t*1E12 < Tau_bound[0] || tau_t*1E12 > Tau_bound[1]) continue;
//if (taue_t*1E12 < TauRes_bound[0] || taue_t*1E12 > TauRes_bound[1]) continue;
vec_bdt.push_back(bdt_t);
}
if (alter_BDT>-1.) {
double eff = 0.;
for (int idx=0; idx<(int)vec_bdt.size(); idx++)
if (vec_bdt[idx]>=alter_BDT) eff += 1.;
return eff/(double)vec_bdt.size();
}
if (alter_eff>=0.) {
sort(vec_bdt.begin(),vec_bdt.end());
return vec_bdt[(int)((double)vec_bdt.size()*(1.-alter_eff))];
}
return -1.;
}
// ----------------------------------------------------
// Prepare the resolution functions for lifetime fit
// current model: double-Gaussian, with <taue> as the main scaling factor
// available options:
// bsmm - build B->mumu resolution model
// bupsik - build B->J/psi K+ resolution model
// --
// triple - using a triple Guassian model
// double - reduced to a double Guassian model
// --
// even - only use the even events
// odd - only use the odd events
//
// NOTE: the "target_cat" can be exactly the category ID (e.g. 2016BFs01_0_0), or the inclusive name of era (2016BFs01).
//
void PrepareLifetimeResolutionModel(RooWorkspace *wspace, TString opt = "bsmm:triple", TString target_cat = "2016BFs01", double alter_BDT = -2.)
{
cout << ">>> PrepareLifetimeResolutionModel() start" << endl;
TString tag, treename;
if (opt.Contains("bsmm")) {
tag = "bsmm";
treename = "bsmmMc";
}else if (opt.Contains("bupsik")) {
tag = "bupsik";
treename = "bupsikMc";
}else {
cout << ">>> Undefined option: " << opt << endl;
return;
}
tag += Form("_%s", target_cat.Data());
TString target_era = target_cat;
for (auto& cat: CatMan.cats)
if (cat.id == target_cat) target_era = cat.era; // retreive the era name if the given target_cat is exactly the category ID
RooRealVar delTau("delTau","",-0.6,+0.6);
TH1D *h_global_deltau = new TH1D("h_global_deltau","",240,-0.6,+0.6);
TH1D *h_global_taue = new TH1D("h_global_taue","",240,TauRes_bound[0],TauRes_bound[1]);
h_global_deltau->Sumw2();
h_global_taue->Sumw2();
// load the corresponding MC sample
TString filename = Form("input/bmm4/small%s-%s.root",target_era.Data(),treename.Data());
TChain *events = new TChain(treename);
exist_protection(filename);
events->Add(filename);
cout << ">>> Loading from " << filename << ", with " << events->GetEntries() << " entries." << endl;
double m_t, me_t, pt_t, tau_t, taue_t, gtau_t, bdt_t;
int chan_t;
bool muid_t, cnc_t;
events->SetBranchAddress("m", &m_t);
events->SetBranchAddress("me", &me_t);
events->SetBranchAddress("pt", &pt_t);
events->SetBranchAddress("tau", &tau_t);
events->SetBranchAddress("taue", &taue_t);
events->SetBranchAddress("gtau", >au_t);
events->SetBranchAddress("bdt", &bdt_t);
events->SetBranchAddress("chan", &chan_t);
events->SetBranchAddress("muid", &muid_t);
events->SetBranchAddress("cnc", &cnc_t);
for (int evt=0; evt<events->GetEntries();evt++) {
events->GetEntry(evt);
if (m_t < Mass_bound[0] || m_t > Mass_bound[1] || !muid_t) continue;
if (me_t/m_t < ReducedMassRes_bound[0] || me_t/m_t > ReducedMassRes_bound[1]) continue;
if (bdt_t < -1.) continue;
if (target_cat==target_era) { // inclusive era selection
int index = CatMan.index(target_era, chan_t, bdt_t);
if (alter_BDT>-1.) {
if (bdt_t<alter_BDT) continue;
}else if (index<0) continue;
}else { // exclusive category ID selection
bool selected = false;
for (auto& cat: CatMan.cats) {
if (cat.id != target_cat) continue;
if (alter_BDT<-1. && cat.region == chan_t &&
bdt_t>=cat.bdt_min && bdt_t<cat.bdt_max) selected = true;
if (alter_BDT>-1. && cat.region == chan_t &&
bdt_t>=alter_BDT) selected = true;
}
if (!selected) continue;
}
if (tau_t*1E12 < Tau_bound[0] || tau_t*1E12 > Tau_bound[1]) continue;
//if (taue_t*1E12 < TauRes_bound[0] || taue_t*1E12 > TauRes_bound[1]) continue;
if (opt.Contains("even") && (evt%2==1)) continue;
if (opt.Contains("odd") && (evt%2==0)) continue;
h_global_deltau->Fill((tau_t-gtau_t)*1E12);
h_global_taue->Fill(taue_t*1E12);
}
delete events;
double mean_taue = h_global_taue->GetMean();
cout << ">>> Average tau_err = " << mean_taue << ", to be used in the resolution function." << endl;
RooDataHist *h_deltau_data = new RooDataHist("h_deltau_data", "", RooArgList(delTau), h_global_deltau);
RooRealVar par_taue(Form("respar_%s_taue",tag.Data()),"",mean_taue);
RooRealVar par_mean(Form("respar_%s_mean",tag.Data()),"",0.0,-0.5,0.5);
RooRealVar par_sig1(Form("respar_%s_sig1",tag.Data()),"",0.7,0.3,1.0);
RooRealVar par_sig2(Form("respar_%s_sig2",tag.Data()),"",1.2,0.7,3.5);
RooRealVar par_sig3(Form("respar_%s_sig3",tag.Data()),"",2.6,1.5,5.5);
RooRealVar par_frac1(Form("respar_%s_frac1",tag.Data()),"",0.4,0.0,0.6);
RooRealVar par_frac2(Form("respar_%s_frac2",tag.Data()),"",0.4,0.0,0.6);
RooProduct par_smean(Form("respar_%s_smean",tag.Data()),"",RooArgList(par_taue,par_mean));
RooProduct par_ssig1(Form("respar_%s_ssig1",tag.Data()),"",RooArgList(par_taue,par_sig1));
RooProduct par_ssig2(Form("respar_%s_ssig2",tag.Data()),"",RooArgList(par_taue,par_sig2));
RooProduct par_ssig3(Form("respar_%s_ssig3",tag.Data()),"",RooArgList(par_taue,par_sig3));
RooGaussian model_g1("model_g1","",delTau,par_smean,par_ssig1);
RooGaussian model_g2("model_g2","",delTau,par_smean,par_ssig2);
RooGaussian model_g3("model_g3","",delTau,par_smean,par_ssig3);
RooAddPdf *model = 0;
if (opt.Contains("triple"))
model = new RooAddPdf("model","",RooArgList(model_g1,model_g2,model_g3),RooArgList(par_frac1,par_frac2));
if (opt.Contains("double")) {
par_frac1.setMax(1.0);
model = new RooAddPdf("model","",RooArgList(model_g1,model_g2),RooArgList(par_frac1));
}
RooFitResult *res = model->fitTo(*h_deltau_data, Extended(false), NumCPU(NCPU), Hesse(false), Save(true), SumW2Error(true));
if (res->status()!=0) converge_protection();
delete res;
RooPlot* frame = delTau.frame(Title(" "));
h_deltau_data->plotOn(frame);
model->plotOn(frame, LineColor(kBlue), LineWidth(3), Name("model"));
frame->SetMinimum(0.);
frame->SetMaximum(frame->GetMaximum()*1.4);
TCanvas* canvas = new TCanvas("canvas", "", 600, 600);
canvas->SetMargin(0.14,0.06,0.13,0.07);
frame->GetYaxis()->SetTitleOffset(1.48);
frame->GetYaxis()->SetTitle("Arbitary Unit");
frame->GetXaxis()->SetTitleOffset(1.15);
frame->GetXaxis()->SetLabelOffset(0.01);
frame->GetXaxis()->SetTitle("tau(rec)-tau(gen) [ps]");
frame->GetXaxis()->SetTitleSize(0.043);
frame->GetYaxis()->SetTitleSize(0.043);
frame->Draw();
TLatex tex;
tex.SetTextFont(42);
tex.SetTextSize(0.035);
tex.SetTextAlign(11);
tex.SetNDC();
tex.DrawLatex(0.14,0.94,"CMS simulation");
TLegend *leg1 = new TLegend(0.45,0.65,0.93,0.91);
leg1->SetFillColor(kWhite);
leg1->SetFillStyle(0);
leg1->SetLineColor(kWhite);
leg1->SetLineWidth(0);
leg1->AddEntry((TObject*)0,Form("<#sigma_{#tau}> = %.4g ps",mean_taue),"");
leg1->AddEntry((TObject*)0,Form("mean = %.4g #pm %.4g",par_mean.getVal(),par_mean.getError()),"");
leg1->AddEntry((TObject*)0,Form("sig1 = %.4g #pm %.4g",par_sig1.getVal(),par_sig1.getError()),"");
leg1->AddEntry((TObject*)0,Form("sig2 = %.4g #pm %.4g",par_sig2.getVal(),par_sig2.getError()),"");
if (opt.Contains("triple")) leg1->AddEntry((TObject*)0,Form("sig3 = %.4g #pm %.4g",par_sig3.getVal(),par_sig3.getError()),"");
leg1->AddEntry((TObject*)0,Form("frac1 = %.4g #pm %.4g",par_frac1.getVal(),par_frac1.getError()),"");
if (opt.Contains("triple")) leg1->AddEntry((TObject*)0,Form("frac2 = %.4g #pm %.4g",par_frac2.getVal(),par_frac2.getError()),"");
leg1->Draw();
canvas->Print(Form("fig/model_taures_%s.pdf",tag.Data()));
RooRealVar *Tau = wspace->var("Tau");
// fixed the parameters and import the model
par_mean.setConstant(true);
par_sig1.setConstant(true);
par_sig2.setConstant(true);
par_sig3.setConstant(true);
par_frac1.setConstant(true);
par_frac2.setConstant(true);
RooGaussModel TauRes_g1(Form("TauRes_g1_%s",tag.Data()),"",*Tau,par_smean,par_ssig1);
RooGaussModel TauRes_g2(Form("TauRes_g2_%s",tag.Data()),"",*Tau,par_smean,par_ssig2);
RooGaussModel TauRes_g3(Form("TauRes_g3_%s",tag.Data()),"",*Tau,par_smean,par_ssig3);
if (opt.Contains("triple")) {
RooAddModel TauRes_Model(Form("TauRes_Model_%s",tag.Data()),"",RooArgList(TauRes_g1,TauRes_g2,TauRes_g3),RooArgList(par_frac1,par_frac2));
wspace->import(TauRes_Model);
}
if (opt.Contains("double")) {
RooAddModel TauRes_Model(Form("TauRes_Model_%s",tag.Data()),"",RooArgList(TauRes_g1,TauRes_g2),RooArgList(par_frac1));
wspace->import(TauRes_Model);
}
// Also produce the projection for taue
h_global_taue->GetYaxis()->SetTitleOffset(1.48);
h_global_taue->GetYaxis()->SetTitle("Arbitary Unit");
h_global_taue->GetXaxis()->SetTitleOffset(1.15);
h_global_taue->GetXaxis()->SetLabelOffset(0.01);
h_global_taue->GetXaxis()->SetTitle("decay time uncertainty #sigma_{#tau} [ps]");
h_global_taue->GetXaxis()->SetTitleSize(0.043);
h_global_taue->GetYaxis()->SetTitleSize(0.043);
h_global_taue->SetFillColor(50);
h_global_taue->SetStats(false);
h_global_taue->Draw("hist");
tex.DrawLatex(0.14,0.94,"CMS simulation");
TLegend *leg2 = new TLegend(0.43,0.80,0.93,0.91);
leg2->SetFillColor(kWhite);
leg2->SetFillStyle(0);
leg2->SetLineColor(kWhite);
leg2->SetLineWidth(0);
leg2->AddEntry((TObject*)0,Form("<#sigma_{#tau}> = %.4g ps",mean_taue),"");
leg2->Draw();
canvas->Print(Form("fig/taures_%s_mc_reco.pdf",tag.Data()));
delete model;
delete h_global_taue;
delete h_global_deltau;
delete h_deltau_data;
delete leg1;
delete leg2;
delete canvas;
}
// ----------------------------------------------------
// Prepare efficiency functions used for lifetime fit
// also produce a histogram PDF for systematic study
//
// available options:
// bsmm - build B->mumu efficiency model
// bupsik - build B->J/psi K+ efficiency model
// --
// one_over_exp - modeling by [0]+[1]*x+[2]*x*x+[3]/(1.+exp(-[4]*x))
// threshold - modeling by threshold function
// --
// taucorr - apply tau-dependent correction
// --
// even - only use the even events
// odd - only use the odd events
//
// NOTE: the "target_cat" can be exactly the category ID (e.g. 2016BFs01_0_0), or the inclusive name of era (2016BFs01).
//
void PrepareLifetimeEfficiencyModel(RooWorkspace *wspace, TString opt = "bsmm:threshold", TString target_cat = "2016BFs01", double alter_BDT = -2.)
{
cout << ">>> PrepareLifetimeEfficiencyModel() start" << endl;
TString tag, treename;
if (opt.Contains("bsmm")) {
tag = "bsmm";
treename = "bsmmMc";
}else if (opt.Contains("bupsik")) {
tag = "bupsik";
treename = "bupsikMc";
}else {
cout << ">>> Undefined option: " << opt << endl;
return;
}
tag += Form("_%s", target_cat.Data());
TH1D *h_taucorr = 0;
if (opt.Contains("taucorr")) {
h_taucorr = (TH1D *)wspace->obj(Form("h_taucorr_%s",tag.Data()));
tag += "_taucorr";
}
TString target_era = target_cat;
for (auto& cat: CatMan.cats)
if (cat.id == target_cat) target_era = cat.era; // retreive the era name if the given target_cat is exactly the category ID
vector<double> xbins = {
0.5,0.625,0.75,0.875,
1.,1.125,1.25,1.375,1.5,1.625,1.75,1.875,
2.,2.125,2.25,2.375,2.5,2.75,
3.,3.25,3.5,3.75,
4.,4.5,5.,5.5,6.,7.,8.,9.,10.,12.};
TH1D *h_global_taueff = new TH1D("h_global_taueff","",xbins.size()-1,xbins.data());
h_global_taueff->Sumw2();
TH1D *h_taureco_mc = new TH1D(Form("h_taureco_mc_%s",tag.Data()),"",xbins.size()-1,xbins.data());
h_taureco_mc->Sumw2();
// load the corresponding MC sample
TString filename = Form("input/bmm4/small%s-%s.root",target_era.Data(),treename.Data());
TChain *events = new TChain(treename);
exist_protection(filename);
events->Add(filename);
cout << ">>> Loading from " << filename << ", with " << events->GetEntries() << " entries." << endl;
double m_t, me_t, pt_t, tau_t, taue_t, gtau_t, bdt_t;
int chan_t;
bool muid_t, cnc_t;
events->SetBranchAddress("m", &m_t);
events->SetBranchAddress("me", &me_t);
events->SetBranchAddress("pt", &pt_t);
events->SetBranchAddress("tau", &tau_t);
events->SetBranchAddress("taue", &taue_t);
events->SetBranchAddress("gtau", >au_t);
events->SetBranchAddress("bdt", &bdt_t);
events->SetBranchAddress("chan", &chan_t);
events->SetBranchAddress("muid", &muid_t);
events->SetBranchAddress("cnc", &cnc_t);
for (int evt=0; evt<events->GetEntries();evt++) {
events->GetEntry(evt);
if (m_t < Mass_bound[0] || m_t > Mass_bound[1] || !muid_t) continue;
if (me_t/m_t < ReducedMassRes_bound[0] || me_t/m_t > ReducedMassRes_bound[1]) continue;
if (bdt_t < -1.) continue;
if (target_cat==target_era) { // inclusive era selection
int index = CatMan.index(target_era, chan_t, bdt_t);
if (alter_BDT>-1.) {
if (bdt_t<alter_BDT) continue;
}else if (index<0) continue;
}else { // exclusive category ID selection
bool selected = false;
for (auto& cat: CatMan.cats) {
if (cat.id != target_cat) continue;
if (alter_BDT<-1. && cat.region == chan_t &&
bdt_t>=cat.bdt_min && bdt_t<cat.bdt_max) selected = true;
if (alter_BDT>-1. && cat.region == chan_t &&
bdt_t>=alter_BDT) selected = true;
}
if (!selected) continue;
}
//if (tau_t*1E12 < Tau_bound[0] || tau_t*1E12 > Tau_bound[1]) continue;
if (tau_t*1E12 < 0.5 || tau_t*1E12 > Tau_bound[1]) continue; // allow a litte bit more to the lower side
//if (taue_t*1E12 < TauRes_bound[0] || taue_t*1E12 > TauRes_bound[1]) continue;
if (opt.Contains("even") && (evt%2==1)) continue;
if (opt.Contains("odd") && (evt%2==0)) continue;
h_global_taueff->Fill(gtau_t*1E12);
h_taureco_mc->Fill(tau_t*1E12);
}
delete events;
TH1D *h_taueff_norm = new TH1D("h_taueff_norm","",xbins.size()-1,xbins.data());
h_taueff_norm->Sumw2();
// extract lifetime & resolution
RooRealVar *Tau = wspace->var("Tau");
//RooResolutionModel *TauRes_Model = (RooResolutionModel*)wspace->obj(Form("TauRes_Model_%s",tag.Data()));
RooTruthModel *TauRes_Model = new RooTruthModel("TauRes_Model","",*Tau); // ideal model
RooRealVar EffTau("EffTau","",1.6);
RooDecay RawDecay("RawDecay","",*Tau,EffTau,*TauRes_Model,RooDecay::SingleSided);
if (tag.Contains("bsmm")) EffTau.setVal(1.472);
if (tag.Contains("bupsik") && (target_era.Contains("2011") || target_era.Contains("2012"))) EffTau.setVal(1.671);
if (tag.Contains("bupsik") && target_era.Contains("2016")) EffTau.setVal(1.638);
double scale_factor = 0.;
for (int bin=1; bin<=h_taueff_norm->GetNbinsX(); bin++) {
Tau->setRange("bin",h_taueff_norm->GetBinLowEdge(bin),h_taueff_norm->GetBinLowEdge(bin)+h_taueff_norm->GetBinWidth(bin));
RooAbsReal* area = RawDecay.createIntegral(*Tau,Range("bin"));
h_taueff_norm->SetBinContent(bin,area->getVal());
delete area;
double ratio = h_global_taueff->GetBinContent(bin)/h_taueff_norm->GetBinContent(bin);
if (ratio>scale_factor) scale_factor = ratio;
}
h_taueff_norm->Scale(scale_factor);
delete TauRes_Model;
for (int bin=1; bin<=h_global_taueff->GetNbinsX(); bin++) {
double val = h_global_taueff->GetBinContent(bin)/h_taueff_norm->GetBinContent(bin);
double err = h_global_taueff->GetBinError(bin)/h_taueff_norm->GetBinContent(bin);
h_global_taueff->SetBinContent(bin,val);
h_global_taueff->SetBinError(bin,err);
}
if (h_taucorr!=0) h_global_taueff->Multiply(h_taucorr);
TCanvas* canvas = new TCanvas("canvas", "", 600, 600);
canvas->SetMargin(0.14,0.06,0.13,0.07);
h_global_taueff->GetYaxis()->SetTitleOffset(1.48);
h_global_taueff->GetYaxis()->SetTitle("Arbitary Unit");
h_global_taueff->GetXaxis()->SetTitleOffset(1.15);
h_global_taueff->GetXaxis()->SetLabelOffset(0.01);
h_global_taueff->GetXaxis()->SetTitle("#tau [ps]");
h_global_taueff->GetXaxis()->SetTitleSize(0.043);
h_global_taueff->GetYaxis()->SetTitleSize(0.043);
h_global_taueff->SetStats(false);
h_global_taueff->SetLineColor(kBlack);
h_global_taueff->SetMarkerStyle(20);
h_global_taueff->SetMaximum(h_global_taueff->GetMaximum()*1.2);
TF1 *effmodel = 0;
// Chandi's model
if (opt.Contains("one_over_exp")) {
effmodel = new TF1("effmodel","[0]+[1]*x+[2]*x*x+[3]/(1.+exp(-[4]*x))",xbins.front(),xbins.back());
effmodel->SetParameters(0.12, 0.006, 0., 0.2, 1.2);
}
// Threshold func.
if (opt.Contains("threshold")) {
effmodel = new TF1("effmodel","[0]+[1]*pow(x,[2])*exp([3]*x+[4]*x*x)",xbins.front(),xbins.back());
effmodel->SetParameters(-4., 4., 0.3, 0., 0.);
}
h_global_taueff->Fit("effmodel","VI","", 0.875, Tau_bound[1]); // 1st fit
h_global_taueff->Fit("effmodel","VI","", 0.875, Tau_bound[1]); // 2nd fit
int fitstat = h_global_taueff->Fit("effmodel","VI","", 0.875, Tau_bound[1]); // 3rd fit
cout << ">>> Fit status = " << fitstat << endl;
if (fitstat!=0 && fitstat!=4000) converge_protection();
TLatex tex;
tex.SetTextFont(42);
tex.SetTextSize(0.035);
tex.SetTextAlign(11);
tex.SetNDC();
tex.DrawLatex(0.14,0.94,"CMS simulation");
TLegend *leg1 = new TLegend(0.52,0.60,0.93,0.91);
if (opt.Contains("one_over_exp")) leg1->SetHeader("Fit to f(t) = k_{1} + k_{2}t + k_{3}t^{2} + #frac{k_{4}}{1+exp(-k_{5}t)}","C");
if (opt.Contains("threshold")) leg1->SetHeader("Fit to f(t) = k_{1} + k_{2}*t^{k_{3}}exp(k_{4}t+k_{5}t^{2})]","C");
//leg1->AddEntry((TObject*)0,"","");
leg1->SetFillColor(kWhite);
leg1->SetFillStyle(0);
leg1->SetLineColor(kWhite);
leg1->SetLineWidth(0);
for (int i=0; i<5; i++)
leg1->AddEntry((TObject*)0,Form("k_{%d} = %.4g #pm %.4g",i+1,effmodel->GetParameter(i),effmodel->GetParError(i)),"");
leg1->AddEntry((TObject*)0,Form("#chi^{2}/NDF = %.3g/%d",effmodel->GetChisquare(),effmodel->GetNDF()),"");
leg1->Draw();
canvas->Print(Form("fig/model_globaleff_%s.pdf",tag.Data()));
RooRealVar *par[5];
for (int i=0; i<5; i++) {
par[i] = new RooRealVar(Form("effpar_%s_k%d",tag.Data(),i+1),"",effmodel->GetParameter(i));
par[i]->setError(effmodel->GetParError(i));
}
TString formula = "";
if (opt.Contains("one_over_exp")) {
formula += Form("max(effpar_%s_k1",tag.Data());
formula += Form("+effpar_%s_k2*Tau",tag.Data());
formula += Form("+effpar_%s_k3*Tau*Tau",tag.Data());
formula += Form("+effpar_%s_k4/(1.+exp(-Tau*effpar_%s_k5)),1E-5)",tag.Data(),tag.Data());
}
// the factor 0.5 is to protect the "efficiency" should be always below 1
if (opt.Contains("threshold")) {
formula += Form("max(effpar_%s_k1+",tag.Data());
formula += Form("effpar_%s_k2*",tag.Data());
formula += Form("pow(Tau,effpar_%s_k3)*",tag.Data());
formula += Form("exp(effpar_%s_k4*Tau+effpar_%s_k5*Tau*Tau),1E-5)*0.5",tag.Data(),tag.Data());
}
RooArgList varlist;
varlist.add(*Tau);
for (int i=0; i<5; i++) varlist.add(*par[i]);
RooFormulaVar TauEff_Model(Form("TauEff_Model_%s",tag.Data()),formula,varlist);
wspace->import(TauEff_Model);
// alternative histogram model
TH1D *h_tau_tmp = new TH1D("h_tau_tmp","",(int)((Tau_bound[1]-Tau_bound[0])*8.),Tau_bound[0],Tau_bound[1]); // convert to fixed bin width histogram
for (int i=1; i<=h_tau_tmp->GetNbinsX(); i++) {
for (int bin=1; bin<=h_global_taueff->GetNbinsX(); bin++) {
double x = h_tau_tmp->GetBinCenter(i);
double min = h_global_taueff->GetBinLowEdge(bin);
double max = min+h_global_taueff->GetBinWidth(bin);
if (x>=min && x<max) h_tau_tmp->SetBinContent(i,h_global_taueff->GetBinContent(bin));
}
}
RooDataHist h_global_taueff_data(Form("h_global_taueff_data_%s",tag.Data()), "", *Tau, h_tau_tmp);
RooHistPdf TauEff_Model_Hist(Form("TauEff_Model_Hist_%s",tag.Data()),"",*Tau,h_global_taueff_data,0);
wspace->import(TauEff_Model_Hist);
RooPlot* frame = Tau->frame(Title(" "));
TauEff_Model_Hist.plotOn(frame, DrawOption("L"), LineColor(kBlue), LineWidth(2), LineStyle(1), NumCPU(NCPU));
frame->GetYaxis()->SetTitleOffset(1.48);
frame->GetYaxis()->SetTitle("Arbitary Unit");
frame->GetXaxis()->SetTitleOffset(1.15);
frame->GetXaxis()->SetLabelOffset(0.01);
frame->GetXaxis()->SetTitle("#tau [ps]");
frame->GetXaxis()->SetTitleSize(0.043);
frame->GetYaxis()->SetTitleSize(0.043);
frame->SetStats(false);
frame->Draw();
canvas->Print(Form("fig/model_globaleff_histpdf_%s.pdf",tag.Data()));
if (!opt.Contains("taucorr")) wspace->import(*h_taureco_mc);
delete h_taureco_mc;
for (int i=0; i<5; i++) delete par[i];
delete h_global_taueff;
delete effmodel;
delete leg1;
delete canvas;
delete frame;
}
// ----------------------------------------------------
// available options:
// bsmm - test with B->mumu MC
// bupsik - test with B->J/psi K+ MC
// --
// genonly - fit to pure generated decay time
// geneff - fit to generated decay time, with efficiency correction
// reco - fit to reco decay time
// toybkg - mixing with toy combinatorial background
//
// NOTE: the "target_cat" can be exactly the category ID (e.g. 2016BFs01_0_0), or the inclusive name of era (2016BFs01).
//
void PerformMCTauSPlotStudy(RooWorkspace *wspace, TString opt = "bsmm:reco", TString target_cat = "2016BFs01", double alter_BDT = -2.)
{
cout << ">>> PerformMCTauSPlotStudy() start" << endl;
TString tag, filename, treename, filename_eff;
if (opt.Contains("bsmm")) {
tag = "bsmm";
treename = "bsmmMc";
}else if (opt.Contains("bupsik")) {
tag = "bupsik";
treename = "bupsikMc";
}else {
cout << ">>> Undefined option: " << opt << endl;
return;
}
tag += Form("_%s", target_cat.Data());
TString target_era = target_cat;
for (auto& cat: CatMan.cats)
if (cat.id == target_cat) target_era = cat.era; // retreive the era name if the given target_cat is exactly the category ID
filename = Form("input/bmm4/small%s-%s.root",target_era.Data(),treename.Data());
filename_eff = Form("input/bmm4/eff%s-%s.root",target_era.Data(),treename.Data());
TChain *events = new TChain(treename);
exist_protection(filename);
events->Add(filename);
TChain *effTree = new TChain("effTree");
//exist_protection(filename_eff);
effTree->Add(filename_eff);
double m_t, me_t, pt_t, tau_t, taue_t, gtau_t, bdt_t;
int chan_t;
bool muid_t, cnc_t;
events->SetBranchAddress("m", &m_t);
events->SetBranchAddress("me", &me_t);
events->SetBranchAddress("pt", &pt_t);
events->SetBranchAddress("tau", &tau_t);
events->SetBranchAddress("taue", &taue_t);
events->SetBranchAddress("gtau", >au_t);
events->SetBranchAddress("bdt", &bdt_t);
events->SetBranchAddress("chan", &chan_t);
events->SetBranchAddress("muid", &muid_t);
events->SetBranchAddress("cnc", &cnc_t);
float effgtau_t;
effTree->SetBranchAddress("gtau", &effgtau_t);
// EffTau model
RooRealVar *Mass = wspace->var("Mass");
RooRealVar *Tau = wspace->var("Tau");
RooResolutionModel *TauRes_Model = (RooResolutionModel*)wspace->obj(Form("TauRes_Model_%s",tag.Data()));
RooFormulaVar *TauEff_Model = (RooFormulaVar*)wspace->obj(Form("TauEff_Model_%s",tag.Data()));
RooRealVar EffTau("EffTau","",1.6,0.1,5.0);
RooDecay RawDecay_reco("RawDecay_reco","",*Tau,EffTau,*TauRes_Model,RooDecay::SingleSided);
RooEffProd Tau_pdf_reco("Tau_pdf_reco","",RawDecay_reco,*TauEff_Model);
RooTruthModel TauRes_TruthModel("TauRes_TruthModel","",*Tau); // ideal model
RooDecay Tau_pdf_genonly("Tau_pdf_genonly","",*Tau,EffTau,TauRes_TruthModel,RooDecay::SingleSided);
RooEffProd Tau_pdf_geneff("Tau_pdf_geneff","",Tau_pdf_genonly,*TauEff_Model);
RooAbsPdf *Tau_pdf = &Tau_pdf_reco;
if (opt.Contains("geneff")) Tau_pdf = &Tau_pdf_geneff;
// place holder for sPlot
//TH1D *h_tau = new TH1D("h_tau", "", Tau_bins.size()-1, Tau_bins.data());
TH1D *h_tau = new TH1D("h_tau", "", (int)((Tau_bound[1]-Tau_bound[0])*10.), Tau_bound[0], Tau_bound[1]);
h_tau->Sumw2();
if (opt.Contains("genonly")) { // generater tau
for (int evt=0; evt<effTree->GetEntries();evt++) {
effTree->GetEntry(evt);
h_tau->Fill(effgtau_t*1E12);
}
Tau_pdf = &Tau_pdf_genonly;
}else {
RooDataSet *rds = new RooDataSet("rds","",RooArgSet(*Tau));
for (int evt=0; evt<events->GetEntries();evt++) {
events->GetEntry(evt);
if (m_t < Mass_bound[0] || m_t > Mass_bound[1] || !muid_t) continue;
if (me_t/m_t < ReducedMassRes_bound[0] || me_t/m_t > ReducedMassRes_bound[1]) continue;
if (bdt_t < -1.) continue;
if (target_cat==target_era) { // inclusive era selection
int index = CatMan.index(target_era, chan_t, bdt_t);
if (alter_BDT>-1.) {
if (bdt_t<alter_BDT) continue;
}else if (index<0) continue;
}else { // exclusive category ID selection
bool selected = false;
for (auto& cat: CatMan.cats) {
if (cat.id != target_cat) continue;
if (alter_BDT<-1. && cat.region == chan_t &&
bdt_t>=cat.bdt_min && bdt_t<cat.bdt_max) selected = true;
if (alter_BDT>-1. && cat.region == chan_t &&
bdt_t>=alter_BDT) selected = true;
}
if (!selected) continue;
}
// tau cuts
if (tau_t*1E12 < Tau_bound[0] || tau_t*1E12 > Tau_bound[1]) continue;
//if (taue_t*1E12 < TauRes_bound[0] || taue_t*1E12 > TauRes_bound[1]) continue;
if (opt.Contains("geneff")) Tau->setVal(gtau_t*1E12);
else Tau->setVal(tau_t*1E12);
rds->add(RooArgSet(*Tau));
}
cout << ">>> " << rds->numEntries() << " MC events to be included in the fit" << endl;
// Add toy background
if (opt.Contains("toybkg")) {
int ns = rds->numEntries();
int nb = rds->numEntries()*50; // assume a 50x background
double mass_mean_sig = 5.35;
if (opt.Contains("bupsik")) {
nb = rds->numEntries()*5; // assume a 5x background for J/psi K+
mass_mean_sig = 5.28;
}
RooGaussian Mass_pdf_sig("Mass_pdf_sig", "", *Mass,RooConst(mass_mean_sig),RooConst(0.035));
RooDataSet *rds_toymass = Mass_pdf_sig.generate(RooArgSet(*Mass),ns);
rds->merge(rds_toymass);
delete rds_toymass;
RooChebychev Mass_pdf_comb("Mass_pdf_comb", "", *Mass, RooArgList(RooConst(0.)));
RooRealVar TauComb("TauComb","",1.2); // assume an 1.2 ps lifetime for combintorial PDF
RooDecay RawDecay_comb("RawDecay_comb","",*Tau,TauComb,*TauRes_Model,RooDecay::SingleSided);
RooEffProd Tau_pdf_comb("Tau_pdf_comb","",RawDecay_comb,*TauEff_Model);
RooProdPdf pdf_comb("pdf_comb","",Mass_pdf_comb,Tau_pdf_comb);
RooDataSet *rds_toybkg = pdf_comb.generate(RooArgSet(*Mass,*Tau),nb);
rds->append(*rds_toybkg);
delete rds_toybkg;
// Make a projection for toy mass distribution
RooAddPdf Mass_pdf("Mass_pdf","",
RooArgList(Mass_pdf_sig, Mass_pdf_comb),
RooArgList(RooConst(ns), RooConst(nb)));
RooPlot* frame_m = Mass->frame();
rds->plotOn(frame_m,Binning(160));
Mass_pdf.plotOn(frame_m);
Mass_pdf.plotOn(frame_m,Components("Mass_pdf_sig"),LineColor(kRed-10),LineWidth(2),LineStyle(kSolid),FillColor(kRed-10), VLines(), DrawOption("F"));
Mass_pdf.plotOn(frame_m,Components("Mass_pdf_comb"),LineColor(kCyan+2),LineWidth(3),LineStyle(7));
TCanvas* canvas_m = new TCanvas("canvas_m", "", 600, 600);
canvas_m->SetMargin(0.14,0.06,0.13,0.07);
frame_m->GetYaxis()->SetTitleOffset(1.48);
frame_m->GetYaxis()->SetTitle("Entries");
frame_m->GetXaxis()->SetTitleOffset(1.15);
frame_m->GetXaxis()->SetLabelOffset(0.01);
frame_m->GetXaxis()->SetTitle("Mass [GeV]");
frame_m->GetXaxis()->SetTitleSize(0.043);
frame_m->GetYaxis()->SetTitleSize(0.043);
frame_m->SetStats(false);
frame_m->SetTitle("");
frame_m->Draw();
canvas_m->Print(Form("fig/proj_mass_%s_mcstudy_toybkg.pdf",tag.Data()));
delete frame_m;
delete canvas_m;
// Now calculate sWeights
enum {_sig, _comb, _nspec};
double yield[_nspec];
yield[_sig] = ns;
yield[_comb] = nb;
TMatrixD covInv(_nspec, _nspec);
covInv = 0.;
RooArgSet norm(*Mass);
for (int evt=0; evt<rds->numEntries(); evt++) {
const RooArgSet* arg = rds->get(evt);
Mass->setVal(arg->getRealValue("Mass"));
Tau->setVal(arg->getRealValue("Tau"));
double pdf[_nspec];
pdf[_sig] = Mass_pdf_sig.getVal(&norm);
pdf[_comb] = Mass_pdf_comb.getVal(&norm);
double pdf_total = 0.;
for (int idx = 0; idx<_nspec; idx++) pdf_total += yield[idx]*pdf[idx];
for (int row = 0; row<_nspec; row++)
for (int col = 0; col<_nspec; col++)
covInv(row,col) += pdf[row]*pdf[col]/(pdf_total*pdf_total);
}
TMatrixD covMatrix(TMatrixD::kInverted,covInv);
for (int evt=0; evt<rds->numEntries(); evt++) {
const RooArgSet* arg = rds->get(evt);
Mass->setVal(arg->getRealValue("Mass"));
Tau->setVal(arg->getRealValue("Tau"));
double pdf[_nspec];
pdf[_sig] = Mass_pdf_sig.getVal(&norm);
pdf[_comb] = Mass_pdf_comb.getVal(&norm);
double denominator = 0.;
for (int idx = 0; idx<_nspec; idx++) denominator += yield[idx]*pdf[idx];
double numerator = 0.;
for (int idx = 0; idx<_nspec; idx++) numerator += covMatrix(_sig,idx)*pdf[idx];
double weight = numerator/denominator;
h_tau->Fill(arg->getRealValue("Tau"),weight);
}
}else { // signal RECO only
for (int evt=0; evt<rds->numEntries(); evt++) {
const RooArgSet* arg = rds->get(evt);
h_tau->Fill(arg->getRealValue("Tau"));
}
}
delete rds;
}
// Binned weighted likelihood fit w/ PDF bin integration
RooFitResult *res1 = NULL, *res2 = NULL;
Fit_sPlot(h_tau, Tau_pdf, Tau, &EffTau, &res1, &res2);
// Projection
RooPlot* frame = Tau->frame(Title(" "));
h_tau->SetMarkerStyle(1);
h_tau->SetLineColor(kBlack);
RooDataHist *h_tau_data = new RooDataHist("h_tau_data", "", RooArgList(*Tau), h_tau);
h_tau_data->plotOn(frame,MarkerStyle(1),LineColor(kBlack));
Tau_pdf->plotOn(frame, DrawOption("L"), LineColor(kBlue), LineWidth(2), LineStyle(1), NumCPU(NCPU));
TCanvas* canvas = new TCanvas("canvas", "", 600, 600);
canvas->SetMargin(0.14,0.06,0.13,0.07);
frame->GetYaxis()->SetTitleOffset(1.48);
frame->GetYaxis()->SetTitle("Entries");
frame->GetXaxis()->SetTitleOffset(1.15);
frame->GetXaxis()->SetLabelOffset(0.01);
frame->GetXaxis()->SetTitle("Decay time [ps]");
frame->GetXaxis()->SetTitleSize(0.043);
frame->GetYaxis()->SetTitleSize(0.043);
frame->SetStats(false);
frame->Draw("E");
TLatex tex;
tex.SetTextFont(42);
tex.SetTextSize(0.035);
tex.SetTextAlign(11);
tex.SetNDC();
tex.DrawLatex(0.14,0.94,"CMS Preliminary");
TLine lin;
lin.SetLineColor(kGray+1);
lin.SetLineWidth(2);
lin.SetLineStyle(7);
lin.DrawLine(1.,0.,12.,0.);
canvas->Update();
TLegend *leg1 = new TLegend(0.50,0.86,0.91,0.91);
leg1->SetNColumns(1);
leg1->SetFillColor(kWhite);
leg1->SetLineColor(kWhite);
if (opt.Contains("bsmm")) leg1->AddEntry(h_tau, "B_{s} #rightarrow #mu^{+}#mu^{-} MC", "lep");
if (opt.Contains("bupsik")) leg1->AddEntry(h_tau, "B^{+} #rightarrow J/#psi K^{+} MC", "lep");
leg1->Draw();
TString pdf_filename = Form("fig/tau_splot_%s_mc_reco.pdf",tag.Data());
if (opt.Contains("genonly")) pdf_filename = Form("fig/tau_splot_%s_mc_genonly.pdf",tag.Data());
if (opt.Contains("geneff")) pdf_filename = Form("fig/tau_splot_%s_mc_geneff.pdf",tag.Data());
if (opt.Contains("toybkg")) pdf_filename = Form("fig/tau_splot_%s_mc_toybkg.pdf",tag.Data());
canvas->Print(pdf_filename);
delete h_tau_data;
delete h_tau;
delete leg1;
delete frame;
delete canvas;
delete res1;
delete res2;
delete events;
delete effTree;
}
// ----------------------------------------------------
// available options:
// bsmm - test with standard B->mumu MC
// bsmmXX - test with B->mumu MC, generated with different lifetime
// --
// genonly - fit to pure generated decay time
// geneff - fit to generated decay time, with efficiency correction
// reco - fit to reco decay time
//
// NOTE: the "target_cat" can be exactly the category ID (e.g. 2016BFs01_0_0), or the inclusive name of era (2016BFs01).
//
void PerformAlterMCTauSPlotStudy(RooWorkspace *wspace, TString opt = "bsmm35:reco", TString target_cat = "2016BFs01", double alter_BDT = -2.)
{
cout << ">>> PerformAlterMCTauSPlotStudy() start" << endl;
TString tag, filename, treename, filename_eff, proc;
if (opt.Contains("bsmm35")) proc = "bsmm35";
else if (opt.Contains("bsmm40")) proc = "bsmm40";
else if (opt.Contains("bsmm45")) proc = "bsmm45";
else if (opt.Contains("bsmm50")) proc = "bsmm50";
else if (opt.Contains("bsmm55")) proc = "bsmm55";
else if (opt.Contains("bsmm60")) proc = "bsmm60";
else if (opt.Contains("bsmm65")) proc = "bsmm65";
else if (opt.Contains("bsmm66")) proc = "bsmm66";
else if (opt.Contains("bsmm67")) proc = "bsmm67";
else if (opt.Contains("bsmm68")) proc = "bsmm68";
else if (opt.Contains("bsmm69")) proc = "bsmm69";
else if (opt.Contains("bsmm70")) proc = "bsmm70";
else if (opt.Contains("bsmm75")) proc = "bsmm75";
else if (opt.Contains("bsmm80")) proc = "bsmm80";
else if (opt.Contains("bsmm")) proc = "bsmm";
else {
cout << ">>> Undefined option: " << opt << endl;
return;
}
treename = "events";
tag = Form("bsmm_%s", target_cat.Data());
TString target_era = target_cat;
for (auto& cat: CatMan.cats)
if (cat.id == target_cat) target_era = cat.era; // retreive the era name if the given target_cat is exactly the category ID
filename = Form("input/bmm4/mini%s-%sMc.root",target_era.Data(),proc.Data());
filename_eff = Form("input/bmm4/eff%s-%sMc.root",target_era.Data(),proc.Data());
TChain *events = new TChain(treename);
exist_protection(filename);
events->Add(filename);
TChain *effTree = new TChain("effTree");
//exist_protection(filename_eff);
effTree->Add(filename_eff);
double m_t, me_t, pt_t, tau_t, taue_t, gtau_t, bdt_t;
int chan_t;
bool gmuid_t, cnc_t, tos_t;
events->SetBranchAddress("m", &m_t);
events->SetBranchAddress("me", &me_t);
events->SetBranchAddress("pt", &pt_t);
events->SetBranchAddress("tau", &tau_t);
events->SetBranchAddress("taue", &taue_t);
events->SetBranchAddress("gtau", >au_t);
events->SetBranchAddress("bdt", &bdt_t);
events->SetBranchAddress("chan", &chan_t);
events->SetBranchAddress("gmuid", &gmuid_t);
events->SetBranchAddress("cnc", &cnc_t);
events->SetBranchAddress("tos", &tos_t);