Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
tPlotter< T > Class Template Reference

generic plotter class - better to have one of these - make sure it can be configured however you like, line styles, marker types, legends etc now a template so can be used for TH1D and TH2D etc More...

#include <computils.h>

Collaboration diagram for tPlotter< T >:

Public Member Functions

 tPlotter (T *_htest=0, T *_href=0, const std::string &s="", TGraphAsymmErrors *_tgtest=0, TGraphAsymmErrors *_tgref=0)
 
 tPlotter (const tPlotter &p)
 
 ~tPlotter ()
 sadly, root manages all the histograms (does it really? who can tell) so we mustn't delete anything just in case More...
 
const std::string & plotfilename () const
 
void trim_errors (bool b)
 
bool trim_errors () const
 
void Draw (int i, Legend *lleg, bool mean=false, bool first=true, bool drawlegend=false)
 
void DrawLegend (int i, Legend &leg, bool mean=false, bool first=true, bool drawlegend=false)
 
void Print (const std::string &s="")
 print the output More...
 
T * htest ()
 
T * href ()
 
TGraphAsymmErrors * tgtest ()
 
TGraphAsymmErrors * tgref ()
 
void max_entries (int i)
 

Static Public Member Functions

static void setplotref (bool b)
 
static void setmeanplotref (bool b)
 

Private Attributes

T * m_htest
 actual histograms More...
 
T * m_href
 
TGraphAsymmErrors * m_tgtest
 
TGraphAsymmErrors * m_tgref
 
std::string m_plotfilename
 
size_t m_max_entries
 
size_t m_entries
 
bool m_trim_errors
 

Static Private Attributes

static bool s_plotref = true
 use non c++17 format for improved external compatability More...
 
static bool s_meanplotref = true
 

Detailed Description

template<typename T>
class tPlotter< T >

generic plotter class - better to have one of these - make sure it can be configured however you like, line styles, marker types, legends etc now a template so can be used for TH1D and TH2D etc

Definition at line 456 of file computils.h.

Constructor & Destructor Documentation

◆ tPlotter() [1/2]

template<typename T >
tPlotter< T >::tPlotter ( T *  _htest = 0,
T *  _href = 0,
const std::string &  s = "",
TGraphAsymmErrors *  _tgtest = 0,
TGraphAsymmErrors *  _tgref = 0 
)
inline

Definition at line 460 of file computils.h.

460  :
461  m_htest(_htest), m_href(_href),
462  m_tgtest(_tgtest), m_tgref(_tgref),
463  m_plotfilename(s),
464  m_max_entries(4),
465  m_entries(0),
466  m_trim_errors(false)
467  {
468  }

◆ tPlotter() [2/2]

template<typename T >
tPlotter< T >::tPlotter ( const tPlotter< T > &  p)
inline

Definition at line 471 of file computils.h.

471  :
472  m_htest(p.m_htest), m_href(p.m_href),
473  m_tgtest(p.m_tgtest), m_tgref(p.m_tgref),
474  m_plotfilename(p.m_plotfilename),
475  m_max_entries(p.m_max_entries),
476  m_entries(0),
477  m_trim_errors(p.m_trim_errors) {
478  }

◆ ~tPlotter()

template<typename T >
tPlotter< T >::~tPlotter ( )
inline

sadly, root manages all the histograms (does it really? who can tell) so we mustn't delete anything just in case

NO, NO, NO, don't delete the objects, root need them because it is TOO STUPID to allow objects to be used as actual objects

Definition at line 487 of file computils.h.

487 { }

Member Function Documentation

◆ Draw()

template<typename T >
void tPlotter< T >::Draw ( int  i,
Legend lleg,
bool  mean = false,
bool  first = true,
bool  drawlegend = false 
)
inline

not quite yet ...

Definition at line 495 of file computils.h.

495  {
496 
497  if ( htest() ) {
498  gStyle->SetOptStat(0);
499  if ( href() ) {
500  href()->SetLineColor(colours[i%6]);
501  href()->SetLineStyle(2);
502  href()->SetMarkerStyle(0);
503  }
504 
505  if ( LINEF ) htest()->SetLineColor(colours[i%6]);
506 
507  htest()->SetLineStyle(1);
508 
509  if ( LINEF ) htest()->SetMarkerColor(htest()->GetLineColor());
510 
511  if ( LINEF ) htest()->SetMarkerStyle(markers[i%6]);
512  // if ( LINEF && htest()->GetMarkerStyle() == 20 )
513 
514  if ( LINEF ) htest()->SetMarkerSize( msizes[i%6]*htest()->GetMarkerSize() );
515 
516  if ( htest() ) std::cout << "\tentries: " << plotable( htest() );
517 
518  std::cout << std::endl;
519 
520  if ( first ) {
521 
522  if ( tgtest() ) {
523  zeroErrors(htest());
524  htest()->GetXaxis()->SetMoreLogLabels(true);
525  if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
526 
527 
528  htest()->Draw("ep");
529  if ( LINES ) htest()->Draw("lhistsame");
530  setParameters( htest(), tgtest() );
531  tgtest()->Draw("esame");
532  }
533  else {
534  htest()->GetXaxis()->SetMoreLogLabels(true);
535  htest()->Draw("ep");
536  if ( LINES ) htest()->Draw("lhistsame");
537  }
538 
539  }
540 
541  if ( s_plotref && href() ) {
542  if ( contains(href()->GetName(),"_vs_") ||
543  contains(href()->GetName(),"sigma") ||
544  contains(href()->GetName(),"mean") ||
545  contains(href()->GetName(),"_eff") ||
546  contains(href()->GetName(),"Res_") ||
547  contains(href()->GetName(),"Eff_") ) href()->Draw("hist same][");
548  else href()->Draw("hist same");
549  }
550 
551  if ( tgtest() ) {
552  zeroErrors(htest());
553 
554  if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
555  setParameters( htest(), tgtest() );
556  tgtest()->Draw("e1same");
557  if ( LINES ) tgtest()->Draw("lsame");
558 
559  }
560 
561 #if 0
562  if ( htest()->GetMarkerStyle()>23 ) {
564  TH1D* hnull = (TH1D*)htest()->Clone("duff"); hnull->SetDirectory(0);
565  zeroErrors( hnull );
566  hnull->SetLineColor(kWhite);
567  hnull->SetMarkerStyle( htest()->GetMarkerStyle()-4 );
568  // hnull->SetMarkerStyle( 0 );
569  hnull->SetMarkerColor(kWhite);
570  hnull->SetMarkerSize( htest()->GetMarkerSize()*0.75 );
571  // hnull->SetMarkerSize( 0 );
572  hnull->DrawCopy("l same");
573  delete hnull;
574  }
575 #endif
576 
577  htest()->Draw("ep same");
578  if ( LINES ) htest()->Draw("lhist same");
579 
580  // href()->Draw("lhistsame");
581  // htest()->Draw("lhistsame");
582 
583  std::string key = m_plotfilename;
584 
585  static TH1D* hnull = new TH1D("hnull", "", 1, 0, 1);
586  hnull->SetMarkerColor(kWhite);
587  hnull->SetLineColor(kWhite);
588  hnull->SetMarkerStyle(0);
589  hnull->SetLineStyle(0);
590  hnull->SetLineWidth(0);
591  hnull->SetMarkerSize(0);
592 
593 
594  if ( lleg ) {
595 
596  Legend& leg = *lleg;
597 
598  if ( mean ) {
599 
600  char meanrefc[64];
601  bool displayref = false;
602  if ( s_meanplotref && href() ) {
603  displayref = true;
604  true_mean muref( href() );
605  std::sprintf( meanrefc, " <t> = %3.2f #pm %3.2f ms (ref)", muref.mean(), muref.error() );
606  }
607  else {
608  std::sprintf( meanrefc, "%s", "" );
609  }
610 
611  true_mean mutest( htest() );
612  char meanc[64];
613  std::sprintf( meanc, " <t> = %3.2f #pm %3.2f ms", mutest.mean(), mutest.error() );
614 
615  std::string dkey = key;
616 
617  std::string remove[7] = { "TIME_", "Time_", "All_", "Algorithm_", "Class_", "HLT_", "Chain_HLT_" };
618 
619  if ( dkey.find("Chain")!=std::string::npos ) {
620  if ( dkey.find("__")!=std::string::npos ) dkey.erase( 0, dkey.find("__")+2 );
621  }
622 
623 
624  for ( int ir=0 ; ir<7 ; ir++ ) {
625  if ( dkey.find( remove[ir] )!=std::string::npos ) dkey.erase( dkey.find( remove[ir]), remove[ir].size() );
626  }
627 
628  std::string rkey = dkey;
629 
630 
631  if ( LINEF || leg.size() < m_max_entries ) {
632  dkey += std::string(" : ");
633 
634  if ( (dkey+meanc).size()>58 ) {
635  leg.AddEntry( htest(), dkey, "p" );
636  leg.AddEntry( hnull, meanc, "p" );
637  }
638  else {
639  leg.AddEntry( htest(), (dkey+meanc).c_str(), "p" );
640  }
641 
642  if ( displayref ) {
643  rkey += std::string(" : ");
645  // leg.AddEntry( hnull, "", "l" );
646 
647  if ( (rkey+meanrefc).size()>58 ) {
648  leg.AddEntry( href(), rkey, "l" );
649  leg.AddEntry( hnull, meanrefc, "l" );
650  }
651  else {
652  leg.AddEntry( href(), (rkey+meanrefc).c_str(), "l" );
653  }
654  }
655  }
656 
657  }
658  else {
659  if ( LINEF || leg.size()<m_max_entries ) leg.AddEntry( htest(), key, "p" );
660  }
661 
662  m_entries++;
663 
664  if ( drawlegend ) leg.Draw();
665  }
666 
667  }
668  }

◆ DrawLegend()

template<typename T >
void tPlotter< T >::DrawLegend ( int  i,
Legend leg,
bool  mean = false,
bool  first = true,
bool  drawlegend = false 
)
inline

Definition at line 672 of file computils.h.

672  {
673 
674  if ( htest() ) {
675  gStyle->SetOptStat(0);
676  if ( href() ) {
677  href()->SetLineColor(colours[i%6]);
678  href()->SetLineStyle(2);
679  href()->SetMarkerStyle(0);
680  }
681 
682  if ( LINEF ) htest()->SetLineColor(colours[i%6]);
683  htest()->SetLineStyle(1);
684  if ( LINEF ) htest()->SetMarkerColor(htest()->GetLineColor());
685  if ( LINEF ) htest()->SetMarkerStyle(markers[i%6]);
686 
687  if ( htest() ) std::cout << "\tentries: " << plotable( htest() );
688  std::cout << std::endl;
689 
690  if ( first ) {
691 
692  if ( tgtest() ) {
693  zeroErrors(htest());
694  htest()->GetXaxis()->SetMoreLogLabels(true);
695  if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
696 
697 
698  // htest()->Draw("ep");
699  if ( LINES ) htest()->Draw("lhistsame");
700  setParameters( htest(), tgtest() );
701  // tgtest()->Draw("esame");
702  }
703  else {
704  htest()->GetXaxis()->SetMoreLogLabels(true);
705  // htest()->Draw("ep");
706  // if ( LINES ) htest()->Draw("lhistsame");
707  }
708 
709  }
710 
711 
712 #if 0
713  if ( s_plotref && href() ) {
714  if ( contains(href()->GetName(),"_vs_") ||
715  contains(href()->GetName(),"sigma") ||
716  contains(href()->GetName(),"mean") ||
717  contains(href()->GetName(),"_eff") ||
718  contains(href()->GetName(),"Res_") ||
719  contains(href()->GetName(),"Eff_") ) href()->Draw("hist same][");
720  else href()->Draw("hist same");
721  }
722 
723  if ( tgtest() ) {
724  zeroErrors(htest());
725 
726  if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
727  setParameters( htest(), tgtest() );
728  tgtest()->Draw("e1same");
729  if ( LINES ) tgtest()->Draw("lsame");
730 
731  }
732 #endif
733 
734 
735 #if 0
736  if ( htest()->GetMarkerStyle()>23 ) {
738  TH1D* hnull = (TH1D*)htest()->Clone("duff"); hnull->SetDirectory(0);
739  zeroErrors( hnull );
740  hnull->SetLineColor(kWhite);
741  hnull->SetMarkerStyle( htest()->GetMarkerStyle()-4 );
742  // hnull->SetMarkerStyle( 0 );
743  hnull->SetMarkerColor(kWhite);
744  hnull->SetMarkerSize( htest()->GetMarkerSize()*0.75 );
745  // hnull->SetMarkerSize( 0 );
746  hnull->DrawCopy("l same");
747  delete hnull;
748  }
749 #endif
750 
751  // htest()->Draw("ep same");
752  // if ( LINES ) htest()->Draw("lhist same");
753 
754  // href()->Draw("lhistsame");
755  // htest()->Draw("lhistsame");
756 
757  std::string key = m_plotfilename;
758 
759  static TH1D* hnull = new TH1D("hnull", "", 1, 0, 1);
760  hnull->SetMarkerColor(kWhite);
761  hnull->SetLineColor(kWhite);
762  hnull->SetMarkerStyle(0);
763  hnull->SetLineStyle(0);
764  hnull->SetLineWidth(0);
765  hnull->SetMarkerSize(0);
766 
767 
768  if ( mean ) {
769 
770  char meanrefc[64];
771  bool displayref = false;
772  if ( s_meanplotref && href() ) {
773  displayref = true;
774  true_mean muref( href() );
775  std::sprintf( meanrefc, " <t> = %3.2f #pm %3.2f ms (ref)", muref.mean(), muref.error() );
776  }
777  else {
778  std::sprintf( meanrefc, "%s", "" );
779  }
780 
781 
782  true_mean mutest( htest() );
783  char meanc[64];
784  std::sprintf( meanc, " <t> = %3.2f #pm %3.2f ms", mutest.mean(), mutest.error() );
785 
786  std::string dkey = key;
787 
788  std::string remove[7] = { "TIME_", "Time_", "All_", "Algorithm_", "Class_", "HLT_", "Chain_HLT_" };
789 
790  if ( dkey.find("Chain")!=std::string::npos ) {
791  if ( dkey.find("__")!=std::string::npos ) dkey.erase( 0, dkey.find("__")+2 );
792  }
793 
794 
795  for ( int ir=0 ; ir<7 ; ir++ ) {
796  if ( dkey.find( remove[ir] )!=std::string::npos ) dkey.erase( dkey.find( remove[ir]), remove[ir].size() );
797  }
798 
799  std::string rkey = dkey;
800 
801 
802  if ( LINEF || leg.size() < m_max_entries ) {
803  dkey += std::string(" : ");
804 
805  if ( (dkey+meanc).size()>58 ) {
806  leg.AddEntry( htest(), dkey, "p" );
807  leg.AddEntry( hnull, meanc, "p" );
808  }
809  else {
810  leg.AddEntry( htest(), (dkey+meanc).c_str(), "p" );
811  }
812 
813  if ( displayref ) {
814  rkey += std::string(" : ");
815  // leg.AddEntry( hnull, "", "l" );
816 
817  if ( (rkey+meanrefc).size()>58 ) {
818  leg.AddEntry( href(), rkey, "l" );
819  leg.AddEntry( hnull, meanrefc, "l" );
820  }
821  else {
822  leg.AddEntry( href(), (rkey+meanrefc).c_str(), "l" );
823  }
824  }
825  }
826 
827  }
828  else {
829  if ( LINEF || leg.size()<m_max_entries ) leg.AddEntry( htest(), key, "p" );
830  }
831 
832  m_entries++;
833 
834  if ( drawlegend ) leg.Draw();
835 
836  }
837  }

◆ href()

template<typename T >
T* tPlotter< T >::href ( )
inline

Definition at line 848 of file computils.h.

848 { return m_href; }

◆ htest()

template<typename T >
T* tPlotter< T >::htest ( )
inline

Definition at line 847 of file computils.h.

847 { return m_htest; }

◆ max_entries()

template<typename T >
void tPlotter< T >::max_entries ( int  i)
inline

Definition at line 855 of file computils.h.

855 { m_max_entries = i; }

◆ plotfilename()

template<typename T >
const std::string& tPlotter< T >::plotfilename ( ) const
inline

Definition at line 489 of file computils.h.

489 { return m_plotfilename; }

◆ Print()

template<typename T >
void tPlotter< T >::Print ( const std::string &  s = "")
inline

print the output

Definition at line 842 of file computils.h.

842  {
843  if ( s!="" ) gPad->Print(s.c_str());
844  else gPad->Print(m_plotfilename.c_str());
845  }

◆ setmeanplotref()

template<typename T >
static void tPlotter< T >::setmeanplotref ( bool  b)
inlinestatic

Definition at line 860 of file computils.h.

860 { s_meanplotref=b; }

◆ setplotref()

template<typename T >
static void tPlotter< T >::setplotref ( bool  b)
inlinestatic

Definition at line 859 of file computils.h.

◆ tgref()

template<typename T >
TGraphAsymmErrors* tPlotter< T >::tgref ( )
inline

Definition at line 852 of file computils.h.

852 { return m_tgref; }

◆ tgtest()

template<typename T >
TGraphAsymmErrors* tPlotter< T >::tgtest ( )
inline

Definition at line 851 of file computils.h.

851 { return m_tgtest; }

◆ trim_errors() [1/2]

template<typename T >
bool tPlotter< T >::trim_errors ( ) const
inline

Definition at line 493 of file computils.h.

493 { return m_trim_errors; }

◆ trim_errors() [2/2]

template<typename T >
void tPlotter< T >::trim_errors ( bool  b)
inline

Definition at line 491 of file computils.h.

491 { m_trim_errors=b; }

Member Data Documentation

◆ m_entries

template<typename T >
size_t tPlotter< T >::m_entries
private

Definition at line 877 of file computils.h.

◆ m_href

template<typename T >
T* tPlotter< T >::m_href
private

Definition at line 866 of file computils.h.

◆ m_htest

template<typename T >
T* tPlotter< T >::m_htest
private

actual histograms

Definition at line 865 of file computils.h.

◆ m_max_entries

template<typename T >
size_t tPlotter< T >::m_max_entries
private

Definition at line 876 of file computils.h.

◆ m_plotfilename

template<typename T >
std::string tPlotter< T >::m_plotfilename
private

Definition at line 871 of file computils.h.

◆ m_tgref

template<typename T >
TGraphAsymmErrors* tPlotter< T >::m_tgref
private

Definition at line 869 of file computils.h.

◆ m_tgtest

template<typename T >
TGraphAsymmErrors* tPlotter< T >::m_tgtest
private

Definition at line 868 of file computils.h.

◆ m_trim_errors

template<typename T >
bool tPlotter< T >::m_trim_errors
private

Definition at line 879 of file computils.h.

◆ s_meanplotref

template<typename T >
bool tPlotter< T >::s_meanplotref = true
staticprivate

Definition at line 874 of file computils.h.

◆ s_plotref

template<typename T >
bool tPlotter< T >::s_plotref = true
staticprivate

use non c++17 format for improved external compatability

Definition at line 873 of file computils.h.


The documentation for this class was generated from the following file:
trim_tgraph
void trim_tgraph(TH1 *h, TGraphAsymmErrors *t)
Definition: computils.cxx:152
tPlotter::href
T * href()
Definition: computils.h:848
tPlotter::m_entries
size_t m_entries
Definition: computils.h:877
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
tPlotter::trim_errors
bool trim_errors() const
Definition: computils.h:493
tPlotter::htest
T * htest()
Definition: computils.h:847
contains
bool contains(const std::string &s, const std::string &p)
does a string contain the substring
Definition: hcg.cxx:111
tPlotter::m_htest
T * m_htest
actual histograms
Definition: computils.h:865
tPlotter::tgtest
TGraphAsymmErrors * tgtest()
Definition: computils.h:851
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
setParameters
void setParameters(T *h, TGraphAsymmErrors *tg)
Definition: computils.h:434
compute_lumi.leg
leg
Definition: compute_lumi.py:95
colours
int colours[6]
Definition: computils.cxx:45
tPlotter::m_max_entries
size_t m_max_entries
Definition: computils.h:876
tPlotter::m_tgtest
TGraphAsymmErrors * m_tgtest
Definition: computils.h:868
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
tPlotter::m_tgref
TGraphAsymmErrors * m_tgref
Definition: computils.h:869
tPlotter::m_plotfilename
std::string m_plotfilename
Definition: computils.h:871
LINEF
bool LINEF
Definition: computils.cxx:39
true_mean
Definition: computils.h:129
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
zeroErrors
void zeroErrors(T *h)
Definition: computils.h:445
DeMoScan.first
bool first
Definition: DeMoScan.py:536
LINES
bool LINES
Definition: computils.cxx:40
tPlotter::s_meanplotref
static bool s_meanplotref
Definition: computils.h:874
msizes
double msizes[6]
Definition: computils.cxx:47
plotable
double plotable(TH1 *h)
Definition: computils.cxx:238
tPlotter::s_plotref
static bool s_plotref
use non c++17 format for improved external compatability
Definition: computils.h:873
markers
int markers[6]
Definition: computils.cxx:46
Legend
slightly more convenient legend class
Definition: computils.h:335
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
tPlotter::m_trim_errors
bool m_trim_errors
Definition: computils.h:879
tPlotter::m_href
T * m_href
Definition: computils.h:866