ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
dqutils::HanOutputFile Class Reference

#include <HanOutputFile.h>

Inheritance diagram for dqutils::HanOutputFile:
Collaboration diagram for dqutils::HanOutputFile:

Public Types

typedef std::map< std::string, TDirectory * > DirMap_t
 
typedef std::map< std::string, TObject * > DirStrMap_t
 
typedef std::map< std::string, std::string > AssMap_t
 DirMap_t but For Version 2 files. More...
 
typedef std::map< std::string, AssMap_t * > DirToAssMap_t
 

Public Member Functions

 HanOutputFile ()
 
 HanOutputFile (const std::string &fileName)
 
virtual ~HanOutputFile ()
 
virtual bool setFile (const std::string &fileName)
 Clears all previous data and opens the file with the given name for analysis, returning a boolean indicating whether the file was opened successfully or not. More...
 
virtual int getFileVersion ()
 
virtual void printAllDQGroups ()
 
virtual void printAllDQAssessments ()
 
virtual void printHistoAssessments ()
 
virtual std::string stringListSystemPaths (std::string location)
 
virtual std::string stringAllDQAssessments ()
 
virtual std::string stringHistoAssessments ()
 
virtual std::string stringAllHistograms ()
 
virtual void streamAllDQAssessments (std::ostream &o, bool streamAll)
 
virtual void streamHistoAssessments (std::ostream &o, bool streamAll)
 
virtual void streamAllHistograms (std::ostream &o, bool streamAll)
 
virtual int saveAllHistograms (const std::string &location, bool drawRefs, const std::string &run_min_LB, int cnvsType=1)
 
virtual bool saveHistogramToFile (const std::string &nameHis, std::string location, TDirectory *groupDir, bool drawRefs, const std::string &run_min_LB, const std::string &pathName, int cnvsType=1)
 
virtual std::pair< std::string, std::string > getHistogram (const std::string &nameHis, TDirectory *groupDir, bool drawRefs, const std::string &run_min_LB, const std::string &pathName, int cnvsType=1)
 
virtual std::string getHistogramPNG (const std::string &nameHis, TDirectory *groupDir, bool drawRefs, const std::string &run_min_LB, const std::string &pathName)
 
virtual std::pair< std::string, std::string > getHistogramJSON (const std::string &nameHis, TDirectory *groupDir, bool drawRefs, const std::string &run_min_LB, const std::string &pathName)
 
virtual bool saveHistogramToFileSuperimposed (const std::string &nameHis, std::string location, TDirectory *groupDir1, TDirectory *groupDir2, bool drawRefs, const std::string &run_min_LB, const std::string &pathName, int cnvsType=1)
 
virtual bool drawH2 (TCanvas *canv, TH2 *hist, std::string &drawopt, std::string &display)
 !! More...
 
virtual bool drawH1 (TCanvas *canv, TH1 *hist, TH1 *reference, std::string &drawopt, std::string &display, std::string &AlgoName)
 
virtual bool drawReference (TCanvas *canv, TH1 *hRef, TH1 *h, std::string &drawopt, std::string &display, std::string &AlgoName)
 
virtual void ratioplot (TCanvas *myC_main, TH1 *h, TH1 *href, std::string str)
 
virtual void ratioplot2D (TCanvas *canvas, TH2 *h2, TH2 *h2Ref, std::string display)
 
virtual void attachFits (TH1 *hist, std::string &drawopt, std::string &display)
 
virtual void setupCanvas (std::string &drawopt, std::string &display)
 
virtual void polynomial (TCanvas *c, std::string str, TH1 *h)
 
virtual void displayExtra (TCanvas *c, const std::string &str)
 
virtual void axisOption (std::string str, TH1 *h)
 
virtual void formatTH1 (TCanvas *c, TH1 *h) const
 
virtual void formatTH2 (TCanvas *c, TH2 *h) const
 
virtual void formatTGraph (TCanvas *c, TGraph *g) const
 
virtual void formatTEfficiency (TCanvas *c, TEfficiency *e) const
 
virtual double getNEntries (std::string location, std::string histname)
 
virtual double getNEntries (const TObject *obj)
 

Static Public Member Functions

static void getAllGroupDirs (DirMap_t &dirmap, TDirectory *dir, const std::string &dirName)
 
static void getAllGroupDirs_V2 (DirStrMap_t &dirstrmap, TObject *obj, const std::string &objName)
 Same as getAllGroupDirs, but works with Version 2.3 files. More...
 
static void getAllAssessments (AssMap_t &dirmap, TDirectory *dir)
 
static void printDQGroupJSON (const nlohmann::json &j, const std::string &location, const char *path_to_file)
 Print path - and name of Assessment, represented as JSON TObjString. More...
 
static std::string getStringName (const std::string &location, int file_version)
 
static std::string getInfo (const std::string &location, int file_version)
 
static std::string getInfo (const std::string &JSON_str)
 
static std::string processJSON_ingetInfo (const nlohmann::ordered_json &j)
 
static std::string getIndentation (const std::string &pathName, const std::string &leadingSpace="")
 
static bool containsDir (std::string dirname, std::string maindir)
 
static std::optional< std::string > containsKeyInJSON (const std::string &pathInJSON, const std::string &jsonName, const std::string &path_to_JSON)
 Checks JSON file for a key (by its path) More...
 

Static Public Attributes

static const int GENERATE_PNG = 1
 cnvsType: 1=pngOnly;2=jsonOnly;3=pngAndJson More...
 
static const int GENERATE_JSON = 2
 

Protected Member Functions

virtual void clearData ()
 
virtual void convertToGraphics (int cnvsType, TCanvas *myC, std::string &json, TImage **img=0, char **x=0, int *y=0)
 
virtual void convertToGraphics (int cnvsType, TCanvas *myC, const std::string &namePNG, const std::string &nameJSON)
 
virtual bool saveFile (int cnvsType, const std::string &pngfName, const std::string &pngContent, const std::string &jsonfName, const std::string &jsonfContent)
 
virtual bool writeToFile (const std::string &fName, const std::string &content)
 

Protected Attributes

TFile * m_file
 
DirMap_t m_indirMap
 
DirStrMap_t m_indirstrMap
 
DirToAssMap_t m_assessMap
 Same Dim_indirMaprMap, but for files of version 2. More...
 
TStyle * m_style
 

Detailed Description

Definition at line 31 of file HanOutputFile.h.

Member Typedef Documentation

◆ AssMap_t

typedef std::map<std::string, std::string> dqutils::HanOutputFile::AssMap_t

DirMap_t but For Version 2 files.

Definition at line 42 of file HanOutputFile.h.

◆ DirMap_t

typedef std::map<std::string, TDirectory*> dqutils::HanOutputFile::DirMap_t

Definition at line 40 of file HanOutputFile.h.

◆ DirStrMap_t

typedef std::map<std::string, TObject*> dqutils::HanOutputFile::DirStrMap_t

Definition at line 41 of file HanOutputFile.h.

◆ DirToAssMap_t

typedef std::map<std::string, AssMap_t*> dqutils::HanOutputFile::DirToAssMap_t

Definition at line 43 of file HanOutputFile.h.

Constructor & Destructor Documentation

◆ HanOutputFile() [1/2]

dqutils::HanOutputFile::HanOutputFile ( )

Definition at line 89 of file HanOutputFile.cxx.

89  : m_file(0), m_style(0) {
91  TPluginHandler* h;
92  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "image"))) {
93  if (h->LoadPlugin() == -1) return;
94 
95  h->ExecPlugin(0);
96  }
97  }

◆ HanOutputFile() [2/2]

dqutils::HanOutputFile::HanOutputFile ( const std::string &  fileName)

Definition at line 99 of file HanOutputFile.cxx.

99  : m_file(0), m_style(0) {
102  TPluginHandler* h;
103  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "image"))) {
104  if (h->LoadPlugin() == -1) return;
105 
106  h->ExecPlugin(0);
107  }
108  }

◆ ~HanOutputFile()

dqutils::HanOutputFile::~HanOutputFile ( )
virtual

Definition at line 110 of file HanOutputFile.cxx.

110  {
111  // bool useRecursiveDelete = gROOT->MustClean();
112  // gROOT->SetMustClean(false);
113 
115 
116  // gROOT->SetMustClean(useRecursiveDelete);
117  }

Member Function Documentation

◆ attachFits()

void dqutils::HanOutputFile::attachFits ( TH1 *  hist,
std::string &  drawopt,
std::string &  display 
)
virtual

Definition at line 2285 of file HanOutputFile.cxx.

2285  {
2286  size_t found = display.find("gaus");
2287 
2288  if (found != std::string::npos) {
2289  Double_t minstat = 0.;
2290  std::size_t fpos1, fpos2, fpos;
2291  fpos = display.find("MinStat");
2292  if (fpos != std::string::npos) {
2293  fpos1 = display.find('(', fpos + 1);
2294  if (fpos1 != std::string::npos) {
2295  fpos2 = display.find(')', fpos1 + 1);
2296  if (fpos2 != std::string::npos) {
2297  std::string s_minstat = display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
2298  minstat = std::strtod(s_minstat.c_str(), NULL);
2299  }
2300  }
2301  }
2302  std::string fitopt("");
2303  fpos = display.find("FitOption");
2304  if (fpos != std::string::npos) {
2305  fpos1 = display.find('(', fpos + 1);
2306  if (fpos1 != std::string::npos) {
2307  fpos2 = display.find(')', fpos1 + 1);
2308  if (fpos2 != std::string::npos) {
2309  fitopt = display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
2310  }
2311  }
2312  }
2313  // plot double gaus
2314  std::size_t found1 = display.find("doublegaus");
2315  if (found1 != std::string::npos) {
2316  std::size_t found2 = display.find('(', found1 + 1);
2317  if (found2 != std::string::npos) {
2318  std::size_t found3 = display.find(')', found2 + 1);
2319  if (found3 != std::string::npos) {
2320  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
2321  Double_t xmin = std::strtod(range.c_str(), NULL);
2322  std::size_t found4 = display.find(',', found2 + 1);
2323  if (found4 != std::string::npos) {
2324  range = display.substr(found4 + 1, found3 - found4 - 1);
2325  Double_t xmax = std::strtod(range.c_str(), NULL);
2326  TF1* f1 = new TF1("f1", "gaus", xmin, xmax);
2327  h->Fit(f1, "q");
2328  Double_t par[6];
2329  f1->GetParameters(par);
2330  TF1* func = new TF1("func", "gaus(0)+gaus(3)", xmin, xmax);
2331  func->SetParameters(par);
2332  func->SetParameter(3, h->GetBinContent(h->GetMaximumBin()));
2333  func->SetParameter(4, h->GetMean());
2334  func->SetParameter(5, par[2]);
2335  func->SetLineColor(kRed);
2336  func->SetLineWidth(2);
2337  if (h->GetEffectiveEntries() > minstat) {
2338  h->Fit(func, ("rq" + fitopt).c_str());
2339  }
2340  delete f1;
2341  delete func;
2342  }
2343  }
2344  }
2345  } else {
2346  // draw gaus+pol1
2347  std::size_t found1 = display.find("gauspluspol1");
2348  if (found1 != std::string::npos) {
2349  std::size_t found2 = display.find('(', found1 + 1);
2350  if (found2 != std::string::npos) {
2351  std::size_t found3 = display.find(')', found2 + 1);
2352  if (found3 != std::string::npos) {
2353  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
2354  Double_t xmin = std::strtod(range.c_str(), NULL);
2355  std::size_t found4 = display.find(',', found2 + 1);
2356  if (found4 != std::string::npos) {
2357  range = display.substr(found4 + 1, found3 - found4 - 1);
2358  Double_t xmax = std::strtod(range.c_str(), NULL);
2359  TF1* func = new TF1("func", "gaus(0)+pol1(3)", xmin, xmax);
2360  func->SetLineColor(kRed);
2361  func->SetLineWidth(2);
2362  func->SetParameters(h->GetBinContent(h->GetMaximumBin()), h->GetMean(), h->GetRMS());
2363  if (h->GetEffectiveEntries() > minstat) {
2364  h->Fit(func, ("rq" + fitopt).c_str());
2365  }
2366  delete func;
2367  }
2368  }
2369  }
2370  } else {
2371  // draw gaus+expo
2372  found1 = display.find("gausplusexpo");
2373  if (found1 != std::string::npos) {
2374  std::size_t found2 = display.find('(', found1 + 1);
2375  if (found2 != std::string::npos) {
2376  std::size_t found3 = display.find(')', found2 + 1);
2377  if (found3 != std::string::npos) {
2378  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
2379  Double_t xmin = std::strtod(range.c_str(), NULL);
2380  std::size_t found4 = display.find(',', found2 + 1);
2381  if (found4 != std::string::npos) {
2382  range = display.substr(found4 + 1, found3 - found4 - 1);
2383  Double_t xmax = std::strtod(range.c_str(), NULL);
2384 
2385  TF1* func = new TF1("func", "gaus(0)+expo(3)", xmin, xmax);
2386  func->SetLineColor(kRed);
2387  func->SetLineWidth(2);
2388  func->SetParameters(h->GetBinContent(h->GetMaximumBin()), h->GetMean(), h->GetRMS());
2389  if (h->GetEffectiveEntries() > minstat) {
2390  h->Fit(func, ("rq" + fitopt).c_str());
2391  }
2392  delete func;
2393  }
2394  }
2395  }
2396  } else {
2397  // the last case: single gaus
2398  std::size_t found2 = display.find('(', found + 1);
2399  if (found2 != std::string::npos) {
2400  std::size_t found3 = display.find(')', found2 + 1);
2401  if (found3 != std::string::npos) {
2402  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
2403  Double_t xmin = std::strtod(range.c_str(), NULL);
2404  std::size_t found4 = display.find(',', found2 + 1);
2405  if (found4 != std::string::npos) {
2406  range = display.substr(found4 + 1, found3 - found4 - 1);
2407  Double_t xmax = std::strtod(range.c_str(), NULL);
2408  TF1* func = new TF1("func", "gaus", xmin, xmax);
2409  func->SetLineColor(kRed);
2410  func->SetLineWidth(2);
2411  if (h->GetEffectiveEntries() > minstat) {
2412  h->Fit(func, ("rq" + fitopt).c_str());
2413  }
2414  delete func;
2415  }
2416  }
2417  }
2418  }
2419  }
2420  }
2421  }
2422  if (!drawopt.empty()) {
2423  // do drawopt related stuff here
2424  }
2425  }

◆ axisOption()

void dqutils::HanOutputFile::axisOption ( std::string  str,
TH1 *  h 
)
virtual

Definition at line 2580 of file HanOutputFile.cxx.

2580  {
2581  std::size_t found = str.find("AxisRange");
2582  while (found != std::string::npos) {
2583  // std::string coordinates, cx1,cy1 ="";
2584  // std::size_t found1 = str.find_first_of(')',found+1);
2585  // std::size_t found2 = str.find_first_of("\'",found+1);
2586  // if (found2!=std::string::npos){
2587  std::string coordinates, cx1, cy1 = "";
2588  std::size_t found1 = str.find_first_of(')', found + 1);
2589  std::size_t found2 = str.find_first_of("\'", found + 1);
2590  if (found2 != std::string::npos) {
2591  found2 = str.find_first_of("\'", found2 + 1);
2592  if (found1 < found2) {
2593  found1 = str.find_first_of(')', found2 + 1);
2594  }
2595  /* }
2596  if (found1!=std::string::npos){
2597  coordinates = str.substr(found+10,found1-found-10);
2598  found1 = coordinates.find_first_of(',');
2599  if (found1!=std::string::npos){
2600  cx1 = coordinates.substr(0,found1);
2601  double x1=std::strtod(cx1.c_str(),NULL);
2602  found2 = coordinates.find_first_of(',',found1+1);
2603  if (found2!=std::string::npos){
2604  cy1 = coordinates.substr(found1+1,found2-found1-1);
2605  double y1=std::strtod(cy1.c_str(),NULL);
2606  std::string txt = coordinates.substr(found2+2,coordinates.size() );
2607  txt = txt.substr(0,txt.size()-1 );
2608  if (txt == "X" && x1 < y1)
2609  {
2610  h->SetAxisRange(x1,y1,"X");
2611  }
2612  if (txt == "Y" && x1 < y1)
2613  {
2614  h->SetAxisRange(x1,y1,"Y");
2615  }
2616  if (txt == "Z" && x1 < y1)
2617  {
2618  h->SetAxisRange(x1,y1,"Z");
2619  }
2620  }
2621  }
2622  }
2623  found=str.find("AxisRange",found+1);
2624  }
2625  */
2626  }
2627  if (found1 != std::string::npos) {
2628  coordinates = str.substr(found + 10, found1 - found - 10);
2629  found1 = coordinates.find_first_of(',');
2630  if (found1 != std::string::npos) {
2631  cx1 = coordinates.substr(0, found1);
2632  double x1 = std::strtod(cx1.c_str(), NULL);
2633  found2 = coordinates.find_first_of(',', found1 + 1);
2634  if (found2 != std::string::npos) {
2635  cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2636  double y1 = std::strtod(cy1.c_str(), NULL);
2637  std::string txt = coordinates.substr(found2 + 2, coordinates.size());
2638  txt.pop_back();
2639  if (txt == "X" && x1 < y1) {
2640  h->GetXaxis()->SetRangeUser(x1, y1);
2641  }
2642  if (txt == "Y" && x1 < y1) {
2643  h->SetAxisRange(x1, y1, "Y");
2644  }
2645  if (txt == "Z" && x1 < y1) {
2646  h->SetAxisRange(x1, y1, "Z");
2647  }
2648  } else {
2649  std::string txt = coordinates.substr(found1 + 2, coordinates.size());
2650  txt.pop_back();
2651  if (txt[1] == 'M') {
2652  if (txt == "XMax") {
2653  double xmin = BINLOEDGE(h, 1);
2654  h->GetXaxis()->SetRangeUser(xmin, x1);
2655  }
2656  if (txt == "XMin") {
2657  double xmax = BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX());
2658  h->GetXaxis()->SetRangeUser(x1, xmax);
2659  }
2660  if (txt == "YMax") {
2661  double ymin = h->GetMinimum();
2662  h->SetAxisRange(ymin, x1, "Y");
2663  }
2664  if (txt == "YMin") {
2665  double ymax = h->GetMaximum();
2666  h->SetAxisRange(x1, ymax, "Y");
2667  }
2668  }
2669  }
2670  }
2671  }
2672  found = str.find("AxisRange", found + 1);
2673  }
2674  }

◆ clearData()

void dqutils::HanOutputFile::clearData ( )
protectedvirtual

Definition at line 3172 of file HanOutputFile.cxx.

3172  {
3174  // bool useRecursiveDelete = gROOT->MustClean();
3175  // gROOT->SetMustClean(false);
3176 
3177  delete m_file;
3178  delete m_style;
3179  m_file = 0;
3180  m_style = 0;
3181  m_indirMap.clear();
3182 
3183  DirToAssMap_t::const_iterator assessMapEnd = m_assessMap.end();
3184  for (DirToAssMap_t::const_iterator i = m_assessMap.begin(); i != assessMapEnd; ++i) {
3185  delete i->second;
3186  }
3187  m_assessMap.clear();
3188 
3189  // gROOT->SetMustClean(useRecursiveDelete);
3190  }

◆ containsDir()

bool dqutils::HanOutputFile::containsDir ( std::string  dirname,
std::string  maindir 
)
static

Definition at line 351 of file HanOutputFile.cxx.

351  {
352  while (dirname.size() > 0 && dirname[dirname.size() - 1] == '/') {
353  dirname.erase(dirname.size() - 2, dirname.size());
354  }
355  while (dirname.size() > 0 && dirname[0] == '/') {
356  dirname = dirname.substr(1, dirname.size());
357  }
358  std::size_t found = dirname.find_first_of("/", 1);
359  std::string str = dirname.substr(0, found);
360  gROOT->cd(maindir.c_str());
361  TKey* key = gDirectory->FindKey(str.c_str());
362  bool status = false;
363  TObject* obj(0);
364  TDirectory* dirobj(0);
365  if (key != 0) {
366  obj = key->ReadObj();
367  dirobj = dynamic_cast<TDirectory*>(obj);
368  }
369  if (dirobj != 0) {
370  if (found != std::string::npos) {
371  maindir = maindir + "/" + str;
372  dirname = dirname.substr(found + 1, dirname.size());
373  status = containsDir(std::move(dirname), std::move(maindir));
374  } else {
375  status = true;
376  }
377  }
378  delete obj;
379  return status;
380  }

◆ containsKeyInJSON()

std::optional< std::string > dqutils::HanOutputFile::containsKeyInJSON ( const std::string &  pathInJSON,
const std::string &  jsonName,
const std::string &  path_to_JSON 
)
static

Checks JSON file for a key (by its path)

The same as containsDir, but works with JSON in V2 files

Parameters
pathInJSON- Only inside JSON (without path to JSON string)
jsonName- Results or Config
Returns
part of JSON string if PathInJSON exists inJSON
"JSON exists", if
Parameters
pathInJSON== ""
Returns
the whole JSON string, if
Parameters
pathInJSON== "/"
Returns
"None" if PathInJSON does not exist inJSON, or the whole JSON string is absent

Definition at line 382 of file HanOutputFile.cxx.

383  {
384  gROOT->cd(path_to_JSON.c_str());
385  TKey* key = gDirectory->FindKey(jsonName.c_str());
386  TObject* obj(0);
387  if (key == 0) {
388  return {}; // the JSON with this name is absent
389  } else {
390  obj = key->ReadObj();
391  }
392  std::string content = obj->GetName(); // In ATLAS DQM root files GetName() actually returns the content rather
393  // than the name of a string
394  if (pathInJSON == "") { // If we should check just the existense of the JSON string
395  delete obj;
396  return "JSON exists";
397  }
398  if (pathInJSON == "/") { // When we need the whole JSON string
399  delete obj;
400  return content;
401  }
402  nlohmann::ordered_json j = nlohmann::ordered_json::parse(content);
403  nlohmann::ordered_json::json_pointer p1(pathInJSON);
404  std::string return_string;
405  try
406  {
407  auto val1 = j.at(p1);
408  if (val1.type() == nlohmann::json::value_t::string) {
409  val1.get_to(return_string);
410  } else if (val1.type() == nlohmann::json::value_t::object) {
411  return_string = val1.dump();
412  } else {
413  std::cout << "Warning: Strange part of JSON" << std::endl;
414  delete obj;
415  return {};
416  }
417  }
418  catch (...)
419  {
420  // std::cout<<" the path not exists\n";
421  // std::cout<<"J\n";
422  delete obj;
423  return {};
424  }
425  delete obj;
426  return return_string;
427  }

◆ convertToGraphics() [1/2]

void dqutils::HanOutputFile::convertToGraphics ( int  cnvsType,
TCanvas *  myC,
const std::string &  namePNG,
const std::string &  nameJSON 
)
protectedvirtual

Definition at line 3212 of file HanOutputFile.cxx.

3213  {
3214  if (cnvsType & GENERATE_PNG) {
3215  myC->SaveAs(namePNG.c_str());
3216  }
3217  if (cnvsType & GENERATE_JSON) {
3218  std::string json = std::string(TBufferJSON::ConvertToJSON(myC));
3219  writeToFile(nameJSON, json);
3220  }
3221  }

◆ convertToGraphics() [2/2]

void dqutils::HanOutputFile::convertToGraphics ( int  cnvsType,
TCanvas *  myC,
std::string &  json,
TImage **  img = 0,
char **  x = 0,
int *  y = 0 
)
protectedvirtual

Definition at line 3203 of file HanOutputFile.cxx.

3203  {
3204  if (cnvsType & GENERATE_PNG) {
3205  if (img) getImageBuffer(img, myC, x, y);
3206  }
3207  if (cnvsType & GENERATE_JSON) {
3208  json = TBufferJSON::ConvertToJSON(myC);
3209  }
3210  }

◆ displayExtra()

void dqutils::HanOutputFile::displayExtra ( TCanvas *  c,
const std::string &  str 
)
virtual

Definition at line 2915 of file HanOutputFile.cxx.

2915  {
2916  std::size_t found = str.find("TLine");
2917  while (found != std::string::npos) {
2918  std::size_t found1 = str.find_first_of(')', found + 1);
2919  if (found1 != std::string::npos) {
2920  std::string coordinates = str.substr(found + 6, found1 - found - 6);
2921  bool NDC = false;
2922  if (found1 < str.size() - 3 && str.substr(found1 + 1, 3) == "NDC") {
2923  NDC = true;
2924  }
2925  found1 = coordinates.find_first_of(',');
2926  if (found1 != std::string::npos) {
2927  std::string cx1 = coordinates.substr(0, found1);
2928  double x1 = std::strtod(cx1.c_str(), NULL);
2929  std::size_t found2 = coordinates.find_first_of(',', found1 + 1);
2930  if (found2 != std::string::npos) {
2931  std::string cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2932  double y1 = std::strtod(cy1.c_str(), NULL);
2933  found1 = coordinates.find_first_of(',', found2 + 1);
2934  if (found1 != std::string::npos) {
2935  std::string cx2 = coordinates.substr(found2 + 1, found1 - found2 - 1);
2936  double x2 = std::strtod(cx2.c_str(), NULL);
2937  std::string cy2 = coordinates.substr(found1 + 1, coordinates.size());
2938  double y2 = std::strtod(cy2.c_str(), NULL);
2939  c->cd();
2940  TLine* L = new TLine;
2941  if (NDC) {
2942  if (x1 <= 1.0 && x1 >= 0.0 && x2 <= 1.0 && x2 >= 0.0 && y1 <= 1.0 && y1 >= 0.0 && y2 <= 1.0 &&
2943  y2 >= 0.0) {
2944  L->DrawLineNDC(x1, y1, x2, y2);
2945  }
2946  } else {
2947  L->DrawLine(x1, y1, x2, y2);
2948  }
2949  }
2950  }
2951  }
2952  }
2953  found = str.find("TLine", found + 1);
2954  }
2955 
2956  found = str.find("TText");
2957  while (found != std::string::npos) {
2958  std::string coordinates, cx1, cy1 = "";
2959  std::size_t found1 = str.find_first_of(')', found + 1);
2960  std::size_t found2 = str.find_first_of('\'', found + 1);
2961  if (found2 != std::string::npos) {
2962  found2 = str.find_first_of('\"', found2 + 1);
2963  if (found2 != std::string::npos && found1 < found2) {
2964  found1 = str.find_first_of(')', found2 + 1);
2965  }
2966  }
2967  if (found1 != std::string::npos) {
2968  coordinates = str.substr(found + 6, found1 - found - 6);
2969  bool NDC = false;
2970  if (found1 < str.size() - 3 && str.substr(found1 + 1, 3) == "NDC") {
2971  NDC = true;
2972  }
2973  found1 = coordinates.find_first_of(',');
2974  if (found1 != std::string::npos) {
2975  cx1 = coordinates.substr(0, found1);
2976  double x1 = std::strtod(cx1.c_str(), NULL);
2977  found2 = coordinates.find_first_of(',', found1 + 1);
2978  if (found2 != std::string::npos) {
2979  cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2980  double y1 = std::strtod(cy1.c_str(), NULL);
2981  std::string txt = coordinates.substr(found2 + 2, coordinates.size());
2982  txt.pop_back();
2983  c->cd();
2984  TText* T = new TText;
2985  if (NDC) {
2986  if (x1 <= 1.0 && x1 >= 0.0 && y1 <= 1.0 && y1 >= 0.0) {
2987  T->DrawTextNDC(x1, y1, txt.c_str());
2988  }
2989  } else {
2990  T->DrawText(x1, y1, txt.c_str());
2991  }
2992  }
2993  }
2994  }
2995  found = str.find("TText", found + 1);
2996  }
2997 
2998  found = str.find("TDota");
2999  while (found != std::string::npos) {
3000  std::size_t found1 = str.find_first_of(')', found + 1);
3001  if (found1 != std::string::npos) {
3002  std::string coordinates = str.substr(found + 6, found1 - found - 6);
3003  bool NDC = false;
3004  if (found1 < str.size() - 3 && str.substr(found1 + 1, 3) == "NDC") {
3005  NDC = true;
3006  }
3007  found1 = coordinates.find_first_of(',');
3008  if (found1 != std::string::npos) {
3009  std::string cx1 = coordinates.substr(0, found1);
3010  double x1 = std::strtod(cx1.c_str(), NULL);
3011  std::size_t found2 = coordinates.find_first_of(',', found1 + 1);
3012  if (found2 != std::string::npos) {
3013  std::string cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
3014  double y1 = std::strtod(cy1.c_str(), NULL);
3015  found1 = coordinates.find_first_of(',', found2 + 1);
3016  if (found1 != std::string::npos) {
3017  std::string cx2 = coordinates.substr(found2 + 1, found1 - found2 - 1);
3018  double x2 = std::strtod(cx2.c_str(), NULL);
3019  std::string cy2 = coordinates.substr(found1 + 1, coordinates.size());
3020  double y2 = std::strtod(cy2.c_str(), NULL);
3021  c->cd();
3022  TLine* L = new TLine;
3023  L->SetLineStyle(2);
3024  if (NDC) {
3025  if (x1 <= 1.0 && x1 >= 0.0 && x2 <= 1.0 && x2 >= 0.0 && y1 <= 1.0 && y1 >= 0.0 && y2 <= 1.0 &&
3026  y2 >= 0.0) {
3027  L->DrawLineNDC(x1, y1, x2, y2);
3028  }
3029  } else {
3030  L->DrawLine(x1, y1, x2, y2);
3031  }
3032  }
3033  }
3034  }
3035  }
3036  found = str.find("TDota", found + 1);
3037  }
3038 
3039  found = str.find("TSize");
3040  while (found != std::string::npos) {
3041  std::string coordinates, cx1, cy1, txtsize = "";
3042  std::size_t found1 = str.find_first_of(')', found + 1);
3043  std::size_t found2 = str.find_first_of('\'', found + 1);
3044  if (found2 != std::string::npos) {
3045  found2 = str.find_first_of('\"', found2 + 1);
3046  if (found2 != std::string::npos && found1 < found2) {
3047  found1 = str.find_first_of(')', found2 + 1);
3048  }
3049  }
3050  if (found1 != std::string::npos) {
3051  coordinates = str.substr(found + 6, found1 - found - 6);
3052  bool NDC = false;
3053  if (found1 < str.size() - 3 && str.substr(found1 + 1, 3) == "NDC") {
3054  NDC = true;
3055  }
3056  found1 = coordinates.find_first_of(',');
3057  if (found1 != std::string::npos) {
3058  cx1 = coordinates.substr(0, found1);
3059  double x1 = std::strtod(cx1.c_str(), NULL);
3060  found2 = coordinates.find_first_of(',', found1 + 1);
3061  if (found2 != std::string::npos) {
3062  cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
3063  double y1 = std::strtod(cy1.c_str(), NULL);
3064  std::size_t found3 = coordinates.find_first_of(',', found2 + 1);
3065  if (found3 != std::string::npos) {
3066  txtsize = coordinates.substr(found2 + 1, found3 - found2 - 1);
3067  double size = std::strtod(txtsize.c_str(), NULL);
3068  std::string txt = coordinates.substr(found3 + 2, coordinates.size());
3069  txt.pop_back();
3070  c->cd();
3071  TText* T = new TText;
3072  T->SetTextSize(size / 100);
3073  if (NDC) {
3074  if (x1 <= 1.0 && x1 >= 0.0 && y1 <= 1.0 && y1 >= 0.0) {
3075  T->DrawTextNDC(x1, y1, txt.c_str());
3076  }
3077  } else {
3078  T->DrawText(x1, y1, txt.c_str());
3079  }
3080  }
3081  }
3082  }
3083  }
3084  found = str.find("TSize", found + 1);
3085  }
3086  }

◆ drawH1()

bool dqutils::HanOutputFile::drawH1 ( TCanvas *  canv,
TH1 *  hist,
TH1 *  reference,
std::string &  drawopt,
std::string &  display,
std::string &  AlgoName 
)
virtual

Definition at line 2427 of file HanOutputFile.cxx.

2428  {
2429  formatTH1(myC, h);
2430  if (display.find("StatBox") != std::string::npos) {
2431  h->SetStats(kTRUE);
2432  }
2433  if (h->GetXaxis()->GetXmin() >= h->GetXaxis()->GetXmax()) {
2434  std::cerr << "HanOutputFile::saveHistogramToFile(): "
2435  << "Inconsistent x-axis settings: min=" << h->GetXaxis()->GetXmin() << ", "
2436  << "max=" << h->GetXaxis()->GetXmax() << ", "
2437  << "Will not save this histogram.\n";
2438  return false;
2439  }
2440  myC->cd();
2441  if (hRef != 0) {
2442  drawReference(myC, hRef, h, drawopt, display, AlgoName);
2443  } else {
2444  myC->cd();
2445  if (h->GetMinimum() >= 0 && h->GetMaximum() > 0.) {
2446  gPad->SetLogy(display.find("LogY") != std::string::npos);
2447  } else {
2448  gPad->SetLogy(false);
2449  }
2450  if (BINLOEDGE(h, 1) > 0) {
2451  gPad->SetLogx(display.find("LogX") != std::string::npos);
2452  } else {
2453  gPad->SetLogx(false);
2454  }
2455  axisOption(display, h);
2456  h->Draw(drawopt.c_str());
2457  }
2458  myC->cd();
2459  displayExtra(myC, display);
2460  myC->RedrawAxis();
2461  return true;
2462  }

◆ drawH2()

bool dqutils::HanOutputFile::drawH2 ( TCanvas *  canv,
TH2 *  hist,
std::string &  drawopt,
std::string &  display 
)
virtual

!!

Definition at line 2219 of file HanOutputFile.cxx.

2219  {
2220  std::string drawopt(drawop);
2221  myC->cd();
2222  if (h2->GetMinimum() >= 0 && h2->GetMaximum() > 0) {
2223  gPad->SetLogy(display.find("LogY") != std::string::npos);
2224  gPad->SetLogz(display.find("LogZ") != std::string::npos);
2225  } else {
2226  gPad->SetLogy(false);
2227  }
2228  if (BINLOEDGE(h2, 1) > 0) {
2229  gPad->SetLogx(display.find("LogX") != std::string::npos);
2230  } else {
2231  gPad->SetLogx(false);
2232  }
2233  formatTH2(myC, h2);
2234  if (h2->GetXaxis()->GetXmin() >= h2->GetXaxis()->GetXmax()) {
2235  std::cerr << "HanOutputFile::saveHistogramToFile(): "
2236  << "Inconsistent x-axis settings: min=" << h2->GetXaxis()->GetXmin() << ", "
2237  << "max=" << h2->GetXaxis()->GetXmax() << ", "
2238  << "Will not save this histogram.\n";
2239  return false;
2240  }
2241  if (h2->GetYaxis()->GetXmin() >= h2->GetYaxis()->GetXmax()) {
2242  std::cerr << "HanOutputFile::saveHistogramToFile(): "
2243  << "Inconsistent y-axis settings: min=" << h2->GetYaxis()->GetXmin() << ", "
2244  << "max=" << h2->GetYaxis()->GetXmax() << ", "
2245  << "Will not save this histogram.\n";
2246  return false;
2247  }
2248  axisOption(display, h2);
2249  if (drawopt == "") {
2250  drawopt = "COLZ";
2251  }
2252  h2->Draw(drawopt.c_str());
2253  displayExtra(myC, display);
2254  // std::cout<<"drawh2 drawopt="<<drawopt<<",display="<<display<<std::endl;
2255  // if (drawopt.find("lego") == std::string::npos) {
2256  myC->RedrawAxis();
2257  //}
2258  return true;
2259  }

◆ drawReference()

bool dqutils::HanOutputFile::drawReference ( TCanvas *  canv,
TH1 *  hRef,
TH1 *  h,
std::string &  drawopt,
std::string &  display,
std::string &  AlgoName 
)
virtual

Definition at line 2464 of file HanOutputFile.cxx.

2465  {
2466  formatTH1(myC, hRef);
2467  TProfile* pRef = dynamic_cast<TProfile*>(hRef);
2468  if (pRef != 0) { // profile reference
2469  hRef->SetMarkerColor(2);
2470  hRef->SetLineColor(2);
2471  hRef->SetLineWidth(2);
2472  double ymin = (hRef->GetMinimum() < h->GetMinimum()) ? hRef->GetMinimum() : h->GetMinimum();
2473  double ymax = (hRef->GetMaximum() > h->GetMaximum()) ? hRef->GetMaximum() : h->GetMaximum();
2474  // double xmin = ( BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1)) ? BINLOEDGE(hRef, 1)-BINWIDTH(hRef, 1) : BINLOEDGE(h,
2475  // 1)-BINWIDTH(h, 1); double xmax = ( BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX()) >
2476  // BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()) ) ?
2477  // BINLOEDGE(hRef, hRef->GetNbinsX()) + 2.0*BINWIDTH(hRef, hRef->GetNbinsX()): BINLOEDGE(h, h->GetNbinsX())
2478  // + 2.0*BINWIDTH(h, h->GetNbinsX()) ;
2479  double xmin = (BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1)) ? BINLOEDGE(hRef, 1) : BINLOEDGE(h, 1);
2480  double xmax = (BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX()) >
2481  BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()))
2482  ? BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX())
2483  : BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX());
2484  // double y_av = (ymax + ymin)/2;
2485  // double y_halv = (ymax-ymin)*0.6;
2486  bool isLogY = (display.find("LogY") != std::string::npos);
2487  if (isLogY) {
2488  if (ymax <= 0.0) ymax = 5.0;
2489  if (ymin > 0.) {
2490  double lymax = log(ymax);
2491  double lymin = log(ymin);
2492  h->SetAxisRange(exp(lymin - (lymax - lymin) * 0.05), exp(lymax + (lymax - lymin) * 0.05), "Y");
2493  // leave 5% gap on above and below
2494  } else {
2495  std::cerr << "ymin is <0. and LogY requested for histogram \"" << h->GetName() << " "
2496  << h->GetDirectory()->GetPath() << "\", ymin=" << ymin << std::endl;
2497  }
2498  } else {
2499  double yMargin = (ymax - ymin) * 0.05;
2500  h->SetAxisRange(ymin - yMargin, ymax + yMargin, "Y");
2501  }
2502  // h->SetAxisRange(xmin,xmax,"X");
2503  h->GetXaxis()->SetRangeUser(xmin, xmax);
2504  axisOption(display, h);
2505  if (h->GetMinimum() >= 0 && hRef->GetMinimum() >= 0 && h->GetMaximum() > 0 && hRef->GetMaximum() > 0) {
2506  gPad->SetLogy(display.find("LogY") != std::string::npos);
2507  }
2508  if (BINLOEDGE(h, 1) > 0 && BINLOEDGE(hRef, 1) > 0) {
2509  gPad->SetLogx(display.find("LogX") != std::string::npos);
2510  }
2511  h->Draw(drawopt.c_str());
2512  hRef->Draw(("SAME" + drawopt).c_str());
2513  h->Draw(("SAME" + drawopt).c_str());
2514  } else { // ordinary reference
2515  double scale = 1.0;
2516  if (display.find("ScaleRef") != std::string::npos) {
2517  scale = getScaleVal(display);
2518  } else if (h->Integral("width") > 0.0 && hRef->Integral("width") > 0.0 &&
2519  (AlgoName.find("BinContentComp") == std::string::npos) &&
2520  (display.find("NoNorm") == std::string::npos)) {
2521  scale = h->Integral("width") / hRef->Integral("width");
2522  }
2523  hRef->Scale(scale);
2524  hRef->SetMarkerColor(15);
2525  hRef->SetFillColor(15);
2526  hRef->SetLineColor(15);
2527  double ymin = (hRef->GetMinimum() < h->GetMinimum()) ? hRef->GetMinimum() : h->GetMinimum();
2528  double ymax = (hRef->GetMaximum() > h->GetMaximum()) ? hRef->GetMaximum() : h->GetMaximum();
2529  // double xmin = ( BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1)) ? BINLOEDGE(hRef, 1)-BINWIDTH(hRef, 1) : BINLOEDGE(h,
2530  // 1)-BINWIDTH(h, 1); double xmax = ( BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX()) >
2531  // BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()) ) ? BINLOEDGE(hRef, hRef->GetNbinsX())
2532  // + 2.0*BINWIDTH(hRef, hRef->GetNbinsX()): BINLOEDGE(h, h->GetNbinsX()) + 2.0*BINWIDTH(h, h->GetNbinsX()) ;
2533  double xmin = (BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1)) ? BINLOEDGE(hRef, 1) : BINLOEDGE(h, 1);
2534  double xmax = (BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX()) >
2535  BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()))
2536  ? BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX())
2537  : BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX());
2538  // double y_av = (ymax + ymin)/2;
2539  // double y_halv = (ymax-ymin)*0.6;
2540  bool isLogY = (display.find("LogY") != std::string::npos);
2541  // if ( ymin == 0.0 && display.find("LogY")!=std::string::npos ){
2542 
2543  if (isLogY) {
2544  if (ymax <= 0.0) ymax = 5.0;
2545  if (ymin > 0.) {
2546  double lymax = log(ymax);
2547  double lymin = log(ymin);
2548  h->SetAxisRange(exp(lymin - (lymax - lymin) * 0.05), exp(lymax + (lymax - lymin) * 0.05), "Y");
2549  // leave 5% gap on above and below
2550  } else {
2551  std::cerr << "ymin is <=0. and LogY requested for histogram \"" << h->GetName() << " "
2552  << h->GetDirectory()->GetPath() << "\", ymin=" << ymin << std::endl;
2553  }
2554  } else {
2555  double yDiff = ymax - ymin;
2556  h->SetAxisRange(ymin - yDiff * 0.05, ymax + yDiff * 0.05, "Y"); // leave 5% gap above and below
2557  }
2558 
2559  // h->SetAxisRange(xmin,xmax,"X");
2560  h->GetXaxis()->SetRangeUser(xmin, xmax);
2561  myC->cd();
2562  if (h->GetMinimum() >= 0. && hRef->GetMinimum() >= 0. && h->GetMaximum() > 0. && hRef->GetMaximum() > 0.) {
2563  gPad->SetLogy(display.find("LogY") != std::string::npos);
2564  }
2565  if (BINLOEDGE(h, 1) > 0 && BINLOEDGE(hRef, 1) > 0) {
2566  gPad->SetLogx(display.find("LogX") != std::string::npos);
2567  }
2568  axisOption(display, h);
2569  h->Draw(drawopt.c_str());
2570  hRef->Draw(("SAME" + drawopt).c_str());
2571  h->Draw(("SAME" + drawopt).c_str());
2572  }
2573  return true;
2574  }

◆ formatTEfficiency()

void dqutils::HanOutputFile::formatTEfficiency ( TCanvas *  c,
TEfficiency *  e 
) const
virtual

Definition at line 3159 of file HanOutputFile.cxx.

3159  {
3160  if (c == 0 || e == 0) return;
3161 
3162  c->SetLeftMargin(0.15);
3163  c->SetRightMargin(0.13);
3164  c->SetBottomMargin(0.15);
3165  c->SetTopMargin(0.12);
3166  }

◆ formatTGraph()

void dqutils::HanOutputFile::formatTGraph ( TCanvas *  c,
TGraph *  g 
) const
virtual

Definition at line 3148 of file HanOutputFile.cxx.

3148  {
3149  if (c == 0 || g == 0) return;
3150 
3151  c->SetLeftMargin(0.15);
3152  c->SetRightMargin(0.13);
3153  c->SetBottomMargin(0.15);
3154  c->SetTopMargin(0.12);
3155 
3156  g->SetMarkerStyle(20);
3157  }

◆ formatTH1()

void dqutils::HanOutputFile::formatTH1 ( TCanvas *  c,
TH1 *  h 
) const
virtual

Definition at line 3088 of file HanOutputFile.cxx.

3088  {
3089  if (c == 0 || h == 0) return;
3090 
3091  c->SetLeftMargin(0.15);
3092  c->SetRightMargin(0.13);
3093  c->SetBottomMargin(0.15);
3094  c->SetTopMargin(0.12);
3095 
3096  h->SetStats(kFALSE);
3097  h->SetLabelSize(0.04, "X");
3098  h->SetLabelSize(0.04, "Y");
3099  h->SetLabelFont(62, "X");
3100  h->SetLabelFont(62, "Y");
3101  h->SetTitleSize(0.04, "X");
3102  h->SetTitleSize(0.04, "Y");
3103  h->GetXaxis()->SetTitleFont(62);
3104  h->GetXaxis()->SetTitleSize(0.04);
3105  h->GetYaxis()->SetTitleFont(62);
3106  h->GetYaxis()->SetTitleSize(0.04);
3107  h->SetMarkerStyle(20);
3108  h->SetMarkerSize(0.8);
3109 
3110  h->SetTitleOffset(1.5, "y");
3111  h->SetTitleOffset(0.9, "x");
3112 
3113  h->SetNdivisions(504, "X");
3114  h->SetNdivisions(504, "Y");
3115  }

◆ formatTH2()

void dqutils::HanOutputFile::formatTH2 ( TCanvas *  c,
TH2 *  h 
) const
virtual

Definition at line 3117 of file HanOutputFile.cxx.

3117  {
3118  if (c == 0 || h == 0) return;
3119 
3120  c->SetLeftMargin(0.15);
3121  c->SetRightMargin(0.13);
3122  c->SetBottomMargin(0.15);
3123  c->SetTopMargin(0.12);
3124 
3125  h->SetStats(kFALSE);
3126 
3127  h->SetLabelSize(0.04, "X");
3128  h->SetLabelSize(0.04, "Y");
3129  h->SetLabelSize(0.04, "Z");
3130  h->SetLabelFont(62, "X");
3131  h->SetLabelFont(62, "Y");
3132  h->SetLabelFont(62, "Z");
3133  h->SetTitleSize(0.04, "X");
3134  h->SetTitleSize(0.04, "Y");
3135  h->SetTitleSize(0.04, "Z");
3136  h->GetXaxis()->SetTitleFont(62);
3137  h->GetXaxis()->SetTitleSize(0.04);
3138  h->GetYaxis()->SetTitleFont(62);
3139  h->GetYaxis()->SetTitleSize(0.04);
3140 
3141  h->SetTitleOffset(1.5, "y");
3142  h->SetTitleOffset(0.9, "x");
3143 
3144  h->SetNdivisions(504, "X");
3145  h->SetNdivisions(504, "Y");
3146  }

◆ getAllAssessments()

void dqutils::HanOutputFile::getAllAssessments ( AssMap_t dirmap,
TDirectory *  dir 
)
static

Definition at line 248 of file HanOutputFile.cxx.

248  {
250 
251  dir->cd();
252  TIter next(dir->GetListOfKeys());
253  TKey* key;
254  while ((key = dynamic_cast<TKey*>(next())) != 0) {
255  TObject* obj = key->ReadObj();
256  if (dynamic_cast<TH1*>(obj) || dynamic_cast<TGraph*>(obj) || dynamic_cast<TEfficiency*>(obj)) {
257  const char* path(dir->GetPath());
258  std::string assName(obj->GetName());
259  AssMap_t::value_type AssmapVal(assName, path);
260  dirmap.insert(std::move(AssmapVal));
261  }
262  delete obj;
263  }
264  }

◆ getAllGroupDirs()

void dqutils::HanOutputFile::getAllGroupDirs ( DirMap_t dirmap,
TDirectory *  dir,
const std::string &  dirName 
)
static

Definition at line 119 of file HanOutputFile.cxx.

119  {
120  if (dir == 0) return;
121 
122  if (dirName != "") { // Not a file
123  std::string name(dir->GetName());
124  if (name == "Config" || name == "Results") {
125  delete dir;
126  return;
127  }
128 
129  std::string::size_type i = name.find_last_of('_');
130  if (i == (name.size() - 1)) {
131  delete dir;
132  return;
133  }
134 
135  DirMap_t::value_type dirmapVal(dirName, dir);
136  dirmap.insert(std::move(dirmapVal));
137  } else {
138  DirMap_t::value_type dirmapVal("<top_level>", dir);
139  dirmap.insert(std::move(dirmapVal));
140  }
141 
142  dir->cd();
143 
144  TIter next(dir->GetListOfKeys());
145  TKey* key;
146  while ((key = dynamic_cast<TKey*>(next())) != 0) {
147  // don't delete TDirectories
148  TObject* obj = key->ReadObj();
149  TDirectory* subdir = dynamic_cast<TDirectory*>(obj);
150  if (subdir != 0) {
151  std::string subdirName(subdir->GetName());
152  std::string fName("");
153  if (dirName != "") {
154  fName += dirName;
155  fName += "/";
156  }
157  fName += subdirName;
158  getAllGroupDirs(dirmap, subdir, fName);
159  } else {
160  delete obj;
161  }
162  }
163  }

◆ getAllGroupDirs_V2()

void dqutils::HanOutputFile::getAllGroupDirs_V2 ( DirStrMap_t dirstrmap,
TObject *  obj,
const std::string &  objName 
)
static

Same as getAllGroupDirs, but works with Version 2.3 files.

getAllGroupDirs ignores types other than Tdirectories. getAllGroupDirs_V2 works also with TObjstring, as they are JSON

Definition at line 165 of file HanOutputFile.cxx.

165  {
166  if (obj == nullptr) return;
167 
168  TDirectory* dir {};
169  TString obj_type = obj->ClassName();
170 
171  if (objName != "") { // Not a file
172  if (obj_type == "TDirectoryFile" || obj_type == "TDirectory" || obj_type == "TFile") {
173  dir = static_cast<TDirectory*> (obj);
174  std::string name(dir->GetName());
175  if (name == "Config" || name == "Results") {
176  delete dir;
177  return;
178  }
179 
180  std::string::size_type i = name.find_last_of('_'); // If this dir is a histgram info
181  if (i == (name.size() - 1)) {
182  delete dir;
183  return;
184  }
185  DirStrMap_t::value_type dirstrmapVal(objName, obj);
186  dirstrmap.insert(std::move(dirstrmapVal));
187  } else {
188  DirStrMap_t::value_type dirstrmapVal(objName, obj);
189  dirstrmap.insert(std::move(dirstrmapVal));
190  }
191  } else { // If the object is a file
192  DirStrMap_t::value_type dirstrmapVal("<top_level>", obj);
193  dirstrmap.insert(std::move(dirstrmapVal));
194  }
195 
196  if (obj_type == "TDirectoryFile" || obj_type == "TDirectory" || obj_type == "TFile") {
197  dir = static_cast<TDirectory*> (obj);
198  dir->cd();
199  TIter next(dir->GetListOfKeys());
200  TKey* key;
201  while ((key = dynamic_cast<TKey*>(next())) != 0) {
202  // don't delete TDirectories
203  std::string fName("");
204  TObject* obj_in_dir = key->ReadObj();
205  TString obj_in_dir_type = obj_in_dir->ClassName();
206  // Check if this is node (not a histogram)
207  if (obj_in_dir_type == "TDirectoryFile" || obj_in_dir_type == "TDirectory" || obj_in_dir_type == "TFile" ||
208  obj_in_dir_type == "TObjString") {
209  std::string obj_in_dirName;
210  obj_in_dirName = key->GetName(); // If we will read name of the string, it will actually be a content of
211  // the string, so that's why we read name of the key
212  if (objName != "") {
213  fName += objName;
214  fName += "/";
215  }
216  fName += obj_in_dirName; //?
217  if (obj_in_dirName != "Config" && obj_in_dirName != "Results" && obj_in_dirName != "Version_name") { // We
218  // don't
219  // save
220  // 'Config'
221  // and
222  // 'Results'
223  // in
224  // dirstrmap
225  // structure.
226  // And we
227  // don't
228  // store
229  // version
230  // flag
231  // in
232  // dirstrmap
233  // object
234  std::string::size_type i =
235  obj_in_dirName.find_last_of('_'); // if it's an object, that stores info about histogram
236  if (i != (obj_in_dirName.size() - 1)) { // We don't store it in a dirstrmap object
237  getAllGroupDirs_V2(dirstrmap, obj_in_dir,
238  fName); // Everything else we store in dirstrmap as it is for getAllGroupDirs method
239  }
240  }
241  } else { // in case if it isn't a node but a histogram
242  delete obj_in_dir;
243  }
244  }
245  }
246  }

◆ getFileVersion()

int dqutils::HanOutputFile::getFileVersion ( )
virtual

Definition at line 641 of file HanOutputFile.cxx.

641  {
642  if (m_file == 0) {
643  std::cerr << "HanOutputFile::getFileVersion(): "
644  << "No input file is open\n";
645  return 0;
646  }
647 
648  m_file->cd("HanMetadata_");
649 
650  if (gDirectory->FindKey("File")) {
651  gDirectory->cd("File");
652  gDirectory->cd("Version_name");
653  TIter next(gDirectory->GetListOfKeys());
654  TKey* key;
655  while ((key = (TKey*) next())) {
656  TString key_name = key->GetName();
657  if (key_name == "V.2.3") {
658  return 2;
659  } else {
660  return 1;
661  }
662  }
663  } else {
664  return 1;
665  }
666  return 0;
667  }

◆ getHistogram()

std::pair< std::string, std::string > dqutils::HanOutputFile::getHistogram ( const std::string &  nameHis,
TDirectory *  groupDir,
bool  drawRefs,
const std::string &  run_min_LB,
const std::string &  pathName,
int  cnvsType = 1 
)
virtual

Definition at line 1182 of file HanOutputFile.cxx.

1184  {
1186  groupDir->cd();
1187 
1188  int iMarkerStyle = 20;
1189  gStyle->SetFrameBorderMode(0);
1190  gStyle->SetFrameFillColor(0);
1191  gStyle->SetCanvasBorderMode(0);
1192  gStyle->SetPadBorderMode(0);
1193  gStyle->SetPadColor(0);
1194  gStyle->SetCanvasColor(0);
1195  gStyle->SetTitleColor(0);
1196  gStyle->SetStatColor(0);
1197  gStyle->SetFillColor(1);
1198  gStyle->SetPalette(1, 0);
1199  gStyle->SetTitleFontSize(0.06);
1200  gStyle->SetTitleH(0.06);
1201  gStyle->SetMarkerStyle(iMarkerStyle);
1202  gStyle->SetOptStat(111100);
1203  gStyle->SetStatBorderSize(0);
1204  gStyle->SetStatX(0.99);
1205  gStyle->SetStatY(0.99);
1206  gStyle->SetStatW(0.2);
1207  gStyle->SetStatH(0.1);
1208 
1209  //Used in TASImage::GetImageBuffer, Buffer must be deallocated after usage with free(buffer) call
1210  char* x = nullptr;
1211  int y {};
1212  std::string json;
1213  TImage* img = nullptr;
1214 
1215  gROOT->SetBatch();
1216  TImageDump tid;
1217  std::string pathname(groupDir->GetPath());
1218  std::string display = "";
1219  bool WasCollectionReference = false;
1220  int file_version = getFileVersion();
1221  bool LookForDisplay;
1222  if (file_version == 1) {
1223  LookForDisplay = containsDir("Config/annotations/display", (pathname + "/" + nameHis + "_"));
1224  if (LookForDisplay) {
1225  display = getStringName(pathname + "/" + nameHis + "_/Config/annotations/display", file_version);
1226  }
1227  } else if (file_version == 2) {
1228  std::optional<std::string> JSON_content;
1229  LookForDisplay = containsDir((nameHis + "_"), pathname);
1230  if (LookForDisplay) {
1231  JSON_content = containsKeyInJSON("/annotations/display", "Config", (pathname + "/" + nameHis + "_"));
1232  if (JSON_content) {
1233  LookForDisplay = true;
1234  } else {
1235  LookForDisplay = false;
1236  }
1237  }
1238  if (LookForDisplay) {
1239  display = JSON_content.value();
1240  }
1241  }
1242  // Plot overflows?
1243  bool PlotOverflows = (display.find("PlotUnderOverflow") != std::string::npos);
1244  // Look for Draw Options
1245  std::size_t found = display.find("Draw=");
1246  std::string drawopt = "";
1247  while (found != std::string::npos) {
1248  std::size_t found1 = display.find_first_of(',', found + 1);
1249  auto temp = display.substr(found + 5, found1 != std::string::npos ? found1 - found - 5 : display.size());
1250  std::ranges::transform(temp, temp.begin(), [](unsigned char c) { return std::tolower(c); });
1251  drawopt += temp;
1252  found = display.find("Draw=", found + 1);
1253  }
1254  // Look for DrawRef Options
1255  found = display.find("DrawRef=");
1256  std::string drawrefopt = "";
1257  while (found != std::string::npos) {
1258  std::size_t found1 = display.find_first_of(',', found + 1);
1259  auto temp = display.substr(found + 8, found1 != std::string::npos ? found1 - found - 8 : display.size());
1260  std::ranges::transform(temp, temp.begin(), [](unsigned char c) { return std::tolower(c); });
1261  drawrefopt += temp;
1262  found = display.find("DrawRef=", found + 1);
1263  }
1264  if (drawrefopt == "") {
1265  drawrefopt = drawopt;
1266  }
1267  // Look for DrawRef2D Options
1268  found = display.find("DrawRef2D=");
1269  std::string drawrefopt2D = "";
1270  while (found != std::string::npos) {
1271  std::size_t found1 = display.find_first_of(',', found + 1);
1272  auto temp = display.substr(found + 10, found1 != std::string::npos ? found1 - found - 10 : display.size());
1273  std::ranges::transform(temp, temp.begin(), [](unsigned char c) { return std::tolower(c); });
1274  drawrefopt2D += temp;
1275  found = display.find("DrawRef2D=", found + 1);
1276  }
1277 
1278  // should we rename "Data" ?
1279  found = display.find("DataName");
1280  std::string datatitle;
1281  if (found == std::string::npos) {
1282  datatitle = "Data";
1283  }
1284  while (found != std::string::npos) {
1285  std::size_t found1 = display.find_first_of(',', found + 1);
1286  if (found1 != std::string::npos) {
1287  datatitle += display.substr(found + 9, found1 - found - 9);
1288  } else {
1289  datatitle += display.substr(found + 9, display.size());
1290  }
1291  found = display.find("DataName", found + 1);
1292  }
1293  groupDir->cd();
1294  TKey* hkey = groupDir->FindKey(nameHis.c_str());
1295  if (hkey == 0) {
1296  std::cerr << "Did not find TKey for \"" << nameHis << "\", will not save this histogram.\n";
1297  return std::pair<std::string, std::string>{
1298  "", ""
1299  };
1300  }
1301  TLegend* legend(0);
1302  TObject* hobj = hkey->ReadObj();
1303  TObject* ref(0);
1304  TH1* hRef(0);
1305  TEfficiency* eRef(0);
1306  TH2* h2Ref(0);
1307  std::vector<TH1*> hRefs;
1308  std::vector<TEfficiency*> eRefs;
1309  bool hasPlotted(false);
1310  TH1* h = dynamic_cast<TH1*>(hobj);
1311  TH2* h2 = dynamic_cast<TH2*>(h);
1312  TGraph* g = dynamic_cast<TGraph*>(hobj);
1313  TEfficiency* e = dynamic_cast<TEfficiency*>(hobj);
1314 
1315  std::string name = nameHis;
1316  /* name+=".png";
1317  std::string::size_type i = location.find_last_of( '/' );
1318  if( i != (location.size()-1) ) {
1319  location+="/";
1320  }
1321  name=location + name; */
1322  std::string AlgoName("");
1323  AlgoName = getStringName(pathname + "/" + nameHis + "_/Config/name", file_version);
1324  int ww = 550;
1325  int wh = 490;
1326  found = display.find("TCanvas", found + 1);
1327  if (found != std::string::npos) {
1328  std::size_t found1 = display.find_first_of(',', found + 1);
1329  ww = std::atoi((display.substr(found + 8, found1 - found - 8)).c_str());
1330  found = display.find_first_of(')', found1 + 1);
1331  wh = std::atoi((display.substr(found1 + 1, found - found1 - 1)).c_str());
1332  }
1333  if (h != 0) {
1334  auto myC = std::make_unique<TCanvas>(nameHis.c_str(), "myC", ww, wh);
1335 
1336  // if( h->GetMinimum() >= 0) {
1337  // gPad->SetLogy(display.find("LogY")!=std::string::npos );
1338  // }
1339  // if( BINLOEDGE(h, 1) > 0) {
1340  // gPad->SetLogx(display.find("LogX")!=std::string::npos );
1341  // }
1342  gPad->SetGridx(display.find("SetGridx") != std::string::npos);
1343  gPad->SetGridy(display.find("SetGridy") != std::string::npos);
1344  std::size_t found = display.find("SetPalette");
1345  if (found != std::string::npos) {
1346  std::size_t found1 = display.find_first_of('(', found + 1);
1347  std::size_t found2 = display.find_first_of(",)", found + 1);
1348  std::string cn = display.substr(found1 + 1, found2 - found1 - 1);
1349  int n1 = std::strtol(cn.c_str(), NULL, 0);
1350  gStyle->SetPalette((Int_t) n1);
1351  }
1352  found = display.find("SetGridStyle");
1353  if (found != std::string::npos) {
1354  std::size_t found1 = display.find_first_of('(', found + 1);
1355  std::size_t found2 = display.find_first_of(",)", found + 1);
1356  std::string cn = display.substr(found1 + 1, found2 - found1 - 1);
1357  int n1 = std::strtol(cn.c_str(), NULL, 0);
1358  gStyle->SetGridStyle((Style_t) n1);
1359  }
1360 
1361  /******************* for plotting fit function on top of histogram ******************/
1362  found = display.find("gaus");
1363  if (found != std::string::npos) {
1364  Double_t minstat = 0.;
1365  std::size_t fpos1, fpos2, fpos;
1366  fpos = display.find("MinStat");
1367  if (fpos != std::string::npos) {
1368  fpos1 = display.find('(', fpos + 1);
1369  if (fpos1 != std::string::npos) {
1370  fpos2 = display.find(')', fpos1 + 1);
1371  if (fpos2 != std::string::npos) {
1372  std::string s_minstat = display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
1373  minstat = std::strtod(s_minstat.c_str(), NULL);
1374  }
1375  }
1376  }
1377  std::string fitopt("");
1378  fpos = display.find("FitOption");
1379  if (fpos != std::string::npos) {
1380  fpos1 = display.find('(', fpos + 1);
1381  if (fpos1 != std::string::npos) {
1382  fpos2 = display.find(')', fpos1 + 1);
1383  if (fpos2 != std::string::npos) {
1384  fitopt = display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
1385  }
1386  }
1387  }
1388  // plot double gaus
1389  std::size_t found1 = display.find("doublegaus");
1390  if (found1 != std::string::npos) {
1391  std::size_t found2 = display.find('(', found1 + 1);
1392  if (found2 != std::string::npos) {
1393  std::size_t found3 = display.find(')', found2 + 1);
1394  if (found3 != std::string::npos) {
1395  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
1396  Double_t xmin = std::strtod(range.c_str(), NULL);
1397  std::size_t found4 = display.find(',', found2 + 1);
1398  if (found4 != std::string::npos) {
1399  range = display.substr(found4 + 1, found3 - found4 - 1);
1400  Double_t xmax = std::strtod(range.c_str(), NULL);
1401  TF1* f1 = new TF1("f1", "gaus", xmin, xmax);
1402  h->Fit(f1, "q");
1403  Double_t par[6];
1404  f1->GetParameters(par);
1405  TF1* func = new TF1("func", "gaus(0)+gaus(3)", xmin, xmax);
1406  func->SetParameters(par);
1407  func->SetParameter(3, h->GetBinContent(h->GetMaximumBin()));
1408  func->SetParameter(4, h->GetMean());
1409  func->SetParameter(5, par[2]);
1410  func->SetLineColor(kRed);
1411  func->SetLineWidth(2);
1412  if (h->GetEffectiveEntries() > minstat) {
1413  h->Fit(func, ("rq" + fitopt).c_str());
1414  }
1415  delete f1;
1416  delete func;
1417  }
1418  }
1419  }
1420  } else {
1421  // draw gaus+pol1
1422  std::size_t found1 = display.find("gauspluspol1");
1423  if (found1 != std::string::npos) {
1424  std::size_t found2 = display.find('(', found1 + 1);
1425  if (found2 != std::string::npos) {
1426  std::size_t found3 = display.find(')', found2 + 1);
1427  if (found3 != std::string::npos) {
1428  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
1429  Double_t xmin = std::strtod(range.c_str(), NULL);
1430  std::size_t found4 = display.find(',', found2 + 1);
1431  if (found4 != std::string::npos) {
1432  range = display.substr(found4 + 1, found3 - found4 - 1);
1433  Double_t xmax = std::strtod(range.c_str(), NULL);
1434  TF1* func = new TF1("func", "gaus(0)+pol1(3)", xmin, xmax);
1435  func->SetLineColor(kRed);
1436  func->SetLineWidth(2);
1437  func->SetParameters(h->GetBinContent(h->GetMaximumBin()), h->GetMean(), h->GetRMS());
1438  if (h->GetEffectiveEntries() > minstat) {
1439  h->Fit(func, ("rq" + fitopt).c_str());
1440  }
1441  delete func;
1442  }
1443  }
1444  }
1445  } else {
1446  // draw gaus+expo
1447  found1 = display.find("gausplusexpo");
1448  if (found1 != std::string::npos) {
1449  std::size_t found2 = display.find('(', found1 + 1);
1450  if (found2 != std::string::npos) {
1451  std::size_t found3 = display.find(')', found2 + 1);
1452  if (found3 != std::string::npos) {
1453  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
1454  Double_t xmin = std::strtod(range.c_str(), NULL);
1455  std::size_t found4 = display.find(',', found2 + 1);
1456  if (found4 != std::string::npos) {
1457  range = display.substr(found4 + 1, found3 - found4 - 1);
1458  Double_t xmax = std::strtod(range.c_str(), NULL);
1459 
1460  TF1* func = new TF1("func", "gaus(0)+expo(3)", xmin, xmax);
1461  func->SetLineColor(kRed);
1462  func->SetLineWidth(2);
1463  func->SetParameters(h->GetBinContent(h->GetMaximumBin()), h->GetMean(), h->GetRMS());
1464  if (h->GetEffectiveEntries() > minstat) {
1465  h->Fit(func, ("rq" + fitopt).c_str());
1466  }
1467  delete func;
1468  }
1469  }
1470  }
1471  } else {
1472  // the last case: single gaus
1473  std::size_t found2 = display.find('(', found + 1);
1474  if (found2 != std::string::npos) {
1475  std::size_t found3 = display.find(')', found2 + 1);
1476  if (found3 != std::string::npos) {
1477  std::string range = display.substr(found2 + 1, found3 - found2 - 1);
1478  Double_t xmin = std::strtod(range.c_str(), NULL);
1479  std::size_t found4 = display.find(',', found2 + 1);
1480  if (found4 != std::string::npos) {
1481  range = display.substr(found4 + 1, found3 - found4 - 1);
1482  Double_t xmax = std::strtod(range.c_str(), NULL);
1483  TF1* func = new TF1("func", "gaus", xmin, xmax);
1484  func->SetLineColor(kRed);
1485  func->SetLineWidth(2);
1486  if (h->GetEffectiveEntries() > minstat) {
1487  h->Fit(func, ("rq" + fitopt).c_str());
1488  }
1489  delete func;
1490  }
1491  }
1492  }
1493  }
1494  }
1495  }
1496  }
1497  if (h2 != 0) {
1498  formatTH2(myC.get(), h2);
1499  myC->cd();
1500  if (h2->GetMinimum() >= 0 && h2->GetMaximum() > 0.) {
1501  gPad->SetLogy(display.find("LogY") != std::string::npos);
1502  gPad->SetLogz(display.find("LogZ") != std::string::npos);
1503  }
1504  if (BINLOEDGE(h2, 1) > 0) {
1505  gPad->SetLogx(display.find("LogX") != std::string::npos);
1506  }
1507  if (h->GetXaxis()->GetXmin() >= h->GetXaxis()->GetXmax()) {
1508  std::cerr << "HanOutputFile::saveHistogramToFile(): "
1509  << "Inconsistent x-axis settings: min=" << h->GetXaxis()->GetXmin() << ", "
1510  << "max=" << h->GetXaxis()->GetXmax() << ", "
1511  << "Will not save this histogram.\n";
1512  return std::pair<std::string, std::string>{
1513  "", ""
1514  };
1515  }
1516  if (h->GetYaxis()->GetXmin() >= h->GetYaxis()->GetXmax()) {
1517  std::cerr << "HanOutputFile::saveHistogramToFile(): "
1518  << "Inconsistent y-axis settings: min=" << h->GetYaxis()->GetXmin() << ", "
1519  << "max=" << h->GetYaxis()->GetXmax() << ", "
1520  << "Will not save this histogram.\n";
1521  return std::pair<std::string, std::string>{
1522  "", ""
1523  };
1524  }
1525  axisOption(display, h2);
1526  if (drawopt == "") {
1527  drawopt = "COLZ";
1528  }
1529  if (drawRefs) {
1530  if (file_version == 1) {
1531  groupDir->cd((nameHis + "_/Results").c_str());
1532  gDirectory->GetObject("Reference;1", ref);
1533  } else if (file_version == 2) {
1534  if (groupDir->GetDirectory((nameHis + "_").c_str()) != 0) {
1535  groupDir->cd((nameHis + "_").c_str());
1536  gDirectory->GetObject("Reference;1", ref);
1537  }
1538  }
1539  h2Ref = dynamic_cast<TH2*>(ref);
1540  TCollection* colln = dynamic_cast<TCollection*>(ref);
1541  if (colln) {
1542  h2Ref = dynamic_cast<TH2*>(colln->MakeIterator()->Next());
1543  }
1544  if (h2Ref && (drawrefopt2D != "")) {
1545  formatTH2(myC.get(), h2Ref);
1546  h2Ref->Draw(drawrefopt2D.c_str());
1547  }
1548  }
1549  h2->Draw(("SAME" + drawopt).c_str());
1550  displayExtra(myC.get(), display);
1551  if (drawopt.find("lego") == std::string::npos) {
1552  myC->RedrawAxis();
1553  }
1554  if (h2Ref) ratioplot2D(myC.get(), h2, h2Ref, display);
1555 
1556  polynomial(myC.get(), display, h2);
1557  TLatex t;
1558  t.SetNDC();
1559  t.SetTextSize(0.03);
1560  t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1561  TLatex tt;
1562  tt.SetNDC();
1563  tt.SetTextSize(0.03);
1564  tt.DrawLatex(0.02, 0.01, pathName.c_str());
1565  convertToGraphics(cnvsType, myC.get(), json, &img, &x, &y);
1566  } else if (h != 0) {
1567  formatTH1(myC.get(), h);
1568  if (display.find("StatBox") != std::string::npos) {
1569  h->SetStats(kTRUE);
1570  }
1571  if (h->GetXaxis()->GetXmin() >= h->GetXaxis()->GetXmax()) {
1572  std::cerr << "HanOutputFile::saveHistogramToFile(): "
1573  << "Inconsistent x-axis settings: min=" << h->GetXaxis()->GetXmin() << ", "
1574  << "max=" << h->GetXaxis()->GetXmax() << ", "
1575  << "Will not save this histogram.\n";
1576  return std::pair<std::string, std::string>{
1577  "", ""
1578  };
1579  }
1580  h->SetLineColor(kBlack);
1581  h->SetMarkerColor(1);
1582  // h->SetMarkerStyle(iMarkerStyle);
1583  // h->SetMarkerSize(0.8);
1584  h->SetFillStyle(0);
1585  h->SetLineWidth(2);
1586  myC->cd();
1587  if (drawRefs) {
1588  if (file_version == 1) {
1589  groupDir->cd((nameHis + "_/Results").c_str());
1590  gDirectory->GetObject("Reference;1", ref);
1591  } else if (file_version == 2) {
1592  if (groupDir->GetDirectory((nameHis + "_").c_str()) != 0) {
1593  groupDir->cd((nameHis + "_").c_str());
1594  gDirectory->GetObject("Reference;1", ref);
1595  }
1596  }
1597  hRef = dynamic_cast<TH1*>(ref);
1598  if (hRef) {
1599  hRefs.push_back(hRef);
1600  } else {
1601  TCollection* colln = dynamic_cast<TCollection*>(ref);
1602  if (colln) {
1603  WasCollectionReference = true;
1604  std::unique_ptr<TIterator> icolln(colln->MakeIterator());
1605  TObject* ref2;
1606  while ((ref2 = icolln->Next())) {
1607  hRef = dynamic_cast<TH1*>(ref2);
1608  if (hRef) {
1609  if (hRef->GetDimension() == h->GetDimension()) {
1610  hRefs.push_back(hRef);
1611  }
1612  } else std::cout << "hRef cast failed!!!" << std::endl;
1613  }
1614  }
1615  }
1616  groupDir->cd();
1617  }
1618 
1619  if (hRefs.size() > 0) {
1620  legend = new TLegend(0.55, 0.77, 0.87, 0.87);
1621  legend->SetTextFont(62);
1622  legend->SetMargin(0.15);
1623  legend->SetFillStyle(0);
1624  legend->SetBorderSize(0);
1625  legend->AddEntry(h, datatitle.c_str());
1626  int itrcolor(0);
1627  for (auto hRef : hRefs) {
1628  int local_color = root_color_choices[itrcolor];
1629  itrcolor++;
1630  formatTH1(myC.get(), hRef);
1631  TProfile* pRef = dynamic_cast<TProfile*>(hRef);
1632  if (pRef != 0) {
1633  hRef->SetMarkerColor(local_color);
1634  // hRef->SetMarkerStyle(iMarkerStyle);
1635  // hRef->SetMarkerSize(0.8);
1636  hRef->SetLineColor(local_color);
1637  hRef->SetLineWidth(2);
1638  double ymin = (hRef->GetMinimum() < h->GetMinimum()) ? hRef->GetMinimum() : h->GetMinimum();
1639  double ymax = (hRef->GetMaximum() > h->GetMaximum()) ? hRef->GetMaximum() : h->GetMaximum();
1640  double xmin, xmax;
1641  if (PlotOverflows) {
1642  xmin = (BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1) ? BINLOEDGE(hRef, 1) - BINWIDTH(hRef, 1)
1643  : BINLOEDGE(h, 1) - BINWIDTH(h, 1));
1644  xmax = (BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX()) >
1645  BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()))
1646  ? BINLOEDGE(hRef, hRef->GetNbinsX()) + 2.0 * BINWIDTH(hRef, hRef->GetNbinsX())
1647  : BINLOEDGE(h, h->GetNbinsX()) + 2.0 * BINWIDTH(h, h->GetNbinsX());
1648  } else {
1649  xmin = (BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1)) ? BINLOEDGE(hRef, 1) : BINLOEDGE(h, 1);
1650  xmax = (BINLOEDGE(hRef, hRef->GetNbinsX()) > BINLOEDGE(h, h->GetNbinsX())
1651  ? BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX())
1652  : BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()));
1653  }
1654  // double y_av = (ymax + ymin)/2;
1655  // double y_halv = (ymax-ymin)*0.6;
1656  bool isLogY = (display.find("LogY") != std::string::npos);
1657  if (isLogY) {
1658  if (ymax <= 0.) ymax = 5.0;
1659  if (ymin > 0.) {
1660  double lymax = log(ymax);
1661  double lymin = log(ymin);
1662  h->SetAxisRange(exp(lymin - (lymax - lymin) * 0.05), exp(lymax + (lymax - lymin) * 0.05),
1663  "Y"); // leave 5% gap on above and below
1664  } else {
1665  std::cerr << "ymin is <0. and LogY requested for histogram \"" << pathname + "/" + nameHis
1666  << "\", ymin=" << ymin << std::endl;
1667  }
1668  } else {
1669  double yMargin = (ymax - ymin) * 0.05;
1670  h->SetAxisRange(ymin - yMargin, ymax + yMargin, "Y");
1671  }
1672  h->GetXaxis()->SetRangeUser(xmin, xmax);
1673  hRef->GetXaxis()->SetRangeUser(xmin, xmax);
1674  axisOption(display, h);
1675  if (h->GetMinimum() >= 0. && hRef->GetMinimum() >= 0. && h->GetMaximum() > 0. &&
1676  hRef->GetMaximum() > 0.) {
1677  gPad->SetLogy(display.find("LogY") != std::string::npos);
1678  }
1679  if (BINLOEDGE(h, 1) > 0 && BINLOEDGE(hRef, 1) > 0) {
1680  gPad->SetLogx(display.find("LogX") != std::string::npos);
1681  }
1682  if (!hasPlotted) {
1683  h->Draw(drawopt.c_str());
1684  hasPlotted = true;
1685  }
1686  hRef->Draw(("SAME" + drawrefopt).c_str());
1687  } else {
1688  double scale = 1.0;
1689  if (display.find("ScaleRef") != std::string::npos) {
1690  scale = getScaleVal(display);
1691  } else if (h->Integral("width") > 0.0 && hRef->Integral("width") > 0.0 &&
1692  (AlgoName.find("BinContentComp") == std::string::npos) &&
1693  (display.find("NoNorm") == std::string::npos)) {
1694  scale = h->Integral("width") / hRef->Integral("width");
1695  }
1696  hRef->Scale(scale);
1697  // hRef->SetMarkerStyle(iMarkerStyle);
1698  // hRef->SetMarkerSize(0.8);
1699  hRef->SetMarkerColor(local_color);
1700  // hRef->SetFillColor(local_color);
1701  hRef->SetLineColor(local_color);
1702  double ymin = (hRef->GetMinimum() < h->GetMinimum()) ? hRef->GetMinimum() : h->GetMinimum();
1703  double ymax = (hRef->GetMaximum() > h->GetMaximum()) ? hRef->GetMaximum() : h->GetMaximum();
1704  double xmin, xmax;
1705  if (PlotOverflows) {
1706  xmin = (BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1)) ? BINLOEDGE(hRef, 1) - BINWIDTH(hRef, 1)
1707  : BINLOEDGE(h, 1) - BINWIDTH(h, 1);
1708  xmax = (BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX()) >
1709  BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()))
1710  ? BINLOEDGE(hRef, hRef->GetNbinsX()) + 2.0 * BINWIDTH(hRef, hRef->GetNbinsX())
1711  : BINLOEDGE(h, h->GetNbinsX()) + 2.0 * BINWIDTH(h, h->GetNbinsX());
1712  } else {
1713  xmin = (BINLOEDGE(hRef, 1) < BINLOEDGE(h, 1)) ? BINLOEDGE(hRef, 1) : BINLOEDGE(h, 1);
1714  xmax = (BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX()) >
1715  BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX()))
1716  ? BINLOEDGE(hRef, hRef->GetNbinsX()) + BINWIDTH(hRef, hRef->GetNbinsX())
1717  : BINLOEDGE(h, h->GetNbinsX()) + BINWIDTH(h, h->GetNbinsX());
1718  }
1719 
1720  // double y_av = (ymax + ymin)/2;
1721  // double y_halv = (ymax-ymin)*0.6;
1722  bool isLogY = (display.find("LogY") != std::string::npos);
1723  // if ( ymin == 0.0 && display.find("LogY")!=std::string::npos ){
1724 
1725  if (isLogY) {
1726  if (ymax <= 0.) ymax = 5.0;
1727  if (ymin > 0.) {
1728  double lymax = log(ymax);
1729  double lymin = log(ymin);
1730  h->SetAxisRange(exp(lymin - (lymax - lymin) * 0.05), exp(lymax + (lymax - lymin) * 0.05), "Y");
1731  // leave 5% gap on above and below
1732  } else {
1733  std::cerr << "ymin is <=0. and LogY requested for histogram \"" << pathname + "/" + nameHis
1734  << "\", ymin=" << ymin << std::endl;
1735  }
1736  } else {
1737  double yDiff = ymax - ymin;
1738  h->SetAxisRange(ymin - yDiff * 0.05, ymax + yDiff * 0.05, "Y"); // leave 5% gap above and below
1739  }
1740 
1741  h->GetXaxis()->SetRangeUser(xmin, xmax);
1742  hRef->GetXaxis()->SetRangeUser(xmin, xmax);
1743  myC->cd();
1744  if (h->GetMinimum() >= 0 && hRef->GetMinimum() >= 0 && h->GetMaximum() > 0. && hRef->GetMaximum() > 0.) {
1745  gPad->SetLogy(display.find("LogY") != std::string::npos);
1746  }
1747  if (BINLOEDGE(h, 1) > 0 && BINLOEDGE(hRef, 1) > 0) {
1748  gPad->SetLogx(display.find("LogX") != std::string::npos);
1749  }
1750  axisOption(display, h);
1751  if (!hasPlotted) {
1752  h->Draw(drawopt.c_str());
1753  hasPlotted = true;
1754  }
1755  hRef->Draw(("SAME" + drawrefopt).c_str());
1756  }
1757  if (WasCollectionReference) {
1758  legend->AddEntry(hRef, hRef->GetName());
1759  } else {
1760  std::string refInfo("");
1761  refInfo = getStringName(pathname + "/" + nameHis + "_/Config/annotations/refInfo", file_version);
1762  legend->AddEntry(hRef, refInfo != "Undefined" ? refInfo.c_str() : "Reference");
1763  }
1764  }
1765  h->Draw(("SAME" + drawopt).c_str());
1766  legend->Draw();
1767  } else {
1768  myC->cd();
1769  if (h->GetMinimum() >= 0) {
1770  gPad->SetLogy(display.find("LogY") != std::string::npos);
1771  }
1772  if (BINLOEDGE(h, 1) > 0) {
1773  gPad->SetLogx(display.find("LogX") != std::string::npos);
1774  }
1775  axisOption(display, h);
1776  h->Draw(drawopt.c_str());
1777  }
1778  myC->cd();
1779  displayExtra(myC.get(), display);
1780  myC->RedrawAxis();
1781 
1782  if (hRef) {
1783  ratioplot(myC.get(), h, hRef, display); // RatioPad
1784  }
1785  myC->cd(); // might be unnecessary
1786  polynomial(myC.get(), display, h); // draw polynome for TH1
1787 
1788  TLatex t;
1789  t.SetNDC();
1790  t.SetTextSize(0.03);
1791  t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1792  TLatex tt;
1793  tt.SetNDC();
1794  tt.SetTextSize(0.03);
1795  tt.DrawLatex(0.02, 0.01, pathName.c_str());
1796 
1797  convertToGraphics(cnvsType, myC.get(), json, &img, &x, &y);
1798  }
1799  // delete myC;
1800  gStyle->Reset();
1801  }
1802  if (g) {
1803  auto myC = std::make_unique<TCanvas>(nameHis.c_str(), "myC", ww, wh);
1804  myC->cd();
1805  if (g->GetMinimum() >= 0. && g->GetMaximum() > 0.) {
1806  gPad->SetLogy(display.find("LogY") != std::string::npos);
1807  }
1808  // if( BINLOEDGE(h2, 1) > 0) {
1809  // gPad->SetLogx(display.find("LogX")!=std::string::npos );
1810  // }
1811  // gPad->SetLogz(display.find("LogZ")!=std::string::npos );
1812  formatTGraph(myC.get(), g);
1813  // axisOption(display,g);
1814  g->Draw((std::string("AP") + drawopt).c_str());
1815  displayExtra(myC.get(), display);
1816  TLatex t;
1817  t.SetNDC();
1818  t.SetTextSize(0.03);
1819  t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1820  TLatex tt;
1821  tt.SetNDC();
1822  tt.SetTextSize(0.03);
1823  tt.DrawLatex(0.02, 0.01, pathName.c_str());
1824  // myC->SaveAs( name.c_str() );
1825 
1826  convertToGraphics(cnvsType, myC.get(), json, &img, &x, &y);
1827 
1828  gStyle->Reset();
1829  }
1830  if (e != 0) {
1831  hasPlotted = false;
1832  auto myC = std::make_unique<TCanvas>(nameHis.c_str(), "myC", ww, wh);
1833  formatTEfficiency(myC.get(), e);
1834  if (drawopt == "") {
1835  if (e->GetDimension() == 1) {
1836  drawopt = "AP";
1837  } else {
1838  drawopt = "COLZ";
1839  }
1840  }
1841  if (drawRefs) {
1842  if (file_version == 1) {
1843  groupDir->cd((nameHis + "_/Results").c_str());
1844  gDirectory->GetObject("Reference;1", ref);
1845  } else if (file_version == 2) {
1846  if (groupDir->cd((nameHis + "_").c_str())) {
1847  gDirectory->GetObject("Reference;1", ref);
1848  }
1849  }
1850  eRef = dynamic_cast<TEfficiency*>(ref);
1851  if (eRef) {
1852  eRefs.push_back(eRef);
1853  } else {
1854  TCollection* colln = dynamic_cast<TCollection*>(ref);
1855  if (colln) {
1856  WasCollectionReference = true;
1857  TIterator* icolln = colln->MakeIterator();
1858  TObject* ref2;
1859  while ((ref2 = icolln->Next())) {
1860  eRef = dynamic_cast<TEfficiency*>(ref2);
1861  if (eRef) {
1862  if (eRef->GetDimension() == e->GetDimension()) {
1863  eRefs.push_back(eRef);
1864  }
1865  } else std::cout << "eRef cast failed!!!" << std::endl;
1866  }
1867  }
1868  }
1869  groupDir->cd();
1870  }
1871  if (eRefs.size() > 0) {
1872  legend = new TLegend(0.55, 0.77, 0.87, 0.87);
1873  legend->SetTextFont(62);
1874  legend->SetMargin(0.15);
1875  legend->SetFillStyle(0);
1876  legend->SetBorderSize(0);
1877  legend->AddEntry(e, datatitle.c_str());
1878  int itrcolor(0);
1879  for (auto eRef : eRefs) {
1880  myC->cd();
1881  e->Draw("");
1882  eRef->Draw("");
1883  gPad->Update();
1884 
1885  int local_color = root_color_choices[itrcolor];
1886  itrcolor++;
1887 
1888  formatTEfficiency(myC.get(), eRef);
1889  eRef->SetMarkerColor(local_color);
1890  eRef->SetLineColor(local_color);
1891 
1892  if (!hasPlotted) {
1893  e->Draw(drawopt.c_str());
1894  hasPlotted = true;
1895  }
1896  eRef->Draw("SAME");
1897  myC->Update();
1898 
1899  if (WasCollectionReference) {
1900  legend->AddEntry(eRef, eRef->GetName());
1901  } else {
1902  std::string refInfo("");
1903  refInfo = getStringName(pathname + "/" + nameHis + "_/Config/annotations/refInfo", file_version);
1904  legend->AddEntry(eRef, refInfo != "Undefined" ? refInfo.c_str() : "Reference");
1905  }
1906  }
1907  legend->Draw();
1908  } else {
1909  myC->cd();
1910  e->Draw(drawopt.c_str());
1911  }
1912 
1913  // Fix to display x axis title
1914  myC->Update();
1915  e->GetPaintedGraph()->GetXaxis()->SetTitleColor();
1916 
1917  myC->cd();
1918  displayExtra(myC.get(), display);
1919  TLatex t;
1920  t.SetNDC();
1921  t.SetTextSize(0.03);
1922  t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1923  TLatex tt;
1924  tt.SetNDC();
1925  tt.SetTextSize(0.03);
1926  tt.DrawLatex(0.02, 0.01, pathName.c_str());
1927  convertToGraphics(cnvsType, myC.get(), json, &img, &x, &y);
1928  gStyle->Reset();
1929  }
1930  std::string rv;
1931  if (cnvsType & GENERATE_PNG) {
1932  if (x) rv.assign(x, y);
1933  }
1934  ;
1935  std::pair<std::string, std::string> rvPair {
1936  rv, json
1937  };
1938  //deallocate image buffer with free(x), see https://root.cern.ch/doc/master/classTASImage.html
1939  free(x);
1940  delete hobj;
1941  delete ref;
1942  delete legend;
1943  return rvPair;
1944  }

◆ getHistogramJSON()

std::pair< std::string, std::string > dqutils::HanOutputFile::getHistogramJSON ( const std::string &  nameHis,
TDirectory *  groupDir,
bool  drawRefs,
const std::string &  run_min_LB,
const std::string &  pathName 
)
virtual

Definition at line 1174 of file HanOutputFile.cxx.

1176  {
1177  int cnvsType = 2;
1178 
1179  return getHistogram(nameHis, groupDir, drawRefs, run_min_LB, pathName, cnvsType);
1180  }

◆ getHistogramPNG()

std::string dqutils::HanOutputFile::getHistogramPNG ( const std::string &  nameHis,
TDirectory *  groupDir,
bool  drawRefs,
const std::string &  run_min_LB,
const std::string &  pathName 
)
virtual

Definition at line 1166 of file HanOutputFile.cxx.

1168  {
1169  int cnvsType = 1;
1170 
1171  return getHistogram(nameHis, groupDir, drawRefs, run_min_LB, pathName, cnvsType).first;
1172  }

◆ getIndentation()

std::string dqutils::HanOutputFile::getIndentation ( const std::string &  pathName,
const std::string &  leadingSpace = "" 
)
static

Definition at line 620 of file HanOutputFile.cxx.

620  {
621  std::string space = leadingSpace;
622  std::string::size_type i = pathName.find_first_of('/');
623  if (i != std::string::npos) {
624  std::string subPath(pathName, i + 1, std::string::npos);
625  space += " ";
626  return getIndentation(subPath, space);
627  }
628  return space;
629  }

◆ getInfo() [1/2]

std::string dqutils::HanOutputFile::getInfo ( const std::string &  JSON_str)
static

Definition at line 579 of file HanOutputFile.cxx.

579  {
581  std::string value("");
582  nlohmann::ordered_json j = nlohmann::ordered_json::parse(JSON_str);
584  return value;
585  }

◆ getInfo() [2/2]

std::string dqutils::HanOutputFile::getInfo ( const std::string &  location,
int  file_version 
)
static

Definition at line 475 of file HanOutputFile.cxx.

475  {
477  std::string value("");
478  if (file_version == 1) {
479  gROOT->cd(location.c_str());
480  TIter mylist(gDirectory->GetListOfKeys());
481  TKey* key;
482  while ((key = dynamic_cast<TKey*>(mylist.Next())) != 0) {
483  TObject* obj = key->ReadObj();
484  TDirectory* subdir = dynamic_cast<TDirectory*>(obj);
485  if (subdir != 0) {
486  std::string name_subdir = subdir->GetName();
487  gROOT->cd((location + "/" + name_subdir).c_str());
488  TIter mylist1(gDirectory->GetListOfKeys());
489  TKey* key1;
490  while ((key1 = dynamic_cast<TKey*>(mylist1.Next())) != 0) {
491  TObject* obj1 = key1->ReadObj();
492  TDirectory* subsubdir = dynamic_cast<TDirectory*>(obj1);
493  if (subsubdir != 0) {
494  std::string name_subsubdir = obj1->GetName();
495  gROOT->cd((location + "/" + name_subdir + "/" + name_subsubdir).c_str());
496  TIter mylist2(gDirectory->GetListOfKeys());
497  TKey* key2;
498  while ((key2 = dynamic_cast<TKey*>(mylist2.Next())) != 0) {
499  TObject* obj2 = key2->ReadObj();
500  TDirectory* finaldir = dynamic_cast<TDirectory*>(obj2);
501  if (finaldir != 0) {
502  std::string name_finaldir = obj2->GetName();
503  gROOT->cd((location + "/" + name_subdir + "/" + name_subsubdir + "/" + name_finaldir).c_str());
504  TIter mylist3(gDirectory->GetListOfKeys());
505  TKey* key3;
506  while ((key3 = dynamic_cast<TKey*>(mylist3.Next())) != 0) {
507  TObject* obj3 = key3->ReadObj();
508  std::string value_info = obj3->GetName();
509  value += (name_subsubdir + name_finaldir + ": " + value_info + " ");
510  delete obj3;
511  }
512  gROOT->cd((location + "/" + name_subdir + "/" + name_subsubdir).c_str());
513  } else if (name_subsubdir != "name" && name_subsubdir != "Status" && name_subsubdir != "display") {
514  // else if(name_subsubdir!="name" && name_subsubdir!="Status"){
515  std::string value_info = obj2->GetName();
516  value += (name_subsubdir + ": " + value_info + " ");
517  }
518  delete obj2;
519  }
520  gROOT->cd((location + "/" + name_subdir).c_str());
521  } else if (name_subdir != "name" && name_subdir != "Status") {
522  std::string value_info = obj1->GetName();
523  value += (name_subdir + ": " + value_info + " ");
524  }
525  delete obj1;
526  }
527  gROOT->cd((location).c_str());
528  }
529  delete obj;
530  }
531  } else if (file_version == 2) {
532  // Separate Tdirectory from the JSON file. JSON File starts with Results or Config Node
533  std::string JSON_name(""); // Results or Config
534  std::string TDir_path(""); // Path befor Results
535  std::string path_inJSON(""); // Path after Results
536  std::size_t split_point = 0;
537  if ((split_point = location.rfind("/Results")) != std::string::npos) {
538  JSON_name = "Results";
539  TDir_path = location.substr(0, split_point);
540  path_inJSON = location.substr(split_point + 8); // 8 - is the length of "/Results"
541  } else if ((split_point = location.rfind("/Config")) != std::string::npos) {
542  JSON_name = "Config";
543  TDir_path = location.substr(0, split_point);
544  path_inJSON = location.substr(split_point + 7); // 7 - is the length of "/Config"
545  }
546  // Go to TDirectory path
547  if (gROOT->cd(TDir_path.c_str()) == 0) { // Go to Tdirectory, that contains JSON
548  return "Undefined";
549  }
550  // Extract JSON object
551  std::unique_ptr<TObjString> JSON_obj(dynamic_cast<TObjString*>(gDirectory->GetKey(JSON_name.c_str())->ReadObj()));
552  if (not JSON_obj) {
553  std::cerr << "HanOutputFile::getInfo : dynamic cast failed\n";
554  return "Null";
555  }
556  std::string JSON_str = (JSON_obj->GetName());
557  nlohmann::ordered_json j = nlohmann::ordered_json::parse(JSON_str);
558  nlohmann::ordered_json json_in_j;
559  if (path_inJSON != "") {
560  nlohmann::ordered_json::json_pointer JSON_ptr(path_inJSON);
561  try
562  {
563  json_in_j = j.at(JSON_ptr);
564  }
565  catch (...)
566  {
567  // Exception. In case if json_pointer (used above) doesn't exist
568  std::cout << "Wrong path: " << location << "\n";
569  return "Null";
570  }
571  } else {
572  json_in_j = std::move(j);
573  }
574  value = processJSON_ingetInfo(json_in_j);
575  }
576  return value;
577  }

◆ getNEntries() [1/2]

double dqutils::HanOutputFile::getNEntries ( const TObject *  obj)
virtual

Definition at line 461 of file HanOutputFile.cxx.

461  {
462  if (const TH1* h = dynamic_cast<const TH1*>(obj)) {
463  return h->GetEntries();
464  } else if (const TGraph* g = dynamic_cast<const TGraph*>(obj)) {
465  return g->GetN();
466  } else if (const TEfficiency* e = dynamic_cast<const TEfficiency*>(obj)) {
467  return e->GetCopyTotalHisto()->GetEntries();
468  } else {
469  std::cerr << "HanOutputFile::getNEntries(): "
470  << "provided object is not a histogram or graph\n";
471  return 0.0;
472  }
473  }

◆ getNEntries() [2/2]

double dqutils::HanOutputFile::getNEntries ( std::string  location,
std::string  histname 
)
virtual

Definition at line 429 of file HanOutputFile.cxx.

429  {
430  if (m_file == 0) {
431  std::cerr << "HanOutputFile::getNEntries(): "
432  << "No input file is open\n";
433  return 0.0;
434  }
435 
436  double Nentries = 0.0;
437  m_file->cd(location.c_str());
438  // gdirectory->cd(location.c_str() );
439  TH1* h(0);
440  gDirectory->GetObject(histname.c_str(), h);
441  if (h != 0) {
442  Nentries = h->GetEntries();
443  delete h;
444  }
445  TGraph* g(0);
446  gDirectory->GetObject(histname.c_str(), g);
447  if (g != 0) {
448  Nentries = g->GetN();
449  delete g;
450  }
451  TEfficiency* e(0);
452  gDirectory->GetObject(histname.c_str(), e);
453  if (e != 0) {
454  Nentries = e->GetCopyTotalHisto()->GetEntries();
455  delete e;
456  }
457 
458  return Nentries;
459  }

◆ getStringName()

std::string dqutils::HanOutputFile::getStringName ( const std::string &  location,
int  file_version 
)
static

Definition at line 289 of file HanOutputFile.cxx.

289  {
290  std::string stringName("Undefined");
291  if (file_version == 1) {
292  // bool success = gROOT->cd(location.c_str() );
293  // if( !success ) {
294  if (gROOT->cd(location.c_str()) == 0) {
295  // std::cout << "Directory \"" << location << "\" is not in han output file\n";
296  return "Undefined";
297  }
298  TIter mylist(gDirectory->GetListOfKeys());
299  TKey* key;
300  while ((key = dynamic_cast<TKey*>(mylist.Next())) != 0) {
301  TObject* obj = key->ReadObj();
302  stringName = (obj->GetName());
303  delete obj;
304  }
305  return stringName;
306  } else if (file_version == 2) {
307  // Split path to TDirectories part and JSON part
308  // All JSON strings are Results or Config
309  std::size_t split_point = 0;
310  std::string JSON_name(""); // Results or Config
311  std::string path_inTDir(""); // Path befor Results
312  std::string path_inJSON(""); // Path after Results
313  if ((split_point = location.find("/Results/")) != std::string::npos) {
314  JSON_name = "Results";
315  path_inTDir = location.substr(0, split_point);
316  path_inJSON = location.substr(split_point + 8); // 8 - is the length of "/Results"
317  } else if ((split_point = location.find("/Config/")) != std::string::npos) {
318  JSON_name = "Config";
319  path_inTDir = location.substr(0, split_point);
320  path_inJSON = location.substr(split_point + 7); // 7 - is the length of "/Config"
321  }
322  // Go to TDirectory path
323  if (gROOT->cd(path_inTDir.c_str()) == 0) {
324  return "Undefined";
325  }
326  // Extract JSON object
327  TObjString* JSON_obj = dynamic_cast<TObjString*>(gDirectory->GetKey(JSON_name.c_str())->ReadObj());
328  if (not JSON_obj) {
329  std::cerr << "HanOutputFile::getStringName : dynamic cast failed\n";
330  return "Null";
331  }
332  std::string JSON_str = (JSON_obj->GetName());
334  nlohmann::json::json_pointer JSON_ptr(path_inJSON);
335  delete JSON_obj; // Maybe should not be used
336  try
337  {
338  auto val = j.at(JSON_ptr);
339  if (!(val.is_null())) stringName = val.get<std::string>();
340  else return "Null";
341  }
342  catch (...)
343  {
344  // Exception. In case if json_pointer (used above) doesn't exist
345  return "Null";
346  }
347  }
348  return stringName;
349  }

◆ polynomial()

void dqutils::HanOutputFile::polynomial ( TCanvas *  c,
std::string  str,
TH1 *  h 
)
virtual

Definition at line 2885 of file HanOutputFile.cxx.

2885  {
2886  double xmin = h->GetXaxis()->GetXmin();
2887  double xmax = h->GetXaxis()->GetXmax();
2888 
2889  std::size_t found = str.find("polynomial(");
2890  while (found != std::string::npos) {
2891  std::size_t endpos = str.find_first_of(')', found + 1);
2892  std::cout << "found;" << found << " endpos;" << endpos << "count "
2893  << " \n";
2894  std::string inp_str = str.substr(found + 11, endpos - found - 11);
2895  std::size_t found1 = 0;
2896  std::size_t found2 = inp_str.find_first_of(',', found1);
2897  TF1* func = new TF1("func", "pol9", xmin, xmax);
2898  for (int j = 0; j < 10; j++) {
2899  std::string value_str = inp_str.substr(found1, found2 - found1);
2900  double value_double = std::strtod(value_str.c_str(), NULL);
2901  func->SetParameter(j, value_double);
2902  if (found2 == std::string::npos) {
2903  break;
2904  }
2905  found1 = found2 + 1;
2906  found2 = inp_str.find_first_of(',', found1);
2907  }
2908  func->SetNpx(1000);
2909  c->cd();
2910  func->Draw("SAME");
2911  found = str.find("polynomial(", found + 1);
2912  }
2913  }

◆ printAllDQAssessments()

void dqutils::HanOutputFile::printAllDQAssessments ( )
virtual

Definition at line 716 of file HanOutputFile.cxx.

716 {streamAllDQAssessments(std::cout, false);}

◆ printAllDQGroups()

void dqutils::HanOutputFile::printAllDQGroups ( )
virtual

Definition at line 669 of file HanOutputFile.cxx.

669  {
670  if (m_file == 0) {
671  std::cerr << "HanOutputFile::printAllGroupDirs(): "
672  << "No input file is open\n";
673  return;
674  }
675  int file_version = getFileVersion();
676  if (file_version == 1) {
677  if (m_indirMap.size() == 0) {
679  }
680 
681  DirMap_t::const_iterator idirend = m_indirMap.end();
682  for (DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir) {
683  std::string idirName = idir->first;
684  const char* path(idir->second->GetPath());
685  std::cout << "name: " << idirName << ", path: " << path << "\n";
686  }
687  } else if (file_version == 2) {
688  if (m_indirstrMap.size() == 0) {
690  }
691  const char* path_to_file = m_file->GetPath();
692  DirStrMap_t::const_iterator idirend = m_indirstrMap.end();
693  for (DirStrMap_t::const_iterator idir = m_indirstrMap.begin(); idir != idirend; ++idir) {
694  std::string idirName = idir->first; // Actually it's a path
695  TDirectory* dirobj = dynamic_cast<TDirectory*>(idir->second);
696  if (dirobj != 0) { // If the object is a TDirectory type
697  std::string pathname(dirobj->GetPath());
698  std::cout << "name: " << idirName << ", path: " << pathname << "\n";
699  } else {
700  std::cout << "name: " << idirName << ", path: " << path_to_file << idirName << "\n";
701  TObjString* strobj = dynamic_cast<TObjString*>(idir->second);
702  if (not strobj) {
703  std::cerr << "HanOutputFile::printAllGroupDirs(): dynamic cast failed\n";
704  continue;
705  }
706  std::string content = strobj->GetName(); // In ATLAS DQM root files GetName() actually returns the
707  // content rather than the name of a string
708  nlohmann::json j = nlohmann::json::parse(content); // Get JSON object from TObjString
709  printDQGroupJSON(j, idirName, path_to_file); // Recursive parsing and print of the nested Assessment in
710  // the form of TOBJString
711  }
712  }
713  }
714  }

◆ printDQGroupJSON()

void dqutils::HanOutputFile::printDQGroupJSON ( const nlohmann::json j,
const std::string &  location,
const char *  path_to_file 
)
static

Print path - and name of Assessment, represented as JSON TObjString.

Definition at line 266 of file HanOutputFile.cxx.

266  {
267  // Parse our JSON and get all nested Assessments
268  nlohmann::json valuestring;
269  for (nlohmann::json::const_iterator it = j.begin(); it != j.end(); ++it) {
270  std::string sName = location;
271  std::string keyname = it.key();
272  if (keyname != "Config" && keyname != "Results") { // We are now at subAssessments (not at Results and Config
273  // nodes)
274  std::string::size_type i = keyname.find_last_of('_'); // if it's an object, that stores info about histogram
275  if (i != (keyname.size() - 1)) { // We don't store it in a dirstrmap object
276  if (location != "") { // Path to the TObjString
277  sName += "/"; // increment the path for the nested assesment
278  }
279  sName += keyname;
280  std::cout << "name: " << sName << ", path: " << path_to_file << sName << "\n";
281  valuestring = it.value(); // JSON content inside the subAssessment
282  printDQGroupJSON(valuestring, sName, path_to_file); // Recursively print Results/Status, Config/name of this
283  // subAssessment and looking for subsubAssessment
284  }
285  }
286  }
287  }

◆ printHistoAssessments()

void dqutils::HanOutputFile::printHistoAssessments ( )
virtual

Definition at line 718 of file HanOutputFile.cxx.

718 {streamHistoAssessments(std::cout, false);}

◆ processJSON_ingetInfo()

std::string dqutils::HanOutputFile::processJSON_ingetInfo ( const nlohmann::ordered_json &  j)
static

Definition at line 587 of file HanOutputFile.cxx.

587  {
588  std::string value("");
589  for (nlohmann::ordered_json::const_iterator it = j.begin(); it != j.end(); ++it) { // Search in Results/Config node
590  const auto& key = it.key(); // subdir name analog
591  auto val = it.value();
592  if (strcmp(val.type_name(), "object") == 0) { // subsubdir analog
593  for (nlohmann::ordered_json::const_iterator it1 = val.begin(); it1 != val.end(); ++it1) {
594  const auto& key1 = it1.key(); // subsubdir name analog
595  auto val1 = it1.value();
596  if (strcmp(val1.type_name(), "object") == 0) { // finaldir analog
597  for (nlohmann::ordered_json::const_iterator it2 = val1.begin(); it2 != val1.end(); ++it2) {
598  const auto& key2 = it2.key(); // finaldir name analog
599  auto val2 = it2.value(); // leaf
600  value += (key1 + key2 + ": " + val2.get<std::string>() +
601  " "); //.get<std::string is needed to get rid of quotes in cout
602  }
603  } else if (key1 != "name" && key1 != "Status" && key1 != "display") {
604  value += (key1 + ": " + val1.get<std::string>() +
605  " "); //.get<std::string is needed to get rid of quotes in cout
606  }
607  }
608  } else if (key != "name" && key != "Status") {
609  if (val.is_null()) {
610  value += (key + ": null ");
611  } else {
612  value +=
613  (key + ": " + val.get<std::string>() + " "); //.get<std::string is needed to get rid of quotes in cout
614  }
615  }
616  }
617  return value;
618  }

◆ ratioplot()

void dqutils::HanOutputFile::ratioplot ( TCanvas *  myC_main,
TH1 *  h,
TH1 *  href,
std::string  str 
)
virtual

Fixing Error Bars ///

Error Bars fixed ///

Definition at line 2677 of file HanOutputFile.cxx.

2677  {
2678  // this method creates two pads under a main canvas, upperpad with input canvas displayed, lower with ratio plot
2679  // Then it clears the input canvas and draws this newly created in input
2680  // I dont know if it is the best aproach,I used this method to minimize the changes on the main code
2681  if (display.find("RatioPad") == std::string::npos) return;
2682 
2683  unsigned int ww = myC_upperpad->GetWw();
2684  unsigned int wh = myC_upperpad->GetWh();
2685  std::string padname = "PAD";
2686  std::string padname_ratio = "PAD_main";
2687  auto myC_ratiopad = std::make_unique<TCanvas>(padname_ratio.c_str(), "myC_ratiopad", ww, wh);
2688  auto myC_main = std::make_unique<TCanvas>(padname.c_str(), "myC_main", ww, wh);
2689  myC_main->cd();
2690  // producing ratio histogram and plotting it on to myC_ratiopad
2691  myC_ratiopad->cd();
2692  myC_ratiopad->SetTopMargin(0);
2693  myC_ratiopad->SetLogx(display.find("LogX") != std::string::npos);
2694  // TH1F *clonehist=(TH1F*)h->Clone();
2695  // clonehist->Divide(hRef);
2696 
2700  TProfile* phRef = dynamic_cast<TProfile*>(hRef);
2701  TProfile* ph = dynamic_cast<TProfile*>(h);
2702  std::unique_ptr<TH1F> clonehist; // we will release this later, but use a unique_ptr in case we return early
2703  std::unique_ptr<TH1F> clonehistref;
2704  // transform if profiles
2705  if (ph != 0) {
2706  clonehist.reset((TH1F*) ph->ProjectionX());
2707  } else {
2708  clonehist.reset((TH1F*) h->Clone());
2709  if (!clonehist->GetSumw2()) {
2710  clonehist->Sumw2();
2711  }
2712  }
2713  if (phRef != 0) {
2714  clonehistref.reset((TH1F*) phRef->ProjectionX());
2715  } else {
2716  clonehistref.reset((TH1F*) hRef->Clone());
2717  if (!clonehistref->GetSumw2()) {
2718  clonehistref->Sumw2();
2719  }
2720  }
2721  if (!clonehist or !clonehistref) {
2722  return;
2723  }
2724  clonehist->SetBit(kCanDelete);
2725  clonehist->Divide(clonehistref.get());
2728 
2729  formatTH1(myC_ratiopad.get(), clonehist.get());
2730  clonehist->SetTitle("");
2731 
2732  // extract delta value from string that holds the draw options
2733  double delta = 0.75;
2734  if (display.find("delta(") != std::string::npos) {
2735  delta = std::stod(display.substr(display.find("delta(") + 6));
2736  }
2737  clonehist->SetAxisRange(1. - delta, 1. + delta, "Y");
2738 
2739  clonehist->GetYaxis()->SetNdivisions(3, true);
2740  clonehist->SetMarkerStyle(1);
2741  clonehist->Draw("E"); // plots into myC_ratiopad
2742  clonehist->GetXaxis()->SetTitleSize(0.11);
2743  clonehist->GetXaxis()->SetLabelSize(0.11);
2744  clonehist->GetYaxis()->SetTitleSize(0.11);
2745  clonehist->GetYaxis()->SetLabelSize(0.11);
2746  myC_main->cd(); // lowerPad and upperPad plotted into myC_main
2747  TPad* lowerPad = new TPad("lowerPad", "lowerPad", .005, .060, .995, .250); // deleted by myC_main
2748  lowerPad->SetTopMargin(0);
2749  lowerPad->SetFillStyle(0);
2750  lowerPad->Draw();
2751  TPad* upperPad = new TPad("upperPad", "upperPad", .005, .250, .995, .995); // deleted by myC_main
2752  upperPad->SetBottomMargin(0);
2753  upperPad->SetFillStyle(0);
2754  upperPad->Draw();
2755 
2756  lowerPad->cd();
2757  myC_ratiopad->DrawClonePad(); // clone contents of myC_ratiopad to lowerPad (will fix ownership later)
2758  // Draw y=1 lineon ratio plot
2759  TLine line;
2760  line.SetLineColor(kRed);
2761  line.SetLineWidth(1);
2762  // method belove might be a problem when axis range changed
2763  double xmin = clonehist->GetXaxis()->GetXmin();
2764  double xmax = clonehist->GetXaxis()->GetXmax();
2765  // double xmin = BINLOEDGE(clonehist, 1)-BINWIDTH(clonehist, 1);
2766  // double xmax = BINLOEDGE(clonehist, clonehist->GetNbinsX() ) + 2.0*BINWIDTH(clonehist, clonehist->GetNbinsX() ) ;
2767  line.DrawLine(xmin, 1, xmax, 1);
2768  upperPad->cd();
2769  myC_upperpad->SetBottomMargin(0);
2770  myC_upperpad->SetFillStyle(0);
2771  h->GetXaxis()->SetLabelSize(0.);
2772  h->GetXaxis()->SetTitleSize(0.);
2773  myC_upperpad->DrawClonePad(); // clone original canvas (i.e. main plot) into upperPad (will fix ownership later)
2774  myC_upperpad->cd();
2775  myC_upperpad->Clear(); // reset original canvas
2776  myC_main->DrawClonePad(); // clone contents of myC_main back into original canvas (will fix ownership shortly)
2777 
2778  std::ignore = clonehist.release(); // this will be deleted by lowerpad cleanup
2779  // At this point myC_main contains the original lowerPad and upperPad, which contain clones of the original canvas
2780  // and ownership of clonehist. Iterate one level down and mark contained objects as deleteable. This will delete
2781  // the pads, as well as clonehist.
2782  for (TObject* o : *(myC_main->GetListOfPrimitives())) {
2783  o->SetBit(kCanDelete);
2784  if (auto* o2 = dynamic_cast<TPad*>(o)) {
2785  for (auto* o3: *(o2->GetListOfPrimitives())) {
2786  if (!dynamic_cast<TFrame*>(o3)) {
2787  o3->SetBit(kCanDelete);
2788  }
2789  }
2790  }
2791  }
2792  // At this point myC_upperpad contains clones of all its objects, including the pads. None of them have pointers
2793  // outside of myC_upperpad and its contained cloned pads. Mark them all deleteable. The original plot will be
2794  // deleted
2795  // in the calling code.
2796  for (TObject* o : *(myC_upperpad->GetListOfPrimitives())) {
2797  o->SetBit(kCanDelete);
2798  if (auto* o2 = dynamic_cast<TPad*>(o)) {
2799  for (auto* o3: *(o2->GetListOfPrimitives())) {
2800  if (!dynamic_cast<TFrame*>(o3)) {
2801  o3->SetBit(kCanDelete);
2802  }
2803  }
2804  }
2805  }
2806  }

◆ ratioplot2D()

void dqutils::HanOutputFile::ratioplot2D ( TCanvas *  canvas,
TH2 *  h2,
TH2 *  h2Ref,
std::string  display 
)
virtual

Definition at line 2808 of file HanOutputFile.cxx.

2808  {
2809  if (display.find("Ref2DRatio") == std::string::npos && display.find("Ref2DSignif") == std::string::npos) return;
2810 
2811  auto canvas_bot =
2812  std::make_unique<TCanvas>("canvas_bottom", "canvas_bottom", canvas_top->GetWw(), canvas_top->GetWh());
2813  auto canvas_all = std::make_unique<TCanvas>("canvas_all", "canvas_all", canvas_top->GetWw(), canvas_top->GetWh());
2814 
2815  canvas_bot->cd();
2816  canvas_bot->SetTopMargin(0);
2817 
2818  h2Ref->Scale(h2->Integral() / h2Ref->Integral());
2819 
2820  TH2* comparison = (TH2*) (h2->Clone());
2821  comparison->Divide(h2, h2Ref, 1.0, 1.0);
2822  comparison->SetTitle("");
2823  formatTH2(canvas_bot.get(), comparison);
2824 
2825  if (display.find("Ref2DRatio") != std::string::npos) {
2826  comparison->GetZaxis()->SetTitle("ratio to ref.");
2827  comparison->SetAxisRange(0.0, 2.0, "Z");
2828  } else if (display.find("Ref2DSignif") != std::string::npos) {
2829  comparison->GetZaxis()->SetTitle("difference to ref. (#sigma)");
2830  comparison->SetAxisRange(-4.5, 4.5, "Z");
2831 
2832  double value_a = 0;
2833  double value_b = 0;
2834  double sigma_a = 0;
2835  double sigma_b = 0;
2836  double signif = 0;
2837 
2838  for (int binx = 0; binx <= comparison->GetNbinsX(); binx++) {
2839  for (int biny = 0; biny <= comparison->GetNbinsY(); biny++) {
2840  value_a = h2->GetBinContent(binx, biny);
2841  value_b = h2Ref->GetBinContent(binx, biny);
2842 
2843  sigma_a = h2->GetBinError(binx, biny);
2844  sigma_b = h2Ref->GetBinError(binx, biny);
2845 
2846  if (sigma_a == 0 && sigma_b == 0) signif = 0;
2847  else signif = (value_a - value_b) / sqrt((sigma_a * sigma_a + sigma_b * sigma_b));
2848 
2849  comparison->SetBinContent(binx, biny, signif);
2850  }
2851  }
2852  }
2853 
2854  comparison->Draw("colz");
2855 
2856  canvas_all->cd();
2857  TPad* pad_bot = new TPad("pad_bot", "pad_bot", 0.005, 0.060, 0.995, 0.550);
2858  TPad* pad_top = new TPad("pad_top", "pad_top", 0.005, 0.550, 0.995, 0.995);
2859 
2860  pad_bot->SetTopMargin(0);
2861  pad_top->SetBottomMargin(0);
2862 
2863  pad_bot->SetFillStyle(0);
2864  pad_top->SetFillStyle(0);
2865 
2866  pad_bot->Draw();
2867  pad_top->Draw();
2868 
2869  pad_bot->cd();
2870  canvas_bot->DrawClonePad();
2871 
2872  pad_top->cd();
2873  canvas_top->SetBottomMargin(0);
2874  canvas_top->SetFillStyle(0);
2875  h2->GetXaxis()->SetLabelSize(0.);
2876  h2->GetXaxis()->SetTitleSize(0.);
2877  canvas_top->DrawClonePad();
2878  canvas_top->cd();
2879  canvas_top->Clear();
2880 
2881  canvas_all->DrawClonePad();
2882  }

◆ saveAllHistograms()

int dqutils::HanOutputFile::saveAllHistograms ( const std::string &  location,
bool  drawRefs,
const std::string &  run_min_LB,
int  cnvsType = 1 
)
virtual

Definition at line 1079 of file HanOutputFile.cxx.

1080  {
1081  if (m_file == 0) {
1082  std::cerr << "HanOutputFile::saveAllHistograms(): "
1083  << "No input file is open\n";
1084  return 0;
1085  }
1086 
1087  if (m_indirMap.size() == 0) {
1089  }
1090 
1091  int nSaved = 0;
1092 
1093  DirMap_t::const_iterator idirend = m_indirMap.end();
1094  for (DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir) {
1095  DirToAssMap_t::const_iterator aMapIter = m_assessMap.find(idir->first);
1096  if (aMapIter == m_assessMap.end()) {
1097  AssMap_t* aMap = new AssMap_t();
1098  DirToAssMap_t::value_type aMapVal(idir->first, aMap);
1099  aMapIter = m_assessMap.insert(std::move(aMapVal)).first;
1100  getAllAssessments(*aMap, idir->second);
1101  }
1102  AssMap_t::const_iterator aend = aMapIter->second->end();
1103  for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
1104  std::string hisName = ias->first;
1105  std::string hisPath = ias->second;
1106  std::string::size_type sepi = hisPath.find(':');
1107  if (sepi != std::string::npos) {
1108  hisPath = std::string(hisPath, sepi + 1, std::string::npos);
1109  }
1110  std::string completeDir(location);
1111  completeDir += hisPath;
1112  completeDir += "/";
1113  std::cout << "Saving " << completeDir << " " << hisName << std::endl;
1114  try
1115  {
1116  bool isSaved = saveHistogramToFile(
1117  hisName, std::move(completeDir), idir->second, drawRefs, run_min_LB, (hisPath + "/" + hisName), cnvsType);
1118  if (isSaved) ++nSaved;
1119  }
1120  catch (std::exception& e)
1121  {
1122  std::cerr << "Exception caught: " << e.what() << std::endl;
1123  }
1124  }
1125  }
1126  return nSaved;
1127  }

◆ saveFile()

bool dqutils::HanOutputFile::saveFile ( int  cnvsType,
const std::string &  pngfName,
const std::string &  pngContent,
const std::string &  jsonfName,
const std::string &  jsonfContent 
)
protectedvirtual

Definition at line 3223 of file HanOutputFile.cxx.

3225  {
3226  bool png = false;
3227  bool json = false;
3228 
3229  if (cnvsType & GENERATE_PNG) {
3230  png = writeToFile(pngfName, pngContent);
3231  }
3232  if (cnvsType & GENERATE_JSON) {
3233  json = writeToFile(jsonfName, jsonfContent);
3234  }
3235  return(png || json);
3236  }

◆ saveHistogramToFile()

bool dqutils::HanOutputFile::saveHistogramToFile ( const std::string &  nameHis,
std::string  location,
TDirectory *  groupDir,
bool  drawRefs,
const std::string &  run_min_LB,
const std::string &  pathName,
int  cnvsType = 1 
)
virtual

Definition at line 1141 of file HanOutputFile.cxx.

1143  {
1144  std::pair<std::string, std::string> pngAndJson =
1145  getHistogram(nameHis, groupDir, drawRefs, run_min_LB, pathName, cnvsType);
1146  // std::string tosave = getHistogramPNG(nameHis, groupDir, drawRefs, run_min_LB, pathName);
1147  if (pngAndJson.first == "" && pngAndJson.second == "") {
1148  return false;
1149  }
1150  std::string namePNG = nameHis;
1151  std::string nameJSON = nameHis;
1152 
1153  namePNG += ".png";
1154  nameJSON += ".json";
1155 
1156  std::string::size_type i = location.find_last_of('/');
1157  if (i != (location.size() - 1)) {
1158  location += '/';
1159  }
1160 
1161  namePNG = location + namePNG;
1162  nameJSON = location + nameJSON;
1163  return saveFile(cnvsType, namePNG, pngAndJson.first, nameJSON, pngAndJson.second);
1164  }

◆ saveHistogramToFileSuperimposed()

bool dqutils::HanOutputFile::saveHistogramToFileSuperimposed ( const std::string &  nameHis,
std::string  location,
TDirectory *  groupDir1,
TDirectory *  groupDir2,
bool  drawRefs,
const std::string &  run_min_LB,
const std::string &  pathName,
int  cnvsType = 1 
)
virtual

Definition at line 1946 of file HanOutputFile.cxx.

1950  {
1952  groupDir1->cd();
1953  gStyle->SetFrameBorderMode(0);
1954  gStyle->SetFrameFillColor(0);
1955  gStyle->SetCanvasBorderMode(0);
1956  gStyle->SetPadBorderMode(0);
1957  gStyle->SetPadColor(0);
1958  gStyle->SetCanvasColor(0);
1959  gStyle->SetTitleColor(0);
1960  gStyle->SetStatColor(0);
1961  gStyle->SetFillColor(1);
1962  gStyle->SetPalette(1, 0);
1963  gStyle->SetTitleFontSize(0.06);
1964  gStyle->SetTitleH(0.06);
1965  gStyle->SetMarkerStyle(20);
1966  gStyle->SetOptStat(111100);
1967  gStyle->SetStatBorderSize(0);
1968  gStyle->SetStatX(0.99);
1969  gStyle->SetStatY(0.99);
1970  gStyle->SetStatW(0.2);
1971  gStyle->SetStatH(0.1);
1972 
1973  gROOT->SetBatch();
1974  std::string pathname(groupDir1->GetPath());
1975  std::string display = "";
1976  int file_version = getFileVersion();
1977  bool LookForDisplay;
1978  if (file_version == 1) {
1979  LookForDisplay = containsDir("Config/annotations/display", (pathname + "/" + nameHis + "_"));
1980  if (LookForDisplay) {
1981  display = getStringName(pathname + "/" + nameHis + "_/Config/annotations/display", file_version);
1982  }
1983  } else if (file_version == 2) {
1984  std::optional<std::string> JSON_content;
1985  LookForDisplay = containsDir((nameHis + "_"), pathname);
1986  if (LookForDisplay) {
1987  JSON_content = containsKeyInJSON("/annotations/display", "Config", (pathname + "/" + nameHis + "_"));
1988  if (JSON_content) {
1989  LookForDisplay = true;
1990  } else {
1991  LookForDisplay = false;
1992  }
1993  }
1994  if (LookForDisplay) {
1995  display = JSON_content.value();
1996  }
1997  }
1998 
1999  // Look for Draw Options
2000  std::size_t found = display.find("Draw");
2001  std::string drawopt = "";
2002  while (found != std::string::npos) {
2003  std::size_t found1 = display.find_first_of(',', found + 1);
2004  auto temp = display.substr(found + 5, found1 != std::string::npos ? found1 - found - 5 : display.size() );
2005  std::ranges::transform(temp, temp.begin(), [](unsigned char c) { return std::tolower(c); });
2006  drawopt += temp;
2007  found = display.find("Draw", found + 1);
2008  }
2009 
2010  groupDir1->cd();
2011  TKey* hkey = groupDir1->FindKey(nameHis.c_str());
2012  groupDir2->cd();
2013  TKey* hkey2 = groupDir2->FindKey(nameHis.c_str());
2014  if (hkey == 0 || hkey2 == 0) {
2015  std::cerr << "Did not find TKey for \"" << nameHis << "\", will not save this histogram.\n";
2016  return false;
2017  }
2018  groupDir1->cd();
2019  TLegend* legend(0);
2020  TObject* hobj = hkey->ReadObj();
2021  TObject* hobj2 = hkey2->ReadObj();
2022  TH1* hRef(0);
2023  TH1* h(0), *hist2(0);
2024  TH2* h2(0), *h2_2(0), *h2Diff(0);
2025  TGraph* g(0), *g2(0);
2026  TEfficiency* e(0), *e2(0);
2027 
2028  std::string json;
2029  std::string nameJSON = nameHis;
2030  std::string namePNG = nameHis;
2031  namePNG += ".png";
2032  nameJSON += ".json";
2033  std::string::size_type i = location.find_last_of('/');
2034  if (i != (location.size() - 1)) {
2035  location += "/";
2036  }
2037  namePNG = location + namePNG;
2038  nameJSON = location + nameJSON;
2039  std::string AlgoName = getStringName(pathname + "/" + nameHis + "_/Config/name", file_version);
2040  int ww = 550;
2041  int wh = 490;
2042  found = display.find("TCanvas", found + 1);
2043  if (found != std::string::npos) {
2044  std::size_t found1 = display.find_first_of(',', found + 1);
2045  ww = std::atoi((display.substr(found + 8, found1 - found - 8)).c_str());
2046  found = display.find_first_of(')', found1 + 1);
2047  wh = std::atoi((display.substr(found1 + 1, found - found1 - 1)).c_str());
2048  }
2049 
2050  if ((h = dynamic_cast<TH1*>(hobj)) != 0 && (hist2 = dynamic_cast<TH1*>(hobj2)) != 0) {
2051  auto myC = std::make_unique<TCanvas>(nameHis.c_str(), "myC", ww, wh);
2052  setupCanvas(drawopt, display);
2053  attachFits(h, drawopt, display);
2054  /******************* for plotting fit function on top of histogram ******************/
2055 
2056  /*************************************************************************************************************/
2057  std::string tmpdraw(drawopt);
2058  if ((h2 = dynamic_cast<TH2*>(h)) != 0 && ((h2_2 = dynamic_cast<TH2*>(hist2)) != 0)) {
2059  // if(tmpdraw=="")
2060  h2Diff = (TH2*) h2->Clone("difference");
2061  // tmpdraw="box";//we don't want colz for overlaid histos
2062  // h2->SetLineColor(2);
2063  // h2->SetMarkerColor(2);
2064  // if(!drawH2(myC,h2,tmpdraw,display))return false;
2065  // h2_2->SetMarkerColor(4);
2066  // //h2_2->SetFillColor(4);
2067  // h2_2->SetLineWidth(2);
2068  // h2_2->SetLineColor(4);
2069  // tmpdraw=" box same";
2070  // if(!drawH2(myC,h2_2,tmpdraw,display))return false;
2071  h2Diff->Add(h2, h2_2, 1.0, -1.0);
2072  h2Diff->SetLineColor(2);
2073  h2Diff->SetMarkerColor(2);
2074  if (!drawH2(myC.get(), h2Diff, tmpdraw, display)) return false;
2075 
2076  TLatex t;
2077  t.SetNDC();
2078  t.SetTextSize(0.03);
2079  t.DrawLatex(0.02, 0.04, (run_min_LB + " difference").c_str());
2080  TLatex tt;
2081  tt.SetNDC();
2082  tt.SetTextSize(0.03);
2083  tt.DrawLatex(0.02, 0.01, pathName.c_str());
2084 
2085  convertToGraphics(cnvsType, myC.get(), namePNG, nameJSON);
2086  } else if (h != 0 && hist2 != 0) {
2087  // Petronel
2088  double scale = 1.0;
2089  if (display.find("ScaleRef") != std::string::npos) {
2090  scale = getScaleVal(display);
2091  } else if (h->Integral("width") > 0.0 && hist2->Integral("width") > 0.0 &&
2092  (AlgoName.find("BinContentComp") == std::string::npos) &&
2093  (display.find("NoNorm") == std::string::npos)) {
2094  scale = h->Integral("width") / hist2->Integral("width");
2095  }
2096  hist2->Scale(scale);
2097  double ymin = (hist2->GetMinimum() < h->GetMinimum()) ? hist2->GetMinimum() : h->GetMinimum();
2098  double ymax = (hist2->GetMaximum() > h->GetMaximum()) ? hist2->GetMaximum() : h->GetMaximum();
2099  double yMargin = (ymax - ymin) * 0.05;
2100  h->SetAxisRange(ymin - yMargin, ymax + yMargin, "Y");
2101 
2102  h->SetMarkerColor(1);
2103  h->SetFillStyle(0);
2104  h->SetLineWidth(2);
2105  hist2->SetMarkerColor(4);
2106  hist2->SetLineColor(4);
2107  hist2->SetFillStyle(0);
2108  hist2->SetLineWidth(2);
2109  if (drawRefs) {
2110  if (file_version == 1) {
2111  groupDir1->cd((nameHis + "_/Results").c_str());
2112  } else {
2113  groupDir1->cd((nameHis + "_").c_str());
2114  }
2115  gDirectory->GetObject("Reference;1", hRef);
2116  groupDir1->cd();
2117  }
2118  if (!drawH1(myC.get(), h, hRef, tmpdraw, display, AlgoName)) return false;
2119 
2120  tmpdraw += "same";
2121  if (!drawH1(myC.get(), hist2, 0, tmpdraw, display, AlgoName)) return false;
2122 
2123  legend = new TLegend(0.55, 0.77, 0.87, 0.87);
2124  legend->SetTextFont(62);
2125  legend->SetMargin(0.15);
2126  legend->SetFillStyle(0);
2127  legend->SetBorderSize(0);
2128 
2129  std::size_t foundN1 = run_min_LB.find_first_of("-");
2130  std::size_t foundN2 = run_min_LB.find_first_of(',');
2131 
2132  legend->AddEntry(h, ("Run " + run_min_LB.substr(5, foundN1 - 5)).c_str());
2133  legend->AddEntry(hist2, ("Run " + run_min_LB.substr(foundN1 + 1, foundN2 - foundN1 - 1)).c_str());
2134  if (hRef) {
2135  legend->AddEntry(hRef, "Reference");
2136  }
2137  legend->Draw();
2138 
2139  TLatex t;
2140  t.SetNDC();
2141  t.SetTextSize(0.03);
2142  t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2143  TLatex tt;
2144  tt.SetNDC();
2145  tt.SetTextSize(0.03);
2146  tt.DrawLatex(0.02, 0.01, pathName.c_str());
2147 
2148  convertToGraphics(cnvsType, myC.get(), namePNG, nameJSON);
2149  } // end histogram drawing
2150  delete h2Diff;
2151  gStyle->Reset();
2152  }
2153 
2154  /*************************************************************************************************************/
2155  if (((g = dynamic_cast<TGraph*>(hobj)) != 0) && ((g2 = dynamic_cast<TGraph*>(hobj2)) != 0)) {
2156  auto myC = std::make_unique<TCanvas>(nameHis.c_str(), "myC", ww, wh);
2157  myC->cd();
2158  if (g->GetMinimum() >= 0. && g2->GetMinimum() >= 0. && g->GetMaximum() > 0. && g2->GetMaximum() > 0.) {
2159  gPad->SetLogy(display.find("LogY") != std::string::npos);
2160  }
2161  formatTGraph(myC.get(), g);
2162  formatTGraph(myC.get(), g2);
2163  g->Draw((std::string("AP") + drawopt).c_str());
2164  displayExtra(myC.get(), display);
2165  g2->SetMarkerColor(2);
2166  g2->SetLineColor(2);
2167  g2->Draw((std::string("P") + drawopt + " same").c_str());
2168  TLatex t;
2169  t.SetNDC();
2170  t.SetTextSize(0.03);
2171  t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2172  TLatex tt;
2173  tt.SetNDC();
2174  tt.SetTextSize(0.03);
2175  tt.DrawLatex(0.02, 0.01, pathName.c_str());
2176 
2177  convertToGraphics(cnvsType, myC.get(), namePNG, nameJSON);
2178 
2179  gStyle->Reset();
2180  }
2181 
2182  if (((e = dynamic_cast<TEfficiency*>(hobj)) != 0) && ((e2 = dynamic_cast<TEfficiency*>(hobj2)) != 0)) {
2183  auto myC = std::make_unique<TCanvas>(nameHis.c_str(), "myC", ww, wh);
2184  myC->cd();
2185 
2186  formatTEfficiency(myC.get(), e);
2187  formatTEfficiency(myC.get(), e2);
2188  e->Draw((std::string("AP") + drawopt).c_str());
2189 
2190  // Fix to display x axis title
2191  myC->Update();
2192  e->GetPaintedGraph()->GetXaxis()->SetTitleColor();
2193 
2194  displayExtra(myC.get(), display);
2195  e2->SetMarkerColor(2);
2196  e2->SetLineColor(2);
2197  e2->Draw((std::string("P") + drawopt + " same").c_str());
2198  TLatex t;
2199  t.SetNDC();
2200  t.SetTextSize(0.03);
2201  t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2202  TLatex tt;
2203  tt.SetNDC();
2204  tt.SetTextSize(0.03);
2205  tt.DrawLatex(0.02, 0.01, pathName.c_str());
2206 
2207  convertToGraphics(cnvsType, myC.get(), namePNG, std::move(nameJSON));
2208 
2209  gStyle->Reset();
2210  }
2211 
2212  delete hobj;
2213  delete hobj2;
2214  delete hRef;
2215  delete legend;
2216  return true;
2217  }

◆ setFile()

bool dqutils::HanOutputFile::setFile ( const std::string &  fileName)
virtual

Clears all previous data and opens the file with the given name for analysis, returning a boolean indicating whether the file was opened successfully or not.

Definition at line 631 of file HanOutputFile.cxx.

631  {
632  clearData();
633  if (fileName == "") return false;
634 
635  m_file = TFile::Open(fileName.c_str());
636  if (m_file != 0) return true;
637 
638  return false;
639  }

◆ setupCanvas()

void dqutils::HanOutputFile::setupCanvas ( std::string &  drawopt,
std::string &  display 
)
virtual

Definition at line 2261 of file HanOutputFile.cxx.

2261  {
2262  gPad->SetGridx(display.find("SetGridx") != std::string::npos);
2263  gPad->SetGridy(display.find("SetGridy") != std::string::npos);
2264  std::size_t found = display.find("SetPalette");
2265  if (found != std::string::npos) {
2266  std::size_t found1 = display.find_first_of('(', found + 1);
2267  std::size_t found2 = display.find_first_of(",)", found + 1);
2268  std::string cn = display.substr(found1 + 1, found2 - found1 - 1);
2269  int n1 = std::strtol(cn.c_str(), NULL, 0);
2270  gStyle->SetPalette((Int_t) n1);
2271  }
2272  found = display.find("SetGridStyle");
2273  if (found != std::string::npos) {
2274  std::size_t found1 = display.find_first_of('(', found + 1);
2275  std::size_t found2 = display.find_first_of(",)", found + 1);
2276  std::string cn = display.substr(found1 + 1, found2 - found1 - 1);
2277  int n1 = std::strtol(cn.c_str(), NULL, 0);
2278  gStyle->SetGridStyle((Style_t) n1);
2279  }
2280  if (!drawopt.empty()) {
2281  // do any modifications coming from drawopt
2282  }
2283  }

◆ streamAllDQAssessments()

void dqutils::HanOutputFile::streamAllDQAssessments ( std::ostream &  o,
bool  streamAll 
)
virtual

Definition at line 777 of file HanOutputFile.cxx.

777  {
778  if (m_file == 0) {
779  std::cerr << "HanOutputFile::streamAllDQAssessments(): "
780  << "No input file is open\n";
781  return;
782  }
783 
784  int file_version = getFileVersion();
785 
786  if ((file_version == 1) || (file_version == 2)) {
787  if (m_indirMap.size() == 0) {
789  }
790 
791  DirMap_t::const_iterator idirend = m_indirMap.end();
792  for (DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir) {
793  std::string idirName = idir->first;
794  std::string pathname(idir->second->GetPath());
795  std::string::size_type i = pathname.find_last_of('/');
796  if (i != (pathname.size() - 1)) {
797  pathname += "/";
798  }
799  std::string pathnameS = pathname + "Results/Status";
800  std::string pathnameA = pathname + "Config/name";
801  std::string idirStatus = getStringName(pathnameS, file_version);
802  std::string idirAlg = getStringName(pathnameA, file_version);
803  std::string indent = (idirName == "<top_level>") ? "" : getIndentation(idirName, " ");
804  if (!streamAll) {
805  std::string::size_type idirNamei = idirName.find_last_of('/');
806  if (idirNamei != std::string::npos) {
807  idirName = std::string(idirName, idirNamei + 1, std::string::npos);
808  }
809  }
810  std::string formattedName(indent);
811  formattedName += idirName;
812 
813  // left-align this text
814  const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
815  // set the width of the next item to be printed
816 
817  o.width(40);
818  o << formattedName << " ";
819  // return to normal right-alignment
820  o.setf(std::ios_base::right, std::ios_base::adjustfield);
821  o.width(9);
822  o << idirStatus << " ";
823  o.width(30);
824  o << idirAlg;
825  if (streamAll) {
826  o << " dir\n";
827  } else {
828  o << "\n";
829  }
830  o.flags(savedFlags);
831 
832  DirToAssMap_t::const_iterator aMapIter = m_assessMap.find(idir->first);
833  if (aMapIter == m_assessMap.end()) {
834  AssMap_t* aMap = new AssMap_t();
835  DirToAssMap_t::value_type aMapVal(idir->first, aMap);
836  aMapIter = m_assessMap.insert(std::move(aMapVal)).first;
837  getAllAssessments(*aMap, idir->second);
838  }
839 
840  AssMap_t::const_iterator aend = aMapIter->second->end();
841  std::string info1("");
842  std::string info2("");
843  for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
844  std::string hisName = ias->first;
845  std::string hisPath = ias->second;
846  std::string Path1 = hisPath + "/" + hisName + "_/Results";
847  std::string Path2 = hisPath + "/" + hisName + "_/Config";
848  if (streamAll) {
849  info1 = getInfo(Path1, file_version);
850 
851  info2 = getInfo(Path2, file_version);
852  }
853  std::string formattedHistName(indent);
854  std::string status = getStringName(Path1 + "/Status", file_version);
855  std::string algo = getStringName(Path2 + "/name", file_version);
856  formattedHistName += " ";
857  formattedHistName += hisName;
858  // left-align this text
859  const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
860  // set the width of the next item to be printed
861 
862  o.width(40);
863  o << formattedHistName << " ";
864  // return to normal right-alignment
865  o.setf(std::ios_base::right, std::ios_base::adjustfield);
866  o.width(9);
867  o << status << " ";
868  o.width(30);
869  o << algo;
870  if (streamAll) {
871  // Get information about hsitogram
872  gDirectory->cd(pathname.c_str());
873  TObject* h;
874  // TH1 *h;
875  gDirectory->GetObject(hisName.c_str(), h);
876  std::string hisTitle = h->GetTitle();
877  // Print information about histograms
878  o << " ass entries: " << getNEntries(h) << " ";
879  TH1* h1;
880  if ((h1 = dynamic_cast<TH1*>(h)) && h1->GetDimension() == 1) {
881  o << " Underflow: " << h1->GetBinContent(0) << " Overflow: " << h1->GetBinContent(h1->GetNbinsX() + 1)
882  << " ";
883  }
884  if (info1 != "" && info2 != "") {
885  o << "Config "
886  << "Config " << info2 << " Results "
887  << "Results " << info1 << " title " << hisTitle << "\n";
888  } else if (info1 != "") {
889  o << "Results Results " << info1 << " title " << hisTitle << "\n";
890  } else if (info2 != "") {
891  o << "Config Config " << info2 << " title " << hisTitle << "\n";
892  } else {
893  o << " title " << hisTitle << "\n";
894  }
895  delete h;
896  } else {
897  o << "\n";
898  }
899  o.flags(savedFlags);
900  }
901  }
902  }
903  }

◆ streamAllHistograms()

void dqutils::HanOutputFile::streamAllHistograms ( std::ostream &  o,
bool  streamAll 
)
virtual

Definition at line 971 of file HanOutputFile.cxx.

971  {
972  if (m_file == 0) {
973  std::cerr << "HanOutputFile::streamAllDQAssessments(): "
974  << "No input file is open\n";
975  return;
976  }
977 
978  if (m_indirMap.size() == 0) {
980  }
981 
982  DirMap_t::const_iterator idirend = m_indirMap.end();
983  for (DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir) {
984  std::string idirName = idir->first;
985  std::string pathname(idir->second->GetPath());
986  std::string::size_type i = pathname.find_last_of('/');
987  if (i != (pathname.size() - 1)) {
988  pathname += "/";
989  }
990  std::string idirStatus = "Undefined";
991  std::string idirAlg = "Undefined";
992  std::string indent = (idirName == "<top_level>") ? "" : getIndentation(idirName, " ");
993  if (!streamAll) {
994  std::string::size_type idirNamei = idirName.find_last_of('/');
995  if (idirNamei != std::string::npos) {
996  idirName = std::string(idirName, idirNamei + 1, std::string::npos);
997  }
998  }
999  std::string formattedName(indent);
1000  formattedName += idirName;
1001 
1002  // left-align this text
1003  const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
1004  // set the width of the next item to be printed
1005  o.width(40);
1006  o << formattedName << " ";
1007  // return to normal right-alignment
1008  o.setf(std::ios_base::right, std::ios_base::adjustfield);
1009  o.width(9);
1010  o << idirStatus << " ";
1011  o.width(30);
1012  o << idirAlg;
1013  if (streamAll) {
1014  o << " dir\n";
1015  } else {
1016  o << "\n";
1017  }
1018  o.flags(savedFlags);
1019 
1020  DirToAssMap_t::const_iterator aMapIter = m_assessMap.find(idir->first);
1021  if (aMapIter == m_assessMap.end()) {
1022  AssMap_t* aMap = new AssMap_t();
1023  DirToAssMap_t::value_type aMapVal(idir->first, aMap);
1024  aMapIter = m_assessMap.insert(std::move(aMapVal)).first;
1025  getAllAssessments(*aMap, idir->second);
1026  }
1027 
1028  AssMap_t::const_iterator aend = aMapIter->second->end();
1029  for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
1030  std::string hisName = ias->first;
1031  std::string hisPath = ias->second;
1032  // std::string Path1 = hisPath + "/"+ hisName + "_/Results";
1033  // std::string info1 = getInfo(Path1);
1034  std::string info1, info2;
1035  // std::string Path2 = hisPath + "/"+ hisName + "_/Config";
1036  // std::string info2 = getInfo(Path2);
1037  std::string formattedHistName(indent);
1038  std::string status = "Undefined";
1039  std::string algo = "Undefined";
1040  gDirectory->cd(pathname.c_str());
1041  // TH1 *h;
1042  TObject* h;
1043  gDirectory->GetObject(hisName.c_str(), h);
1044  std::string hisTitle(h->GetTitle());
1045  formattedHistName += " ";
1046  formattedHistName += hisName;
1047  // left-align this text
1048  const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
1049  // set the width of the next item to be printed
1050  o.width(40);
1051  o << formattedHistName << " ";
1052  // return to normal right-alignment
1053  o.setf(std::ios_base::right, std::ios_base::adjustfield);
1054  o.width(9);
1055  o << status << " ";
1056  o.width(30);
1057  o << algo;
1058  if (streamAll) {
1059  o << " ass entries: " << getNEntries(h) << " ";
1060  if (info1 != "" && info2 != "") {
1061  o << "Config "
1062  << "Config " << info2 << " Results "
1063  << "Results " << info1 << " title " << hisTitle << "\n";
1064  } else if (info1 != "") {
1065  o << "Results Results " << info1 << " title " << hisTitle << "\n";
1066  } else if (info2 != "") {
1067  o << "Config Config " << info2 << " title " << hisTitle << "\n";
1068  } else {
1069  o << " title " << hisTitle << "\n";
1070  }
1071  } else {
1072  o << "\n";
1073  }
1074  o.flags(savedFlags);
1075  }
1076  }
1077  }

◆ streamHistoAssessments()

void dqutils::HanOutputFile::streamHistoAssessments ( std::ostream &  o,
bool  streamAll 
)
virtual

Definition at line 905 of file HanOutputFile.cxx.

905  {
906  if (m_file == 0) {
907  std::cerr << "HanOutputFile::streamHistoAssessments(): "
908  << "No input file is open\n";
909  return;
910  }
911 
912  if (m_indirMap.size() == 0) {
914  }
915 
916  DirMap_t::const_iterator idirend = m_indirMap.end();
917  for (DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir) {
918  std::string idirName = idir->first;
919  std::string pathname(idir->second->GetPath());
920  std::string::size_type i = pathname.find_last_of('/');
921  if (i != (pathname.size() - 1)) {
922  pathname += "/";
923  }
924  std::string idirStatus = "Undefined";
925  std::string idirAlg = "Undefined";
926  std::string indent = (idirName == "<top_level>") ? "" : getIndentation(idirName, " ");
927  if (!streamAll) {
928  std::string::size_type idirNamei = idirName.find_last_of('/');
929  if (idirNamei != std::string::npos) {
930  idirName = std::string(idirName, idirNamei + 1, std::string::npos);
931  }
932  }
933  std::string formattedName;
934  formattedName += idirName;
935 
936  DirToAssMap_t::const_iterator aMapIter = m_assessMap.find(idir->first);
937  if (aMapIter == m_assessMap.end()) {
938  AssMap_t* aMap = new AssMap_t();
939  DirToAssMap_t::value_type aMapVal(idir->first, aMap);
940  aMapIter = m_assessMap.insert(std::move(aMapVal)).first;
941  getAllAssessments(*aMap, idir->second);
942  }
943 
944  AssMap_t::const_iterator aend = aMapIter->second->end();
945  for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
946  std::string hisName = ias->first;
947  std::string hisPath = ias->second;
948  std::string formattedHistName;
949  gDirectory->cd(pathname.c_str());
950  // TH1 *h;
951  TObject* h;
952  gDirectory->GetObject(hisName.c_str(), h);
953  std::string hisTitle(h->GetTitle());
954  formattedHistName += "";
955  formattedHistName += hisName;
956  // left-align this text
957  const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
958  o.width(40);
959 
960  if (streamAll) {
961  o << hisPath << "/" << formattedHistName << " "
962  << "\n";
963  } else {
964  o << "\n";
965  }
966  o.flags(savedFlags);
967  }
968  }
969  }

◆ stringAllDQAssessments()

std::string dqutils::HanOutputFile::stringAllDQAssessments ( )
virtual

Definition at line 759 of file HanOutputFile.cxx.

759  {
760  std::ostringstream result;
762  return result.str();
763  }

◆ stringAllHistograms()

std::string dqutils::HanOutputFile::stringAllHistograms ( )
virtual

Definition at line 771 of file HanOutputFile.cxx.

771  {
772  std::ostringstream result;
774  return result.str();
775  }

◆ stringHistoAssessments()

std::string dqutils::HanOutputFile::stringHistoAssessments ( )
virtual

Definition at line 765 of file HanOutputFile.cxx.

765  {
766  std::ostringstream result;
768  return result.str();
769  }

◆ stringListSystemPaths()

std::string dqutils::HanOutputFile::stringListSystemPaths ( std::string  location)
virtual

Definition at line 720 of file HanOutputFile.cxx.

720  {
721  if (m_file == 0) {
722  std::cerr << "HanOutputFile::stringListSystemPaths(): "
723  << "No input file is open\n";
724  return "";
725  }
726 
727  if (m_indirMap.size() == 0) {
729  }
730 
731  std::string result("");
732 
733  DirMap_t::const_iterator idirend = m_indirMap.end();
734  for (DirMap_t::const_iterator idir = m_indirMap.begin(); idir != idirend; ++idir) {
735  DirToAssMap_t::const_iterator aMapIter = m_assessMap.find(idir->first);
736  if (aMapIter == m_assessMap.end()) {
737  AssMap_t* aMap = new AssMap_t();
738  DirToAssMap_t::value_type aMapVal(idir->first, aMap);
739  aMapIter = m_assessMap.insert(std::move(aMapVal)).first;
740  getAllAssessments(*aMap, idir->second);
741  }
742 
743  AssMap_t::const_iterator ias = aMapIter->second->begin();
744  if (ias != aMapIter->second->end()) {
745  std::string hisPath = ias->second;
746  std::string::size_type sepi = hisPath.find(':');
747  if (sepi != std::string::npos) {
748  hisPath = std::string(hisPath, sepi + 1, std::string::npos);
749  }
750  std::string completeDir(location);
751  completeDir += hisPath;
752  result += completeDir;
753  result += " ";
754  }
755  }
756  return result;
757  }

◆ writeToFile()

bool dqutils::HanOutputFile::writeToFile ( const std::string &  fName,
const std::string &  content 
)
protectedvirtual

Definition at line 3192 of file HanOutputFile.cxx.

3192  {
3193  std::ofstream outfile(fname);
3194  if (!outfile.is_open()) {
3195  std::cerr << "Error writing file to " << fname << std::endl;
3196  return false;
3197  }
3198  outfile << content;
3199  outfile.close();
3200  return true;
3201  }

Member Data Documentation

◆ GENERATE_JSON

const int dqutils::HanOutputFile::GENERATE_JSON = 2
static

Definition at line 96 of file HanOutputFile.h.

◆ GENERATE_PNG

const int dqutils::HanOutputFile::GENERATE_PNG = 1
static

cnvsType: 1=pngOnly;2=jsonOnly;3=pngAndJson

Definition at line 95 of file HanOutputFile.h.

◆ m_assessMap

DirToAssMap_t dqutils::HanOutputFile::m_assessMap
protected

Same Dim_indirMaprMap, but for files of version 2.

Definition at line 181 of file HanOutputFile.h.

◆ m_file

TFile* dqutils::HanOutputFile::m_file
protected

Definition at line 178 of file HanOutputFile.h.

◆ m_indirMap

DirMap_t dqutils::HanOutputFile::m_indirMap
protected

Definition at line 179 of file HanOutputFile.h.

◆ m_indirstrMap

DirStrMap_t dqutils::HanOutputFile::m_indirstrMap
protected

Definition at line 180 of file HanOutputFile.h.

◆ m_style

TStyle* dqutils::HanOutputFile::m_style
protected

Definition at line 182 of file HanOutputFile.h.


The documentation for this class was generated from the following files:
dqutils::HanOutputFile::formatTEfficiency
virtual void formatTEfficiency(TCanvas *c, TEfficiency *e) const
Definition: HanOutputFile.cxx:3159
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:215
dqutils::HanOutputFile::drawH1
virtual bool drawH1(TCanvas *canv, TH1 *hist, TH1 *reference, std::string &drawopt, std::string &display, std::string &AlgoName)
Definition: HanOutputFile.cxx:2427
ymin
double ymin
Definition: listroot.cxx:63
get_generator_info.result
result
Definition: get_generator_info.py:21
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
dqutils::HanOutputFile::axisOption
virtual void axisOption(std::string str, TH1 *h)
Definition: HanOutputFile.cxx:2580
dqutils::HanOutputFile::getInfo
static std::string getInfo(const std::string &location, int file_version)
Definition: HanOutputFile.cxx:475
json
nlohmann::json json
Definition: HistogramDef.cxx:9
rootconvert.fName
string fName
Definition: rootconvert.py:5
dqutils::HanOutputFile::getAllAssessments
static void getAllAssessments(AssMap_t &dirmap, TDirectory *dir)
Definition: HanOutputFile.cxx:248
dqutils::HanOutputFile::m_assessMap
DirToAssMap_t m_assessMap
Same Dim_indirMaprMap, but for files of version 2.
Definition: HanOutputFile.h:181
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:217
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1113
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
skel.it
it
Definition: skel.GENtoEVGEN.py:407
dirname
std::string dirname(std::string name)
Definition: utils.cxx:200
dqutils::HanOutputFile::drawH2
virtual bool drawH2(TCanvas *canv, TH2 *hist, std::string &drawopt, std::string &display)
!!
Definition: HanOutputFile.cxx:2219
dqutils::HanOutputFile::ratioplot
virtual void ratioplot(TCanvas *myC_main, TH1 *h, TH1 *href, std::string str)
Definition: HanOutputFile.cxx:2677
dqutils::HanOutputFile::getNEntries
virtual double getNEntries(std::string location, std::string histname)
Definition: HanOutputFile.cxx:429
ReadCellNoiseFromCoolCompare.obj2
obj2
Definition: ReadCellNoiseFromCoolCompare.py:303
athena.value
value
Definition: athena.py:124
dqutils::HanOutputFile::polynomial
virtual void polynomial(TCanvas *c, std::string str, TH1 *h)
Definition: HanOutputFile.cxx:2885
dqutils::HanOutputFile::getAllGroupDirs
static void getAllGroupDirs(DirMap_t &dirmap, TDirectory *dir, const std::string &dirName)
Definition: HanOutputFile.cxx:119
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
PrintTrkAnaSummary.dirName
dirName
Definition: PrintTrkAnaSummary.py:275
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
dqutils::HanOutputFile::setFile
virtual bool setFile(const std::string &fileName)
Clears all previous data and opens the file with the given name for analysis, returning a boolean ind...
Definition: HanOutputFile.cxx:631
x
#define x
dqi::DisableMustClean
Definition: HanUtils.h:30
dqutils::HanOutputFile::processJSON_ingetInfo
static std::string processJSON_ingetInfo(const nlohmann::ordered_json &j)
Definition: HanOutputFile.cxx:587
dq_defect_bulk_create_defects.line
line
Definition: dq_defect_bulk_create_defects.py:27
WriteLumiToCool.val1
val1
Definition: WriteLumiToCool.py:184
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
module_driven_slicing.key2
key2
Definition: module_driven_slicing.py:158
dqutils::HanOutputFile::displayExtra
virtual void displayExtra(TCanvas *c, const std::string &str)
Definition: HanOutputFile.cxx:2915
dqutils::HanOutputFile::m_file
TFile * m_file
Definition: HanOutputFile.h:178
dqutils::HanOutputFile::containsKeyInJSON
static std::optional< std::string > containsKeyInJSON(const std::string &pathInJSON, const std::string &jsonName, const std::string &path_to_JSON)
Checks JSON file for a key (by its path)
Definition: HanOutputFile.cxx:382
dqutils::HanOutputFile::attachFits
virtual void attachFits(TH1 *hist, std::string &drawopt, std::string &display)
Definition: HanOutputFile.cxx:2285
grepfile.content
string content
Definition: grepfile.py:56
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
dqutils::HanOutputFile::getIndentation
static std::string getIndentation(const std::string &pathName, const std::string &leadingSpace="")
Definition: HanOutputFile.cxx:620
covarianceTool.pathName
pathName
Definition: covarianceTool.py:704
dqutils::HanOutputFile::GENERATE_JSON
static const int GENERATE_JSON
Definition: HanOutputFile.h:96
PixelAthClusterMonAlgCfg.histname
histname
Definition: PixelAthClusterMonAlgCfg.py:106
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:37
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
dqutils::HanOutputFile::formatTH2
virtual void formatTH2(TCanvas *c, TH2 *h) const
Definition: HanOutputFile.cxx:3117
lumiFormat.i
int i
Definition: lumiFormat.py:85
xmin
double xmin
Definition: listroot.cxx:60
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
dqutils::HanOutputFile::convertToGraphics
virtual void convertToGraphics(int cnvsType, TCanvas *myC, std::string &json, TImage **img=0, char **x=0, int *y=0)
Definition: HanOutputFile.cxx:3203
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
WriteLumiToCool.val2
val2
Definition: WriteLumiToCool.py:185
dqutils::HanOutputFile::clearData
virtual void clearData()
Definition: HanOutputFile.cxx:3172
extractSporadic.h
list h
Definition: extractSporadic.py:96
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
python.CaloAddPedShiftConfig.str
str
Definition: CaloAddPedShiftConfig.py:42
calibdata.exception
exception
Definition: calibdata.py:495
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
parseDir.wh
wh
Definition: parseDir.py:45
dqutils::HanOutputFile::writeToFile
virtual bool writeToFile(const std::string &fName, const std::string &content)
Definition: HanOutputFile.cxx:3192
dqutils::HanOutputFile::containsDir
static bool containsDir(std::string dirname, std::string maindir)
Definition: HanOutputFile.cxx:351
dqutils::HanOutputFile::formatTH1
virtual void formatTH1(TCanvas *c, TH1 *h) const
Definition: HanOutputFile.cxx:3088
SCT_Monitoring::disabled
@ disabled
Definition: SCT_MonitoringNumbers.h:60
dqutils::HanOutputFile::m_indirMap
DirMap_t m_indirMap
Definition: HanOutputFile.h:179
pyroot.display
display
Definition: pyroot.py:42
dqutils::HanOutputFile::printDQGroupJSON
static void printDQGroupJSON(const nlohmann::json &j, const std::string &location, const char *path_to_file)
Print path - and name of Assessment, represented as JSON TObjString.
Definition: HanOutputFile.cxx:266
beamspotman.dir
string dir
Definition: beamspotman.py:619
dqutils::HanOutputFile::saveFile
virtual bool saveFile(int cnvsType, const std::string &pngfName, const std::string &pngContent, const std::string &jsonfName, const std::string &jsonfContent)
Definition: HanOutputFile.cxx:3223
dqutils::HanOutputFile::setupCanvas
virtual void setupCanvas(std::string &drawopt, std::string &display)
Definition: HanOutputFile.cxx:2261
dqutils::HanOutputFile::getAllGroupDirs_V2
static void getAllGroupDirs_V2(DirStrMap_t &dirstrmap, TObject *obj, const std::string &objName)
Same as getAllGroupDirs, but works with Version 2.3 files.
Definition: HanOutputFile.cxx:165
dqutils::HanOutputFile::streamHistoAssessments
virtual void streamHistoAssessments(std::ostream &o, bool streamAll)
Definition: HanOutputFile.cxx:905
BINWIDTH
#define BINWIDTH(h, n)
Definition: HanOutputFile.cxx:50
plotBeamSpotVxVal.legend
legend
Definition: plotBeamSpotVxVal.py:97
fitman.g2
g2
Definition: fitman.py:624
dqutils::HanOutputFile::formatTGraph
virtual void formatTGraph(TCanvas *c, TGraph *g) const
Definition: HanOutputFile.cxx:3148
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
dqutils::HanOutputFile::ratioplot2D
virtual void ratioplot2D(TCanvas *canvas, TH2 *h2, TH2 *h2Ref, std::string display)
Definition: HanOutputFile.cxx:2808
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:28
dqutils::HanOutputFile::m_indirstrMap
DirStrMap_t m_indirstrMap
Definition: HanOutputFile.h:180
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
dq_make_web_display.rv
def rv
Definition: dq_make_web_display.py:218
dqutils::HanOutputFile::GENERATE_PNG
static const int GENERATE_PNG
cnvsType: 1=pngOnly;2=jsonOnly;3=pngAndJson
Definition: HanOutputFile.h:95
dqutils::HanOutputFile::getHistogram
virtual std::pair< std::string, std::string > getHistogram(const std::string &nameHis, TDirectory *groupDir, bool drawRefs, const std::string &run_min_LB, const std::string &pathName, int cnvsType=1)
Definition: HanOutputFile.cxx:1182
python.changerun.o2
o2
Definition: changerun.py:43
BINLOEDGE
#define BINLOEDGE(h, n)
Definition: HanOutputFile.cxx:49
Rtt_histogram.n1
n1
Definition: Rtt_histogram.py:21
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:66
y
#define y
h
egammaEnergyPositionAllSamples::e2
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
ref
const boost::regex ref(r_ef)
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
dqutils::HanOutputFile::getFileVersion
virtual int getFileVersion()
Definition: HanOutputFile.cxx:641
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
dqutils::root_color_choices
std::vector< int > root_color_choices
Definition: HanOutputFile.cxx:85
dqutils::HanOutputFile::getStringName
static std::string getStringName(const std::string &location, int file_version)
Definition: HanOutputFile.cxx:289
xmax
double xmax
Definition: listroot.cxx:61
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
dqutils::HanOutputFile::saveHistogramToFile
virtual bool saveHistogramToFile(const std::string &nameHis, std::string location, TDirectory *groupDir, bool drawRefs, const std::string &run_min_LB, const std::string &pathName, int cnvsType=1)
Definition: HanOutputFile.cxx:1141
dqutils::HanOutputFile::AssMap_t
std::map< std::string, std::string > AssMap_t
DirMap_t but For Version 2 files.
Definition: HanOutputFile.h:42
pickleTool.object
object
Definition: pickleTool.py:29
str
Definition: BTagTrackIpAccessor.cxx:11
merge.status
status
Definition: merge.py:16
dqutils::HanOutputFile::drawReference
virtual bool drawReference(TCanvas *canv, TH1 *hRef, TH1 *h, std::string &drawopt, std::string &display, std::string &AlgoName)
Definition: HanOutputFile.cxx:2464
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
dqutils::HanOutputFile::m_style
TStyle * m_style
Definition: HanOutputFile.h:182
jobOptions.fileName
fileName
Definition: jobOptions.SuperChic_ALP2.py:39
python.LumiCalcRecover.subdir
subdir
Definition: LumiCalcRecover.py:25
dqutils::HanOutputFile::streamAllHistograms
virtual void streamAllHistograms(std::ostream &o, bool streamAll)
Definition: HanOutputFile.cxx:971
python.PyAthena.obj
obj
Definition: PyAthena.py:132
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:876
DeMoGenerateWWW.maindir
string maindir
Definition: DeMoGenerateWWW.py:15
python.compressB64.c
def c
Definition: compressB64.py:93
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
ymax
double ymax
Definition: listroot.cxx:64
read_hist_ntuple.f1
f1
Definition: read_hist_ntuple.py:4
python.SystemOfUnits.L
float L
Definition: SystemOfUnits.py:92
CompareRootFiles.hist2
hist2
Definition: CompareRootFiles.py:37
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
dqutils::HanOutputFile::streamAllDQAssessments
virtual void streamAllDQAssessments(std::ostream &o, bool streamAll)
Definition: HanOutputFile.cxx:777
module_driven_slicing.key1
key1
Definition: module_driven_slicing.py:157