-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrawReducedTrees.h
3276 lines (2683 loc) · 116 KB
/
drawReducedTrees.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- C++ -*-
#include "TStopwatch.h"
#include "TRegexp.h"
//classes now split into their own files
#include "ConfigurationDescriptions.h"
// #include "SignalEffData.h" //deprecated
//#include "SearchRegion.h" //deprecated
#include "TGraphAsymmErrors.h"
#include "TSystem.h"
#include <utility>
//New (2014) CMS Style
#include "tdrstyle.C"
#include "CMS_lumi.C"
//CMS style
bool useNewStyle_=false; //default to old CMS Style
TStyle *theStyle =0;
TString theStyleName_;
void initStyle() {
if (useNewStyle_) {
setTDRStyle();
theStyleName_="tdrStyle";
}
else if (theStyle==0 && gROOT->GetStyle("CMS")==0) {
//check if the style is already defined
theStyleName_="CMS";
theStyle = new TStyle("CMS","Style for P-TDR");
// For the canvas:
theStyle->SetCanvasBorderMode(0);
theStyle->SetCanvasColor(kWhite);
theStyle->SetCanvasDefH(600); //Height of canvas
theStyle->SetCanvasDefW(600); //Width of canvas
theStyle->SetCanvasDefX(0); //POsition on screen
theStyle->SetCanvasDefY(0);
// For the Pad:
theStyle->SetPadBorderMode(0);
// theStyle->SetPadBorderSize(Width_t size = 1);
theStyle->SetPadColor(kWhite);
theStyle->SetPadGridX(false);
theStyle->SetPadGridY(false);
theStyle->SetGridColor(0);
theStyle->SetGridStyle(3);
theStyle->SetGridWidth(1);
// For the frame:
theStyle->SetFrameBorderMode(0);
theStyle->SetFrameBorderSize(1);
theStyle->SetFrameFillColor(0);
theStyle->SetFrameFillStyle(0);
theStyle->SetFrameLineColor(1);
theStyle->SetFrameLineStyle(1);
theStyle->SetFrameLineWidth(1);
// For the histo:
// theStyle->SetHistFillColor(1);
// theStyle->SetHistFillStyle(0);
theStyle->SetHistLineColor(1);
theStyle->SetHistLineStyle(0);
theStyle->SetHistLineWidth(1);
// theStyle->SetLegoInnerR(Float_t rad = 0.5);
// theStyle->SetNumberContours(Int_t number = 20);
theStyle->SetEndErrorSize(2);
// theStyle->SetErrorMarker(20);
theStyle->SetErrorX(0.);
theStyle->SetMarkerStyle(20);
//For the fit/function:
theStyle->SetOptFit(1);
theStyle->SetFitFormat("5.4g");
theStyle->SetFuncColor(2);
theStyle->SetFuncStyle(1);
theStyle->SetFuncWidth(1);
//For the date:
theStyle->SetOptDate(0);
// theStyle->SetDateX(Float_t x = 0.01);
// theStyle->SetDateY(Float_t y = 0.01);
// For the statistics box:
theStyle->SetOptFile(0);
theStyle->SetOptStat(0); // To display the mean and RMS: SetOptStat("mr");
theStyle->SetStatColor(kWhite);
theStyle->SetStatFont(42);
theStyle->SetStatFontSize(0.025);
theStyle->SetStatTextColor(1);
theStyle->SetStatFormat("6.4g");
theStyle->SetStatBorderSize(1);
theStyle->SetStatH(0.1);
theStyle->SetStatW(0.15);
// theStyle->SetStatStyle(Style_t style = 1001);
// theStyle->SetStatX(Float_t x = 0);
// theStyle->SetStatY(Float_t y = 0);
// Margins:
theStyle->SetPadTopMargin(0.05);
theStyle->SetPadBottomMargin(0.13);
theStyle->SetPadLeftMargin(0.16);
theStyle->SetPadRightMargin(0.02);
// For the Global title:
theStyle->SetOptTitle(0);
theStyle->SetTitleFont(42);
theStyle->SetTitleColor(1);
theStyle->SetTitleTextColor(1);
theStyle->SetTitleFillColor(10);
theStyle->SetTitleFontSize(0.05);
// theStyle->SetTitleH(0); // Set the height of the title box
// theStyle->SetTitleW(0); // Set the width of the title box
// theStyle->SetTitleX(0); // Set the position of the title box
// theStyle->SetTitleY(0.985); // Set the position of the title box
// theStyle->SetTitleStyle(Style_t style = 1001);
// theStyle->SetTitleBorderSize(2);
// For the axis titles:
theStyle->SetTitleColor(1, "XYZ");
theStyle->SetTitleFont(42, "XYZ");
theStyle->SetTitleSize(0.06, "XYZ");
// theStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
// theStyle->SetTitleYSize(Float_t size = 0.02);
theStyle->SetTitleXOffset(0.9);
theStyle->SetTitleYOffset(1.25);
// theStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
// For the axis labels:
theStyle->SetLabelColor(1, "XYZ");
theStyle->SetLabelFont(42, "XYZ");
theStyle->SetLabelOffset(0.007, "XYZ");
theStyle->SetLabelSize(0.05, "XYZ");
// For the axis:
theStyle->SetAxisColor(1, "XYZ");
theStyle->SetStripDecimals(kTRUE);
theStyle->SetTickLength(0.03, "XYZ");
theStyle->SetNdivisions(510, "XYZ");
theStyle->SetPadTickX(1); // To get tick marks on the opposite side of the frame
theStyle->SetPadTickY(1);
// Change for log plots:
theStyle->SetOptLogx(0);
theStyle->SetOptLogy(0);
theStyle->SetOptLogz(0);
// Postscript options:
theStyle->SetPaperSize(20.,20.);
// theStyle->SetLineScalePS(Float_t scale = 3);
// theStyle->SetLineStyleString(Int_t i, const char* text);
// theStyle->SetHeaderPS(const char* header);
// theStyle->SetTitlePS(const char* pstitle);
// theStyle->SetBarOffset(Float_t baroff = 0.5);
// theStyle->SetBarWidth(Float_t barwidth = 0.5);
// theStyle->SetPaintTextFormat(const char* format = "g");
// theStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
// theStyle->SetTimeOffset(Double_t toffset);
// theStyle->SetHistMinimumZero(kTRUE);
theStyle->cd(); //what does this do?
//end CMS style
}
else theStyleName_="CMS";
}
//useful for playing around with plots in interactive ROOT
TH1D* hinteractive=0;
TH2D* h2d=0;
TLatex* text1=0;
TLatex* text2=0;
TLatex* text3=0;
TLatex* text4=0;
//holds a list of the *active* samples (to be plotted)
std::vector<TString> samples_;
//hold a list of all samples
std::set<TString> samplesAll_;
//config descriptions defined below
//these maps use the sample names as keys
std::map<TString, std::map<TString, std::pair<TFile*,TChain*> > > files_;
std::map<TString, TH1D*> histos_;
std::map<TString, UInt_t> sampleColor_;
std::map<TString, TString> sampleLabel_;
std::map<TString, UInt_t> sampleMarkerStyle_;
std::map<TString, UInt_t> sampleLineStyle_;
std::map<TString, TString> sampleWeightFactor_;//an arbitary string for weighting individual samples
std::map<TString, float> sampleScaleFactor_; //1 by default //implemented only for drawPlots!
std::map<TString, TChain*> primaryDatasets_;
std::vector<TLine*> verticalLines_; //for decorating plots with a set of vertical lines
std::vector<float> verticalLinePositions_; //for decorating plots with a set of vertical lines
TChain* dtree=0;
TH1D* hdata=0;
TH2D* hdata2d=0;
TString outputdirectory_="";
TString currentConfig_;
TH2D* scanSMSngen=0;
TH3D* scanSMSngen3D=0;
//TH1D* referenceCrossSectionGluino=0;
CrossSectionTable * CrossSectionTable_gluino_=0;
CrossSectionTable * CrossSectionTable_stop_=0;
CrossSectionTable * CrossSectionTable_higgsino_ = 0;
//default selection
TString selection_ ="cutHT==1 && cutPV==1 && cutTrigger==1 && cut3Jets==1 && cutEleVeto==1 && cutMuVeto==1";
TString nameOfEventWeight_="weight";
TString reducedTreeName_="reducedTree";
float leg_x1 , leg_x2, leg_y1, leg_y2;
void resetLegendPositionR() {
leg_x1 = 0.2;
leg_x2=0.45;
leg_y1=0.65;
leg_y2=0.9;
}
void resetLegendPositionNewStyle() {
leg_x1 = 0.67;
leg_x2=0.92;
leg_y1=0.42;
leg_y2=0.84;
}
void resetLegendPosition() {
if (useNewStyle_) {resetLegendPositionNewStyle(); return;}
leg_x1 = 0.696;
leg_x2=0.94;
leg_y1=0.5;
leg_y2=0.9;
}
ConfigurationDescriptions configDescriptions_;
// class for holding inputs to drawSimple (could be expanded)
class toPlot {
TString varname;
int nbins;
double binlow, binhigh;
public:
toPlot(TString,int,double,double);
void print();
TString getVarName() {return varname;}
int getNBins() {return nbins;}
double getBinLow() {return binlow;}
double getBinHigh() {return binhigh;}
};
toPlot::toPlot(TString a, int b, double c, double d) {
varname = a;
nbins = b;
binlow = c;
binhigh = d;
}
void toPlot::print() {
cout << varname << ": " << nbins << " bins, from " << binlow << " to " << binhigh << endl;
}
bool quiet_=false;
//bool quiet_=true;
bool doRatio_=false;
TString fitRatio_="";
bool logz_=false;
bool logy_=false;
bool logx_=false;
bool dostack_=true;
bool stackSignal_=true;
bool doleg_=true;
bool dodata_=true;
bool drawDataZeroes_=false;
bool addOverflow_=true;
//bool doSubtraction_=false;
bool drawMCErrors_=false;
bool drawBTagErrors_=false; // ONLY works for HH analysis 2b,3b,4b bins
bool drawTopPtErrors_=false; //
bool renormalizeBins_=false;//no setter function
double renormalizeWidth_=1;
bool owenColor_ = false;
bool drawFilenameOnPlot_=false;
bool dataPoissonError_=true;
float unstackedLineWidth_ = 2; //for line-only plots, i don't like a thicker width
float dataMarkerSize_=1; //my default
int m0_=0;
int m12_=0;
int mIntermediate_=0;
TString susyCrossSectionVariation_="";
bool normalized_=false;
bool usePUweight_=false;
bool useTrigEff_ = false;
TString trigEffWeight_="*hlteff";
TString triggerSelectionMC_="";
TString triggerSelectionData_="";
TString btagSFweight_="1";
bool savePlots_ = true; //no setter function
bool drawTotalSM_=false; //no setter function
bool drawTotalSMSusy_=false;//no setter function
bool drawSusyOnly_=false;//no setter function
bool drawMarkers_=true;//no setter function
bool treatAllAsSM_=false;
bool useMassInLegend_=true;
bool doCustomPlotMax_=false;
double customPlotMax_=0;
bool doCustomPlotMin_=false;
double customPlotMin_=0;
float maxScaleFactor_ = 1.05;
float xlabeloffset_=0.015;
float xtitleoffset_=1.16; //was 0.97
int customDivisionsVal_ = 505;
bool customDivisions_=false;
//revamp the plot header options
/*
desired logic:
plotting data ?
if yes, write CMS [Preliminary], lumi, sqrt(s) = X TeV
if no, write CMS Simulation
lumi is optional
energy is mandatory
options needed:
bool isPreliminary_
energy
when to write lumi? if not normalized, then yes
*/
bool isPreliminary_ = true;
bool isTwikiOnly_ = false;
bool billGaryHeader_ = false;
TString dataLegendDrawOptions_ = "lpf";
int cmEnergy_=8; //let's see if we ever need to change this to float!
bool plotSelectionLabel_ = true;
TString selectionLabel_="";
bool doAppendBinWidth_ = true;
//bool latexMode_=false;
bool latexMode_=true;
const TString pm = latexMode_ ? " \\pm " : " +/- ";
TCanvas* thecanvas=0;
//TCanvas* cratio=0;
TLegend* leg=0;
THStack* thestack=0;
TLatex* extraTextLatex=0;
TString extratext_="";
double rLine = -1;
TH1D* totalsm=0;
//special histos for systematics
TH1D* totalsm_btagP1=0;
TH1D* totalsm_btagM1=0;
TH1D* totalsm_topptP1=0;
TH1D* totalsm_topptM1=0;
//special histos for counting different combinations of events (a bit old-fashioned at this point)
TH1D* totalsmsusy=0;
TH1D* totalewk=0;
TH1D* totalqcdttbar=0;
TH1D* totalnonttbar=0;
TH1D* totalnonqcd=0;
TH1D* totalqcd=0; //ben - just for ease of doing event counts with drawPlots
TH1D* ratio=0; float ratioMin=0.0; float ratioMax=2.5;
TLine* ratioLine=0;
TGraphErrors* mcerrors=0;
TGraphAsymmErrors* effgraph=0;
bool loaded_=false; //bookkeeping
bool loadedSusyHistos_=false;//bookkeeping
//initialized tchains that point to MC samples
void resetChains() {
cout<<"[resetting chains]"<<endl;
//loop over files and set the TChain to point to the reducedTree in that files
for ( std::map<TString, std::map<TString, std::pair<TFile*,TChain*> > >::iterator ifile = files_.begin();
ifile != files_.end(); ++ifile) {
cout<<"\t"<<ifile->first<<endl;
std::map<TString, std::pair<TFile*,TChain*> > thisguy = ifile->second;
for ( std::map<TString, std::pair<TFile*,TChain*> >::iterator icfg = thisguy.begin(); icfg!= thisguy.end(); ++icfg) {
if (icfg->second.first !=0 && (!icfg->second.first->IsZombie())) {
cout<<"\t"<<icfg->first<<" "<<icfg->second.first->GetName()<<endl ;
//now we've got the std::pair
// files_[ifile->first][icfg->first].second = (TChain*) icfg->second.first->Get(reducedTreeName_);
if (files_[ifile->first][icfg->first].second != 0) delete files_[ifile->first][icfg->first].second;
files_[ifile->first][icfg->first].second = new TChain(reducedTreeName_);
files_[ifile->first][icfg->first].second->Add( files_[ifile->first][icfg->first].first->GetName() );
}
else files_[ifile->first][icfg->first].second =0;
}
}
}
TString stripSamplename(TString fullname) {
//actually, this is ok
// if ( fullname.Contains("$") && fullname.Contains(":") ) cout<<"Simultaneous use of $ and : syntax not currently allowed!"<<endl;
//eg for samplename T1tttt$900$100, return T1tttt
TString name = fullname.Tokenize("$")->At(0)->GetName();
//also allow the TTbarJets:cutstring syntax
name = name.Tokenize(":")->At(0)->GetName();
return name;
}
TChain* getTree(const TString & samplename) {
TChain* t = (TChain*) files_[currentConfig_][samplename].second;
return t;
}
//plot multiple "samples" as one
void chainSamples(const TString & parent, const TString & child) {
if (parent.Contains("$") || parent.Contains(":") ) {
cout<<" cannot chain subsamples defined with $ or :"<<endl;
return;
}
//first enforce some sanity
//the parent must be plotted, and the child must not be plotted
//the might be a bit overzealous, especially the first part. we'll see
bool foundit=false;
for (unsigned int isample = 0; isample<samples_.size(); isample++) {
if (samples_[isample] == parent || stripSamplename(samples_[isample])==parent) { foundit=true;}
if (samples_[isample] == child) {
cout<<child<<" is already on the plotting list! Why do you want to plot it twice? quitting..."<<endl;
return;
}
}
if (!foundit) {
cout<<parent<<" is not on the plotting list! Not chaining samples...."<<endl;
return;
}
cout<<"Adding "<<child<<" to "<<parent<<". n entries goes from "<<getTree(parent)->GetEntries()<<" to ";
TChain* newtree = getTree(child);
if (newtree==0) assert(0);
getTree(parent)->Add( newtree);
cout<<getTree(parent)->GetEntries()<<endl;
}
// == set configuration options ==
void setQuiet(bool q) {
quiet_ = q;
}
void doRatioPlot(bool doIt) {
doRatio_=doIt;
}
void setPlotMaximum(double max) {
customPlotMax_=max;
doCustomPlotMax_=true;
}
void resetPlotMaximum() {
doCustomPlotMax_=false;
}
void setPlotMinimum(double min) {
customPlotMin_=min;
doCustomPlotMin_=true;
}
void resetPlotMinimum() {
doCustomPlotMin_=false;
}
TLine* getVerticalLine(unsigned int index) { return verticalLines_[index];}
void addVerticalLine(float position) {
verticalLinePositions_.push_back(position);
}
// void showDataMinusMC(bool dosub) {
// doSubtraction_=dosub;
// }
void deleteVerticalLines() {
for (unsigned int il=0; il<verticalLines_.size(); il++) {
// cout<<" DEBUG deleting line "<<il<<" "<< verticalLines_.at(il)<<endl;
delete verticalLines_.at(il);
}
verticalLines_.clear();
}
void resetVerticalLine() {
//this can crash the code if run at the wrong time. why?
// deleteVerticalLines();
//
verticalLinePositions_.clear();
}
void setOutputDirectory(TString path) {
if (TString(path( path.Length()-1 ))!="/") path.Append("/");
outputdirectory_ = path;
FileStat_t fs;
int dirnotthere = gSystem->GetPathInfo(outputdirectory_.Data(),fs);
if (dirnotthere==1) { //then make the directory
cout<<"Directory "<<outputdirectory_<<" not found. ";
int mkdirstat = gSystem->mkdir(outputdirectory_.Data());
if (mkdirstat==0) cout<<"Created it!"<<endl;
else {
cout<<"Problem creating directory. Will revert to output in main directory."<<endl;
outputdirectory_="";
}
}
}
void doOverflowAddition(bool doOv) {
addOverflow_ = doOv;
}
void setLogY(bool dolog) {
logy_=dolog;
if (logy_) maxScaleFactor_=3;
else maxScaleFactor_=1.05;
}
void doData(bool dodata) {
dodata_=dodata;
}
void drawLegend(bool doleg) {
doleg_=doleg;
}
void setLumiScale(double lumiscale){
lumiScale_ = lumiscale;
}
//CMSSM/mSugra stuff is definitely not up-to-date -- may not work anymore
CrossSectionTable * CrossSectionTable_mSUGRAtanb40_=0;
void loadSusyCrossSections() {
if (CrossSectionTable_mSUGRAtanb40_==0) {
CrossSectionTable_mSUGRAtanb40_ = new CrossSectionTable("NLOxsec_tanb40_10.txt");
}
}
bool isSampleSMS(const TString & name ) {
if (name.Contains("T1bbbb")) return true;
if (name.Contains("T2bb")) return true;
if (name.Contains("T1tttt")) return true;
if (name.Contains("T1ttcc")) return true;
if (name.Contains("T5tttt")) return true;
if (name.Contains("T1t1t")) return true;
if (name.Contains("T2tt")) return true;
if (name.BeginsWith("HiggsinoNLSP")) return true;
if (name.BeginsWith("SMS-TChiHH")) return true;
if (name.BeginsWith("SMS-TChiZH")) return true;
return false;
}
bool isSampleScan(const TString & name ) {
if (isSampleSMS(name)) return true;
if (name.Contains("SUGRA")) return true;
return false;
}
bool isSampleSM(const TString & name) {
if (treatAllAsSM_) return true;
if (name.Contains("LM")) return false;
if (name.Contains("sbottom")) return false;
if (name.Contains("TChihh")) return false;
if (name.Contains("HbbHbb")) return false;
if (name.Contains("Higgsino")) return false;
if (name.Contains("SUGRA")) return false;
if (isSampleSMS(name)) return false;
if (name.Contains("susyhit"))return false; //Delphes Upgrade sample
if (name.Contains("naturalModel"))return false; //Delphes Upgrade sample
if (name.Contains("stoc"))return false; //Delphes Upgrade sample
return true;
}
TString extractExtraCut(TString fullname) {
if ( !fullname.Contains(":") ) return "";
TString cuts = fullname.Tokenize(":")->At(1)->GetName();
cuts.Prepend("(");
cuts += ")";
return cuts;
}
void setScanPoint(const TString & name) {
// format is e.g. T1bbbb$m0$m12
// --or-- T1t1t$m0$mIntermediate$m12
//either of these is supported
if (!name.Contains("$")) {
if (!quiet_) cout<<"warning -- not setting scan point"<<endl;
return;
}
//careful...need to clean up memory after tokenize
TObjArray * substrs = name.Tokenize("$");
if ( substrs->At(1)==0 || substrs->At(2)==0) assert(0);
int index_mlsp = 2;
TString mintermediate="";
if ( substrs->At(3) !=0) {
index_mlsp=3;
mintermediate = TString(substrs->At(2)->GetName());
mIntermediate_ = mintermediate.Atoi();
}
else {
mIntermediate_=0;
}
TString m0=TString(substrs->At(1)->GetName());
TString m12=TString(substrs->At(index_mlsp)->GetName());
m0_=m0.Atoi();
m12_=m12.Atoi();
delete substrs;
}
int getSMSProdProcess(const TString & sample) {
if (sample.Contains("T1")) return 8; //gluino-gluino production
assert(0); //T2 needs implementation
return 10;
}
void loadScanSMSngen(const TString& sampleOfInterest) {
scanSMSngen = (TH2D*) files_[currentConfig_][sampleOfInterest].first->Get("scanSMSngen");
scanSMSngen3D = (TH3D*) files_[currentConfig_][sampleOfInterest].first->Get("scanSMSngen3D");
}
void loadReferenceCrossSections() {
if ( CrossSectionTable_gluino_ == 0) {
cout<<"Loading reference cross section file (g~g~)"<<endl;
CrossSectionTable_gluino_ = new CrossSectionTable("gluino.root","smsroot","gluino");
}
if (CrossSectionTable_stop_ == 0) {
cout<<"Loading reference cross section file (t~t~)"<<endl;
CrossSectionTable_stop_ = new CrossSectionTable("stop.root","smsroot","stop");
}
if (CrossSectionTable_higgsino_==0) {
cout<<"Loading reference cross section file (higgsino)"<<endl;
CrossSectionTable_higgsino_ = new CrossSectionTable("CrossSectionsHiggsino.txt","simplesms");
}
}
// jmt Dec 2012 -- honestly not sure if this is needed anymore. leave it for now.
//m0, m12 //pdf set
map<pair<int,int>, map<TString, TH2D*> > scanProcessTotalsMap;
void loadSusyScanHistograms() {
if (loadedSusyHistos_) return;
TFile* susyfile = 0;
for (unsigned int isample=0; isample<samples_.size(); isample++) {
if ( !isSampleSM(samples_[isample])) {
susyfile = files_[currentConfig_][samples_[isample]].first;
cout<<" Loading SUSY scan histograms from file: "<<susyfile->GetName()<<endl;
}
}
if (susyfile==0) {cout<<"did not find SUSY file in loadSusyScanHistograms!"<<endl; return;}
TString fn=susyfile->GetName();
bool isSMS = !fn.Contains("SUGRA");
if (isSMS && scanSMSngen==0) assert(0);
const int ntotal = susyfile->GetListOfKeys()->GetEntries();
cout<<"found this many keys: "<<ntotal<<endl;
int nloaded=0;
for (int i=0; i<ntotal; i++) {
TString objname= susyfile->GetListOfKeys()->At(i)->GetName();
if (objname.BeginsWith("scanProcessTotals") ) {
TString pdfset= objname.Tokenize("_")->At(0)->GetName();
pdfset.ReplaceAll("scanProcessTotals","");
TString m0str= objname.Tokenize("_")->At(1)->GetName();
TString m12str= objname.Tokenize("_")->At(2)->GetName();
int m0 = m0str.Atoi();
int m12 = m12str.Atoi();
if (isSMS && TMath::Nint(scanSMSngen->GetBinContent(scanSMSngen->FindBin(m0,m12))) ==0) continue;
scanProcessTotalsMap[make_pair(m0,m12)][pdfset] = (TH2D*) susyfile->Get(objname);
nloaded++;
if (nloaded%1000==0) cout<<nloaded<<" ; "<<i<<" / "<<ntotal<<endl;
}
}
loadedSusyHistos_=true;
}
//oct 13 -- not sure this function is really in use anymore, but leave it here for now
void drawPlotHeaderInside(TString displaytext="",float xNDC=0.6,float yNDC=0.9) {
if (text1 != 0 ) delete text1;
if ( displaytext=="") displaytext = "CMS Simulation";
text1 = new TLatex(5,23.08044,displaytext);
text1->SetNDC();
text1->SetTextAlign(13);
text1->SetX(xNDC);
text1->SetY(yNDC);
text1->SetTextFont(42);
text1->SetTextSizePixels(24);
text1->SetTextSize(0.044);
text1->Draw();
}
void drawPlotHeader() {
//Oct 2013 -- cleaned up the cruft that had accumulated in here. hopefully didn't break anything
//2014 -- new rules demand that certain plots be labeled 'CMS Unpublished'
//summer 2014 -- new plot style code is supposed to take the place of this!
//testing it out
if (useNewStyle_) {
if (isTwikiOnly_) {
extraText="Unpublished"; writeExtraText=true;
}
else if (!dodata_ && cmEnergy_<12) {
//for 14 TeV studies, 'Simulation' comes in through the other script
extraText="Simulation"; writeExtraText=true;
}
else if (isPreliminary_) {
extraText="Preliminary"; writeExtraText=true;
}
else writeExtraText=false;
TString lumiString;
if (lumiScale_/1000.0 > 49) lumiString.Form("%.0f fb^{-1}",lumiScale_/1000.);
else lumiString.Form("%.1f fb^{-1}",lumiScale_/1000.);
lumi_8TeV = lumiString;
lumi_7TeV = lumiString;
lumi_14TeV = lumiString;
lumi_14TeV += ", PU = 140";
int iPeriod=1;
if (cmEnergy_==7) iPeriod = 1;
else if (cmEnergy_==8) iPeriod=2;
else if (cmEnergy_==14) iPeriod=14;
CMS_lumi( thecanvas, iPeriod, 11 ); //see https://twiki.cern.ch/twiki/pub/CMS/TpRootStyle/myMacro.C
//leaves out option to plotSelectionLabel_
//also seems like it isn't smart when it comes to printing the lumi or not
return;
}
if (text1 != 0 ) delete text1;
TString cmsString="CMS";
//if no data, it is Simulation
if (isTwikiOnly_) cmsString += " Unpublished";
else if (!dodata_) cmsString += " Simulation";
//if data, then add Preliminary if desired
else if (isPreliminary_) cmsString += " Preliminary";
//add lumi if there is data or if it is a lumi-normalized MC plot
if ( dodata_ || !normalized_ ) {
TString lumiString;
// if (billGaryHeader_&&isPreliminary_)lumiString.Form(" L = %.1f fb^{-1}",lumiScale_/1000.);//bill asked for no commas and a lot of space
if (billGaryHeader_ ) lumiString.Form(" L = %.1f fb^{-1}",lumiScale_/1000.);//bill asked for no commas and a lot of space
else if (lumiScale_/1000.0 > 49) lumiString.Form(", L = %.0f fb^{-1}",lumiScale_/1000.);
else lumiString.Form(", L = %.1f fb^{-1}",lumiScale_/1000.);
cmsString += lumiString;
}
// always add energy
TString energyString;
if (billGaryHeader_ ) energyString.Form(" #sqrt{s} = %d TeV",cmEnergy_);//bill asked for no commas and a lot of space
else energyString.Form(", #sqrt{s} = %d TeV",cmEnergy_);
cmsString += energyString;
//bill asked for the text to be "centered" above the figure
if (billGaryHeader_ && (isPreliminary_ || !dodata_)) cmsString.Prepend(" ");
if (billGaryHeader_ && !isPreliminary_) cmsString.Prepend(" ");
if (text2 != 0 ) delete text2;
text2 = new TLatex(3.570061,23.08044,cmsString);
text2->SetNDC();
text2->SetTextAlign(13);
text2->SetX(0.17);
text2->SetY(0.985 );
text2->SetTextFont(42);
text2->SetTextSizePixels(24);
text2->SetTextSize(0.044); //was 0.045
text2->Draw();
if(plotSelectionLabel_){
if (text4 != 0 ) delete text4;
text4 = new TLatex(5,23.08044,selectionLabel_);
text4->SetNDC();
text4->SetTextAlign(13);
text4->SetX(0.2);
text4->SetY(.89);
text4->SetTextFont(42);
//text4->SetTextSizePixels(26);
text4->SetTextSize(0.06);
text4->Draw();
}
}
void setSelectionLabel(TString label){
selectionLabel_ = label;
}
int mainpadWidth; int mainpadHeight;
int ratiopadHeight = 150;
// TPad* mainPad=0;
// TPad* ratioPad=0;
void renewCanvas(const TString opt="",const int ncol=1) {
//careful: ncol argument is not supported by drawPlots()
if (thecanvas!=0) delete thecanvas;
int canvasWidth = mainpadWidth;
int canvasHeight = opt.Contains("ratio") ? mainpadHeight+ratiopadHeight : mainpadHeight;
// if (drawCutsOnPlot_) canvasHeight += 50;
thecanvas= new TCanvas("thecanvas","the canvas",canvasWidth,canvasHeight);
thecanvas->cd()->SetRightMargin(0.04);
thecanvas->cd()->SetTopMargin(0.08); //test
if (opt.Contains("ratio")) {
//thecanvas->Divide(1,2);
//const float padding=0.01; const float ydivide=0.2;
gStyle->SetPadBorderMode(0);
gStyle->SetFrameBorderMode(0);
Float_t small = 1e-5;
thecanvas->Divide(1,2,small,small);
const float padding=1e-5; const float ydivide=0.3;
thecanvas->GetPad(1)->SetPad( padding, ydivide + padding, 1-padding, 1-padding);
thecanvas->GetPad(2)->SetPad( padding, padding, 1-padding, ydivide-padding);
thecanvas->GetPad(1)->SetTopMargin(0.07); //0.06
thecanvas->GetPad(1)->SetRightMargin(.05);
thecanvas->GetPad(2)->SetRightMargin(.05);
thecanvas->GetPad(2)->SetBottomMargin(.4);
thecanvas->GetPad(1)->Modified();
thecanvas->GetPad(2)->Modified();
thecanvas->cd(1);
gPad->SetBottomMargin(small);
gPad->Modified();
if (false) cout<< thecanvas->GetPad(1)->GetXlowNDC() <<"\t" //no need to see this anymore
<< thecanvas->GetPad(1)->GetWNDC() <<"\t"
<< thecanvas->GetPad(1)->GetYlowNDC() <<"\t"
<< thecanvas->GetPad(1)->GetHNDC() <<endl;
if (logz_) thecanvas->GetPad(1)->SetLogz();
if (logy_) thecanvas->GetPad(1)->SetLogy();
if (logx_) thecanvas->GetPad(1)->SetLogx();
}
else {
// cout<<"[ renewCanvas ] "<<ncol<<endl;
if (ncol>1) { //only support multple columns for the no ratio plot option -- this is a hack!
thecanvas->Divide(ncol,1);
for (int icol=1;icol<=ncol;icol++) {
if (logz_) thecanvas->GetPad(icol)->SetLogz();
if (logy_) thecanvas->GetPad(icol)->SetLogy();
if (logx_) thecanvas->GetPad(icol)->SetLogx();
}
}
else {
if (logz_) thecanvas->SetLogz();
if (logy_) thecanvas->SetLogy();
if (logx_) thecanvas->SetLogx();
}
thecanvas->GetPad(0)->SetBottomMargin(0.16); //default 0.13
}
int cdarg = (opt.Contains("ratio") || ncol>1) ? 1 : 0;
thecanvas->cd(cdarg);
}
void resetPadDimensions() {
mainpadWidth = 600;
mainpadHeight=550;
}
void setPadDimensions(int x, int y) {
mainpadWidth = x;
mainpadHeight= y;
}
void renewLegend(int fillstyle=0) {
if (leg!=0) delete leg;
leg = new TLegend(leg_x1, leg_y1, leg_x2, leg_y2);
leg->SetBorderSize(0);
leg->SetLineStyle(0);
leg->SetTextFont(42);
leg->SetFillStyle(fillstyle);
if (fillstyle!=0) leg->SetFillColor(0);
}
void renewExtraText() {
if (extraTextLatex!=0) delete extraTextLatex;
extraTextLatex = new TLatex();
extraTextLatex->SetNDC();
extraTextLatex->SetTextAlign(13);
extraTextLatex->SetX(0.5);
extraTextLatex->SetY(.85);
extraTextLatex->SetTextFont(42);
extraTextLatex->SetTextSizePixels(24);
}
void resetHistos() {
for ( std::map<TString, TH1D*>::iterator i = histos_.begin(); i!=histos_.end(); ++i) {
if (i->second != 0) {
delete i->second;
i->second= 0;
}
}
}
double findOverallMax(const TH1D* hh) {
double max=-1e9;