JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwHistogramHelper.h
Go to the documentation of this file.
1/*!
2 * \file QwHistogramHelper.h
3 * \brief Helper functions and utilities for ROOT histogram management
4 */
5
6/// This class exists to encapsulate several helper functions to aid in
7/// describing histograms.
8/// There will be a global copy defined within the analysis framework.
9
10#pragma once
11
12#include <string>
13#include <vector>
14#include <TString.h>
15#include <TRegexp.h>
16#include <TH1.h>
17#include <TH2.h>
18#include <TProfile.h>
19#include <TProfile2D.h>
20
21#include "QwParameterFile.h"
22#include "QwOptions.h"
23/**
24 * \class QwHistogramHelper
25 * \ingroup QwAnalysis
26 * \brief Utility class for histogram creation and management
27 *
28 * Provides helper functions for creating, configuring, and managing
29 * ROOT histograms with consistent naming and binning conventions
30 * throughout the analysis framework.
31 */
33 public:
34 QwHistogramHelper(): fDEBUG(kFALSE) { fHistParams.clear(); };
35 virtual ~QwHistogramHelper() { };
36
37 /// \brief Define the configuration options
38 static void DefineOptions(QwOptions &options);
39 /// \brief Process the configuration options
40 void ProcessOptions(QwOptions &options);
41
42 void LoadHistParamsFromFile(const std::string& filename);
43 void LoadTreeParamsFromFile(const std::string& filename);
44
45 // Print the histogram parameters
46 void PrintHistParams() const;
47
48 TH1F* Construct1DHist(const TString& inputfile, const TString& name_title) {
49 std::string tmpfile = inputfile.Data();
50 return Construct1DHist(tmpfile, name_title);
51 };
52 TH2F* Construct2DHist(const TString& inputfile, const TString& name_title) {
53 std::string tmpfile = inputfile.Data();
54 return Construct2DHist(tmpfile, name_title);
55 };
56
57 TH1F* Construct1DHist(const TString& name_title);
58 TH2F* Construct2DHist(const TString& name_title);
59 TProfile* Construct1DProf(const TString& name_title);
60 TProfile2D* Construct2DProf(const TString& name_title);
61
62 TH1F* Construct1DHist(const std::string& inputfile, const TString& name_title);
63 TH2F* Construct2DHist(const std::string& inputfile, const TString& name_title);
64 TProfile* Construct1DProf(const std::string& inputfile, const TString& name_title);
65 TProfile2D* Construct2DProf(const std::string& inputfile, const TString& name_title);
66
67 Bool_t MatchDeviceParamsFromList(const std::string& devicename);
68 Bool_t MatchVQWKElementFromList(const std::string& subsystemname,
69 const std::string& moduletype,
70 const std::string& devicename);
71
72 protected:
73
74 /// Histogram parameter class
75 class HistParams {
76 public:
77 TRegexp expression;
78 TString name_title;
79 TString type;
80 Int_t nbins;
81 Int_t x_nbins;
82 Float_t x_min;
83 Float_t x_max;
84 Int_t y_nbins;
85 Float_t y_min;
86 Float_t y_max;
87 Int_t z_nbins;
88 Float_t z_min;
89 Float_t z_max;
90 TString xtitle;
91 TString ytitle;
92 Float_t min;
93 Float_t max;
94
95 /// Constructor
97
98 public:
99 /// Relational less-than operator overload
100 bool operator< (const HistParams& that) const {
101 // Compare only lowercase strings
102 TString thisname(this->name_title); thisname.ToLower();
103 TString thatname(that.name_title); thatname.ToLower();
104 if (thisname.MaybeRegexp() && thatname.MaybeRegexp()) {
105 // Both wildcarded: latest occurrence of 'wildest card'
106 if (thisname.Contains("*") != thatname.Contains("*"))
107 return thatname.Contains("*");
108 else if (thisname.First("*") != thatname.First("*"))
109 return (thisname.First("*") > thatname.First("*"));
110 else if (thisname.Contains("+") != thatname.Contains("+"))
111 return thatname.Contains("+");
112 else if (thisname.First("+") != thatname.First("+"))
113 return (thisname.First("+") > thatname.First("+"));
114 else if (thisname.CountChar('?') != thatname.CountChar('?'))
115 return (thisname.CountChar('?') < thatname.CountChar('?'));
116 else if (thisname.CountChar('.') != thatname.CountChar('.'))
117 return (thisname.CountChar('.') < thatname.CountChar('.'));
118 else return (thisname < thatname);
119 } else if (thisname.MaybeRegexp() || thatname.MaybeRegexp())
120 // One wildcarded: explicit case has precedence
121 return thatname.MaybeRegexp();
122 else
123 // No wildcards: alphabetic ordering on the lower case names
124 return (thisname < thatname);
125 };
126
127 /// Output stream operator overload
128 friend std::ostream& operator<< (std::ostream& stream, const HistParams& h) {
129 stream << h.type << " " << h.name_title
130 << " x (" << h.xtitle << "): " << h.x_min << " -- " << h.x_max << " (" << h.x_nbins << " bins), "
131 << " y (" << h.ytitle << "): " << h.y_min << " -- " << h.y_max << " (" << h.y_nbins << " bins)";
132 return stream;
133 }
134 };
135
136 protected:
137 TH1F* Construct1DHist(const HistParams &params);
138 TH2F* Construct2DHist(const HistParams &params);
139
140 TProfile* Construct1DProf(const HistParams &params);
141 TProfile2D* Construct2DProf(const HistParams &params);
142
143 const HistParams GetHistParamsFromLine(QwParameterFile &mapstr);
144
145 // Look up the histogram parameters from a file according to histname.
146 const HistParams GetHistParamsFromFile(const std::string& filename,
147 const TString& histname);
148 const HistParams GetHistParamsFromList(const TString& histname);
149
150 Bool_t DoesMatch(const TString& s, const TRegexp& wildcard);
151
152 protected:
153 static const Double_t fInvalidNumber;
154 static const TString fInvalidName;
155 Bool_t fDEBUG;
159
160 std::string fInputFile;
161 std::vector<HistParams> fHistParams;
162 std::vector< std::pair< TString,TRegexp > > fTreeParams;
163
164 std::vector<TString> fSubsystemList;//stores the list of subsystems
165 std::vector<std::vector<TString> > fModuleList;//will store list modules in each subsystem (ex. for BCM, BPM etc in Beam line sub system)
166 std::vector<std::vector<std::vector<TString> > > fVQWKTrimmedList; //will store list of VQWK elements for each subsystem for each module
167};
168
169// Declare a global copy of the histogram helper.
170// It is instantiated in the source file.
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
An options class which parses command line, config file and environment.
Parameter file parsing and management.
Utility class for histogram creation and management.
void PrintHistParams() const
void LoadHistParamsFromFile(const std::string &filename)
std::vector< HistParams > fHistParams
std::vector< TString > fSubsystemList
static const TString fInvalidName
const HistParams GetHistParamsFromFile(const std::string &filename, const TString &histname)
const HistParams GetHistParamsFromList(const TString &histname)
std::vector< std::vector< std::vector< TString > > > fVQWKTrimmedList
void LoadTreeParamsFromFile(const std::string &filename)
Bool_t MatchVQWKElementFromList(const std::string &subsystemname, const std::string &moduletype, const std::string &devicename)
std::vector< std::vector< TString > > fModuleList
static const Double_t fInvalidNumber
static void DefineOptions(QwOptions &options)
Define the configuration options.
TProfile * Construct1DProf(const TString &name_title)
const HistParams GetHistParamsFromLine(QwParameterFile &mapstr)
Bool_t MatchDeviceParamsFromList(const std::string &devicename)
TProfile2D * Construct2DProf(const TString &name_title)
void ProcessOptions(QwOptions &options)
Process the configuration options.
TH1F * Construct1DHist(const TString &inputfile, const TString &name_title)
std::vector< std::pair< TString, TRegexp > > fTreeParams
Bool_t DoesMatch(const TString &s, const TRegexp &wildcard)
TH2F * Construct2DHist(const TString &inputfile, const TString &name_title)
bool operator<(const HistParams &that) const
Relational less-than operator overload.
friend std::ostream & operator<<(std::ostream &stream, const HistParams &h)
Output stream operator overload.
Command-line and configuration file options processor.
Definition QwOptions.h:141
Configuration file parser with flexible tokenization and search capabilities.