ATLAS Offline Software
Loading...
Searching...
No Matches
Plots Class Reference

set of generic plots More...

#include <computils.h>

Inheritance diagram for Plots:
Collaboration diagram for Plots:

Public Member Functions

 Plots (const std::string &s="", bool errors=false)
double realmin (double lo=0, double hi=0)
double realmax (double lo=0, double hi=0)
void MaxScale (double scale=1.1, double lo=0, double hi=0)
void MinScale (double scale, double lo=0, double hi=0)
void Min (double scale)
void Max (double scale)
std::vector< double > findxrange (bool symmetric=false)
void sortx (const AxisInfo &xinfo)
double lo () const
double hi () const
void xrange (bool symmetric=false)
void SetRangeUser (double lo, double hi)
void limits ()
void Draw (Legend &leg, bool means=false)
void Draw_i (Legend &leg, bool means=false)
void SetLogx (bool b=true)
void SetLogy (bool b=true)
std::string GetXaxisTitle ()
std::string GetYaxisTitle ()
void SetXaxisTitle (const std::string &s)
void SetYaxisTitle (const std::string &s)
void push_back (const Plotter &val)
 this is so that we can update the stats as we go along, but no updating isn't done at the moment

Static Public Member Functions

static void setwatermark (bool b)

Public Attributes

elements
 STL member.

Private Attributes

std::string m_name
bool m_logx
 canvas log setting
bool m_logy
bool m_maxset
 yaxis range setting
double m_max
bool m_minset
double m_min
bool m_rangeset
 xaxis range setting
double m_lo
double m_hi
bool m_trim_errors

Static Private Attributes

static bool s_watermark = true

Detailed Description

set of generic plots

Definition at line 917 of file computils.h.

Constructor & Destructor Documentation

◆ Plots()

Plots::Plots ( const std::string & s = "",
bool errors = false )
inline

Definition at line 921 of file computils.h.

921 :
922 m_name(s),
923 m_logx(false), m_logy(false),
924 m_maxset(false), m_max(0),
925 m_minset(false), m_min(0),
926 m_rangeset(false),
927 m_lo(0.0), m_hi(0.0),
928 m_trim_errors(errors)
929 { }
double m_hi
Definition computils.h:1244
double m_lo
Definition computils.h:1243
double m_min
Definition computils.h:1239
bool m_maxset
yaxis range setting
Definition computils.h:1235
bool m_trim_errors
Definition computils.h:1246
bool m_logy
Definition computils.h:1232
bool m_logx
canvas log setting
Definition computils.h:1231
bool m_rangeset
xaxis range setting
Definition computils.h:1242
double m_max
Definition computils.h:1236
std::string m_name
Definition computils.h:1228
bool m_minset
Definition computils.h:1238

Member Function Documentation

◆ Draw()

void Plots::Draw ( Legend & leg,
bool means = false )
inline

Definition at line 1156 of file computils.h.

1156 {
1157 Draw_i( leg, means );
1158 if ( LINES ) {
1159 LINES=false;
1160 Draw_i( leg, means );
1161 LINES=true;
1162 }
1163 }
void Draw_i(Legend &leg, bool means=false)
Definition computils.h:1165
bool LINES
Definition computils.cxx:41

◆ Draw_i()

void Plots::Draw_i ( Legend & leg,
bool means = false )
inline

increase the number of log labels if only a few decades

still can't get this working correctly - for the time being leave these alternative loop orders in place but commented out until we can find a better solution ...

Definition at line 1165 of file computils.h.

1165 {
1166
1167 bool first = true;
1168
1169 if ( m_logy ) {
1170 for ( unsigned i=0 ; i<size() ; i++, first=false ) {
1171 double ymax = at(i).htest()->GetMaximum();
1172 double ymin = at(i).htest()->GetMinimum();
1173 at(i).htest()->GetYaxis()->SetMoreLogLabels(true);
1174 if ( ymax/ymin>1e6 ) at(i).htest()->GetYaxis()->SetMoreLogLabels(false);
1175 break;
1176 }
1177 }
1178
1179 for ( unsigned i=0 ; i<size() ; i++ ) at(i).trim_errors( m_trim_errors );
1180
1183
1184 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).DrawLegend( i, leg, means, first, (i==size()-1) );
1185 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).Draw( i, &leg, means, first, (i==size()-1) );
1186 for ( unsigned i=size() ; i-- ; first=false ) at(i).Draw( i, &leg, means, first, i==0 );
1187
1188 if ( s_watermark ) DrawLabel(0.1, 0.02, "built "+stime()+release, kBlack, 0.03 );
1189
1190 gPad->SetLogy(m_logy);
1191 gPad->SetLogx(m_logx);
1192 }
int DrawLabel(float xstart, float ystart, string label)
static bool s_watermark
Definition computils.h:1250
std::string stime()
return the current data and time
static std::string release
Definition computils.h:50
double ymin
Definition listroot.cxx:63
double ymax
Definition listroot.cxx:64
bool first
Definition DeMoScan.py:534

◆ findxrange()

std::vector< double > Plots::findxrange ( bool symmetric = false)
inline

don't use empty histograms to find the bin limits unless they are all empty

Definition at line 1023 of file computils.h.

1023 {
1024
1027
1028 std::vector<double> v(2,0);
1029
1030 TH1F* hf = at(0).htest();
1031
1032 double vlo = 1e21;
1033 double vhi = -1e21;
1034
1035 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1036 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1037
1038 if ( size()>0 ) v = ::findxrangeuser( hf, symmetric );
1039
1040 bool first = false;
1041
1042 for ( unsigned i=1 ; i<size() ; i++ ) {
1043
1044 hf = at(i).htest();
1045
1046 if ( ::empty( hf ) ) continue;
1047
1048 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1049 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1050
1051 std::vector<double> limits = ::findxrangeuser( hf, symmetric );
1052
1053 double lo = limits[0];
1054 double hi = limits[1];
1055 //coverity[dead_error_condition]
1056 if ( first ) {
1057 //coverity[dead_error_begin]
1058 v[0] = lo;
1059 v[1] = hi;
1060 }
1061 else {
1062 if ( v[0]>lo ) v[0] = lo;
1063 if ( v[1]<hi ) v[1] = hi;
1064 }
1065
1066 first = false;
1067 }
1068
1069 double upper = ( v[1]-v[0] )*1.1 + v[0];
1070 double lower = v[0] - ( v[1]-v[0] )*0.1;
1071
1072 if ( m_logx ) {
1073 double dx = std::log10(v[1])-std::log10(v[0]);
1074 upper = std::pow(10,dx*1.1 + std::log10(v[0]));
1075 lower = std::pow(10,std::log10(v[0]) - dx*0.1);
1076 }
1077
1078 if ( lower<vlo ) lower = vlo;
1079 if ( upper>vhi ) upper = vhi;
1080
1081 v[0] = lower;
1082 v[1] = upper;
1083
1084 return v;
1085 }
int upper(int c)
static const Attributes_t empty
double hi() const
Definition computils.h:1124
void limits()
Definition computils.h:1146
double lo() const
Definition computils.h:1123
std::vector< double > findxrangeuser(TH1 *h, bool symmetric=false)
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)

◆ GetXaxisTitle()

std::string Plots::GetXaxisTitle ( )
inline

Definition at line 1197 of file computils.h.

1197 {
1198 if ( size()>0 ) return at(0).htest()->GetXaxis()->GetTitle();
1199 return "";
1200 }

◆ GetYaxisTitle()

std::string Plots::GetYaxisTitle ( )
inline

Definition at line 1202 of file computils.h.

1202 {
1203 if ( size()>0 ) return at(0).htest()->GetYaxis()->GetTitle();
1204 return "";
1205 }

◆ hi()

double Plots::hi ( ) const
inline

Definition at line 1124 of file computils.h.

1124{ return m_hi; }

◆ limits()

void Plots::limits ( )
inline

Definition at line 1146 of file computils.h.

1146 {
1147 double rmax = realmax();
1148 double rmin = realmin();
1149 if ( rmin<0 ) {
1150 std::cout << "\tlimits \t" << m_name << "\tmin " << rmin << "\tmax " << rmax << std::endl;
1151 }
1152 }
double realmax(double lo=0, double hi=0)
Definition computils.h:942
double realmin(double lo=0, double hi=0)
Definition computils.h:931

◆ lo()

double Plots::lo ( ) const
inline

Definition at line 1123 of file computils.h.

1123{ return m_lo; }

◆ Max()

void Plots::Max ( double scale)
inline

Definition at line 1015 of file computils.h.

1015 {
1016 m_maxset = true;
1017 for ( unsigned i=0 ; i<size() ; i++ ) {
1018 if ( at(i).href() ) at(i).href()->SetMaximum(scale);
1019 at(i).htest()->SetMaximum(scale);
1020 }
1021 }

◆ MaxScale()

void Plots::MaxScale ( double scale = 1.1,
double lo = 0,
double hi = 0 )
inline

Definition at line 956 of file computils.h.

956 {
957
958 if ( size()<1 ) return;
959
960 double tmax = realmax(lo,hi);
961 double tmin = realmin(lo,hi);
962
963 m_max = scale*tmin;
964
965 if ( m_logy ) m_min = tmin;
966
967 for ( unsigned i=0 ; i<size() ; i++ ) {
968 if ( at(i).href() ) at(i).href()->SetMaximum(scale*tmax);
969 at(i).htest()->SetMaximum(scale*tmax);
970 }
971
972 }

◆ Min()

void Plots::Min ( double scale)
inline

Definition at line 1002 of file computils.h.

1002 {
1003 m_minset = true;
1004 for ( unsigned i=0 ; i<size() ; i++ ) {
1005 if ( at(i).href() ) at(i).href()->SetMinimum(scale);
1006 at(i).htest()->SetMinimum(scale);
1007 if ( m_logy ) {
1008 if ( at(i).href() ) if ( at(i).href()->GetMinimum()<=0 ) at(i).href()->GetMinimum(1e-4);
1009 if ( at(i).htest()->GetMinimum()<=0 ) at(i).htest()->GetMinimum(1e-4);
1010 }
1011 }
1012 }

◆ MinScale()

void Plots::MinScale ( double scale,
double lo = 0,
double hi = 0 )
inline

Definition at line 975 of file computils.h.

975 {
976
977 if ( size()<1 ) return;
978
979 if ( scale==0 ) {
980 for ( unsigned i=0 ; i<size() ; i++ ) {
981 if ( at(i).href() ) at(i).href()->SetMinimum(0);
982 at(i).htest()->SetMinimum(0);
983 }
984 return;
985 }
986
987
988 double tmin = 0;
989
990 if ( lo!=hi ) tmin = realmin( lo, hi );
991 else tmin = realmin();
992
993 m_min = scale*tmin;
994
995 for ( unsigned i=0 ; i<size() ; i++ ) {
996 if ( at(i).href() ) at(i).href()->SetMinimum(scale*tmin);
997 at(i).htest()->SetMinimum(scale*tmin);
998 }
999 }

◆ push_back()

void Plots::push_back ( const Plotter & val)
inline

this is so that we can update the stats as we go along, but no updating isn't done at the moment

Definition at line 1218 of file computils.h.

1218 {
1219 std::vector<Plotter>::push_back( val );
1220 }

◆ realmax()

double Plots::realmax ( double lo = 0,
double hi = 0 )
inline

Definition at line 942 of file computils.h.

942 {
943 bool first = true;
944 double max = 0;
945 for ( unsigned i=0 ; i<size() ; i++ ) {
946 // double rmref = realmin( at(i).href(), false );
947 double rmtest = ::realmax( at(i).htest(), false, lo, hi );
948 if ( rmtest!=0 && ( first || max<rmtest ) ) max = rmtest;
949 if ( rmtest!=0 ) first = false;
950 }
951 return max;
952 }
#define max(a, b)
Definition cfImp.cxx:41

◆ realmin()

double Plots::realmin ( double lo = 0,
double hi = 0 )
inline

Definition at line 931 of file computils.h.

931 {
932 bool first = true;
933 double min = 1000;
934 for ( unsigned i=0 ; i<size() ; i++ ) {
935 double rmtest = ::realmin( at(i).htest(), false, lo, hi );
936 if ( rmtest!=0 && ( first || min>rmtest ) ) min = rmtest;
937 if ( rmtest!=0 ) first = false;
938 }
939 return min;
940 }
#define min(a, b)
Definition cfImp.cxx:40

◆ SetLogx()

void Plots::SetLogx ( bool b = true)
inline

Definition at line 1194 of file computils.h.

◆ SetLogy()

void Plots::SetLogy ( bool b = true)
inline

Definition at line 1195 of file computils.h.

1195{ m_logy=b; }

◆ SetRangeUser()

void Plots::SetRangeUser ( double lo,
double hi )
inline

Definition at line 1135 of file computils.h.

1135 {
1136 m_rangeset = true;
1137 m_lo = lo;
1138 m_hi = hi;
1139 for ( unsigned i=0 ; i<size() ; i++ ) {
1140 if ( at(i).href() ) at(i).href()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1141 at(i).htest()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1142 }
1143 }

◆ setwatermark()

void Plots::setwatermark ( bool b)
inlinestatic

Definition at line 1224 of file computils.h.

1224{ s_watermark = b; }

◆ SetXaxisTitle()

void Plots::SetXaxisTitle ( const std::string & s)
inline

Definition at line 1207 of file computils.h.

1207 {
1208 if ( size()>0 ) at(0).htest()->GetXaxis()->SetTitle(s.c_str());
1209 }

◆ SetYaxisTitle()

void Plots::SetYaxisTitle ( const std::string & s)
inline

Definition at line 1211 of file computils.h.

1211 {
1212 if ( size()>0 ) at(0).htest()->GetYaxis()->SetTitle(s.c_str());
1213 }

◆ sortx()

void Plots::sortx ( const AxisInfo & xinfo)
inline

Definition at line 1089 of file computils.h.

1089 {
1090
1091 if ( xinfo.rangeset() ) {
1092 m_lo = xinfo.lo();
1093 m_hi = xinfo.hi();
1094 }
1095
1096 if ( xinfo.autoset() && size() > 0 ) {
1097 std::vector<double> limits = findxrange( xinfo.symmetric() );
1098 if ( xinfo.rangeset() ) {
1099 if ( limits[0]<m_lo ) m_lo = limits[0];
1100 if ( limits[1]>m_hi ) m_hi = limits[1];
1101 }
1102 else {
1103 m_lo = limits[0];
1104 m_hi = limits[1];
1105 }
1106 }
1107 else if (size() == 0)
1108 {
1109 std::cout<<"Warning in computils.h::sortx() size=0. Setting m_lo/m_hi to 0/1. You will probably have empty figures."<<std::endl;
1110 m_lo = 0;
1111 m_hi = 1;
1112 }
1113
1114 if ( xinfo.rangeset() || xinfo.autoset() ) {
1116 if ( xinfo.log() && m_lo>0 ) SetLogx(true);
1117 else SetLogx(false);
1118 }
1119
1120 }
bool autoset() const
Definition computils.h:252
bool symmetric() const
Definition computils.h:258
bool rangeset() const
Definition computils.h:260
double hi() const
Definition computils.h:269
bool log() const
Definition computils.h:250
double lo() const
Definition computils.h:268
std::vector< double > findxrange(bool symmetric=false)
Definition computils.h:1023
void SetLogx(bool b=true)
Definition computils.h:1194
void SetRangeUser(double lo, double hi)
Definition computils.h:1135

◆ xrange()

void Plots::xrange ( bool symmetric = false)
inline

Definition at line 1127 of file computils.h.

1127 {
1128 m_rangeset = false;
1129 for ( unsigned i=0 ; i<size() ; i++ ) {
1130 if ( at(i).href() ) ::xrange( at(i).href(), symmetric );
1131 ::xrange( at(i).htest(), symmetric );
1132 }
1133 }
void xrange(bool symmetric=false)
Definition computils.h:1127

Member Data Documentation

◆ elements

T std::vector< T >::elements
inherited

STL member.

◆ m_hi

double Plots::m_hi
private

Definition at line 1244 of file computils.h.

◆ m_lo

double Plots::m_lo
private

Definition at line 1243 of file computils.h.

◆ m_logx

bool Plots::m_logx
private

canvas log setting

Definition at line 1231 of file computils.h.

◆ m_logy

bool Plots::m_logy
private

Definition at line 1232 of file computils.h.

◆ m_max

double Plots::m_max
private

Definition at line 1236 of file computils.h.

◆ m_maxset

bool Plots::m_maxset
private

yaxis range setting

Definition at line 1235 of file computils.h.

◆ m_min

double Plots::m_min
private

Definition at line 1239 of file computils.h.

◆ m_minset

bool Plots::m_minset
private

Definition at line 1238 of file computils.h.

◆ m_name

std::string Plots::m_name
private

Definition at line 1228 of file computils.h.

◆ m_rangeset

bool Plots::m_rangeset
private

xaxis range setting

Definition at line 1242 of file computils.h.

◆ m_trim_errors

bool Plots::m_trim_errors
private

Definition at line 1246 of file computils.h.

◆ s_watermark

bool Plots::s_watermark = true
staticprivate

Definition at line 1250 of file computils.h.


The documentation for this class was generated from the following files: