-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEP1Analysis.C
226 lines (209 loc) · 8.09 KB
/
LEP1Analysis.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
#if !defined(__CINT__) || defined(__MAKECINT__)
#include "Analysis.hh"
#include "Observable.hh"
#include "FilledObservable.hh"
#include "ObservableFactory.hh"
#include "Unfolder.hh"
#include "OutputWriter.hh"
#include "NtupleReader.hh"
#include <sstream>
using std::ostringstream;
#include <iostream>
using std::cout;
using std::endl;
#include <vector>
using std::vector;
#include <string>
using std::string;
#include <stdexcept>
using std::logic_error;
#endif
void processAnalyses( const vector<Analysis>& analyses,
const vector<Observable*>& vobs,
const string& filename,
Int_t maxevt ) {
cout << "processAnalyses: file " << filename << ", analyses:" << endl;
for( size_t i= 0; i < analyses.size(); i++ ) {
cout << analyses[i].getTag() << endl;
}
NtupleReader* ntr= new NtupleReader( filename.c_str() );
Int_t nevnt= ntr->GetNumberEntries();
for( Int_t ievnt= 0; ievnt < TMath::Min( nevnt, maxevt ); ievnt++ ) {
if( ntr->GetEvent( ievnt ) == 0 ) {
ostringstream txt;
txt << "processAnalyses: event not found: " << ievnt;
throw logic_error( txt.str() );
}
map<string,Bool_t> selections= ntr->LEP1Selections();
bool MCnonrad= ntr->MCNonRad();
for( size_t ianal= 0; ianal < analyses.size(); ianal++ ) {
Analysis analysis= analyses[ianal];
string cuts= analysis.getCuts();
string mccuts= analysis.getMccuts();
if( ( cuts == "none" or selections[cuts] ) and
( mccuts == "none" or MCnonrad ) ) {
for( size_t iobs= 0; iobs < vobs.size(); iobs++ ) {
Observable* obs= vobs[iobs];
// Not all observables have all analysis variants
// due to filling of transfer matrices:
if( obs->containsAnalysis( analysis ) ) {
try {
obs->fill( ntr, analysis );
}
catch( const std::out_of_range& oor ) {
cout << oor.what() << " " << obs->getName() << " "
<< analysis.getTag() << endl;
}
}
}
}
}
}
delete ntr;
return;
}
void processUnfolding( const vector<Analysis>& measuredAnalyses,
string unfoldsource,
const vector<FilledObservable*>& vobs ) {
cout << "processUnfolding: bin-by-bin unfolding for analyses:" << endl;
Analysis hadronlevel( unfoldsource, "hadron", "none", "nonrad" );
cout << "Hadron level: " << hadronlevel.getTag() << endl;
for( size_t ianal= 0; ianal < measuredAnalyses.size(); ianal++ ) {
Analysis measured= measuredAnalyses[ianal];
Analysis measuredMC( measured );
measuredMC.setSource( unfoldsource );
cout << measured.getTag() << ", " << measuredMC.getTag() << endl;
Unfolder unfolder( measured, measuredMC, hadronlevel );
for( size_t iobs= 0; iobs < vobs.size(); iobs++ ) {
unfolder.unfold( vobs[iobs] );
}
}
return;
}
vector<FilledObservable*> getFilled( const vector<Observable*>& vobs ) {
vector<FilledObservable*> vfobs;
for( size_t iobs= 0; iobs < vobs.size(); iobs++ ) {
vector<FilledObservable*> vfobspart= vobs[iobs]->getFilledObservables();
vfobs.insert( vfobs.end(), vfobspart.begin(), vfobspart.end() );
}
return vfobs;
}
void LEP1Analysis( Int_t maxevt=1000,
const char* datafilename="da91_96_200.root",
const char* pyfilename="mc5025_1_200.root",
const char* hwfilename="mc12406_1_200.root" ) {
// Load libs in root before loading this macro
// gROOT->LoadMacro("libNtupleReaderDict.so");
// gROOT->ProcessLine(".include /home/skluth/qcd/fastjet/fastjet-3.0.6/install/include")
// to allow ACLIC
// Define analysis variations:
vector<Analysis> measuredAnalyses;
measuredAnalyses.push_back( Analysis( "data", "mt", "stand" ) );
measuredAnalyses.push_back( Analysis( "data", "mt", "costt07" ) );
measuredAnalyses.push_back( Analysis( "data", "mt", "nch7" ) );
measuredAnalyses.push_back( Analysis( "data", "tc", "stand" ) );
vector<Analysis> pyAnalyses;
pyAnalyses.push_back( Analysis( "py", "mt", "stand" ) );
pyAnalyses.push_back( Analysis( "py", "mt", "costt07" ) );
pyAnalyses.push_back( Analysis( "py", "mt", "nch7" ) );
pyAnalyses.push_back( Analysis( "py", "tc", "stand" ) );
pyAnalyses.push_back( Analysis( "py", "hadron", "none", "nonrad" ) );
vector<Analysis> hwAnalyses;
hwAnalyses.push_back( Analysis( "hw", "mt", "stand" ) );
hwAnalyses.push_back( Analysis( "hw", "hadron", "none", "nonrad" ) );
vector<Analysis> allAnalyses( measuredAnalyses );
allAnalyses.insert( allAnalyses.end(), pyAnalyses.begin(), pyAnalyses.end() );
allAnalyses.insert( allAnalyses.end(), hwAnalyses.begin(), hwAnalyses.end() );
// Define observables:
vector<string> obsnames;
obsnames.push_back( "thrust" );
obsnames.push_back( "partonshower" );
obsnames.push_back( "durhamymerge23" );
obsnames.push_back( "jadeymerge23" );
obsnames.push_back( "durhamymergefj" );
obsnames.push_back( "jadeymergefj" );
obsnames.push_back( "durhamycutfj" );
obsnames.push_back( "jadeycutfj" );
obsnames.push_back( "durhamycut" );
obsnames.push_back( "jadeycut" );
obsnames.push_back( "antiktemin" );
obsnames.push_back( "antiktR" );
obsnames.push_back( "sisconeemin" );
obsnames.push_back( "sisconeR" );
obsnames.push_back( "pxconeemin" );
obsnames.push_back( "pxconeR" );
ObservableFactory obsfac;
vector<Observable*> vobs;
try {
vobs= obsfac.createObservables( obsnames, allAnalyses );
}
catch( const std::exception& e ) {
cout << "Cought exception: " << e.what() << endl;
return;
}
// Add extras for migration matrices where needed:
vector<Analysis> pyMatrixExtras;
pyMatrixExtras.push_back( Analysis( "py", "hadron", "stand", "nonrad" ) );
pyMatrixExtras.push_back( Analysis( "py", "mt", "stand", "nonrad", "hadron" ) );
pyAnalyses.insert( pyAnalyses.end(), pyMatrixExtras.begin(), pyMatrixExtras.end() );
vector<Analysis> hwMatrixExtras;
hwMatrixExtras.push_back( Analysis( "hw", "hadron", "stand", "nonrad" ) );
hwMatrixExtras.push_back( Analysis( "hw", "mt", "stand", "nonrad", "hadron" ) );
hwAnalyses.insert( hwAnalyses.end(), hwMatrixExtras.begin(), hwMatrixExtras.end() );
for( size_t iobs= 0; iobs < vobs.size(); iobs++ ) {
Observable* obs= vobs[iobs];
if( obs->getName() == "thrust" or
obs->getName() == "durhamymerge23" or
obs->getName() == "jadeymerge23" or
obs->getName() == "partonshower" ) {
obs->addAnalyses( pyMatrixExtras );
obs->addAnalyses( hwMatrixExtras );
}
}
// Fill from data and mc (PYTHIA and HERWIG) ntuples:
try {
processAnalyses( measuredAnalyses, vobs, datafilename, maxevt );
processAnalyses( pyAnalyses, vobs, pyfilename, maxevt );
processAnalyses( hwAnalyses, vobs, hwfilename, maxevt );
}
catch( const std::exception& e ) {
cout << "Cought exception: " << e.what() << endl;
return;
}
// Get FilledObservables for further processing:
vector<FilledObservable*> vfobs= getFilled( vobs );
// Unfolding bin-by-bin:
try {
// PYHTHIA based:
processUnfolding( measuredAnalyses, "py", vfobs );
// HERWIG based for systematic:
vector<Analysis> measuredAnalysesHw;
measuredAnalysesHw.push_back( Analysis( "data", "mt", "stand" ) );
processUnfolding( measuredAnalysesHw, "hw", vfobs );
// MC detector level with MC as cross check for PYTHIA and HERWIG:
vector<Analysis> measuredPyAnalyses;
measuredPyAnalyses.push_back( Analysis( "py", "mt", "stand" ) );
measuredPyAnalyses.push_back( Analysis( "py", "mt", "costt07" ) );
measuredPyAnalyses.push_back( Analysis( "py", "mt", "nch7" ) );
measuredPyAnalyses.push_back( Analysis( "py", "tc", "stand" ) );
processUnfolding( measuredPyAnalyses, "py", vfobs );
vector<Analysis> measuredHwAnalyses;
measuredHwAnalyses.push_back( Analysis( "hw", "mt", "stand" ) );
processUnfolding( measuredHwAnalyses, "hw", vfobs );
}
catch( const std::exception& e ) {
cout << "Cought exception: " << e.what() << endl;
return;
}
// Normalise and calculate stat errors, print
// Normalisation only during postprocessing
for( size_t i= 0; i < vfobs.size(); i++ ) {
// vfobs[i]->finalise();
vfobs[i]->print();
}
// Write root objects (TH1D or TGraphErrors, and TH2D):
OutputWriter writer( "LEP1Analysis.root" );
writer.write( vfobs );
// The End:
return;
}