File indexing completed on 2025-12-16 09:20:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "QAHistManagerDef.h"
0012
0013 #include <fun4all/Fun4AllHistoManager.h>
0014 #include <fun4all/Fun4AllServer.h>
0015
0016 #include <phool/recoConsts.h>
0017
0018 #include <TAxis.h>
0019 #include <TH1.h>
0020 #include <TSystem.h>
0021
0022 #include <cassert>
0023 #include <cmath>
0024 #include <iosfwd> // for std
0025
0026 namespace QAHistManagerDef
0027 {
0028
0029 Fun4AllHistoManager *
0030 getHistoManager()
0031 {
0032 Fun4AllServer *se = Fun4AllServer::instance();
0033 Fun4AllHistoManager *hm = se->getHistoManager(HistoManagerName);
0034
0035 if (!hm)
0036 {
0037
0038
0039
0040 hm = new Fun4AllHistoManager(HistoManagerName);
0041 se->registerHistoManager(hm);
0042 }
0043
0044 assert(hm);
0045
0046 return hm;
0047 }
0048 std::vector<std::string> tokenize(const std::string &str, const char *delimiter)
0049 {
0050 std::vector<std::string> tokens;
0051 size_t start = 0;
0052 size_t end = str.find(delimiter);
0053
0054 while (end != std::string::npos)
0055 {
0056 tokens.push_back(str.substr(start, end - start));
0057 start = end + 1;
0058 end = str.find(delimiter, start);
0059 }
0060 tokens.push_back(str.substr(start));
0061
0062 return tokens;
0063 }
0064
0065 void saveQARootFile(const std::string &file_name)
0066 {
0067
0068 std::string build;
0069 const char *offline_main = getenv("OFFLINE_MAIN");
0070 if (!offline_main)
0071 {
0072 std::cout << "OFFLINE_MAIN not set - this should really not happen, quitting now" << std::endl;
0073 gSystem->Exit(1);
0074 exit(1);
0075 }
0076 const std::string offlinemain = offline_main;
0077 auto tokens = tokenize(offlinemain, "/");
0078 for (const auto &token : tokens)
0079 {
0080 if (token.find("new") != std::string::npos)
0081 {
0082 build = "new";
0083 }
0084 else if (token.find("ana") != std::string::npos)
0085 {
0086 build = tokens.back();
0087 }
0088 }
0089 auto *rc = recoConsts::instance();
0090 std::string dbtag = rc->get_StringFlag("CDB_GLOBALTAG");
0091 std::string info = "Build: " + build + " , dbtag: " + dbtag;
0092 TH1 *h = new TH1I("h_QAHistManagerDef_ProductionInfo", "", 10, 0, 10);
0093 h->SetTitle(info.c_str());
0094 getHistoManager()->registerHisto(h);
0095
0096
0097 getHistoManager()->dumpHistos(file_name);
0098 }
0099
0100
0101 void useLogBins(TAxis *axis)
0102 {
0103 assert(axis);
0104 assert(axis->GetXmin() > 0);
0105 assert(axis->GetXmax() > 0);
0106
0107 const int bins = axis->GetNbins();
0108
0109 Axis_t from = log10(axis->GetXmin());
0110 Axis_t to = log10(axis->GetXmax());
0111 Axis_t width = (to - from) / bins;
0112 std::vector<Axis_t> new_bins(bins + 1);
0113
0114 for (int i = 0; i <= bins; i++)
0115 {
0116 new_bins[i] = pow(10, from + i * width);
0117 }
0118 axis->Set(bins, new_bins.data());
0119 }
0120 }