NAGASH 0.9.8
Next Generation Analysis System
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
SystTool.cxx
Go to the documentation of this file.
1#include "NAGASH/SystTool.h"
2
3using namespace std;
4using namespace NAGASH;
5
86{
87 if (!isSetVar)
88 {
89 MSGUser()->StartTitle("SystTool::CurrentVariation");
90 MSGUser()->MSG(MSGLevel::DEBUG, "No variation is set, will set to nominal");
91 MSGUser()->EndTitle();
92
93 SetToVariation("Nominal");
94 currentvar = "Nominal";
95 }
96 return currentvar;
97}
98
102void SystTool::SetVariationCorrelation(const TString &name, double correlation)
103{
104 auto findresult = CorrMap.find(name);
105 if (findresult != CorrMap.end())
106 {
107 findresult->second = correlation;
108 }
109 else
110 {
111 MSGUser()->StartTitle("SystTool::SetVariationCorrelation");
112 MSGUser()->MSG(MSGLevel::WARNING, "no variation named ", name, ", this call will be ignored");
113 MSGUser()->EndTitle();
114 }
115}
116
119double SystTool::GetVariationCorrelation(const TString &name)
120{
121 auto findresult = CorrMap.find(name);
122 if (findresult != CorrMap.end())
123 {
124 return findresult->second;
125 }
126 else
127 {
128 MSGUser()->StartTitle("SystTool::GetVariationCorrelation");
129 MSGUser()->MSG(MSGLevel::WARNING, "no variation named ", name, ", returning zero");
130 MSGUser()->EndTitle();
131 return 0;
132 }
133}
134
136const std::vector<TString> &SystTool::GetListOfVariations()
137{
139 {
140 return SystList;
141 }
142 else
143 {
144 SystList.clear();
145 for (auto &t : CorrMap)
146 {
147 SystList.emplace_back(t.first);
148 // move Nominal to the front
149 if (t.first == "Nominal")
150 std::swap(SystList[0], SystList.back());
151 }
152
153 isSystListSorted = true;
154 return SystList;
155 }
156}
157
160std::vector<TString> SystTool::GetListOfVariations(const TString &name)
161{
162 auto findresult = SystListMap.find(name);
163 if (findresult != SystListMap.end())
164 {
165 return SystListMap.find(name)->second;
166 }
167 else
168 {
169 MSGUser()->StartTitle("SystTool::GetListOfVariations");
170 MSGUser()->MSG(MSGLevel::WARNING, "Variable ", name, " does not exist, return NULL vector");
171 MSGUser()->EndTitle();
172 return std::vector<TString>();
173 }
174}
175
178void SystTool::SetToVariation(const TString &name)
179{
180 if (isSetVar)
181 {
182 // if SystMapFull has been made
183 auto findresult = SystMapFull.find(name);
184 if (findresult != SystMapFull.end())
185 {
186 for (auto &var : findresult->second)
187 {
188 *(var.Current) = *(var.Variation);
189 }
190 currentvar = name;
191 }
192 else
193 {
194 MSGUser()->StartTitle("SystTool::SetVariation");
195 MSGUser()->MSG(MSGLevel::WARNING, "Variation ", name, " does not exist, no variation will be set");
196 MSGUser()->EndTitle();
197 return;
198 }
199 }
200 else
201 {
202 // make SystMapFull
203 SystMapFull.clear();
204 for (auto &systname : SystList)
205 {
206 std::vector<AuxVar> tempvec;
207 for (auto &t : VarMapFull)
208 {
209 AuxVar tempvar;
210 tempvar.Current = &(t.second.CurrentVar);
211 auto findresult = t.second.VarMap.find(systname);
212 if (findresult != t.second.VarMap.end())
213 {
214 tempvar.Variation = &(findresult->second);
215 }
216 else if (t.second.NominalVar.has_value())
217 {
218 tempvar.Variation = &(t.second.NominalVar);
219 }
220 else
221 {
222 MSGUser()->StartTitle("SystTool::SetVariation");
223 MSGUser()->MSG(MSGLevel::WARNING, "Variable ", t.first, " has not Nominal variation, will set to the first variation ", t.second.VarMap.begin()->first);
224 MSGUser()->EndTitle();
225 tempvar.Variation = &(t.second.VarMap.begin()->second);
226 }
227 tempvec.push_back(tempvar);
228 }
229 SystMapFull.insert(pair<TString, std::vector<AuxVar>>(systname, tempvec));
230 }
231 isSetVar = true;
232 SetToVariation(name);
233 }
234}
235
238{
239 return SystList.size();
240}
241
244int SystTool::GetNVariations(const TString &name)
245{
246 auto findresult = VarMapFull.find(name);
247 if (findresult != VarMapFull.end())
248 {
249 return findresult->second.VarMap.size();
250 }
251 else
252 {
253 MSGUser()->StartTitle("SystTool::SetVariation");
254 MSGUser()->MSG(MSGLevel::WARNING, "Variable ", name, " does not exist, returnint zero");
255 MSGUser()->EndTitle();
256 return 0;
257 }
258}
std::map< TString, std::vector< TString > > SystListMap
Definition SystTool.h:50
double GetVariationCorrelation(const TString &name)
Get the correlation factor of the given systematic variation.
Definition SystTool.cxx:119
void SetVariationCorrelation(const TString &name, double correlation)
Set the correlation factor of the given systematic variation.
Definition SystTool.cxx:102
const std::vector< TString > & GetListOfVariations()
get the list of all systematic variations.
Definition SystTool.cxx:136
TString currentvar
Definition SystTool.h:46
std::vector< TString > SystList
Definition SystTool.h:51
int GetNVariations()
get the number of systematic variations.
Definition SystTool.cxx:237
std::map< TString, std::vector< AuxVar > > SystMapFull
Definition SystTool.h:48
bool isSystListSorted
Definition SystTool.h:45
const TString & CurrentVariation()
Get the name of the current systematic variation.
Definition SystTool.cxx:85
std::map< TString, double > CorrMap
Definition SystTool.h:49
void SetToVariation(const TString &name)
set the current variation to the given one.
Definition SystTool.cxx:178
std::map< TString, VarWithSyst > VarMapFull
Definition SystTool.h:47
std::shared_ptr< MSGTool > MSGUser()
return the MSGTool inside.
Definition Tool.h:91