forked from rsyarif/PostLJMetAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.C
1640 lines (1379 loc) · 79.2 KB
/
post.C
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
#define post_C
#include <TStyle.h>
#include <TCanvas.h>
#include <TH1F.h>
#include <TH2.h>
#include <TH3.h>
#include "TAxis.h"
#include "TF1.h"
#include "TLine.h"
#include "TColor.h"
#include "TMath.h"
#include "TFile.h"
#include "TTree.h"
#include "TLegend.h"
#include "TPaveText.h"
#include "TLatex.h"
//#include "TGraphAsymmErrors.h"
#include <iostream>
#include <fstream>
#include "interface/DMCclass_list.h"
#include "interface/DMCblock.h"
#include "interface/stringmap.h"
#include "interface/controlpannel.h"
#include "interface/utilities.h"
#include "interface/CMSStyle.C"
#include "interface/KinematicVar.h"
#include <assert.h>
using namespace std;
using namespace controlpannel;
//void SaveCanvas(TCanvas * c, string fileNameAndDir, string FileTypes = "crootpdfjpggif");
typedef stringmap<TH1F*> histmap;
typedef stringmap<histmap*> histtable;
typedef stringmap<TH2F*> histmap2D;
typedef stringmap<histmap2D*> histtable2D;
struct thetaSigFile{
thetaSigFile(string _filename, double _bWbr, double _tHbr):filename(_filename),bWbr(_bWbr),tHbr(_tHbr){}
string filename;
double bWbr;
double tHbr;
};
TH1F* extrackBkg(TH2F* bkg_hist);
TH1F* make_ratio_uncertainty_hist(TH1F* data, TH1F* bkg);
void fix_negatives(TH1F* hist);
void fix_negativesX(TH2F* hist);
void check_for_negatives(TH1F* hist);
string MakeThetaRootFile_Yield(histtable htable, histmap2D* histmapbkg, string dir,
std::vector<string> SigtoInclude, int SignalInflationFactor,
string dataClassName,
std::vector<DMCclass*> vBkgClasses,
std::vector<DMCclass*> vBkgClassesUP,
std::vector<DMCclass*> vBkgClassesDOWN,
bool draw_ddbkg);
string MakeThetaRootFile_Yield_nonsignal(histtable htable, histmap2D* histmapbkg, string dir,
string dataClassName, std::vector<DMCclass*> vBkgClasses, std::vector<DMCclass*> vBkgClassesUP, std::vector<DMCclass*> vBkgClassesDOWN, bool draw_ddbkg );
std::vector<thetaSigFile*> MakeThetaRootFile_Yield_signalScan(stringmap<std::vector<TH1F*>> Signal_yields, std::vector<DMCclass*> vSigClassesAll,string dir, int nBRslices);
TH1F* brRescale( std::vector<TH1F*> hists, float bWbr, float tHbr, string outname);
string MakeThetaCounts(histtable htable, histmap2D* histmapbkg, string SigClassToUse, std::vector<DMCclass*> vBkgClasses,bool draw_ddbkg);
string ThetaFileNameSig(string directory, string classname, double bWbr, double tHbr);
float get_bZbr(float bWbr, float tHbr);
void post(){
CMSStyle();
//typedef stringmap<TH1F*> histmap;
//typedef stringmap<histmap*> histtable;
//typedef stringmap<TH2F*> histmap2D;
//typedef stringmap<histmap2D*> histtable2D;
std::vector<string> SigtoInclude;
std::vector<string> plotnames;
std::vector<string> bkgplotnames;
LabelKinVars allkinvar_stringmap = setupAllKinematicVar(); //the entire universe of kinvars
stringmap<KinematicVar*> chosenkinvar_stringmap; // map from plotname to the corresponding kinvar.
///////////////////////////// Switcehs //////////////////////////////////////
//Most switches are on the control pannel.
bool saveImages = true;
bool draw_ddbkg = false;
//
bool makeStackPlots_lin = false;
bool makeStackPlots_lin_ratio = false;
bool makeStackPlots_log = false;
bool makeStackPlots_log_ratio = false;
bool makeStackPlots_log_SBsignif = true ; //added by rizki
bool produceThetaOut = true;
///////////////////////////// Lists //////////////////////////////////////
namedstring plotdirs;
plotdirs.set("c", plotsdirC);
plotdirs.set("root", plotsdirroot);
plotdirs.set("jpg", plotsdirjpg );
plotdirs.set("pdf", plotsdirpdf );
plotdirs.set("png", plotsdirpng );
plotdirs.set("gif", plotsdirgif );
plotdirs.set("eps", plotsdireps );
SigtoInclude.push_back(string("TpTp700")+(T50ns_F25ns?"s":"f"));
// SigtoInclude.push_back(string("TpTp800")+(T50ns_F25ns?"s":"f"));
SigtoInclude.push_back(string("TpTp1200")+(T50ns_F25ns?"s":"f"));
string dataClassName = string("Data2lep")+(T50ns_F25ns?"s":"f");
//MAKE A LIST OF ALL THE PLOT NAMES TO LOAD IN: "plotnames", AND BKG PLOT NAMES "bkgplotnames"
//Map the plotname or bkgplotname to the kinvar in chosenkinvar_stringmap.set
try{
//Special plots to load in
// plotnames.push_back("h_ST_OSDL1sansS"); chosenkinvar_stringmap.set(plotnames.back(),allkinvar_stringmap->get_throwable("ST",1));
// plotnames.push_back("h_ST_OSDL1sansSlb"); chosenkinvar_stringmap.set(plotnames.back(),allkinvar_stringmap->get_throwable("ST",1));
plotnames.push_back("h_yield"); chosenkinvar_stringmap.set(plotnames.back(),allkinvar_stringmap->get_throwable("yield",1));
//Special background plots to load in
// bkgplotnames.push_back("b_ST_OSDL1sansS"); chosenkinvar_stringmap.set(bkgplotnames.back(),allkinvar_stringmap->get_throwable("ST",1));
// bkgplotnames.push_back("b_ST_OSDL1sansSlb"); chosenkinvar_stringmap.set(bkgplotnames.back(),allkinvar_stringmap->get_throwable("ST",1));
bkgplotnames.push_back("b_yield"); chosenkinvar_stringmap.set(bkgplotnames.back(),allkinvar_stringmap->get_throwable("yield",1));
for (int iTopo = 0; iTopo<nEventTopologies; iTopo++) {
for (int kKinVar = 0; kKinVar < nKinemVars_all; kKinVar++) {
//make a list of the names of all the grid plots
plotnames.push_back( string("h_")+s_KinemVars_all[kKinVar]+s_EventTopology[iTopo]);
chosenkinvar_stringmap.set(plotnames.back(),allkinvar_stringmap->get_throwable(s_KinemVars_all[kKinVar],2)); //map kinvars to plotname
//make a list of the names of all the background grid plots
bkgplotnames.push_back( string("b_")+s_KinemVars_all[kKinVar]+s_EventTopology[iTopo]);
chosenkinvar_stringmap.set(bkgplotnames.back(),allkinvar_stringmap->get_throwable(s_KinemVars_all[kKinVar],3)); //map kinvars to plotname
}//end for every kinvar
}//end for every topo
}//end list all special plot names
catch(std::pair <std::string,int> errorpair){
switch(errorpair.second ){
case 1: cerr<<"Stringmap Error! While setting up specail plot names. Invalid string key "<<errorpair.first<< " sought in allkinvar_stringmap"<<endl; break;
case 2: cerr<<"Stringmap Error! While setting up general plot names. Invalid string key "<<errorpair.first<< " sought in allkinvar_stringmap"<<endl;
case 3: cerr<<"Stringmap Error! While setting up general plot names. Invalid string key "<<errorpair.first<< " sought in allkinvar_stringmap"<<endl;
}//end switch
std::terminate();
}
//add to the list a list of all the grid plots names to intake, then list all the bkg plots.
//Make a list vClasses of all the classes to run
DMCclass* dataClass = setupDMCclass( dataClassName);
std::vector<DMCclass*> vBkgClasses = MCbkgDMCclass(T50ns_F25ns);//bkgs that will go on the plot.
std::vector<DMCclass*> vBkgClassesDOWN = MCbkgDMCclassDOWN(T50ns_F25ns);
std::vector<DMCclass*> vBkgClassesUP = MCbkgDMCclassUP(T50ns_F25ns);
std::vector<DMCclass*> vSigClassesAll = MCTpTpsigDMCclass(T50ns_F25ns);//all the signal classes, used for limits.
std::vector<DMCclass*> vSigClasses; //The signal classes to go on the plots
std::vector<DMCclass*> vClasses; //mostly a copy of vBkgClasses, but with MC and data appended.
std::vector<DMCclass*> vClassesAll;
//vectorize all the classes
// cout<<"Background Classes:"<<endl;
for(std::vector<DMCclass*>::iterator iclass = vBkgClasses.begin();iclass< vBkgClasses.end();iclass++){
//cout<<(*iclass)->name<<endl;
vClasses.push_back((*iclass));
}
//find the signal classes you want on the plots. add them to vSigClasses and vClasses.
for(std::vector<string>::iterator istr=SigtoInclude.begin();istr<SigtoInclude.end();istr++){ //for all the chosen siganl classes.
for(std::vector<DMCclass*>::iterator iclass = vSigClassesAll.begin();iclass< vSigClassesAll.end();iclass++){ //look @ all sig classes
if((*iclass)->name.compare(*istr) ==0){ //if it's one of the signal classes you wanted.
vSigClasses.push_back(*iclass);//add to the list of desired signal classes
vClasses.push_back(*iclass); //and add it to the list of all classes for the plots .
break;
}
}
}
//for(std::vector<string>::iterator istr =SigtoInclude.begin();istr <SigtoInclude.end();istr++)vSigClasses.push_back(setupDMCclass(*istr));
//for(std::vector<DMCclass*>::iterator iclass = vSigClasses.begin();iclass< vSigClasses.end();iclass++) vClasses.push_back((*iclass));
vClasses.push_back(dataClass);
stringmap<DMCclass*>* mClasses = makemap(vClasses);
////
for(std::vector<DMCclass*>::iterator iclass = vClasses.begin();iclass< vClasses.end();iclass++) vClassesAll.push_back((*iclass));
for(std::vector<DMCclass*>::iterator iclass = vBkgClassesUP.begin();iclass< vBkgClassesUP.end();iclass++) vClassesAll.push_back((*iclass));
for(std::vector<DMCclass*>::iterator iclass = vBkgClassesDOWN.begin();iclass< vBkgClassesDOWN.end();iclass++) vClassesAll.push_back((*iclass));
stringmap<DMCclass*>* mClassesAll = makemap(vClassesAll);
///////////////////////////// File Work ///////////////////////////////////////
////////////////////////// LOAD MAIN HISTOGRAMS ///////////////////////////////
//load in all the histograms from all the files.
cout<<"Start loading plots from files"<<endl;
histtable htable; //[vClass name][plotname]
std::vector<TFile*> vFiles;
int start_of_data_in_vFiles=-1;//will hold the index of vFiles of the first data file.
int start_of_signal_in_vFiles=-1;//will hold the index of vFiles of the first data file.
for(std::vector<DMCclass*>::iterator iclass = vClassesAll.begin();iclass<vClassesAll.end();iclass++){ //for every dmc class.
bool firstround = true; //tells if it's the first block in the iclass.
histmap* temphistmap = new histmap();
//cout<<"loading for "<<(*iclass)->name<<endl;
for(std::vector<DMCblock*>::iterator iblock = (*iclass)->blocks.begin();iblock<(*iclass)->blocks.end();iblock++){ //for every block
if( not fileExists( (*iblock)->string_meta["EventLoopOutRoot"]) ){
cerr<<"Error! Cannot find EventLoop file "<<(*iblock)->string_meta["EventLoopOutRoot"]<< " for DMCblock "<<(*iblock)->name<<endl;
std::terminate();
}
vFiles.push_back(new TFile((*iblock)->string_meta["EventLoopOutRoot"].c_str(), "READ"));
//if((*iclass)->name.compare(dataClassName)==0 and firstround) start_of_data_in_vFiles = vFiles.size()-1;//old note which file the data starts on.
if((*iclass)->int_meta["isData"]==1 and start_of_data_in_vFiles ==-1) start_of_data_in_vFiles = vFiles.size()-1;//note which file the data starts on.
if((*iclass)->int_meta["isSignal"]==1 and start_of_signal_in_vFiles ==-1){
start_of_signal_in_vFiles = vFiles.size()-1;//note which file the signal starts on.
cout<<"setting start_of_signal_in_vFiles to "<<start_of_signal_in_vFiles<<" which is "<<vFiles.back()->GetName()<<" = "<<vFiles[start_of_signal_in_vFiles]->GetName()<<endl;
}
vFiles.back()->cd();
//cout<<"loading for block "<<(*iblock)->name<<endl;
for(std::vector<string>::iterator iplot = plotnames.begin(); iplot<plotnames.end();iplot++){
if(not vFiles.back()->GetListOfKeys()->Contains((*iplot).c_str()) ){
cerr<<"Error! Cannot find plot "<<*iplot<<" in file "<<(*iblock)->string_meta["EventLoopOutRoot"]<< " for DMCblock "<<(*iblock)->name<<endl;
std::terminate();
}
//cout<<"fetching "<<*iplot<<endl;
TH1F* temp = (TH1F*)vFiles.back()->Get((*iplot).c_str());//
TH1F* temp2;
if(firstround) temp2 = (TH1F*)temp->Clone((*iplot + "_" + (*iclass)->name ).c_str());
else temp2 = (TH1F*)temp->Clone((*iplot + "_" + (*iblock)->name ).c_str());
AddOverflow(temp2);
fix_negatives(temp2);
if((*iblock)->isMC) temp2->Scale(Integrated_Luminosity_Data*1000.0*(*iblock)->cs_pb/((*iblock)->NGenPoints));
try{
KinematicVar* thiskinvar = chosenkinvar_stringmap.get_throwable(*iplot,2);
//rebin histogram
/*if( thiskinvar->useCustomReBinning)
temp2 = (TH1F*)temp2->Rebin(thiskinvar->nbins_rebin / thiskinvar->nbins, (string(temp2->GetName())+"_r").c_str(), thiskinvar->CustomReBinning );
else temp2 = (TH1F*)temp2->Rebin(thiskinvar->nbins_rebin, (string(temp2->GetName())+"_r").c_str() );
*/
//see Rebin documentation here: https://root.cern.ch/doc/master/classTH1.html#aff6520fdae026334bf34fa1800946790
//attempt to set labels
if(thiskinvar->tag.compare("HT") == 0) temp2 = (TH1F*)temp2->Rebin(40,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("ST") == 0) temp2 = (TH1F*)temp2->Rebin(2,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MET") == 0) temp2 = (TH1F*)temp2->Rebin(12,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("BTm") == 0) temp2 = (TH1F*)temp2->Rebin(30,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("BTl") == 0) temp2 = (TH1F*)temp2->Rebin(30,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MinMlb") == 0) temp2 = (TH1F*)temp2->Rebin(2,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("Mll") == 0) temp2 = (TH1F*)temp2->Rebin(4,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("Mlll") == 0) temp2 = (TH1F*)temp2->Rebin(8,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("minMll") == 0) temp2 = (TH1F*)temp2->Rebin(10,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("LepT") == 0) temp2 = (TH1F*)temp2->Rebin(16,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MSum") == 0) temp2 = (TH1F*)temp2->Rebin(10,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("LHT") == 0) temp2 = (TH1F*)temp2->Rebin(20,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MSumovST") == 0) temp2 = (TH1F*)temp2->Rebin(4,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MtSum") == 0) temp2 = (TH1F*)temp2->Rebin(25,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("lepPt") == 0) temp2 = (TH1F*)temp2->Rebin(4,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("jetPt") == 0) temp2 = (TH1F*)temp2->Rebin(4,(string(temp2->GetName())+"_r").c_str());
temp2->SetTitle( thiskinvar->titles.c_str() );
temp2->SetXTitle( thiskinvar->xlabels.c_str() );
temp2->SetYTitle( "Events" );
if(firstround) temphistmap->set(*iplot,temp2);
else temphistmap->get_throwable(*iplot,3)->Add(temp2);
//cout<<"Class "<<(*iclass)->name<<" block "<<(*iblock)->name<<" plot "<<*iplot<<". Adding "<<temp2->Integral()<<" Sum: "<<
// temphistmap->get_throwable(*iplot)->Integral()<<endl;
}
catch(std::pair <std::string,int> errorpair){
cerr<<"Stringmap Error! Invalid string key "<<errorpair.first<< " sought in temphistmap. Error code "<<errorpair.second<<endl;
std::terminate();
}
// cout<<"end "<<*iplot<<endl<<flush;
} //for ever plot in the file
firstround = false;
cout<<"end block "<<(*iblock)->name<<endl<<flush;
}//for every block in the class
htable.set((*iclass)->name,temphistmap);
}//end for every DMCclass
/*cout<<"Test bkgplotname behavior on repeated calling"<<endl;
for(std::vector<string>::iterator iplot = bkgplotnames.begin(); iplot<bkgplotnames.end();iplot++){ cout<<*iplot<<endl; }
cout<<"2"<<endl<<flush;
for(std::vector<string>::iterator iplot = bkgplotnames.begin(); iplot<bkgplotnames.end();iplot++){ cout<<*iplot<<endl; }
cout<<"3"<<endl<<flush;
for(std::vector<string>::iterator iplot = bkgplotnames.begin(); iplot<bkgplotnames.end();iplot++){ cout<<*iplot<<endl; }
cout<<"Should be stable by now. if this isn't changig, then something is changing iplot as it gots."<<endl<<flush;*/
//you know this produces nothing.
////////////////////////// Load signal yields /////////////////////////////////////
//construct a map of Signal_yields[iClass name in vSigClassesAll][iyield]
/*
string h_yield_strings[nBByields] = {"h_yield_WW", "h_yield_WH", "h_yield_WZ", "h_yield_HH", "h_yield_HZ", "h_yield_ZZ"};
//0:WW, 1:WH, 2: WZ, 3: HH, 4: HZ, 5: ZZ
stringmap<std::vector<TH1F*>> Signal_yields;//only the ones that are meant to be included.
stringmap<std::vector<TH1F*>> Signal_yields_all;//for all the signal.
cout<<"Beginning to Fetch Yields"<<endl;
for(std::vector<DMCclass*>::iterator iclass = vSigClassesAll.begin();iclass<vSigClassesAll.end();iclass++){ //for every dmc class.
bool firstblock = true;
std::vector<TH1F*> hists;
for(std::vector<DMCblock*>::iterator iblock = (*iclass)->blocks.begin();iblock<(*iclass)->blocks.end();iblock++){ //for every block
int thisfile = start_of_signal_in_vFiles++; //appears to not be getting pointed to the right file.
vFiles[thisfile]->cd();
for(int iyield = 0;iyield<nBByields;iyield++){
if( string(vFiles[thisfile]->GetName()).compare((*iblock)->string_meta["EventLoopOutRoot"]) != 0){
cerr<<"Yield File Getter has file mismatch: start_of_signal_in_vFiles indicates "<<vFiles[thisfile]->GetName()<<" but we want "<<(*iblock)->string_meta["EventLoopOutRoot"]<<endl;
std::terminate();
}
if(not vFiles[thisfile]->GetListOfKeys()->Contains((h_yield_strings[iyield]).c_str()) ){
cerr<<"Error! in Get BByields: Cannot find plot "<<h_yield_strings[iyield]<<" in file "<<(*iblock)->string_meta["EventLoopOutRoot"]<< " for DMCblock "<<(*iblock)->name<<endl;
std::terminate();
}
TH1F* temp = (TH1F*) vFiles[thisfile]->Get(h_yield_strings[iyield].c_str());
TH1F* temp2;
if(firstblock) temp2 = (TH1F*)temp->Clone((h_yield_strings[iyield] + "_" + (*iclass)->name ).c_str());
else temp2 = (TH1F*)temp->Clone((h_yield_strings[iyield] + "_" + (*iblock)->name ).c_str());
temp2->Scale(Integrated_Luminosity_Data*1000.0*(*iblock)->cs_pb/((*iblock)->NGenPoints));
if(firstblock) hists.push_back(temp2);
else hists[iyield]->Add(temp2);
}//for every h_yield.
firstblock = false;
}//end for every block
Signal_yields.set((*iclass)->name,hists);
}//end for every signal class
*/
////////////////////////// LOAD BACKGROUND HISTOGRAMS ///////////////////////////////
cout<<"Start loading bkg plots from files"<<endl;
//load histograms into histmapbkg
bool firstround = true;
histmap2D* histmapbkg = new histmap2D();
for(std::vector<DMCblock*>::iterator iblock = dataClass->blocks.begin();iblock<dataClass->blocks.end();iblock++){ //for every block
int thisfile = start_of_data_in_vFiles++;
vFiles[thisfile]->cd();//cd to the data files. This only works if ddbkgclass only contains dataClass.
//cout<<"loading for block "<<(*iblock)->name<<endl;
for(std::vector<string>::iterator iplot = bkgplotnames.begin(); iplot<bkgplotnames.end();iplot++){
if(not vFiles[thisfile]->GetListOfKeys()->Contains((*iplot).c_str()) ){
cerr<<"Error! Cannot find plot "<<*iplot<<" in file "<<(*iblock)->string_meta["EventLoopOutRoot"]<< " for DMCblock "<<(*iblock)->name<<endl;
std::terminate();
}
//cout<<"fetching "<<*iplot<<endl;
TH2F* temp = (TH2F*)vFiles[thisfile]->Get((*iplot).c_str());///fix.
//cout<<"bkg "<<(*iblock)->name<<" plot "<<*iplot<<" first bkg bin: "<<temp->GetBinContent(1,1)<<endl;//xxx
TH2F* temp2;
if(firstround) temp2 = (TH2F*)temp->Clone((*iplot + "_ddBkg").c_str());
else{
temp2 = (TH2F*)temp->Clone((*iplot + "_" + (*iblock)->name ).c_str());
//cout<<"Try cloning under second round with "<<(*iplot) + "_" + (*iblock)->name<<endl<<flush;
}
AddOverflowX(temp2);
fix_negativesX(temp2);
assert(!(*iblock)->isMC);
try{
KinematicVar* thiskinvar = chosenkinvar_stringmap.get_throwable(*iplot,2);
if(thiskinvar->tag.compare("HT") == 0) temp2 = (TH2F*)temp2->RebinX(40,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("ST") == 0) temp2 = (TH2F*)temp2->RebinX(2,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MET") == 0) temp2 = (TH2F*)temp2->RebinX(12,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("BTm") == 0) temp2 = (TH2F*)temp2->RebinX(30,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("BTl") == 0) temp2 = (TH2F*)temp2->RebinX(30,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MinMlb") == 0) temp2 = (TH2F*)temp2->RebinX(2,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("Mll") == 0) temp2 = (TH2F*)temp2->RebinX(4,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("Mlll") == 0) temp2 = (TH2F*)temp2->RebinX(8,(string(temp2->GetName())+"_r").c_str()); // added by rizki - IS THIS RIGHT??
else if(thiskinvar->tag.compare("minMll") == 0) temp2 = (TH2F*)temp2->RebinX(10,(string(temp2->GetName())+"_r").c_str()); // added by rizki - IS THIS RIGHT??
else if(thiskinvar->tag.compare("LepT") == 0) temp2 = (TH2F*)temp2->RebinX(16,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MSum") == 0) temp2 = (TH2F*)temp2->RebinX(10,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("LHT") == 0) temp2 = (TH2F*)temp2->RebinX(20,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MSumovST") == 0) temp2 = (TH2F*)temp2->RebinX(4,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("MtSum") == 0) temp2 = (TH2F*)temp2->RebinX(25,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("lepPt") == 0) temp2 = (TH2F*)temp2->RebinX(4,(string(temp2->GetName())+"_r").c_str());
else if(thiskinvar->tag.compare("jetPt") == 0) temp2 = (TH2F*)temp2->RebinX(4,(string(temp2->GetName())+"_r").c_str());
temp2->SetTitle( thiskinvar->titles.c_str() );
temp2->SetXTitle( thiskinvar->xlabels.c_str() );
temp2->SetYTitle( "Events" );
//change the plot name index to the same index system used by everything else.
string thisbkgplotname(*iplot);//copy iplot
thisbkgplotname.replace(0,1,"h");//convert to the h_form for indexing.
//cout<<"Check: iplot should be b_: "<<*iplot<<" and thisbkgplotname should be h_: "<<thisbkgplotname<<endl;
assert(thisbkgplotname.compare(*iplot));
if(firstround) histmapbkg->set(thisbkgplotname,temp2);
else histmapbkg->get_throwable(thisbkgplotname,3)->Add(temp2);
}
catch(std::pair <std::string,int> errorpair){
cerr<<"Stringmap Error! Invalid string key "<<errorpair.first<< " sought in histmapbkg. Error code "<<errorpair.second<<endl;
std::terminate();
}//end catch
} //for ever plot in the file
firstround = false;
}//for every block in the class
////////////////////////////////////////////////////////
//////////////////////// END FILEWORK //////////////////
////////////////////////////////////////////////////////
//finished loading all the plots into memory.
cout<<"Finished loading all plots from all files"<<endl;
//Build 1D data driven backgrounds
histmap histmapbkg1D;
for(std::map<std::string, TH2F*>::iterator iplot=histmapbkg->begin(); iplot!=histmapbkg->end(); ++iplot) {
histmapbkg1D.set(iplot->first, extrackBkg(iplot->second));
}
////////////////////////////////////////////////////////
//////////////////////MAKE PLOTS////////////////////////
////////////////////////////////////////////////////////
//Run 2 has different rules for the plot decorations:
//no more integal sign, no more sqrt symbol.
//use Helvetica.
TLatex *TEX_CMSlumi = new TLatex(0.879397, 0.92238,Form("%.1f fb^{-1} (13 TeV)",Integrated_Luminosity_Data));
TLatex *TEX_CMSlumi_rat = new TLatex(0.943467,0.92,Form("%.1f fb^{-1} (13 TeV)",Integrated_Luminosity_Data));
TEX_CMSlumi->SetTextAlign(right_justify);
TEX_CMSlumi_rat->SetTextAlign(right_justify);
TLatex *TEX_CMSSim = new TLatex(0.174623, 0.92238,"#bf{CMS} #it{Simulation}");
TLatex *TEX_CMSPrelim = new TLatex(0.174623, 0.92238, "#bf{CMS} #it{Preliminary}");
TLatex *TEX_CMSReal = new TLatex(0.174623, 0.92238,"#bf{CMS}");
//TLatex *TEX_CMSReal = new TLatex(0.15,0.92,"#bf{CMS}");
TLatex *TEX_CMSSim_rat = new TLatex(0.174623,0.92,"#bf{CMS} #it{Simulation}");
TLatex *TEX_CMSPrelim_rat = new TLatex(0.174623,0.92, "#bf{CMS} #it{Preliminary}");
TLatex *TEX_CMSReal_rat = new TLatex(0.174623,0.92,"#bf{CMS}");
/*TLatex *TEX_CMSSim = new TLatex(0.15,0.92,Form("CMS Simulation, #scale[0.75]{#int}#it{L} d#it{t} = %.1f fb^{-1}, #sqrt{s} = 13 TeV",Integrated_Luminosity_Data));
TLatex *TEX_CMSPrelim = new TLatex(0.15,0.92,Form("CMS Preliminary, #scale[0.75]{#int}#it{L} d#it{t} = %.1f fb^{-1}, #sqrt{s} = 13 TeV",Integrated_Luminosity_Data));
TLatex *TEX_CMSReal = new TLatex(0.15,0.92,Form("CMS, #scale[0.75]{#int}#it{L} d#it{t} = %.1f fb^{-1}, #sqrt{s} = 13 TeV",Integrated_Luminosity_Data));*/
PrettyLatex(TEX_CMSlumi,0.04);
PrettyLatex(TEX_CMSSim,0.04);
PrettyLatex(TEX_CMSPrelim,0.04);
PrettyLatex(TEX_CMSReal,0.04);
int MCcolor0 = kGreen;
int MCcolor1 = kBlue;
int MCcolor2 = kRed;
int MCcolorDef = kMagenta+2;
//Common procedure:
try{
for(std::vector<string>::iterator iplot = plotnames.begin(); iplot<plotnames.end();iplot++){
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
htable.get_throwable(*imc,5)->get_throwable(*iplot,6)->Scale(SignalInflationFactor);
}
}
}//end try;
catch(std::pair <std::string,int> errorpair){
cerr<<"Stringmap Error! While making StackPlots, Invalid string key "<<errorpair.first<< " error code "<<errorpair.second<<endl;
std::terminate();
}
if(makeStackPlots_lin){
try{
for(std::vector<string>::iterator iplot = plotnames.begin(); iplot<plotnames.end();iplot++){
TH1F* nametemplate = htable.get_throwable( vClasses[0]->name,1)->get_throwable(*iplot,2);
TH1F* background = (TH1F*) nametemplate->Clone((*iplot + "_bkg").c_str());
background->Reset();
//string Xaxislabel = nametemplate->GetXaxis()->GetTitle();
//string Yaxislabel = nametemplate->GetYaxis()->GetTitle();
//string title = nametemplate->GetTitle();
//string canvtitle = title + ";" + Xaxislabel + ";" + Yaxislabel;
//TCanvas* canv =PrettyCanvas( newTCanvas((*iplot).c_str(),canvtitle.c_str())); //turns out the title is ugly and undesirable.
TCanvas* canv =PrettyCanvas( newTCanvas((*iplot + "_lin").c_str(),""));
canv->SetLeftMargin(0.12);
canv->cd();
THStack* sstack = new THStack((*iplot + "_stack_lin").c_str(), "");
//now for everything on the
TLegend* leg_left = new TLegend( 0.153266, 0.624352, 0.384422, 0.876943);
TLegend* leg_right = new TLegend( 0.616834, 0.624352, 0.84799 , 0.876943);
PrettyLegend(leg_left,0.041);
PrettyLegend(leg_right,0.041);
std::vector<TH1F*> hists_for_set_range;
TH1F* ddbkghist = histmapbkg1D.get_throwable(*iplot,20);
check_for_negatives(ddbkghist);
TH1F* datahist = htable.get_throwable(dataClassName,7)->get_throwable(*iplot,8);
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
hists_for_set_range.push_back(htable.get_throwable(*imc,5)->get_throwable(*iplot,6));
}
hists_for_set_range.push_back(datahist);
//beautify data and put it on the legend
PrettyHist(datahist);
PrettyMarker(datahist);
datahist->SetBinErrorOption(TH1::kPoisson);
if(showData) leg_left->AddEntry(datahist,"DATA");
//beautify dd bkg and put it on the legend
int ddbkgcolor = kGray;
PrettyHist(ddbkghist, ddbkgcolor);
PrettyMarker(ddbkghist,ddbkgcolor,20,0.);
PrettyFillColor(ddbkghist, ddbkgcolor);
ddbkghist->SetBinErrorOption(TH1::kPoisson);
if(draw_ddbkg) leg_left->AddEntry(ddbkghist,"DD Bkg");
//compute legend division
int nTotal = vBkgClasses.size() + SigtoInclude.size() + showData+1; //use this for splitting the legend in two
int nBkgLeft = nTotal/2 + nTotal%2 - SigtoInclude.size() - showData-1;//use this for splitting the legend in two
//Add all the MC plots and the ddBkg to the stack. Also add them to the
int i = 1;
for(std::vector<DMCclass*>::iterator iclass = vBkgClasses.begin();iclass<vBkgClasses.end();iclass++){
//cout<<"plot "<<*iplot<<" filling bkg for class "<< (*iclass)->name<<endl;
TH1F* thishist = htable.get_throwable((*iclass)->name,3)->get_throwable(*iplot,4); // threw 4 on h_MinMlb_OSDL1_sansMlb
//cout<<"plotting bkg for "<<(*iclass)->name<<" X: "<<thishist->GetXaxis()->GetTitle()<<" Y: "<<thishist->GetYaxis()->GetTitle()<<endl;
PrettyFillColor( thishist, (*iclass)->int_meta["FillColor"] );
PrettyMarker( thishist, (*iclass)->int_meta["FillColor"] ,20,0.);
sstack->Add( thishist);
background->Add( thishist);
if(i++ <= nBkgLeft) leg_left->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
else leg_right->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
}//end for all the Backgrounds
if(draw_ddbkg) sstack->Add( ddbkghist);//hopefully this will be the top of the stack. //this line is not the problem.
if(draw_ddbkg) background->Add(ddbkghist);
hists_for_set_range.push_back(background);
//void SameRange_and_leave_legend_room(std::vector<TH1F*> hists, float legendFraction=0., Double_t _min = -1.0, Double_t _max = -1.0);
SameRange_and_leave_legend_room(hists_for_set_range, 0.37, 0.0, -1);
if(((int)SigtoInclude.size())>0){ //I'm guessing this is needed to get the axis labels down.
TH1F* starter_hist = htable.get_throwable(SigtoInclude[0],10)->get_throwable(*iplot,11);
starter_hist->Draw("histo");
}//end if.
sstack->Draw("sameHISTO");
int whichmc = 0;
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
TH1F* thishist = htable.get_throwable(*imc,5)->get_throwable(*iplot,6); //alternative failure point xxx
int linecolor;
switch (whichmc){ //this is inelegant. use meta info.
case 0: linecolor = MCcolor0 /*kGreen*/; break;
case 1: linecolor = MCcolor1 /*kBlue*/; break;
case 2: linecolor = MCcolor2 /*kRed*/; break;
default:linecolor = MCcolorDef /*kMagenta+2*/; break;
}
PrettyHist(thishist, linecolor); //PrettyHist(TH1D* h, int color = 1, int width = 3, int linestyle = 0);
PrettyMarker(thishist,linecolor,20,0.);
//thishist->Sumw2();
thishist->Draw("samehisto");
int thisTpMass = mClasses->get_throwable(*imc,7)->blocks[0]->int_meta["TprimeMass"];//xxx update class with metainfo
leg_left->AddEntry(thishist, ("T'#bar{T}' ("+to_string(thisTpMass) + " GeV) x " + to_string((int) SignalInflationFactor)).c_str() );//xxx could use update with metainfo
//leg_left->AddEntry(thishist,mClasses->get_throwable(*imc,7)->string_meta["LegendLabel"].c_str()); // ("T'#bar{T}' ("+to_string(thisTpMass) + " GeV) x " + to_string((int) SignalInflationFactor)).c_str() );//xxx could use update with metainfo
whichmc++;
}
cout<<"drawing hist "<<*iplot<<endl; //problem is after here.
if(showData) datahist->Draw("Esame");
cout<<"fin draw data"<<endl;
leg_left->Draw("same");
leg_right->Draw("same");
TLatex *plotlabel = new TLatex(0.07,0.015,(*iplot).c_str());
PrettyLatex(plotlabel,0.03);
plotlabel->Draw("same");
gPad->RedrawAxis();
if(showData && preliminary) TEX_CMSPrelim->Draw("same");
else if(showData) TEX_CMSReal->Draw("same");
else TEX_CMSSim->Draw("same"); //this will change once you have a data driven Background.
TEX_CMSlumi->Draw("same");
//problem is before here.
if(saveImages) SaveCanvas(canv,*iplot + "_lin", &plotdirs,savewhat);
}//end for every plot.
}//end try;
catch(std::pair <std::string,int> errorpair){
cerr<<"Stringmap Error! While making StackPlots, Invalid string key "<<errorpair.first<< " error code "<<errorpair.second<<endl;
std::terminate();
}
} //end StackPlots
if(makeStackPlots_lin_ratio){
try{
for(std::vector<string>::iterator iplot = plotnames.begin(); iplot<plotnames.end();iplot++){
TH1F* nametemplate = htable.get_throwable( vClasses[0]->name,1)->get_throwable(*iplot,2);
TH1F* background = (TH1F*) nametemplate->Clone((*iplot + "_bkg").c_str());
background->Reset();
TH1F* MCbackground = (TH1F*) nametemplate->Clone((*iplot + "_mcbkg").c_str());
MCbackground->Reset();
//string Xaxislabel = nametemplate->GetXaxis()->GetTitle();
//string Yaxislabel = nametemplate->GetYaxis()->GetTitle();
//string title = nametemplate->GetTitle();
//string canvtitle = title + ";" + Xaxislabel + ";" + Yaxislabel;
//TCanvas* canv =PrettyCanvas( newTCanvas((*iplot).c_str(),canvtitle.c_str())); //turns out the title is ugly and undesirable.
TCanvas* canv =PrettyCanvas( newTCanvas((*iplot + "_linR").c_str(),""));
TPad* pad_main_for_ratio = new TPad("pad_main_for_ratio","",0.,0.30,1.,0.94);
TPad* pad_ratio = new TPad("pad_ratio","", 0.,0.061,1.,0.30);
//TPad* pad_ratio = new TPad("pad_ratio","", 0.,0.145,1.,0.30);
pad_main_for_ratio->SetBottomMargin(0);
pad_ratio->SetTopMargin(0);
pad_ratio->SetBottomMargin(0.43);
pad_main_for_ratio->cd();
THStack* sstack = new THStack((*iplot + "_stack_linR").c_str(), "");
//now for everything on the
TLegend* leg_left = new TLegend( 0.21608, 0.624352, 0.447236, 0.91385);
TLegend* leg_right = new TLegend( 0.616834, 0.624352, 0.84799 , 0.91385);
PrettyLegend(leg_left,0.041);
PrettyLegend(leg_right,0.041);
std::vector<TH1F*> hists_for_set_range;
TH1F* ddbkghist = histmapbkg1D.get_throwable(*iplot,20);
check_for_negatives(ddbkghist);
TH1F* datahist = htable.get_throwable(dataClassName,7)->get_throwable(*iplot,8);
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
hists_for_set_range.push_back(htable.get_throwable(*imc,5)->get_throwable(*iplot,6));
}
hists_for_set_range.push_back(datahist);
//beautify data and put it on the legend
PrettyHist(datahist);
PrettyMarker(datahist);
datahist->SetBinErrorOption(TH1::kPoisson);
if(showData) leg_left->AddEntry(datahist,"DATA");
//beautify dd bkg and put it on the legend
int ddbkgcolor = kGray;
PrettyHist(ddbkghist, ddbkgcolor);
PrettyMarker(ddbkghist,ddbkgcolor,20,0.);
PrettyFillColor(ddbkghist, ddbkgcolor);
ddbkghist->SetBinErrorOption(TH1::kPoisson);
if(draw_ddbkg) leg_left->AddEntry(ddbkghist,"DD Bkg");
//compute legend division
int nTotal = vBkgClasses.size() + SigtoInclude.size() + showData+1; //use this for splitting the legend in two
int nBkgLeft = nTotal/2 + nTotal%2 - SigtoInclude.size() - showData-1;//use this for splitting the legend in two
//Add all the MC plots and the ddBkg to the stack. Also add them to the
int i = 1;
for(std::vector<DMCclass*>::iterator iclass = vBkgClasses.begin();iclass<vBkgClasses.end();iclass++){
//cout<<"plot "<<*iplot<<" filling bkg for class "<< (*iclass)->name<<endl;
TH1F* thishist = htable.get_throwable((*iclass)->name,3)->get_throwable(*iplot,4); // threw 4 on h_MinMlb_OSDL1_sansMlb
//cout<<"plotting bkg for "<<(*iclass)->name<<" X: "<<thishist->GetXaxis()->GetTitle()<<" Y: "<<thishist->GetYaxis()->GetTitle()<<endl;
PrettyFillColor( thishist, (*iclass)->int_meta["FillColor"] );
PrettyMarker( thishist, (*iclass)->int_meta["FillColor"] ,20,0.);
sstack->Add( thishist);
background->Add( thishist);
MCbackground->Add( thishist);
if(i++ <= nBkgLeft) leg_left->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
else leg_right->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
}//end for all the Backgrounds
if(draw_ddbkg) sstack->Add( ddbkghist);//hopefully this will be the top of the stack.
if(draw_ddbkg) background->Add(ddbkghist);
hists_for_set_range.push_back(background);
//SameRange_and_leave_legend_room(hists_for_set_range, 0.37,false,0.05); //fix scale:
SameRange_and_leave_legend_room(hists_for_set_range, 0.37, 0.0, -1);//********************************
if(((int)SigtoInclude.size())>0){ //I'm guessing this is needed to get the axis labels down.
TH1F* starter_hist = htable.get_throwable(SigtoInclude[0],10)->get_throwable(*iplot,11);
starter_hist->Draw("histo");
}//end if.
sstack->Draw("sameHISTO");
int whichmc = 0;
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
TH1F* thishist = htable.get_throwable(*imc,5)->get_throwable(*iplot,6); //alternative failure point xxx
int linecolor;
switch (whichmc){ //this is inelegant. use meta info.
case 0: linecolor = MCcolor0 /*kGreen*/; break;
case 1: linecolor = MCcolor1 /*kBlue*/; break;
case 2: linecolor = MCcolor2 /*kRed*/; break;
default:linecolor = MCcolorDef /*kMagenta+2*/; break;
}
PrettyHist(thishist, linecolor); //PrettyHist(TH1D* h, int color = 1, int width = 3, int linestyle = 0);
PrettyMarker(thishist,linecolor,20,0.);
//thishist->Sumw2();
thishist->Draw("samehisto");
int thisTpMass = mClasses->get_throwable(*imc,7)->blocks[0]->int_meta["TprimeMass"];//xxx update class with metainfo
leg_left->AddEntry(thishist, ("T'#bar{T}' ("+to_string(thisTpMass) + " GeV) x " + to_string((int) SignalInflationFactor)).c_str() );//xxx could use update with metainfo
//leg_left->AddEntry(thishist,mClasses->get_throwable(*imc,7)->string_meta["LegendLabel"].c_str()); // ("T'#bar{T}' ("+to_string(thisTpMass) + " GeV) x " + to_string((int) SignalInflationFactor)).c_str() );//xxx could use update with metainfo
whichmc++;
}
cout<<"drawing hist "<<*iplot<<endl; //problem is after here.
if(showData) datahist->Draw("Esame");
leg_left->Draw("same");
leg_right->Draw("same");
gPad->RedrawAxis();
///////////////// Ratio subplot ///////////////////////
pad_ratio->cd();
TH1F* ratio = DivideHists(datahist,MCbackground); //ot be drawn as data. with Draw("Esame")
ratio->GetYaxis()->SetTitle("Data/MC Bkg");
PrettyRatioPlot(ratio);
PrettyMarker(ratio);
ratio->GetYaxis()->SetRangeUser(0.,2.);
ratio->Draw("Esame");
TH1F* uncert = make_ratio_uncertainty_hist(datahist, MCbackground);
//PrettyRatioPlot(uncert);
PrettyBlock(uncert, kGray,"//thach");//PrettyBlock2(h[3],kRed,3345,2);
uncert->Draw("E2same");
//Draw the one-line.
TAxis* x = ratio->GetXaxis();
TLine *OneLine = new TLine(x->GetXmin(),1.0,x->GetXmax(),1.0);
OneLine->SetLineColor(kBlack);
OneLine->SetLineWidth(2);
OneLine->SetLineStyle(7);//dashed.
OneLine->Draw("same");
ratio->Draw("Esame");
gPad->RedrawAxis();
////////////////////////////////////////
canv->cd();
pad_main_for_ratio->Draw();
pad_ratio->Draw("same");
TLatex *plotlabel = new TLatex(0.07,0.015,(*iplot).c_str());
PrettyLatex(plotlabel,0.03);
plotlabel->Draw("same");
if(showData && preliminary) TEX_CMSPrelim->Draw("same");
else if(showData) TEX_CMSReal->Draw("same");
else TEX_CMSSim->Draw("same"); //this will change once you have a data driven background.
TEX_CMSlumi->Draw("same");
//SaveCanvas(canv,plotsdir + *iplot,savewhat);
if(saveImages) SaveCanvas(canv,*iplot + "_linRat", &plotdirs,savewhat);
}//end for every plot.
}//end try;
catch(std::pair <std::string,int> errorpair){
cerr<<"Stringmap Error! While making StackPlots, Invalid string key "<<errorpair.first<< " error code "<<errorpair.second<<endl;
std::terminate();
}
} //end StackPlots
if(makeStackPlots_log){
try{
for(std::vector<string>::iterator iplot = plotnames.begin(); iplot<plotnames.end();iplot++){
TH1F* nametemplate = htable.get_throwable( vClasses[0]->name,1)->get_throwable(*iplot,2);
TH1F* background = (TH1F*) nametemplate->Clone((*iplot + "_bkg").c_str());
background->Reset();
//string Xaxislabel = nametemplate->GetXaxis()->GetTitle();
//string Yaxislabel = nametemplate->GetYaxis()->GetTitle();
//string title = nametemplate->GetTitle();
//string canvtitle = title + ";" + Xaxislabel + ";" + Yaxislabel;
//TCanvas* canv =PrettyCanvas( newTCanvas((*iplot).c_str(),canvtitle.c_str())); //turns out the title is ugly and undesirable.
TCanvas* canv =PrettyCanvas( newTCanvas((*iplot + "_log").c_str(),""));
canv->SetLeftMargin(0.12);
canv->cd();
canv->SetLogy();
THStack* sstack = new THStack((*iplot + "_stack_log").c_str(), "");
//now for everything on the
TLegend* leg_left = new TLegend( 0.153266, 0.624352, 0.384422, 0.876943);
TLegend* leg_right = new TLegend( 0.616834, 0.624352, 0.84799 , 0.876943);
PrettyLegend(leg_left,0.041);
PrettyLegend(leg_right,0.041);
std::vector<TH1F*> hists_for_set_range;
TH1F* ddbkghist = histmapbkg1D.get_throwable(*iplot,20);
check_for_negatives(ddbkghist);
TH1F* datahist = htable.get_throwable(dataClassName,7)->get_throwable(*iplot,8);
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
//htable.get_throwable(*imc,5)->get_throwable(*iplot,6)->Scale(SignalInflationFactor);
//fill a vector with everything to go on this plot.
hists_for_set_range.push_back(htable.get_throwable(*imc,5)->get_throwable(*iplot,6));
}
hists_for_set_range.push_back(datahist);
//beautify data and put it on the legend
PrettyHist(datahist);
PrettyMarker(datahist);
datahist->SetBinErrorOption(TH1::kPoisson);
if(showData) leg_left->AddEntry(datahist,"DATA");
//beautify dd bkg and put it on the legend
int ddbkgcolor = kGray;
PrettyHist(ddbkghist, ddbkgcolor);
PrettyMarker(ddbkghist,ddbkgcolor,20,0.);
PrettyFillColor(ddbkghist, ddbkgcolor);
ddbkghist->SetBinErrorOption(TH1::kPoisson);
leg_left->AddEntry(ddbkghist,"DD Bkg");
//compute legend division
int nTotal = vBkgClasses.size() + SigtoInclude.size() + showData+1; //use this for splitting the legend in two
int nBkgLeft = nTotal/2 + nTotal%2 - SigtoInclude.size() - showData-1;//use this for splitting the legend in two
//Add all the MC plots and the ddBkg to the stack. Also add them to the
int i = 1;
for(std::vector<DMCclass*>::iterator iclass = vBkgClasses.begin();iclass<vBkgClasses.end();iclass++){
//cout<<"plot "<<*iplot<<" filling bkg for class "<< (*iclass)->name<<endl;
TH1F* thishist = htable.get_throwable((*iclass)->name,3)->get_throwable(*iplot,4); // threw 4 on h_MinMlb_OSDL1_sansMlb
//cout<<"plotting bkg for "<<(*iclass)->name<<" X: "<<thishist->GetXaxis()->GetTitle()<<" Y: "<<thishist->GetYaxis()->GetTitle()<<endl;
PrettyFillColor( thishist, (*iclass)->int_meta["FillColor"] );
PrettyMarker( thishist, (*iclass)->int_meta["FillColor"] ,20,0.);
sstack->Add( thishist);
background->Add( thishist);
if(i++ <= nBkgLeft) leg_left->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
else leg_right->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
}//end for all the Backgrounds
if(draw_ddbkg) sstack->Add( ddbkghist);//hopefully this will be the top of the stack.
if(draw_ddbkg) background->Add(ddbkghist);
hists_for_set_range.push_back(background);
//void SameRange_and_leave_legend_room_log(std::vector<TH1F*> hists, float legendFraction, bool tinymin_override, Double_t _min, Double_t _max){
SameRange_and_leave_legend_room_log(hists_for_set_range, 0.37,false,0.05); //fix scale:
if(((int)SigtoInclude.size())>0){ //I'm guessing this is needed to get the axis labels down.
TH1F* starter_hist = htable.get_throwable(SigtoInclude[0],10)->get_throwable(*iplot,11);
starter_hist->Draw("histo");
}//end if.
sstack->Draw("sameHISTO");
int whichmc = 0;
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
TH1F* thishist = htable.get_throwable(*imc,5)->get_throwable(*iplot,6); //alternative failure point xxx
int linecolor;
switch (whichmc){ //this is inelegant. use meta info.
case 0: linecolor = MCcolor0 /*kGreen*/; break;
case 1: linecolor = MCcolor1 /*kBlue*/; break;
case 2: linecolor = MCcolor2 /*kRed*/; break;
default:linecolor = MCcolorDef /*kMagenta+2*/; break;
}
PrettyHist(thishist, linecolor); //PrettyHist(TH1D* h, int color = 1, int width = 3, int linestyle = 0);
PrettyMarker(thishist,linecolor,20,0.);
//thishist->Sumw2();
thishist->Draw("samehisto");
int thisTpMass = mClasses->get_throwable(*imc,7)->blocks[0]->int_meta["TprimeMass"];//xxx update class with metainfo
leg_left->AddEntry(thishist, ("T'#bar{T}' ("+to_string(thisTpMass) + " GeV) x " + to_string((int) SignalInflationFactor)).c_str() );//xxx could use update with metainfo
//leg_left->AddEntry(thishist,mClasses->get_throwable(*imc,7)->string_meta["LegendLabel"].c_str()); // ("T'#bar{T}' ("+to_string(thisTpMass) + " GeV) x " + to_string((int) SignalInflationFactor)).c_str() );//xxx could use update with metainfo
whichmc++;
}
cout<<"drawing hist "<<*iplot<<endl; //problem is after here.
if(showData) datahist->Draw("Esame");
leg_left->Draw("same");
leg_right->Draw("same");
TLatex *plotlabel = new TLatex(0.07,0.015,(*iplot).c_str());
PrettyLatex(plotlabel,0.03);
plotlabel->Draw("same");
gPad->RedrawAxis();
if(showData && preliminary) TEX_CMSPrelim->Draw("same");
else if(showData) TEX_CMSReal->Draw("same");
else TEX_CMSSim->Draw("same"); //this will change once you have a data driven background.
TEX_CMSlumi->Draw("same");
//SaveCanvas(canv,plotsdir + *iplot,savewhat);
if(saveImages) SaveCanvas(canv,*iplot + "_log", &plotdirs,savewhat);
}//end for every plot.
}//end try;
catch(std::pair <std::string,int> errorpair){
cerr<<"Stringmap Error! While making StackPlots, Invalid string key "<<errorpair.first<< " error code "<<errorpair.second<<endl;
std::terminate();
}
} //end StackPlots
if(makeStackPlots_log_ratio){
try{
for(std::vector<string>::iterator iplot = plotnames.begin(); iplot<plotnames.end();iplot++){
TH1F* nametemplate = htable.get_throwable( vClasses[0]->name,1)->get_throwable(*iplot,2);
TH1F* background = (TH1F*) nametemplate->Clone((*iplot + "_bkg").c_str());
background->Reset();
TH1F* MCbackground = (TH1F*) nametemplate->Clone((*iplot + "_MCbkg").c_str());
MCbackground->Reset();
//string Xaxislabel = nametemplate->GetXaxis()->GetTitle();
//string Yaxislabel = nametemplate->GetYaxis()->GetTitle();
//string title = nametemplate->GetTitle();
//string canvtitle = title + ";" + Xaxislabel + ";" + Yaxislabel;
//TCanvas* canv =PrettyCanvas( newTCanvas((*iplot).c_str(),canvtitle.c_str())); //turns out the title is ugly and undesirable.
TCanvas* canv =PrettyCanvas( newTCanvas((*iplot + "_logR").c_str(),""));
TPad* pad_main_for_ratio = new TPad("pad_main_for_ratio","",0.,0.30,1.,0.94);
TPad* pad_ratio = new TPad("pad_ratio","", 0.,0.061,1.,0.30);
//TPad* pad_ratio = new TPad("pad_ratio","", 0.,0.145,1.,0.30);
pad_main_for_ratio->SetBottomMargin(0);
pad_ratio->SetTopMargin(0);
pad_ratio->SetBottomMargin(0.43);
pad_main_for_ratio->cd();
pad_main_for_ratio->SetLogy();
THStack* sstack = new THStack((*iplot + "_stack_logR").c_str(), "");
//now for everything on the
TLegend* leg_left = new TLegend( 0.21608, 0.624352, 0.447236, 0.91385);
TLegend* leg_right = new TLegend( 0.616834, 0.624352, 0.84799 , 0.91385);
PrettyLegend(leg_left,0.041);
PrettyLegend(leg_right,0.041);
std::vector<TH1F*> hists_for_set_range;
TH1F* ddbkghist = histmapbkg1D.get_throwable(*iplot,20);
check_for_negatives(ddbkghist);
TH1F* datahist = htable.get_throwable(dataClassName,7)->get_throwable(*iplot,8);
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
hists_for_set_range.push_back(htable.get_throwable(*imc,5)->get_throwable(*iplot,6));
}
hists_for_set_range.push_back(datahist);
//beautify data and put it on the legend
PrettyHist(datahist);
PrettyMarker(datahist);
datahist->SetBinErrorOption(TH1::kPoisson);
if(showData) leg_left->AddEntry(datahist,"DATA");
//beautify dd bkg and put it on the legend
int ddbkgcolor = kGray;
PrettyHist(ddbkghist, ddbkgcolor);
PrettyMarker(ddbkghist,ddbkgcolor,20,0.);
PrettyFillColor(ddbkghist, ddbkgcolor);
ddbkghist->SetBinErrorOption(TH1::kPoisson);
if(draw_ddbkg) leg_left->AddEntry(ddbkghist,"DD Bkg");
//compute legend division
int nTotal = vBkgClasses.size() + SigtoInclude.size() + showData+1; //use this for splitting the legend in two
int nBkgLeft = nTotal/2 + nTotal%2 - SigtoInclude.size() - showData-1;//use this for splitting the legend in two
//Add all the MC plots and the ddBkg to the stack. Also add them to the
int i = 1;
for(std::vector<DMCclass*>::iterator iclass = vBkgClasses.begin();iclass<vBkgClasses.end();iclass++){
//cout<<"plot "<<*iplot<<" filling bkg for class "<< (*iclass)->name<<endl;
TH1F* thishist = htable.get_throwable((*iclass)->name,3)->get_throwable(*iplot,4); // threw 4 on h_MinMlb_OSDL1_sansMlb
//cout<<"plotting bkg for "<<(*iclass)->name<<" X: "<<thishist->GetXaxis()->GetTitle()<<" Y: "<<thishist->GetYaxis()->GetTitle()<<endl;
PrettyFillColor( thishist, (*iclass)->int_meta["FillColor"] );
PrettyMarker( thishist, (*iclass)->int_meta["FillColor"] ,20,0.);
sstack->Add( thishist);
background->Add( thishist);
MCbackground->Add( thishist);
//HERE add the uncertainty to the bkg.
if(i++ <= nBkgLeft) leg_left->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
else leg_right->AddEntry( thishist, (*iclass)->string_meta["LegendLabel"].c_str() );
}//end for all the backgrounds
if(draw_ddbkg) sstack->Add( ddbkghist);//hopefully this will be the top of the stack.
if(draw_ddbkg) background->Add(ddbkghist);
hists_for_set_range.push_back(background);
SameRange_and_leave_legend_room_log(hists_for_set_range, 0.37,false,0.05); //fix scale:
if(((int)SigtoInclude.size())>0){ //I'm guessing this is needed to get the axis labels down.
TH1F* starter_hist = htable.get_throwable(SigtoInclude[0],10)->get_throwable(*iplot,11);
starter_hist->Draw("histo");
}//end if.
sstack->Draw("sameHISTO");
int whichmc = 0;
for(std::vector<string>::iterator imc = SigtoInclude.begin();imc<SigtoInclude.end();imc++){
TH1F* thishist = htable.get_throwable(*imc,5)->get_throwable(*iplot,6); //alternative failure point xxx
int linecolor;
switch (whichmc){ //this is inelegant. use meta info.
case 0: linecolor = MCcolor0 /*kGreen*/; break;
case 1: linecolor = MCcolor1 /*kBlue*/; break;
case 2: linecolor = MCcolor2 /*kRed*/; break;
default:linecolor = MCcolorDef /*kMagenta+2*/; break;