forked from acarvalh/Limit_codes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
R2GGBBFitter_mgg_addhiggs.cc
executable file
·1705 lines (1633 loc) · 78.1 KB
/
R2GGBBFitter_mgg_addhiggs.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
// C++ headers
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <boost/program_options.hpp>
// ROOT headers
#include "TROOT.h"
#include "TSystem.h"
#include <TFile.h>
#include <TTree.h>
#include <TH2F.h>
#include <TLatex.h>
#include <TGraphAsymmErrors.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TLegend.h>
// RooFit headers
#include <RooWorkspace.h>
#include <RooFitResult.h>
#include <RooRealVar.h>
#include <RooCategory.h>
#include <RooArgSet.h>
#include <HLFactory.h>
#include <RooDataSet.h>
#include <RooFormulaVar.h>
#include <RooGenericPdf.h>
#include <RooPlot.h>
#include <RooAbsPdf.h>
#include <RooBernstein.h>
#include <RooExtendPdf.h>
#include <RooMinimizer.h>
#include <RooStatsUtils.h>
// namespaces
using namespace std;
using namespace RooFit;
using namespace RooStats;
namespace po = boost::program_options;
//Important options first
Bool_t doblinding = true; //True if you want to blind
// this one is for mgg fit
Int_t NCAT =0;
Int_t sigMass;
bool addHiggs=true;
void AddSigData(RooWorkspace*, Float_t, TString);
void AddHigData(RooWorkspace*, Float_t,TString,int);
void AddBkgData(RooWorkspace*, TString);
void SigModelFit(RooWorkspace*, Float_t);
void HigModelFit(RooWorkspace*, Float_t, int);
void MakePlots(RooWorkspace*, Float_t);
void MakePlotsHiggs(RooWorkspace* w, Float_t Mass);
void MakeSigWS(RooWorkspace* w, const char* filename);
void MakeHigWS(RooWorkspace* w, const char* filename,int);
void MakeBkgWS(RooWorkspace* w, const char* filename);//,
// const char* filenameh0, const char* filenameh1, const char* filenameh2, const char* filenameh4);
void MakeDataCard(RooWorkspace* w, const char* filename, const char* filename1,
const char*, const char*, const char*, const char*, const char*, Bool_t);
void MakeDataCardonecatnohiggs(RooWorkspace* w, TString filename1, TString filename2, Bool_t);
void SetParamNames(RooWorkspace*);
void SetConstantParams(const RooArgSet* params);
void style();
RooFitResult* BkgModelFitBernstein(RooWorkspace*, Bool_t);
RooArgSet* defineVariables()
{
RooRealVar* mgg = new RooRealVar("mgg","M(#gamma#gamma)",100,180,"GeV");
//RooRealVar* mtot = new RooRealVar("mtot","M(#gamma#gammajj)",200,1600,"GeV");
//RooRealVar* mjj = new RooRealVar("mjj","M(jj)",100,1600,"GeV");
RooRealVar* evWeight = new RooRealVar("evWeight","HqT x PUwei",0,100,"");
RooCategory* cut_based_ct = new RooCategory("cut_based_ct","event category 4") ;
//
cut_based_ct->defineType("cat4_0",0);
cut_based_ct->defineType("cat4_1",1);
cut_based_ct->defineType("cat4_2",2);
cut_based_ct->defineType("cat4_3",3);
//
RooArgSet* ntplVars = new RooArgSet(*mgg, * cut_based_ct, *evWeight);
ntplVars->add(*mgg);
//ntplVars->add(*mtot);
//ntplVars->add(*mjj);
ntplVars->add(*cut_based_ct);
return ntplVars;
}
int main(int argc, const char* argv[])
{
Float_t mass;
Bool_t doBands;
int version;
string analysisType;
string nonresFile;
Bool_t useSigTheoryUnc;
try
{
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("Hmass", po::value<float>(&mass)->default_value(125.02), "Mass of SM Higgs. Default is 125.02.")
("doBands", po::value<bool>(&doBands)->default_value(true), "Option to calculate and show 1,2 sigma bands on bkg fit.")
("version,v", po::value<int>(&version)->default_value(42), "Version for limit trees.")
("ncat,n", po::value<int>(&NCAT)->default_value(2), "Number of categories to fit")
("sigMass", po::value<int>(&sigMass)->default_value(0), "Mass of signal. 0 is for nonresonant.")
("analysisType", po::value<string>(&analysisType)->default_value("fitToMgg_nonresSearch_withKinFit"), "Can choose among fitToMgg_{nonres,res}Search_with{RegKin,Kin}Fit")
("nonresFile", po::value<string>(&nonresFile)->default_value("Lam_1d0_Yt_1d0_c2_0d0"), "nonres signal to run in the case sigMass is 0. default is the SM value.")
("useSigTheoryUnc", po::value<bool>(&useSigTheoryUnc)->default_value(false), "option to add an uncertainty to the datacard for the SM diHiggs theory uncertainty. Default is off.")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
} catch(exception& e) {
cerr << "error: " << e.what() << "\n";
return 1;
} catch(...) {
cerr << "Exception of unknown type!\n";
}
// end of argument parsing
style();
TString fileBaseName = TString::Format("hgg.mH%.1f_8TeV", mass);
TString fileHiggsNameggh = TString::Format("hgg.hig.mH%.1f_8TeV.ggh", mass);
TString fileHiggsNametth = TString::Format("hgg.hig.mH%.1f_8TeV.tth", mass);
TString fileHiggsNamevbf = TString::Format("hgg.hig.mH%.1f_8TeV.vbf", mass);
TString fileHiggsNamevh = TString::Format("hgg.hig.mH%.1f_8TeV.vh", mass);
TString fileHiggsNamebbh = TString::Format("hgg.hig.mH%.1f_8TeV.bbh", mass);
TString fileBkgName = "hgg.inputbkg_8TeV";
TString card_name = "models_mgg.rs"; // put the model parameters here!
HLFactory hlf("HLFactory", card_name, false);
RooWorkspace* w = hlf.GetWs();
RooFitResult* fitresults;
// the limit trees to be addeed
//
TString dir = TString::Format("/afs/cern.ch/work/o/obondu/public/forRadion/limitTrees/v%d/v%d_%s",version,version,analysisType.c_str());
TString hhiggsggh = TString::Format("%s/ggh_m125_powheg_8TeV_m%d.root",dir.Data(),sigMass);
TString hhiggstth = TString::Format("%s/tth_m125_8TeV_m%d.root",dir.Data(),sigMass);;
TString hhiggsvbf = TString::Format("%s/vbf_m125_8TeV_m%d.root",dir.Data(),sigMass);;
TString hhiggsvh = TString::Format("%s/wzh_m125_8TeV_zh_m%d.root",dir.Data(),sigMass);;
TString hhiggsbbh = TString::Format("%s/bbh_m125_8TeV_m%d.root",dir.Data(),sigMass);;
//
TString ddata = TString::Format("%s/Data_m%d.root",dir.Data(),sigMass);
TString ssignal;
if (sigMass == 260) ssignal = TString::Format("%s/MSSM_m260_8TeV_m260.root",dir.Data());
else if (sigMass >= 270) ssignal = TString::Format("%s/Radion_m%d_8TeV_m%d.root",dir.Data(),sigMass,sigMass);
else ssignal = TString::Format("%s/ggHH_%s_8TeV_m0.root",dir.Data(),nonresFile.c_str());
cout<<"Signal: "<<ssignal<<endl;
cout<<"Data: "<<ddata<<endl;
//
AddSigData(w, mass,ssignal);
cout<<"SIGNAL ADDED"<<endl;
SigModelFit(w, mass); // constructing signal pdf
MakeSigWS(w, fileBaseName);
MakePlots(w, mass);
cout<<" did signal WS's"<<endl;
//
cout<<"Higgs: "<<hhiggsggh<<endl;
AddHigData(w, mass,hhiggsggh,0);
HigModelFit(w, mass,0); // constructing higgs pdf
MakeHigWS(w, fileHiggsNameggh,0);
//
cout<<"Higgs: "<<hhiggstth<<endl;
AddHigData(w, mass,hhiggstth,1);
HigModelFit(w, mass,1); // constructing higgs pdf
MakeHigWS(w, fileHiggsNametth,1);
//
cout<<"Higgs: "<<hhiggsvbf<<endl;
AddHigData(w, mass,hhiggsvbf,2);
HigModelFit(w, mass,2); // constructing higgs pdf
MakeHigWS(w, fileHiggsNamevbf,2);
//
cout<<"=============================== Higgs: ============================= "<<hhiggsvh<<endl;
AddHigData(w, mass,hhiggsvh,3);
HigModelFit(w, mass,3); // constructing higgs pdf
MakeHigWS(w, fileHiggsNamevh,3);
cout<<"HIGGS ADDED"<<endl;
//
cout<<"=============================== Higgs: ============================= "<<hhiggsbbh<<endl;
AddHigData(w, mass,hhiggsbbh,4);
HigModelFit(w, mass,4); // constructing higgs pdf
MakeHigWS(w, fileHiggsNamebbh,4);
cout<<"HIGGS ADDED"<<endl;
MakePlotsHiggs(w, mass);
//
AddBkgData(w,ddata);
w->Print("v");
cout<<"BKG ADDED"<<endl;
cout<<"here 1.0\n\n";
fitresults = BkgModelFitBernstein(w, doBands); // this is berestein 3
cout<<"here 1.1\n\n";
MakeBkgWS(w, fileBkgName);
cout<<"here 1.2\n\n";
// construct the models to fit
//
MakeDataCardonecatnohiggs(w, fileBaseName, fileBkgName, useSigTheoryUnc);
MakeDataCard(w, fileBaseName, fileBkgName, fileHiggsNameggh, fileHiggsNametth, fileHiggsNamevbf, fileHiggsNamevh, fileHiggsNamebbh, useSigTheoryUnc);
cout<< "here"<<endl;
return 0;
} // close runfits
////////////////////////////////////////////////////////////////////
// we add the data to the workspace in categories
void AddSigData(RooWorkspace* w, Float_t mass, TString signalfile) {
cout << "================= Add Signal==============================" << endl;
const Int_t ncat = NCAT;
// Luminosity:
Float_t Lum = 19712.0; // pb-1
RooRealVar lumi("lumi","lumi",Lum);
w->import(lumi);
RooArgSet* ntplVars = defineVariables();
TFile sigFile(signalfile);
TTree* sigTree = (TTree*) sigFile.Get("TCVARS");
// common preselection cut
TString mainCut("1");
RooDataSet sigScaled(
"sigScaled",
"dataset",
sigTree,
*ntplVars,
mainCut,
"evWeight");
cout << "======================================================================" << endl;
RooDataSet* sigToFit[ncat];
TString cut0 = " && 1>0";
//
// we take only mtot to fit to the workspace, we include the cuts
for ( int i=0; i<ncat; ++i){
sigToFit[i] = (RooDataSet*) sigScaled.reduce(
*w->var("mgg"),
mainCut+TString::Format(" && cut_based_ct==%d ",i)+cut0);
w->import(*sigToFit[i],Rename(TString::Format("Sig_cat%d",i)));
}
// Create full signal data set without categorization
RooDataSet* sigToFitAll = (RooDataSet*) sigScaled.reduce(*w->var("mgg"),mainCut);
cout << "======================================================================" << endl;
w->import(*sigToFitAll,Rename("Sig"));
// here we print the number of entries on the different categories
cout << "========= the number of entries on the different categories ==========" << endl;
cout << "---- one channel: " << sigScaled.sumEntries() << endl;
for (int c = 0; c < ncat; ++c) {
Float_t nExpEvt = sigToFit[c]->sumEntries();
cout << TString::Format("nEvt exp. cat%d : ",c) << nExpEvt
<< TString::Format(" eff x Acc cat%d : ",c)
<< "%"
<< endl;
} // close ncat
cout << "======================================================================" << endl;
sigScaled.Print("v");
return;
} // end add signal function
///////////////////////////////////////////////////////////////////////////////////
// we add the data to the workspace in categories
void AddBkgData(RooWorkspace* w, TString datafile) {
const Int_t ncat = NCAT;
// common preselection cut
TString mainCut("1");
RooArgSet* ntplVars = defineVariables();
RooRealVar weightVar("weightVar","",1,0,1000);
weightVar.setVal(1.);
// no common preselection cut applied yet;
TFile dataFile(datafile);
TTree* dataTree = (TTree*) dataFile.Get("TCVARS");
RooDataSet Data("Data","dataset",dataTree,*ntplVars,"","evWeight");
// evweight is 1 anyway...
RooDataSet* dataToFit[ncat];
RooDataSet* dataToPlot[ncat];
TString cut0 = "&& 1>0";
//
cout<<" HERE TAKE DATASET"<<endl;
for( int i=0; i<ncat; ++i){
dataToFit[i] = (RooDataSet*) Data.reduce(
*w->var("mgg"),
mainCut+TString::Format(" && cut_based_ct==%d",i)+cut0);
if(doblinding){ dataToPlot[i] = (RooDataSet*) Data.reduce(
*w->var("mgg"),
mainCut+TString::Format(" && cut_based_ct==%d",i)
+TString::Format(" && (mgg > 130 || mgg < 120)")// blind
+cut0);
}else{
dataToPlot[i] = (RooDataSet*) Data.reduce(
*w->var("mgg"),
mainCut+TString::Format(" && cut_based_ct==%d",i)
+cut0);
}
}
for (int c = 0; c < ncat; ++c) {
w->import(*dataToFit[c],Rename(TString::Format("Data_cat%d",c)));
w->import(*dataToPlot[c],Rename(TString::Format("Dataplot_cat%d",c)));
}
// Create full data set without categorization
RooDataSet* data = (RooDataSet*) Data.reduce(*w->var("mgg"),mainCut);
w->import(*data, Rename("Data"));
data->Print("v");
return;
} // close add data ..
/////////////////////////////////////////////////////////////////////
// we make the fit model
void SigModelFit(RooWorkspace* w, Float_t mass) {
const Int_t ncat = NCAT;
Float_t MASS(mass);
//******************************************//
// Fit signal with model pdfs
//******************************************//
// four categories to fit
RooDataSet* sigToFit[ncat];
RooAbsPdf* mggSig[ncat];
// fit range
Float_t minSigFit(115),maxSigFit(135);
for (int c = 0; c < ncat; ++c) {
// import sig and data from workspace
sigToFit[c] = (RooDataSet*) w->data(TString::Format("Sig_cat%d",c));
mggSig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggSig_cat%d",c));
((RooRealVar*) w->var(TString::Format("mgg_sig_m0_cat%d",c)))->setVal(MASS);
//RooRealVar* peak = w->var(TString::Format("mgg_sig_m0_cat%d",c));
//peak->setVal(MASS);
cout << "OK up to now..." <<MASS<< endl;
// Fit model as M(x|y) to D(x,y)
mggSig[c]->fitTo(*sigToFit[c],Range(minSigFit,maxSigFit),SumW2Error(kTRUE));
cout << "old = " << ((RooRealVar*) w->var(TString::Format("mgg_sig_m0_cat%d",c)))->getVal() << endl;
double mPeak = ((RooRealVar*) w->var(TString::Format("mgg_sig_m0_cat%d",c)))->getVal()+(MASS-125.0); // shift the peak
((RooRealVar*) w->var(TString::Format("mgg_sig_m0_cat%d",c)))->setVal(mPeak); // shift the peak
cout << "mPeak = " << mPeak << endl;
cout << "new mPeak position = " << ((RooRealVar*) w->var(TString::Format("mgg_sig_m0_cat%d",c)))->getVal() << endl;
// IMPORTANT: fix all pdf parameters to constant, why?
w->defineSet(TString::Format("SigPdfParam_cat%d",c),
RooArgSet(
*w->var(TString::Format("mgg_sig_m0_cat%d",c)),
*w->var(TString::Format("mgg_sig_sigma_cat%d",c)),
*w->var(TString::Format("mgg_sig_alpha_cat%d",c)),
*w->var(TString::Format("mgg_sig_n_cat%d",c)),
*w->var(TString::Format("mgg_sig_gsigma_cat%d",c)),
*w->var(TString::Format("mgg_sig_frac_cat%d",c))) );
SetConstantParams(w->set(TString::Format("SigPdfParam_cat%d",c)));
} // close for ncat
} // close signal model fit
/////////////////////////////////////////
// we make the higgs model
void HigModelFit(RooWorkspace* w, Float_t mass, int higgschannel) {
const Int_t ncat = NCAT;
Float_t MASS(mass);
// four categories to fit
RooDataSet* higToFit[ncat];
RooAbsPdf* mggHig[ncat];
// fit range
Float_t minHigFit(115),maxHigFit(135);
for (int c = 0; c < ncat; ++c) {
// import sig and data from workspace
higToFit[c] = (RooDataSet*) w->data(TString::Format("Hig_%d_cat%d",higgschannel,c));
mggHig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggHig_%d_cat%d",higgschannel,c));
//RooRealVar* peak = w->var(TString::Format("mgg_hig_m0_cat%d",c));
//peak->setVal(MASS);
((RooRealVar*) w->var(TString::Format("mgg_hig_m0_%d_cat%d",higgschannel,c)))->setVal(MASS);
cout << "OK up to now..." <<MASS<< endl;
cout << "old = " << ((RooRealVar*) w->var(TString::Format("mgg_hig_m0_%d_cat%d",higgschannel,c)))->getVal() << endl;
double mPeak = ((RooRealVar*) w->var(TString::Format("mgg_hig_m0_%d_cat%d",higgschannel,c)))->getVal()+(MASS-125.0); // shift the peak
((RooRealVar*) w->var(TString::Format("mgg_hig_m0_%d_cat%d",higgschannel,c)))->setVal(mPeak); // shift the peak
cout << "mPeak = " << mPeak << endl;
cout << "new mPeak position = " << ((RooRealVar*) w->var(TString::Format("mgg_hig_m0_%d_cat%d",higgschannel,c)))->getVal() << endl;
// Fit model as M(x|y) to D(x,y)
mggHig[c]->fitTo(*higToFit[c],Range(minHigFit,maxHigFit),SumW2Error(kTRUE));
// IMPORTANT: fix all pdf parameters to constant
w->defineSet(TString::Format("HigPdfParam_%d_cat%d",higgschannel,c),
RooArgSet(
*w->var(TString::Format("mgg_hig_m0_%d_cat%d",higgschannel,c)),
*w->var(TString::Format("mgg_hig_sigma_%d_cat%d",higgschannel,c)),
*w->var(TString::Format("mgg_hig_alpha_%d_cat%d",higgschannel,c)),
*w->var(TString::Format("mgg_hig_n_%d_cat%d",higgschannel,c)),
*w->var(TString::Format("mgg_hig_gsigma_%d_cat%d",higgschannel,c)),
*w->var(TString::Format("mgg_hig_frac_%d_cat%d",higgschannel,c))) );
SetConstantParams(w->set(TString::Format("HigPdfParam_%d_cat%d",higgschannel,c)));
} // close for ncat
} // close higgs model fit
////////////////////////////////////////////////////////////
// BKG model berestein 3
RooFitResult* BkgModelFitBernstein(RooWorkspace* w, Bool_t doBands) {
const Int_t ncat = NCAT;
std::vector<TString> catdesc;
if ( NCAT == 2 ){
catdesc.push_back("2 btag");
catdesc.push_back("1 btag");
}
else{
catdesc.push_back("2 btag, M_{#gamma#gammajj}^{kin} > 350 GeV");
catdesc.push_back("1 btag, M_{#gamma#gammajj}^{kin} > 360 GeV");
catdesc.push_back("2 btag, M_{#gamma#gammajj}^{kin} < 350 GeV");
catdesc.push_back("1 btag, M_{#gamma#gammajj}^{kin} < 360 GeV");
}
//******************************************//
// Fit background with model pdfs
//******************************************//
// retrieve pdfs and datasets from workspace to fit with pdf models
RooDataSet* data[ncat];
RooDataSet* dataplot[ncat]; // the data
RooBernstein* mggBkg[ncat];// the polinomial of 4* order
RooPlot* plotmggBkg[ncat];
RooDataSet* sigToFit0[ncat];
RooDataSet* sigToFit1[ncat];
RooDataSet* sigToFit2[ncat];
RooDataSet* sigToFit3[ncat];
RooDataSet* sigToFit4[ncat];
RooAbsPdf* mggSig[ncat];
RooAbsPdf* mggSig0[ncat];
RooAbsPdf* mggSig1[ncat];
RooAbsPdf* mggSig2[ncat];
RooAbsPdf* mggSig3[ncat];
RooAbsPdf* mggSig4[ncat];
Float_t minMassFit(100),maxMassFit(180);
// Fit data with background pdf for data limit
RooRealVar* mgg = w->var("mgg");
mgg->setUnit("GeV");
//
TLatex *text = new TLatex();
text->SetNDC();
text->SetTextSize(0.04);
//
for (int c = 0; c < ncat; ++c) { // to each category
data[c] = (RooDataSet*) w->data(TString::Format("Data_cat%d",c));
cout << "!!!!!!!!!!!!!" << endl;
////////////////////////////////////
// these are the parameters for the bkg polinomial
// one slope by category - float from -10 > 10
// the parameters are squared
RooFormulaVar *p1mod = new RooFormulaVar(
TString::Format("p1mod_cat%d",c),
"","@0*@0",
*w->var(TString::Format("mgg_bkg_8TeV_slope1_cat%d",c)));
RooAbsPdf* mggBkgTmp0 = new RooGenericPdf(
TString::Format("MggNonresBkg_%d",c),
"1./pow(@0,@1)",
RooArgList(*mgg, *p1mod));
// we first wrap the normalization of mggBkgTmp0
w->factory(TString::Format("mgg_bkg_8TeV_norm_cat%d[1.0,0.0,100000]",c));
RooExtendPdf mggBkgTmp( // we copy the pdf? normalized
TString::Format("mggBkg_cat%d",c),
"",*mggBkgTmp0,
*w->var(TString::Format("mgg_bkg_8TeV_norm_cat%d",c)) // normalization only on full bkg
);
mggBkgTmp.fitTo( // fit with normalized pdf,and return values
*data[c], // bkg
Strategy(1), // MINUIT strategy
Minos(kFALSE), // interpretation on the errors, nonlinearities
Range(minMassFit,maxMassFit),
SumW2Error(kTRUE),
Save(kTRUE));
w->import(mggBkgTmp);
//************************************************//
// Plot mgg background fit results per categories
//************************************************//
TCanvas* ctmp = new TCanvas(TString::Format("ctmpBkg_cat%d",c),"mgg Background Categories",0,0,500,500);
Int_t nBinsMass(80);
plotmggBkg[c] = mgg->frame(nBinsMass);
cout<<" here 1"<<endl;
dataplot[c] = (RooDataSet*) w->data(TString::Format("Dataplot_cat%d",c));
cout<<" here 1"<<endl;
dataplot[c]->plotOn(plotmggBkg[c]); //
mggBkgTmp.plotOn(
plotmggBkg[c],
LineColor(kBlue),
Range("fitrange"),NormRange("fitrange"));
dataplot[c]->plotOn(plotmggBkg[c]);
cout << "!!!!!!!!!!!!!!!!!" << endl;
cout << "!!!!!!!!!!!!!!!!!" << endl; // now we fit the gaussian on signal
//plotmggBkg[c]->SetMinimum(0.01); // no error bar in bins with zero events
if(c==0||c==2)plotmggBkg[c]->SetMinimum(0.005); // no error bar in bins with zero events
if(c==1||c==3)plotmggBkg[c]->SetMinimum(0.001); // no error bar in bins with zero events
plotmggBkg[c]->Draw();
plotmggBkg[c]->SetTitle("CMS preliminary 19.7/fb");
//plotmggBkg[c]->SetMinimum(0.01); // no error bar in bins with zero events
plotmggBkg[c]->SetMaximum(1.40*plotmggBkg[c]->GetMaximum());
plotmggBkg[c]->GetXaxis()->SetTitle("M_{#gamma#gamma} (GeV)");
//double test = sigToFit[c]->sumEntries();
//cout<<"number of events on dataset "<<test<<endl;
TGraphAsymmErrors *onesigma, *twosigma;
if (doBands) {
RooAbsPdf *cpdf; cpdf = mggBkgTmp0;
onesigma = new TGraphAsymmErrors();
twosigma = new TGraphAsymmErrors();
RooRealVar *nlim = new RooRealVar(TString::Format("nlim%d",c),"",0.0,0.0,10.0);
nlim->removeRange();
RooCurve *nomcurve = dynamic_cast<RooCurve*>(plotmggBkg[c]->getObject(1));
for (int i=1; i<(plotmggBkg[c]->GetXaxis()->GetNbins()+1); ++i) {
double lowedge = plotmggBkg[c]->GetXaxis()->GetBinLowEdge(i);
double upedge = plotmggBkg[c]->GetXaxis()->GetBinUpEdge(i);
double center = plotmggBkg[c]->GetXaxis()->GetBinCenter(i);
double nombkg = nomcurve->interpolate(center);
nlim->setVal(nombkg);
mgg->setRange("errRange",lowedge,upedge);
RooAbsPdf *epdf = 0;
epdf = new RooExtendPdf("epdf","",*cpdf,*nlim,"errRange");
RooAbsReal *nll = epdf->createNLL(*(data[c]),Extended());
RooMinimizer minim(*nll);
minim.setStrategy(0);
double clone = 1.0 - 2.0*RooStats::SignificanceToPValue(1.0);
double cltwo = 1.0 - 2.0*RooStats::SignificanceToPValue(2.0);
minim.migrad();
minim.minos(*nlim);
// printf("errlo = %5f, errhi = %5f\n",nlim->getErrorLo(),nlim->getErrorHi());
onesigma->SetPoint(i-1,center,nombkg);
onesigma->SetPointError(i-1,0.,0.,-nlim->getErrorLo(),nlim->getErrorHi());
minim.setErrorLevel(0.5*pow(ROOT::Math::normal_quantile(1-0.5*(1-cltwo),1.0), 2));
// the 0.5 is because qmu is -2*NLL
// eventually if cl = 0.95 this is the usual 1.92!
minim.migrad();
minim.minos(*nlim);
twosigma->SetPoint(i-1,center,nombkg);
twosigma->SetPointError(i-1,0.,0.,-nlim->getErrorLo(),nlim->getErrorHi());
delete nll;
delete epdf;
} // close for bin
mgg->setRange("errRange",minMassFit,maxMassFit);
twosigma->SetLineColor(kYellow);
twosigma->SetFillColor(kYellow);
twosigma->SetMarkerColor(kYellow);
twosigma->Draw("L3 SAME");
onesigma->SetLineColor(kGreen);
onesigma->SetFillColor(kGreen);
onesigma->SetMarkerColor(kGreen);
onesigma->Draw("L3 SAME");
plotmggBkg[c]->Draw("SAME");
} else plotmggBkg[c]->Draw("SAME"); // close dobands
//plotmggBkg[c]->getObject(1)->Draw("SAME");
//plotmggBkg[c]->getObject(2)->Draw("P SAME");
////////////////////////////////////////////////////////// plot higgs
sigToFit0[c] = (RooDataSet*) w->data(TString::Format("Hig_0_cat%d",c));
double norm0; norm0 = 1.0*sigToFit0[c]->sumEntries(); //
//norm0 = 0.0000001;
cout<<" here 0.0\n";
mggSig0[c] = (RooAbsPdf*) w->pdf(TString::Format("mggHig_0_cat%d",c));
// we are not constructing signal pdf, this is constructed on sig to fit function...
cout<<" here 0.1\n";
mggSig0[c] ->plotOn(
plotmggBkg[c],
Normalization(norm0,RooAbsPdf::NumEvent),
DrawOption("F"),
LineColor(kRed),FillStyle(1001),FillColor(19));
cout<<" here 0.2\n";
mggSig0[c]->plotOn(
plotmggBkg[c],
Normalization(norm0,RooAbsPdf::NumEvent),LineColor(kRed),LineStyle(1));
cout<<" here 0.3\n";
//
sigToFit1[c] = (RooDataSet*) w->data(TString::Format("Hig_1_cat%d",c));
double norm1 = 1.0*sigToFit1[c]->sumEntries(); //
mggSig1[c] = (RooAbsPdf*) w->pdf(TString::Format("mggHig_1_cat%d",c));
// we are not constructing signal pdf, this is constructed on sig to fit function...
mggSig1[c] ->plotOn(
plotmggBkg[c],
Normalization(norm1,RooAbsPdf::NumEvent),
DrawOption("F"),
LineColor(kGreen),FillStyle(1001),FillColor(19));
mggSig1[c]->plotOn(
plotmggBkg[c],
Normalization(norm1,RooAbsPdf::NumEvent),LineColor(kGreen),LineStyle(1));
//
sigToFit2[c] = (RooDataSet*) w->data(TString::Format("Hig_2_cat%d",c));
double norm2;
//if(sigToFit2[c]->sumEntries()>0)
norm2 = 1.0*sigToFit2[c]->sumEntries(); //else
//norm2 = 0.0000000000001; //
mggSig2[c] = (RooAbsPdf*) w->pdf(TString::Format("mggHig_2_cat%d",c));
// we are not constructing signal pdf, this is constructed on sig to fit function...
mggSig2[c] ->plotOn(
plotmggBkg[c],
Normalization(norm2,RooAbsPdf::NumEvent),
DrawOption("F"),
LineColor(kMagenta),FillStyle(1001),FillColor(19));
mggSig2[c]->plotOn(
plotmggBkg[c],
Normalization(norm2,RooAbsPdf::NumEvent),LineColor(kMagenta),LineStyle(1));
//
sigToFit3[c] = (RooDataSet*) w->data(TString::Format("Hig_3_cat%d",c));
double norm3 = 1.0*sigToFit3[c]->sumEntries(); //
mggSig3[c] = (RooAbsPdf*) w->pdf(TString::Format("mggHig_3_cat%d",c));
// we are not constructing signal pdf, this is constructed on sig to fit function...
mggSig3[c] ->plotOn(
plotmggBkg[c],
Normalization(norm3,RooAbsPdf::NumEvent),
DrawOption("F"),
LineColor(kCyan),FillStyle(1001),FillColor(19));
mggSig3[c]->plotOn(
plotmggBkg[c],
Normalization(norm3,RooAbsPdf::NumEvent),LineColor(kCyan),LineStyle(1));
sigToFit4[c] = (RooDataSet*) w->data(TString::Format("Hig_4_cat%d",c));
double norm4 = 1.0*sigToFit4[c]->sumEntries(); //
mggSig4[c] = (RooAbsPdf*) w->pdf(TString::Format("mggHig_4_cat%d",c));
// we are not constructing signal pdf, this is constructed on sig to fit function...
mggSig4[c] ->plotOn(
plotmggBkg[c],
Normalization(norm4,RooAbsPdf::NumEvent),
DrawOption("F"),
LineColor(kBlue),FillStyle(1001),FillColor(19));
mggSig4[c]->plotOn(
plotmggBkg[c],
Normalization(norm4,RooAbsPdf::NumEvent),LineColor(kBlue),LineStyle(1));
cout<<" here 0.4\n";
//////////////////////////////////////////////////////////
plotmggBkg[c]->Draw("SAME");
if(c==0||c==2)plotmggBkg[c]->SetMinimum(0.005); // no error bar in bins with zero events
if(c==1||c==3)plotmggBkg[c]->SetMinimum(0.01); // no error bar in bins with zero events
if(c==0||c==2)plotmggBkg[c]->SetMaximum(5.3); // no error bar in bins with zero events
if(c==1||c==3)plotmggBkg[c]->SetMaximum(20); // no error bar in bins with zero events
// plotmggBkg[c]->SetMinimum(0.005); // no error bar in bins with zero events
//plotmggBkg[c]->SetLogy(0);
cout << "!!!!!!!!!!!!!!!!!" << endl;
TLegend *legmc = new TLegend(0.40,0.72,0.62,0.9);
TLegend *legmcH = new TLegend(0.66,0.72,0.94,0.9);
legmc->AddEntry(plotmggBkg[c]->getObject(2),"Data","LPE"); // not...
legmc->AddEntry(plotmggBkg[c]->getObject(1),"Bkg Fit","L");
if(doBands)legmc->AddEntry(onesigma,"#pm1 #sigma","F");
if(doBands)legmc->AddEntry(twosigma,"#pm2 #sigma","F"); // not...
legmcH->AddEntry(plotmggBkg[c]->getObject(3),"ggH ","LPE"); // not...
legmcH->AddEntry(plotmggBkg[c]->getObject(5),"ttH ","LPE"); // not...
legmcH->AddEntry(plotmggBkg[c]->getObject(7),"VBF ","LPE"); // not...
legmcH->AddEntry(plotmggBkg[c]->getObject(9),"VH ","LPE"); // not...
legmcH->AddEntry(plotmggBkg[c]->getObject(11),"bbH ","LPE"); // not...
if ( sigMass ==0 ) legmc->SetHeader(" Nonresonace");
else legmc->SetHeader(TString::Format(" %d GeV",sigMass));
legmcH->SetHeader(" Higgs");
legmc->SetBorderSize(0);
legmc->SetFillStyle(0);
legmcH->SetBorderSize(0);
legmcH->SetFillStyle(0);
legmc->Draw();
legmcH->Draw();
cout<<" here 0.5\n";
TLatex *lat2 = new TLatex(minMassFit+1.5,0.75*plotmggBkg[c]->GetMaximum(),catdesc.at(c));
lat2->Draw();
//
ctmp->SaveAs(TString::Format("databkgoversig_cat%d.pdf",c));
ctmp->SaveAs(TString::Format("databkgoversig_cat%d.png",c));
if(c==0||c==2)plotmggBkg[c]->SetMaximum(100); // no error bar in bins with zero events
if(c==1||c==3)plotmggBkg[c]->SetMaximum(1000); // no error bar in bins with zero events
ctmp->SetLogy(1);
ctmp->SaveAs(TString::Format("databkgoversig_cat%d_log.pdf",c));
ctmp->SaveAs(TString::Format("databkgoversig_cat%d_log.png",c));
// ctmp->SaveAs(TString::Format("databkgoversig_cat%d.C",c));
} // close to each category
RooRealVar *constVar = new RooRealVar("constantVar","",1.0,1.0,1.0);
constVar->setConstant(true);
RooBernstein mggBkgAll("mggBkgAll", "", *mgg,
RooArgList(*constVar,
*w->var("mgg_bkg_8TeV_slope1")));
w->import(mggBkgAll);
RooFitResult* fitresults;
fitresults = w->pdf("mggBkgAll")->fitTo( // save results to workspace
*w->data("Data"),
Range(minMassFit,maxMassFit),
SumW2Error(kTRUE), Save(kTRUE));
cout<<" here 0.9\n";
fitresults->Print();
cout<<" here 0.99\n";
return fitresults;
} // close berestein 3
///////////////////////////////////////////////////////////////
void MakeSigWS(RooWorkspace* w, const char* fileBaseName) {
TString wsDir = "workspaces/";
const Int_t ncat = NCAT;
//**********************************************************************//
// Write pdfs and datasets into the workspace before to save
// for statistical tests.
//**********************************************************************//
RooAbsPdf* mggSigPdf[ncat];
RooWorkspace *wAll = new RooWorkspace("w_all","w_all");
for (int c = 0; c < ncat; ++c) {
mggSigPdf[c] = (RooAbsPdf*) w->pdf(TString::Format("mggSig_cat%d",c));
wAll->import(*w->pdf(TString::Format("mggSig_cat%d",c)));
}
// (2) Systematics on energy scale and resolution
// 1,1,1 statistical to be treated on the datacard
wAll->factory("CMS_hgg_sig_m0_absShift[1,1,1]");
wAll->factory("prod::CMS_hgg_sig_m0_cat0(mgg_sig_m0_cat0, CMS_hgg_sig_m0_absShift)");
wAll->factory("prod::CMS_hgg_sig_m0_cat1(mgg_sig_m0_cat1, CMS_hgg_sig_m0_absShift)");
if ( NCAT > 2 ){
wAll->factory("prod::CMS_hgg_sig_m0_cat2(mgg_sig_m0_cat2, CMS_hgg_sig_m0_absShift)");
wAll->factory("prod::CMS_hgg_sig_m0_cat3(mgg_sig_m0_cat3, CMS_hgg_sig_m0_absShift)");
}
// (3) Systematics on resolution
wAll->factory("CMS_hgg_sig_sigmaScale[1,1,1]");
wAll->factory("prod::CMS_hgg_sig_sigma_cat0(mgg_sig_sigma_cat0, CMS_hgg_sig_sigmaScale)");
wAll->factory("prod::CMS_hgg_sig_sigma_cat1(mgg_sig_sigma_cat1, CMS_hgg_sig_sigmaScale)");
if ( NCAT > 2 ){
wAll->factory("prod::CMS_hgg_sig_sigma_cat2(mgg_sig_sigma_cat2, CMS_hgg_sig_sigmaScale)");
wAll->factory("prod::CMS_hgg_sig_sigma_cat3(mgg_sig_sigma_cat3, CMS_hgg_sig_sigmaScale)");
}
wAll->factory("prod::CMS_hgg_sig_gsigma_cat0(mgg_sig_gsigma_cat0, CMS_hgg_sig_sigmaScale)");
wAll->factory("prod::CMS_hgg_sig_gsigma_cat1(mgg_sig_gsigma_cat1, CMS_hgg_sig_sigmaScale)");
if ( NCAT > 2 ){
wAll->factory("prod::CMS_hgg_sig_gsigma_cat2(mgg_sig_gsigma_cat2, CMS_hgg_sig_sigmaScale)");
wAll->factory("prod::CMS_hgg_sig_gsigma_cat3(mgg_sig_gsigma_cat3, CMS_hgg_sig_sigmaScale)");
}
// (4) do reparametrization of signal
for (int c = 0; c < ncat; ++c) wAll->factory(
TString::Format("EDIT::CMS_hgg_sig_cat%d(mggSig_cat%d,",c,c) +
TString::Format(" mgg_sig_m0_cat%d=CMS_hgg_sig_m0_cat%d, ", c,c) +
TString::Format(" mgg_sig_sigma_cat%d=CMS_hgg_sig_sigma_cat%d, ", c,c) +
// TString::Format(" mgg_sig_alpha_cat%d=CMS_hgg_sig_alpha_cat%d, ", c,c) +
// TString::Format(" mgg_sig_n_cat%d=CMS_hgg_sig_n_cat%d, ", c,c) +
// TString::Format(" mgg_sig_frac_cat%d=CMS_hgg_sig_frac_cat%d, ", c,c) +
TString::Format(" mgg_sig_gsigma_cat%d=CMS_hgg_sig_gsigma_cat%d)", c,c)
);
TString filename(wsDir+TString(fileBaseName)+".inputsig.root");
wAll->writeToFile(filename);
cout << "Write signal workspace in: " << filename << " file" << endl;
return;
} // close make signal WP
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
void MakeBkgWS(RooWorkspace* w, const char* fileBaseName) {
TString wsDir = "workspaces/";
const Int_t ncat = NCAT;
//**********************************************************************//
// Write pdfs and datasets into the workspace before to save to a file
// for statistical tests.
//**********************************************************************//
RooDataSet* data[ncat];
RooAbsPdf* mggBkgPdf[ncat];
RooWorkspace *wAll = new RooWorkspace("w_all","w_all");
for (int c = 0; c < ncat; ++c) {
cout<<"here"<<endl;
data[c] = (RooDataSet*) w->data(TString::Format("Data_cat%d",c));
//RooDataHist* dataBinned = data[c]->binnedClone(); // Uncomment if you want to use wights in the limits
mggBkgPdf[c] = (RooAbsPdf*) w->pdf(TString::Format("mggBkg_cat%d",c));
wAll->import(*data[c], Rename(TString::Format("data_obs_cat%d",c)));// Comment if you want to use wights in the limits
//wAll->import(*dataBinned, Rename(TString::Format("data_obs_cat%d",c))); // Uncomment if you want to use wights in the limits
cout<<"here"<<endl;
wAll->import(*w->pdf(TString::Format("mggBkg_cat%d",c)));
cout<<"here"<<endl;
wAll->factory(
TString::Format("CMS_hgg_bkg_8TeV_cat%d_norm[%g,0.0,100000.0]",
c, w->var(TString::Format("mgg_bkg_8TeV_norm_cat%d",c))->getVal()));
cout<<"here"<<endl;
wAll->factory(
TString::Format("CMS_hgg_bkg_8TeV_slope1_cat%d[%g,-10,10]",
c, w->var(TString::Format("mgg_bkg_8TeV_slope1_cat%d",c))->getVal()));
cout<<"here"<<endl;
} // close ncat
// (2) do reparametrization of background
for (int c = 0; c < ncat; ++c){
wAll->factory(
TString::Format("EDIT::CMS_hgg_bkg_8TeV_cat%d(mggBkg_cat%d,",c,c) +
TString::Format(" mgg_bkg_8TeV_norm_cat%d=CMS_hgg_bkg_8TeV_cat%d_norm,", c,c)+
TString::Format(" mgg_bkg_8TeV_slope1_cat%d=CMS_hgg_bkg_8TeV_slope1_cat%d)", c,c)
//TString::Format(" mgg_bkg_8TeV_slope2_cat%d=CMS_hgg_bkg_8TeV_slope2_cat%d,", c,c)+
//TString::Format(" mgg_bkg_8TeV_slope3_cat%d=CMS_hgg_bkg_8TeV_slope3_cat%d)", c,c)
);
} // close for cat
TString filename(wsDir+TString(fileBaseName)+".root");
wAll->writeToFile(filename);
cout << "Write background workspace in: " << filename << " file" << endl;
std::cout << "observation ";
for (int c = 0; c < ncat; ++c) {
std::cout << " " << wAll->data(TString::Format("data_obs_cat%d",c))->sumEntries();
}
std::cout << std::endl;
return;
} // close make BKG workspace
////////////////////////////////////////////////////////////////////
void SetConstantParams(const RooArgSet* params) {
// set constant parameters for signal fit, ... NO IDEA !!!!
TIterator* iter(params->createIterator());
for (TObject *a = iter->Next(); a != 0; a = iter->Next()) {
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
if (rrv) { rrv->setConstant(true); std::cout << " " << rrv->GetName(); }
}
} // close set const parameters
////////////////////////////////////////////////////////////////////////
void MakePlots(RooWorkspace* w, Float_t Mass) {
const Int_t ncat = NCAT;
std::vector<TString> catdesc;
if ( NCAT == 2 ){
catdesc.push_back(" 2 btag");
catdesc.push_back(" 1 btag");
}
else{
catdesc.push_back(" 2 btag, M_{#gamma#gammajj}^{kin} > 350 GeV");
catdesc.push_back(" 1 btag, M_{#gamma#gammajj}^{kin} > 360 GeV");
catdesc.push_back(" 2 btag, M_{#gamma#gammajj}^{kin} < 350 GeV");
catdesc.push_back(" 1 btag, M_{#gamma#gammajj}^{kin} < 360 GeV");
}
// retrieve data sets from the workspace
// RooDataSet* dataAll = (RooDataSet*) w->data("Data");
RooDataSet* signalAll = (RooDataSet*) w->data("Sig");
//RooDataSet* higgsAll = (RooDataSet*) w->data("Hig");
// blinded dataset
// RooDataSet* data[ncat];
RooDataSet* sigToFit[ncat];
RooAbsPdf* mggGaussSig[ncat];
RooAbsPdf* mggCBSig[ncat];
RooAbsPdf* mggSig[ncat];
//
RooAbsPdf* mggBkg[ncat];
for (int c = 0; c < ncat; ++c) {
// data[c] = (RooDataSet*) w->data(TString::Format("Data_cat%d",c));
sigToFit[c] = (RooDataSet*) w->data(TString::Format("Sig_cat%d",c));
mggGaussSig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggGaussSig_cat%d",c));
mggCBSig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggCBSig_cat%d",c));
mggSig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggSig_cat%d",c));
mggBkg[c] = (RooAbsPdf*) w->pdf(TString::Format("mggBkg_cat%d",c));
} // close categories
RooRealVar* mgg = w->var("mgg");
mgg->setUnit("GeV");
RooAbsPdf* mggGaussSigAll = w->pdf("mggGaussSig");
RooAbsPdf* mggCBSigAll = w->pdf("mggCBSig");
RooAbsPdf* mggSigAll = w->pdf("mggSig");
//RooAbsPdf* mggBkgAll = w->pdf("mggBkg_cat1");
//
//****************************//
// Plot mgg Fit results
//****************************//
// Set P.D.F. parameter names
// WARNING: Do not use it if Workspaces are created
// SetParamNames(w);
Float_t minSigFit(120),maxSigFit(130);
Float_t MASS(Mass);
Int_t nBinsMass(20); // just need to plot
RooPlot* plotmggAll = mgg->frame(Range(minSigFit,maxSigFit),Bins(nBinsMass));
signalAll->plotOn(plotmggAll);
gStyle->SetOptTitle(0);
TCanvas* c1 = new TCanvas("cSig","mgg",0,0,500,500);
c1->cd(1);
//********************************************//
// Plot Signal Categories
//****************************//
TLatex *text = new TLatex();
text->SetNDC();
text->SetTextSize(0.04);
RooPlot* plotmgg[ncat];
for (int c = 0; c < ncat; ++c) {
plotmgg[c] = mgg->frame(Range(minSigFit,maxSigFit),Bins(nBinsMass));
sigToFit[c]->plotOn(plotmgg[c]);
mggSig[c] ->plotOn(plotmgg[c]);
double chi2n = plotmgg[c]->chiSquare(0) ;
cout << "------------------------- Experimentakl chi2 = " << chi2n << endl;
mggSig[c] ->plotOn(
plotmgg[c],
Components(TString::Format("GaussSig_cat%d",c)),
LineStyle(kDashed),LineColor(kGreen));
mggSig[c] ->plotOn(
plotmgg[c],
Components(TString::Format("CBSig_cat%d",c)),
LineStyle(kDashed),LineColor(kRed));
mggSig[c] ->paramOn(plotmgg[c]);
sigToFit[c] ->plotOn(plotmgg[c]);
// TCanvas* dummy = new TCanvas("dummy", "dummy",0, 0, 400, 400);
TH1F *hist = new TH1F(TString::Format("hist_cat%d",c), "hist", 400, minSigFit, maxSigFit);
plotmgg[c]->SetTitle("CMS preliminary 19.7/fb ");
plotmgg[c]->SetMinimum(0.0);
plotmgg[c]->SetMaximum(1.40*plotmgg[c]->GetMaximum());
plotmgg[c]->GetXaxis()->SetTitle("M_{#gamma#gamma} (GeV)");
TCanvas* ctmp = new TCanvas(TString::Format("ctmpSig_cat%d",c),"Background Categories",0,0,500,500);
plotmgg[c]->Draw();
plotmgg[c]->Draw("SAME");
TLegend *legmc = new TLegend(0.62,0.75,0.99,0.99);
legmc->AddEntry(plotmgg[c]->getObject(5),"Simulation","LPE");
legmc->AddEntry(plotmgg[c]->getObject(1),"Parametric Model","L");
legmc->AddEntry(plotmgg[c]->getObject(2),"Gaussian Outliers","L");
legmc->AddEntry(plotmgg[c]->getObject(3),"Crystal Ball component","L");
legmc->SetHeader(" ");
legmc->SetBorderSize(0);
legmc->SetFillStyle(0);
legmc->Draw();
// float effS = effSigma(hist);
TString latLabel = " Nonresonance - SM";
if ( sigMass != 0) latLabel = TString::Format(" Resonance - %d GeV",sigMass);
TLatex *lat = new TLatex(
minSigFit+0.5,0.85*plotmgg[c]->GetMaximum(),latLabel.Data());
lat->Draw();
TLatex *lat2 = new TLatex(
minSigFit+1.5,0.75*plotmgg[c]->GetMaximum(),catdesc.at(c));
lat2->Draw();
///////
char myChi2buffer[50];
sprintf(myChi2buffer,"#chi^{2}/ndof = %f",chi2n);
TLatex* latex = new TLatex(0.52, 0.7, myChi2buffer);
latex -> SetNDC();
latex -> SetTextFont(42);
latex -> SetTextSize(0.04);
//latex -> Draw("same");
ctmp->SaveAs(TString::Format("sigmodel_cat%d.pdf",c));
ctmp->SaveAs(TString::Format("sigmodel_cat%d.png",c));
//ctmp->SaveAs(TString::Format("sigmodel_cat%d.C",c));
} // close categories
return;
} // close makeplots signal
////////////////////////////////////////////////////////////////////////
void MakePlotsHiggs(RooWorkspace* w, Float_t Mass) {
const Int_t ncat = NCAT;
std::vector<TString> catdesc;
if ( NCAT == 2 ){
catdesc.push_back(" 2 btag");
catdesc.push_back(" 1 btag");
}
else{
catdesc.push_back(" 2 btag, M_{#gamma#gammajj}^{kin} > 350 GeV");
catdesc.push_back(" 1 btag, M_{#gamma#gammajj}^{kin} > 360 GeV");
catdesc.push_back(" 2 btag, M_{#gamma#gammajj}^{kin} < 350 GeV");
catdesc.push_back(" 1 btag, M_{#gamma#gammajj}^{kin} < 360 GeV");
}
// retrieve data sets from the workspace
// RooDataSet* dataAll = (RooDataSet*) w->data("Data");
//RooDataSet* signalAll = (RooDataSet*) w->data("Sig");
//RooDataSet* higgsAll = (RooDataSet*) w->data("Hig");
// blinded dataset
// RooDataSet* data[ncat];
TString component[5] = {"ggH","ttH","VBF","VH", "bbH"};
// higToFit[c] = (RooDataSet*) w->data(TString::Format("Hig_%d_cat%d",higgschannel,c));
for (int d = 0; d < 5; ++d){
RooDataSet* sigToFit[ncat];
RooAbsPdf* mggGaussSig[ncat];
RooAbsPdf* mggCBSig[ncat];
RooAbsPdf* mggSig[ncat];
//
RooAbsPdf* mggBkg[ncat];
for (int c = 0; c < ncat; ++c) {
// data[c] = (RooDataSet*) w->data(TString::Format("Data_cat%d",c));
sigToFit[c] = (RooDataSet*) w->data(TString::Format("Hig_%d_cat%d",d,c));
mggGaussSig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggGaussHig_%d_cat%d",d,c));
mggCBSig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggCBHig_%d_cat%d",d,c));
mggSig[c] = (RooAbsPdf*) w->pdf(TString::Format("mggHig_%d_cat%d",d,c));
mggBkg[c] = (RooAbsPdf*) w->pdf(TString::Format("mggBkg_%d_cat%d",d,c));
} // close categories
RooRealVar* mgg = w->var("mgg");
mgg->setUnit("GeV");
//RooAbsPdf* mggBkgAll = w->pdf("mggBkg_cat1");
//
//****************************//
// Plot mgg Fit results
//****************************//
// Set P.D.F. parameter names
// WARNING: Do not use it if Workspaces are created
// SetParamNames(w);
Float_t minSigFit(120),maxSigFit(130);
Float_t MASS(Mass);
Int_t nBinsMass(20); // just need to plot
//RooPlot* plotmggAll = mgg->frame(Range(minSigFit,maxSigFit),Bins(nBinsMass));
//higgsAll->plotOn(plotmggAll);
gStyle->SetOptTitle(0);
TCanvas* c1 = new TCanvas(TString::Format("cHig_%d",d),"mgg",0,0,500,500);
c1->cd(1);
//********************************************//
// Plot Signal Categories
//****************************//
TLatex *text = new TLatex();
text->SetNDC();
text->SetTextSize(0.04);
RooPlot* plotmgg[ncat];
for (int c = 0; c < ncat; ++c) {
plotmgg[c] = mgg->frame(Range(minSigFit,maxSigFit),Bins(nBinsMass));
sigToFit[c]->plotOn(plotmgg[c]);
mggSig[c] ->plotOn(plotmgg[c]);
double chi2n = plotmgg[c]->chiSquare(0) ;
cout << "------------------------- Experimentakl chi2 = " << chi2n << endl;
mggSig[c] ->plotOn(
plotmgg[c],
Components(TString::Format("GaussHig_%d_cat%d",d,c)),
LineStyle(kDashed),LineColor(kGreen));
mggSig[c] ->plotOn(
plotmgg[c],
Components(TString::Format("CBHig_%d_cat%d",d,c)),
LineStyle(kDashed),LineColor(kRed));
mggSig[c] ->paramOn(plotmgg[c]);