-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatAnalysis.cc
More file actions
2955 lines (2635 loc) · 147 KB
/
StatAnalysis.cc
File metadata and controls
2955 lines (2635 loc) · 147 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "../interface/StatAnalysis.h"
#include "Sorters.h"
#include "PhotonReducedInfo.h"
#include <iostream>
#include <algorithm>
#include <stdio.h>
#define PADEBUG 0
#define FMDEBUG 0
#define FMDEBUG_1 0
using namespace std;
void dumpPhoton(std::ostream & eventListText, int lab,
LoopAll & l, int ipho, int ivtx, TLorentzVector & phop4, float * pho_energy_array);
void dumpJet(std::ostream & eventListText, int lab, LoopAll & l, int ijet);
// ----------------------------------------------------------------------------------------------------
StatAnalysis::StatAnalysis() :
name_("StatAnalysis")
{
systRange = 3.; // in units of sigma
nSystSteps = 1;
doSystematics = true;
nVBFDijetJetCategories=2;
scaleClusterShapes = true;
dumpAscii = false;
dumpMcAscii = false;
unblind = false;
doMcOptimization = false;
nVBFCategories = 0;
nVHhadCategories = 0;
nVHhadBtagCategories = 0;
nVHlepCategories = 0;
nVHmetCategories = 0;
nTTHhadCategories = 0;
nTTHlepCategories = 0;
nTprimehadCategories = 0;//GIUSEPPE
nTprimelepCategories = 0;//GIUSEPPE
nLooseCategories = 0;//GIUSEPPE
ntHqLeptonicCategories = 0;
nVtxCategories = 0;
R9CatBoundary = 0.94;
fillOptTree = false;
doFullMvaFinalTree = false;
splitwzh=false;
sigmaMrv=0.;
sigmaMwv=0.;
}
// ----------------------------------------------------------------------------------------------------
StatAnalysis::~StatAnalysis()
{
}
// ----------------------------------------------------------------------------------------------------
void StatAnalysis::Term(LoopAll& l)
{
std::string outputfilename = (std::string) l.histFileName;
cout<<"OUTFILENAME"<<outputfilename<<endl;
// Make Fits to the data-sets and systematic sets
std::string postfix=(dataIs2011?"":"_8TeV");
l.rooContainer->FitToData("data_pol_model"+postfix,"data_mass"); // Fit to full range of dataset
// l.rooContainer->WriteSpecificCategoryDataCards(outputfilename,"data_mass","sig_mass","data_pol_model");
// l.rooContainer->WriteDataCard(outputfilename,"data_mass","sig_mass","data_pol_model");
// mode 0 as above, 1 if want to bin in sub range from fit,
// Write the data-card for the Combinations Code, needs the output filename, makes binned analysis DataCard
// Assumes the signal datasets will be called signal_name+"_mXXX"
// l.rooContainer->GenerateBinnedPdf("bkg_mass_rebinned","data_pol_model","data_mass",1,50,1); // 1 means systematics from the fit effect only the backgroundi. last digit mode = 1 means this is an internal constraint fit
// l.rooContainer->WriteDataCard(outputfilename,"data_mass","sig_mass","bkg_mass_rebinned");
eventListText.close();
lep_sync.close();
std::cout << " nevents " << nevents << " " << sumwei << std::endl;
met_sync.close();
// kfacFile->Close();
// PhotonAnalysis::Term(l);
}
// ----------------------------------------------------------------------------------------------------
void StatAnalysis::Init(LoopAll& l)
{
if(PADEBUG)
cout << "InitRealStatAnalysis START"<<endl;
nevents=0., sumwei=0.;
sumaccept=0., sumsmear=0., sumev=0.;
met_sync.open ("met_sync.txt");
std::string outputfilename = (std::string) l.histFileName;
eventListText.open(Form("%s",l.outputTextFileName.c_str()));
lep_sync.open ("lep_sync.txt");
//eventListText.open(Form("%s_ascii_events.txt",outputfilename.c_str()));
FillSignalLabelMap(l);
//
// These parameters are set in the configuration file
std::cout
<< "\n"
<< "-------------------------------------------------------------------------------------- \n"
<< "StatAnalysis " << "\n"
<< "-------------------------------------------------------------------------------------- \n"
<< "leadEtCut "<< leadEtCut << "\n"
<< "subleadEtCut "<< subleadEtCut << "\n"
<< "doTriggerSelection "<< doTriggerSelection << "\n"
<< "nEtaCategories "<< nEtaCategories << "\n"
<< "nR9Categories "<< nR9Categories << "\n"
<< "nPtCategories "<< nPtCategories << "\n"
<< "doEscaleSyst "<< doEscaleSyst << "\n"
<< "doEresolSyst "<< doEresolSyst << "\n"
<< "doEcorrectionSyst "<< doEcorrectionSyst << "\n"
<< "efficiencyFile " << efficiencyFile << "\n"
<< "doPhotonIdEffSyst "<< doPhotonIdEffSyst << "\n"
<< "doR9Syst "<< doR9Syst << "\n"
<< "doVtxEffSyst "<< doVtxEffSyst << "\n"
<< "doTriggerEffSyst "<< doTriggerEffSyst << "\n"
<< "doKFactorSyst "<< doKFactorSyst << "\n"
<< "-------------------------------------------------------------------------------------- \n"
<< std::endl;
// call the base class initializer
PhotonAnalysis::Init(l);
// Avoid reweighing from histo conainer
for(size_t ind=0; ind<l.histoContainer.size(); ind++) {
l.histoContainer[ind].setScale(1.);
}
diPhoCounter_ = l.countersred.size();
l.countersred.resize(diPhoCounter_+1);
// initialize the analysis variables
nInclusiveCategories_ = nEtaCategories;
if( nR9Categories != 0 ) nInclusiveCategories_ *= nR9Categories;
if( nPtCategories != 0 ) nInclusiveCategories_ *= nPtCategories;
// mva removed cp march 8
//if( useMVA ) nInclusiveCategories_ = nDiphoEventClasses;
// CP
nPhotonCategories_ = nEtaCategories;
if( nR9Categories != 0 ) nPhotonCategories_ *= nR9Categories;
nVBFCategories = ((int)includeVBF)*( (mvaVbfSelection && !multiclassVbfSelection) ? mvaVbfCatBoundaries.size()-1 : nVBFEtaCategories*nVBFDijetJetCategories );
std::sort(mvaVbfCatBoundaries.begin(),mvaVbfCatBoundaries.end(), std::greater<float>() );
if (multiclassVbfSelection) {
std::vector<int> vsize;
vsize.push_back((int)multiclassVbfCatBoundaries0.size());
vsize.push_back((int)multiclassVbfCatBoundaries1.size());
vsize.push_back((int)multiclassVbfCatBoundaries2.size());
std::sort(vsize.begin(),vsize.end(), std::greater<int>());
// sanity check: there sould be at least 2 vectors with size==2
if (vsize[0]<2 || vsize[1]<2 ){
std::cout << "Not enough category boundaries:" << std::endl;
std::cout << "multiclassVbfCatBoundaries0 size = " << multiclassVbfCatBoundaries0.size() << endl;
std::cout << "multiclassVbfCatBoundaries1 size = " << multiclassVbfCatBoundaries1.size() << endl;
std::cout << "multiclassVbfCatBoundaries2 size = " << multiclassVbfCatBoundaries2.size() << endl;
assert( 0 );
}
nVBFCategories = vsize[0]-1;
std::sort(multiclassVbfCatBoundaries0.begin(),multiclassVbfCatBoundaries0.end(), std::greater<float>() );
std::sort(multiclassVbfCatBoundaries1.begin(),multiclassVbfCatBoundaries1.end(), std::greater<float>() );
std::sort(multiclassVbfCatBoundaries2.begin(),multiclassVbfCatBoundaries2.end(), std::greater<float>() );
}
nVHhadCategories = ((int)includeVHhad)*nVHhadEtaCategories;
nVHhadBtagCategories =((int)includeVHhadBtag);
nTTHhadCategories =((int)includeTTHhad);
nTTHlepCategories =((int)includeTTHlep);
nTprimehadCategories =((int)includeTprimehad);//GIUSEPPE
nTprimelepCategories =((int)includeTprimelep);//GIUSEPPE
nLooseCategories =((int)includeLoose);//GIUSEPPE
ntHqLeptonicCategories = ((int)includetHqLeptonic);
if(includeVHlep){
nVHlepCategories = nElectronCategories + nMuonCategories;
}
//--------------------------- ANIELLO --------------------------//
if(includeVHlepB){
nVHlepCategories = 2;
}
//-------------------------------------------------------------//
nVHmetCategories = (int)includeVHmet; //met at analysis step
// nCategories_=(nInclusiveCategories_+nVBFCategories+nVHhadCategories+nVHlepCategories+nVHmetCategories); //met at analysis step
// nCategories_=(nInclusiveCategories_+nVBFCategories+nVHhadCategories+nVHlepCategories);
//CONTROLLO NUMERO DI CATEGORIE:
nCategories_=(nInclusiveCategories_+nVBFCategories+nVHhadCategories+nVHlepCategories+nVHmetCategories+nVHhadBtagCategories+nTTHhadCategories+nTTHlepCategories+ntHqLeptonicCategories+nTprimehadCategories+nTprimelepCategories+nLooseCategories); //=>Tprime GIUSEPPE
cout<<"Numero di categorie"<<nCategories_<<endl;
cout<<"Numero di inclusive"<<nInclusiveCategories_<<endl;
cout<<"Numero di VBF"<<nVBFCategories<<endl;
cout<<"Numero di categorie VHhad"<<nVHhadCategories<<endl;
cout<<"Numero di categorie VH lep"<<nVHlepCategories<<endl;
cout<<"Numero di categorie VH met"<<nVHmetCategories<<endl;
cout<<"Numero di categorie VH had Btag"<<nVHhadBtagCategories<<endl;
cout<<"Numero di categorie TTh had"<<nTTHhadCategories<<endl;
cout<<"Numero di categorie TTh lep"<<nTTHlepCategories<<endl;
cout<<"Numero di categorie THq"<<ntHqLeptonicCategories<<endl;
cout<<"Numero di categorie Tprime had"<<nTprimehadCategories<<endl;
cout<<"Numero di categorie Tprime lep"<<nTprimelepCategories<<endl;
cout<<"Numero di categorie Loose"<<nLooseCategories<<endl;
effSmearPars.categoryType = effPhotonCategoryType;
effSmearPars.n_categories = effPhotonNCat;
effSmearPars.efficiency_file = efficiencyFile;
diPhoEffSmearPars.n_categories = 8;
diPhoEffSmearPars.efficiency_file = efficiencyFile;
if( doEcorrectionSmear ) {
// instance of this smearer done in PhotonAnalysis
photonSmearers_.push_back(eCorrSmearer);
}
if( doEscaleSmear ) {
setupEscaleSmearer();
}
if( doEresolSmear ) {
setupEresolSmearer();
}
if( doPhotonIdEffSmear ) {
// photon ID efficiency
std::cerr << __LINE__ << std::endl;
idEffSmearer = new EfficiencySmearer( effSmearPars );
idEffSmearer->name("idEff");
idEffSmearer->setEffName("ratioTP");
idEffSmearer->init();
idEffSmearer->doPhoId(true);
photonSmearers_.push_back(idEffSmearer);
}
if( doR9Smear ) {
// R9 re-weighting
r9Smearer = new EfficiencySmearer( effSmearPars );
r9Smearer->name("r9Eff");
r9Smearer->setEffName("ratioR9");
r9Smearer->init();
r9Smearer->doR9(true);
photonSmearers_.push_back(r9Smearer);
}
if( doVtxEffSmear ) {
// Vertex ID
std::cerr << __LINE__ << std::endl;
vtxEffSmearer = new DiPhoEfficiencySmearer( diPhoEffSmearPars ); // triplicate TF1's here
vtxEffSmearer->name("vtxEff");
vtxEffSmearer->setEffName("ratioVertex");
vtxEffSmearer->doVtxEff(true);
vtxEffSmearer->init();
diPhotonSmearers_.push_back(vtxEffSmearer);
}
if( doTriggerEffSmear ) {
// trigger efficiency
std::cerr << __LINE__ << std::endl;
triggerEffSmearer = new DiPhoEfficiencySmearer( diPhoEffSmearPars );
triggerEffSmearer->name("triggerEff");
triggerEffSmearer->setEffName("effL1HLT");
triggerEffSmearer->doVtxEff(false);
triggerEffSmearer->init();
diPhotonSmearers_.push_back(triggerEffSmearer);
}
if(doKFactorSmear) {
// kFactor efficiency
std::cerr << __LINE__ << std::endl;
kFactorSmearer = new KFactorSmearer( kfacHist );
kFactorSmearer->name("kFactor");
kFactorSmearer->init();
genLevelSmearers_.push_back(kFactorSmearer);
}
if(doInterferenceSmear) {
// interference efficiency
std::cerr << __LINE__ << std::endl;
interferenceSmearer = new InterferenceSmearer(2.5e-2,0.);
genLevelSmearers_.push_back(interferenceSmearer);
}
// Define the number of categories for the statistical analysis and
// the systematic sets to be formed
// FIXME move these params to config file
l.rooContainer->SetNCategories(nCategories_);
l.rooContainer->nsigmas = nSystSteps;
l.rooContainer->sigmaRange = systRange;
if( doEcorrectionSmear && doEcorrectionSyst ) {
// instance of this smearer done in PhotonAnalysis
systPhotonSmearers_.push_back(eCorrSmearer);
std::vector<std::string> sys(1,eCorrSmearer->name());
std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
if( doEscaleSmear && doEscaleSyst ) {
setupEscaleSyst(l);
//// systPhotonSmearers_.push_back( eScaleSmearer );
//// std::vector<std::string> sys(1,eScaleSmearer->name());
//// std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
//// l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
if( doEresolSmear && doEresolSyst ) {
setupEresolSyst(l);
//// systPhotonSmearers_.push_back( eResolSmearer );
//// std::vector<std::string> sys(1,eResolSmearer->name());
//// std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
//// l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
if( doPhotonIdEffSmear && doPhotonIdEffSyst ) {
systPhotonSmearers_.push_back( idEffSmearer );
std::vector<std::string> sys(1,idEffSmearer->name());
std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
if( doR9Smear && doR9Syst ) {
systPhotonSmearers_.push_back( r9Smearer );
std::vector<std::string> sys(1,r9Smearer->name());
std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
if( doVtxEffSmear && doVtxEffSyst ) {
systDiPhotonSmearers_.push_back( vtxEffSmearer );
std::vector<std::string> sys(1,vtxEffSmearer->name());
std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
if( doTriggerEffSmear && doTriggerEffSyst ) {
systDiPhotonSmearers_.push_back( triggerEffSmearer );
std::vector<std::string> sys(1,triggerEffSmearer->name());
std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
if(doKFactorSmear && doKFactorSyst) {
systGenLevelSmearers_.push_back(kFactorSmearer);
std::vector<std::string> sys(1,kFactorSmearer->name());
std::vector<int> sys_t(1,-1); // -1 for signal, 1 for background 0 for both
l.rooContainer->MakeSystematicStudy(sys,sys_t);
}
// ----------------------------------------------------
// ----------------------------------------------------
// Global systematics - Lumi
l.rooContainer->AddGlobalSystematic("lumi",1.045,1.00);
// ----------------------------------------------------
// Create observables for shape-analysis with ranges
// l.rooContainer->AddObservable("mass" ,100.,150.);
l.rooContainer->AddObservable("CMS_hgg_mass" ,massMin,massMax);
l.rooContainer->AddConstant("IntLumi",l.intlumi_);
// SM Model
l.rooContainer->AddConstant("XSBR_tth_155",0.00004370);
l.rooContainer->AddConstant("XSBR_ggh_150",0.01428);
l.rooContainer->AddConstant("XSBR_vbf_150",0.001308);
l.rooContainer->AddConstant("XSBR_wzh_150",0.000641);
l.rooContainer->AddConstant("XSBR_tth_150",0.000066);
l.rooContainer->AddConstant("XSBR_ggh_145",0.018820);
l.rooContainer->AddConstant("XSBR_vbf_145",0.001676);
l.rooContainer->AddConstant("XSBR_wzh_145",0.000891);
l.rooContainer->AddConstant("XSBR_tth_145",0.000090);
l.rooContainer->AddConstant("XSBR_ggh_140",0.0234109);
l.rooContainer->AddConstant("XSBR_vbf_140",0.00203036);
l.rooContainer->AddConstant("XSBR_wzh_140",0.001163597);
l.rooContainer->AddConstant("XSBR_tth_140",0.000117189);
l.rooContainer->AddConstant("XSBR_ggh_135",0.0278604);
l.rooContainer->AddConstant("XSBR_vbf_135",0.002343);
l.rooContainer->AddConstant("XSBR_wzh_135",0.001457559);
l.rooContainer->AddConstant("XSBR_tth_135",0.000145053);
l.rooContainer->AddConstant("XSBR_ggh_130",0.0319112);
l.rooContainer->AddConstant("XSBR_vbf_130",0.00260804);
l.rooContainer->AddConstant("XSBR_wzh_130",0.001759636);
l.rooContainer->AddConstant("XSBR_tth_130",0.000173070);
l.rooContainer->AddConstant("XSBR_ggh_125",0.0350599);
l.rooContainer->AddConstant("XSBR_vbf_125",0.00277319);
l.rooContainer->AddConstant("XSBR_wzh_125",0.002035123);
l.rooContainer->AddConstant("XSBR_tth_125",0.000197718);
l.rooContainer->AddConstant("XSBR_TprimeM400_120",0.00524638);// GIUSEPPE
l.rooContainer->AddConstant("XSBR_TprimeM450_120",0.00253536);// GIUSEPPE
l.rooContainer->AddConstant("XSBR_TprimeM500_120",0.00180348);// GIUSEPPE
l.rooContainer->AddConstant("XSBR_TprimeM550_120",0.0006954);// GIUSEPPE
l.rooContainer->AddConstant("XSBR_TprimeM700_120",0.000129732);// GIUSEPPE
l.rooContainer->AddConstant("XSBR_TprimeM800_120",0.000047424);// GIUSEPPE
l.rooContainer->AddConstant("XSBR_TprimeM900_120",0.0000184452);// GIUSEPPE
l.rooContainer->AddConstant("XSBR_ggh_120",0.0374175);
l.rooContainer->AddConstant("XSBR_vbf_120",0.00285525);
l.rooContainer->AddConstant("XSBR_wzh_120",0.002285775);
l.rooContainer->AddConstant("XSBR_tth_120",0.00021951);
l.rooContainer->AddConstant("XSBR_ggh_123",0.0360696);
l.rooContainer->AddConstant("XSBR_vbf_123",0.00281352);
l.rooContainer->AddConstant("XSBR_wzh_123",0.00213681);
l.rooContainer->AddConstant("XSBR_tth_123",0.00020663);
l.rooContainer->AddConstant("XSBR_ggh_121",0.0369736);
l.rooContainer->AddConstant("XSBR_vbf_121",0.00284082);
l.rooContainer->AddConstant("XSBR_wzh_121",0.00223491);
l.rooContainer->AddConstant("XSBR_tth_121",0.00021510);
l.rooContainer->AddConstant("XSBR_ggh_115",0.0386169);
l.rooContainer->AddConstant("XSBR_vbf_115",0.00283716);
l.rooContainer->AddConstant("XSBR_wzh_115",0.002482089);
l.rooContainer->AddConstant("XSBR_tth_115",0.000235578);
l.rooContainer->AddConstant("XSBR_ggh_110",0.0390848);
l.rooContainer->AddConstant("XSBR_vbf_110",0.00275406);
l.rooContainer->AddConstant("XSBR_wzh_110",0.002654575);
l.rooContainer->AddConstant("XSBR_tth_110",0.000247629);
l.rooContainer->AddConstant("XSBR_ggh_105",0.0387684);
l.rooContainer->AddConstant("XSBR_vbf_105",0.00262016);
l.rooContainer->AddConstant("XSBR_wzh_105",0.002781962);
l.rooContainer->AddConstant("XSBR_tth_105",0.000255074);
// FF model
l.rooContainer->AddConstant("ff_XSBR_vbf_150",0.00259659);
l.rooContainer->AddConstant("ff_XSBR_wzh_150",0.00127278);
l.rooContainer->AddConstant("ff_XSBR_vbf_145",0.00387544);
l.rooContainer->AddConstant("ff_XSBR_wzh_145",0.00205969);
l.rooContainer->AddConstant("ff_XSBR_vbf_140",0.00565976);
l.rooContainer->AddConstant("ff_XSBR_wzh_140",0.003243602);
l.rooContainer->AddConstant("ff_XSBR_vbf_135",0.00825);
l.rooContainer->AddConstant("ff_XSBR_wzh_135",0.00513225);
l.rooContainer->AddConstant("ff_XSBR_vbf_130",0.0122324);
l.rooContainer->AddConstant("ff_XSBR_wzh_130",0.00825316);
l.rooContainer->AddConstant("ff_XSBR_vbf_125",0.0186494);
l.rooContainer->AddConstant("ff_XSBR_wzh_125",0.01368598);
l.rooContainer->AddConstant("ff_XSBR_vbf_123",0.022212);
l.rooContainer->AddConstant("ff_XSBR_wzh_123",0.0168696);
l.rooContainer->AddConstant("ff_XSBR_vbf_121",0.0266484);
l.rooContainer->AddConstant("ff_XSBR_wzh_121",0.0209646);
l.rooContainer->AddConstant("ff_XSBR_vbf_120",0.0293139);
l.rooContainer->AddConstant("ff_XSBR_wzh_120",0.02346729);
l.rooContainer->AddConstant("ff_XSBR_vbf_115",0.0482184);
l.rooContainer->AddConstant("ff_XSBR_wzh_115",0.04218386);
l.rooContainer->AddConstant("ff_XSBR_vbf_110",0.083181);
l.rooContainer->AddConstant("ff_XSBR_wzh_110",0.08017625);
l.rooContainer->AddConstant("ff_XSBR_vbf_105",0.151616);
l.rooContainer->AddConstant("ff_XSBR_wzh_105",0.1609787);
// -----------------------------------------------------
// Configurable background model
// if no configuration was given, set some defaults
std::string postfix=(dataIs2011?"":"_8TeV");
if( bkgPolOrderByCat.empty() ) {//MAYBE IS USELESS???GIUSEPPE
for(int i=0; i<nCategories_; i++){
if(i<nInclusiveCategories_) {
bkgPolOrderByCat.push_back(5);
} else if(i<nInclusiveCategories_+nVBFCategories){
bkgPolOrderByCat.push_back(3);
} else if(i<nInclusiveCategories_+nVBFCategories+nVHhadCategories){
bkgPolOrderByCat.push_back(2);
} else if(i<nInclusiveCategories_+nVBFCategories+nVHhadCategories+nVHlepCategories){
bkgPolOrderByCat.push_back(1);
} else if(i<nInclusiveCategories_+nVBFCategories+nVHhadCategories+nVHhadBtagCategories+nVHlepCategories+nTTHhadCategories+nTTHlepCategories){
bkgPolOrderByCat.push_back(3);
} else if(i<nInclusiveCategories_+nVBFCategories+nVHhadCategories+nVHhadBtagCategories+nVHlepCategories+nTTHhadCategories+nTTHlepCategories+ntHqLeptonicCategories){
bkgPolOrderByCat.push_back(3);
}
}
}
// build the model
buildBkgModel(l, postfix);
// -----------------------------------------------------
// Make some data sets from the observables to fill in the event loop
// Binning is for histograms (will also produce unbinned data sets)
l.rooContainer->CreateDataSet("CMS_hgg_mass","data_mass" ,nDataBins); // (100,110,150) -> for a window, else full obs range is taken
l.rooContainer->CreateDataSet("CMS_hgg_mass","bkg_mass" ,nDataBins);
// Create Signal DataSets:
for(size_t isig=0; isig<sigPointsToBook.size(); ++isig) {
int sig = sigPointsToBook[isig];
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_ggh_mass_m%d",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_vbf_mass_m%d",sig),nDataBins);
if(!splitwzh) l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_wzh_mass_m%d",sig),nDataBins);
else{
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_wh_mass_m%d",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_zh_mass_m%d",sig),nDataBins);
}
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_tth_mass_m%d",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM400_mass_m%d",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM450_mass_m%d",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM500_mass_m%d",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM550_mass_m%d",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM700_mass_m%d",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM800_mass_m%d",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM900_mass_m%d",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_ggh_mass_m%d_rv",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_vbf_mass_m%d_rv",sig),nDataBins);
if(!splitwzh) l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_wzh_mass_m%d_rv",sig),nDataBins);
else{
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_wh_mass_m%d_rv",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_zh_mass_m%d_rv",sig),nDataBins);
}
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_tth_mass_m%d_rv",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM400_mass_m%d_rv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM450_mass_m%d_rv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM500_mass_m%d_rv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM550_mass_m%d_rv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM700_mass_m%d_rv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM800_mass_m%d_rv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM900_mass_m%d_rv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_ggh_mass_m%d_wv",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_vbf_mass_m%d_wv",sig),nDataBins);
if(!splitwzh) l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_wzh_mass_m%d_wv",sig),nDataBins);
else{
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_wh_mass_m%d_wv",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_zh_mass_m%d_wv",sig),nDataBins);
}
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_tth_mass_m%d_wv",sig),nDataBins);
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM400_mass_m%d_wv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM450_mass_m%d_wv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM500_mass_m%d_wv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM550_mass_m%d_wv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM700_mass_m%d_wv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM800_mass_m%d_wv",sig),nDataBins);//GIUSEPPE
l.rooContainer->CreateDataSet("CMS_hgg_mass",Form("sig_TprimeM900_mass_m%d_wv",sig),nDataBins);//GIUSEPPE
}
// Make more datasets representing Systematic Shifts of various quantities
for(size_t isig=0; isig<sigPointsToBook.size(); ++isig) {
int sig = sigPointsToBook[isig];
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_ggh_mass_m%d",sig),-1);
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_vbf_mass_m%d",sig),-1);
if(!splitwzh) l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_wzh_mass_m%d",sig),-1);
else{
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_wh_mass_m%d",sig),-1);
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_zh_mass_m%d",sig),-1);
}
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_tth_mass_m%d",sig),-1);
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_TprimeM400_mass_m%d",sig),-1);//GIUSEPPE
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_TprimeM450_mass_m%d",sig),-1);//GIUSEPPE
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_TprimeM500_mass_m%d",sig),-1);//GIUSEPPE
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_TprimeM550_mass_m%d",sig),-1);//GIUSEPPE
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_TprimeM700_mass_m%d",sig),-1);//GIUSEPPE
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_TprimeM800_mass_m%d",sig),-1);//GIUSEPPE
l.rooContainer->MakeSystematics("CMS_hgg_mass",Form("sig_TprimeM900_mass_m%d",sig),-1);//GIUSEPPE
}
// Make sure the Map is filled
FillSignalLabelMap(l);
if(PADEBUG)
cout << "InitRealStatAnalysis END"<<endl;
// FIXME book of additional variables
}
// ----------------------------------------------------------------------------------------------------
void StatAnalysis::buildBkgModel(LoopAll& l, const std::string & postfix)
{
// sanity check
if( bkgPolOrderByCat.size() != nCategories_ ) {
std::cout << "Number of categories not consistent with specified background model " << nCategories_ << " " << bkgPolOrderByCat.size() << std::endl;
assert( 0 );
}
l.rooContainer->AddRealVar("CMS_hgg_pol6_0"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol6_1"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol6_2"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol6_3"+postfix,-0.01,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol6_4"+postfix,-0.01,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol6_5"+postfix,-0.01,-1.0,1.0);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol6_0"+postfix,"@0*@0","CMS_hgg_pol6_0"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol6_1"+postfix,"@0*@0","CMS_hgg_pol6_1"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol6_2"+postfix,"@0*@0","CMS_hgg_pol6_2"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol6_3"+postfix,"@0*@0","CMS_hgg_pol6_3"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol6_4"+postfix,"@0*@0","CMS_hgg_pol6_4"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol6_5"+postfix,"@0*@0","CMS_hgg_pol6_4"+postfix);
l.rooContainer->AddRealVar("CMS_hgg_pol5_0"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol5_1"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol5_2"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol5_3"+postfix,-0.01,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_pol5_4"+postfix,-0.01,-1.0,1.0);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol5_0"+postfix,"@0*@0","CMS_hgg_pol5_0"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol5_1"+postfix,"@0*@0","CMS_hgg_pol5_1"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol5_2"+postfix,"@0*@0","CMS_hgg_pol5_2"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol5_3"+postfix,"@0*@0","CMS_hgg_pol5_3"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modpol5_4"+postfix,"@0*@0","CMS_hgg_pol5_4"+postfix);
l.rooContainer->AddRealVar("CMS_hgg_quartic0"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_quartic1"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_quartic2"+postfix,-0.1,-1.0,1.0);
l.rooContainer->AddRealVar("CMS_hgg_quartic3"+postfix,-0.01,-1.0,1.0);
l.rooContainer->AddFormulaVar("CMS_hgg_modquartic0"+postfix,"@0*@0","CMS_hgg_quartic0"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modquartic1"+postfix,"@0*@0","CMS_hgg_quartic1"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modquartic2"+postfix,"@0*@0","CMS_hgg_quartic2"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modquartic3"+postfix,"@0*@0","CMS_hgg_quartic3"+postfix);
l.rooContainer->AddRealVar("CMS_hgg_quad0"+postfix,-0.1,-1.5,1.5);
l.rooContainer->AddRealVar("CMS_hgg_quad1"+postfix,-0.01,-1.5,1.5);
l.rooContainer->AddFormulaVar("CMS_hgg_modquad0"+postfix,"@0*@0","CMS_hgg_quad0"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modquad1"+postfix,"@0*@0","CMS_hgg_quad1"+postfix);
l.rooContainer->AddRealVar("CMS_hgg_cubic0"+postfix,-0.1,-1.5,1.5);
l.rooContainer->AddRealVar("CMS_hgg_cubic1"+postfix,-0.1,-1.5,1.5);
l.rooContainer->AddRealVar("CMS_hgg_cubic2"+postfix,-0.01,-1.5,1.5);
l.rooContainer->AddFormulaVar("CMS_hgg_modcubic0"+postfix,"@0*@0","CMS_hgg_cubic0"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modcubic1"+postfix,"@0*@0","CMS_hgg_cubic1"+postfix);
l.rooContainer->AddFormulaVar("CMS_hgg_modcubic2"+postfix,"@0*@0","CMS_hgg_cubic2"+postfix);
l.rooContainer->AddRealVar("CMS_hgg_lin0"+postfix,-0.01,-1.5,1.5);
l.rooContainer->AddFormulaVar("CMS_hgg_modlin0"+postfix,"@0*@0","CMS_hgg_lin0"+postfix);
l.rooContainer->AddRealVar("CMS_hgg_plaw0"+postfix,0.01,-10,10);
l.rooContainer->AddRealVar("CMS_hgg_exp0"+postfix,-1,-10,0);//exp model
// prefix for models parameters
std::map<int,std::string> parnames;
parnames[1] = "modlin";
parnames[2] = "modquad";
parnames[3] = "modcubic";
parnames[4] = "modquartic";
parnames[5] = "modpol5_";
parnames[6] = "modpol6_";
parnames[-1] = "plaw";
parnames[-10] = "exp";//exp model
// map order to categories flags + parameters names
std::map<int, std::pair<std::vector<int>, std::vector<std::string> > > catmodels;
// fill the map
for(int icat=0; icat<nCategories_; ++icat) {
// get the poly order for this category
int catmodel = bkgPolOrderByCat[icat];
std::vector<int> & catflags = catmodels[catmodel].first;
std::vector<std::string> & catpars = catmodels[catmodel].second;
// if this is the first time we find this order, build the parameters
if( catflags.empty() ) {
assert( catpars.empty() );
// by default no category has the new model
catflags.resize(nCategories_, 0);
std::string & parname = parnames[catmodel];
if( catmodel > 0 ) {
for(int iorder = 0; iorder<catmodel; ++iorder) {
catpars.push_back( Form( "CMS_hgg_%s%d%s", parname.c_str(), iorder, +postfix.c_str() ) );
}
} else {
cout<<"catmodel:"<<catmodel<<endl;
if( catmodel != -1 && catmodel != -10 ) {
std::cout << "The only supported negative bkg poly orders are -1 and -10, ie 1-parmeter power law -10 exponential" << std::endl;
assert( 0 );
}
if(catmodel == -1 ){
catpars.push_back( Form( "CMS_hgg_%s%d%s", parname.c_str(), 0, +postfix.c_str() ) );
}else if(catmodel == -10 ){
catpars.push_back( Form( "CMS_hgg_%s%d%s", parname.c_str(), 0, +postfix.c_str() ) );
}
}
} else if ( catmodel != -1 && catmodel != -10) {
assert( catflags.size() == nCategories_ && catpars.size() == catmodel );
}
// chose category order
catflags[icat] = 1;
}
// now loop over the models and allocate the pdfs
/// for(size_t imodel=0; imodel<catmodels.size(); ++imodel ) {
for(std::map<int, std::pair<std::vector<int>, std::vector<std::string> > >::iterator modit = catmodels.begin();
modit!=catmodels.end(); ++modit ) {
std::vector<int> & catflags = modit->second.first;
std::vector<std::string> & catpars = modit->second.second;
if( modit->first > 0 ) {
l.rooContainer->AddSpecificCategoryPdf(&catflags[0],"data_pol_model"+postfix,
"0","CMS_hgg_mass",catpars,70+catpars.size());
// >= 71 means RooBernstein of order >= 1
} else if (modit->first == -1){
l.rooContainer->AddSpecificCategoryPdf(&catflags[0],"data_pol_model"+postfix,
"0","CMS_hgg_mass",catpars,6);
// 6 is power law
}else{
l.rooContainer->AddSpecificCategoryPdf(&catflags[0],"data_pol_model"+postfix,
"0","CMS_hgg_mass",catpars,1);
// 1 is exp
}
}
}
// ----------------------------------------------------------------------------------------------------
bool StatAnalysis::Analysis(LoopAll& l, Int_t jentry)//MARKER
{
if(jentry==32534){ cout<<"Analysis di StatAnalysis.cc"<<endl;}
if(PADEBUG)
cout << "Analysis START; cur_type is: " << l.itype[l.current] <<endl;
int cur_type = l.itype[l.current];
float weight = l.sampleContainer[l.current_sample_index].weight;
float sampleweight = l.sampleContainer[l.current_sample_index].weight;
if(jentry==32534){ cout<<"dopo l.current"<<endl;}
// Set reRunCiC Only if this is an MC event since scaling of R9 and Energy isn't done at reduction
if (cur_type==0) {
l.runCiC=reRunCiCForData;
} else {
l.runCiC = true;
}
if (l.runZeeValidation) l.runCiC=true;
// make sure that rho is properly set
if( dataIs2011 ) {
l.version = 12;
}
if( l.version >= 13 && forcedRho < 0. ) {
l.rho = l.rho_algo1;
}
l.FillCounter( "Processed", 1. );
if( weight <= 0. ) {
std::cout << "Zero or negative weight " << cur_type << " " << weight << std::endl;
assert( 0 );
}
l.FillCounter( "XSWeighted", weight );
nevents+=1.;
if(jentry==32534){cout<<"prima di PU"<<endl;}
//PU reweighting
double pileupWeight=getPuWeight( l.pu_n, cur_type, &(l.sampleContainer[l.current_sample_index]), jentry == 1);
sumwei +=pileupWeight;
weight *= pileupWeight;
sumev += weight;
assert( weight >= 0. );
l.FillCounter( "PUWeighted", weight );
if( jentry % 1000 == 0 ) {
std::cout << " nevents " << nevents << " sumpuweights " << sumwei << " ratio " << sumwei / nevents
<< " equiv events " << sumev << " accepted " << sumaccept << " smeared " << sumsmear << " "
<< sumaccept / sumev << " " << sumsmear / sumaccept
<< std::endl;
}
// ------------------------------------------------------------
//PT-H K-factors
double gPT = 0;
TLorentzVector gP4(0,0,0,0);
if (!l.runZeeValidation && cur_type<0){
gP4 = l.GetHiggs();
gPT = gP4.Pt();
//assert( gP4.M() > 0. );
}
if(jentry==32534){cout<<"prima di cluster shape variables"<<endl;}
//Calculate cluster shape variables prior to shape rescaling
for (int ipho=0;ipho<l.pho_n;ipho++){
//// l.pho_s4ratio[ipho] = l.pho_e2x2[ipho]/l.pho_e5x5[ipho];
l.pho_s4ratio[ipho] = l.pho_e2x2[ipho]/l.bc_s25[l.sc_bcseedind[l.pho_scind[ipho]]];
float rr2=l.pho_eseffsixix[ipho]*l.pho_eseffsixix[ipho]+l.pho_eseffsiyiy[ipho]*l.pho_eseffsiyiy[ipho];
l.pho_ESEffSigmaRR[ipho] = 0.0;
if(rr2>0. && rr2<999999.) {
l.pho_ESEffSigmaRR[ipho] = sqrt(rr2);
}
}
if(jentry==32534){cout<<"prima di MC corrections"<<endl;}
// Data driven MC corrections to cluster shape variables and energy resolution estimate
if (cur_type !=0 && scaleClusterShapes ){
rescaleClusterVariables(l);
}
if( useDefaultVertex ) {
for(int id=0; id<l.dipho_n; ++id ) {
l.dipho_vtxind[id] = 0;
}
} else if( reRunVtx ) {
reVertex(l);
}
if(jentry==32534){cout<<"prima di re-apply jec"<<endl;}
// Re-apply JEC and / or recompute JetID
if(includeVBF || includeVHhad || includeVHhadBtag || includeTTHhad || includeTTHlep || includetHqLeptonic ||includeTprimehad || includeTprimelep || includeLoose) { postProcessJets(l); }
if(jentry==32534){cout<<"prima di Analyse the event"<<endl;}
// Analyse the event assuming nominal values of corrections and smearings
float mass, evweight, diphotonMVA;
int diphoton_id, category;
bool isCorrectVertex;
bool storeEvent = false;
if(jentry==32534||jentry==32533){cout<<"category"<<category<<endl;AnalyseEvent(l,jentry, weight, gP4, mass, evweight, category, diphoton_id, isCorrectVertex,diphotonMVA); cout<<"dopo la valutazione AnalyseEvent"<<endl;}
if( AnalyseEvent(l,jentry, weight, gP4, mass, evweight, category, diphoton_id, isCorrectVertex,diphotonMVA) ) {
// feed the event to the RooContainer
if(jentry==32534){cout<<"dentro if ANAlyseEvent"<<endl;}
FillRooContainer(l, cur_type, mass, diphotonMVA, category, evweight, isCorrectVertex, diphoton_id);
storeEvent = true;
}
if(jentry==32534){cout<<"prima di syste uncert"<<endl;}
// Systematics uncertaities for the binned model
// We re-analyse the event several times for different values of corrections and smearings
if( cur_type < 0 && doMCSmearing && doSystematics ) {
// fill steps for syst uncertainty study
float systStep = systRange / (float)nSystSteps;
float syst_mass, syst_weight, syst_diphotonMVA;
int syst_category;
std::vector<double> mass_errors;
std::vector<double> mva_errors;
std::vector<double> weights;
std::vector<int> categories;
if(jentry==32534){cout<<"prima di diphoton"<<endl;}
if (diphoton_id > -1 ) {
// gen-level systematics, i.e. ggH k-factor for the moment
for(std::vector<BaseGenLevelSmearer*>::iterator si=systGenLevelSmearers_.begin(); si!=systGenLevelSmearers_.end(); si++){
mass_errors.clear(), weights.clear(), categories.clear(), mva_errors.clear();
for(float syst_shift=-systRange; syst_shift<=systRange; syst_shift+=systStep ) {
if( syst_shift == 0. ) { continue; } // skip the central value
syst_mass = 0., syst_category = -1, syst_weight = 0.;
// re-analyse the event without redoing the event selection as we use nominal values for the single photon
// corrections and smearings
AnalyseEvent(l, jentry, weight, gP4, syst_mass, syst_weight, syst_category, diphoton_id, isCorrectVertex,syst_diphotonMVA,
true, syst_shift, true, *si, 0, 0 );
AccumulateSyst( cur_type, syst_mass, syst_diphotonMVA, syst_category, syst_weight,
mass_errors, mva_errors, categories, weights);
}
FillRooContainerSyst(l, (*si)->name(), cur_type, mass_errors, mva_errors, categories, weights,diphoton_id);
}
if(jentry==32534){cout<<"prima di vertex efficiency"<<endl;}
// di-photon systematics: vertex efficiency and trigger
for(std::vector<BaseDiPhotonSmearer *>::iterator si=systDiPhotonSmearers_.begin(); si!= systDiPhotonSmearers_.end(); ++si ) {
mass_errors.clear(), weights.clear(), categories.clear(), mva_errors.clear();
for(float syst_shift=-systRange; syst_shift<=systRange; syst_shift+=systStep ) {
if( syst_shift == 0. ) { continue; } // skip the central value
syst_mass = 0., syst_category = -1, syst_weight = 0.;
// re-analyse the event without redoing the event selection as we use nominal values for the single photon
// corrections and smearings
AnalyseEvent(l,jentry, weight, gP4, syst_mass, syst_weight, syst_category, diphoton_id, isCorrectVertex,syst_diphotonMVA,
true, syst_shift, true, 0, 0, *si );
AccumulateSyst( cur_type, syst_mass, syst_diphotonMVA, syst_category, syst_weight,
mass_errors, mva_errors, categories, weights);
}
FillRooContainerSyst(l, (*si)->name(), cur_type, mass_errors, mva_errors, categories, weights, diphoton_id);
}
}
int diphoton_id_syst;
if(jentry==32534){cout<<"prima di single photon level syst"<<endl;}
// single photon level systematics: several
for(std::vector<BaseSmearer *>::iterator si=systPhotonSmearers_.begin(); si!= systPhotonSmearers_.end(); ++si ) {
mass_errors.clear(), weights.clear(), categories.clear(), mva_errors.clear();
for(float syst_shift=-systRange; syst_shift<=systRange; syst_shift+=systStep ) {
if( syst_shift == 0. ) { continue; } // skip the central value
syst_mass = 0., syst_category = -1, syst_weight = 0.;
// re-analyse the event redoing the event selection this time
AnalyseEvent(l,jentry, weight, gP4, syst_mass, syst_weight, syst_category, diphoton_id_syst, isCorrectVertex,syst_diphotonMVA,
true, syst_shift, false, 0, *si, 0 );
AccumulateSyst( cur_type, syst_mass, syst_diphotonMVA, syst_category, syst_weight,
mass_errors, mva_errors, categories, weights);
}
FillRooContainerSyst(l, (*si)->name(), cur_type, mass_errors, mva_errors, categories, weights, diphoton_id);
}
}
if(PADEBUG)
cout<<"myFillHistRed END"<<endl;
if(jentry==32534){cout<<"prima di return"<<endl;}
return storeEvent;
}
// ----------------------------------------------------------------------------------------------------
bool StatAnalysis::AnalyseEvent(LoopAll& l, Int_t jentry, float weight, TLorentzVector & gP4,
float & mass, float & evweight, int & category, int & diphoton_id, bool & isCorrectVertex,
float &kinematic_bdtout,
bool isSyst,
float syst_shift, bool skipSelection,
BaseGenLevelSmearer *genSys, BaseSmearer *phoSys, BaseDiPhotonSmearer * diPhoSys)
{//MARK 2
assert( isSyst || ! skipSelection );
l.createCS_=createCS;
int cur_type = l.itype[l.current];
float sampleweight = l.sampleContainer[l.current_sample_index].weight;
/// diphoton_id = -1;
std::pair<int,int> diphoton_index;
vbfIjet1=-1, vbfIjet2=-1;
// do gen-level dependent first (e.g. k-factor); only for signal
genLevWeight=1.;
if(cur_type!=0 ) {
applyGenLevelSmearings(genLevWeight,gP4,l.pu_n,cur_type,genSys,syst_shift);
}
cout<<"dentro AnalyseEvents di StatAnalysis.cc"<<endl;
// event selection
int muVtx=-1;
int mu_ind=-1;
int elVtx=-1;
int el_ind=-1;
int leadpho_ind=-1;
int subleadpho_ind=-1;
//-------------------------------- ANIELLO --------------------------------//
bool VHmuevent_prov=false;
bool VHelevent_prov=false;
//-------------------------------------------------------------------------//
cout<<"prima di !skipSelection"<<endl;
if( ! skipSelection ) {
cout<<"dentro !skipSelection"<<endl;
// first apply corrections and smearing on the single photons
smeared_pho_energy.clear(); smeared_pho_energy.resize(l.pho_n,0.);
smeared_pho_r9.clear(); smeared_pho_r9.resize(l.pho_n,0.);
smeared_pho_weight.clear(); smeared_pho_weight.resize(l.pho_n,1.);
cout<<"prima di applySinglePhoton"<<endl;
applySinglePhotonSmearings(smeared_pho_energy, smeared_pho_r9, smeared_pho_weight, cur_type, l, energyCorrected, energyCorrectedError,
phoSys, syst_shift);//CHE FA? Se non serve lo butto!
cout<<"dopo applySinglePhoton"<<endl;
// Fill CiC efficiency plots for ggH, mH=124
//fillSignalEfficiencyPlots(weight, l);
// inclusive category di-photon selection
// FIXME pass smeared R9
std::vector<bool> veto_indices;
cout<<"prima di DiphotonCiCSlection"<<endl;//gia non arriva proprio qui
veto_indices.clear();
diphoton_id = l.DiphotonCiCSelection(l.phoSUPERTIGHT, l.phoSUPERTIGHT, leadEtCut, subleadEtCut, 4,applyPtoverM, &smeared_pho_energy[0], false, -1, veto_indices, cicCutLevels );
cout<<"dopo diphoton_id dentro !skipSelection"<<endl;
//// diphoton_id = l.DiphotonCiCSelection(l.phoNOCUTS, l.phoNOCUTS, leadEtCut, subleadEtCut, 4,applyPtoverM, &smeared_pho_energy[0] );
cout<<"prima di ! isSyst"<<endl;
// N-1 plots
if( ! isSyst ) {
cout<<"dentro N-1 plots"<<endl;
int diphoton_nm1_id = l.DiphotonCiCSelection(l.phoSUPERTIGHT, l.phoNOCUTS, leadEtCut, subleadEtCut, 4,applyPtoverM, &smeared_pho_energy[0] );
if(diphoton_nm1_id>-1) {
float eventweight = weight * smeared_pho_weight[diphoton_index.first] * smeared_pho_weight[diphoton_index.second] * genLevWeight;
float myweight=1.;
if(eventweight*sampleweight!=0) myweight=eventweight/sampleweight;
ClassicCatsNm1Plots(l, diphoton_nm1_id, &smeared_pho_energy[0], eventweight, myweight);
}
}
cout<<"prima di Excluse Modes"<<endl;
// Exclusive Modes
int diphotonVBF_id = -1;
int diphotonVHhad_id = -1;
int diphotonVHhadBtag_id = -1;
int diphotonTTHhad_id = -1;
int diphotonTTHlep_id = -1;
int diphotonTprimehad_id = -1;//GIUSEPPE
int diphotonTprimelep_id = -1;//GIUSEPPE
int diphotonLoose_id = -1;//GIUSEPPE
int diphotonVHlep_id = -1;
int diphotonVHmet_id = -1; //met at analysis step
int diphotontHqLeptonic_id = -1;
VHmuevent = false;
VHelevent = false;
VHlep1event = false; //ANIELLO
VHlep2event = false; //ANIELLO
VHmuevent_cat = 0;
VHelevent_cat = 0;
VBFevent = false;
VHhadevent = false;
VHhadBtagevent = false;
TTHhadevent = false;
TTHlepevent = false;
Tprimehadevent = false;//GIUSEPPE
Tprimelepevent = false;//GIUSEPPE
Looseevent = false;//GIUSEPPE
VHmetevent = false; //met at analysis step
tHqLeptonicevent = false;
// lepton tag
if(includeVHlep){
//Add tighter cut on dr to tk
if(dataIs2011){
diphotonVHlep_id = l.DiphotonCiCSelection(l.phoSUPERTIGHT, l.phoSUPERTIGHT, leadEtVHlepCut, subleadEtVHlepCut, 4, false, &smeared_pho_energy[0], true, true );
if(l.pho_drtotk_25_99[l.dipho_leadind[diphotonVHlep_id]] < 1 || l.pho_drtotk_25_99[l.dipho_subleadind[diphotonVHlep_id]] < 1) diphotonVHlep_id = -1;
VHmuevent=MuonTag2011(l, diphotonVHlep_id, &smeared_pho_energy[0]);
VHelevent=ElectronTag2011(l, diphotonVHlep_id, &smeared_pho_energy[0]);
} else {
//VHmuevent=MuonTag2012(l, diphotonVHlep_id, &smeared_pho_energy[0],lep_sync);
//VHelevent=ElectronTag2012(l, diphotonVHlep_id, &smeared_pho_energy[0],lep_sync);
float eventweight = weight * genLevWeight;
VHmuevent=MuonTag2012B(l, diphotonVHlep_id, mu_ind, muVtx, VHmuevent_cat, &smeared_pho_energy[0], lep_sync, false, -0.2, eventweight, smeared_pho_weight, !isSyst);
if(!VHmuevent){
VHelevent=ElectronTag2012B(l, diphotonVHlep_id, el_ind, elVtx, VHelevent_cat, &smeared_pho_energy[0], lep_sync, false, -0.2, eventweight, smeared_pho_weight, !isSyst);