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);
37 TList*
keys = parentDir->GetListOfKeys();
38 if(isWPdirectory(
keys)){
42 TList* labelkeys = parentDir->GetListOfKeys();
45 std::set<std::string> DSID_set;
46 std::set<std::string> systematics_set;
49 std::string taggername =
path.at(0);
50 std::string jetcollname =
path.at(1);
51 std::string workingpointname =
path.at(2);
56 for(
const auto label : *labelkeys){
57 std::string labelname =
label->GetName();
58 if(labelname ==
"cutvalue" || labelname.find(
"fraction") != std::string::npos)
continue;
59 m_labels.insert(labelname);
60 theseLabels.push_back(labelname);
63 TDirectoryFile*
flavourDir = (TDirectoryFile*)parentDir->Get(labelname.c_str());
67 for(
const auto CDHistCont : *DSIDkeys){
68 std::string DSIDname = CDHistCont->GetName();
69 DSID_set.insert(DSIDname);
70 m_DSIDs.insert(DSIDname);
71 if(DSIDname ==
"default_SF"){
73 std::string
dir = taggername +
"/" + jetcollname +
"/" + workingpointname +
"/" + labelname +
"/default_SF";
75 m_CDIFile->GetObject(
dir.c_str(), cont);
77 std::cout <<
"No default_SF CalibrationDataHistogramContainer?" << std::endl;
80 for(std::string
s : uncertainties){
81 systematics_set.insert(
s);
85 std::string flav_spec_unc_name = labelname +
"_syst";
86 theseData[flav_spec_unc_name] = uncertainties;
90 std::cout <<
"No flavour directory?" << std::endl;
94 std::sort(theseLabels.begin(), theseLabels.end());
95 theseData[
"labels"] = theseLabels;
97 Labels theseDSIDs(DSID_set.size());
98 std::copy(DSID_set.begin(), DSID_set.end(), theseDSIDs.begin());
99 theseData[
"DSIDs"] = theseDSIDs;
101 Labels theseSystematics(systematics_set.size());
102 std::copy(systematics_set.begin(), systematics_set.end(), theseSystematics.begin());
103 theseData[
"systematics"] = theseSystematics;
106 record_metadata_map(theseData, metamap);
108 for(
const auto coll: *
keys){
109 std::string collname = coll->GetName();
110 if ( collname.find(
"cutvalue") != std::string::npos || collname.find(
"fraction") != std::string::npos)
continue;
112 record_metadata(collname,
depth+1);
113 TDirectoryFile* collDir = (TDirectoryFile*)parentDir->Get(collname.c_str());
114 if(collDir && collname !=
"VersionInfo"){
115 std::string nextmap = metamap +
";" + collname;
116 crawlCDI(collDir,
depth+1, nextmap);
118 std::cout <<
"No collection directory?" << std::endl;
146 int current_tagger = (
tagger < 0) ? -1 : 0;
147 int current_jetcoll = (
jetcoll < 0) ? -1 : 0;
148 int current_wpoint = (wpoint < 0) ? -1 : 0;
149 int current_label = (
label < 0) ? -1 : 0;
151 for (
const auto& [
tag,
jets] : m_metadata){
152 if(current_tagger != -1) current_tagger += 1;
155 std::cout <<
"| " <<
tag << std::endl;
157 for (
const auto& [
jet, wps] :
jets){
158 if(current_jetcoll != -1) current_jetcoll += 1;
161 std::cout <<
"|\\__ " <<
jet << std::endl;
163 int num_wps = wps.size();
165 for(
const auto& [
wp,
labels] : wps){
166 if(current_wpoint != -1) current_wpoint += 1;
167 if(wpoint != current_wpoint || wpoint == 0)
continue;
169 if(num_wp_seen != num_wps){
170 std::cout <<
"| |\\__" <<
wp << std::endl;
172 std::cout <<
"| \\__" <<
wp << std::endl;
177 for(
const std::string&
l :
d[
"labels"]){
178 if(current_label != -1) current_label += 1;
179 if(
label != current_label ||
label == 0)
continue;
180 if(num_wp_seen != num_wps && label_index == 0){
181 std::cout <<
"| | \\___" <<
" (" << label_index <<
") " <<
l << std::endl;
182 }
else if(label_index != 0 && num_wp_seen != num_wps) {
183 std::cout <<
"| | \\___" <<
" (" << label_index <<
") " <<
l << std::endl;
185 std::cout <<
"| \\___" <<
" (" << label_index <<
") " <<
l << std::endl;
198 bool configured =
false;
206 if(m_metadata.count(
tagger) > 0){
208 for(
const auto&
tag : m_metadata){
214 for(
const auto&
jet : m_metadata[
tagger]){
222 if(wpoint.first ==
wp)
break;
224 if (
verbose) std::cout <<
" Your configuration looks good! Available labels are : " << std::endl;
225 if (
verbose) printMetadata(tagger_ind, jetcoll_ind, wp_ind, -1);
227 for(
const std::string& flavour_label : m_metadata[
tagger][
jetcoll][
wp][
"labels"]){
228 m_label_vec.push_back(flavour_label);
231 std::sort(m_label_vec.begin(), m_label_vec.end());
234 if (
verbose) std::cout <<
"Couldn't find \"" <<
wp <<
"\" for " <<
tagger <<
" / " <<
jetcoll <<
" in this CDI file!" << std::endl;
235 if (
verbose) std::cout <<
"Here are your options :" << std::endl;
236 if (
verbose) printMetadata(tagger_ind, jetcoll_ind, -1, 0);
239 if (
verbose) std::cout <<
"Couldn't find \"" <<
jetcoll <<
"\" under " <<
tagger <<
" in this CDI file!" << std::endl;
240 if (
verbose) std::cout <<
"Here are your options :" << std::endl;
241 if (
verbose) printMetadata(tagger_ind, -1, 0, 0);
244 if (
verbose) std::cout <<
"Couldn't find \"" <<
tagger <<
"\" in this CDI file" << std::endl;
245 if (
verbose) std::cout <<
"Here are your options :" << std::endl;
246 if (
verbose) printMetadata(-1,0,0,0);
251 json json_metadata(m_metadata);
255 std::ofstream
output(filepath);
256 output << std::setw(4) << json_metadata << std::endl;
259 m_initialized = configured;
266 std::cout <<
" CDIReader :: You need to validate your configuration before working with (flavour) labels!" << std::endl;
269 if (
tagger.empty() || jetcollection.empty() || workingpoint.empty()){
271 Labels DSID_vec(m_DSIDs.size());
272 std::copy(m_DSIDs.begin(), m_DSIDs.end(), DSID_vec.begin());
275 }
else if(m_taggers.find(
tagger) == m_taggers.end()){
276 std::cout <<
" The tagger [" <<
tagger <<
"] doesn't exist in this CDI file!" << std::endl;
278 }
else if(m_jetcollections.find(jetcollection) == m_jetcollections.end()){
279 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " <<
tagger <<
" this CDI file!" << std::endl;
281 }
else if(m_workingpoints.find(workingpoint) == m_workingpoints.end()){
282 std::cout <<
" The working point [" << workingpoint <<
"] doesn't exist in " <<
tagger <<
"/" << jetcollection <<
" this CDI file!" << std::endl;
284 for (
const std::string&
DSID : m_metadata[
tagger][jetcollection][workingpoint][
"DSIDs"]){
285 DSIDs.push_back(
DSID);
293 std::cout <<
" CDIReader :: You need to validate your configuration before working with (flavour) labels!" << std::endl;
296 if (
tagger.empty() || jetcollection.empty() || workingpoint.empty()){
299 }
else if(m_taggers.find(
tagger) == m_taggers.end()){
300 std::cout <<
" The tagger [" <<
tagger <<
"] doesn't exist in this CDI file!" << std::endl;
301 }
else if(m_jetcollections.find(jetcollection) == m_jetcollections.end()){
302 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " <<
tagger <<
" this CDI file!" << std::endl;
303 }
else if(m_workingpoints.find(workingpoint) == m_workingpoints.end()){
304 std::cout <<
" The working point [" << workingpoint <<
"] doesn't exist in " <<
tagger <<
"/" << jetcollection <<
" this CDI file!" << std::endl;
306 for (
const std::string&
label : m_metadata[
tagger][jetcollection][workingpoint][
"labels"]){
317 jetcolls.assign(m_jetcollections.begin(), m_jetcollections.end());
318 }
else if (m_taggers.find(
tagger) == m_taggers.end()) {
319 std::cout <<
" The tagger [" <<
tagger <<
"] doesn't exist in this CDI file!" << std::endl;
322 for(
const auto&
jet : m_metadata[
tagger]){
323 jetcolls.push_back(
jet.first);
332 if (
tagger.empty() || jetcollection.empty()){
334 wps.assign(m_workingpoints.begin(), m_workingpoints.end());
335 }
else if(m_taggers.find(
tagger) == m_taggers.end()){
336 std::cout <<
" The tagger [" <<
tagger <<
"] doesn't exist in this CDI file!" << std::endl;
337 }
else if(m_jetcollections.find(jetcollection) == m_jetcollections.end()){
338 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " <<
tagger <<
" this CDI file!" << std::endl;
340 for(
const auto&
wp : m_metadata[
tagger][jetcollection]){
341 wps.push_back(
wp.first);
349 taggers.assign(m_taggers.begin(), m_taggers.end());