Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:59

0001 // $Id: $
0002 
0003 /*!
0004  * \file QAHistManagerDef.h
0005  * \brief
0006  * \author Jin Huang <jhuang@bnl.gov>
0007  * \version $Revision:   $
0008  * \date $Date: $
0009  */
0010 
0011 #include "QAHistManagerDef.h"
0012 
0013 #include <fun4all/Fun4AllHistoManager.h>
0014 #include <fun4all/Fun4AllServer.h>
0015 #include <phool/recoConsts.h>
0016 
0017 #include <TAxis.h>
0018 #include <TH1.h>
0019 
0020 #include <cassert>
0021 #include <cmath>
0022 #include <iosfwd>  // for std
0023 
0024 namespace QAHistManagerDef
0025 {
0026   //! Get a pointer to the default hist manager for QA modules
0027   Fun4AllHistoManager *
0028   getHistoManager()
0029   {
0030     Fun4AllServer *se = Fun4AllServer::instance();
0031     Fun4AllHistoManager *hm = se->getHistoManager(HistoManagerName);
0032 
0033     if (not hm)
0034     {
0035       //        std::cout
0036       //            << "QAHistManagerDef::get_HistoManager - Making Fun4AllHistoManager EMCalAna_HISTOS"
0037       //            << std::endl;
0038       hm = new Fun4AllHistoManager(HistoManagerName);
0039       se->registerHistoManager(hm);
0040     }
0041 
0042     assert(hm);
0043 
0044     return hm;
0045   }
0046   std::vector<std::string> tokenize(const std::string& str, const char* delimiter)
0047   {
0048     std::vector<std::string> tokens;
0049   size_t start = 0;
0050   size_t end = str.find(delimiter);
0051 
0052   while (end != std::string::npos)
0053   {
0054     tokens.push_back(str.substr(start, end - start));
0055     start = end + 1;
0056     end = str.find(delimiter, start);
0057   }
0058   tokens.push_back(str.substr(start));
0059 
0060   return tokens;
0061   }
0062   //! Save hist to root files
0063   void saveQARootFile(const std::string &file_name)
0064   {
0065     // add provenance info
0066     std::string build = "";
0067     const std::string offlinemain = getenv("OFFLINE_MAIN");
0068     auto tokens = tokenize(offlinemain,"/");
0069     for(const auto& token : tokens)
0070     {
0071       if(token.find("new") != std::string::npos)
0072     {
0073       build = "new";
0074     }
0075       else if (token.find("ana") != std::string::npos)
0076       {
0077         build = tokens.back();
0078       }
0079     }
0080     auto rc = recoConsts::instance();
0081     std::string dbtag = rc->get_StringFlag("CDB_GLOBALTAG");
0082     std::string info = "Build: " + build + " , dbtag: " + dbtag;
0083     TH1* h = new TH1I("h_QAHistManagerDef_ProductionInfo","",10,0,10);
0084     h->SetTitle(info.c_str());
0085     getHistoManager()->registerHisto(h);
0086     
0087 
0088     // dump histos to file
0089     getHistoManager()->dumpHistos(file_name);
0090   }
0091 
0092   //! utility function to
0093   void useLogBins(TAxis *axis)
0094   {
0095     assert(axis);
0096     assert(axis->GetXmin() > 0);
0097     assert(axis->GetXmax() > 0);
0098 
0099     const int bins = axis->GetNbins();
0100 
0101     Axis_t from = log10(axis->GetXmin());
0102     Axis_t to = log10(axis->GetXmax());
0103     Axis_t width = (to - from) / bins;
0104     std::vector<Axis_t> new_bins(bins + 1);
0105 
0106     for (int i = 0; i <= bins; i++)
0107     {
0108       new_bins[i] = pow(10, from + i * width);
0109     }
0110     axis->Set(bins, new_bins.data());
0111   }
0112 }  // namespace QAHistManagerDef