11 #include <nlohmann/json.hpp>
18 m_CDIFile->GetObject(
"VersionInfo/BuildNumber",
s);
20 std::cout <<
" CDI file build number: " <<
s->GetName() << std::endl;
22 TList* taggerkeys =
m_CDIFile->GetListOfKeys();
23 for (
const auto tagger : *taggerkeys){
24 const char* taggername = tagger->GetName();
25 if(strcmp(taggername,
"VersionInfo") != 0){
27 TDirectoryFile* taggerDir = (TDirectoryFile*)
m_CDIFile->Get(taggername);
36 TList*
keys = parentDir->GetListOfKeys();
37 if(isWPdirectory(
keys)){
41 TList* labelkeys = parentDir->GetListOfKeys();
44 std::set<std::string> DSID_set;
45 std::set<std::string> systematics_set;
48 std::string taggername =
path.at(0);
49 std::string jetcollname =
path.at(1);
50 std::string workingpointname =
path.at(2);
55 for(
const auto label : *labelkeys){
56 std::string labelname =
label->GetName();
57 if(labelname ==
"cutvalue" || labelname.find(
"fraction") != std::string::npos)
continue;
58 m_labels.insert(labelname);
59 theseLabels.push_back(labelname);
62 TDirectoryFile*
flavourDir = (TDirectoryFile*)parentDir->Get(labelname.c_str());
66 for(
const auto CDHistCont : *DSIDkeys){
67 std::string DSIDname = CDHistCont->GetName();
68 DSID_set.insert(DSIDname);
69 m_DSIDs.insert(DSIDname);
70 if(DSIDname ==
"default_SF"){
72 std::string
dir = taggername +
"/" + jetcollname +
"/" + workingpointname +
"/" + labelname +
"/default_SF";
74 m_CDIFile->GetObject(
dir.c_str(), cont);
76 std::cout <<
"No default_SF CalibrationDataHistogramContainer?" << std::endl;
79 for(std::string
s : uncertainties){
80 systematics_set.insert(
s);
84 std::string flav_spec_unc_name = labelname +
"_syst";
85 theseData[flav_spec_unc_name] = uncertainties;
89 std::cout <<
"No flavour directory?" << std::endl;
93 std::sort(theseLabels.begin(), theseLabels.end());
94 theseData[
"labels"] = theseLabels;
96 Labels theseDSIDs(DSID_set.size());
97 std::copy(DSID_set.begin(), DSID_set.end(), theseDSIDs.begin());
98 theseData[
"DSIDs"] = theseDSIDs;
100 Labels theseSystematics(systematics_set.size());
101 std::copy(systematics_set.begin(), systematics_set.end(), theseSystematics.begin());
102 theseData[
"systematics"] = theseSystematics;
105 record_metadata_map(theseData, metamap);
107 for(
const auto coll: *
keys){
108 std::string collname = coll->GetName();
110 record_metadata(collname,
depth+1);
111 TDirectoryFile* collDir = (TDirectoryFile*)parentDir->Get(collname.c_str());
112 if(collDir && collname !=
"VersionInfo"){
113 std::string nextmap = metamap +
";" + collname;
114 crawlCDI(collDir,
depth+1, nextmap);
116 std::cout <<
"No collection directory?" << std::endl;
144 int current_tagger = (tagger < 0) ? -1 : 0;
145 int current_jetcoll = (
jetcoll < 0) ? -1 : 0;
146 int current_wpoint = (wpoint < 0) ? -1 : 0;
147 int current_label = (
label < 0) ? -1 : 0;
149 for (
const auto& [
tag,
jets] : m_metadata){
150 if(current_tagger != -1) current_tagger += 1;
151 if(tagger != current_tagger || tagger == 0)
continue;
153 std::cout <<
"| " <<
tag << std::endl;
155 for (
const auto& [
jet, wps] :
jets){
156 if(current_jetcoll != -1) current_jetcoll += 1;
159 std::cout <<
"|\\__ " <<
jet << std::endl;
161 int num_wps = wps.size();
163 for(
const auto& [
wp,
labels] : wps){
164 if(current_wpoint != -1) current_wpoint += 1;
165 if(wpoint != current_wpoint || wpoint == 0)
continue;
167 if(num_wp_seen != num_wps){
168 std::cout <<
"| |\\__" <<
wp << std::endl;
170 std::cout <<
"| \\__" <<
wp << std::endl;
175 for(
const std::string&
l :
d[
"labels"]){
176 if(current_label != -1) current_label += 1;
177 if(
label != current_label ||
label == 0)
continue;
178 if(num_wp_seen != num_wps && label_index == 0){
179 std::cout <<
"| | \\___" <<
" (" << label_index <<
") " <<
l << std::endl;
180 }
else if(label_index != 0 && num_wp_seen != num_wps) {
181 std::cout <<
"| | \\___" <<
" (" << label_index <<
") " <<
l << std::endl;
183 std::cout <<
"| \\___" <<
" (" << label_index <<
") " <<
l << std::endl;
196 bool configured =
false;
204 if(m_metadata.count(tagger) > 0){
206 for(
const auto&
tag : m_metadata){
208 if(
tag.first == tagger)
break;
212 for(
const auto&
jet : m_metadata[tagger]){
218 for(
const auto& wpoint : m_metadata[tagger][
jetcoll]){
220 if(wpoint.first ==
wp)
break;
222 if (
verbose) std::cout <<
" Your configuration looks good! Available labels are : " << std::endl;
223 if (
verbose) printMetadata(tagger_ind, jetcoll_ind, wp_ind, -1);
225 for(std::string flavour_label : m_metadata[tagger][
jetcoll][
wp][
"labels"]){
226 m_label_vec.push_back(flavour_label);
229 std::sort(m_label_vec.begin(), m_label_vec.end());
232 if (
verbose) std::cout <<
"Couldn't find \"" <<
wp <<
"\" for " << tagger <<
" / " <<
jetcoll <<
" in this CDI file!" << std::endl;
233 if (
verbose) std::cout <<
"Here are your options :" << std::endl;
234 if (
verbose) printMetadata(tagger_ind, jetcoll_ind, -1, 0);
237 if (
verbose) std::cout <<
"Couldn't find \"" <<
jetcoll <<
"\" under " << tagger <<
" in this CDI file!" << std::endl;
238 if (
verbose) std::cout <<
"Here are your options :" << std::endl;
239 if (
verbose) printMetadata(tagger_ind, -1, 0, 0);
242 if (
verbose) std::cout <<
"Couldn't find \"" << tagger <<
"\" in this CDI file" << std::endl;
243 if (
verbose) std::cout <<
"Here are your options :" << std::endl;
244 if (
verbose) printMetadata(-1,0,0,0);
249 json json_metadata(m_metadata);
253 std::ofstream
output(filepath);
254 output << std::setw(4) << json_metadata << std::endl;
257 m_initialized = configured;
264 std::cout <<
" CDIReader :: You need to validate your configuration before working with (flavour) labels!" << std::endl;
267 if (tagger.empty() || jetcollection.empty() || workingpoint.empty()){
269 Labels DSID_vec(m_DSIDs.size());
270 std::copy(m_DSIDs.begin(), m_DSIDs.end(), DSID_vec.begin());
273 }
else if(m_taggers.find(tagger) == m_taggers.end()){
274 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
276 }
else if(m_jetcollections.find(jetcollection) == m_jetcollections.end()){
277 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " << tagger <<
" this CDI file!" << std::endl;
279 }
else if(m_workingpoints.find(workingpoint) == m_workingpoints.end()){
280 std::cout <<
" The working point [" << workingpoint <<
"] doesn't exist in " << tagger <<
"/" << jetcollection <<
" this CDI file!" << std::endl;
282 for (
const std::string&
DSID : m_metadata[tagger][jetcollection][workingpoint][
"DSIDs"]){
283 DSIDs.push_back(
DSID);
291 std::cout <<
" CDIReader :: You need to validate your configuration before working with (flavour) labels!" << std::endl;
294 if (tagger.empty() || jetcollection.empty() || workingpoint.empty()){
297 }
else if(m_taggers.find(tagger) == m_taggers.end()){
298 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
299 }
else if(m_jetcollections.find(jetcollection) == m_jetcollections.end()){
300 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " << tagger <<
" this CDI file!" << std::endl;
301 }
else if(m_workingpoints.find(workingpoint) == m_workingpoints.end()){
302 std::cout <<
" The working point [" << workingpoint <<
"] doesn't exist in " << tagger <<
"/" << jetcollection <<
" this CDI file!" << std::endl;
304 for (std::string
label : m_metadata[tagger][jetcollection][workingpoint][
"labels"]){
315 jetcolls.assign(m_jetcollections.begin(), m_jetcollections.end());
316 }
else if (m_taggers.find(tagger) == m_taggers.end()) {
317 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
320 for(
const auto&
jet : m_metadata[tagger]){
321 jetcolls.push_back(
jet.first);
330 if (tagger.empty() || jetcollection.empty()){
332 wps.assign(m_workingpoints.begin(), m_workingpoints.end());
333 }
else if(m_taggers.find(tagger) == m_taggers.end()){
334 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
335 }
else if(m_jetcollections.find(jetcollection) == m_jetcollections.end()){
336 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " << tagger <<
" this CDI file!" << std::endl;
338 for(
const auto&
wp : m_metadata[tagger][jetcollection]){
339 wps.push_back(
wp.first);
347 taggers.assign(m_taggers.begin(), m_taggers.end());