ATLAS Offline Software
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 458 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 462 of file computils.h.

462  :
465  m_plotfilename(s),
466  m_max_entries(4),
467  m_entries(0),
468  m_trim_errors(false)
469  {
470  }

◆ tPlotter() [2/2]

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

Definition at line 473 of file computils.h.

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

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

489 { }

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

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

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

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

◆ href()

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

Definition at line 850 of file computils.h.

850 { return m_href; }

◆ htest()

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

Definition at line 849 of file computils.h.

849 { return m_htest; }

◆ max_entries()

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

Definition at line 857 of file computils.h.

857 { m_max_entries = i; }

◆ plotfilename()

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

Definition at line 491 of file computils.h.

491 { return m_plotfilename; }

◆ Print()

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

print the output

Definition at line 844 of file computils.h.

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

◆ setmeanplotref()

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

Definition at line 862 of file computils.h.

862 { s_meanplotref=b; }

◆ setplotref()

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

Definition at line 861 of file computils.h.

◆ tgref()

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

Definition at line 854 of file computils.h.

854 { return m_tgref; }

◆ tgtest()

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

Definition at line 853 of file computils.h.

853 { return m_tgtest; }

◆ trim_errors() [1/2]

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

Definition at line 495 of file computils.h.

495 { return m_trim_errors; }

◆ trim_errors() [2/2]

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

Definition at line 493 of file computils.h.

493 { m_trim_errors=b; }

Member Data Documentation

◆ m_entries

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

Definition at line 879 of file computils.h.

◆ m_href

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

Definition at line 868 of file computils.h.

◆ m_htest

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

actual histograms

Definition at line 867 of file computils.h.

◆ m_max_entries

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

Definition at line 878 of file computils.h.

◆ m_plotfilename

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

Definition at line 873 of file computils.h.

◆ m_tgref

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

Definition at line 871 of file computils.h.

◆ m_tgtest

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

Definition at line 870 of file computils.h.

◆ m_trim_errors

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

Definition at line 881 of file computils.h.

◆ s_meanplotref

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

Definition at line 876 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 875 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:153
tPlotter::href
T * href()
Definition: computils.h:850
tPlotter::m_entries
size_t m_entries
Definition: computils.h:879
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:495
tPlotter::tgref
TGraphAsymmErrors * tgref()
Definition: computils.h:854
tPlotter::htest
T * htest()
Definition: computils.h:849
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:867
tPlotter::tgtest
TGraphAsymmErrors * tgtest()
Definition: computils.h:853
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:209
lumiFormat.i
int i
Definition: lumiFormat.py:85
setParameters
void setParameters(T *h, TGraphAsymmErrors *tg)
Definition: computils.h:436
compute_lumi.leg
leg
Definition: compute_lumi.py:95
colours
int colours[6]
Definition: computils.cxx:46
tPlotter::m_max_entries
size_t m_max_entries
Definition: computils.h:878
tPlotter::m_tgtest
TGraphAsymmErrors * m_tgtest
Definition: computils.h:870
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
tPlotter::m_tgref
TGraphAsymmErrors * m_tgref
Definition: computils.h:871
tPlotter::m_plotfilename
std::string m_plotfilename
Definition: computils.h:873
LINEF
bool LINEF
Definition: computils.cxx:40
true_mean
Definition: computils.h:130
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
zeroErrors
void zeroErrors(T *h)
Definition: computils.h:447
DeMoScan.first
bool first
Definition: DeMoScan.py:534
LINES
bool LINES
Definition: computils.cxx:41
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
tPlotter::s_meanplotref
static bool s_meanplotref
Definition: computils.h:876
msizes
double msizes[6]
Definition: computils.cxx:48
plotable
double plotable(TH1 *h)
Definition: computils.cxx:239
tPlotter::s_plotref
static bool s_plotref
use non c++17 format for improved external compatability
Definition: computils.h:875
markers
int markers[6]
Definition: computils.cxx:47
Legend
slightly more convenient legend class
Definition: computils.h:337
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
tPlotter::m_trim_errors
bool m_trim_errors
Definition: computils.h:881
tPlotter::m_href
T * m_href
Definition: computils.h:868