-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitMass.cc
1013 lines (909 loc) · 53.7 KB
/
fitMass.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
// Fit the mjj and mggjj spectra to get the resolution out
// O. Bondu (May 2013)
// C++ headers
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <boost/program_options.hpp>
// ROOT headers
#include "TROOT.h"
#include "TSystem.h"
#include <TFile.h>
#include <TTree.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TLatex.h>
#include <TEntryList.h>
#include <TF1.h>
// RooFit headers
#include "RooRealVar.h"
#include "RooFormulaVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooVoigtian.h"
#include "RooCBShape.h"
#include "RooPlot.h"
#include "RooFitResult.h"
#include "RooCategory.h"
#include "RooSimultaneous.h"
#include "RooBernstein.h"
#include "RooAddPdf.h"
#include "RooExponential.h"
// local files
#include "CMSStyle.C"
// Verbosity
#define DEBUG 0
// namespaces
using namespace std;
using namespace RooFit;
namespace po = boost::program_options;
void plotParameters(RooArgList *r2_cat0_param, TCanvas *c, int canvasDivision, RooPlot* frame0, bool isThereSeveralFits, int iclass, string datasetName, float mvaInf, float mvaSup, int precision);
pair<float,float> sigmaEff(TTree* tree, string variable, string cut = "");
float getFWHM(RooAddPdf *pdf, RooRealVar *var);
int main (int argc, char *argv[])
{
// declare arguments
int compareWithRegression;
int massHypothesis;
int CRYSTALBALL;
string inputfile;
string inputtree;
string inputregfile;
string inputregtree;
string outputfile;
// print out passed arguments
copy(argv, argv + argc, ostream_iterator<char*>(cout, " ")); cout << endl;
// argument parsing itself
try
{
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("inputfile", po::value<string>(&inputfile)->default_value("2014-02-17_selection_noRegression_noMassCut_v10/Radion_m300_8TeV_noRegression_noMassCut_v10.root"), "input file")
("inputtree", po::value<string>(&inputtree)->default_value("Radion_m300_8TeV"), "input tree")
("inputregfile", po::value<string>(&inputregfile)->default_value("2014-02-17_selection_noRegression_noMassCut_v10/Radion_m300_8TeV_noRegression_noMassCut_v10.root"), "input file")
("inputregtree", po::value<string>(&inputregtree)->default_value("Radion_m300_8TeV"), "input tree")
("massHypothesis", po::value<int>(&massHypothesis)->default_value(300), "mass hypothesis")
("compareWithRegression", po::value<int>(&compareWithRegression)->default_value(0), "switch on/off comparison with regression")
("outputfile", po::value<string>(&outputfile)->default_value("resolution_Radion_m300_8TeV.txt"), "output file to store fit results")
("crystalBall", po::value<int>(&CRYSTALBALL)->default_value(1), "perform CrystalBall fit")
;
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
//################################################
// Initialize plot style
gROOT->Reset();
gROOT->ProcessLine(".x setTDRStyle.C");
CMSStyle();
gStyle->SetOptTitle(0);
gStyle->SetOptStat(0);
if( !compareWithRegression )
{
// Initialize stuff
TCanvas *c1 = new TCanvas("c1", "c1", 600, 600);
TFile *infile = TFile::Open(inputfile.c_str());
TTree *intree = (TTree*)infile->Get(inputtree.c_str());
ofstream outfile;
outfile.open(outputfile.c_str());
// outfile << "Spectrum\tCategory\tMethod\tmu\tsigma\tres" << endl;
cout << "Performing the fits" << endl;
// Observables
float min_jj = 50.;
float max_jj = 250.;
float min_ggjj = massHypothesis - 200.;
float max_ggjj = massHypothesis + 200.;
RooRealVar jj_mass("jj_mass", "m_{jj}", min_jj, max_jj, "GeV");
jj_mass.setBins(50);
RooRealVar ggjj_mass("ggjj_mass", "m_{jj#gamma#gamma}", min_ggjj, max_ggjj, "GeV");
ggjj_mass.setBins(50);
RooRealVar njets_kRadionID_and_CSVM("njets_kRadionID_and_CSVM", "njets_kRadionID_and_CSVM", 0, 10);
vector<string> categoryCut;
categoryCut.clear();
vector<string> categoryName;
categoryName.clear();
// categoryCut.push_back(Form("jj_mass > %f && jj_mass < %f && ggjj_mass > %f && ggjj_mass < %f", min_jj, max_jj, min_ggjj, max_ggjj));
// categoryName.push_back("allcat");
categoryCut.push_back(Form("njets_kRadionID_and_CSVM < 1.5 && jj_mass > %f && jj_mass < %f && ggjj_mass > %f && ggjj_mass < %f", min_jj, max_jj, min_ggjj, max_ggjj));
categoryName.push_back("cat1");
categoryCut.push_back(Form("njets_kRadionID_and_CSVM > 1.5 && jj_mass > %f && jj_mass < %f && ggjj_mass > %f && ggjj_mass < %f", min_jj, max_jj, min_ggjj, max_ggjj));
categoryName.push_back("cat0");
for(int icat = 0 ; icat < (int)categoryCut.size() ; icat++)
{
// datatset definition depend on category
RooDataSet full_dataset("radion", "radion", intree, RooArgList(jj_mass, ggjj_mass, njets_kRadionID_and_CSVM));
RooDataSet dataset = *((RooDataSet*)full_dataset.reduce(categoryCut[icat].c_str()));
float mean_jj = dataset.mean(jj_mass);
float rms_jj = dataset.rmsVar(jj_mass)->getVal();
float mean_ggjj = dataset.mean(ggjj_mass);
float rms_ggjj = dataset.rmsVar(ggjj_mass)->getVal();
pair<float, float> ms_jj = make_pair(0., 0.);
pair<float, float> ms_gg = make_pair(0., 0.);
pair<float, float> ms_ggjj = make_pair(0., 0.);
ms_jj = sigmaEff(intree, "jj_mass", categoryCut[icat]);
ms_gg = sigmaEff(intree, "gg_mass", categoryCut[icat]);
ms_ggjj = sigmaEff(intree, "ggjj_mass", categoryCut[icat]);
cout << "ncor: " << "\tmean= " << ms_jj.first << "\tsigma= " << ms_jj.second << "\tres= " << ms_jj.second / ms_jj.first * 100. << endl;
cout << "ncor: " << "\tmean= " << ms_ggjj.first << "\tsigma= " << ms_ggjj.second << "\tres= " << ms_ggjj.second / ms_ggjj.first * 100. << endl;
/*
outfile << "mjj\t" << setprecision (2) << fixed << categoryName[icat] << "\t" << "sigmaEff"
<< "\t" << ms_jj.first << "\t" << ms_jj.second << "\t" << ms_jj.second / ms_jj.first * 100.
<< endl;
outfile << "mggjj\t" << setprecision (2) << fixed << categoryName[icat] << "\t" << "sigmaEff"
<< "\t" << ms_ggjj.first << "\t" << ms_ggjj.second << "\t" << ms_ggjj.second / ms_ggjj.first * 100.
<< endl;
*/
outfile << "mass= " << massHypothesis
<< "\t" << "var= " << "mgg"
<< "\t" << "cat= " << categoryName[icat]
<< "\t" << "method= " << "sigmaEff"
<< "\t" << "width= " << ms_gg.second
<< "\t" << "mean= " << 125.
<< endl;
outfile << "mass= " << massHypothesis
<< "\t" << "var= " << "mjj"
<< "\t" << "cat= " << categoryName[icat]
<< "\t" << "method= " << "sigmaEff"
<< "\t" << "width= " << ms_jj.second
<< "\t" << "mean= " << 125.
<< endl;
outfile << "mass= " << massHypothesis
<< "\t" << "var= " << "mtot"
<< "\t" << "cat= " << categoryName[icat]
<< "\t" << "method= " << "sigmaEff"
<< "\t" << "width= " << ms_ggjj.second
<< "\t" << "mean= " << massHypothesis
<< endl;
if( CRYSTALBALL )
{
// Fit is in three steps:
// - gauss fit of the peak
// - gauss + pol3 fit of the full range
// - CB + pol3 fit of the full range
// Define pol3
RooRealVar a0_jj("a0_jj", "a0_jj", 0.5001, 0., 1.);
RooRealVar a1_jj("a1_jj", "a1_jj", 0.5001, 0., 1.);
RooRealVar a2_jj("a2_jj", "a2_jj", 0.5001, 0., 1.);
RooRealVar a3_jj("a3_jj", "a3_jj", 0.5001, 0., 1.);
RooBernstein pol3_jj("pol3_jj", "pol3_jj", jj_mass, RooArgList(a0_jj, a1_jj, a2_jj, a3_jj));
RooRealVar f0_jj("f0_jj", "f0_jj", 0.2, 0.001, .5);
// Define gauss and CB (common parameters)
RooRealVar mu_CrystalBall_jj("mu_CrystalBall_jj", "#mu", mean_jj, mean_jj-rms_jj, mean_jj+rms_jj, "GeV");
RooRealVar sigma_CrystalBall_jj("sigma_CrystalBall_jj", "#sigma", rms_jj, .01*rms_jj, 5*rms_jj, "GeV");
RooRealVar alpha_CrystalBall_jj("alpha_CrystalBall_jj", "#alpha", 1., 0., 30., "GeV");
RooRealVar n_CrystalBall_jj("n_CrystalBall_jj", "n", 10., 0., 30., "GeV");
RooCBShape CrystalBall_jj("CrystalBall_jj", "CrystalBall_jj", jj_mass, mu_CrystalBall_jj, sigma_CrystalBall_jj, alpha_CrystalBall_jj, n_CrystalBall_jj);
RooGaussian gauss_jj("gauss_jj", "gauss_jj", jj_mass, mu_CrystalBall_jj, sigma_CrystalBall_jj);
// Models definitions
RooAddPdf first_jj("first_jj", "first_jj", pol3_jj, gauss_jj, f0_jj);
RooAddPdf model_jj("model_jj", "model_jj", pol3_jj, CrystalBall_jj, f0_jj);
RooPlot * jj_frame = jj_mass.frame();
// plot data
dataset.plotOn(jj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
// first: gaussian fit
gauss_jj.fitTo(dataset, Save(), Range(mean_jj-1.5*rms_jj, mean_jj+1.5*rms_jj));
// then, pol3 fit
pol3_jj.fitTo(dataset, Save());
// then pol + gauss fit
first_jj.fitTo(dataset, Save());
// first_jj.plotOn(jj_frame, LineColor(kBlue), LineWidth(2));
// finally, CB + pol fit
RooFitResult *f = model_jj.fitTo(dataset, Save());
model_jj.plotOn(jj_frame, LineColor(kGreen+3), LineWidth(2));
RooArgList p = f->floatParsFinal();
jj_frame->Draw();
double res = sigma_CrystalBall_jj.getVal()/mu_CrystalBall_jj.getVal()*100.;
// printing out plot parameters + creating plots
plotParameters( &p, c1, 0, jj_frame, true, 1, Form("CrystalBall+Pol3 (%s)", categoryName[icat].c_str()), 98, 99, 2);
c1->Print(Form("pdf/mjj_m%d_CrystalBall_%s.pdf", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("root/mjj_m%d_CrystalBall_%s.root", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("gif/mjj_m%d_CrystalBall_%s.gif", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("png/mjj_m%d_CrystalBall_%s.png", massHypothesis, categoryName[icat].c_str()));
c1->Clear();
outfile << "mass= " << massHypothesis
<< "\t" << "var= " << "mjj"
<< "\t" << "cat= " << categoryName[icat]
<< "\t" << "method= " << "CrystalBall"
<< "\t" << "width= " << sigma_CrystalBall_jj.getVal()
<< "\t" << "mean= " << 125.
<< endl;
outfile << "mass= " << massHypothesis
<< "\t" << "var= " << "mjj"
<< "\t" << "cat= " << categoryName[icat]
<< "\t" << "method= " << "FWHM"
<< "\t" << "width= " << getFWHM(&model_jj, &jj_mass)
<< "\t" << "mean= " << 125.
<< endl;
// M_jjgg
// Define pol3
RooRealVar a0_ggjj("a0_ggjj", "a0_ggjj", 0.5001, 0., 1.);
RooRealVar a1_ggjj("a1_ggjj", "a1_ggjj", 0.5001, 0., 1.);
RooRealVar a2_ggjj("a2_ggjj", "a2_ggjj", 0.5001, 0., 1.);
RooRealVar a3_ggjj("a3_ggjj", "a3_ggjj", 0.5001, 0., 1.);
RooBernstein pol3_ggjj("pol3_ggjj", "pol3_ggjj", ggjj_mass, RooArgList(a0_ggjj, a1_ggjj, a2_ggjj, a3_ggjj));
RooRealVar f0_ggjj("f0_ggjj", "f0_ggjj", 0.2, 0.001, .5);
// Define gauss and CB (common parameters)
RooRealVar mu_CrystalBall_ggjj("mu_CrystalBall_ggjj", "#mu", mean_ggjj, mean_ggjj-rms_ggjj, mean_ggjj+rms_ggjj, "GeV");
RooRealVar sigma_CrystalBall_ggjj("sigma_CrystalBall_ggjj", "#sigma", rms_ggjj, .01*rms_ggjj, 5*rms_ggjj, "GeV");
RooRealVar alpha_CrystalBall_ggjj("alpha_CrystalBall_ggjj", "#alpha", 1., 0., 30., "GeV");
RooRealVar n_CrystalBall_ggjj("n_CrystalBall_ggjj", "n", 20., 0., 30., "GeV");
RooCBShape CrystalBall_ggjj("CrystalBall_ggjj", "CrystalBall_ggjj", ggjj_mass, mu_CrystalBall_ggjj, sigma_CrystalBall_ggjj, alpha_CrystalBall_ggjj, n_CrystalBall_ggjj);
RooGaussian gauss_ggjj("gauss_ggjj", "gauss_ggjj", ggjj_mass, mu_CrystalBall_ggjj, sigma_CrystalBall_ggjj);
// Models definitions
RooAddPdf first_ggjj("first_ggjj", "first_ggjj", pol3_ggjj, gauss_ggjj, f0_ggjj);
RooAddPdf model_ggjj("model_ggjj", "model_ggjj", pol3_ggjj, CrystalBall_ggjj, f0_ggjj);
RooPlot * ggjj_frame = ggjj_mass.frame();
// plot data
dataset.plotOn(ggjj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
// first: gaussian fit
gauss_ggjj.fitTo(dataset, Save(), Range(mean_ggjj-1.5*rms_ggjj, mean_ggjj+1.5*rms_ggjj));
// then, pol3 fit
pol3_ggjj.fitTo(dataset, Save());
// then pol + gauss fit
first_ggjj.fitTo(dataset, Save());
// first_ggjj.plotOn(ggjj_frame, LineColor(kBlue), LineWidth(2));
// finally, CB + pol fit
RooFitResult *fggjj = model_ggjj.fitTo(dataset, Save());
model_ggjj.plotOn(ggjj_frame, LineColor(kGreen+3), LineWidth(2));
RooArgList pggjj = fggjj->floatParsFinal();
ggjj_frame->Draw();
// printing out plot parameters + creating plots
plotParameters( &pggjj, c1, 0, ggjj_frame, true, 1, Form("CrystalBall+Pol3 (%s)", categoryName[icat].c_str()), 98, 99, 2);
c1->Print(Form("pdf/mggjj_m%d_CrystalBall_%s.pdf", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("root/mggjj_m%d_CrystalBall_%s.root", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("gif/mggjj_m%d_CrystalBall_%s.gif", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("png/mggjj_m%d_CrystalBall_%s.png", massHypothesis, categoryName[icat].c_str()));
c1->Clear();
double res_ = sigma_CrystalBall_ggjj.getVal()/mu_CrystalBall_ggjj.getVal()*100.;
outfile << "mass= " << massHypothesis
<< "\t" << "var= " << "mtot"
<< "\t" << "cat= " << categoryName[icat]
<< "\t" << "method= " << "CrystalBall"
<< "\t" << "width= " << sigma_CrystalBall_ggjj.getVal()
<< "\t" << "mean= " << massHypothesis
<< endl;
outfile << "mass= " << massHypothesis
<< "\t" << "var= " << "mtot"
<< "\t" << "cat= " << categoryName[icat]
<< "\t" << "method= " << "FWHM"
<< "\t" << "width= " << getFWHM(&model_ggjj, &ggjj_mass)
<< "\t" << "mean= " << massHypothesis
<< endl;
} // end of if CRYSTALBALL
} // end of loop over categories
// clean stuff
outfile.close();
delete c1;
c1 = 0;
infile->Close();
} else {
// TFile *infile = TFile::Open("simple_genjet.root");
// TFile *infile = TFile::Open("simple_parton.root");
// TFile *infilereg = TFile::Open("simple_reg_genjet.root");
// TFile *infilereg = TFile::Open("simple_reg_parton.root");
// TFile *infile = TFile::Open("simple_genjet_globeinputs.root");
// TTree *intree = (TTree*)infile->Get("Radion_m300_8TeV_nm");
// TFile *infilereg = TFile::Open("simple_reg_genjet_globeinputs.root");
// TTree *intreereg = (TTree*)infilereg->Get("Radion_m300_8TeV_nm");
TFile *infile = TFile::Open(inputfile.c_str());
TTree *intree = (TTree*)infile->Get(inputtree.c_str());
TFile *infilereg = TFile::Open(inputregfile.c_str());
TTree *intreereg = (TTree*)infilereg->Get(inputregtree.c_str());
// ofstream outfile;
// outfile.open(outputfile.c_str());
// TFile *infile = TFile::Open("2013-12-12_selection_noRegression_noMassCut_v02/Radion_m300_8TeV_noRegression_noMassCut_v02.root");
// TTree *intree = (TTree*)infile->Get("Radion_m300_8TeV");
// TFile *infilereg = TFile::Open("2013-12-12_selection_noRegression_noMassCut_v02/Radion_m350_8TeV_noRegression_noMassCut_v02.root");
// TTree *intreereg = (TTree*)infilereg->Get("Radion_m350_8TeV");
ofstream outfile_mjj, outfile_mggjj;
outfile_mjj.open(Form("performanceSummary_m%d_mjj.txt", massHypothesis));
outfile_mggjj.open(Form("performanceSummary_m%d_mggjj.txt", massHypothesis));
outfile_mjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
outfile_mggjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
// Observables
float min_jj = 50.;
float max_jj = 250.;
float min_ggjj = massHypothesis - 200.;
float max_ggjj = massHypothesis + 200.;
RooRealVar regjj_mass("regjj_mass", "m_{jj}", min_jj, max_jj, "GeV");
regjj_mass.setBins(50);
RooRealVar regggjj_mass("regggjj_mass", "m_{jj#gamma#gamma}", min_ggjj, max_ggjj, "GeV");
regggjj_mass.setBins(50);
RooRealVar njets_kRadionID_and_CSVM("njets_kRadionID_and_CSVM", "njets_kRadionID_and_CSVM", 0, 10);
TCanvas *c1 = new TCanvas("c1", "c1", 600, 600);
bool GAUSS = false;
bool CRYSTALBALL = true;
bool VOIGT = false;
bool SIMVOIGT = false;
vector<string> categoryCut;
categoryCut.clear();
vector<string> categoryName;
categoryName.clear();
categoryCut.push_back(Form("regjj_mass > %f && regjj_mass < %f && regggjj_mass > %f && regggjj_mass < %f", min_jj, max_jj, min_ggjj, max_ggjj));
categoryName.push_back("allcat");
categoryCut.push_back(Form("njets_kRadionID_and_CSVM < 1.5 && regjj_mass > %f && regjj_mass < %f && regggjj_mass > %f && regggjj_mass < %f", min_jj, max_jj, min_ggjj, max_ggjj));
categoryName.push_back("cat1");
categoryCut.push_back(Form("njets_kRadionID_and_CSVM > 1.5 && regjj_mass > %f && regjj_mass < %f && regggjj_mass > %f && regggjj_mass < %f", min_jj, max_jj, min_ggjj, max_ggjj));
categoryName.push_back("cat0");
for(int icat = 0 ; icat < (int)categoryCut.size() ; icat++)
{
// datatset definition depend on category
RooDataSet full_dataset("radion", "radion", intree, RooArgList(regjj_mass, regggjj_mass, njets_kRadionID_and_CSVM));
RooDataSet full_datasetreg("radion", "radion", intreereg, RooArgList(regjj_mass, regggjj_mass, njets_kRadionID_and_CSVM));
RooDataSet dataset = *((RooDataSet*)full_dataset.reduce(categoryCut[icat].c_str()));
RooDataSet datasetreg = *((RooDataSet*)full_datasetreg.reduce(categoryCut[icat].c_str()));
float mean_jj = dataset.mean(regjj_mass);
float mean_regjj = datasetreg.mean(regjj_mass);
float rms_jj = dataset.rmsVar(regjj_mass)->getVal();
float rms_regjj = datasetreg.rmsVar(regjj_mass)->getVal();
float mean_ggjj = dataset.mean(regggjj_mass);
float mean_regggjj = datasetreg.mean(regggjj_mass);
float rms_ggjj = dataset.rmsVar(regggjj_mass)->getVal();
float rms_regggjj = datasetreg.rmsVar(regggjj_mass)->getVal();
pair<float, float> ms_jj = make_pair(0., 0.);
pair<float, float> ms_regjj = make_pair(0., 0.);
pair<float, float> ms_ggjj = make_pair(0., 0.);
pair<float, float> ms_regggjj = make_pair(0., 0.);
ms_jj = sigmaEff(intree, "regjj_mass", categoryCut[icat]);
ms_regjj = sigmaEff(intreereg, "regjj_mass", categoryCut[icat]);
ms_ggjj = sigmaEff(intree, "regggjj_mass", categoryCut[icat]);
ms_regggjj = sigmaEff(intreereg, "regggjj_mass", categoryCut[icat]);
cout << "ncor: " << "\tmean= " << ms_jj.first << "\tsigma= " << ms_jj.second << "\tres= " << ms_jj.second / ms_jj.first * 100. << endl;
cout << "cor: " << "\tmean= " << ms_regjj.first << "\tsigma= " << ms_regjj.second << "\tres= " << ms_regjj.second / ms_regjj.first * 100. << endl;
cout << "improvement= " << - (ms_regjj.second / ms_regjj.first - ms_jj.second / ms_jj.first) / (ms_jj.second / ms_jj.first) * 100. << endl;
// outfile_mjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
outfile_mjj << setprecision (2) << fixed << categoryName[icat] << "\t" << "sigmaEff"
<< "\t" << ms_jj.first << "\t" << ms_jj.second << "\t" << ms_jj.second / ms_jj.first * 100.
<< "\t" << ms_regjj.first << "\t" << ms_regjj.second << "\t" << ms_regjj.second / ms_regjj.first * 100.
<< "\t" << - (ms_regjj.second / ms_regjj.first - ms_jj.second / ms_jj.first) / (ms_jj.second / ms_jj.first) * 100.
<< endl;
outfile_mggjj << setprecision (2) << fixed << categoryName[icat] << "\t" << "sigmaEff"
<< "\t" << ms_ggjj.first << "\t" << ms_ggjj.second << "\t" << ms_ggjj.second / ms_ggjj.first * 100.
<< "\t" << ms_regggjj.first << "\t" << ms_regggjj.second << "\t" << ms_regggjj.second / ms_regggjj.first * 100.
<< "\t" << - (ms_regggjj.second / ms_regggjj.first - ms_ggjj.second / ms_ggjj.first) / (ms_ggjj.second / ms_ggjj.first) * 100.
<< endl;
cout << "sigma improvement= " << (ms_jj.second - ms_regjj.second) / ms_jj.second * 100. << endl;
// fit parameters
if(GAUSS)
{
RooRealVar mu_gauss("mu_gauss", "mean", mean_jj, mean_jj-rms_jj, mean_jj+rms_jj, "GeV");
RooRealVar sigma_gauss("sigma_gauss", "sigma", rms_jj, .01*rms_jj, 5.*rms_jj, "GeV");
RooGaussian gauss("gauss", "gauss", regjj_mass, mu_gauss, sigma_gauss);
RooRealVar mu_gaussreg("mu_gaussreg", "mean (reg)", mean_regjj, mean_regjj-rms_regjj, mean_regjj+rms_regjj, "GeV");
RooRealVar sigma_gaussreg("sigma_gaussreg", "sigma (reg)", rms_regjj, .01*rms_regjj, 5.*rms_regjj, "GeV");
RooGaussian gaussreg("gaussreg", "gaussreg", regjj_mass, mu_gaussreg, sigma_gaussreg);
RooRealVar mu_gauss_("mu_gauss_", "mean", mean_ggjj, mean_ggjj-rms_ggjj, mean_ggjj+rms_ggjj, "GeV");
RooRealVar sigma_gauss_("sigma_gauss_", "sigma", rms_ggjj, .01*rms_ggjj, 5.*rms_ggjj, "GeV");
RooGaussian gauss_("gauss_", "gauss_", regggjj_mass, mu_gauss_, sigma_gauss_);
RooRealVar mu_gauss_reg("mu_gauss_reg", "mean (reg)", mean_regggjj, mean_regggjj-rms_regggjj, mean_regggjj+rms_regggjj, "GeV");
RooRealVar sigma_gauss_reg("sigma_gauss_reg", "sigma (reg)", rms_regggjj, .01*rms_regggjj, 5.*rms_regggjj, "GeV");
RooGaussian gauss_reg("gauss_reg", "gauss_reg", regggjj_mass, mu_gauss_reg, sigma_gauss_reg);
RooPlot * jj_frame = regjj_mass.frame();
dataset.plotOn(jj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(jj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
// RooFitResult *f = gauss.fitTo(dataset, Save(), Range(mean_jj-0.9*rms_jj, mean_jj+1.5*rms_jj));
RooFitResult *f = gauss.fitTo(dataset, Save(), Range(mean_jj-1.5*rms_jj, mean_jj+1.5*rms_jj));
gauss.plotOn(jj_frame, LineColor(kGreen+3), LineWidth(2));
RooFitResult * freg = gaussreg.fitTo(datasetreg, Save(), Range(mean_regjj-1.5*rms_regjj, mean_regjj+1.5*rms_regjj));
gaussreg.plotOn(jj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList p = f->floatParsFinal();
RooArgList preg = freg->floatParsFinal();
jj_frame->Draw();
float res = sigma_gauss.getVal() / mu_gauss.getVal() * 100.;
float resreg = sigma_gaussreg.getVal() / mu_gaussreg.getVal() * 100.;
plotParameters( &p, c1, 0, jj_frame, true, 1, "Gaussian", 98, 99, 2);
plotParameters( &preg, c1, 0, jj_frame, true, 3, "test", res, resreg, 2);
c1->Print(Form("pdf/mjj_gauss_%s.pdf", categoryName[icat].c_str()));
c1->Print(Form("root/mjj_gauss_%s.root", categoryName[icat].c_str()));
c1->Print(Form("gif/mjj_gauss_%s.gif", categoryName[icat].c_str()));
c1->Print(Form("png/mjj_gauss_%s.png", categoryName[icat].c_str()));
c1->Clear();
// outfile_mjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
outfile_mjj << setprecision (2) << fixed << categoryName[icat] << "\tGauss"
<< "\t" << mu_gauss.getVal() << "\t" << sigma_gauss.getVal() << "\t" << sigma_gauss.getVal() / mu_gauss.getVal() * 100.
<< "\t" << mu_gaussreg.getVal() << "\t" << sigma_gaussreg.getVal() << "\t" << sigma_gaussreg.getVal() / mu_gaussreg.getVal() * 100.
<< "\t" << - (resreg - res) / res * 100.
<< endl;
RooPlot * ggjj_frame = regggjj_mass.frame();
dataset.plotOn(ggjj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(ggjj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
RooFitResult *f_ = gauss_.fitTo(dataset, Save(), Range(mean_ggjj-1.5*rms_ggjj, mean_ggjj+1.5*rms_ggjj));
gauss_.plotOn(ggjj_frame, LineColor(kGreen+3), LineWidth(2));
RooFitResult * freg_ = gauss_reg.fitTo(datasetreg, Save(), Range(mean_regggjj-1.5*rms_regggjj, mean_regggjj+1.5*rms_regggjj));
gauss_reg.plotOn(ggjj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList p_ = f_->floatParsFinal();
RooArgList preg_ = freg_->floatParsFinal();
ggjj_frame->Draw();
float res_ = sigma_gauss_.getVal() / mu_gauss_.getVal() * 100.;
float resreg_ = sigma_gauss_reg.getVal() / mu_gauss_reg.getVal() * 100.;
plotParameters( &p_, c1, 0, ggjj_frame, true, 1, "Gaussian", 98, 99, 2);
plotParameters( &preg_, c1, 0, ggjj_frame, true, 3, "test", res_, resreg_, 2);
c1->Print(Form("pdf/mggjj_gauss_%s.pdf", categoryName[icat].c_str()));
c1->Print(Form("root/mggjj_gauss_%s.root", categoryName[icat].c_str()));
c1->Print(Form("gif/mggjj_gauss_%s.gif", categoryName[icat].c_str()));
c1->Print(Form("png/mggjj_gauss_%s.png", categoryName[icat].c_str()));
c1->Clear();
cout << "res= " << res << "\tresreg= " << resreg << "\timprov= " << fabs(res-resreg)/res*100. << endl;
cout << "res_= " << res_ << "\tresreg_= " << resreg_ << "\timprov= " << fabs(res_-resreg_)/res_*100. << endl;
// outfile_mjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
outfile_mggjj << setprecision (2) << fixed << categoryName[icat] << "\tGauss"
<< "\t" << mu_gauss_.getVal() << "\t" << sigma_gauss_.getVal() << "\t" << sigma_gauss_.getVal() / mu_gauss_.getVal() * 100.
<< "\t" << mu_gauss_reg.getVal() << "\t" << sigma_gauss_reg.getVal() << "\t" << sigma_gauss_reg.getVal() / mu_gauss_reg.getVal() * 100.
<< "\t" << - (resreg_ - res_) / res_ * 100.
<< endl;
} // end of if GAUSS
if( CRYSTALBALL )
{
// Fit is in three steps:
// - gauss fit of the peak
// - gauss + pol3 fit of the full range
// - CB + pol3 fit of the full range
// Define pol3
RooRealVar a0_jj("a0_jj", "a0_jj", 0.5001, 0., 1.);
RooRealVar a1_jj("a1_jj", "a1_jj", 0.5001, 0., 1.);
RooRealVar a2_jj("a2_jj", "a2_jj", 0.5001, 0., 1.);
RooRealVar a3_jj("a3_jj", "a3_jj", 0.5001, 0., 1.);
RooBernstein pol3_jj("pol3_jj", "pol3_jj", regjj_mass, RooArgList(a0_jj, a1_jj, a2_jj, a3_jj));
RooRealVar f0_jj("f0_jj", "f0_jj", 0.2, 0.001, .5);
RooRealVar a0_regjj("a0_regjj", "a0_regjj", 0.5001, 0., 1.);
RooRealVar a1_regjj("a1_regjj", "a1_regjj", 0.5001, 0., 1.);
RooRealVar a2_regjj("a2_regjj", "a2_regjj", 0.5001, 0., 1.);
RooRealVar a3_regjj("a3_regjj", "a3_regjj", 0.5001, 0., 1.);
RooBernstein pol3_regjj("pol3_regjj", "pol3_regjj", regjj_mass, RooArgList(a0_regjj, a1_regjj, a2_regjj, a3_regjj));
RooRealVar f0_regjj("f0_regjj", "f0_regjj", 0.2, 0.001, .5);
// Define gauss and CB (common parameters)
RooRealVar mu_CrystalBall_jj("mu_CrystalBall_jj", "#mu", mean_jj, mean_jj-rms_jj, mean_jj+rms_jj, "GeV");
RooRealVar sigma_CrystalBall_jj("sigma_CrystalBall_jj", "#sigma", rms_jj, .01*rms_jj, 5*rms_jj, "GeV");
RooRealVar alpha_CrystalBall_jj("alpha_CrystalBall_jj", "#alpha", 1., 0., 30., "GeV");
RooRealVar n_CrystalBall_jj("n_CrystalBall_jj", "n", 10., 0., 30., "GeV");
RooCBShape CrystalBall_jj("CrystalBall_jj", "CrystalBall_jj", regjj_mass, mu_CrystalBall_jj, sigma_CrystalBall_jj, alpha_CrystalBall_jj, n_CrystalBall_jj);
RooGaussian gauss_jj("gauss_jj", "gauss_jj", regjj_mass, mu_CrystalBall_jj, sigma_CrystalBall_jj);
RooRealVar mu_CrystalBall_regjj("mu_CrystalBall_regjj", "#mu (reg)", mean_regjj, mean_regjj-rms_regjj, mean_regjj+rms_regjj, "GeV");
RooRealVar sigma_CrystalBall_regjj("sigma_CrystalBall_regjj", "#sigma (reg)", rms_regjj, .01*rms_regjj, 5*rms_regjj, "GeV");
RooRealVar alpha_CrystalBall_regjj("alpha_CrystalBall_regjj", "#alpha (reg)", 1., 0., 30., "GeV");
RooRealVar n_CrystalBall_regjj("n_CrystalBall_regjj", "n (reg)", 10., 0., 30., "GeV");
RooCBShape CrystalBall_regjj("CrystalBall_regjj", "CrystalBall_regjj", regjj_mass, mu_CrystalBall_regjj, sigma_CrystalBall_regjj, alpha_CrystalBall_regjj, n_CrystalBall_regjj);
RooGaussian gauss_regjj("gauss_regjj", "gauss_regjj", regjj_mass, mu_CrystalBall_regjj, sigma_CrystalBall_regjj);
// Models definitions
RooAddPdf first_jj("first_jj", "first_jj", pol3_jj, gauss_jj, f0_jj);
RooAddPdf model_jj("model_jj", "model_jj", pol3_jj, CrystalBall_jj, f0_jj);
RooAddPdf first_regjj("first_regjj", "first_regjj", pol3_regjj, gauss_regjj, f0_regjj);
RooAddPdf model_regjj("model_regjj", "model_regjj", pol3_regjj, CrystalBall_regjj, f0_regjj);
RooPlot * jj_frame = regjj_mass.frame();
// plot data
dataset.plotOn(jj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(jj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
// first: gaussian fit
gauss_jj.fitTo(dataset, Save(), Range(mean_jj-1.5*rms_jj, mean_jj+1.5*rms_jj));
gauss_regjj.fitTo(dataset, Save(), Range(mean_regjj-1.5*rms_regjj, mean_regjj+1.5*rms_regjj));
// then, pol3 fit
pol3_jj.fitTo(dataset, Save());
pol3_regjj.fitTo(dataset, Save());
// then pol + gauss fit
first_jj.fitTo(dataset, Save());
// first_jj.plotOn(jj_frame, LineColor(kBlue), LineWidth(2));
first_regjj.fitTo(datasetreg, Save());
// first_regjj.plotOn(jj_frame, LineColor(kBlue), LineWidth(2));
// finally, CB + pol fit
RooFitResult *f = model_jj.fitTo(dataset, Save());
RooFitResult *freg = model_regjj.fitTo(datasetreg, Save());
model_jj.plotOn(jj_frame, LineColor(kGreen+3), LineWidth(2));
model_regjj.plotOn(jj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList p = f->floatParsFinal();
RooArgList preg = freg->floatParsFinal();
jj_frame->Draw();
double res = sigma_CrystalBall_jj.getVal()/mu_CrystalBall_jj.getVal()*100.;
double resreg = sigma_CrystalBall_regjj.getVal()/mu_CrystalBall_regjj.getVal()*100.;
// printing out plot parameters + creating plots
plotParameters( &p, c1, 0, jj_frame, true, 1, "CrystalBall+Pol3", 98, 99, 2);
plotParameters( &preg, c1, 0, jj_frame, true, 3, "test", sigma_CrystalBall_jj.getVal()/mu_CrystalBall_jj.getVal()*100., sigma_CrystalBall_regjj.getVal()/mu_CrystalBall_regjj.getVal()*100., 2);
c1->Print(Form("pdf/mjj_m%d_CrystalBall_%s.pdf", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("root/mjj_m%d_CrystalBall_%s.root", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("gif/mjj_m%d_CrystalBall_%s.gif", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("png/mjj_m%d_CrystalBall_%s.png", massHypothesis, categoryName[icat].c_str()));
c1->Clear();
// outfile_mjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
outfile_mjj << setprecision (2) << fixed << categoryName[icat] << "\tCrystalBall"
<< "\t" << mu_CrystalBall_jj.getVal() << "\t" << sigma_CrystalBall_jj.getVal() << "\t" << sigma_CrystalBall_jj.getVal() / mu_CrystalBall_jj.getVal() * 100.
<< "\t" << mu_CrystalBall_regjj.getVal() << "\t" << sigma_CrystalBall_regjj.getVal() << "\t" << sigma_CrystalBall_regjj.getVal() / mu_CrystalBall_regjj.getVal() * 100.
<< "\t" << - (resreg - res) / res * 100.
<< endl;
// M_jjgg
// Define pol3
RooRealVar a0_ggjj("a0_ggjj", "a0_ggjj", 0.5001, 0., 1.);
RooRealVar a1_ggjj("a1_ggjj", "a1_ggjj", 0.5001, 0., 1.);
RooRealVar a2_ggjj("a2_ggjj", "a2_ggjj", 0.5001, 0., 1.);
RooRealVar a3_ggjj("a3_ggjj", "a3_ggjj", 0.5001, 0., 1.);
RooBernstein pol3_ggjj("pol3_ggjj", "pol3_ggjj", regggjj_mass, RooArgList(a0_ggjj, a1_ggjj, a2_ggjj, a3_ggjj));
RooRealVar f0_ggjj("f0_ggjj", "f0_ggjj", 0.2, 0.001, .5);
RooRealVar a0_regggjj("a0_regggjj", "a0_regggjj", 0.5001, 0., 1.);
RooRealVar a1_regggjj("a1_regggjj", "a1_regggjj", 0.5001, 0., 1.);
RooRealVar a2_regggjj("a2_regggjj", "a2_regggjj", 0.5001, 0., 1.);
RooRealVar a3_regggjj("a3_regggjj", "a3_regggjj", 0.5001, 0., 1.);
RooBernstein pol3_regggjj("pol3_regggjj", "pol3_regggjj", regggjj_mass, RooArgList(a0_regggjj, a1_regggjj, a2_regggjj, a3_regggjj));
RooRealVar f0_regggjj("f0_regggjj", "f0_regggjj", 0.2, 0.001, .5);
// Define gauss and CB (common parameters)
RooRealVar mu_CrystalBall_ggjj("mu_CrystalBall_ggjj", "#mu", mean_ggjj, mean_ggjj-rms_ggjj, mean_ggjj+rms_ggjj, "GeV");
RooRealVar sigma_CrystalBall_ggjj("sigma_CrystalBall_ggjj", "#sigma", rms_ggjj, .01*rms_ggjj, 5*rms_ggjj, "GeV");
RooRealVar alpha_CrystalBall_ggjj("alpha_CrystalBall_ggjj", "#alpha", 1., 0., 30., "GeV");
RooRealVar n_CrystalBall_ggjj("n_CrystalBall_ggjj", "n", 20., 0., 30., "GeV");
RooCBShape CrystalBall_ggjj("CrystalBall_ggjj", "CrystalBall_ggjj", regggjj_mass, mu_CrystalBall_ggjj, sigma_CrystalBall_ggjj, alpha_CrystalBall_ggjj, n_CrystalBall_ggjj);
RooGaussian gauss_ggjj("gauss_ggjj", "gauss_ggjj", regggjj_mass, mu_CrystalBall_ggjj, sigma_CrystalBall_ggjj);
RooRealVar mu_CrystalBall_regggjj("mu_CrystalBall_regggjj", "#mu (reg)", mean_regggjj, mean_regggjj-rms_regggjj, mean_regggjj+rms_regggjj, "GeV");
RooRealVar sigma_CrystalBall_regggjj("sigma_CrystalBall_regggjj", "#sigma (reg)", rms_regggjj, .01*rms_regggjj, 5*rms_regggjj, "GeV");
RooRealVar alpha_CrystalBall_regggjj("alpha_CrystalBall_regggjj", "#alpha (reg)", 1., 0., 30., "GeV");
RooRealVar n_CrystalBall_regggjj("n_CrystalBall_regggjj", "n (reg)", 20., 0., 30., "GeV");
RooCBShape CrystalBall_regggjj("CrystalBall_regggjj", "CrystalBall_regggjj", regggjj_mass, mu_CrystalBall_regggjj, sigma_CrystalBall_regggjj, alpha_CrystalBall_regggjj, n_CrystalBall_regggjj);
RooGaussian gauss_regggjj("gauss_regggjj", "gauss_regggjj", regggjj_mass, mu_CrystalBall_regggjj, sigma_CrystalBall_regggjj);
// Models definitions
RooAddPdf first_ggjj("first_ggjj", "first_ggjj", pol3_ggjj, gauss_ggjj, f0_ggjj);
RooAddPdf model_ggjj("model_ggjj", "model_ggjj", pol3_ggjj, CrystalBall_ggjj, f0_ggjj);
RooAddPdf first_regggjj("first_regggjj", "first_regggjj", pol3_regggjj, gauss_regggjj, f0_regggjj);
RooAddPdf model_regggjj("model_regggjj", "model_regggjj", pol3_regggjj, CrystalBall_regggjj, f0_regggjj);
RooPlot * ggjj_frame = regggjj_mass.frame();
// plot data
dataset.plotOn(ggjj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(ggjj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
// first: gaussian fit
gauss_ggjj.fitTo(dataset, Save(), Range(mean_ggjj-1.5*rms_ggjj, mean_ggjj+1.5*rms_ggjj));
gauss_regggjj.fitTo(dataset, Save(), Range(mean_regggjj-1.5*rms_regggjj, mean_regggjj+1.5*rms_regggjj));
// then, pol3 fit
pol3_ggjj.fitTo(dataset, Save());
pol3_regggjj.fitTo(dataset, Save());
// then pol + gauss fit
first_ggjj.fitTo(dataset, Save());
// first_ggjj.plotOn(ggjj_frame, LineColor(kBlue), LineWidth(2));
first_regggjj.fitTo(datasetreg, Save());
// first_regggjj.plotOn(ggjj_frame, LineColor(kBlue), LineWidth(2));
// finally, CB + pol fit
RooFitResult *fggjj = model_ggjj.fitTo(dataset, Save());
RooFitResult *fregggjj = model_regggjj.fitTo(datasetreg, Save());
model_ggjj.plotOn(ggjj_frame, LineColor(kGreen+3), LineWidth(2));
model_regggjj.plotOn(ggjj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList pggjj = fggjj->floatParsFinal();
RooArgList pregggjj = fregggjj->floatParsFinal();
ggjj_frame->Draw();
// printing out plot parameters + creating plots
plotParameters( &pggjj, c1, 0, ggjj_frame, true, 1, "CrystalBall+Pol3", 98, 99, 2);
plotParameters( &pregggjj, c1, 0, ggjj_frame, true, 3, "test", sigma_CrystalBall_ggjj.getVal()/mu_CrystalBall_ggjj.getVal()*100., sigma_CrystalBall_regggjj.getVal()/mu_CrystalBall_regggjj.getVal()*100., 2);
c1->Print(Form("pdf/mggjj_m%d_CrystalBall_%s.pdf", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("root/mggjj_m%d_CrystalBall_%s.root", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("gif/mggjj_m%d_CrystalBall_%s.gif", massHypothesis, categoryName[icat].c_str()));
c1->Print(Form("png/mggjj_m%d_CrystalBall_%s.png", massHypothesis, categoryName[icat].c_str()));
c1->Clear();
double res_ = sigma_CrystalBall_ggjj.getVal()/mu_CrystalBall_ggjj.getVal()*100.;
double resreg_ = sigma_CrystalBall_regggjj.getVal()/mu_CrystalBall_regggjj.getVal()*100.;
// outfile_mjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
outfile_mggjj << setprecision (2) << fixed << categoryName[icat] << "\tCrystalBall"
<< "\t" << mu_CrystalBall_ggjj.getVal() << "\t" << sigma_CrystalBall_ggjj.getVal() << "\t" << sigma_CrystalBall_ggjj.getVal() / mu_CrystalBall_ggjj.getVal() * 100.
<< "\t" << mu_CrystalBall_regggjj.getVal() << "\t" << sigma_CrystalBall_regggjj.getVal() << "\t" << sigma_CrystalBall_regggjj.getVal() / mu_CrystalBall_regggjj.getVal() * 100.
<< "\t" << - (resreg_ - res_) / res_ * 100.
<< endl;
} // end of if CRYSTALBALL
if(VOIGT)
{
RooRealVar mu_voigt("mu_voigt", "mean", mean_jj, mean_jj-rms_jj, mean_jj+rms_jj, "GeV");
RooRealVar width_voigt("width_voigt", "width", rms_jj, 0.1*rms_jj, 5.*rms_jj, "GeV");
RooRealVar sigma_voigt("sigma_voigt", "sigma", 5., 0.0001, 20., "GeV");
RooVoigtian voigt("voigt", "voigt", regjj_mass, mu_voigt, width_voigt, sigma_voigt);
RooRealVar mu_voigtreg("mu_voigtreg", "mean (reg)", mean_regjj, mean_jj-rms_jj, mean_jj+rms_jj, "GeV");
RooRealVar width_voigtreg("width_voigtreg", "width (reg)", rms_jj, 0.1*rms_jj, 5.*rms_jj, "GeV");
RooRealVar sigma_voigtreg("sigma_voigtreg", "sigma (reg)", 5., 0.0001, 20., "GeV");
RooVoigtian voigtreg("voigtreg", "voigtreg", regjj_mass, mu_voigtreg, width_voigtreg, sigma_voigtreg);
RooVoigtian voigtreg2("voigtreg2", "voigtreg2", regjj_mass, mu_voigtreg, width_voigtreg, sigma_voigt);
RooPlot * jj_frame = regjj_mass.frame();
dataset.plotOn(jj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(jj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
RooFitResult *f = voigt.fitTo(dataset, Save());
voigt.plotOn(jj_frame, LineColor(kGreen+3), LineWidth(2));
RooFitResult * freg = voigtreg.fitTo(datasetreg, Save());
voigtreg.plotOn(jj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList p = f->floatParsFinal();
RooArgList preg = freg->floatParsFinal();
jj_frame->Draw();
float fg = 2. * sigma_voigt.getVal() * sqrt(2. * log(2));
float fl = 2. * width_voigt.getVal();
float fv = 0.5346 * fl + sqrt(0.2166 * pow(fl, 2.) + pow(fg, 2.));
float fgreg = 2. * sigma_voigtreg.getVal() * sqrt(2. * log(2));
float flreg = 2. * width_voigtreg.getVal();
float fvreg = 0.5346 * flreg + sqrt(0.2166 * pow(flreg, 2.) + pow(fgreg, 2.));
float res= fv / mu_voigt.getVal() * 100. / (2. * sqrt(2. * log(2.)));
float resreg= fvreg / mu_voigtreg.getVal() * 100. / (2. * sqrt(2. * log(2.)));
plotParameters( &p, c1, 0, jj_frame, true, 1, "Voigtian", 98, 99, 2);
plotParameters( &preg, c1, 0, jj_frame, true, 4, "test", res, resreg, 2);
c1->Print(Form("pdf/mjj_voigt_%s.pdf", categoryName[icat].c_str()));
c1->Print(Form("root/mjj_voigt_%s.root", categoryName[icat].c_str()));
c1->Print(Form("gif/mjj_voigt_%s.gif", categoryName[icat].c_str()));
c1->Print(Form("png/mjj_voigt_%s.png", categoryName[icat].c_str()));
c1->Clear();
// outfile_mjj << "Category\tMethod\tmu\tsigma\tres\tmu_reg\tsigma_reg\tres_reg\timprovement" << endl;
outfile_mjj << setprecision (2) << fixed << categoryName[icat] << "\tVoigt"
<< "\t" << mu_voigt.getVal() << "\t" << fv << "\t" << res
<< "\t" << mu_voigtreg.getVal() << "\t" << fvreg << "\t" << resreg
<< "\t" << - (resreg - res) / res * 100.
<< endl;
RooRealVar mu_voigt_("mu_voigt_", "mean", massHypothesis, min_ggjj, max_ggjj, "GeV");
RooRealVar width_voigt_("width_voigt_", "width", 35., 5., 50., "GeV");
RooRealVar sigma_voigt_("sigma_voigt_", "sigma", 5., .0, 20., "GeV");
RooVoigtian voigt_("voigt_", "voigt_", regggjj_mass, mu_voigt_, width_voigt_, sigma_voigt_);
RooRealVar mu_voigt_reg("mu_voigt_reg", "mean (reg)", massHypothesis, min_ggjj, max_ggjj, "GeV");
RooRealVar width_voigt_reg("width_voigt_reg", "width (reg)", 35., 5., 50., "GeV");
RooRealVar sigma_voigt_reg("sigma_voigt_reg", "sigma (reg)", 5., 0.0001, 20., "GeV");
RooVoigtian voigt_reg("voigt_reg", "voigt_reg", regggjj_mass, mu_voigt_reg, width_voigt_reg, sigma_voigt_reg);
RooPlot * ggjj_frame = regggjj_mass.frame();
dataset.plotOn(ggjj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(ggjj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
RooFitResult *f_ = voigt_.fitTo(dataset, Save());
voigt_.plotOn(ggjj_frame, LineColor(kGreen+3), LineWidth(2));
RooFitResult * freg_ = voigt_reg.fitTo(datasetreg, Save());
voigt_reg.plotOn(ggjj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList p_ = f_->floatParsFinal();
RooArgList preg_ = freg_->floatParsFinal();
ggjj_frame->Draw();
float fg_ = 2. * sigma_voigt_.getVal() * sqrt(2. * log(2));
float fl_ = 2. * width_voigt_.getVal();
float fv_ = 0.5346 * fl_ + sqrt(0.2166 * pow(fl_, 2.) + pow(fg_, 2.));
float fgreg_ = 2. * sigma_voigt_reg.getVal() * sqrt(2. * log(2));
float flreg_ = 2. * width_voigt_reg.getVal();
float fvreg_ = 0.5346 * flreg_ + sqrt(0.2166 * pow(flreg_, 2.) + pow(fgreg_, 2.));
float res_= fv_ / mu_voigt_.getVal() * 100. / (2. * sqrt(2. * log(2.)));
float resreg_= fvreg_ / mu_voigt_reg.getVal() * 100. / (2. * sqrt(2. * log(2.)));
plotParameters( &p_, c1, 0, ggjj_frame, true, 1, "Voigtian", 98, 99, 2);
plotParameters( &preg_, c1, 0, ggjj_frame, true, 4, "test", res_, resreg_, 2);
c1->Print(Form("pdf/mggjj_voigt_%s.pdf", categoryName[icat].c_str()));
c1->Print(Form("root/mggjj_voigt_%s.root", categoryName[icat].c_str()));
c1->Print(Form("gif/mggjj_voigt_%s.gif", categoryName[icat].c_str()));
c1->Print(Form("png/mggjj_voigt_%s.png", categoryName[icat].c_str()));
c1->Clear();
outfile_mggjj << setprecision (2) << fixed << categoryName[icat] << "\tVoigt"
<< "\t" << mu_voigt_.getVal() << "\t" << fv_ << "\t" << res_
<< "\t" << mu_voigt_reg.getVal() << "\t" << fvreg_ << "\t" << resreg_
<< "\t" << - (resreg_ - res_) / res_ * 100.
<< endl;
cout << "fg= " << fg << "\tfl= " << fl << "\tfv= " << fv << endl;
cout << "fgreg= " << fgreg << "\tflreg= " << flreg << "\tfvreg= " << fvreg << endl;
cout << "res= " << res << "\tresreg= " << resreg << "\timprov= " << fabs(res - resreg)/res * 100.<< endl;
cout << "fg_= " << fg_ << "\tfl_= " << fl_ << "\tfv_= " << fv_ << endl;
cout << "fgreg_= " << fgreg_ << "\tflreg_= " << flreg_ << "\tfvreg_= " << fvreg_ << endl;
cout << "res_= " << res_ << "\tresreg_= " << resreg_ << "\timprov_= " << fabs(res_ - resreg_)/res_ * 100.<< endl;
}// end of if VOIGT
if(SIMVOIGT)
{
RooRealVar mu_voigt("mu_voigt", "mean", mean_jj, mean_jj-rms_jj, mean_jj+rms_jj, "GeV");
RooRealVar width_voigt("width_voigt", "width", rms_jj, 0.1*rms_jj, 5.*rms_jj, "GeV");
RooRealVar sigma_voigt("sigma_voigt", "sigma", 5., 0.0001, 20., "GeV");
RooVoigtian voigt("voigt", "voigt", regjj_mass, mu_voigt, width_voigt, sigma_voigt);
RooRealVar mu_voigtreg("mu_voigtreg", "mean (reg)", mean_regjj, mean_jj-rms_jj, mean_jj+rms_jj, "GeV");
RooRealVar width_voigtreg("width_voigtreg", "width (reg)", rms_jj, 0.1*rms_jj, 5.*rms_jj, "GeV");
RooRealVar sigma_voigtreg("sigma_voigtreg", "sigma (reg)", 5., 0.0001, 20., "GeV");
RooVoigtian voigtreg2("voigtreg2", "voigtreg2", regjj_mass, mu_voigtreg, width_voigtreg, sigma_voigt);
RooCategory sample("sample", "sample");
sample.defineType("vanilla");
sample.defineType("regression");
RooDataSet combData("combdata", "combdata", RooArgList(regjj_mass, regggjj_mass), Index(sample), Import("vanilla", dataset), Import("regression", datasetreg));
RooSimultaneous sim("sim", "sim", sample);
sim.addPdf(voigt, "vanilla");
sim.addPdf(voigtreg2, "regression");
RooPlot * jj_frame = regjj_mass.frame();
dataset.plotOn(jj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(jj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
RooFitResult *f = sim.fitTo(combData, Save());
voigt.plotOn(jj_frame, LineColor(kGreen+3), LineWidth(2));
voigtreg2.plotOn(jj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList p = f->floatParsFinal();
jj_frame->Draw();
float fg = 2. * sigma_voigt.getVal() * sqrt(2. * log(2));
float fl = 2. * width_voigt.getVal();
float fv = 0.5346 * fl + sqrt(0.2166 * pow(fl, 2.) + pow(fg, 2.));
float fgreg = 2. * sigma_voigt.getVal() * sqrt(2. * log(2));
float flreg = 2. * width_voigtreg.getVal();
float fvreg = 0.5346 * flreg + sqrt(0.2166 * pow(flreg, 2.) + pow(fgreg, 2.));
float res= fv / mu_voigt.getVal() * 100. / (2. * sqrt(2. * log(2.)));
float resreg= fvreg / mu_voigtreg.getVal() * 100. / (2. * sqrt(2. * log(2.)));
plotParameters( &p, c1, 0, jj_frame, false, 1, "Simultaneous Voigtian fit", res, resreg, 2);
c1->Print(Form("pdf/mjj_simvoigt_%s.pdf", categoryName[icat].c_str()));
c1->Print(Form("root/mjj_simvoigt_%s.root", categoryName[icat].c_str()));
c1->Print(Form("gif/mjj_simvoigt_%s.gif", categoryName[icat].c_str()));
c1->Print(Form("png/mjj_simvoigt_%s.png", categoryName[icat].c_str()));
c1->Clear();
outfile_mjj << setprecision (2) << fixed << categoryName[icat] << "\tSimVoigt"
<< "\t" << mu_voigt.getVal() << "\t" << fv << "\t" << res
<< "\t" << mu_voigtreg.getVal() << "\t" << fvreg << "\t" << resreg
<< "\t" << - (resreg - res) / res * 100.
<< endl;
RooRealVar mu_voigt_("mu_voigt_", "mean", massHypothesis, min_ggjj, max_ggjj, "GeV");
RooRealVar width_voigt_("width_voigt_", "width", 35., 5., 50., "GeV");
RooRealVar sigma_voigt_("sigma_voigt_", "sigma", 5., .0, 20., "GeV");
RooVoigtian voigt_("voigt_", "voigt_", regggjj_mass, mu_voigt_, width_voigt_, sigma_voigt_);
RooRealVar mu_voigt_reg("mu_voigt_reg", "mean (reg)", massHypothesis, min_ggjj, max_ggjj, "GeV");
RooRealVar width_voigt_reg("width_voigt_reg", "width (reg)", 35., 5., 50., "GeV");
RooRealVar sigma_voigt_reg("sigma_voigt_reg", "sigma (reg)", 5., 0.0001, 20., "GeV");
RooVoigtian voigt_reg2("voigt_reg2", "voigt_reg2", regggjj_mass, mu_voigt_reg, width_voigt_reg, sigma_voigt_);
RooSimultaneous sim_("sim_", "sim_", sample);
sim_.addPdf(voigt_, "vanilla");
sim_.addPdf(voigt_reg2, "regression");
RooPlot * ggjj_frame = regggjj_mass.frame();
dataset.plotOn(ggjj_frame, LineColor(kGreen+3), MarkerColor(kGreen+3), XErrorSize(0));
datasetreg.plotOn(ggjj_frame, LineColor(kRed+2), MarkerColor(kRed+2), MarkerStyle(23), XErrorSize(0));
RooFitResult *f_ = sim_.fitTo(combData, Save());
voigt_.plotOn(ggjj_frame, LineColor(kGreen+3), LineWidth(2));
voigt_reg2.plotOn(ggjj_frame, LineColor(kRed+2), LineWidth(2));
RooArgList p_ = f_->floatParsFinal();
ggjj_frame->Draw();
float fg_ = 2. * sigma_voigt_.getVal() * sqrt(2. * log(2));
float fl_ = 2. * width_voigt_.getVal();
float fv_ = 0.5346 * fl_ + sqrt(0.2166 * pow(fl_, 2.) + pow(fg_, 2.));
float fg_reg = 2. * sigma_voigt_.getVal() * sqrt(2. * log(2));
float fl_reg = 2. * width_voigt_reg.getVal();
float fv_reg = 0.5346 * fl_reg + sqrt(0.2166 * pow(fl_reg, 2.) + pow(fg_reg, 2.));
float res_= fv_ / mu_voigt_.getVal() * 100. / (2. * sqrt(2. * log(2.)));
float resreg_= fv_reg / mu_voigt_reg.getVal() * 100. / (2. * sqrt(2. * log(2.)));
plotParameters( &p_, c1, 0, ggjj_frame, false, 1, "Simultaneous Voigtian fit", res_, resreg_, 2);
c1->Print(Form("pdf/mggjj_simvoigt_%s.pdf", categoryName[icat].c_str()));
c1->Print(Form("root/mggjj_simvoigt_%s.root", categoryName[icat].c_str()));
c1->Print(Form("gif/mggjj_simvoigt_%s.gif", categoryName[icat].c_str()));
c1->Print(Form("png/mggjj_simvoigt_%s.png", categoryName[icat].c_str()));
c1->Clear();
outfile_mggjj << setprecision (2) << fixed << categoryName[icat] << "\tSimVoigt"
<< "\t" << mu_voigt_.getVal() << "\t" << fv_ << "\t" << res_
<< "\t" << mu_voigt_reg.getVal() << "\t" << fv_reg << "\t" << resreg_
<< "\t" << - (resreg_ - res_) / res_ * 100.
<< endl;
} // end of if SIMVOIGT
}// end of loop over categories
outfile_mjj.close();
outfile_mggjj.close();
delete c1;
c1 = 0;
infile->Close();
infilereg->Close();
} // end of if compareWithRegression
return 0;
} // end of main
void plotParameters(RooArgList *r2_cat0_param, TCanvas *c, int canvasDivision, RooPlot* frame0, bool isThereSeveralFits, int iclass, string fitfunctionName, float mvaInf, float mvaSup, int precision )
{
// cout << "entering plotParameters" << endl;
// Written by H. Brun (November 2011)
c->cd(canvasDivision);
TLatex latexLabel;
latexLabel.SetNDC();
latexLabel.SetTextSize(0.03);
std::ostringstream mvaStream;
mvaStream << setprecision (3) << fixed << mvaInf << " #leq mva < " << mvaSup;
string mvaString = mvaStream.str();
// latexLabel.DrawLatex(0.18, 0.96, Form("CMS Private 2011, #sqrt{s} = 7 TeV, Simulation: %s, %s", isThereSeveralFits ? "signal":"background", mvaString.c_str()));
latexLabel.DrawLatex(0.18, 0.96, "CMS Private 2013, #sqrt{s} = 8 TeV");
// latexLabel.DrawLatex(0.45, 0.91, "#sqrt{s} = 7 TeV");
// latexLabel.DrawLatex(0.67, 0.91, isThereSeveralFits ? "Simulation: signal" : "Simulation: background");
latexLabel.SetTextSize(0.03);
RooRealVar* obj = new RooRealVar();
float position = 0.92;
position -= 0.04 * (iclass);
if(iclass == 1) latexLabel.DrawLatex(0.55, position, Form("Fit: %s", fitfunctionName.c_str()));
TIterator *it = (TIterator*) r2_cat0_param->createIterator();
obj = (RooRealVar*)it->Next();
while( obj != 0 )
{
// cout << "obj->GetName()= " << obj->GetName() << "\tobj->getVal()= " << obj->getVal() << "\tobj->getError()= " << obj->getError() << endl;
if( strspn("f0_", (char*)obj->GetName())>=3 ) {obj = (RooRealVar*)it->Next(); continue;}
if( strspn("a0_", (char*)obj->GetName())>=3 ) {obj = (RooRealVar*)it->Next(); continue;}
if( strspn("a1_", (char*)obj->GetName())>=3 ) {obj = (RooRealVar*)it->Next(); continue;}
if( strspn("a2_", (char*)obj->GetName())>=3 ) {obj = (RooRealVar*)it->Next(); continue;}
if( strspn("a3_", (char*)obj->GetName())>=3 ) {obj = (RooRealVar*)it->Next(); continue;}
if( strspn("n_", (char*)obj->GetName())>=2 ) {obj = (RooRealVar*)it->Next(); continue;}
if( strspn("alpha_", (char*)obj->GetName())>=6 ) {obj = (RooRealVar*)it->Next(); continue;}
position -= 0.04;
std::ostringstream valueStream;
if( (float)obj->getError() != 0.0 )
{
valueStream << setprecision (precision) << fixed << (float)obj->getVal() << " +- " << (float)obj->getError();
// cout << setprecision (precision) << fixed << (float)obj->getVal() << " +- " << (float)obj->getError() << endl;;
} else {
valueStream << setprecision (precision) << fixed << (float)obj->getVal();
}
string valueString = valueStream.str();
latexLabel.DrawLatex(0.60, position, Form("%s = %s %s", obj->GetTitle(), valueString.c_str(), (char*)obj->getUnit()));
cout << "obj->GetName()= " << obj->GetName() << "\tobj->getVal()= " << ((RooRealVar*)obj)->getVal() << endl;
obj = (RooRealVar*)it->Next();
}
if( (iclass != 1) || (!isThereSeveralFits) )
{
position -= 0.04;
std::ostringstream valueStream;
valueStream << setprecision (precision) << fixed << mvaInf;
string valueString = valueStream.str();
latexLabel.DrawLatex(0.60, position, Form("#sigma/#mu= %s %%", valueString.c_str()));
position -= 0.04;
valueStream.clear(); valueStream.str(""); valueString = "";
valueStream << setprecision (precision) << fixed << mvaSup;
valueString = valueStream.str();
latexLabel.DrawLatex(0.60, position, Form("#sigma/#mu (reg)= %s %%", valueString.c_str()));
position -= 0.04;
valueStream.clear(); valueStream.str(""); valueString = "";
valueStream << setprecision (precision) << fixed << fabs(mvaInf - mvaSup) / mvaInf * 100.;
valueString = valueStream.str();
latexLabel.DrawLatex(0.60, position, Form("improvement= %s %%", valueString.c_str()));
}
return;
} // end of plotParameters
pair<float,float> sigmaEff(TTree* tree, string var, string cut)
{
float sigmaEff_ = 0.;
float mean = 0.;
int ntot = tree->GetEntries(cut.c_str());
float variable = 0.;
tree->SetBranchAddress(var.c_str(), &variable);
tree->Draw(">>elist", cut.c_str(), "entrylist");
// tree->Draw(">>elist", "regjj_mass < 300", "entrylist");
TEntryList *elist = (TEntryList*)gDirectory->Get("elist");
// cout << "ntot= " << ntot << endl;
// cout << "elist->GetN()= " << elist->GetN() << endl;
// tree->SetEntryList(elist);
int ievt = elist->GetEntry(0);
vector<float> values;
for(int ievtlist = 0 ; ievtlist < ntot ; ievtlist++)
{
if(ievt < 0 ) continue;
// cout << "ievtlist= " << ievtlist << "\tievt= " << ievt << endl;
tree->GetEntry(ievt);
mean += variable / (float)ntot;
values.push_back(variable);
ievt = elist->Next();
}// end of event loop
// sorting values
sort(values.begin(), values.end());
// number of entries to be considered
// 1 sigma = 68.2689492%
int nInSigma = floor(elist->GetN() * 0.682689492);
// cout << "nInSigma= " << nInSigma << endl;
sigmaEff_ = values[elist->GetN()-1] - values[0];
// cout << "sigmaEff_= " << sigmaEff_ << endl;
float valueMin = values[0];
float valueMax = values[elist->GetN()-1];
float sigma = valueMax - valueMin;
// cout << "valueMin= " << valueMin << "\tvalueMax= " << valueMax << endl;
for(int iscan = 0 ; iscan < (elist->GetN() - nInSigma) ; iscan++)
{
sigma = values[iscan+nInSigma] - values[iscan];
// cout << "iscan= " << iscan << "\tvalues[iscan]= " << values[iscan] << "\tvalues[iscan+nInSigma]= " << values[iscan+nInSigma] << "\tsigma= " << sigma << "\tsigmaMax= " << sigmaMax << endl;
if( sigma < sigmaEff_ )
{
valueMin = values[iscan];
valueMax = values[iscan+nInSigma];
sigmaEff_ = sigma;
}
}
// sigmaEff_ = sigmaEff_;
tree->ResetBranchAddresses();
// cout << "elist->GetN()= " << elist->GetN() << "\tvalues.size()= " << values.size() << endl;
// cout << var << "\tcut= " << cut << "\tntot= " << ntot << "\tmean= " << mean << endl;
return make_pair(mean, sigmaEff_);
} // end of sigmaEff
float getFWHM(RooAddPdf *pdf, RooRealVar *var)