11#include <nlohmann/json.hpp>
13using json = nlohmann::json;
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();
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;
60 theseLabels.push_back(labelname);
63 TDirectoryFile* flavourDir = (TDirectoryFile*)parentDir->Get(labelname.c_str());
66 TList* DSIDkeys = flavourDir->GetListOfKeys();
67 for(
const auto CDHistCont : *DSIDkeys){
68 std::string DSIDname = CDHistCont->GetName();
69 DSID_set.insert(DSIDname);
71 if(DSIDname ==
"default_SF"){
73 std::string dir = taggername +
"/" + jetcollname +
"/" + workingpointname +
"/" + labelname +
"/default_SF";
77 std::cout <<
"No default_SF CalibrationDataHistogramContainer?" << std::endl;
80 for(
const 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"] = std::move(theseLabels);
97 Labels theseDSIDs(DSID_set.size());
98 std::copy(DSID_set.begin(), DSID_set.end(), theseDSIDs.begin());
99 theseData[
"DSIDs"] = std::move(theseDSIDs);
101 Labels theseSystematics(systematics_set.size());
102 std::copy(systematics_set.begin(), systematics_set.end(), theseSystematics.begin());
103 theseData[
"systematics"] = std::move(theseSystematics);
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;
113 TDirectoryFile* collDir = (TDirectoryFile*)parentDir->Get(collname.c_str());
114 if(collDir && collname !=
"VersionInfo"){
115 std::string nextmap = metamap +
";" + collname;
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;
152 if(current_tagger != -1) current_tagger += 1;
153 if(tagger != current_tagger || tagger == 0)
continue;
155 std::cout <<
"| " << tag << std::endl;
157 for (
const auto& [
jet, wps] : jets){
158 if(current_jetcoll != -1) current_jetcoll += 1;
159 if(jetcoll != current_jetcoll || jetcoll == 0)
continue;
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;
210 if(tag.first == tagger)
break;
216 if(
jet.first == jetcoll)
break;
220 for(
const auto& wpoint :
m_metadata[tagger][jetcoll]){
222 if(wpoint.first == wp)
break;
224 if (
verbose) std::cout <<
" Your configuration looks good! Available labels are : " << std::endl;
227 for(
const std::string& flavour_label :
m_metadata[tagger][jetcoll][wp][
"labels"]){
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;
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;
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;
253 std::filesystem::path
cwd = std::filesystem::current_path();
254 std::filesystem::path filepath =
cwd /
"CDI.json";
255 std::ofstream output(filepath);
256 output << std::setw(4) << json_metadata << std::endl;
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()){
273 DSIDs = std::move(DSID_vec);
276 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
279 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " << tagger <<
" this CDI file!" << std::endl;
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()){
300 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
302 std::cout <<
" The jet collection [" << jetcollection <<
"] doesn't exist in " << tagger <<
" this CDI file!" << std::endl;
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"]){
307 labels.push_back(
label);
319 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
323 jetcolls.push_back(
jet.first);
332 if (tagger.empty() || jetcollection.empty()){
336 std::cout <<
" The tagger [" << tagger <<
"] doesn't exist in this CDI file!" << std::endl;
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);
void record_metadata(const std::string &datum, int depth=0)
Labels getDSIDs(const std::string &tagger="", const std::string &jetcollection="", const std::string &workingpoint="")
Labels getLabels(const std::string &tagger="", const std::string &jetcollection="", const std::string &workingpoint="")
std::unique_ptr< TFile > m_CDIFile
std::set< std::string > m_taggers
std::set< std::string > m_DSIDs
void record_metadata_map(const Data &data, const std::string &path)
Labels getWorkingPoints(const std::string &tagger, const std::string &jetcollection)
bool checkConfig(const std::string &tagger, const std::string &jetcoll, const std::string &wp, bool verbose=false)
bool isWPdirectory(TList *list)
std::set< std::string > m_workingpoints
Labels getJetCollections(const std::string &tagger)
std::set< std::string > m_jetcollections
CDIReader(const std::string &cdipath, bool verbose=false)
normal constructor.
std::set< std::string > m_labels
std::map< std::string, Labels > Data
void printMetadata(int tagger=-1, int jetcoll=-1, int wpoint=-1, int label=-1)
std::vector< std::string > Labels
bool m_initialized
flag whether the initialization has been carried out
void crawlCDI(TDirectoryFile *parentDir, int depth=0, const std::string &metamap="")
std::vector< std::string > listUncertainties() const
retrieve the list of "uncertainties" accessible to this object.
This is the class holding information for histogram-based calibration results.
std::string depth
tag string for intendation
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
std::vector< std::string > split(const std::string &s, const std::string &t=":")
std::string label(const std::string &format, int i)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.