-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutput.cc
184 lines (154 loc) · 6.63 KB
/
Output.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
#include <iostream>
#include <sys/stat.h>
#include "Output.h"
Output::Output() {
}
void Output::addPlot(TCanvas* can, const TString &var, const TString &dataSetLabel, const TString &selection) {
TString dsLabel = cleanName(dataSetLabel);
TString plotName = cleanName(GlobalParameters::analysisId()+"__"+var+"__"+dsLabel+"__"+selection);
std::map< TString, std::map< TString, std::vector<TString> > >::iterator itVar = plotsSingleSpectrum_.find(var);
if( itVar != plotsSingleSpectrum_.end() ) {
std::map< TString, std::vector<TString> >::iterator itDS = itVar->second.find(dsLabel);
if( itDS != itVar->second.end() ) {
itDS->second.push_back(plotName);
} else {
std::vector<TString> v;
v.push_back(plotName);
itVar->second[dsLabel] = v;
}
} else {
std::vector<TString> v;
v.push_back(plotName);
std::map< TString, std::vector<TString> > m;
m[dsLabel] = v;
plotsSingleSpectrum_[var] = m;
}
storeCanvas(can,selection,plotName);
}
void Output::addPlot(TCanvas* can, const TString &var, const std::vector<TString> &dataSetLabels, const TString &plotType, const TString &selection) {
TString label = dataSetLabels.front();
for(std::vector<TString>::const_iterator it = dataSetLabels.begin()+1;
it != dataSetLabels.end(); ++it) {
label += "+"+*it;
}
TString dsLabel = cleanName(label);
TString plotName = cleanName(GlobalParameters::analysisId()+"__"+var+"__"+dsLabel+"-"+plotType+"__"+selection);
std::map< TString, std::map< TString, std::vector<TString> > >::iterator itVar = plotsStack_.find(var);
if( itVar != plotsStack_.end() ) {
std::map< TString, std::vector<TString> >::iterator itDS = itVar->second.find(dsLabel);
if( itDS != itVar->second.end() ) {
itDS->second.push_back(plotName);
} else {
std::vector<TString> v;
v.push_back(plotName);
itVar->second[dsLabel] = v;
}
} else {
std::vector<TString> v;
v.push_back(plotName);
std::map< TString, std::vector<TString> > m;
m[dsLabel] = v;
plotsStack_[var] = m;
}
storeCanvas(can,selection,plotName);
}
void Output::addPlot(TCanvas* can, const TString &var, const std::vector<TString> &dataSetLabels1, const std::vector<TString> &dataSetLabels2, const TString &selection) {
TString label1 = dataSetLabels1.front();
for(std::vector<TString>::const_iterator it = dataSetLabels1.begin()+1;
it != dataSetLabels1.end(); ++it) {
label1 += "+"+*it;
}
TString label2 = dataSetLabels2.front();
for(std::vector<TString>::const_iterator it = dataSetLabels2.begin()+1;
it != dataSetLabels2.end(); ++it) {
label2 += "+"+*it;
}
TString dsLabel = cleanName(label1+"_vs_"+label2);
TString plotName = cleanName(GlobalParameters::analysisId()+"__"+var+"__"+dsLabel+"__"+selection);
std::map< TString, std::map< TString, std::vector<TString> > >::iterator itVar = plotsStack_.find(var);
if( itVar != plotsStack_.end() ) {
std::map< TString, std::vector<TString> >::iterator itDS = itVar->second.find(dsLabel);
if( itDS != itVar->second.end() ) {
itDS->second.push_back(plotName);
} else {
std::vector<TString> v;
v.push_back(plotName);
itVar->second[dsLabel] = v;
}
} else {
std::vector<TString> v;
v.push_back(plotName);
std::map< TString, std::vector<TString> > m;
m[dsLabel] = v;
plotsStack_[var] = m;
}
storeCanvas(can,selection,plotName);
}
void Output::storeCanvas(TCanvas* can, const TString &selection, const TString &plotName) {
can->SetName(plotName);
can->SetTitle(plotName);
if( GlobalParameters::outputEPS() ) can->SaveAs(resultDir()+"/"+dir(selection)+"/"+plotName+".eps","eps");
if( GlobalParameters::outputPDF() ) can->SaveAs(resultDir()+"/"+dir(selection)+"/"+plotName+".pdf");
if( GlobalParameters::outputPNG() ) can->SaveAs(resultDir()+"/"+dir(selection)+"/"+plotName+".png");
}
void Output::createLaTeXSlide() const {
// std::cout << "\n\nSingle Spectrum" << std::endl;
// for(std::map< TString, std::map< TString, std::vector<TString> > >::const_iterator itVar = plotsSingleSpectrum_.begin(); itVar != plotsSingleSpectrum_.end(); ++itVar) {
// std::cout << " Variable " << itVar->first << std::endl;
// for(std::map< TString, std::vector<TString> >::const_iterator itDS = itVar->second.begin(); itDS != itVar->second.end(); ++itDS) {
// std::cout << " Dataset " << itDS->first << std::endl;
// for(std::vector<TString>::const_iterator itFN = itDS->second.begin(); itFN != itDS->second.end(); ++itFN) {
// std::cout << " " << *itFN << std::endl;
// }
// }
// }
// std::cout << "\n\nStacks" << std::endl;
// for(std::map< TString, std::map< TString, std::vector<TString> > >::const_iterator itVar = plotsStack_.begin(); itVar != plotsStack_.end(); ++itVar) {
// std::cout << " Variable " << itVar->first << std::endl;
// for(std::map< TString, std::vector<TString> >::const_iterator itDS = itVar->second.begin(); itDS != itVar->second.end(); ++itDS) {
// std::cout << " Dataset " << itDS->first << std::endl;
// for(std::vector<TString>::const_iterator itFN = itDS->second.begin(); itFN != itDS->second.end(); ++itFN) {
// std::cout << " " << *itFN << std::endl;
// }
// }
// }
// std::cout << "\n\nNormalised Spectra" << std::endl;
// for(std::map< TString, std::vector<TString> >::const_iterator itVar = plotsNormedSpectra_.begin(); itVar != plotsNormedSpectra_.end(); ++itVar) {
// std::cout << " Variable " << itVar->first << std::endl;
// for(std::vector<TString>::const_iterator itFN = itVar->second.begin(); itFN != itVar->second.end(); ++itFN) {
// std::cout << " " << *itFN << std::endl;
// }
// }
}
TString Output::dir(const TString &selection) {
std::map< TString, TString >::const_iterator it = dirs_.find(selection);
if( it != dirs_.end() ) {
return it->second;
} else {
TString dirName = cleanName(selection);
TString path = resultDir()+"/"+dirName;
mkdir(path.Data(),S_IRWXU);
dirs_[selection] = dirName;
return dirName;
}
}
TString Output::cleanName(const TString &name) {
TString cleanedName = name;
cleanedName.ReplaceAll(">","gtr");
cleanedName.ReplaceAll("<","lss");
cleanedName.ReplaceAll(" ","_");
cleanedName.ReplaceAll(":","-");
cleanedName.ReplaceAll("_{","");
cleanedName.ReplaceAll("#","");
cleanedName.ReplaceAll("{","");
cleanedName.ReplaceAll("}","");
cleanedName.ReplaceAll("[","");
cleanedName.ReplaceAll("]","");
return cleanedName;
}
TString Output::cleanLatexName(const TString &name) {
TString cleanedName = name;
cleanedName.ReplaceAll("_","\\_");
cleanedName.ReplaceAll("#","\\");
return cleanedName;
}