|
ATLAS Offline Software
|
Go to the documentation of this file.
33 #include "TGraphAsymmErrors.h"
58 bool contains(
const std::string&
s,
const std::string&
p);
59 bool contains(
const std::string&
s,
char p) noexcept;
62 bool fcontains(
const std::string&
s,
const std::string&
p);
68 std::string
tail( std::string
s,
const std::string&
pattern );
71 std::string
head( std::string
s,
const std::string&
pattern );
74 std::string
globbed(
const std::string&
s );
80 const std::string&
path=
"" );
85 const std::vector<std::string>&
patterns=std::vector<std::string>(),
86 const std::string&
path=
"" );
89 double realmax( TH1*
h,
bool include_error=
true,
double lo=0,
double hi=0 );
90 double realmin( TH1*
h,
bool include_error=
true,
double lo=0,
double hi=0 );
92 std::string
findcell( std::string
name,
const std::string&
regex,
const std::string& splitex=
"/" );
102 virtual const char*
what()
const throw() {
return "data don't match"; }
109 for (
unsigned i=0 ;
i<
v.size() ;
i++ )
s <<
"\t" <<
v[
i];
115 std::vector<int>
findxrange(TH1*
h,
bool symmetric=
false );
123 void xrange(TH1*
h,
bool symmetric=
true );
169 std::vector<std::string>
keys =
split(
s,
":" );
178 for (
size_t i=1 ;
i<
keys.size() ;
i++ ) {
190 std::cout <<
"offset:" << std::endl;
191 std::cout <<
"\tkey: " <<
keys[
i] << std::endl;
192 std::cout <<
"\tpos: " <<
keys[
i].find(
"offset") << std::endl;
197 std::cout <<
"m_offset: " <<
m_offset << std::endl;
199 else if (
keys[
i]==
"auton" ) {
203 else if (
keys[
i]==
"autow" ) {
207 else if (
keys[
i]==
"autown" ||
keys[
i]==
"autonw" ) {
212 else if (
keys[
i]==
"autosym" ) {
216 else if (
keys[
i]==
"normw" ||
keys[
i]==
"widthn" ) {
220 else if ( !minset ) {
225 std::cerr <<
"not enough values for the axis range: " <<
s << std::endl;
235 std::cout <<
"AxisInfo::info" <<
m_info <<
"\n";
236 std::cout <<
"\tlog " <<
m_log <<
"\n";
237 std::cout <<
"\tauto " <<
m_autoset <<
"\n";
276 static std::vector<std::string>
split(
const std::string&
s,
const std::string&
t=
":" ) {
281 std::vector<std::string>
tags;
283 while (
pos!=std::string::npos ) {
321 s <<
"[ " <<
a.tag() << (
a.log() ?
" : log" :
"" ) <<
" ";
322 if (
a.autoset() )
s <<
" : auto";
323 else if (
a.rangeset() )
s <<
" : range " <<
a.lo() <<
" - " <<
a.hi();
376 void AddEntry( TObject* tobj,
const std::string&
s,
const std::string&
type=
"p" ) {
377 m_obj.push_back( tobj );
399 m_leg->SetBorderSize(0);
400 m_leg->SetTextFont(42);
401 m_leg->SetTextSize(0.04);
402 m_leg->SetFillStyle(3000);
403 m_leg->SetFillColor(0);
404 m_leg->SetLineColor(0);
435 tg->SetLineColor(
h->GetLineColor() );
436 tg->SetMarkerColor(
h->GetMarkerColor() );
437 tg->SetMarkerStyle(
h->GetMarkerStyle() );
438 tg->SetMarkerSize(
h->GetMarkerSize() );
439 tg->SetLineWidth(
h->GetLineWidth() );
440 tg->SetLineStyle(
h->GetLineStyle() );
446 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ )
h->SetBinError(
i, 1
e-100 );
460 tPlotter(
T* _htest=0,
T* _href=0,
const std::string&
s=
"", TGraphAsymmErrors* _tgtest=0, TGraphAsymmErrors* _tgref=0 ) :
498 gStyle->SetOptStat(0);
501 href()->SetLineStyle(2);
502 href()->SetMarkerStyle(0);
507 htest()->SetLineStyle(1);
518 std::cout << std::endl;
524 htest()->GetXaxis()->SetMoreLogLabels(
true);
534 htest()->GetXaxis()->SetMoreLogLabels(
true);
548 else href()->Draw(
"hist same");
562 if (
htest()->GetMarkerStyle()>23 ) {
564 TH1D* hnull = (TH1D*)
htest()->Clone(
"duff"); hnull->SetDirectory(0);
566 hnull->SetLineColor(kWhite);
567 hnull->SetMarkerStyle(
htest()->GetMarkerStyle()-4 );
569 hnull->SetMarkerColor(kWhite);
570 hnull->SetMarkerSize(
htest()->GetMarkerSize()*0.75 );
572 hnull->DrawCopy(
"l same");
577 htest()->Draw(
"ep same");
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);
601 bool displayref =
false;
605 std::sprintf( meanrefc,
" <t> = %3.2f #pm %3.2f ms (ref)", muref.
mean(), muref.
error() );
608 std::sprintf( meanrefc,
"%s",
"" );
613 std::sprintf( meanc,
" <t> = %3.2f #pm %3.2f ms", mutest.
mean(), mutest.
error() );
615 std::string dkey =
key;
617 std::string
remove[7] = {
"TIME_",
"Time_",
"All_",
"Algorithm_",
"Class_",
"HLT_",
"Chain_HLT_" };
619 if ( dkey.find(
"Chain")!=std::string::npos ) {
620 if ( dkey.find(
"__")!=std::string::npos ) dkey.erase( 0, dkey.find(
"__")+2 );
624 for (
int ir=0 ;
ir<7 ;
ir++ ) {
628 std::string rkey = dkey;
632 dkey += std::string(
" : ");
634 if ( (dkey+meanc).
size()>58 ) {
636 leg.AddEntry( hnull, meanc,
"p" );
639 leg.AddEntry(
htest(), (dkey+meanc).c_str(),
"p" );
643 rkey += std::string(
" : ");
647 if ( (rkey+meanrefc).
size()>58 ) {
648 leg.AddEntry(
href(), rkey,
"l" );
649 leg.AddEntry( hnull, meanrefc,
"l" );
652 leg.AddEntry(
href(), (rkey+meanrefc).c_str(),
"l" );
664 if ( drawlegend )
leg.Draw();
675 gStyle->SetOptStat(0);
678 href()->SetLineStyle(2);
679 href()->SetMarkerStyle(0);
683 htest()->SetLineStyle(1);
688 std::cout << std::endl;
694 htest()->GetXaxis()->SetMoreLogLabels(
true);
704 htest()->GetXaxis()->SetMoreLogLabels(
true);
720 else href()->Draw(
"hist same");
736 if (
htest()->GetMarkerStyle()>23 ) {
738 TH1D* hnull = (TH1D*)
htest()->Clone(
"duff"); hnull->SetDirectory(0);
740 hnull->SetLineColor(kWhite);
741 hnull->SetMarkerStyle(
htest()->GetMarkerStyle()-4 );
743 hnull->SetMarkerColor(kWhite);
744 hnull->SetMarkerSize(
htest()->GetMarkerSize()*0.75 );
746 hnull->DrawCopy(
"l same");
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);
771 bool displayref =
false;
775 std::sprintf( meanrefc,
" <t> = %3.2f #pm %3.2f ms (ref)", muref.
mean(), muref.
error() );
778 std::sprintf( meanrefc,
"%s",
"" );
784 std::sprintf( meanc,
" <t> = %3.2f #pm %3.2f ms", mutest.
mean(), mutest.
error() );
786 std::string dkey =
key;
788 std::string
remove[7] = {
"TIME_",
"Time_",
"All_",
"Algorithm_",
"Class_",
"HLT_",
"Chain_HLT_" };
790 if ( dkey.find(
"Chain")!=std::string::npos ) {
791 if ( dkey.find(
"__")!=std::string::npos ) dkey.erase( 0, dkey.find(
"__")+2 );
795 for (
int ir=0 ;
ir<7 ;
ir++ ) {
799 std::string rkey = dkey;
803 dkey += std::string(
" : ");
805 if ( (dkey+meanc).
size()>58 ) {
807 leg.AddEntry( hnull, meanc,
"p" );
810 leg.AddEntry(
htest(), (dkey+meanc).c_str(),
"p" );
814 rkey += std::string(
" : ");
817 if ( (rkey+meanrefc).
size()>58 ) {
818 leg.AddEntry(
href(), rkey,
"l" );
819 leg.AddEntry( hnull, meanrefc,
"l" );
822 leg.AddEntry(
href(), (rkey+meanrefc).c_str(),
"l" );
834 if ( drawlegend )
leg.Draw();
843 if (
s!=
"" ) gPad->Print(
s.c_str());
902 std::cout << __FUNCTION__ << std::endl;
903 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
904 double duff =
h->GetBinContent(
i);
906 std::cout<<
"\t\t" << __FUNCTION__ <<
" " <<
h->GetName() <<
" " <<
i <<
" " <<
h->GetBinContent(
i) <<
" " << (duff*1e6) << std::endl;
910 gPad->Print( (std::string(
"duff-")+
h->GetName()+
".pdf").c_str() );
915 class Plots :
public std::vector<Plotter> {
932 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
934 if ( rmtest!=0 && (
first ||
min>rmtest ) )
min = rmtest;
935 if ( rmtest!=0 )
first =
false;
943 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
946 if ( rmtest!=0 && (
first ||
max<rmtest ) )
max = rmtest;
947 if ( rmtest!=0 )
first =
false;
956 if (
size()<1 )
return;
965 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
966 if ( at(
i).href() ) at(
i).href()->SetMaximum(
scale*tmax);
967 at(
i).htest()->SetMaximum(
scale*tmax);
975 if (
size()<1 )
return;
978 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
979 if ( at(
i).href() ) at(
i).href()->SetMinimum(0);
980 at(
i).htest()->SetMinimum(0);
993 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
994 if ( at(
i).href() ) at(
i).href()->SetMinimum(
scale*tmin);
995 at(
i).htest()->SetMinimum(
scale*tmin);
1002 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1003 if ( at(
i).href() ) at(
i).href()->SetMinimum(
scale);
1004 at(
i).htest()->SetMinimum(
scale);
1006 if ( at(
i).
href() )
if ( at(
i).
href()->GetMinimum()<=0 ) at(
i).href()->GetMinimum(1
e-4);
1007 if ( at(
i).
htest()->GetMinimum()<=0 ) at(
i).htest()->GetMinimum(1
e-4);
1015 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1016 if ( at(
i).href() ) at(
i).href()->SetMaximum(
scale);
1017 at(
i).htest()->SetMaximum(
scale);
1026 std::vector<double>
v(2,0);
1028 TH1F* hf = at(0).htest();
1033 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1034 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1040 for (
unsigned i=1 ;
i<
size() ;
i++ ) {
1044 if ( ::
empty( hf ) )
continue;
1046 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1047 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1059 if (
v[0]>
lo )
v[0] =
lo;
1060 if (
v[1]<
hi )
v[1] =
hi;
1066 double upper = (
v[1]-
v[0] )*1.1 +
v[0];
1067 double lower =
v[0] - (
v[1]-
v[0] )*0.1;
1070 double dx = std::log10(
v[1])-std::log10(
v[0]);
1075 if ( lower<vlo ) lower = vlo;
1104 else if (
size() == 0)
1106 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;
1126 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1127 if ( at(
i).href() ) ::
xrange( at(
i).href(), symmetric );
1136 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1137 if ( at(
i).href() ) at(
i).href()->GetXaxis()->SetRangeUser(
m_lo,
m_hi );
1138 at(
i).htest()->GetXaxis()->SetRangeUser(
m_lo,
m_hi );
1147 std::cout <<
"\tlimits \t" <<
m_name <<
"\tmin " << rmin <<
"\tmax " << rmax << std::endl;
1168 double ymax = at(
i).htest()->GetMaximum();
1169 double ymin = at(
i).htest()->GetMinimum();
1170 at(
i).htest()->GetYaxis()->SetMoreLogLabels(
true);
1171 if (
ymax/
ymin>1e6 ) at(
i).htest()->GetYaxis()->SetMoreLogLabels(
false);
1195 if (
size()>0 )
return at(0).htest()->GetXaxis()->GetTitle();
1200 if (
size()>0 )
return at(0).htest()->GetYaxis()->GetTitle();
1205 if (
size()>0 ) at(0).htest()->GetXaxis()->SetTitle(
s.c_str());
1209 if (
size()>0 ) at(0).htest()->GetYaxis()->SetTitle(
s.c_str());
1216 std::vector<Plotter>::push_back(
val );
1312 return s <<
"[ " <<
h.name() <<
" \tx: \"" <<
h.xtitle() <<
"\" " <<
h.xaxis() <<
"\t\ty: \"" <<
h.ytitle() <<
"\" " <<
h.yaxis() <<
" ]";
1371 s <<
"Panel: " <<
p.name();
1372 if (
p.size() == 1 )
s <<
"\t" <<
p[0];
1373 else for (
size_t i=0 ;
i<
p.size() ;
i++ )
s <<
"\n\t" <<
p[
i];
1381 #endif // COMPUTILS_H
void trim_tgraph(TH1 *h, TGraphAsymmErrors *t)
HistDetails(const std::string *vp)
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory="", const std::string &pattern="", const std::string &path="")
bool m_rangeset
xaxis range setting
Plots(const std::string &s="", bool errors=false)
const std::string & detail() const
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="")
void AddEntry(TObject *tobj, const std::string &s, const std::string &type="p")
path
python interpreter configuration --------------------------------------—
Panel(const std::string &s, int nc)
don't know how many rows or total hists yet, but do know number of columns
void copyReleaseInfo(TFile *finput, TFile *foutdir)
copy the TTree of release info from one directory to another
virtual const char * what() const
std::string find(const std::string &s)
return a remapped string
AxisInfo(const std::string &s)
Legend(const Legend &legend)
void push_back(const HistDetails &h)
std::vector< TObject * > m_obj
TGraphAsymmErrors * tgref()
std::vector< std::string > patterns
void Draw(Legend &leg, bool means=false)
bool contains(const std::string &s, const std::string &p)
does a string contain the substring
T * m_htest
actual histograms
void Draw_i(Legend &leg, bool means=false)
std::string chop(std::string &s1, const std::string &s2)
TGraphAsymmErrors * tgtest()
data_mismatch(const std::string &s)
const AxisInfo & yaxis() const
std::vector< std::string > m_type
void Draw(int i, Legend *lleg, bool mean=false, bool first=true, bool drawlegend=false)
bool fcontains(const std::string &s, const std::string &p)
does a string contain the substring at the beginning of the string
void xrange(TH1 *h, bool symmetric=true)
std::string tail(std::string s, const std::string &pattern)
tail of a string
const std::string & c_str() const
const HistDetails & operator[](int i) const
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
void SetRangeUser(double lo, double hi)
std::string globbed(const std::string &s)
match a file name
const std::string & name() const
void Print(const std::string &s="")
print the output
void ATLASFORAPP_LABEL(double x, double y, int color, double size=0.06)
std::vector< std::string > tags
static void setplotref(bool b)
tPlotter(T *_htest=0, T *_href=0, const std::string &s="", TGraphAsymmErrors *_tgtest=0, TGraphAsymmErrors *_tgref=0)
details of the histogram axes etc
void setParameters(T *h, TGraphAsymmErrors *tg)
std::vector< double > findxrange(bool symmetric=false)
double realmin(double lo=0, double hi=0)
std::ostream & operator<<(std::ostream &s, std::vector< T > &v)
bool exists(const std::string &filename)
does a file exist
const std::string & plotfilename() const
void myText(Double_t x, Double_t y, Color_t color, const std::string &text, Double_t tsize)
std::vector< double > findxrangeuser(TH1 *h, bool symmetric=false)
double realmax(double lo=0, double hi=0)
void sortx(const AxisInfo &xinfo)
std::vector< std::string > m_entries
void SetXaxisTitle(const std::string &s)
std::string GetYaxisTitle()
void MaxScale(double scale=1.1, double lo=0, double hi=0)
double atof(std::string_view str)
Converts a string into a double / float.
void Norm(TH1 *h, double scale=1)
bool m_maxset
yaxis range setting
double realmax(TH1 *h, bool include_error=true, double lo=0, double hi=0)
~tPlotter()
sadly, root manages all the histograms (does it really? who can tell) so we mustn't delete anything j...
void DrawLegend(int i, Legend &leg, bool mean=false, bool first=true, bool drawlegend=false)
static void setwatermark(bool b)
generic plotter class - better to have one of these - make sure it can be configured however you like...
TGraphAsymmErrors * m_tgtest
Panel(const std::string &s, int nr, int nc)
know number of rows and columns
const AxisInfo & xaxis() const
const std::string & tag() const
accessors
TGraphAsymmErrors * m_tgref
static void setmeanplotref(bool b)
void SetLogy(bool b=true)
HistDetails & operator[](int i)
std::string m_plotfilename
std::string head(std::string s, const std::string &pattern)
head of a string
std::vector< HistDetails > m_hist
double realmin(TH1 *h, bool include_error=true, double lo=0, double hi=0)
Legend(double x1, double x2, double y1, double y2)
tPlotter(const tPlotter &p)
int ir
counter of the current depth
static std::vector< std::string > split(const std::string &s, const std::string &t=":")
std::string ytitle() const
const HistDetails & back() const
std::string GetXaxisTitle()
std::string xtitle() const
HistDetails(const std::vector< std::string > &v)
void xrange(bool symmetric=false)
static bool s_meanplotref
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
std::string findcell(std::string name, const std::string ®ex, const std::string &splitex="/")
bool m_logx
canvas log setting
void SetYaxisTitle(const std::string &s)
std::vector< std::string > m_details
constexpr int pow(int base, int exp) noexcept
static bool s_plotref
use non c++17 format for improved external compatability
void MinScale(double scale, double lo=0, double hi=0)
class to store information about axes, limits, whether it is log or linear scale etc
std::string stime()
return the current data and time
void SetLogx(bool b=true)
std::string findrun(TFile *f)
slightly more convenient legend class
std::vector< int > findxrange(TH1 *h, bool symmetric=false)
automatically set the xrange on a histogram