-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotGenerationExample.cc
221 lines (159 loc) · 6.73 KB
/
plotGenerationExample.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// ################
// # Includes #
// ################
#include "common.h"
// Sonic screwdriver
#include "../interface/SonicScrewdriver.h"
#include "../interface/tables/TableDataMC.h"
using namespace theDoctor;
// ####################
// # Event format #
// ####################
typedef struct
{
float invariantMass;
float MET;
float leptonPt;
float leptonFlavor;
int mMuf;
}
microEvent;
microEvent myEvent;
// ######################################################
// # Additional variables to be computed on the fly #
// ######################################################
float leptonPtOverMET()
{
return myEvent.leptonPt / myEvent.MET;
}
// ################
// # Channels #
// ################
// Channels
bool combinedChannel()
{
return true;
}
bool eChannel()
{
if (myEvent.leptonFlavor == 0) return true;
else return false;
}
bool muChannel()
{
if (myEvent.leptonFlavor == 1) return true;
else return false;
}
// ####################
// # Main program #
// ####################
int main (int argc, char *argv[])
{
printBoxedMessage("Starting plot generation");
// ####################
// ## Init tools ##
// ####################
// Create a sonic Screwdriver
SonicScrewdriver s;
s.LoadJsonConfig("./testStyleConfig.json");
// ##########################
// ## Create Variables ##
// ##########################
s.AddVariable("invariantMass", "Invariant mass", "GeV", 40,60,160, &(myEvent.invariantMass), "noUnderflowInFirstBin,noOverflowInLastBin");
s.AddVariable("MET", "Missing E_{T}", "GeV", 40,0,400, &(myEvent.MET), "logY" );
s.AddVariable("leptonPt", "p_{T}(lepton)", "GeV", 30,0,150, &(myEvent.leptonPt), "noUnderflowInFirstBin");
s.AddVariable("mMuf", "True muf mass", "GeV", 11,114,136, &(myEvent.mMuf), "noUnderflowInFirstBin");
// Variable with value defined by a function
s.AddVariable("leptonPtOverMET", "Lepton pT / E^#text{miss}_{T}", "", 40,0,10, &(leptonPtOverMET), "noUnderflowInFirstBin");
// Variable with a custom binning
float customBinning[17] = {0.0,5.0,10.0,15.0,20.0,25.0,30.0,35.0,40.0,50.0,60.0,70.0,80.0,90.0,100.0,125.0,150.0};
s.AddVariable("leptonPt_customBinning", "p_{T}(lepton)", "GeV", 16,customBinning, &(myEvent.leptonPt), "noUnderflowInFirstBin");
// #########################################################
// ## Create ProcessClasses (and associated datasets) ##
// #########################################################
// Backgrounds
s.AddProcessClass("foo", "Foo", "background", COLORPLOT_RED);
s.AddDataset("foo","foo",50000,0.495);
s.AddProcessClass("bar", "Bar", "background", COLORPLOT_ORANGE);
s.AddDataset("bar","bar",50000,0.495);
// Signal(s)
s.AddProcessClass("muf", "Muf", "signal", COLORPLOT_BLUE, "no1DPlots");
s.AddDataset("muf","muf",50000 / 11,0.01);
s.AddProcessClass("muf_125", "Muf (m=125 GeV)", "signal", COLORPLOT_BLUE);
// Data
s.AddProcessClass("data" , "Data", "data", COLORPLOT_BLACK);
s.AddDataset("data","data",-1,-1);
s.SetLumi(50000);
// ##########################
// ## Create Regions ##
// ##########################
vector<Cut> preSelection { Cut("invariantMass", '>', 90) };
s.AddRegion("preSelection","Pre-selection", preSelection);
// Signal region is a daughter of "preSelection", with additional cuts
vector<Cut> signalRegion { Cut("MET", '>', 50), Cut("leptonPt",'>', 50) };
s.AddRegion("signalRegion","Signal region","preSelection",signalRegion);
// ##########################
// ## Create Channels ##
// ##########################
s.AddChannel("combinedChannel","e/#mu-channel",&combinedChannel);
//s.AddChannel("eChannel", "e-channel", &eChannel );
//s.AddChannel("muChannel", "#mu-channel", &muChannel );
// ########################################
// ## Create histograms and ##
// ## schedule type of plots to produce ##
// ########################################
// Create histograms
s.Create1DHistos();
s.Add2DHisto("invariantMass","leptonPt");
s.Add2DHisto("mMuf","invariantMass");
// Schedule plots
s.SchedulePlots("1DSuperimposed");
s.SchedulePlots("1DStack");
s.SchedulePlots("1DDataMCComparison");
s.SchedulePlots("1DFigureOfMerit","var=leptonPt,cutType=keepHighValues");
s.SchedulePlots("2D");
// ########################################
// ## Run over the events ##
// ########################################
vector<string> datasetsList;
s.GetDatasetList(&datasetsList);
cout << " > Reading datasets " << endl;
for (unsigned int d = 0 ; d < datasetsList.size() ; d++)
{
// Get current dataset
string currentDataset = datasetsList[d];
string currentProcessClass = s.GetProcessClass(currentDataset);
// Open dataset tree
TTree* theTree;
TFile* f = new TFile(("trees/"+currentDataset+".root").c_str());
f->GetObject("theTree",theTree);
theTree->SetBranchAddress("theBranch",&myEvent);
// Loop over the events
int nEntries = theTree->GetEntries();
for (int i = 0 ; i < nEntries ; i++)
{
if (i % (nEntries / 50) == 0) printProgressBar(i,nEntries,currentDataset);
// Get the i-th entry
theTree->GetEntry(i);
// Reweight event to luminosity
float weight = s.GetDatasetLumiWeight(currentDataset);
// Fill all the variables
s.AutoFillProcessClass(currentProcessClass,weight);
// Also fill muf_125
if ((currentProcessClass == "muf") && (myEvent.mMuf == 125))
s.AutoFillProcessClass("muf_125",weight);
}
printProgressBar(nEntries,nEntries,currentDataset);
cout << endl;
}
// ###################################
// ## Make plots and write them ##
// ###################################
cout << " > Making and writing plots ... " << endl;
s.MakePlots();
s.WritePlots("./plots/");
vector<string> regionsForTable = { "preSelection", "signalRegion" };
TableDataMC(&s,regionsForTable,"combinedChannel","includeSignal").Print("yieldTable.tab",2);
printBoxedMessage("Plot generation completed");
return (0);
}