-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrRA2.cc
171 lines (147 loc) · 7.56 KB
/
MrRA2.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
// $Id: MrRA2.cc,v 1.17 2013/05/21 16:35:25 mschrode Exp $
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include "DataSet.h"
#include "EventInfoPrinter.h"
#include "GlobalParameters.h"
#include "MrRA2.h"
#include "EventYieldPrinter.h"
#include "Output.h"
#include "PlotBuilder.h"
#include "Selection.h"
#include "Style.h"
#include "Variable.h"
int main(int argc, char *argv[]) {
if( argc > 1 ) {
MrRA2* mr = new MrRA2(argv[1]);
delete mr;
} else {
std::cerr << "\n\n ERROR: Missing configuration file" << std::endl;
std::cerr << " Usage './run config-file-name\n" << std::endl;
}
return 0;
}
MrRA2::MrRA2(const TString& configFileName) {
std::cout << "\n +------------------------------------------------+" << std::endl;
std::cout << " | |" << std::endl;
std::cout << " | MrRA2 - the Really Awesome plotting 2l |" << std::endl;
std::cout << " | |" << std::endl;
std::cout << " +------------------------------------------------+\n" << std::endl;
if( GlobalParameters::cvsTag() == "" ) {
std::cout << "Developer's version" << std::endl;
} else {
std::cout << "Version " << GlobalParameters::cvsTag() << std::endl;
}
std::cout << "\n" << std::endl;
// Initialization
std::cout << "Initializing MrRA2" << std::endl;
Config cfg(configFileName);
checkForLatestSyntax(cfg);
GlobalParameters::init(cfg,"global");
Style::init(cfg,"style");
Variable::init(cfg,"variable");
Selection::init(cfg,"selection");
DataSet::init(cfg,"dataset");
std::cout << "\n\n\n";
// Print setup info
std::cout << "The following datasets are defined:" << std::endl;
DataSets inputDataSets = DataSet::findAllUnselected();
for(DataSetIt itd = inputDataSets.begin(); itd != inputDataSets.end(); ++itd) {
std::cout << " " << (*itd)->label() << " (type '" << DataSet::toString((*itd)->type()) << "'): " << (*itd)->size() << " entries" << std::endl;
}
std::cout << "\nThe following selections are defined:" << std::endl;
for(SelectionIt its = Selection::begin(); its != Selection::end(); ++its) {
if( (*its)->uid() != "unselected" ) (*its)->print();
}
std::cout << "\n";
// Print simple cut flow
std::cout << "The following number of events (entries) are selected:" << std::endl;
for(DataSetIt itd = inputDataSets.begin(); itd != inputDataSets.end(); ++itd) {
std::cout << " " << std::setw(Selection::maxLabelLength()) << (*itd)->label() << " (" << DataSet::toString((*itd)->type()) << ") : " << std::setw(15) << (*itd)->yield() << " (" << (*itd)->size() << ")" << std::endl;
DataSets selectedDataSets = DataSet::findAllWithLabel((*itd)->label());
for(DataSetIt itsd = selectedDataSets.begin(); itsd != selectedDataSets.end(); ++itsd) {
std::cout << " " << std::setw(Selection::maxLabelLength()) << (*itsd)->selectionUid() << " : " << std::setw(15) << (*itsd)->yield() << " (" << (*itsd)->size() << ")" << std::endl;
}
}
// Control the output
Output out;
// Control plots without selection
std::cout << "\n\n\nProcessing the output" << std::endl;
PlotBuilder(cfg,out);
EventInfoPrinter evtInfoPrinter(cfg);
EventYieldPrinter evtYieldPrinter;
std::cout << "Done.\nThank you for using MrRA2! Want to donate money? Contact M. Schroeder." << std::endl;
}
MrRA2::~MrRA2() {
DataSet::clear();
Selection::clear();
}
void MrRA2::checkForLatestSyntax(const Config &cfg) const {
// 2013.05.09: New syntax for plots
std::vector<Config::Attributes> attrList = cfg("plot");
for(std::vector<Config::Attributes>::const_iterator it = attrList.begin();
it != attrList.end(); ++it) {
if( it->hasName("datasets") || ( it->hasName("dataset1") && it->hasName("dataset2") ) ) {
std::cerr << "\n\n\nDear user (Hallo Arne...)!\n" << std::endl;
std::cerr << "With the current version of MrRA2, the config-syntax has been changed" << std::endl;
std::cerr << "towards greater readability and more convenience! The old syntax you" << std::endl;
std::cerr << "are using in your config-file is not supported anymore. Please change" << std::endl;
std::cerr << "it as follows:\n" << std::endl;
std::cerr << "1) 'Data vs Bkg' plots" << std::endl;
std::cerr << " old syntax: 'plot :: variable: <var>; dataset1: <name[+name+...]>; dataset2: <name[+name+...]>; [signal: <name[,name,...]>;] histogram:...' " << std::endl;
std::cerr << " new syntax: 'plot :: variable: <var>; data: <name>; background: <name[+name+...]>; [signal: <name[,name,...]>;] histogram:...' " << std::endl;
std::cerr << " -^- -^- -^-" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "2) 'Comparison of spectra' plots" << std::endl;
std::cerr << " old syntax: 'plot :: variable: <var>; datasets: <name[,name,...]>; histogram:...' " << std::endl;
std::cerr << " new syntax: 'plot :: variable: <var>; dataset: <name[,name,...]>; histogram:...' " << std::endl;
std::cerr << " -^-" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "You can find an example config file in config/example.txt" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "To repair your config file, you can probably (no guarantee!!) simply type:" << std::endl;
std::cerr << "> sed -i 's/dataset1/data/g' <config-file>" << std::endl;
std::cerr << "> sed -i 's/dataset2/background/g' <config-file>" << std::endl;
std::cerr << "> sed -i 's/datasets/dataset/g' <config-file>" << std::endl;
std::cerr << "\n\n" << std::endl;
exit(-1);
}
}
// 2013.05.20: New syntax for variables
attrList = cfg("event content");
if( !attrList.empty() ) {
std::cerr << "With the current version of MrRA2, the config-syntax has been changed." << std::endl;
std::cerr << "The old syntax you are using is not supported anymore. Please apply the" << std::endl;
std::cerr << "following changes:" << std::endl;
std::cerr << "\n 'event content' --> 'variable'" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "You can find an example config file in config/example.txt" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "To repair your config file, you can probably (no guarantee!!) simply type:" << std::endl;
std::cerr << "> sed -i 's/event content/variable/g' <config-file>" << std::endl;
std::cerr << "\n\n" << std::endl;
exit(-1);
}
// 2013.05.20: New syntax for file names
attrList = cfg("dataset");
for(std::vector<Config::Attributes>::const_iterator it = attrList.begin();
it != attrList.end(); ++it) {
if( it->hasName("file") ) {
std::cerr << "With the current version of MrRA2, the config-syntax has been changed." << std::endl;
std::cerr << "The old syntax you are using is not supported anymore. Please apply the" << std::endl;
std::cerr << "following changes:" << std::endl;
std::cerr << "\n in the 'dataset' section: 'file' --> 'files'" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "You can find an example config file in config/example.txt" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "" << std::endl;
std::cerr << "To repair your config file, you can probably (no guarantee!!) simply type:" << std::endl;
std::cerr << "> sed -i '/dataset/ s=file=files=' <config-file>" << std::endl;
std::cerr << "\n\n" << std::endl;
exit(-1);
}
}
}