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 1210 of file computils.h.

Constructor & Destructor Documentation

◆ Plots()

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

Definition at line 1214 of file computils.h.

1214 :
1215 m_name(s),
1216 m_logx(false), m_logy(false),
1217 m_maxset(false), m_max(0),
1218 m_minset(false), m_min(0),
1219 m_rangeset(false),
1220 m_lo(0.0), m_hi(0.0),
1221 m_trim_errors(errors)
1222 { }
double m_hi
Definition computils.h:1553
double m_lo
Definition computils.h:1552
double m_min
Definition computils.h:1548
bool m_maxset
yaxis range setting
Definition computils.h:1544
bool m_trim_errors
Definition computils.h:1555
bool m_logy
Definition computils.h:1541
bool m_logx
canvas log setting
Definition computils.h:1540
bool m_rangeset
xaxis range setting
Definition computils.h:1551
double m_max
Definition computils.h:1545
std::string m_name
Definition computils.h:1537
bool m_minset
Definition computils.h:1547

Member Function Documentation

◆ Draw()

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

Definition at line 1452 of file computils.h.

1452 {
1453 Draw_i( leg, means );
1454 if ( LINES ) {
1455 LINES=false;
1456 Draw_i( leg, means );
1457 LINES=true;
1458 }
1459 }
void Draw_i(Legend &leg, bool means=false)
Definition computils.h:1461
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 1461 of file computils.h.

1461 {
1462
1463 bool first = true;
1464
1465#if 1
1466 if ( m_logy ) {
1467 for ( unsigned i=0 ; i<size() ; i++, first=false ) {
1468 double ymax = at(i).htest()->GetMaximum();
1469 double ymin = at(i).htest()->GetMinimum();
1470 at(i).htest()->GetYaxis()->SetMoreLogLabels(true);
1471 if ( ymax/ymin>1e6 ) at(i).htest()->GetYaxis()->SetMoreLogLabels(false);
1472 break;
1473 }
1474 }
1475#endif
1476
1477#if 1
1478 for ( unsigned i=0 ; i<size() ; i++ ) at(i).trim_errors( m_trim_errors );
1479
1482
1483#endif
1484
1485 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).Draw( i, &leg, means, first, (i==size()-1) );
1486 // for ( unsigned i=size() ; i-- ; first=false ) at(i).Draw( i, &leg, means, first, i==0 );
1487
1488 for ( unsigned i=size() ; i-- ; first=false ) at(i).Draw( i, &leg, means, first, i==0 );
1489
1490 // dev versions ...
1491 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).DrawLegend( i, leg, means, first, (i==size()-1) );
1492 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).Draw( i, &leg, means, first, i==size() );
1493
1494
1495
1496 if ( s_watermark ) DrawLabel(0.1, 0.02, "built "+stime()+release, kBlack, 0.03 );
1497
1498 gPad->SetLogy(m_logy);
1499 gPad->SetLogx(m_logx);
1500
1501 }
int DrawLabel(float xstart, float ystart, string label)
size_t size() const
Number of registered mappings.
static bool s_watermark
Definition computils.h:1559
std::string stime()
return the current data and time
static std::string release
Definition computils.h:54
double ymin
Definition listroot.cxx:63
double ymax
Definition listroot.cxx:64
mapped_type at(key_type key) const
Look up an element in the map.
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 1316 of file computils.h.

1316 {
1317
1320
1321 std::vector<double> v(2,0);
1322
1323 TH1F* hf = at(0).htest();
1324
1325 double vlo = 1e21;
1326 double vhi = -1e21;
1327
1328 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1329 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1330
1331 if ( size()>0 ) v = ::findxrangeuser( hf, symmetric );
1332
1333 bool first = false;
1334
1335 for ( unsigned i=1 ; i<size() ; i++ ) {
1336
1337 hf = at(i).htest();
1338
1339 if ( ::empty( hf ) ) continue;
1340
1341 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1342 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1343
1344 std::vector<double> limits = ::findxrangeuser( hf, symmetric );
1345
1346 double lo = limits[0];
1347 double hi = limits[1];
1348
1349 if ( first ) {
1350 v[0] = lo;
1351 v[1] = hi;
1352 }
1353 else {
1354 if ( v[0]>lo ) v[0] = lo;
1355 if ( v[1]<hi ) v[1] = hi;
1356 }
1357
1358 first = false;
1359 }
1360
1361 double upper = ( v[1]-v[0] )*1.1 + v[0];
1362 double lower = v[0] - ( v[1]-v[0] )*0.1;
1363
1364 if ( m_logx ) {
1365 double dx = std::log10(v[1])-std::log10(v[0]);
1366 upper = std::pow(10,dx*1.1 + std::log10(v[0]));
1367 lower = std::pow(10,std::log10(v[0]) - dx*0.1);
1368 }
1369
1370 if ( lower<vlo ) lower = vlo;
1371 if ( upper>vhi ) upper = vhi;
1372
1373 v[0] = lower;
1374 v[1] = upper;
1375
1376 return v;
1377 }
int upper(int c)
static const Attributes_t empty
double hi() const
Definition computils.h:1419
void limits()
Definition computils.h:1442
double lo() const
Definition computils.h:1418
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 1506 of file computils.h.

1506 {
1507 if ( size()>0 ) return at(0).htest()->GetXaxis()->GetTitle();
1508 return "";
1509 }

◆ GetYaxisTitle()

std::string Plots::GetYaxisTitle ( )
inline

Definition at line 1511 of file computils.h.

1511 {
1512 if ( size()>0 ) return at(0).htest()->GetYaxis()->GetTitle();
1513 return "";
1514 }

◆ hi()

double Plots::hi ( ) const
inline

Definition at line 1419 of file computils.h.

1419{ return m_hi; }

◆ limits()

void Plots::limits ( )
inline

Definition at line 1442 of file computils.h.

1442 {
1443 double rmax = realmax();
1444 double rmin = realmin();
1445 if ( rmin<0 ) {
1446 std::cout << "\tlimits \t" << m_name << "\tmin " << rmin << "\tmax " << rmax << std::endl;
1447 }
1448 }
double realmax(double lo=0, double hi=0)
Definition computils.h:1235
double realmin(double lo=0, double hi=0)
Definition computils.h:1224

◆ lo()

double Plots::lo ( ) const
inline

Definition at line 1418 of file computils.h.

1418{ return m_lo; }

◆ Max()

void Plots::Max ( double scale)
inline

Definition at line 1308 of file computils.h.

1308 {
1309 m_maxset = true;
1310 for ( unsigned i=0 ; i<size() ; i++ ) {
1311 if ( at(i).href() ) at(i).href()->SetMaximum(scale);
1312 at(i).htest()->SetMaximum(scale);
1313 }
1314 }

◆ MaxScale()

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

Definition at line 1249 of file computils.h.

1249 {
1250
1251 if ( size()<1 ) return;
1252
1253 double tmax = realmax(lo,hi);
1254 double tmin = realmin(lo,hi);
1255
1256 m_max = scale*tmax;
1257
1258 if ( m_logy ) m_min = tmin;
1259
1260 for ( unsigned i=0 ; i<size() ; i++ ) {
1261 if ( at(i).href() ) at(i).href()->SetMaximum(scale*tmax);
1262 at(i).htest()->SetMaximum(scale*tmax);
1263 }
1264
1265 }

◆ Min()

void Plots::Min ( double scale)
inline

Definition at line 1295 of file computils.h.

1295 {
1296 m_minset = true;
1297 for ( unsigned i=0 ; i<size() ; i++ ) {
1298 if ( at(i).href() ) at(i).href()->SetMinimum(scale);
1299 at(i).htest()->SetMinimum(scale);
1300 if ( m_logy ) {
1301 if ( at(i).href() ) if ( at(i).href()->GetMinimum()<=0 ) at(i).href()->GetMinimum(1e-4);
1302 if ( at(i).htest()->GetMinimum()<=0 ) at(i).htest()->GetMinimum(1e-4);
1303 }
1304 }
1305 }

◆ MinScale()

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

Definition at line 1268 of file computils.h.

1268 {
1269
1270 if ( size()<1 ) return;
1271
1272 if ( scale==0 ) {
1273 for ( unsigned i=0 ; i<size() ; i++ ) {
1274 if ( at(i).href() ) at(i).href()->SetMinimum(0);
1275 at(i).htest()->SetMinimum(0);
1276 }
1277 return;
1278 }
1279
1280
1281 double tmin = 0;
1282
1283 if ( lo!=hi ) tmin = realmin( lo, hi );
1284 else tmin = realmin();
1285
1286 m_min = scale*tmin;
1287
1288 for ( unsigned i=0 ; i<size() ; i++ ) {
1289 if ( at(i).href() ) at(i).href()->SetMinimum(scale*tmin);
1290 at(i).htest()->SetMinimum(scale*tmin);
1291 }
1292 }

◆ 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 1527 of file computils.h.

1527 {
1528 std::vector<Plotter>::push_back( val );
1529 }

◆ realmax()

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

Definition at line 1235 of file computils.h.

1235 {
1236 bool first = true;
1237 double max = 0;
1238 for ( unsigned i=0 ; i<size() ; i++ ) {
1239 // double rmref = realmin( at(i).href(), false );
1240 double rmtest = ::realmax( at(i).htest(), false, lo, hi );
1241 if ( rmtest!=0 && ( first || max<rmtest ) ) max = rmtest;
1242 if ( rmtest!=0 ) first = false;
1243 }
1244 return max;
1245 }
#define max(a, b)
Definition cfImp.cxx:41

◆ realmin()

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

Definition at line 1224 of file computils.h.

1224 {
1225 bool first = true;
1226 double min = 1000;
1227 for ( unsigned i=0 ; i<size() ; i++ ) {
1228 double rmtest = ::realmin( at(i).htest(), false, lo, hi );
1229 if ( rmtest!=0 && ( first || min>rmtest ) ) min = rmtest;
1230 if ( rmtest!=0 ) first = false;
1231 }
1232 return min;
1233 }
#define min(a, b)
Definition cfImp.cxx:40

◆ SetLogx()

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

Definition at line 1503 of file computils.h.

◆ SetLogy()

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

Definition at line 1504 of file computils.h.

1504{ m_logy=b; }

◆ SetRangeUser()

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

Definition at line 1430 of file computils.h.

1430 {
1431 m_rangeset = true;
1432 m_lo = lo;
1433 m_hi = hi;
1434 for ( unsigned i=0 ; i<size() ; i++ ) {
1435 if ( at(i).href() ) at(i).href()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1436 at(i).htest()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1437 at(i).SetRange(m_lo, m_hi);
1438 }
1439 }

◆ setwatermark()

void Plots::setwatermark ( bool b)
inlinestatic

Definition at line 1533 of file computils.h.

1533{ s_watermark = b; }

◆ SetXaxisTitle()

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

Definition at line 1516 of file computils.h.

1516 {
1517 if ( size()>0 ) at(0).htest()->GetXaxis()->SetTitle(s.c_str());
1518 }

◆ SetYaxisTitle()

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

Definition at line 1520 of file computils.h.

1520 {
1521 if ( size()>0 ) at(0).htest()->GetYaxis()->SetTitle(s.c_str());
1522 }

◆ sortx()

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

Definition at line 1381 of file computils.h.

1381 {
1382
1383 if ( xinfo.rangeset() ) {
1384 std::cout << "xr1: " << xinfo << std::endl;
1385 m_lo = xinfo.lo();
1386 m_hi = xinfo.hi();
1387 }
1388
1389 if ( xinfo.autoset() && size() > 0 ) {
1390 std::vector<double> limits = findxrange( xinfo.symmetric() );
1391 if ( xinfo.rangeset() ) {
1392 std::cout << "xr2: " << xinfo << std::endl;
1393 if ( limits[0]<m_lo ) m_lo = limits[0];
1394 if ( limits[1]>m_hi ) m_hi = limits[1];
1395 }
1396 else {
1397 std::cout << "xr3: " << xinfo << std::endl;
1398 m_lo = limits[0];
1399 m_hi = limits[1];
1400 }
1401 }
1402 else if (size() == 0)
1403 {
1404 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;
1405 m_lo = 0;
1406 m_hi = 1;
1407 }
1408
1409 if ( xinfo.rangeset() || xinfo.autoset() ) {
1411 if ( xinfo.log() && m_lo>0 ) SetLogx(true);
1412 else SetLogx(false);
1413 }
1414
1415 }
bool autoset() const
Definition computils.h:256
bool symmetric() const
Definition computils.h:262
bool rangeset() const
Definition computils.h:264
double hi() const
Definition computils.h:273
bool log() const
Definition computils.h:254
double lo() const
Definition computils.h:272
std::vector< double > findxrange(bool symmetric=false)
Definition computils.h:1316
void SetLogx(bool b=true)
Definition computils.h:1503
void SetRangeUser(double lo, double hi)
Definition computils.h:1430

◆ xrange()

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

Definition at line 1422 of file computils.h.

1422 {
1423 m_rangeset = false;
1424 for ( unsigned i=0 ; i<size() ; i++ ) {
1425 if ( at(i).href() ) ::xrange( at(i).href(), symmetric );
1426 ::xrange( at(i).htest(), symmetric );
1427 }
1428 }
void xrange(bool symmetric=false)
Definition computils.h:1422

Member Data Documentation

◆ elements

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

STL member.

◆ m_hi

double Plots::m_hi
private

Definition at line 1553 of file computils.h.

◆ m_lo

double Plots::m_lo
private

Definition at line 1552 of file computils.h.

◆ m_logx

bool Plots::m_logx
private

canvas log setting

Definition at line 1540 of file computils.h.

◆ m_logy

bool Plots::m_logy
private

Definition at line 1541 of file computils.h.

◆ m_max

double Plots::m_max
private

Definition at line 1545 of file computils.h.

◆ m_maxset

bool Plots::m_maxset
private

yaxis range setting

Definition at line 1544 of file computils.h.

◆ m_min

double Plots::m_min
private

Definition at line 1548 of file computils.h.

◆ m_minset

bool Plots::m_minset
private

Definition at line 1547 of file computils.h.

◆ m_name

std::string Plots::m_name
private

Definition at line 1537 of file computils.h.

◆ m_rangeset

bool Plots::m_rangeset
private

xaxis range setting

Definition at line 1551 of file computils.h.

◆ m_trim_errors

bool Plots::m_trim_errors
private

Definition at line 1555 of file computils.h.

◆ s_watermark

bool Plots::s_watermark = true
staticprivate

Definition at line 1559 of file computils.h.


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