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

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

Constructor & Destructor Documentation

◆ Plots()

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

Definition at line 1208 of file computils.h.

1208 :
1209 m_name(s),
1210 m_logx(false), m_logy(false),
1211 m_maxset(false), m_max(0),
1212 m_minset(false), m_min(0),
1213 m_rangeset(false),
1214 m_lo(0.0), m_hi(0.0),
1215 m_trim_errors(errors)
1216 { }
double m_hi
Definition computils.h:1547
double m_lo
Definition computils.h:1546
double m_min
Definition computils.h:1542
bool m_maxset
yaxis range setting
Definition computils.h:1538
bool m_trim_errors
Definition computils.h:1549
bool m_logy
Definition computils.h:1535
bool m_logx
canvas log setting
Definition computils.h:1534
bool m_rangeset
xaxis range setting
Definition computils.h:1545
double m_max
Definition computils.h:1539
std::string m_name
Definition computils.h:1531
bool m_minset
Definition computils.h:1541

Member Function Documentation

◆ Draw()

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

Definition at line 1446 of file computils.h.

1446 {
1447 Draw_i( leg, means );
1448 if ( LINES ) {
1449 LINES=false;
1450 Draw_i( leg, means );
1451 LINES=true;
1452 }
1453 }
void Draw_i(Legend &leg, bool means=false)
Definition computils.h:1455
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 1455 of file computils.h.

1455 {
1456
1457 bool first = true;
1458
1459#if 1
1460 if ( m_logy ) {
1461 for ( unsigned i=0 ; i<size() ; i++, first=false ) {
1462 double ymax = at(i).htest()->GetMaximum();
1463 double ymin = at(i).htest()->GetMinimum();
1464 at(i).htest()->GetYaxis()->SetMoreLogLabels(true);
1465 if ( ymax/ymin>1e6 ) at(i).htest()->GetYaxis()->SetMoreLogLabels(false);
1466 break;
1467 }
1468 }
1469#endif
1470
1471#if 1
1472 for ( unsigned i=0 ; i<size() ; i++ ) at(i).trim_errors( m_trim_errors );
1473
1476
1477#endif
1478
1479 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).Draw( i, &leg, means, first, (i==size()-1) );
1480 // for ( unsigned i=size() ; i-- ; first=false ) at(i).Draw( i, &leg, means, first, i==0 );
1481
1482 for ( unsigned i=size() ; i-- ; first=false ) at(i).Draw( i, &leg, means, first, i==0 );
1483
1484 // dev versions ...
1485 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).DrawLegend( i, leg, means, first, (i==size()-1) );
1486 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).Draw( i, &leg, means, first, i==size() );
1487
1488
1489
1490 if ( s_watermark ) DrawLabel(0.1, 0.02, "built "+stime()+release, kBlack, 0.03 );
1491
1492 gPad->SetLogy(m_logy);
1493 gPad->SetLogx(m_logx);
1494
1495 }
int DrawLabel(float xstart, float ystart, string label)
size_t size() const
Number of registered mappings.
static bool s_watermark
Definition computils.h:1553
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 1310 of file computils.h.

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

1500 {
1501 if ( size()>0 ) return at(0).htest()->GetXaxis()->GetTitle();
1502 return "";
1503 }

◆ GetYaxisTitle()

std::string Plots::GetYaxisTitle ( )
inline

Definition at line 1505 of file computils.h.

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

◆ hi()

double Plots::hi ( ) const
inline

Definition at line 1413 of file computils.h.

1413{ return m_hi; }

◆ limits()

void Plots::limits ( )
inline

Definition at line 1436 of file computils.h.

1436 {
1437 double rmax = realmax();
1438 double rmin = realmin();
1439 if ( rmin<0 ) {
1440 std::cout << "\tlimits \t" << m_name << "\tmin " << rmin << "\tmax " << rmax << std::endl;
1441 }
1442 }
double realmax(double lo=0, double hi=0)
Definition computils.h:1229
double realmin(double lo=0, double hi=0)
Definition computils.h:1218

◆ lo()

double Plots::lo ( ) const
inline

Definition at line 1412 of file computils.h.

1412{ return m_lo; }

◆ Max()

void Plots::Max ( double scale)
inline

Definition at line 1302 of file computils.h.

1302 {
1303 m_maxset = true;
1304 for ( unsigned i=0 ; i<size() ; i++ ) {
1305 if ( at(i).href() ) at(i).href()->SetMaximum(scale);
1306 at(i).htest()->SetMaximum(scale);
1307 }
1308 }

◆ MaxScale()

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

Definition at line 1243 of file computils.h.

1243 {
1244
1245 if ( size()<1 ) return;
1246
1247 double tmax = realmax(lo,hi);
1248 double tmin = realmin(lo,hi);
1249
1250 m_max = scale*tmax;
1251
1252 if ( m_logy ) m_min = tmin;
1253
1254 for ( unsigned i=0 ; i<size() ; i++ ) {
1255 if ( at(i).href() ) at(i).href()->SetMaximum(scale*tmax);
1256 at(i).htest()->SetMaximum(scale*tmax);
1257 }
1258
1259 }

◆ Min()

void Plots::Min ( double scale)
inline

Definition at line 1289 of file computils.h.

1289 {
1290 m_minset = true;
1291 for ( unsigned i=0 ; i<size() ; i++ ) {
1292 if ( at(i).href() ) at(i).href()->SetMinimum(scale);
1293 at(i).htest()->SetMinimum(scale);
1294 if ( m_logy ) {
1295 if ( at(i).href() ) if ( at(i).href()->GetMinimum()<=0 ) at(i).href()->GetMinimum(1e-4);
1296 if ( at(i).htest()->GetMinimum()<=0 ) at(i).htest()->GetMinimum(1e-4);
1297 }
1298 }
1299 }

◆ MinScale()

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

Definition at line 1262 of file computils.h.

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

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

1521 {
1522 std::vector<Plotter>::push_back( val );
1523 }

◆ realmax()

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

Definition at line 1229 of file computils.h.

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

◆ realmin()

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

Definition at line 1218 of file computils.h.

1218 {
1219 bool first = true;
1220 double min = 1000;
1221 for ( unsigned i=0 ; i<size() ; i++ ) {
1222 double rmtest = ::realmin( at(i).htest(), false, lo, hi );
1223 if ( rmtest!=0 && ( first || min>rmtest ) ) min = rmtest;
1224 if ( rmtest!=0 ) first = false;
1225 }
1226 return min;
1227 }
#define min(a, b)
Definition cfImp.cxx:40

◆ SetLogx()

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

Definition at line 1497 of file computils.h.

◆ SetLogy()

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

Definition at line 1498 of file computils.h.

1498{ m_logy=b; }

◆ SetRangeUser()

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

Definition at line 1424 of file computils.h.

1424 {
1425 m_rangeset = true;
1426 m_lo = lo;
1427 m_hi = hi;
1428 for ( unsigned i=0 ; i<size() ; i++ ) {
1429 if ( at(i).href() ) at(i).href()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1430 at(i).htest()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1431 at(i).SetRange(m_lo, m_hi);
1432 }
1433 }

◆ setwatermark()

void Plots::setwatermark ( bool b)
inlinestatic

Definition at line 1527 of file computils.h.

1527{ s_watermark = b; }

◆ SetXaxisTitle()

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

Definition at line 1510 of file computils.h.

1510 {
1511 if ( size()>0 ) at(0).htest()->GetXaxis()->SetTitle(s.c_str());
1512 }

◆ SetYaxisTitle()

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

Definition at line 1514 of file computils.h.

1514 {
1515 if ( size()>0 ) at(0).htest()->GetYaxis()->SetTitle(s.c_str());
1516 }

◆ sortx()

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

Definition at line 1375 of file computils.h.

1375 {
1376
1377 if ( xinfo.rangeset() ) {
1378 std::cout << "xr1: " << xinfo << std::endl;
1379 m_lo = xinfo.lo();
1380 m_hi = xinfo.hi();
1381 }
1382
1383 if ( xinfo.autoset() && size() > 0 ) {
1384 std::vector<double> limits = findxrange( xinfo.symmetric() );
1385 if ( xinfo.rangeset() ) {
1386 std::cout << "xr2: " << xinfo << std::endl;
1387 if ( limits[0]<m_lo ) m_lo = limits[0];
1388 if ( limits[1]>m_hi ) m_hi = limits[1];
1389 }
1390 else {
1391 std::cout << "xr3: " << xinfo << std::endl;
1392 m_lo = limits[0];
1393 m_hi = limits[1];
1394 }
1395 }
1396 else if (size() == 0)
1397 {
1398 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;
1399 m_lo = 0;
1400 m_hi = 1;
1401 }
1402
1403 if ( xinfo.rangeset() || xinfo.autoset() ) {
1405 if ( xinfo.log() && m_lo>0 ) SetLogx(true);
1406 else SetLogx(false);
1407 }
1408
1409 }
bool autoset() const
Definition computils.h:262
bool symmetric() const
Definition computils.h:268
bool rangeset() const
Definition computils.h:270
double hi() const
Definition computils.h:279
bool log() const
Definition computils.h:260
double lo() const
Definition computils.h:278
std::vector< double > findxrange(bool symmetric=false)
Definition computils.h:1310
void SetLogx(bool b=true)
Definition computils.h:1497
void SetRangeUser(double lo, double hi)
Definition computils.h:1424

◆ xrange()

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

Definition at line 1416 of file computils.h.

1416 {
1417 m_rangeset = false;
1418 for ( unsigned i=0 ; i<size() ; i++ ) {
1419 if ( at(i).href() ) ::xrange( at(i).href(), symmetric );
1420 ::xrange( at(i).htest(), symmetric );
1421 }
1422 }
void xrange(bool symmetric=false)
Definition computils.h:1416

Member Data Documentation

◆ elements

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

STL member.

◆ m_hi

double Plots::m_hi
private

Definition at line 1547 of file computils.h.

◆ m_lo

double Plots::m_lo
private

Definition at line 1546 of file computils.h.

◆ m_logx

bool Plots::m_logx
private

canvas log setting

Definition at line 1534 of file computils.h.

◆ m_logy

bool Plots::m_logy
private

Definition at line 1535 of file computils.h.

◆ m_max

double Plots::m_max
private

Definition at line 1539 of file computils.h.

◆ m_maxset

bool Plots::m_maxset
private

yaxis range setting

Definition at line 1538 of file computils.h.

◆ m_min

double Plots::m_min
private

Definition at line 1542 of file computils.h.

◆ m_minset

bool Plots::m_minset
private

Definition at line 1541 of file computils.h.

◆ m_name

std::string Plots::m_name
private

Definition at line 1531 of file computils.h.

◆ m_rangeset

bool Plots::m_rangeset
private

xaxis range setting

Definition at line 1545 of file computils.h.

◆ m_trim_errors

bool Plots::m_trim_errors
private

Definition at line 1549 of file computils.h.

◆ s_watermark

bool Plots::s_watermark = true
staticprivate

Definition at line 1553 of file computils.h.


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