-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakeTableMC.C
281 lines (216 loc) · 15.2 KB
/
makeTableMC.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
#include <iostream>
#include <fstream>
using namespace std;
#include "CommonFunctions.C"
#include " TH1D.h"
void calculateA( TCut baseline, const char* var, bool isGen, float& event_total, float& event_plus, float& event_minus, float& event_corr, float& asymm, float& asymm_err ){
const char* temp = Form("(%s*%s_gen) >0", var, var);
TCut corrSign = temp && baseline;
cout <<temp <<endl;
TCut plusSign ;
TCut minusSign ;
if(!isGen){
plusSign = Form("%s >0", var) && baseline;
minusSign = Form("%s <0", var) && baseline;
}
else{
plusSign = Form("%s_gen >0", var) && baseline;
minusSign = Form("%s_gen <0", var) && baseline;
}
TH1D* hlepChargeA = new TH1D("lepChargeA", "lepChargeA", 4, -10, 10);
hlepChargeA->Sumw2();
TH1D* hlepChargeA_plus = new TH1D("lepChargeA_plus", "lepChargeA_plus", 4, -10, 10);
hlepChargeA_plus->Sumw2();
TH1D* hlepChargeA_minus = new TH1D("lepChargeA_minus", "lepChargeA_minus", 4, -10, 10);
hlepChargeA_minus->Sumw2();
TH1D* hlepChargeA_corr = new TH1D("lepChargeA_corr", "lepChargeA_corr", 4, -10, 10);
hlepChargeA_corr->Sumw2();
tree->Draw(Form("%s >> %s", var, "lepChargeA"), baseline*"weight");
tree->Draw(Form("%s >> %s", var, "lepChargeA_corr"), corrSign*"weight");
if(!isGen){
tree->Draw(Form("%s >> %s", var, "lepChargeA_plus") , plusSign*"weight");
tree->Draw(Form("%s >> %s", var, "lepChargeA_minus"), minusSign*"weight");
}
else{
tree->Draw(Form("%s >> %s", var, "lepChargeA_plus") , plusSign*"weight");
tree->Draw(Form("%s >> %s", var, "lepChargeA_minus"), minusSign*"weight");
}
int nbins = lepChargeA->GetNbinsX();
Double_t event_plus_err;
Double_t event_minus_err;
//cout<<"int int+e "<<lepChargeA->Integral(0, nbins+1)<<" "<< lepChargeA->IntegralAndError(0, nbins+1, err,"")<<" "<<err<<endl;
event_total= lepChargeA->Integral(0, nbins+1);
event_plus = lepChargeA_plus-> IntegralAndError(0, nbins+1, event_plus_err,"");
event_minus = lepChargeA_minus-> IntegralAndError(0, nbins+1, event_minus_err,"");
//cout<<event_plus<<" "<<sqrt(event_plus)<<" "<<event_plus_err<<endl;
event_corr = (lepChargeA_corr->Integral(0, nbins+1))/event_total;
asymm = (event_plus-event_minus)/(event_plus+event_minus);
//double asymm_err_datasim = sqrt(4*(event_plus*event_minus)/(event_total*event_total*event_total));
asymm_err = sqrt(4*(event_plus*event_plus*event_minus_err*event_minus_err + event_minus*event_minus*event_plus_err*event_plus_err)/(event_total*event_total*event_total*event_total));
//cout<<"asym_err, asym_err_sqrtN "<<asymm_err<<" "<<asymm_err_datasim<<endl;
delete hlepChargeA ;
delete hlepChargeA_plus;
delete hlepChargeA_minus;
delete hlepChargeA_corr;
}
void makeTableMC(TString samplename, int ycut=0, bool isData=false){
TString inputrootfilename = samplename;
inputrootfilename += ".root";
TChain *ch = new TChain("tree");
ch->Add(inputrootfilename.Data());
if(!isData){
ch->Add("ttotr.root");
ch->Add("wjets.root");
ch->Add("DYee.root");
ch->Add("DYmm.root");
ch->Add("DYtautau.root");
ch->Add("tw.root");
ch->Add("VV.root");
}
bool latex=true;
std::string pmSign = latex ? " $\\pm$ " : " ± ";
std::string colSep = latex ? " & " : " | ";
std::string beginL = latex ? "" : "| ";
std::string endL = latex ? " \\\\ " : " | ";
std::string mathSep = latex ? "$" : "";
const char* formatS = "%6.3f";
if(ycut == -2) TCut baseline = "";
if(ycut == -1) TCut baseline = "t_mass > 0";
if(ycut == 0) TCut baseline = "t_mass > 0 && tt_mass >450";
if(ycut == 1) TCut baseline = "t_mass > 0 && tt_mass >450 && ((ttRapidity > 2.0)||(ttRapidity < -2.0))";
if(ycut == 2) TCut baseline = "t_mass > 0 && tt_mass >450 && (ttRapidity < 2.0)&&(ttRapidity > -2.0)";
float lepChargeA ;
float lepChargeA_plus;
float lepChargeA_minus;
float lepChargeA_corr ;
float lepChargeA_quant ;
float lepChargeA_err ;
float lepChargeA_plus_gen ;
float lepChargeA_minus_gen ;
float lepChargeA_quant_gen ;
float lepChargeA_err_gen ;
calculateA( baseline, "lep_charge_asymmetry", false, lepChargeA, lepChargeA_plus, lepChargeA_minus, lepChargeA_corr, lepChargeA_quant, lepChargeA_err );
calculateA( baseline, "lep_charge_asymmetry", true, lepChargeA, lepChargeA_plus_gen, lepChargeA_minus_gen, lepChargeA_corr, lepChargeA_quant_gen, lepChargeA_err_gen );
float lepAzimA ;
float lepAzimA_plus;
float lepAzimA_minus;
float lepAzimA_corr ;
float lepAzimA_quant ;
float lepAzimA_err ;
float lepAzimA_plus_gen ;
float lepAzimA_minus_gen ;
float lepAzimA_quant_gen ;
float lepAzimA_err_gen ;
calculateA( baseline, "lep_azimuthal_asymmetry", false, lepAzimA, lepAzimA_plus, lepAzimA_minus, lepAzimA_corr, lepAzimA_quant, lepAzimA_err );
calculateA( baseline, "lep_azimuthal_asymmetry", true, lepAzimA, lepAzimA_plus_gen, lepAzimA_minus_gen, lepAzimA_corr, lepAzimA_quant_gen, lepAzimA_err_gen );
float topCosThetaA ;
float topCosThetaA_plus;
float topCosThetaA_minus;
float topCosThetaA_corr ;
float topCosThetaA_quant ;
float topCosThetaA_err ;
float topCosThetaA_plus_gen ;
float topCosThetaA_minus_gen ;
float topCosThetaA_quant_gen ;
float topCosThetaA_err_gen ;
calculateA( baseline, "top_costheta_cms", false, topCosThetaA, topCosThetaA_plus, topCosThetaA_minus, topCosThetaA_corr, topCosThetaA_quant, topCosThetaA_err );
calculateA( baseline, "top_costheta_cms", true, topCosThetaA, topCosThetaA_plus_gen, topCosThetaA_minus_gen, topCosThetaA_corr, topCosThetaA_quant_gen, topCosThetaA_err_gen );
float lepCosThetaA ;
float lepCosThetaA_plus;
float lepCosThetaA_minus;
float lepCosThetaA_corr ;
float lepCosThetaA_quant ;
float lepCosThetaA_err ;
float lepCosThetaA_plus_gen ;
float lepCosThetaA_minus_gen ;
float lepCosThetaA_quant_gen ;
float lepCosThetaA_err_gen ;
calculateA( baseline, "lep_costheta_cms", false, lepCosThetaA, lepCosThetaA_plus, lepCosThetaA_minus, lepCosThetaA_corr, lepCosThetaA_quant, lepCosThetaA_err );
calculateA( baseline, "lep_costheta_cms", true, lepCosThetaA, lepCosThetaA_plus_gen, lepCosThetaA_minus_gen, lepCosThetaA_corr, lepCosThetaA_quant_gen, lepCosThetaA_err_gen );
float topSpinCorrA ;
float topSpinCorrA_plus;
float topSpinCorrA_minus;
float topSpinCorrA_corr ;
float topSpinCorrA_quant ;
float topSpinCorrA_err ;
float topSpinCorrA_plus_gen ;
float topSpinCorrA_minus_gen ;
float topSpinCorrA_quant_gen ;
float topSpinCorrA_err_gen ;
calculateA( baseline, "top_spin_correlation", false, topSpinCorrA, topSpinCorrA_plus, topSpinCorrA_minus, topSpinCorrA_corr, topSpinCorrA_quant, topSpinCorrA_err );
calculateA( baseline, "top_spin_correlation", true, topSpinCorrA, topSpinCorrA_plus_gen, topSpinCorrA_minus_gen, topSpinCorrA_corr, topSpinCorrA_quant_gen, topSpinCorrA_err_gen );
float toprapiditydiffA ;
float toprapiditydiffA_plus;
float toprapiditydiffA_minus;
float toprapiditydiffA_corr ;
float toprapiditydiffA_quant ;
float toprapiditydiffA_err ;
float toprapiditydiffA_plus_gen ;
float toprapiditydiffA_minus_gen ;
float toprapiditydiffA_quant_gen ;
float toprapiditydiffA_err_gen ;
calculateA( baseline, "top_rapiditydiff_cms", false, toprapiditydiffA, toprapiditydiffA_plus, toprapiditydiffA_minus, toprapiditydiffA_corr, toprapiditydiffA_quant, toprapiditydiffA_err );
calculateA( baseline, "top_rapiditydiff_cms", true, toprapiditydiffA, toprapiditydiffA_plus_gen, toprapiditydiffA_minus_gen, toprapiditydiffA_corr, toprapiditydiffA_quant_gen, toprapiditydiffA_err_gen );
float pseudorapiditydiffA ;
float pseudorapiditydiffA_plus;
float pseudorapiditydiffA_minus;
float pseudorapiditydiffA_corr ;
float pseudorapiditydiffA_quant ;
float pseudorapiditydiffA_err ;
float pseudorapiditydiffA_plus_gen ;
float pseudorapiditydiffA_minus_gen ;
float pseudorapiditydiffA_quant_gen ;
float pseudorapiditydiffA_err_gen ;
calculateA( baseline, "top_pseudorapiditydiff_cms", false, pseudorapiditydiffA, pseudorapiditydiffA_plus, pseudorapiditydiffA_minus, pseudorapiditydiffA_corr, pseudorapiditydiffA_quant, pseudorapiditydiffA_err );
calculateA( baseline, "top_pseudorapiditydiff_cms", true, pseudorapiditydiffA, pseudorapiditydiffA_plus_gen, pseudorapiditydiffA_minus_gen, pseudorapiditydiffA_corr, pseudorapiditydiffA_quant_gen, pseudorapiditydiffA_err_gen );
//cout.unsetf(ios::floatfield); // floatfield not set
cout.precision(4);
//code to send cout output to file
if(ycut==-2) samplename+="presel";
if(ycut==-1) samplename+="topsol";
if(ycut==1) samplename+="ycut";
if(ycut==2) samplename+="antiycut";
ofstream file;
file.open (samplename.Data());
streambuf* sbuf = cout.rdbuf();
cout.rdbuf(file.rdbuf());
//cout << "This is sent to file" << endl;
//cout.rdbuf(sbuf);
//cout << "This is sent to prompt" << endl;
// if(!isData){
//cout << "\\begin{tabular}{l| c c c c c c}" << endl;
//cout << "\\hline" << endl;
//cout << beginL <<"Var "<< colSep << " " << colSep<< "Total Events" << colSep <<"Plus Sign" << colSep <<"Minus Sign " << colSep << "Prob of Corr Sign" << colSep << "Asym" << endL <<endl;
cout << beginL <<"Lep Charge Asy"<<colSep << " Gen " << colSep<< lepChargeA << colSep <<lepChargeA_plus_gen << colSep <<lepChargeA_minus_gen << colSep << "-" << colSep <<formatFloat(lepChargeA_quant_gen, formatS) <<pmSign << formatFloat(lepChargeA_err_gen,formatS)<< endL <<endl;
cout << beginL <<"Lep Charge Asy"<<colSep << " Reco " << colSep << lepChargeA << colSep <<lepChargeA_plus << colSep <<lepChargeA_minus << colSep <<formatFloat(lepChargeA_corr,formatS) << colSep <<formatFloat(lepChargeA_quant,formatS) <<pmSign << formatFloat(lepChargeA_err, formatS) << endL <<endl;
cout << beginL <<"Lep Azim Asy"<<colSep << " Gen " << colSep<< lepAzimA << colSep <<lepAzimA_plus_gen << colSep <<lepAzimA_minus_gen << colSep << "-" << colSep <<formatFloat(lepAzimA_quant_gen, formatS) <<pmSign << formatFloat(lepAzimA_err_gen,formatS)<< endL <<endl;
cout << beginL <<"Lep Azim Asy"<<colSep << " Reco " << colSep << lepAzimA << colSep <<lepAzimA_plus << colSep <<lepAzimA_minus << colSep <<formatFloat(lepAzimA_corr,formatS) << colSep <<formatFloat(lepAzimA_quant,formatS) <<pmSign << formatFloat(lepAzimA_err, formatS) << endL <<endl;
cout << beginL <<"Top Charge Asy"<<colSep << " Gen " << colSep<< topCosThetaA << colSep <<topCosThetaA_plus_gen << colSep <<topCosThetaA_minus_gen << colSep << "-" << colSep <<formatFloat(topCosThetaA_quant_gen, formatS) <<pmSign << formatFloat(topCosThetaA_err_gen,formatS)<< endL <<endl;
cout << beginL <<"Top Charge Asy"<<colSep << " Reco " << colSep << topCosThetaA << colSep <<topCosThetaA_plus << colSep <<topCosThetaA_minus << colSep <<formatFloat(topCosThetaA_corr,formatS) << colSep <<formatFloat(topCosThetaA_quant,formatS) <<pmSign << formatFloat(topCosThetaA_err, formatS) << endL <<endl;
cout << beginL <<"Top Polarization"<<colSep << " Gen " << colSep<< lepCosThetaA << colSep <<lepCosThetaA_plus_gen << colSep <<lepCosThetaA_minus_gen << colSep << "-" << colSep <<formatFloat(lepCosThetaA_quant_gen, formatS) <<pmSign << formatFloat(lepCosThetaA_err_gen,formatS)<< endL <<endl;
cout << beginL <<"Top Polarization"<<colSep << " Reco " << colSep << lepCosThetaA << colSep <<lepCosThetaA_plus << colSep <<lepCosThetaA_minus << colSep <<formatFloat(lepCosThetaA_corr,formatS) << colSep <<formatFloat(lepCosThetaA_quant,formatS) <<pmSign << formatFloat(lepCosThetaA_err, formatS) << endL <<endl;
cout << beginL <<"Top Spin Correlation"<<colSep << " Gen " << colSep<< topSpinCorrA << colSep <<topSpinCorrA_plus_gen << colSep <<topSpinCorrA_minus_gen << colSep << "-" << colSep <<formatFloat(topSpinCorrA_quant_gen, formatS) <<pmSign << formatFloat(topSpinCorrA_err_gen,formatS)<< endL <<endl;
cout << beginL <<"Top Spin Correlation"<<colSep << " Reco " << colSep << topSpinCorrA << colSep <<topSpinCorrA_plus << colSep <<topSpinCorrA_minus << colSep <<formatFloat(topSpinCorrA_corr,formatS) << colSep <<formatFloat(topSpinCorrA_quant,formatS) <<pmSign << formatFloat(topSpinCorrA_err, formatS) << endL <<endl;
cout << beginL <<"Top Asy I"<<colSep << " Gen " << colSep<< toprapiditydiffA << colSep <<toprapiditydiffA_plus_gen << colSep <<toprapiditydiffA_minus_gen << colSep << "-" << colSep <<formatFloat(toprapiditydiffA_quant_gen, formatS) <<pmSign << formatFloat(toprapiditydiffA_err_gen,formatS)<< endL <<endl;
cout << beginL <<"Top Asy I"<<colSep << " Reco " << colSep << toprapiditydiffA << colSep <<toprapiditydiffA_plus << colSep <<toprapiditydiffA_minus << colSep <<formatFloat(toprapiditydiffA_corr,formatS) << colSep <<formatFloat(toprapiditydiffA_quant,formatS) <<pmSign << formatFloat(toprapiditydiffA_err, formatS) << endL <<endl;
cout << beginL <<"Top Asy II"<<colSep << " Gen " << colSep<< pseudorapiditydiffA << colSep <<pseudorapiditydiffA_plus_gen << colSep <<pseudorapiditydiffA_minus_gen << colSep << "-" << colSep <<formatFloat(pseudorapiditydiffA_quant_gen, formatS) <<pmSign << formatFloat(pseudorapiditydiffA_err_gen,formatS)<< endL <<endl;
cout << beginL <<"Top Asy II"<<colSep << " Reco " << colSep << pseudorapiditydiffA << colSep <<pseudorapiditydiffA_plus << colSep <<pseudorapiditydiffA_minus << colSep <<formatFloat(pseudorapiditydiffA_corr,formatS) << colSep <<formatFloat(pseudorapiditydiffA_quant,formatS) <<pmSign << formatFloat(pseudorapiditydiffA_err, formatS) << endL <<endl;
//cout << "\\hline" << endl;
//cout << "\\end{tabular}" << endl;
// }
/*
else{
cout << "\\begin{tabular}{l| c c c c c c}" << endl;
cout << "\\hline" << endl;
cout << beginL <<"Var "<< colSep<< "Total Events" << colSep <<"Plus Sign" << colSep <<"Minus Sign " << colSep << "Asym" << endL <<endl;
cout << beginL <<"Lep Charge Asy" << colSep << lepChargeA << colSep <<lepChargeA_plus << colSep <<lepChargeA_minus << colSep <<formatFloat(lepChargeA_quant,formatS) <<pmSign << formatFloat(lepChargeA_err, formatS) << endL <<endl;
cout << beginL <<"Lep Azim Asy" << colSep << lepAzimA << colSep <<lepAzimA_plus << colSep <<lepAzimA_minus << colSep <<formatFloat(lepAzimA_quant,formatS) <<pmSign << formatFloat(lepAzimA_err, formatS) << endL <<endl;
cout << beginL <<"Top AFB" << colSep << topCosThetaA << colSep <<topCosThetaA_plus << colSep <<topCosThetaA_minus << colSep <<formatFloat(topCosThetaA_quant,formatS) <<pmSign << formatFloat(topCosThetaA_err, formatS) << endL <<endl;
cout << beginL <<"Top Polorization" << colSep << lepCosThetaA << colSep <<lepCosThetaA_plus << colSep <<lepCosThetaA_minus << colSep <<formatFloat(lepCosThetaA_quant,formatS) <<pmSign << formatFloat(lepCosThetaA_err, formatS) << endL <<endl;
cout << beginL <<"Top Spin Correlation" << colSep << topSpinCorrA << colSep <<topSpinCorrA_plus << colSep <<topSpinCorrA_minus << colSep <<formatFloat(topSpinCorrA_quant,formatS) <<pmSign << formatFloat(topSpinCorrA_err, formatS) << endL <<endl;
cout << "\\hline" << endl;
cout << "\\end{tabular}" << endl;
}
*/
//delete ch;
}